0028088: Visualization, AIS_InteractiveContext - drop default value for Update Viewer...
[occt.git] / samples / mfc / standard / 02_Modeling / src / ModelingDoc.cpp
CommitLineData
7fd59977 1// ModelingDoc.cpp : implementation of the CModelingDoc class
2//
3
4#include "stdafx.h"
5
6#include "ModelingDoc.h"
7
8#include "ModelingApp.h"
9#include "ResultDialog.h"
10#include "State.h"
11
12#include "ISession_Direction.h"
13#include "..\res\resource.h"
14
15#include <AIS_ListOfInteractive.hxx>
16#include <AIS_ListIteratorOfListOfInteractive.hxx>
17#include <TColStd_Array2OfReal.hxx>
18#include <OCC_MainFrame.h>
234e52be 19#include <BRepPrimAPI_MakeCylinder.hxx>
20#include <TopExp_Explorer.hxx>
21#include <Geom_Plane.hxx>
22#include <BRepTools.hxx>
7fd59977 23
e0280ce9 24static Handle(AIS_Shape) AIS1;
25static TopoDS_Face THE_F1, THE_F2;
26static TopoDS_Edge THE_E1, THE_E2;
7fd59977 27
28/////////////////////////////////////////////////////////////////////////////
29// CModelingDoc
30
31IMPLEMENT_DYNCREATE(CModelingDoc, CDocument)
32
33BEGIN_MESSAGE_MAP(CModelingDoc, OCC_3dBaseDoc)
34 //{{AFX_MSG_MAP(CModelingDoc)
35 ON_COMMAND(ID_MIRROR, OnMirror)
36 ON_COMMAND(ID_MIRRORAXIS, OnMirroraxis)
37 ON_COMMAND(ID_ROTATE, OnRotate)
38 ON_COMMAND(ID_SCALE, OnScale)
39 ON_COMMAND(ID_TRANSLATION, OnTranslation)
40 ON_COMMAND(ID_DISPLACEMENT, OnDisplacement)
41 ON_COMMAND(ID_DEFORM, OnDeform)
42 ON_COMMAND(ID_BOX, OnBox)
43 ON_COMMAND(ID_Cylinder, OnCylinder)
44 ON_COMMAND(ID_CONE, OnCone)
45 ON_COMMAND(ID_SPHERE, OnSphere)
46 ON_COMMAND(ID_TORUS, OnTorus)
47 ON_COMMAND(ID_WEDGE, OnWedge)
48 ON_COMMAND(ID_PRISM, OnPrism)
49 ON_COMMAND(ID_REVOL, OnRevol)
50 ON_COMMAND(ID_PIPE, OnPipe)
51 ON_COMMAND(ID_THRU, OnThru)
52 ON_COMMAND(ID_EVOLVED, OnEvolved)
53 ON_COMMAND(ID_DRAFT, OnDraft)
54 ON_COMMAND(ID_CUT, OnCut)
55 ON_COMMAND(ID_FUSE, OnFuse)
56 ON_COMMAND(ID_SECTION, OnSection)
57 ON_COMMAND(ID_COMMON, OnCommon)
58 ON_COMMAND(ID_PSECTION, OnPsection)
59 ON_COMMAND(ID_BLEND, OnBlend)
60 ON_COMMAND(ID_CHAMF, OnChamf)
61 ON_COMMAND(ID_EVOLVEDBLEND, OnEvolvedblend)
62 ON_COMMAND(ID_PRISM_LOCAL, OnPrismLocal)
63 ON_COMMAND(ID_REVOL_LOCAL, OnRevolLocal)
64 ON_COMMAND(ID_GLUE_LOCAL, OnGlueLocal)
65 ON_COMMAND(ID_DPRISM_LOCAL, OnDprismLocal)
66 ON_COMMAND(ID_Pipe_LOCAL, OnPipeLocal)
67 ON_COMMAND(ID_LINEAR_LOCAL, OnLinearLocal)
68 ON_COMMAND(ID_SPLIT_LOCAL, OnSplitLocal)
69 ON_COMMAND(ID_THICK_LOCAL, OnThickLocal)
70 ON_COMMAND(ID_OFFSET_LOCAL, OnOffsetLocal)
71 ON_COMMAND(ID_VERTEX, OnVertex)
72 ON_COMMAND(ID_EDGE, OnEdge)
73 ON_COMMAND(ID_WIRE, OnWire)
74 ON_COMMAND(ID_FACE, OnFace)
75 ON_COMMAND(ID_SHELL, OnShell)
76 ON_COMMAND(ID_COMPOUND, OnCompound)
77 ON_COMMAND(ID_GEOMETRIE, OnGeometrie)
78 ON_COMMAND(ID_SEWING, OnSewing)
79 ON_COMMAND(ID_EXPLORER, OnExplorer)
80 ON_COMMAND(ID_BUILDER, OnBuilder)
81 ON_COMMAND(ID_VALID, OnValid)
82 ON_COMMAND(ID_LINEAR, OnLinear)
83 ON_COMMAND(ID_VOLUME, OnVolume)
84 ON_COMMAND(ID_SURFACE, OnSurface)
85 ON_COMMAND(ID_BUTTON_FILL, OnButtonFill)
86 ON_COMMAND(ID_STOP_STOP, OnStopStop)
87 ON_COMMAND(ID_FILLWITHTANG, OnFillwithtang)
88 //}}AFX_MSG_MAP
89END_MESSAGE_MAP()
90
91/////////////////////////////////////////////////////////////////////////////
92// CModelingDoc construction/destruction
93
94CModelingDoc::CModelingDoc()
95{
96 myAISContext->SetDisplayMode(AIS_Shaded,Standard_False);
97}
98
99CModelingDoc::~CModelingDoc()
100{
101}
102
103void CModelingDoc::OnMirror()
104{
105 AIS_ListOfInteractive aList;
106 myAISContext->DisplayedObjects(aList);
107 AIS_ListIteratorOfListOfInteractive aListIterator;
108 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 109 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 110 }
576f8b11 111 TopoDS_Shape S = BRepPrimAPI_MakeWedge (60.,100.,80.,20.).Shape();
7fd59977 112 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
5c573e69 113 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
114 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
7fd59977 115 myAISContext->Display(ais1,Standard_False);
116 gp_Trsf theTransformation;
117 gp_Pnt PntCenterOfTheTransformation(110,60,60);
118 Handle(AIS_Point) aispnt = new AIS_Point(new Geom_CartesianPoint(PntCenterOfTheTransformation));
119 myAISContext->Display(aispnt,Standard_False);
120 theTransformation.SetMirror(PntCenterOfTheTransformation);
121 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
122 TopoDS_Shape S2 = myBRepTransformation.Shape();
123 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
124 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
125 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
126 myAISContext->Display(ais2,Standard_False);
127 Fit();
128 TCollection_AsciiString Message ("\
129\n\
130TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
131gp_Trsf theTransformation; \n\
132gp_Pnt PntCenterOfTheTransformation(110,60,60); \n\
133theTransformation.SetMirror(PntCenterOfTheTransformation);\n\
134BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
135TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
136 PocessTextInDialog("Transform a Shape with Mirror and One point.", Message);
137
138}
139
140void CModelingDoc::OnMirroraxis()
141{
142 AIS_ListOfInteractive aList;
143 myAISContext->DisplayedObjects(aList);
144 AIS_ListIteratorOfListOfInteractive aListIterator;
145 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 146 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 147 }
576f8b11 148 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape();
7fd59977 149 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
150 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
151 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
152 myAISContext->Display(ais1,Standard_False);
153 gp_Trsf theTransformation;
154 gp_Ax1 axe = gp_Ax1(gp_Pnt(110,60,60),gp_Dir(0.,1.,0.));
155 Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
156 Handle (AIS_Axis) ax1 = new AIS_Axis(Gax1);
157 myAISContext->Display(ax1,Standard_False);
158 theTransformation.SetMirror(axe);
159 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
160 TopoDS_Shape S2 = myBRepTransformation.Shape();
161 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
162 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
163 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
164 myAISContext->Display(ais2,Standard_False);
165 Fit();
166
167 TCollection_AsciiString Message ("\
168\n\
169TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
170gp_Trsf theTransformation; \n\
171gp_Ax1 Axis = gp_Ax1(gp_Pnt(110,60,60),gp_Dir(0.,1.,0.)); \n\
172theTransformation.SetMirror(Axis);\n\
173BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
174TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
175
176 PocessTextInDialog("Transform a Shape with Mirror and One axis.", Message);
177
178}
179
180
181void CModelingDoc::OnRotate()
182{
183 AIS_ListOfInteractive aList;
184 myAISContext->DisplayedObjects(aList);
185 AIS_ListIteratorOfListOfInteractive aListIterator;
186 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 187 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 188 }
576f8b11 189 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape();
7fd59977 190 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
191 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
192 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
193 myAISContext->Display(ais1,Standard_False);
194 gp_Trsf theTransformation;
195 gp_Ax1 axe = gp_Ax1(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.));
196 Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
197 Handle (AIS_Axis) ax1 = new AIS_Axis(Gax1);
198 myAISContext->Display(ax1,Standard_False);
42e4630c 199 theTransformation.SetRotation(axe,30*M_PI/180);
7fd59977 200 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
201 TopoDS_Shape S2 = myBRepTransformation.Shape();
202 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
203 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
204 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
205 myAISContext->Display(ais2,Standard_False);
206 Fit();
207
208 TCollection_AsciiString Message ("\
209\n\
210TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
211gp_Trsf theTransformation; \n\
212gp_Ax1 Axis = gp_Ax1(gp_Pnt(200,60,60),gp_Dir(0.,1.,0.)); \n\
213theTransformation.SetRotation(Axis,30*PI/180); // Rotation of 30 degrees \n\
214BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
215TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
216
217 PocessTextInDialog("Transform a Shape with Rotation.", Message);
218
219}
220
221void CModelingDoc::OnScale()
222{
223 AIS_ListOfInteractive aList;
224 myAISContext->DisplayedObjects(aList);
225 AIS_ListIteratorOfListOfInteractive aListIterator;
226 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 227 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 228 }
576f8b11 229 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape();
7fd59977 230 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
231 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
232 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
233 myAISContext->Display(ais1,Standard_False);
234 gp_Trsf theTransformation;
235 gp_Pnt theCenterOfScale(200,60,60);
236 Handle(AIS_Point) aispnt = new AIS_Point(new Geom_CartesianPoint(theCenterOfScale));
237
238 myAISContext->Display(aispnt,Standard_False);
239 theTransformation.SetScale(theCenterOfScale,0.5);
240 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
241 TopoDS_Shape S2 = myBRepTransformation.Shape();
242
243 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
244 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
245 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
246 myAISContext->Display(ais2,Standard_False);
247 Fit();
248
249 TCollection_AsciiString Message ("\
250\n\
251TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
252gp_Trsf theTransformation; \n\
253gp_Pnt theCenterOfScale(200,60,60); \n\
254theTransformation.SetScale(theCenterOfScale,0.5); // Scale : value = 0.5 \n\
255BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
256TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
257
258 PocessTextInDialog("Scale a Shape with One point.", Message);
259
260
261}
262
263
264
265void CModelingDoc::OnTranslation()
266{
267 AIS_ListOfInteractive aList;
268 myAISContext->DisplayedObjects(aList);
269 AIS_ListIteratorOfListOfInteractive aListIterator;
270 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 271 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 272 }
576f8b11 273 TopoDS_Shape S = BRepPrimAPI_MakeWedge(6.,10.,8.,2.).Shape();
7fd59977 274 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
275 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
276 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
277 myAISContext->Display(ais1,Standard_False);
278 gp_Trsf theTransformation;
279 gp_Vec theVectorOfTranslation(-6,-6,6);
5c573e69 280
9e3ca93a 281 Handle(ISession_Direction) aDirection1 = new ISession_Direction(gp_Pnt(0,0,0),theVectorOfTranslation);
7fd59977 282 myAISContext->Display(aDirection1,Standard_False);
283
284 theTransformation.SetTranslation(theVectorOfTranslation);
285 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
286 TopoDS_Shape S2 = myBRepTransformation.Shape();
287
288 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
289 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
290 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
291 myAISContext->Display(ais2,Standard_False);
292
293 Fit();
294
295 TCollection_AsciiString Message ("\
296\n\
297TopoDS_Shape S = BRepBuilderAPI_MakeWedge(6.,10.,8.,2.); \n\
298gp_Trsf theTransformation; \n\
299gp_Vec theVectorOfTranslation(6,6,6); \n\
300theTransformation.SetTranslation(theVectorOfTranslation); \n\
301BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
302TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
303
304 PocessTextInDialog("Translate a Shape with One vector.", Message);
305
306}
307
308void CModelingDoc::OnDisplacement()
309{
310 AIS_ListOfInteractive aList;
311 myAISContext->DisplayedObjects(aList);
312 AIS_ListIteratorOfListOfInteractive aListIterator;
313 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 314 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 315 }
576f8b11 316 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
7fd59977 317 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
318 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
319 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
320 myAISContext->Display(ais1,Standard_False);
321 gp_Trsf theTransformation;
322
323 gp_Ax3 ax3_1(gp_Pnt(0,0,0),gp_Dir(0,0,1));
324 gp_Ax3 ax3_2(gp_Pnt(60,60,60),gp_Dir(1,1,1));
325
326 theTransformation.SetDisplacement(ax3_1,ax3_2);
327 BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);
328 TopoDS_Shape TransformedShape = myBRepTransformation.Shape();
329 Handle(AIS_Shape) ais2 = new AIS_Shape(TransformedShape);
330 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
331 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
332 myAISContext->Display(ais2,Standard_False);
333 Fit();
334 TCollection_AsciiString Message ("\
335\n\
336TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
337gp_Trsf theTransformation; \n\
338gp_Ax3 ax3_1(gp_Pnt(0,0,0),gp_Dir(0,0,1)); \n\
339gp_Ax3 ax3_2(gp_Pnt(60,60,60),gp_Dir(1,1,1)); \n\
340theTransformation.SetDisplacement(ax3_1,ax3_2); \n\
341BRepBuilderAPI_Transform myBRepTransformation(S,theTransformation);\n\
342TopoDS_Shape TransformedShape = myBRepTransformation.Shape(); \n");
343
344 PocessTextInDialog("Displace a Shape with Two coordinate systems.", Message);
345
346
347}
348
349
350void CModelingDoc::OnDeform()
351{
352 AIS_ListOfInteractive aList;
353 myAISContext->DisplayedObjects(aList);
354 AIS_ListIteratorOfListOfInteractive aListIterator;
355 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 356 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 357 }
576f8b11 358 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
7fd59977 359 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
360 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
361 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
362 myAISContext->Display(ais1,Standard_False);
363
364 gp_GTrsf theTransformation;
365 gp_Mat rot(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5);
366 theTransformation.SetVectorialPart(rot);
367 theTransformation.SetTranslationPart(gp_XYZ(5,5,5));
368
369 BRepBuilderAPI_GTransform myBRepTransformation(S,theTransformation);
370 TopoDS_Shape S2 = myBRepTransformation.Shape();
371
372 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
373 myAISContext->SetColor(ais2,Quantity_NOC_BLUE1,Standard_False);
374 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
375 myAISContext->Display(ais2,Standard_False);
376 Fit();
377 TCollection_AsciiString Message ("\
378\n\
379TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.); \n\
380gp_GTrsf theTransformation; \n\
381gp_Mat rot(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5); // scaling : 100% on X ; 50% on Y ; 150% on Z . \n\
382theTransformation.SetVectorialPart(rot); \n\
383theTransformation.SetTranslationPart(gp_XYZ(5,5,5)); \n\
384BRepBuilderAPI_GTransform myBRepGTransformation(S,theTransformation);\n\
385TopoDS_Shape TransformedShape = myBRepGTransformation.Shape(); \n");
386
387 PocessTextInDialog("Deform a Shape with One matrix of deformation and One translation.", Message);
388}
389
390/* =================================================================================
391 ==================== P R I M I T I V E S ====================================
392 ================================================================================= */
393
394void CModelingDoc::OnBox()
395{
396 AIS_ListOfInteractive aList;
397 myAISContext->DisplayedObjects(aList);
398 AIS_ListIteratorOfListOfInteractive aListIterator;
399 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 400 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 401 }
576f8b11 402 TopoDS_Shape B1 = BRepPrimAPI_MakeBox(200., 150., 100.).Shape();
7fd59977 403 Handle(AIS_Shape) aBox1 = new AIS_Shape(B1);
404 myAISContext->SetMaterial(aBox1,Graphic3d_NOM_PLASTIC,Standard_False);
405 myAISContext->SetColor(aBox1,Quantity_NOC_GREEN,Standard_False);
406 myAISContext->Display(aBox1,Standard_False);
407 TopoDS_Shape B2 = BRepPrimAPI_MakeBox (gp_Ax2(gp_Pnt(-200.,-80.,-70.),
576f8b11 408 gp_Dir(1.,2.,1.)),
409 80., 90., 120.).Shape();
7fd59977 410 Handle(AIS_Shape) aBox2 = new AIS_Shape(B2);
411 myAISContext->SetMaterial(aBox2,Graphic3d_NOM_PLASTIC,Standard_False);
412 myAISContext->SetColor(aBox2,Quantity_NOC_RED,Standard_False);
413 myAISContext->Display(aBox2,Standard_False);
414 Fit();
415 TCollection_AsciiString Message ("\
416 \n\
417TopoDS_Shape B1 = BRepPrimAPI_MakeBox (200.,150.,100.); \n\
418TopoDS_Shape B2 = BRepPrimAPI_MakeBox (gp_Ax2(gp_Pnt(-200.,-80.,-70.), \n\
419 gp_Dir(1.,2.,1.)), \n\
420 80.,90.,120.); \n\
421 \n");
422 PocessTextInDialog("Make a topological box", Message);
423}
424
425void CModelingDoc::OnCylinder()
426{
427 AIS_ListOfInteractive aList;
428 myAISContext->DisplayedObjects(aList);
429 AIS_ListIteratorOfListOfInteractive aListIterator;
430 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 431 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 432 }
433
576f8b11 434 TopoDS_Shape C1 = BRepPrimAPI_MakeCylinder(50., 200.).Shape();
7fd59977 435 Handle(AIS_Shape) aCyl1 = new AIS_Shape(C1);
436 myAISContext->SetMaterial(aCyl1,Graphic3d_NOM_PLASTIC,Standard_False);
437 myAISContext->SetColor(aCyl1,Quantity_NOC_RED,Standard_False);
438 myAISContext->Display(aCyl1,Standard_False);
439 TopoDS_Shape C2 = BRepPrimAPI_MakeCylinder (gp_Ax2(gp_Pnt(200.,200.,0.),
576f8b11 440 gp_Dir(0.,0.,1.)),
441 40., 110., 210.*M_PI / 180).Shape();
7fd59977 442 Handle(AIS_Shape) aCyl2 = new AIS_Shape(C2);
443 myAISContext->SetMaterial(aCyl2,Graphic3d_NOM_PLASTIC,Standard_False);
444 myAISContext->SetColor(aCyl2,Quantity_NOC_MATRABLUE,Standard_False);
445 myAISContext->Display(aCyl2,Standard_False);
446 Fit();
447
448 TCollection_AsciiString Message ("\
449 \n\
450TopoDS_Shape C1 = BRepPrimAPI_MakeCylinder (50.,200.); \n\
451TopoDS_Shape C2 = BRepPrimAPI_MakeCylinder (gp_Ax2(gp_Pnt(200.,200.,0.), \n\
452 gp_Dir(0.,0.,1.)), \n\
453 40.,110.,210.*PI180.); \n\
454 \n");
455 PocessTextInDialog("Make a cylinder", Message);
456}
457
458
459void CModelingDoc::OnCone()
460{
461 AIS_ListOfInteractive aList;
462 myAISContext->DisplayedObjects(aList);
463 AIS_ListIteratorOfListOfInteractive aListIterator;
464 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 465 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 466 }
576f8b11 467 TopoDS_Shape C1 = BRepPrimAPI_MakeCone(50., 25., 200.).Shape();
7fd59977 468 Handle(AIS_Shape) ais1 = new AIS_Shape(C1);
469 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
470 myAISContext->SetColor(ais1,Quantity_NOC_MATRABLUE,Standard_False);
471 myAISContext->Display(ais1,Standard_False);
472 TopoDS_Shape C2 = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(100.,100.,0.),
576f8b11 473 gp_Dir(0.,0.,1.)),
474 60., 0., 150., 210.*M_PI / 180).Shape();
7fd59977 475 Handle(AIS_Shape) ais2 = new AIS_Shape(C2);
476 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
477 myAISContext->SetColor(ais2,Quantity_NOC_GREEN,Standard_False);
478 myAISContext->Display(ais2,Standard_False);
479 Fit();
480
481 TCollection_AsciiString Message ("\
482 \n\
483TopoDS_Shape C1 = BRepPrimAPI_MakeCone (50.,25.,200.); \n\
484TopoDS_Shape C2 = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(100.,100.,0.), \n\
485 gp_Dir(0.,0.,1.)), \n\
486 605.,0.,150.,210.*PI180); \n\
487 \n");
488 PocessTextInDialog("Make a cone", Message);
489}
490
491void CModelingDoc::OnSphere()
492{
493 AIS_ListOfInteractive aList;
494 myAISContext->DisplayedObjects(aList);
495 AIS_ListIteratorOfListOfInteractive aListIterator;
496 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 497 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 498 }
499
576f8b11 500 TopoDS_Shape S1 = BRepPrimAPI_MakeSphere(gp_Pnt(-200., -250., 0.), 80.).Shape();
7fd59977 501 Handle(AIS_Shape) ais1 = new AIS_Shape(S1);
502 myAISContext->SetColor(ais1,Quantity_NOC_AZURE,Standard_False);
503 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
504 myAISContext->Display(ais1,Standard_False);
576f8b11 505 TopoDS_Shape S2 = BRepPrimAPI_MakeSphere(100., 120.*M_PI / 180).Shape();
7fd59977 506 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
507 myAISContext->SetColor(ais2,Quantity_NOC_GREEN,Standard_False);
508 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
509 myAISContext->Display(ais2,Standard_False);
510 TopoDS_Shape S3 = BRepPrimAPI_MakeSphere(gp_Pnt(200.,250.,0.),100.,
576f8b11 511 -60.*M_PI / 180, 60.*M_PI / 180).Shape();
7fd59977 512 Handle(AIS_Shape) ais3 = new AIS_Shape(S3);
513 myAISContext->SetColor(ais3,Quantity_NOC_RED,Standard_False);
514 myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC,Standard_False);
515 myAISContext->Display(ais3,Standard_False);
516 TopoDS_Shape S4 = BRepPrimAPI_MakeSphere(gp_Pnt(0.,0.,-300.),150.,
576f8b11 517 -45.*M_PI / 180, 45.*M_PI / 180, 45.*M_PI / 180).Shape();
7fd59977 518 Handle(AIS_Shape) ais4 = new AIS_Shape(S4);
519 myAISContext->SetColor(ais4,Quantity_NOC_MATRABLUE,Standard_False);
520 myAISContext->SetMaterial(ais4,Graphic3d_NOM_PLASTIC,Standard_False);
521 myAISContext->Display(ais4,Standard_False);
522 Fit();
523
524 TCollection_AsciiString Message ("\
525 \n\
526TopoDS_Shape S1 = BRepPrimAPI_MakeSphere(gp_Pnt(-200.,-250.,0.),80.); \n\
527TopoDS_Shape S2 = BRepPrimAPI_MakeSphere(100.,120.*PI180); \n\
528TopoDS_Shape S3 = BRepPrimAPI_MakeSphere(gp_Pnt(200.,250.,0.),100., \n\
529 -60.*PI180, 60.*PI180); \n\
530TopoDS_Shape S4 = BRepPrimAPI_MakeSphere(gp_Pnt(0.,0.,-300.),150., \n\
531 -45.*PI180, 45.*PI180, 45.*PI180); \n\
532 \n");
533 PocessTextInDialog("Make a sphere", Message);
534}
535
536void CModelingDoc::OnTorus()
537{
538 AIS_ListOfInteractive aList;
539 myAISContext->DisplayedObjects(aList);
540 AIS_ListIteratorOfListOfInteractive aListIterator;
541 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 542 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 543 }
544
576f8b11 545 TopoDS_Shape S1 = BRepPrimAPI_MakeTorus(60., 20.).Shape();
7fd59977 546 Handle(AIS_Shape) ais1 = new AIS_Shape(S1);
547 myAISContext->SetColor(ais1,Quantity_NOC_AZURE,Standard_False);
548 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
549 myAISContext->Display(ais1,Standard_False);
550 TopoDS_Shape S2 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(1.,1.,1.)),
576f8b11 551 50., 20., 210.*M_PI / 180).Shape();
7fd59977 552 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
553 myAISContext->SetColor(ais2,Quantity_NOC_GREEN,Standard_False);
554 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
555 myAISContext->Display(ais2,Standard_False);
556 TopoDS_Shape S3 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(-200.,-150.,-100),gp_Dir(0.,1.,0.)),
576f8b11 557 60., 20., -45.*M_PI / 180, 45.*M_PI / 180, 90.*M_PI / 180).Shape();
7fd59977 558 Handle(AIS_Shape) ais3= new AIS_Shape(S3);
559 myAISContext->SetColor(ais3,Quantity_NOC_CORAL,Standard_False);
560 myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC,Standard_False);
561 myAISContext->Display(ais3,Standard_False);
562 Fit();
563
564 TCollection_AsciiString Message ("\
565 \n\
566TopoDS_Shape S1 = BRepPrimAPI_MakeTorus(60.,20.); \n\
567TopoDS_Shape S2 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(1.,1.,1.)), \n\
568 50.,20.,210.*PI180); \n\
569TopoDS_Shape S3 = BRepPrimAPI_MakeTorus(gp_Ax2(gp_Pnt(-200.,-150.,-100),gp_Dir(0.,1.,0.)), \n\
570 60.,20.,-45.*PI180,45.*PI180,90.*PI180); \n\
571 \n");
572 PocessTextInDialog("Make a torus", Message);
573}
574
575void CModelingDoc::OnWedge()
576{
577 AIS_ListOfInteractive aList;
578 myAISContext->DisplayedObjects(aList);
579 AIS_ListIteratorOfListOfInteractive aListIterator;
580 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 581 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 582 }
583
576f8b11 584 TopoDS_Shape S1 = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
7fd59977 585 Handle(AIS_Shape) ais1 = new AIS_Shape(S1);
586 myAISContext->SetColor(ais1,Quantity_NOC_AZURE,Standard_False);
587 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
588 myAISContext->Display(ais1,Standard_False);
589 TopoDS_Shape S2 = BRepPrimAPI_MakeWedge(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(0.,0.,1.)),
576f8b11 590 60., 50., 80., 25., -10., 40., 70.).Shape();
7fd59977 591 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
592 myAISContext->SetColor(ais2,Quantity_NOC_CORAL2,Standard_False);
593 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
594 myAISContext->Display(ais2,Standard_False);
595 Fit();
596
597 TCollection_AsciiString Message ("\
598 \n\
599TopoDS_Shape S1 = BRepPrimAPI_MakeWedge(60.,100.,80.,20.); \n\
600TopoDS_Shape S2 = BRepPrimAPI_MakeWedge(gp_Ax2(gp_Pnt(100.,100.,0.),gp_Dir(0.,0.,1.)), \n\
601 60.,50.,80.,25.,-10.,40.,70.); \n\
602 \n");
603 PocessTextInDialog("Make a wedge", Message);
604}
605
606void CModelingDoc::OnPrism()
607{
608 AIS_ListOfInteractive aList;
609 myAISContext->DisplayedObjects(aList);
610 AIS_ListIteratorOfListOfInteractive aListIterator;
611 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 612 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 613 }
614
615 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.));
616 Handle(AIS_Shape) ais1 = new AIS_Shape(V1);
617 myAISContext->Display(ais1,Standard_False);
618 TopoDS_Shape S1 = BRepPrimAPI_MakePrism(V1,gp_Vec(0.,0.,100.));
619 Handle(AIS_Shape) ais2 = new AIS_Shape(S1);
620 myAISContext->Display(ais2,Standard_False);
621
622 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-150.,-150,0.), gp_Pnt(-50.,-50,0.));
623 Handle(AIS_Shape) ais3 = new AIS_Shape(E);
624 myAISContext->Display(ais3,Standard_False);
625 TopoDS_Shape S2 = BRepPrimAPI_MakePrism(E,gp_Vec(0.,0.,100.));
626 Handle(AIS_Shape) ais4 = new AIS_Shape(S2);
627 myAISContext->SetColor(ais4,Quantity_NOC_CORAL2,Standard_False);
628 myAISContext->SetMaterial(ais4,Graphic3d_NOM_PLASTIC,Standard_False);
629 myAISContext->Display(ais4,Standard_False);
630
631 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.));
632 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.));
633 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.));
634 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3);
635 TopoDS_Shape S3 = BRepPrimAPI_MakePrism(W,gp_Vec(0.,0.,100.));
636 Handle(AIS_Shape) ais5 = new AIS_Shape(W);
637 myAISContext->Display(ais5,Standard_False);
638 Handle(AIS_Shape) ais6 = new AIS_Shape(S3);
639 myAISContext->SetColor(ais6,Quantity_NOC_GREEN,Standard_False);
640 myAISContext->SetMaterial(ais6,Graphic3d_NOM_PLASTIC,Standard_False);
641 myAISContext->Display(ais6,Standard_False);
642
643 gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.);
644 TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
645 TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
646 TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc);
647 Handle(AIS_Shape) ais7 = new AIS_Shape(F);
648 myAISContext->Display(ais7,Standard_False);
649 TopoDS_Shape S4 = BRepPrimAPI_MakePrism(F,gp_Vec(0.,0.,100.));
650 Handle(AIS_Shape) ais8 = new AIS_Shape(S4);
651 myAISContext->SetColor(ais8,Quantity_NOC_MATRABLUE,Standard_False);
652 myAISContext->SetMaterial(ais8,Graphic3d_NOM_PLASTIC,Standard_False);
653 myAISContext->Display(ais8,Standard_False);
654 Fit();
655
656 TCollection_AsciiString Message ("\
657 \n\
658--- Prism a vertex -> result is an edge --- \n\
659\n\
660TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.)); \n\
661TopoDS_Shape S1 = BRepBuilderAPI_MakePrism(V1,gp_Vec(0.,0.,100.)); \n\
662\n\
663--- Prism an edge -> result is a face --- \n\
664\n\
665TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-150.,-150,0.), gp_Pnt(-50.,-50,0.)); \n\
666TopoDS_Shape S2 = BRepPrimAPI_MakePrism(E,gp_Vec(0.,0.,100.)); \n\
667\n\
668--- Prism an wire -> result is a shell --- \n\
669\n\
670TopoDS_Edge E1 = BREpBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.)); \n\
671TopoDS_Edge E2 = BREpBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.)); \n\
672TopoDS_Edge E3 = BREpBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.)); \n\
673TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3); \n\
674TopoDS_Shape S3 = BRepPrimAPI_MakePrism(W,gp_Vec(0.,0.,100.)); \n\
675\n\
676--- Prism a face or a shell -> result is a solid --- \n\
677\n\
678gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.gp_Dir(0.,0.,1.)), 80.); \n\
679TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c); \n\
680TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec); \n\
681TopoDS_Face F = BRepBuilderAPI_MakeFace(gp::XOY(),Wc); \n\
682TopoDS_Shape S4 = BRepBuilderAPI_MakePrism(F,gp_Vec(0.,0.,100.)); \n\
683 \n");
684 PocessTextInDialog("Make a prism", Message);
685}
686
687void CModelingDoc::OnRevol()
688{
689 AIS_ListOfInteractive aList;
690 myAISContext->DisplayedObjects(aList);
691 AIS_ListIteratorOfListOfInteractive aListIterator;
692 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 693 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 694 }
695
696 TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.));
697 Handle(AIS_Shape) ais1 = new AIS_Shape(V1);
698 myAISContext->Display(ais1,Standard_False);
699 gp_Ax1 axe = gp_Ax1(gp_Pnt(-170.,-170.,0.),gp_Dir(0.,0.,1.));
700 Handle(Geom_Axis1Placement) Gax1 = new Geom_Axis1Placement(axe);
701 Handle (AIS_Axis) ax1 = new AIS_Axis(Gax1);
702 myAISContext->Display(ax1,Standard_False);
703 TopoDS_Shape S1 = BRepPrimAPI_MakeRevol(V1,axe);
704 Handle(AIS_Shape) ais2 = new AIS_Shape(S1);
705 myAISContext->Display(ais2,Standard_False);
706
707 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-120.,-120,0.), gp_Pnt(-120.,-120,100.));
708 Handle(AIS_Shape) ais3 = new AIS_Shape(E);
709 myAISContext->Display(ais3,Standard_False);
710 axe = gp_Ax1(gp_Pnt(-100.,-100.,0.),gp_Dir(0.,0.,1.));
711 Handle(Geom_Axis1Placement) Gax2 = new Geom_Axis1Placement(axe);
712 Handle (AIS_Axis) ax2 = new AIS_Axis(Gax2);
713 myAISContext->Display(ax2,Standard_False);
714 TopoDS_Shape S2 = BRepPrimAPI_MakeRevol(E,axe);
715 Handle(AIS_Shape) ais4 = new AIS_Shape(S2);
716 myAISContext->SetColor(ais4,Quantity_NOC_YELLOW,Standard_False);
717 myAISContext->SetMaterial(ais4,Graphic3d_NOM_PLASTIC,Standard_False);
718 myAISContext->Display(ais4,Standard_False);
719
720 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.));
721 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.));
722 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.));
723 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3);
724 axe = gp_Ax1(gp_Pnt(0.,0.,30.),gp_Dir(0.,1.,0.));
725 Handle(Geom_Axis1Placement) Gax3 = new Geom_Axis1Placement(axe);
726 Handle (AIS_Axis) ax3 = new AIS_Axis(Gax3);
727 myAISContext->Display(ax3,Standard_False);
42e4630c 728 TopoDS_Shape S3 = BRepPrimAPI_MakeRevol(W,axe, 210.*M_PI/180);
7fd59977 729 Handle(AIS_Shape) ais5 = new AIS_Shape(W);
730 myAISContext->Display(ais5,Standard_False);
731 Handle(AIS_Shape) ais6 = new AIS_Shape(S3);
732 myAISContext->SetColor(ais6,Quantity_NOC_GREEN,Standard_False);
733 myAISContext->SetMaterial(ais6,Graphic3d_NOM_PLASTIC,Standard_False);
734 myAISContext->Display(ais6,Standard_False);
735
736 gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.);
737 TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
738 TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
739 TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc);
740 axe = gp_Ax1(gp_Pnt(290,290.,0.),gp_Dir(0.,1,0.));
741 Handle(Geom_Axis1Placement) Gax4 = new Geom_Axis1Placement(axe);
742 Handle (AIS_Axis) ax4 = new AIS_Axis(Gax4);
743 myAISContext->Display(ax4,Standard_False);
42e4630c 744 TopoDS_Shape S4 = BRepPrimAPI_MakeRevol(F,axe, 90.*M_PI/180);
7fd59977 745 Handle(AIS_Shape) ais8 = new AIS_Shape(S4);
746 myAISContext->SetColor(ais8,Quantity_NOC_MATRABLUE,Standard_False);
747 myAISContext->SetMaterial(ais8,Graphic3d_NOM_PLASTIC,Standard_False);
748 myAISContext->Display(ais8,Standard_False);
749 Fit();
750
751 TCollection_AsciiString Message ("\
752 \n\
753--- Revol of a vertex -> result is an edge --- \n\
754\n\
755TopoDS_Vertex V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-200.,-200.,0.)); \n\
756gp_Ax1 axe = gp_Ax1(gp_Pnt(-170.,-170.,0.),gp_Dir(0.,0.,1.)); \n\
757TopoDS_Shape S1 = BRepPrimAPI_MakeRevol(V1,axe); \n\
758\n\
759--- Revol of an edge -> result is a face --- \n\
760\n\
761TopoDS_Edge E = BRepBuilderAPI_MakeEdge(gp_Pnt(-120.,-120,0.), gp_Pnt(-120.,-120,100.)); \n\
762axe = gp_Ax1(gp_Pnt(-100.,-100.,0.),gp_Dir(0.,0.,1.)); \n\
763TopoDS_Shape S2 = BRepPrimAPI_MakeRevol(E,axe); \n\
764\n\
765--- Revol of a wire -> result is a shell --- \n\
766\n\
767TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,0.,0.), gp_Pnt(50.,0.,0.)); \n\
768TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,0.,0.), gp_Pnt(50.,50.,0.)); \n\
769TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(50.,50.,0.), gp_Pnt(0.,0.,0.)); \n\
770TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3); \n\
771axe = gp_Ax1(gp_Pnt(0.,0.,30.),gp_Dir(0.,1.,0.)); \n\
772TopoDS_Shape S3 = BRepPrimAPI_MakeRevol(W,axe, 210.*PI180); \n\
773\n\
774--- Revol of a face -> result is a solid --- \n\
775\n\
776gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.),gp_Dir(0.,0.,1.)), 80.); \n\
777TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c); \n\
778TopoDS_Wire Wc = BRepBuilderPI_MakeWire(Ec); \n\
779TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()),Wc); \n\
780axe = gp_Ax1(gp_Pnt(290,290.,0.),gp_Dir(0.,1,0.)); \n\
781TopoDS_Shape S4 = BRepPrimAPI_MakeRevol(F,axe, 90.*PI180); \n\
782 \n");
3f23e6ac 783 PocessTextInDialog("Make a revol", Message);
7fd59977 784}
785
786void CModelingDoc::OnPipe()
787{
788 AIS_ListOfInteractive aList;
789 myAISContext->DisplayedObjects(aList);
790 AIS_ListIteratorOfListOfInteractive aListIterator;
791 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 792 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 793 }
794
795 TColgp_Array1OfPnt CurvePoles(1,4);
796 gp_Pnt pt = gp_Pnt(0.,0.,0.);
797 CurvePoles(1) = pt;
798 pt = gp_Pnt(20.,50.,0.);
799 CurvePoles(2) = pt;
800 pt = gp_Pnt(60.,100.,0.);
801 CurvePoles(3) = pt;
802 pt = gp_Pnt(150.,0.,0.);
803 CurvePoles(4) = pt;
804 Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);
805 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
806 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);
807 Handle(AIS_Shape) ais1 = new AIS_Shape(W);
808 myAISContext->Display(ais1,Standard_False);
809 Fit();
810 Sleep(500);
811 gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.);
812 TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
813 TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
814 Handle(AIS_Shape) ais3 = new AIS_Shape(Wc);
815 myAISContext->Display(ais3,Standard_False);
816 TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::ZOX()),Wc);
817 TopoDS_Shape S = BRepOffsetAPI_MakePipe(W,F);
818 Handle(AIS_Shape) ais2 = new AIS_Shape(S);
819 myAISContext->SetColor(ais2,Quantity_NOC_MATRABLUE,Standard_False);
820 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
821 myAISContext->Display(ais2,Standard_False);
822 Fit();
823
824 TCollection_AsciiString Message ("\
825 \n\
826TColgp_Array1OfPnt CurvePoles(1,6);\n\
827gp_Pnt pt = gp_Pnt(0.,0.,0.);\n\
828CurvePoles(1) = pt;\n\
829pt = gp_Pnt(20.,50.,0.);\n\
830CurvePoles(2) = pt;\n\
831pt = gp_Pnt(60.,100.,0.);\n\
832CurvePoles(3) = pt;\n\
833pt = gp_Pnt(150.,0.,0.);\n\
834CurvePoles(4) = pt;\n\
835Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);\n\
836TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);\n\
837TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);\n\
838gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(0.,0.,0.),gp_Dir(0.,1.,0.)),10.);\n\
839TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);\n\
840TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);\n\
841TopoDS_Face F = BRepBuilderAPI_MakeFace(gp_Pln(gp::ZOX()),Wc);\n\
842TopoDS_Shape S = BRepBuilderAPI_MakePipe(W,F);\n\
843 \n");
576f8b11 844 PocessTextInDialog("Make a pipe", Message);
7fd59977 845
846}
847
848void CModelingDoc::OnThru()
849{
850 AIS_ListOfInteractive aList;
851 myAISContext->DisplayedObjects(aList);
852 AIS_ListIteratorOfListOfInteractive aListIterator;
853 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 854 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 855 }
856
857 gp_Circ c1 = gp_Circ(gp_Ax2(gp_Pnt(-100.,0.,-100.),gp_Dir(0.,0.,1.)),40.);
858 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(c1);
859 TopoDS_Wire W1 = BRepBuilderAPI_MakeWire(E1);
860 Handle(AIS_Shape) sec1 = new AIS_Shape(W1);
861 myAISContext->Display(sec1,Standard_False);
862 gp_Circ c2 = gp_Circ(gp_Ax2(gp_Pnt(-10.,0.,-0.),gp_Dir(0.,0.,1.)),40.);
863 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(c2);
864 TopoDS_Wire W2 = BRepBuilderAPI_MakeWire(E2);
865 Handle(AIS_Shape) sec2 = new AIS_Shape(W2);
866 myAISContext->Display(sec2,Standard_False);
867 gp_Circ c3 = gp_Circ(gp_Ax2(gp_Pnt(-75.,0.,100.),gp_Dir(0.,0.,1.)),40.);
868 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(c3);
869 TopoDS_Wire W3 = BRepBuilderAPI_MakeWire(E3);
870 Handle(AIS_Shape) sec3 = new AIS_Shape(W3);
871 myAISContext->Display(sec3,Standard_False);
872 gp_Circ c4= gp_Circ(gp_Ax2(gp_Pnt(0.,0.,200.),gp_Dir(0.,0.,1.)),40.);
873 TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(c4);
874 TopoDS_Wire W4 = BRepBuilderAPI_MakeWire(E4);
875 Handle(AIS_Shape) sec4 = new AIS_Shape(W4);
876 myAISContext->Display(sec4,Standard_False);
877 BRepOffsetAPI_ThruSections generator(Standard_False,Standard_True);
878 generator.AddWire(W1);
879 generator.AddWire(W2);
880 generator.AddWire(W3);
881 generator.AddWire(W4);
882 generator.Build();
883 TopoDS_Shape S1 = generator.Shape();
884 Handle(AIS_Shape) ais1 = new AIS_Shape(S1);
885 myAISContext->SetColor(ais1,Quantity_NOC_MATRABLUE,Standard_False);
886 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
887 myAISContext->Display(ais1,Standard_False);
888
889 gp_Circ c1b = gp_Circ(gp_Ax2(gp_Pnt(100.,0.,-100.),gp_Dir(0.,0.,1.)),40.);
890 TopoDS_Edge E1b = BRepBuilderAPI_MakeEdge(c1b);
891 TopoDS_Wire W1b = BRepBuilderAPI_MakeWire(E1b);
892 Handle(AIS_Shape) sec1b = new AIS_Shape(W1b);
893 myAISContext->Display(sec1b,Standard_False);
894 gp_Circ c2b = gp_Circ(gp_Ax2(gp_Pnt(210.,0.,-0.),gp_Dir(0.,0.,1.)),40.);
895 TopoDS_Edge E2b = BRepBuilderAPI_MakeEdge(c2b);
896 TopoDS_Wire W2b = BRepBuilderAPI_MakeWire(E2b);
897 Handle(AIS_Shape) sec2b = new AIS_Shape(W2b);
898 myAISContext->Display(sec2b,Standard_False);
899 gp_Circ c3b = gp_Circ(gp_Ax2(gp_Pnt(275.,0.,100.),gp_Dir(0.,0.,1.)),40.);
900 TopoDS_Edge E3b = BRepBuilderAPI_MakeEdge(c3b);
901 TopoDS_Wire W3b = BRepBuilderAPI_MakeWire(E3b);
902 Handle(AIS_Shape) sec3b = new AIS_Shape(W3b);
903 myAISContext->Display(sec3b,Standard_False);
904 gp_Circ c4b= gp_Circ(gp_Ax2(gp_Pnt(200.,0.,200.),gp_Dir(0.,0.,1.)),40.);
905 TopoDS_Edge E4b = BRepBuilderAPI_MakeEdge(c4b);
906 TopoDS_Wire W4b = BRepBuilderAPI_MakeWire(E4b);
907 Handle(AIS_Shape) sec4b = new AIS_Shape(W4b);
908 myAISContext->Display(sec4b,Standard_False);
909 BRepOffsetAPI_ThruSections generatorb(Standard_True,Standard_False);
910 generatorb.AddWire(W1b);
911 generatorb.AddWire(W2b);
912 generatorb.AddWire(W3b);
913 generatorb.AddWire(W4b);
914 generatorb.Build();
915 TopoDS_Shape S2 = generatorb.Shape();
916 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
917 myAISContext->SetColor(ais2,Quantity_NOC_ALICEBLUE,Standard_False);
918 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
919 myAISContext->Display(ais2,Standard_False);
920 Fit();
921
922 TCollection_AsciiString Message ("\
923 \n\
924---------- ruled -------------- \n\
925\n\
926gp_Circ c1 = gp_Circ(gp_Ax2(gp_Pnt(-100.,0.,-100.),gp_Dir(0.,0.,1.)),40.);\n\
927TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(c1);\n\
928TopoDS_Wire W1 = BRepBuilderAPI_MakeWire(E1);\n\
929gp_Circ c2 = gp_Circ(gp_Ax2(gp_Pnt(-10.,0.,-0.),gp_Dir(0.,0.,1.)),40.);\n\
930TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(c2);\n\
931TopoDS_Wire W2 = BRepBuilderAPI_MakeWire(E2);\n\
932gp_Circ c3 = gp_Circ(gp_Ax2(gp_Pnt(-75.,0.,100.),gp_Dir(0.,0.,1.)),40.);\n\
933TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(c3);\n\
934TopoDS_Wire W3 = BRepBuilderAPI_MakeWire(E3);\n\
935gp_Circ c4= gp_Circ(gp_Ax2(gp_Pnt(0.,0.,200.),gp_Dir(0.,0.,1.)),40.);\n\
936TopoDS_Edge E4 = BRep>BuilderAPI_MakeEdge(c4);\n\
937TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(c4);\n\
938TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(c4);\n\
939TopoDS_Wire W4 = BRepBuilderAPI_MakeWire(E4);\n\
940BRepOffsetAPI_ThruSections generator(Standard_False,Standard_True);\n\
941generator.AddWire(W1);\n\
942generator.AddWire(W2);\n\
943generator.AddWire(W3);\n\
944generator.AddWire(W4);\n\
945generator.Build();\n\
946TopoDS_Shape S1 = generator.Shape();\n\
947\n\
948---------- smooth -------------- \n\
949\n\
950gp_Circ c1b = gp_Circ(gp_Ax2(gp_Pnt(100.,0.,-100.),gp_Dir(0.,0.,1.)),40.); \n\
951TopoDS_Edge E1b = BRepBuilderAPI_MakeEdge(c1b); \n\
952TopoDS_Wire W1b = BRepBuilderAPI_MakeWire(E1b); \n\
953gp_Circ c2b = gp_Circ(gp_Ax2(gp_Pnt(210.,0.,-0.),gp_Dir(0.,0.,1.)),40.); \n\
954TopoDS_Edge E2b = BRepBuilderAPI_MakeEdge(c2b);\n\
955TopoDS_Wire W2b = BRepBuilderAPI_MakeWire(E2b); \n\
956gp_Circ c3b = gp_Circ(gp_Ax2(gp_Pnt(275.,0.,100.),gp_Dir(0.,0.,1.)),40.);\n\
957TopoDS_Edge E3b = BRepBuilderAPI_MakeEdge(c3b);\n\
958TopoDS_Wire W3b = BRepBuilderAPI_MakeWire(E3b);\n\
959gp_Circ c4b= gp_Circ(gp_Ax2(gp_Pnt(200.,0.,200.),gp_Dir(0.,0.,1.)),40.);\n\
960TopoDS_Edge E4b = BRepBuilderAPI_MakeEdge(c4b);\n\
961TopoDS_Wire W4b = BRepBuilderAPI_MakeWire(E4b);\n\
962BRepOffsetAPI_ThruSections generatorb(Standard_True,Standard_False);\n\
963generatorb.AddWire(W1b);\n\
964generatorb.AddWire(W2b);\n\
965generatorb.AddWire(W3b);\n\
966generatorb.AddWire(W4b);\n\
967generatorb.Build();\n\
968TopoDS_Shape S2 = generatorb.Shape();\n\
969 \n");
576f8b11 970 PocessTextInDialog("Make a Thru sections", Message);
7fd59977 971
972}
973
974void CModelingDoc::OnEvolved()
975{
976 AIS_ListOfInteractive aList;
977 myAISContext->DisplayedObjects(aList);
978 AIS_ListIteratorOfListOfInteractive aListIterator;
979 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 980 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 981 }
982
983 BRepBuilderAPI_MakePolygon P;
984 P.Add(gp_Pnt(0.,0.,0.));
985 P.Add(gp_Pnt(200.,0.,0.));
986 P.Add(gp_Pnt(200.,200.,0.));
987 P.Add(gp_Pnt(0.,200.,0.));
988 P.Add(gp_Pnt(0.,0.,0.));
989 TopoDS_Wire W = P.Wire();
990
991 Handle(AIS_Shape) ais1 = new AIS_Shape(W);
992 myAISContext->Display(ais1,Standard_False);
993
994 TopoDS_Wire wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0.,0.,0.),gp_Pnt(-60.,-60.,-200.));
995
996 Handle(AIS_Shape) ais3 = new AIS_Shape(wprof);
997 myAISContext->Display(ais3,Standard_False);
998 Fit();
999 Sleep(500);
1000 TopoDS_Shape S = BRepOffsetAPI_MakeEvolved(W,wprof,GeomAbs_Arc,Standard_True,Standard_False,Standard_True,0.0001);
1001
1002 Handle(AIS_Shape) ais2 = new AIS_Shape(S);
1003 myAISContext->SetColor(ais2,Quantity_NOC_MATRABLUE,Standard_False);
1004 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
1005 myAISContext->Display(ais2,Standard_False);
1006 Fit();
1007
1008 TCollection_AsciiString Message ("\
1009 \n\
1010---------- Evolved shape -------------- \n\
1011\n\
1012BRepBuilderAPI_MakePolygon P;\n\
1013P.Add(gp_Pnt(0.,0.,0.));\n\
1014P.Add(gp_Pnt(200.,0.,0.));\n\
1015P.Add(gp_Pnt(200.,200.,0.));\n\
1016P.Add(gp_Pnt(0.,200.,0.));\n\
1017P.Add(gp_Pnt(0.,0.,0.));\n\
1018TopoDS_Wire W = P.Wire();\n\
1019TopoDS_Wire wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0.,0.,0.),gp_Pnt(-60.,-60.,-200.));\n\
1020TopoDS_Shape S = BRepBuilderAPI_MakeEvolved(W,wprof,GeomAbs_Arc,Standard_True,Standard_False,Standard_True,0.0001);\n\
1021 \n");
1022 PocessTextInDialog("Make an evolved shape", Message);
1023
1024}
1025
1026void CModelingDoc::OnDraft()
1027{
1028 AIS_ListOfInteractive aList;
1029 myAISContext->DisplayedObjects(aList);
1030 AIS_ListIteratorOfListOfInteractive aListIterator;
1031 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1032 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1033 }
1034
576f8b11 1035 TopoDS_Shape S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape();
7fd59977 1036 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
1037 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
1038 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1039 myAISContext->Display(ais1,Standard_False);
1040 Fit();
1041 Sleep(500);
1042 BRepOffsetAPI_DraftAngle adraft(S);
1043 TopExp_Explorer Ex;
1044 for (Ex.Init(S,TopAbs_FACE); Ex.More(); Ex.Next()) {
1045 TopoDS_Face F = TopoDS::Face(Ex.Current());
1046 Handle(Geom_Plane) surf = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F));
1047 gp_Pln apln = surf->Pln();
1048 gp_Dir dirF = apln.Axis().Direction();
1049 if (dirF.IsNormal(gp_Dir(0.,0.,1.),Precision::Angular()))
42e4630c 1050 adraft.Add(F, gp_Dir(0.,0.,1.), 15.*M_PI/180, gp_Pln(gp::XOY()));
7fd59977 1051 }
1052 ais1->Set(adraft.Shape());
1053 myAISContext->Redisplay(ais1,Standard_False);
1054 Fit();
1055
1056 TCollection_AsciiString Message ("\
1057 \n\
1058---------- Tapered shape -------------- \n\
1059\n\
1060TopoDS_Shape S = BRepPrimAPI_MakeBox(200.,300.,150.);\n\
1061BRepOffsetAPI_DraftAngle adraft(S);\n\
1062TopExp_Explorer Ex;\n\
1063for (Ex.Init(S,TopAbs_FACE); Ex.More(); Ex.Next()) {\n\
1064 TopoDS_Face F = TopoDS::Face(Ex.Current());\n\
1065 Handle(Geom_Plane) surf = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(F));\n\
1066 gp_Pln apln = surf->Pln();\n\
1067 gp_Dir dirF = apln.Axis().Direction();\n\
1068 if (dirF.IsNormal(gp_Dir(0.,0.,1.),Precision::Angular()))\n\
1069 adraft.Add(F, gp_Dir(0.,0.,1.), 15.*PI180, gp_Pln(gp::XOY()));\n\
1070}\n\
1071 \n");
576f8b11 1072 PocessTextInDialog("Make a tapered shape", Message);
7fd59977 1073
1074}
1075
1076/* =================================================================================
1077 ==================== O P E R A T I O N S ====================================
1078 ================================================================================= */
1079
1080void CModelingDoc::OnCut()
1081{
1082 AIS_ListOfInteractive aList;
1083 myAISContext->DisplayedObjects(aList);
1084 AIS_ListIteratorOfListOfInteractive aListIterator;
1085 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1086 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1087 }
1088
576f8b11 1089 TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape();
7fd59977 1090
1091Handle (AIS_Shape) ais1 = new AIS_Shape(theBox);
1092myAISContext->SetDisplayMode(ais1,1,Standard_False);
1093myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
1094myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1095myAISContext->Display(ais1,Standard_False);
404c8936 1096const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1097myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1098Fit();
1099Sleep(1000);
1100
1101
576f8b11 1102TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape();
7fd59977 1103Handle (AIS_Shape) ais2 = new AIS_Shape(theSphere);
1104myAISContext->SetDisplayMode(ais2,1,Standard_False);
1105myAISContext->SetColor(ais2,Quantity_NOC_YELLOW,Standard_False);
1106myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
1107myAISContext->Display(ais2,Standard_False);
404c8936 1108const Handle(AIS_InteractiveObject)& anIO2 = ais2;
1109myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 1110Fit();
1111Sleep(1000);
1112
1113TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere,theBox);
1114
eb4320f2 1115myAISContext->Erase(ais1,Standard_False);
1116myAISContext->Erase(ais2,Standard_False);
7fd59977 1117
1118Handle (AIS_Shape) aSection = new AIS_Shape(ShapeCut);
1119myAISContext->SetDisplayMode(aSection,1,Standard_False);
1120myAISContext->SetColor(aSection,Quantity_NOC_RED,Standard_False);
1121myAISContext->SetMaterial(aSection,Graphic3d_NOM_PLASTIC,Standard_False);
1122myAISContext->Display(aSection,Standard_False);
404c8936 1123const Handle(AIS_InteractiveObject)& anIOSection = aSection;
1124myAISContext->SetSelected (anIOSection, Standard_False);
7fd59977 1125Fit();
1126
1127 TCollection_AsciiString Message ("\
1128 \n\
1129TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,40,40); \n\
1130 \n\
1131TopoDS_Shape theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100,20,20),80); \n\
1132 \n\
1133TopoDS_Shape ShapeCut = BRepAlgoAPI_Cut(theSphere,theBox); \n\
1134 \n");
1135 PocessTextInDialog("Cut the sphere with a box", Message);
1136
1137
1138}
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149void CModelingDoc::OnFuse()
1150{
1151 AIS_ListOfInteractive aList;
1152 myAISContext->DisplayedObjects(aList);
1153 AIS_ListIteratorOfListOfInteractive aListIterator;
1154 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1155 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1156 }
1157
1158gp_Pnt P(-5,5,-5);
576f8b11 1159TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(60, 200, 70).Shape();
7fd59977 1160Handle (AIS_Shape) ais1 = new AIS_Shape(theBox1);
1161myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
1162myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1163myAISContext->Display(ais1,Standard_False);
404c8936 1164const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1165myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1166Fit();
1167Sleep(1000);
1168
576f8b11 1169TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P, 20, 150, 110).Shape();
7fd59977 1170Handle (AIS_Shape) ais2 = new AIS_Shape(theBox2);
1171myAISContext->SetColor(ais2,Quantity_NOC_YELLOW,Standard_False);
1172myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
1173myAISContext->Display(ais2,Standard_False);
404c8936 1174const Handle(AIS_InteractiveObject)& anIO2 = ais2;
1175myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 1176Fit();
1177Sleep(1000);
1178
1179TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theBox1,theBox2);
1180
eb4320f2 1181myAISContext->Erase(ais1,Standard_True);
1182myAISContext->Erase(ais2,Standard_True);
7fd59977 1183
1184Handle (AIS_Shape) aFusion = new AIS_Shape(FusedShape);
1185myAISContext->SetDisplayMode(aFusion,1,Standard_False);
1186myAISContext->SetColor(aFusion,Quantity_NOC_RED,Standard_False);
1187myAISContext->SetMaterial(aFusion,Graphic3d_NOM_PLASTIC,Standard_False);
1188myAISContext->Display(aFusion,Standard_False);
404c8936 1189const Handle(AIS_InteractiveObject)& anIOFusion = aFusion;
1190myAISContext->SetSelected (anIOFusion, Standard_False);
7fd59977 1191Fit();
1192
1193 TCollection_AsciiString Message ("\
1194 \n\
1195TopoDS_Shape theBox1 = BRepPrimAPI_MakeBox(50,200,70); \n\
1196 \n\
1197TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(-30,150,70); \n\
1198 \n\
1199TopoDS_Shape FusedShape = BRepAlgoAPI_Fuse(theBox1,theBox2); \n");
1200 PocessTextInDialog("Fuse the boxes", Message);
1201
1202}
1203
1204void CModelingDoc::OnCommon()
1205{
1206 AIS_ListOfInteractive aList;
1207 myAISContext->DisplayedObjects(aList);
1208 AIS_ListIteratorOfListOfInteractive aListIterator;
1209 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1210 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1211 }
1212
1213gp_Ax2 axe(gp_Pnt(10,10,10),gp_Dir(1,2,1));
576f8b11 1214TopoDS_Shape theBox = BRepPrimAPI_MakeBox(axe, 60, 80, 100).Shape();
7fd59977 1215
1216Handle(AIS_Shape) aboxshape=new AIS_Shape(theBox);
1217myAISContext->SetColor(aboxshape,Quantity_NOC_YELLOW,Standard_False);
1218myAISContext->SetMaterial(aboxshape,Graphic3d_NOM_PLASTIC,Standard_False);
1219myAISContext->SetDisplayMode(aboxshape,1,Standard_False);
1220myAISContext->SetTransparency(aboxshape,0.2,Standard_False);
1221myAISContext->Display(aboxshape,Standard_False);
404c8936 1222const Handle(AIS_InteractiveObject)& anIOBoxShape = aboxshape;
1223myAISContext->SetSelected (anIOBoxShape, Standard_False);
7fd59977 1224Fit();
1225Sleep(500);
1226
576f8b11 1227TopoDS_Shape theWedge = BRepPrimAPI_MakeWedge(60., 100., 80., 20.).Shape();
7fd59977 1228
1229Handle(AIS_Shape) awedge = new AIS_Shape(theWedge);
1230myAISContext->SetColor(awedge,Quantity_NOC_RED,Standard_False);
1231myAISContext->SetMaterial(awedge,Graphic3d_NOM_PLASTIC,Standard_False);
1232myAISContext->SetTransparency(awedge,0.0,Standard_False);
1233myAISContext->Display(awedge,Standard_False);
404c8936 1234const Handle(AIS_InteractiveObject)& anIOWedge = awedge;
1235myAISContext->SetSelected (anIOWedge, Standard_False);
7fd59977 1236Fit();
1237Sleep(500);
1238
1239TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(theBox,theWedge);
1240
eb4320f2 1241myAISContext->Erase(aboxshape,Standard_True);
1242myAISContext->Erase(awedge,Standard_True);
7fd59977 1243
1244Handle(AIS_Shape) acommon = new AIS_Shape(theCommonSurface);
1245myAISContext->SetColor(acommon,Quantity_NOC_GREEN,Standard_False);
1246myAISContext->SetMaterial(acommon,Graphic3d_NOM_PLASTIC,Standard_False);
1247myAISContext->Display(acommon,Standard_False);
404c8936 1248const Handle(AIS_InteractiveObject)& anIOCommon = acommon;
1249myAISContext->SetSelected (anIOCommon, Standard_False);
7fd59977 1250
1251 TCollection_AsciiString Message ("\
1252 \n\
1253gp_Ax2 axe(gp_Pnt(10,10,10),gp_Dir(1,2,1)); \n\
1254 \n\
1255TopoDS_Shape theBox = BRepPrimAPI_MakeBox(axe,60,80,100); \n\
1256 \n\
1257TopoDS_Shape theWedge = BRepPrimAPI_MakeWedge(60.,100.,80.,20.); \n\
1258 \n\
1259TopoDS_Shape theCommonSurface = BRepAlgoAPI_Common(theBox,theWedge); \n\
1260 \n");
1261
1262 PocessTextInDialog("Compute the common surface ", Message);
1263
1264}
1265
1266void CModelingDoc::OnSection()
1267{
1268
1269 AIS_ListOfInteractive aList;
1270 myAISContext->DisplayedObjects(aList);
1271 AIS_ListIteratorOfListOfInteractive aListIterator;
1272 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1273 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1274 }
1275
576f8b11 1276 TopoDS_Shape atorus = BRepPrimAPI_MakeTorus(120, 20).Shape();
7fd59977 1277
1278 Handle(AIS_Shape) ashape=new AIS_Shape(atorus);
1279 myAISContext->SetColor(ashape,Quantity_NOC_RED,Standard_False);
1280 myAISContext->SetMaterial(ashape,Graphic3d_NOM_PLASTIC,Standard_False);
1281 myAISContext->SetDisplayMode(ashape,1,Standard_False);
1282 myAISContext->SetTransparency(ashape,0.1,Standard_False);
1283 myAISContext->Display(ashape,Standard_False);
1284
1285gp_Vec V1(1,1,1);
1286Standard_Real radius = 120;
1287Standard_Integer i=-3;
1288
1289for(i;i<=3;i++) {
576f8b11 1290 TopoDS_Shape asphere = BRepPrimAPI_MakeSphere(gp_Pnt(26 * 3 * i, 0, 0), radius).Shape();
7fd59977 1291
1292 Handle (AIS_Shape) theShape=new AIS_Shape (asphere);
1293 myAISContext->SetTransparency(theShape,0.1,Standard_False);
1294 myAISContext->SetColor(theShape,Quantity_NOC_WHITE,Standard_False);
1295 myAISContext->SetDisplayMode(theShape,1,Standard_False);
1296 myAISContext->Display(theShape,Standard_False);
1297 Fit();
1298
1299 Standard_Boolean PerformNow=Standard_False;
1300
1301 BRepAlgoAPI_Section section(atorus,asphere,PerformNow);
1302 section.ComputePCurveOn1(Standard_True);
1303 section.Approximation(TopOpeBRepTool_APPROX);
1304 section.Build();
1305
1306 Handle(AIS_Shape) asection=new AIS_Shape(section.Shape());
0577ae8c 1307 myAISContext->SetDisplayMode (asection, 0, Standard_False);
1308 myAISContext->SetColor (asection, Quantity_NOC_WHITE, Standard_False);
1309 myAISContext->Display (asection, Standard_False);
7fd59977 1310 if(i<3) {
0577ae8c 1311 myAISContext->Remove (theShape, Standard_False);
7fd59977 1312 }
1313}
0577ae8c 1314 myAISContext->UpdateCurrentViewer();
7fd59977 1315 TCollection_AsciiString Message ("\
1316 \n\
1317TopoDS_Shape atorus = BRepPrimAPI_MakeTorus(120,20); \n\
1318gp_Vec V1(1,1,1); \n\
1319Standard_Real radius = 120; \n\
1320Standard_Integer i=-3; \n\
1321for(i;i<=3;i++) { \n\
1322 TopoDS_Shape asphere = BRepPrimAPI_MakeSphere(gp_Pnt(78*i,0,0),radius); \n\
1323 Standard_Boolean PerformNow=Standard_False; \n\
1324 BRepAlgoAPI_Section section(atorus,asphere,PerformNow); \n\
1325 section.ComputePCurveOn1(Standard_True); \n\
1326 section.Approximation(TopOpeBRepTool_APPROX); \n\
1327 section.Build(); \n\
1328 \n");
1329
1330 PocessTextInDialog("Compute the sections ", Message);
1331
1332}
1333
1334void CModelingDoc::OnPsection()
1335{
1336 AIS_ListOfInteractive aList;
1337 myAISContext->DisplayedObjects(aList);
1338 AIS_ListIteratorOfListOfInteractive aListIterator;
1339 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1340 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1341 }
1342
576f8b11 1343TopoDS_Shape theTorus = BRepPrimAPI_MakeTorus(35, 8).Shape();
7fd59977 1344Handle(AIS_Shape) atorus = new AIS_Shape(theTorus);
1345myAISContext->SetColor(atorus,Quantity_NOC_YELLOW,Standard_False);
1346myAISContext->SetMaterial(atorus,Graphic3d_NOM_PLASTIC,Standard_False);
1347myAISContext->SetTransparency(atorus,0.1,Standard_False);
1348myAISContext->Display(atorus,Standard_False);
404c8936 1349const Handle(AIS_InteractiveObject)& anIOTorus = atorus;
1350myAISContext->SetSelected (anIOTorus, Standard_False);
7fd59977 1351Fit();
1352Sleep(500);
1353
1354gp_Pln aplane(1,0.25,3,4);
1355Handle (Geom_Plane) thePlane = new Geom_Plane(aplane);
1356Handle (AIS_Plane) ais1 = new AIS_Plane(thePlane);
1357myAISContext->Display(ais1,Standard_False);
404c8936 1358const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1359myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1360Fit();
1361Sleep(300);
1362
1363BRepAlgoAPI_Section section(theTorus,thePlane,Standard_False);
1364section.ComputePCurveOn1(Standard_True);
1365section.Approximation(TopOpeBRepTool_APPROX);
1366section.Build();
1367
1368Handle(AIS_Shape) asection=new AIS_Shape(section.Shape());
1369myAISContext->SetDisplayMode(asection ,0,Standard_False);
1370myAISContext->SetColor(asection,Quantity_NOC_WHITE,Standard_False);
1371myAISContext->Display(asection,Standard_False);
1372Fit();
1373
1374 TCollection_AsciiString Message ("\
1375 \n\
1376TopoDS_Shape theTorus = BRepPrimAPI_MakeTorus(60.,20.); \n\
1377 \n\
1378gp_Pln P(1,2,1,-15); \n\
1379 \n\
1380TopoDS_Shape Psection = BRepAlgoAPI_Section(theTorus,P); \n\
1381\n");
1382
1383 PocessTextInDialog("Compute the plane section ", Message);
1384
1385}
1386
1387void CModelingDoc::OnBlend()
1388{
1389 AIS_ListOfInteractive aList;
1390 myAISContext->DisplayedObjects(aList);
1391 AIS_ListIteratorOfListOfInteractive aListIterator;
1392 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1393 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1394 }
1395
576f8b11 1396TopoDS_Shape Box = BRepPrimAPI_MakeBox(gp_Pnt(-400,0,0),200,230,180).Shape();
7fd59977 1397Handle(AIS_Shape) ais1 = new AIS_Shape(Box);
1398myAISContext->SetColor(ais1,Quantity_NOC_YELLOW,Standard_False);
1399myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1400myAISContext->Display(ais1,Standard_False);
404c8936 1401const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1402myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1403Fit();
1404Sleep(500);
1405
1406BRepFilletAPI_MakeFillet fillet(Box);
1407
1408for (TopExp_Explorer ex(Box,TopAbs_EDGE); ex.More(); ex.Next()) {
1409 TopoDS_Edge Edge =TopoDS::Edge(ex.Current());
1410 fillet.Add(20,Edge);
1411}
1412
1413myAISContext->Remove(ais1,Standard_False);
1414
1415TopoDS_Shape blendedBox = fillet.Shape();
1416Handle(AIS_Shape) aBlendbox = new AIS_Shape(blendedBox);
1417myAISContext->SetColor(aBlendbox,Quantity_NOC_YELLOW,Standard_False);
1418myAISContext->SetMaterial(aBlendbox,Graphic3d_NOM_PLASTIC,Standard_False);
1419myAISContext->Display(aBlendbox,Standard_False);
404c8936 1420const Handle(AIS_InteractiveObject)& anIOBlendBox = aBlendbox;
1421myAISContext->SetSelected (anIOBlendBox, Standard_False);
7fd59977 1422Fit();
1423Sleep(500);
1424
1425
1426gp_Pnt P1(250,150,75);
576f8b11 1427TopoDS_Shape S1 = BRepPrimAPI_MakeBox(300, 200, 200).Shape();
1428TopoDS_Shape S2 = BRepPrimAPI_MakeBox(P1, 120, 180, 70).Shape();
7fd59977 1429
1430TopoDS_Shape fusedShape = BRepAlgoAPI_Fuse(S1,S2);
1431Handle(AIS_Shape) ais2 = new AIS_Shape(fusedShape);
1432myAISContext->SetColor(ais2,Quantity_NOC_RED,Standard_False);
1433myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
1434myAISContext->Display(ais2,Standard_False);
404c8936 1435const Handle(AIS_InteractiveObject)& anIO2 = ais2;
1436myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 1437Fit();
1438
1439BRepFilletAPI_MakeFillet fill(fusedShape);
1440
1441for (TopExp_Explorer ex1(fusedShape,TopAbs_EDGE); ex1.More(); ex1.Next()) {
1442 TopoDS_Edge E =TopoDS::Edge(ex1.Current());
1443 fill.Add(E);
1444}
1445
1446for (Standard_Integer i = 1;i<=fill.NbContours();i++) {
1447 Standard_Real longueur(fill.Length(i));
1448 Standard_Real Rad(0.15*longueur);
1449 fill.SetRadius(Rad,i, 1);
1450}
1451
1452TopoDS_Shape blendedFusedSolids = fill.Shape();
1453
1454Handle(AIS_Shape) aBlend = new AIS_Shape(blendedFusedSolids);
1455myAISContext->SetColor(aBlend,Quantity_NOC_RED,Standard_False);
1456myAISContext->SetMaterial(aBlend,Graphic3d_NOM_PLASTIC,Standard_False);
1457myAISContext->Display(aBlend,Standard_False);
1458
1459myAISContext->Remove(ais2,Standard_False);
1460Fit();
1461
1462
1463 TCollection_AsciiString Message ("\
1464 \n\
1465//THE YELLOW BOX\n\
1466TopoDS_Shape Box = BRepPrimAPI_MakeBox(gp_Pnt(-400,0,0),200,230,180);\n\
1467\n\
1468BRepPrimAPI_MakeFillet fillet(Box);\n\
1469\n\
1470for (TopExp_Explorer ex(Box,TopAbs_EDGE); ex.More(); ex.Next()) {\n\
1471 TopoDS_Edge Edge =TopoDS::Edge(ex.Current());\n\
1472 fillet.Add(20,Edge);\n\
1473}\n\
1474TopoDS_Shape blendedBox = fillet.Shape();\n\
1475\n\
1476////////////////////////////////////////////////////////////////////////\n\
1477\n\
1478//THE RED SOLID\n\
1479 \n\
1480//Warning : On the acute angles of the boxes a fillet is created. \n\
1481On the angles of fusion a blend is created. \n\
1482\n\
1483gp_Pnt P1(150,150,75);\n\
1484TopoDS_Shape S1 = BRepPrimAPI_MakeBox(300,200,200);\n\
1485TopoDS_Shape S2 = BRepPrimAPI_MakeBox(P1,100,200,70);\n\
1486\n\
1487TopoDS_Shape fusedShape = BRepAlgoAPI_Fuse(S1,S2);\n\
1488BRepPrimAPI_MakeFillet fill(fusedShape);\n\
1489\n\
1490for (TopExp_Explorer ex1(fusedShape,TopAbs_EDGE); ex1.More(); ex1.Next()) {\n\
1491 TopoDS_Edge E =TopoDS::Edge(ex1.Current());\n\
1492 fill.Add(E);\n\
1493}\n\
1494\n\
1495for (Standard_Integer i = 1;i<=fill.NbContours();i++) {\n\
1496 Standard_Real longueur(fill.Length(i));\n\
1497 Standard_Real Rad(0.2*longueur);\n\
1498 fill.SetRadius(Rad,i);\n\
1499}\n\
1500\n\
1501TopoDS_Shape blendedFusedSolids = fill.Shape(); \n");
1502
1503 PocessTextInDialog("Compute the blend on the edges ", Message);
1504}
1505
1506void CModelingDoc::OnEvolvedblend()
1507{
1508
1509 AIS_ListOfInteractive aList;
1510 myAISContext->DisplayedObjects(aList);
1511 AIS_ListIteratorOfListOfInteractive aListIterator;
1512 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1513 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1514 }
1515
576f8b11 1516TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200, 200, 200).Shape();
7fd59977 1517Handle(AIS_Shape) ais1 = new AIS_Shape(theBox);
1518myAISContext->SetColor(ais1,Quantity_NOC_BROWN,Standard_False);
1519myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1520myAISContext->Display(ais1,Standard_False);
404c8936 1521const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1522myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1523Fit();
1524Sleep(500);
1525
1526BRepFilletAPI_MakeFillet Rake(theBox);
1527
1528TopExp_Explorer ex(theBox,TopAbs_EDGE);
1529ex.Next();
1530ex.Next();
1531ex.Next();
1532ex.Next();
1533Rake.Add(8,50,TopoDS::Edge(ex.Current()));
1534Rake.Build();
1535if (Rake.IsDone() ){
1536 TopoDS_Shape evolvedBox = Rake.Shape();
1537 ais1->Set(evolvedBox);
1538 myAISContext->Redisplay(ais1,Standard_False);
404c8936 1539 myAISContext->SetSelected(anIO1, Standard_False);
7fd59977 1540 Fit();
1541 Sleep(500);
1542
1543}
1544
576f8b11 1545TopoDS_Shape theCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-300, 0, 0), gp::DZ()), 100, 200).Shape();
7fd59977 1546Handle(AIS_Shape) ais3 = new AIS_Shape(theCylinder);
1547myAISContext->SetColor(ais3,Quantity_NOC_GREEN,Standard_False);
1548myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC,Standard_False);
1549myAISContext->Display(ais3,Standard_False);
404c8936 1550const Handle(AIS_InteractiveObject)& anIO3 = ais3;
1551myAISContext->SetSelected (anIO3, Standard_False);
7fd59977 1552Fit();
1553Sleep(500);
1554
1555BRepFilletAPI_MakeFillet fillet(theCylinder);
1556
1557TColgp_Array1OfPnt2d TabPoint2(1,20);
1558
1559for (Standard_Integer i=0; i<=19; i++) {
42e4630c 1560 gp_Pnt2d Point2d(i*2*M_PI/19,60*cos(i*M_PI/19-M_PI/2)+10);
7fd59977 1561 TabPoint2.SetValue(i+1,Point2d);
1562}
1563
1564TopExp_Explorer exp2(theCylinder,TopAbs_EDGE);
1565fillet.Add(TabPoint2,TopoDS::Edge(exp2.Current()));
1566fillet.Build();
1567if (fillet.IsDone() ){
1568 TopoDS_Shape LawEvolvedCylinder = fillet.Shape();
1569 ais3->Set(LawEvolvedCylinder);
1570 myAISContext->Redisplay(ais3,Standard_False);
404c8936 1571 myAISContext->SetSelected(anIO3,Standard_False);
7fd59977 1572 Fit();
1573 Sleep(500);
1574}
1575
1576gp_Pnt P(350,0,0);
576f8b11 1577TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape();
7fd59977 1578Handle(AIS_Shape) ais2 = new AIS_Shape(theBox2);
1579myAISContext->SetColor(ais2,Quantity_NOC_RED,Standard_False);
1580myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
1581myAISContext->Display(ais2,Standard_False);
404c8936 1582const Handle(AIS_InteractiveObject)& anIO2 = ais2;
1583myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 1584Fit();
1585Sleep(500);
1586
1587
1588BRepFilletAPI_MakeFillet afillet(theBox2);
1589
1590TColgp_Array1OfPnt2d TabPoint(1,6);
1591
1592gp_Pnt2d P1(0.,8.);
1593gp_Pnt2d P2(0.2,16.);
1594gp_Pnt2d P3(0.4,25.);
1595gp_Pnt2d P4(0.6,55.);
1596gp_Pnt2d P5(0.8,28.);
1597gp_Pnt2d P6(1.,20.);
1598TabPoint.SetValue(1,P1);
1599TabPoint.SetValue(2,P2);
1600TabPoint.SetValue(3,P3);
1601TabPoint.SetValue(4,P4);
1602TabPoint.SetValue(5,P5);
1603TabPoint.SetValue(6,P6);
1604
1605TopExp_Explorer exp(theBox2,TopAbs_EDGE);
1606exp.Next();
1607exp.Next();
1608exp.Next();
1609exp.Next();
1610
1611afillet.Add(TabPoint, TopoDS::Edge(exp.Current()));
1612
1613afillet.Build();
1614if (afillet.IsDone() ){
1615 TopoDS_Shape LawevolvedBox = afillet.Shape();
1616 ais2->Set(LawevolvedBox);
1617 myAISContext->Redisplay(ais2,Standard_False);
404c8936 1618 myAISContext->SetSelected(anIO2,Standard_False);
7fd59977 1619 Fit();
1620
1621}
1622
1623 TCollection_AsciiString Message ("\
1624 \n\
1625//THE BROWN BOX \n\
1626\n\
1627TopoDS_Shape theBox = BRepPrimAPI_MakeBox(200,200,200); \n\
1628 \n\
1629BRepPrimAPI_MakeFillet Rake(theBox); \n\
1630ChFi3d_FilletShape FSh = ChFi3d_Rational; \n\
1631Rake.SetFilletShape(FSh); \n\
1632 \n\
1633TopExp_Explorer ex(theBox,TopAbs_EDGE); \n\
1634ex.Next(); //in order to recover the front edge \n\
1635ex.Next(); \n\
1636ex.Next(); \n\
1637ex.Next(); \n\
1638Rake.Add(8,50,TopoDS::Edge(ex.Current())); \n\
1639 \n\
1640Rake.Build(); \n\
1641if (Rake.IsDone() ) \n\
1642 TopoDS_Shape theBrownBox = Rake.Shape(); \n\
1643 \n\
1644////////////////////////////////////////////////////////// \n\
1645 \n\
1646//THE GREEN CYLINDER \n\
1647 \n\
1648TopoDS_Shape theCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(gp_Pnt(-300,0,0),gp_Dir(0,0,1)),100,200); \n\
1649 \n\
1650BRepPrimAPI_MakeFillet fillet(theCylinder); \n\
1651 \n\
1652TColgp_Array1OfPnt2d TabPoint2(1,20); \n\
1653 \n\
1654for (Standard_Integer i=0; i<=19; i++) { \n\
1655 gp_Pnt2d Point2d(i*2*PI/19,60*cos(i*PI/19-PI/2)+10); \n\
1656 TabPoint2.SetValue(i+1,Point2d); \n\
1657} \n\
1658 \n\
1659TopExp_Explorer exp2(theCylinder,TopAbs_EDGE); \n\
1660fillet.Add(TabPoint2,TopoDS::Edge(exp2.Current())); \n\
1661 \n\
1662fillet.Build(); \n\
1663if (fillet.IsDone() ) \n\
1664 TopoDS_Shape LawEvolvedCylinder = fillet.Shape(); \n\
1665 \n\
1666//////////////////////////////////////////////////////////// \n\
1667 \n\
1668 //THE RED BOX \n\
1669 \n\
1670gp_Pnt P(350,0,0); \n\
1671TopoDS_Shape theBox2 = BRepPrimAPI_MakeBox(P,200,200,200); \n\
1672 \n\
1673BRepPrimAPI_MakeFillet fill(theBox2); \n\
1674 \n\
1675TColgp_Array1OfPnt2d TabPoint(1,6); \n\
1676gp_Pnt2d P1(0,8); \n\
1677gp_Pnt2d P2(0.2,16); \n\
1678gp_Pnt2d P3(0.4,25); \n\
1679gp_Pnt2d P4(0.6,55); \n\
1680gp_Pnt2d P5(0.8,28); \n\
1681gp_Pnt2d P6(1,20); \n\
1682TabPoint.SetValue(1,P1); \n\
1683TabPoint.SetValue(2,P2); \n\
1684TabPoint.SetValue(3,P3); \n\
1685TabPoint.SetValue(4,P4); \n\
1686TabPoint.SetValue(5,P5); \n\
1687TabPoint.SetValue(6,P6); \n\
1688 \n\
1689TopExp_Explorer exp(theBox2,TopAbs_EDGE); \n\
1690exp.Next(); //in order to trcover the front edge \n\
1691exp.Next(); \n\
1692exp.Next(); \n\
1693exp.Next(); \n\
1694fill.Add(TabPoint,TopoDS::Edge(exp.Current())); \n\
1695 \n\
1696fill.Build(); \n\
1697if (fillet.IsDone() ) \n\
1698 TopoDS_Shape theRedBox = fill.Shape(); \n\
1699\n");
1700
1701 PocessTextInDialog("Compute evolutiv blend on an edge ", Message);
1702
1703}
1704
1705void CModelingDoc::OnChamf()
1706{
1707 AIS_ListOfInteractive aList;
1708 myAISContext->DisplayedObjects(aList);
1709 AIS_ListIteratorOfListOfInteractive aListIterator;
1710 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1711 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1712 }
1713
576f8b11 1714TopoDS_Shape theBox = BRepPrimAPI_MakeBox(60,200,70).Shape();
7fd59977 1715Handle(AIS_Shape) ais1 = new AIS_Shape(theBox);
1716myAISContext->SetColor(ais1,Quantity_NOC_YELLOW,Standard_False);
1717myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1718myAISContext->Display(ais1,Standard_False);
404c8936 1719const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1720myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1721Fit();
1722Sleep(500);
1723
1724BRepFilletAPI_MakeChamfer MC(theBox);
1725// add all the edges to chamfer
1726TopTools_IndexedDataMapOfShapeListOfShape M;
1727TopExp::MapShapesAndAncestors(theBox,TopAbs_EDGE,TopAbs_FACE,M);
1728for (Standard_Integer i = 1;i<=M.Extent();i++) {
1729 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
1730 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
1731 MC.Add(5,5,E,F);
1732 }
1733
1734TopoDS_Shape ChanfrenedBox = MC.Shape();
1735Handle(AIS_Shape) aBlendedBox = new AIS_Shape(ChanfrenedBox);
1736myAISContext->SetColor(aBlendedBox,Quantity_NOC_YELLOW,Standard_False);
1737myAISContext->SetMaterial(aBlendedBox,Graphic3d_NOM_PLASTIC,Standard_False);
1738myAISContext->Display(aBlendedBox,Standard_False);
404c8936 1739const Handle(AIS_InteractiveObject)& anIOBlendedBox = aBlendedBox;
1740myAISContext->SetSelected (anIOBlendedBox, Standard_False);
7fd59977 1741Fit();
1742Sleep(500);
1743
eb4320f2 1744myAISContext->Erase(ais1,Standard_True);
7fd59977 1745
1746 TCollection_AsciiString Message ("\
1747 \n\
1748TopoDS_Shape theBox = BRepPrimAPI_MakeBox(130,200,170); \n\
1749BRepFilletAPI_MakeChamfer MC(theBox); \n\
1750TopTools_IndexedDataMapOfShapeListOfShape M; \n\
1751TopExp::MapShapesAndAncestors(theBox,TopAbs_EDGE,TopAbs_FACE,M); \n\
1752for (Standar1d_Integer i;i<M.Extent();i++) { \n\
1753 TopoDS_Edge E = TopoDS::Edge(M.FindKey(i)); \n\
1754 TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First()); \n\
1755 MC.Add(15,15,E,F); \n\
1756 } \n\
1757TopoDS_Shape ChanfrenedBox = MC.Shape(); \n");
1758
1759 PocessTextInDialog("Compute the chamfers on all the edges ", Message);
1760}
1761
1762/* =================================================================================
1763 ==================== L O C A L O P E R A T I O N S ========================
1764 ================================================================================= */
1765
1766void CModelingDoc::OnPrismLocal()
1767{
1768 AIS_ListOfInteractive aList;
1769 myAISContext->DisplayedObjects(aList);
1770 AIS_ListIteratorOfListOfInteractive aListIterator;
1771 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1772 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1773 }
576f8b11 1774 TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape();
7fd59977 1775 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
1776
1777 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
1778 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1779 myAISContext->Display(ais1,Standard_False);
404c8936 1780 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1781 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1782 Fit();
1783 Sleep(500);
1784
1785 TopExp_Explorer Ex;
1786 Ex.Init(S,TopAbs_FACE);
1787 Ex.Next();
1788 TopoDS_Face F = TopoDS::Face(Ex.Current());
1789 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
1790 Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(surf);
1791 gp_Dir D = Pl->Pln().Axis().Direction();
1792// new in 2.0 ..use the trigonometric orientation to make the extrusion.
1793 D.Reverse();
1794 gp_Pnt2d p1,p2;
1795 Handle(Geom2d_Curve) aline;
1796 BRepBuilderAPI_MakeWire MW;
1797 p1 = gp_Pnt2d(200.,-100.);
1798 p2 = gp_Pnt2d(100.,-100.);
1799 aline = GCE2d_MakeLine(p1,p2).Value();
1800 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1801 p1 = p2;
1802 p2 = gp_Pnt2d(100.,-200.);
1803 aline = GCE2d_MakeLine(p1,p2).Value();
1804 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1805 p1 = p2;
1806 p2 = gp_Pnt2d(200.,-200.);
1807 aline = GCE2d_MakeLine(p1,p2).Value();
1808 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1809 p1 = p2;
1810 p2 = gp_Pnt2d(200.,-100.);
1811 aline = GCE2d_MakeLine(p1,p2).Value();
1812 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1813 BRepBuilderAPI_MakeFace MKF;
9181b66d 1814 MKF.Init(surf,Standard_False, Precision::Confusion());
7fd59977 1815 MKF.Add(MW.Wire());
1816 TopoDS_Shape FP = MKF.Face();
1817 BRepLib::BuildCurves3d(FP);
1818 BRepFeat_MakePrism MKP(S,FP,F,D,0,Standard_True);
1819 MKP.Perform(200.);
1820 TopoDS_Shape res1 = MKP.Shape();
1821 ais1->Set(res1);
1822
1823 myAISContext->Redisplay(ais1,Standard_False);
404c8936 1824 myAISContext->SetSelected(anIO1,Standard_False);
7fd59977 1825 Fit();
1826 Sleep(500);
1827
1828 Ex.Next();
1829 TopoDS_Face F2 = TopoDS::Face(Ex.Current());
1830 surf = BRep_Tool::Surface(F2);
1831 Pl = Handle(Geom_Plane)::DownCast(surf);
1832 D = Pl->Pln().Axis().Direction();
1833 D.Reverse();
1834 BRepBuilderAPI_MakeWire MW2;
1835 p1 = gp_Pnt2d(100.,100.);
1836 p2 = gp_Pnt2d(200.,100.);
1837 aline = GCE2d_MakeLine(p1,p2).Value();
1838 MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1839 p1 = p2;
1840 p2 = gp_Pnt2d(150.,200.);
1841 aline = GCE2d_MakeLine(p1,p2).Value();
1842 MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1843 p1 = p2;
1844 p2 = gp_Pnt2d(100.,100.);
1845 aline = GCE2d_MakeLine(p1,p2).Value();
1846 MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
1847 BRepBuilderAPI_MakeFace MKF2;
9181b66d 1848 MKF2.Init(surf,Standard_False, Precision::Confusion());
7fd59977 1849 MKF2.Add(MW2.Wire());
1850 FP = MKF2.Face();
1851 BRepLib::BuildCurves3d(FP);
1852 BRepFeat_MakePrism MKP2(res1,FP,F2,D,1,Standard_True);
1853 MKP2.Perform(100.);
1854 TopoDS_Shape res2 = MKP2.Shape();
1855 ais1->Set(res2);
1856
0577ae8c 1857 myAISContext->Redisplay (ais1, Standard_False);
1858 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1859 Fit();
1860
1861 TCollection_AsciiString Message ("\
1862 \n\
1863--- Extrusion ---\n\
1864 \n\
1865TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);\n\
1866TopExp_Explorer Ex;\n\
1867Ex.Init(S,TopAbs_FACE);\n\
1868Ex.Next();\n\
1869TopoDS_Face F = TopoDS::Face(Ex.Current());\n\
1870Handle(Geom_Surface) surf = BRep_Tool::Surface(F);\n\
1871Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(surf);\n\
1872gp_Dir D = Pl->Pln().Axis().Direction();\n\
1873D.Reverse();\n\
1874gp_Pnt2d p1,p2;\n\
1875Handle(Geom2d_Curve) aline;\n\
1876BRepBuilderAPI_MakeWire MW;\n\
1877p1 = gp_Pnt2d(200.,-100.);\n\
1878p2 = gp_Pnt2d(100.,-100.);\n\
1879aline = GCE2d_MakeLine(p1,p2).Value();\n\
1880MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1881p1 = p2;\n\
1882p2 = gp_Pnt2d(100.,-200.);\n\
1883aline = GCE2d_MakeLine(p1,p2).Value();\n\
1884MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1885p1 = p2;\n\
1886p2 = gp_Pnt2d(200.,-200.);\n\
1887aline = GCE2d_MakeLine(p1,p2).Value();\n\
1888MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1889p1 = p2;\n\
1890p2 = gp_Pnt2d(200.,-100.);\n\
1891aline = GCE2d_MakeLine(p1,p2).Value();\n\
1892MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1893BRepBuilderAPI_MakeFace MKF;\n\
1894MKF.Init(surf,Standard_False);\n\
1895MKF.Add(MW.Wire());\n\
1896TopoDS_Shape FP = MKF.Face();\n\
1897BRepLib::BuildCurves3d(FP);\n\
1898BRepFeat_MakePrism MKP(S,FP,F,D,0,Standard_True);\n\
1899MKP.Perform(200);\n\
1900TopoDS_Shape res1 = MKP.Shape();\n\
1901 \n");
1902 Message += "\n\
1903--- Protrusion --- \n\
1904\n\
1905Ex.Next();\n\
1906TopoDS_Face F2 = TopoDS::Face(Ex.Current());\n\
1907surf = BRep_Tool::Surface(F2);\n\
1908Pl = Handle(Geom_Plane)::DownCast(surf);\n\
1909D = Pl->Pln().Axis().Direction();\n\
1910D.Reverse();\n\
1911BRepBuilderAPI_MakeWire MW2;\n\
1912p1 = gp_Pnt2d(100.,100.);\n\
1913p2 = gp_Pnt2d(200.,100.);\n\
1914aline = GCE2d_MakeLine(p1,p2).Value();\n\
1915MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1916p1 = p2;\n\
1917p2 = gp_Pnt2d(150.,200.);\n\
1918aline = GCE2d_MakeLine(p1,p2).Value();\n\
1919MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1920p1 = p2;\n\
1921p2 = gp_Pnt2d(100.,100.);\n\
1922aline = GCE2d_MakeLine(p1,p2).Value();\n\
1923MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
1924BRepBuilderAPI_MakeFace MKF2;\n\
1925MKF2.Init(surf,Standard_False);\n\
1926MKF2.Add(MW2.Wire());\n\
1927FP = MKF2.Face();\n\
1928BRepLib::BuildCurves3d(FP);\n\
1929BRepFeat_MakePrism MKP2(res1,FP,F2,D,1,Standard_True);\n\
1930MKP2.Perform(100.);\n\
1931TopoDS_Shape res2 = MKP2.Shape();\n\
1932 \n";
1933 PocessTextInDialog("Make an extrusion or a protrusion", Message);
1934}
1935
1936//
1937// BRepFeat_MakeDPrism
1938//
1939void CModelingDoc::OnDprismLocal()
1940{
1941 AIS_ListOfInteractive aList;
1942 myAISContext->DisplayedObjects(aList);
1943 AIS_ListIteratorOfListOfInteractive aListIterator;
1944 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 1945 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 1946 }
1947
576f8b11 1948 TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape();
7fd59977 1949 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
1950
1951 myAISContext->SetColor(ais1,Quantity_NOC_RED,Standard_False);
1952 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
1953
1954 TopExp_Explorer Ex;
1955 Ex.Init(S,TopAbs_FACE);
1956 Ex.Next();
1957 Ex.Next();
1958 Ex.Next();
1959 Ex.Next();
1960 Ex.Next();
1961 TopoDS_Face F = TopoDS::Face(Ex.Current());
1962 Handle(Geom_Surface) surf = BRep_Tool::Surface(F);
1963 gp_Circ2d c(gp_Ax2d(gp_Pnt2d(200.,130.),gp_Dir2d(1.,0.)),50.);
1964 BRepBuilderAPI_MakeWire MW;
1965 Handle(Geom2d_Curve) aline = new Geom2d_Circle(c);
42e4630c 1966 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,M_PI));
1967 MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,M_PI,2.*M_PI));
7fd59977 1968 BRepBuilderAPI_MakeFace MKF;
9181b66d 1969 MKF.Init(surf,Standard_False, Precision::Confusion());
7fd59977 1970 MKF.Add(MW.Wire());
1971 TopoDS_Face FP = MKF.Face();
1972 BRepLib::BuildCurves3d(FP);
42e4630c 1973 BRepFeat_MakeDPrism MKDP(S,FP,F,10*M_PI/180,1,Standard_True);
7fd59977 1974 MKDP.Perform(200);
1975 TopoDS_Shape res1 = MKDP.Shape();
1976
1977 myAISContext->Display(ais1,Standard_False);
404c8936 1978 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
1979 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 1980 Fit();
1981 Sleep(500);
1982
1983 ais1->Set(res1);
1984
1985 myAISContext->Redisplay(ais1,Standard_False);
404c8936 1986 myAISContext->SetSelected(anIO1,Standard_False);
7fd59977 1987
1988 Fit();
1989
1990 TCollection_AsciiString Message ("\
1991 \n\
1992--- Protrusion with draft angle --- \n\
1993 \n\
1994TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);\n\
1995TopExp_Explorer Ex;\n\
1996Ex.Init(S,TopAbs_FACE);\n\
1997Ex.Next();\n\
1998Ex.Next();\n\
1999Ex.Next();\n\
2000Ex.Next();\n\
2001Ex.Next();\n\
2002TopoDS_Face F = TopoDS::Face(Ex.Current());\n\
2003Handle(Geom_Surface) surf = BRep_Tool::Surface(F);\n\
2004gp_Circ2d c(gp_Ax2d(gp_Pnt2d(200.,130.),gp_Dir2d(1.,0.)),50.);\n\
2005BRepBuilderAPI_MakeWire MW;\n\
2006Handle(Geom2d_Curve) aline = new Geom2d_Circle(c);\n\
2007MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,PI));\n\
2008MW.Add(BRepBuilderAPI_MakeEdge(aline,surf,PI,2.*PI));\n\
2009BRepBuilderAPI_MakeFace MKF;\n\
2010MKF.Init(surf,Standard_False);\n\
2011MKF.Add(MW.Wire());\n\
2012TopoDS_Face FP = MKF.Face();\n\
2013BRepLib::BuildCurves3d(FP);\n\
2014BRepFeat_MakeDPrism MKDP(S,FP,F,10*PI180,1,Standard_True);\n\
2015MKDP.Perform(200);\n\
2016TopoDS_Shape res1 = MKDP.Shape();\n\
2017 \n");
2018 PocessTextInDialog("Make an extrusion or a protrusion with a draft angle", Message);
2019}
2020
2021void CModelingDoc::OnRevolLocal()
2022{
2023 AIS_ListOfInteractive aList;
2024 myAISContext->DisplayedObjects(aList);
2025 AIS_ListIteratorOfListOfInteractive aListIterator;
2026 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2027 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2028 }
576f8b11 2029 TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape();
7fd59977 2030
2031 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
2032
2033 myAISContext->SetColor(ais1,Quantity_NOC_CORAL,Standard_False);
2034 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2035 myAISContext->Display(ais1,Standard_False);
404c8936 2036 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2037 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2038 Fit();
2039 Sleep(500);
2040
2041 TopExp_Explorer Ex;
2042 Ex.Init(S,TopAbs_FACE);
2043 Ex.Next();
2044 Ex.Next();
2045 TopoDS_Face F1 = TopoDS::Face(Ex.Current());
2046 Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);
2047 Handle (Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(surf);
2048 gp_Ax1 D = gp::OX();
2049 BRepBuilderAPI_MakeWire MW1;
2050 gp_Pnt2d p1,p2;
2051 p1 = gp_Pnt2d(100.,100.);
2052 p2 = gp_Pnt2d(200.,100.);
2053 Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();
2054 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2055 p1 = p2;
2056 p2 = gp_Pnt2d(150.,200.);
2057 aline = GCE2d_MakeLine(p1,p2).Value();
2058 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2059 p1 = p2;
2060 p2 = gp_Pnt2d(100.,100.);
2061 aline = GCE2d_MakeLine(p1,p2).Value();
2062 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2063 BRepBuilderAPI_MakeFace MKF1;
9181b66d 2064 MKF1.Init(surf,Standard_False, Precision::Confusion());
7fd59977 2065 MKF1.Add(MW1.Wire());
2066 TopoDS_Face FP = MKF1.Face();
2067 BRepLib::BuildCurves3d(FP);
2068 BRepFeat_MakeRevol MKrev(S,FP,F1,D,1,Standard_True);
2069 Ex.Next();
2070 Ex.Next();
2071 TopoDS_Face F2 = TopoDS::Face(Ex.Current());
2072 MKrev.Perform(F2);
2073 TopoDS_Shape res1 = MKrev.Shape();
2074
2075
0577ae8c 2076 myAISContext->Remove (ais1, Standard_False);
7fd59977 2077 Handle(AIS_Shape) ais2 = new AIS_Shape(res1);
2078 myAISContext->Display(ais2,Standard_False);
404c8936 2079 const Handle(AIS_InteractiveObject)& anIO2 = ais2;
2080 myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 2081 Fit();
2082
2083 TCollection_AsciiString Message ("\
2084 \n\
2085TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);\n\
2086TopExp_Explorer Ex;\n\
2087Ex.Init(S,TopAbs_FACE);\n\
2088Ex.Next();\n\
2089Ex.Next();\n\
2090TopoDS_Face F1 = TopoDS::Face(Ex.Current());\n\
2091Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);\n\
2092Handle (Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(surf);\n\
2093gp_Ax1 D = gp::OX();\n\
2094BRepBuilderAPI_MakeWire MW1;\n\
2095gp_Pnt2d p1,p2;\n\
2096p1 = gp_Pnt2d(100.,100.);\n\
2097p2 = gp_Pnt2d(200.,100.);\n\
2098Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();\n\
2099MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2100p1 = p2;\n\
2101p2 = gp_Pnt2d(150.,200.);\n\
2102aline = GCE2d_MakeLine(p1,p2).Value();\n\
2103MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2104p1 = p2;\n\
2105p2 = gp_Pnt2d(100.,100.);\n\
2106aline = GCE2d_MakeLine(p1,p2).Value();\n\
2107MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2108BRepBuilderAPI_MakeFace MKF1;\n\
2109MKF1.Init(surf,Standard_False);\n\
2110MKF1.Add(MW1.Wire());\n\
2111TopoDS_Face FP = MKF1.Face();\n\
2112BRepLib::BuildCurves3d(FP);\n\
2113BRepFeat_MakeRevol MKrev(S,FP,F1,D,1,Standard_True);\n\
2114Ex.Next();\n\
2115TopoDS_Face F2 = TopoDS::Face(Ex.Current());\n\
2116MKrev.Perform(F2);\n\
2117TopoDS_Shape res1 = MKrev.Shape();\n\
2118 \n");
576f8b11 2119 PocessTextInDialog("Make a local revolution", Message);
7fd59977 2120}
2121
2122void CModelingDoc::OnGlueLocal()
2123{
2124 AIS_ListOfInteractive aList;
2125 myAISContext->DisplayedObjects(aList);
2126 AIS_ListIteratorOfListOfInteractive aListIterator;
2127 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2128 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2129 }
576f8b11 2130 TopoDS_Shape S1 = BRepPrimAPI_MakeBox(gp_Pnt(-500., -500., 0.), gp_Pnt(-100., -250., 300.)).Shape();
7fd59977 2131
2132 Handle(AIS_Shape) ais1 = new AIS_Shape(S1);
2133 myAISContext->SetColor(ais1,Quantity_NOC_ORANGE,Standard_False);
2134 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2135 myAISContext->Display(ais1,Standard_False);
404c8936 2136 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2137 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2138 Fit();
2139 Sleep(1000);
2140
2141 TopExp_Explorer Ex1;
2142 Ex1.Init(S1,TopAbs_FACE);
2143 Ex1.Next();
2144 Ex1.Next();
2145 Ex1.Next();
2146 Ex1.Next();
2147 Ex1.Next();
2148 TopoDS_Face F1 = TopoDS::Face(Ex1.Current());
576f8b11 2149 TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(-400., -400., 300.), gp_Pnt(-200., -300., 500.)).Shape();
7fd59977 2150 Handle(AIS_Shape) ais2 = new AIS_Shape(S2);
2151
2152 myAISContext->SetColor(ais2,Quantity_NOC_AZURE,Standard_False);
2153 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
2154 myAISContext->Display(ais2,Standard_False);
404c8936 2155 const Handle(AIS_InteractiveObject)& anIO2 = ais2;
2156 myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 2157 Fit();
2158 Sleep(1000);
2159
2160 TopExp_Explorer Ex2;
2161 Ex2.Init(S2,TopAbs_FACE);
2162 Ex2.Next();
2163 Ex2.Next();
2164 Ex2.Next();
2165 Ex2.Next();
2166 TopoDS_Face F2 = TopoDS::Face(Ex2.Current());
2167 BRepFeat_Gluer glue(S2,S1);
2168 glue.Bind(F2,F1);
2169 TopoDS_Shape res1 = glue.Shape();
eb4320f2 2170 myAISContext->Erase(ais2,Standard_False);
7fd59977 2171
2172 ais1->Set(res1);
2173
0577ae8c 2174 myAISContext->Redisplay (ais1, Standard_False);
404c8936 2175 myAISContext->SetSelected(anIO1,Standard_False);
7fd59977 2176 Fit();
2177 Sleep(1000);
2178
576f8b11 2179 TopoDS_Shape S3 = BRepPrimAPI_MakeBox(500., 400., 300.).Shape();
7fd59977 2180
2181 Handle(AIS_Shape) ais3 = new AIS_Shape(S3);
2182 myAISContext->SetColor(ais3,Quantity_NOC_ORANGE,Standard_False);
2183 myAISContext->SetMaterial(ais3,Graphic3d_NOM_PLASTIC,Standard_False);
2184 myAISContext->Display(ais3,Standard_False);
404c8936 2185 const Handle(AIS_InteractiveObject)& anIO3 = ais3;
2186 myAISContext->SetSelected (anIO3, Standard_False);
7fd59977 2187 Fit();
2188 Sleep(1000);
2189
2190 TopExp_Explorer Ex3;
2191 Ex3.Init(S3,TopAbs_FACE);
2192 Ex3.Next();
2193 Ex3.Next();
2194 Ex3.Next();
2195 Ex3.Next();
2196 Ex3.Next();
2197 TopoDS_Face F3 = TopoDS::Face(Ex3.Current());
576f8b11 2198 TopoDS_Shape S4 = BRepPrimAPI_MakeBox(gp_Pnt(0., 0., 300.), gp_Pnt(200., 200., 500.)).Shape();
7fd59977 2199
2200 Handle(AIS_Shape) ais4 = new AIS_Shape(S4);
2201 myAISContext->SetColor(ais4,Quantity_NOC_AZURE,Standard_False);
2202 myAISContext->SetMaterial(ais4,Graphic3d_NOM_PLASTIC,Standard_False);
2203 myAISContext->Display(ais4,Standard_False);
404c8936 2204 const Handle(AIS_InteractiveObject)& anIO4 = ais4;
2205 myAISContext->SetSelected (anIO4, Standard_False);
7fd59977 2206 Fit();
2207 Sleep(1000);
2208
2209 TopExp_Explorer Ex4;
2210 Ex4.Init(S4,TopAbs_FACE);
2211 Ex4.Next();
2212 Ex4.Next();
2213 Ex4.Next();
2214 Ex4.Next();
2215 TopoDS_Face F4 = TopoDS::Face(Ex4.Current());
2216 BRepFeat_Gluer glue2(S4,S3);
2217 glue2.Bind(F4,F3);
2218 LocOpe_FindEdges CommonEdges(F4,F3);
2219 for (CommonEdges.InitIterator(); CommonEdges.More(); CommonEdges.Next())
2220 glue2.Bind(CommonEdges.EdgeFrom(),CommonEdges.EdgeTo());
2221 TopoDS_Shape res2 = glue2.Shape();
eb4320f2 2222 myAISContext->Erase(ais3,Standard_False);
7fd59977 2223
2224 ais4->Set(res2);
2225
2226 myAISContext->Redisplay(ais4,Standard_False);
404c8936 2227 myAISContext->SetSelected(anIO4,Standard_False);
7fd59977 2228 Fit();
2229 Sleep(1000);
2230
2231 TCollection_AsciiString Message ("\
2232 \n\
2233--- Without common edges ---\n\
2234 \n\
2235TopoDS_Shape S1 = BRepPrimAPI_MakeBox(gp_Pnt(-500.,-500.,0.),gp_Pnt(-100.,-250.,300.));\n\
2236TopExp_Explorer Ex1;\n\
2237Ex1.Init(S1,TopAbs_FACE);\n\
2238Ex1.Next();\n\
2239Ex1.Next();\n\
2240Ex1.Next();\n\
2241Ex1.Next();\n\
2242Ex1.Next();\n\
2243TopoDS_Face F1 = TopoDS::Face(Ex1.Current());\n\
2244TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(-400.,-400.,300.),gp_Pnt(-200.,-300.,500.));\n\
2245TopExp_Explorer Ex2;\n\
2246Ex2.Init(S2,TopAbs_FACE);\n\
2247Ex2.Next();\n\
2248Ex2.Next();\n\
2249Ex2.Next();\n\
2250Ex2.Next();\n\
2251TopoDS_Face F2 = TopoDS::Face(Ex2.Current());\n\
2252BRepFeat_Gluer glue(S2,S1);\n\
2253glue.Bind(F2,F1);\n\
2254TopoDS_Shape res1 = glue.Shape();\n\
2255\n\
2256--- With common edges ---\n\
2257\n\
2258TopoDS_Shape S3 = BRepPrimAPI_MakeBox(500.,400.,300.);\n\
2259TopExp_Explorer Ex3;\n\
2260Ex3.Init(S3,TopAbs_FACE);\n\
2261Ex3.Next();\n\
2262Ex3.Next();\n\
2263Ex3.Next();\n\
2264Ex3.Next();\n\
2265Ex3.Next();\n\
2266TopoDS_Face F3 = TopoDS::Face(Ex3.Current());\n\
2267TopoDS_Shape S4 = BRepPrimAPI_MakeBox(gp_Pnt(0.,0.,300.),gp_Pnt(200.,200.,500.));\n\
2268TopExp_Explorer Ex4;\n\
2269Ex4.Init(S4,TopAbs_FACE);\n\
2270Ex4.Next();\n\
2271Ex4.Next();\n\
2272Ex4.Next();\n\
2273Ex4.Next();\n\
2274TopoDS_Face F4 = TopoDS::Face(Ex4.Current());\n\
2275BRepFeat_Gluer glue2(S4,S3);\n\
2276glue2.Bind(F4,F3);\n\
2277LocOpe_FindEdges CommonEdges(F4,F3);\n\
2278for (CommonEdges.InitIterator(); CommonEdges.More(); CommonEdges.Next()) \n\
2279 glue2.Bind(CommonEdges.EdgeFrom(),CommonEdges.EdgeTo());\n\
2280TopoDS_Shape res2 = glue2.Shape();\n\
2281 \n");
576f8b11 2282 PocessTextInDialog("Glue two solids", Message);
7fd59977 2283}
2284
2285
2286void CModelingDoc::OnPipeLocal()
2287{
2288 AIS_ListOfInteractive aList;
2289 myAISContext->DisplayedObjects(aList);
2290 AIS_ListIteratorOfListOfInteractive aListIterator;
2291 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2292 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2293 }
576f8b11 2294 TopoDS_Shape S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape();
7fd59977 2295 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
2296
2297 myAISContext->SetColor(ais1,Quantity_NOC_CORAL,Standard_False);
2298 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2299 myAISContext->Display(ais1,Standard_False);
404c8936 2300 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2301 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2302 Fit();
2303 Sleep(500);
2304
2305 TopExp_Explorer Ex;
2306 Ex.Init(S,TopAbs_FACE);
2307 Ex.Next();
2308 Ex.Next();
2309 TopoDS_Face F1 = TopoDS::Face(Ex.Current());
2310 Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);
2311 BRepBuilderAPI_MakeWire MW1;
2312 gp_Pnt2d p1,p2;
2313 p1 = gp_Pnt2d(100.,100.);
2314 p2 = gp_Pnt2d(200.,100.);
2315 Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();
2316 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2317 p1 = p2;
2318 p2 = gp_Pnt2d(150.,200.);
2319 aline = GCE2d_MakeLine(p1,p2).Value();
2320 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2321 p1 = p2;
2322 p2 = gp_Pnt2d(100.,100.);
2323 aline = GCE2d_MakeLine(p1,p2).Value();
2324 MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));
2325 BRepBuilderAPI_MakeFace MKF1;
9181b66d 2326 MKF1.Init(surf,Standard_False, Precision::Confusion());
7fd59977 2327 MKF1.Add(MW1.Wire());
2328 TopoDS_Face FP = MKF1.Face();
2329 BRepLib::BuildCurves3d(FP);
2330 TColgp_Array1OfPnt CurvePoles(1,3);
2331 gp_Pnt pt = gp_Pnt(150.,0.,150.);
2332 CurvePoles(1) = pt;
2333 pt = gp_Pnt(200.,-100.,150.);
2334 CurvePoles(2) = pt;
2335 pt = gp_Pnt(150.,-200.,150.);
2336 CurvePoles(3) = pt;
2337 Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);
2338 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);
2339 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);
2340 BRepFeat_MakePipe MKPipe(S,FP,F1,W,1,Standard_True);
2341 MKPipe.Perform();
2342 TopoDS_Shape res1 = MKPipe.Shape();
2343 ais1->Set(res1);
2344
2345 myAISContext->Redisplay(ais1,Standard_False);
404c8936 2346 myAISContext->SetSelected(anIO1,Standard_False);
7fd59977 2347 Fit();
2348
2349 TCollection_AsciiString Message ("\
2350 \n\
2351TopoDS_Shape S = BRepPrimAPI_MakeBox(400.,250.,300.);\n\
2352TopExp_Explorer Ex;\n\
2353Ex.Init(S,TopAbs_FACE);\n\
2354Ex.Next();\n\
2355Ex.Next();\n\
2356TopoDS_Face F1 = TopoDS::Face(Ex.Current());\n\
2357Handle(Geom_Surface) surf = BRep_Tool::Surface(F1);\n\
2358BRepBuilderAPI_MakeWire MW1;\n\
2359gp_Pnt2d p1,p2;\n\
2360p1 = gp_Pnt2d(100.,100.);\n\
2361p2 = gp_Pnt2d(200.,100.);\n\
2362Handle(Geom2d_Line) aline = GCE2d_MakeLine(p1,p2).Value();\n\
2363MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2364p1 = p2;\n\
2365p2 = gp_Pnt2d(150.,200.);\n\
2366aline = GCE2d_MakeLine(p1,p2).Value();\n\
2367MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2368p1 = p2;\n\
2369p2 = gp_Pnt2d(100.,100.);\n\
2370aline = GCE2d_MakeLine(p1,p2).Value();\n\
2371MW1.Add(BRepBuilderAPI_MakeEdge(aline,surf,0.,p1.Distance(p2)));\n\
2372BRepBuilderAPI_MakeFace MKF1;\n\
2373MKF1.Init(surf,Standard_False);\n\
2374TopoDS_Face FP = MKF1.Face();\n\
2375BRepLib::BuildCurves3d(FP);\n\
2376TColgp_Array1OfPnt CurvePoles(1,3);\n\
2377gp_Pnt pt = gp_Pnt(150.,0.,150.);\n\
2378CurvePoles(1) = pt;\n\
2379pt = gp_Pnt(200.,-100.,150.);\n\
2380CurvePoles(2) = pt;\n\
2381pt = gp_Pnt(150.,-200.,150.);\n\
2382CurvePoles(3) = pt;\n\
2383Handle(Geom_BezierCurve) curve = new Geom_BezierCurve(CurvePoles);\n\
2384TopoDS_Edge E = BRepBuilderAPI_MakeEdge(curve);\n\
2385TopoDS_Wire W = BRepBuilderAPI_MakeWire(E);\n\
2386BRepFeat_MakePipe MKPipe(S,FP,F1,W,1,Standard_True);\n\
2387MKPipe.Perform();\n\
2388TopoDS_Shape res1 = MKPipe.Shape();\n\
2389 \n");
576f8b11 2390 PocessTextInDialog("Make a local pipe", Message);
7fd59977 2391}
2392
2393
2394void CModelingDoc::OnLinearLocal()
2395{
2396 AIS_ListOfInteractive aList;
2397 myAISContext->DisplayedObjects(aList);
2398 AIS_ListIteratorOfListOfInteractive aListIterator;
2399 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2400 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2401 }
2402 BRepBuilderAPI_MakeWire mkw;
2403 gp_Pnt p1 = gp_Pnt(0.,0.,0.);
2404 gp_Pnt p2 = gp_Pnt(200.,0.,0.);
2405 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2406 p1 = p2;
2407 p2 = gp_Pnt(200.,0.,50.);
2408 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2409 p1 = p2;
2410 p2 = gp_Pnt(50.,0.,50.);
2411 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2412 p1 = p2;
2413 p2 = gp_Pnt(50.,0.,200.);
2414 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2415 p1 = p2;
2416 p2 = gp_Pnt(0.,0.,200.);
2417 mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));
2418 p1 = p2;
2419 mkw.Add(BRepBuilderAPI_MakeEdge(p2,gp_Pnt(0.,0.,0.)));
2420
2421 TopoDS_Shape S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()),
2422 gp_Vec(gp_Pnt(0.,0.,0.),gp_Pnt(0.,100.,0.)));
2423
2424 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
2425 myAISContext->SetColor(ais1,Quantity_NOC_CYAN2,Standard_False);
2426 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2427 myAISContext->Display(ais1,Standard_False);
404c8936 2428 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2429 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2430 Fit();
2431 Sleep(500);
2432
2433 TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50.,45.,100.),
2434 gp_Pnt(100.,45.,50.)));
2435 Handle(Geom_Plane) aplane = new Geom_Plane(0.,1.,0.,-45.);
2436 BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Vec(0.,10.,0.), gp_Vec(0.,0.,0.),
2437 1, Standard_True);
2438 aform.Perform(/*10.*/); // new in 2.0
2439
2440 TopoDS_Shape res = aform.Shape();
2441 ais1->Set(res);
2442 myAISContext->Redisplay(ais1,Standard_False);
0577ae8c 2443 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2444 Fit();
2445
2446 TCollection_AsciiString Message ("\
2447 \n\
2448BRepBuilderAPI_MakeWire mkw;\n\
2449gp_Pnt p1 = gp_Pnt(0.,0.,0.);\n\
2450gp_Pnt p2 = gp_Pnt(200.,0.,0.);\n\
2451mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));\n\
2452p1 = p2;\n\
2453p2 = gp_Pnt(200.,0.,50.);\n\
2454mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));\n\
2455p1 = p2;\n\
2456p2 = gp_Pnt(50.,0.,50.);\n\
2457mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));\n\
2458p1 = p2;\n\
2459p2 = gp_Pnt(50.,0.,200.);\n\
2460mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));\n\
2461p1 = p2;\n\
2462p2 = gp_Pnt(0.,0.,200.);\n\
2463mkw.Add(BRepBuilderAPI_MakeEdge(p1,p2));\n\
2464p1 = p2;\n\
2465mkw.Add(BRepBuilderAPI_MakeEdge(p2,gp_Pnt(0.,0.,0.)));\n\
2466TopoDS_Shape S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()), \n\
2467 gp_Vec(gp_Pnt(0.,0.,0.),gp_Pnt(0.,100.,0.)));\n\
2468TopoDS_Wire W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50.,45.,100.),\n\
2469 gp_Pnt(100.,45.,50.)));\n\
2470Handle(Geom_Plane) aplane = new Geom_Plane(0.,1.,0.,-45.);\n\
2471BRepFeat_MakeLinearForm aform(S, W, aplane, gp_Dir(0.,10.,0.), gp_Dir(0.,0.,0.),\n\
2472 1, Standard_True);\n\
2473aform.Perform(10.);\n\
2474TopoDS_Shape res = aform.Shape();\n\
2475 \n");
576f8b11 2476 PocessTextInDialog("Make a rib", Message);
7fd59977 2477}
2478
2479
2480void CModelingDoc::OnSplitLocal()
2481{
2482 AIS_ListOfInteractive aList;
2483 myAISContext->DisplayedObjects(aList);
2484 AIS_ListIteratorOfListOfInteractive aListIterator;
2485 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2486 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2487 }
2488
576f8b11 2489 TopoDS_Shape S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape();
7fd59977 2490
2491 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
2492 myAISContext->SetColor(ais1,Quantity_NOC_RED,Standard_False);
2493 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2494 myAISContext->Display(ais1,Standard_False);
404c8936 2495 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2496 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2497 Fit();
2498 Sleep(500);
2499
2500 BRepAlgoAPI_Section asect(S, gp_Pln(1,2,1,-15),Standard_False);
2501 asect.ComputePCurveOn1(Standard_True);
2502 asect.Approximation(Standard_True);
2503 asect.Build();
2504 TopoDS_Shape R = asect.Shape();
2505 BRepTools::Write(R,"E:\\temp\\R");
2506
2507 BRepFeat_SplitShape asplit(S);
2508
2509 for (TopExp_Explorer Ex(R,TopAbs_EDGE); Ex.More(); Ex.Next()) {
2510 TopoDS_Shape anEdge = Ex.Current();
2511 TopoDS_Shape aFace;
2512 if (asect.HasAncestorFaceOn1(anEdge,aFace)) {
2513 TopoDS_Face F = TopoDS::Face(aFace);
2514 TopoDS_Edge E = TopoDS::Edge(anEdge);
2515 asplit.Add(E,F);
2516 }
2517 }
2518
2519 asplit.Build();
2520
2521 //Sleep(1000);
eb4320f2 2522 myAISContext->Erase(ais1,Standard_False);
7fd59977 2523 //Fit();
2524
2525 TopoDS_Shape Result = asplit.Shape();
2526
2527 Handle(AIS_Shape) ais2 = new AIS_Shape(Result);
2528
2529 myAISContext->SetColor(ais2,Quantity_NOC_RED,Standard_False);
2530 myAISContext->SetMaterial(ais2,Graphic3d_NOM_PLASTIC,Standard_False);
2531 myAISContext->SetDisplayMode(ais2,1,Standard_False);
2532 myAISContext->Display(ais2,Standard_False);
404c8936 2533 const Handle(AIS_InteractiveObject)& anIO2 = ais2;
2534 myAISContext->SetSelected (anIO2, Standard_False);
7fd59977 2535 Fit();
2536 TCollection_AsciiString Message ("\
2537 \n\
2538TopoDS_Shape S = BRepPrimAPI_MakeBox(gp_Pnt(-100,-60,-80),150,200,170); \n\
2539 \n\
2540BRepBuilderAPI_Section asect(S, gp_Pln(1,2,1,-15),Standard_False); \n\
2541asect.ComputePCurveOn1(Standard_True); \n\
2542asect.Approximation(Standard_True); \n\
2543asect.Build(); \n\
2544TopoDS_Shape R = asect.Shape(); \n\
2545 \n\
2546BRepFeat_SplitShape asplit(S); \n\
2547 \n\
2548for (TopExp_Explorer Ex(R,TopAbs_EDGE); Ex.More(); Ex.Next()) { \n\
2549TopoDS_Shape anEdge = Ex.Current(); \n\
2550 TopoDS_Shape aFace; \n\
2551 if (asect.HasAncestorFaceOn1(anEdge,aFace)) { \n\
2552 TopoDS_Face F = TopoDS::Face(aFace); \n\
2553 TopoDS_Edge E = TopoDS::Edge(anEdge); \n\
2554 asplit.Add(E,F); \n\
2555 } \n\
2556} \n\
2557 \n\
2558asplit.Build(); \n\
2559 \n\
2560TopoDS_Shape Result = asplit.Shape(); \n\
2561 \n\
2562\n");
2563
2564PocessTextInDialog("Split a shape", Message);
2565}
2566
2567
2568
2569void CModelingDoc::OnThickLocal()
2570{
2571 AIS_ListOfInteractive L;
2572 myAISContext->DisplayedObjects(L);
2573 AIS_ListIteratorOfListOfInteractive aListIterator;
2574 for(aListIterator.Initialize(L);aListIterator.More();aListIterator.Next()){
0577ae8c 2575 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2576 }
2577
576f8b11 2578 TopoDS_Shape S1 = BRepPrimAPI_MakeBox(150, 200, 110).Shape();
7fd59977 2579
2580 Handle(AIS_Shape) abox1 = new AIS_Shape(S1);
0577ae8c 2581 myAISContext->SetColor (abox1, Quantity_NOC_WHITE, Standard_False);
7fd59977 2582 myAISContext->SetMaterial(abox1,Graphic3d_NOM_PLASTIC,Standard_False);
2583 myAISContext->Display(abox1,Standard_False);
404c8936 2584 const Handle(AIS_InteractiveObject)& anIOBox1 = abox1;
2585 myAISContext->SetSelected (anIOBox1, Standard_False);
7fd59977 2586 Fit();
2587 Sleep(1000);
2588
2589 TopTools_ListOfShape aList;
2590 TopExp_Explorer Ex(S1,TopAbs_FACE);
2591 Ex.Next(); //this is the front face
2592 TopoDS_Shape aFace = Ex.Current();
2593 aList.Append(aFace);
8013367c 2594
2595 BRepOffsetAPI_MakeThickSolid aSolidMaker;
2596 aSolidMaker.MakeThickSolidByJoin(S1,aList,10,0.01);
2597 TopoDS_Shape aThickSolid = aSolidMaker.Shape();
7fd59977 2598
2599 Handle(AIS_Shape) ais1 = new AIS_Shape(aThickSolid);
2600 myAISContext->SetColor(ais1,Quantity_NOC_RED,Standard_False);
2601 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
2602 myAISContext->Display(ais1,Standard_False);
404c8936 2603 const Handle(AIS_InteractiveObject)& anIO1 = ais1;
2604 myAISContext->SetSelected (anIO1, Standard_False);
7fd59977 2605 Fit();
2606 Sleep(1000);
2607
eb4320f2 2608 myAISContext->Erase(abox1,Standard_True);
7fd59977 2609 Fit();
2610
2611
2612 TCollection_AsciiString Message ("\
2613 \n\
2614TopoDS_Shape S = BRepPrimAPI_MakeBox(150,200,110); \n\
2615 \n\
2616TopTools_ListOfShape aList; \n\
2617TopExp_Explorer Ex(S,TopAbs_FACE); \n\
2618Ex.Next(); //in order to recover the front face \n\
2619TopoDS_Shape aFace = Ex.Current(); \n\
2620aList.Append(aFace); \n\
2621 \n\
2622TopoDS_Shape aThickSolid = BRepPrimAPI_MakeThickSolid(S,aList,15,0.01); \n\
2623 \n\
2624\n");
2625PocessTextInDialog("Make a thick solid", Message);
2626}
2627
2628void CModelingDoc::OnOffsetLocal()
2629{
2630 AIS_ListOfInteractive aList;
2631 myAISContext->DisplayedObjects(aList);
2632 AIS_ListIteratorOfListOfInteractive aListIterator;
2633 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2634 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2635 }
2636
576f8b11 2637 TopoDS_Shape S1 = BRepPrimAPI_MakeBox(150, 200, 110).Shape();
7fd59977 2638
2639 Handle(AIS_Shape) aisBox1 = new AIS_Shape(S1);
2640 myAISContext->SetColor(aisBox1,Quantity_NOC_BROWN,Standard_False);
2641 myAISContext->SetMaterial(aisBox1,Graphic3d_NOM_GOLD,Standard_False);
2642 myAISContext->Display(aisBox1,Standard_False);
2643 Fit();
2644 Sleep(500);
2645
8013367c 2646 BRepOffsetAPI_MakeOffsetShape aShapeMaker1;
2647 aShapeMaker1.PerformByJoin(S1,60,0.01);
2648 TopoDS_Shape anOffsetShape1 = aShapeMaker1.Shape();
7fd59977 2649
2650 Handle(AIS_Shape) ais1 = new AIS_Shape(anOffsetShape1);
2651 myAISContext->SetColor(ais1,Quantity_NOC_MATRABLUE,Standard_False);
2652 myAISContext->SetMaterial(ais1,Graphic3d_NOM_GOLD,Standard_False);
2653 myAISContext->SetTransparency(ais1,0.5,Standard_False);
2654 myAISContext->Display(ais1,Standard_False);
2655 Fit();
2656 Sleep(500);
2657
576f8b11 2658 TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(500, 0, 0), 220, 140, 180).Shape();
7fd59977 2659
2660 Handle(AIS_Shape) aisBox2 = new AIS_Shape(S2);
2661 myAISContext->SetColor(aisBox2,Quantity_NOC_WHITE,Standard_False);
2662 myAISContext->SetMaterial(aisBox2,Graphic3d_NOM_GOLD,Standard_False);
2663 myAISContext->SetTransparency(aisBox2,0.5,Standard_False);
2664 myAISContext->Display(aisBox2,Standard_False);
2665 Fit();
2666 Sleep(500);
2667
8013367c 2668 BRepOffsetAPI_MakeOffsetShape aShapeMaker2;
2669 aShapeMaker2.PerformByJoin(S2,-40,0.01,
2670 BRepOffset_Skin,Standard_False,Standard_False,GeomAbs_Arc);
2671 TopoDS_Shape anOffsetShape2 = aShapeMaker2.Shape();
7fd59977 2672
2673 Handle(AIS_Shape) ais2 = new AIS_Shape(anOffsetShape2);
0577ae8c 2674 myAISContext->SetColor (ais2, Quantity_NOC_MATRABLUE, Standard_False);
7fd59977 2675 myAISContext->SetMaterial(ais2,Graphic3d_NOM_GOLD,Standard_False);
0577ae8c 2676 myAISContext->Display (ais2, Standard_False);
7fd59977 2677 Fit();
2678
2679 TCollection_AsciiString Message ("\
2680 \n\
2681\n\
2682TopoDS_Shape S1 = BRepPrimAPI_MakeBox(150,200,110); \n\
2683\n\
2684TopoDS_Shape anOffsetShape1 = BRepPrimAPI_MakeOffsetShape(S1,60,0.01); \n\
2685\n\
2686//The white box \n\
2687 \n\
2688TopoDS_Shape S2 = BRepPrimAPI_MakeBox(gp_Pnt(300,0,0),220,140,180); \n\
2689\n\
2690TopoDS_Shape anOffsetShape2 = BRepPrimAPI_MakeOffsetShape(S2,-20,0.01, \n\
2691 BRepOffset_Skin,Standard_False,Standard_False,GeomAbs_Arc); \n\
2692 \n\
2693\n\
2694\n");
2695PocessTextInDialog("Make an offset shape", Message);
2696
2697}
2698
2699/* =================================================================================
2700 ==================== B U I L D I N G ========================================
2701 ================================================================================= */
2702
2703
2704void CModelingDoc::OnVertex()
2705{
2706 AIS_ListOfInteractive aList;
2707 myAISContext->DisplayedObjects(aList);
2708 AIS_ListIteratorOfListOfInteractive aListIterator;
2709 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2710 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2711 }
2712
2713 TopoDS_Vertex V1,V2,V3;
2714
2715 V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(0,0,0));
2716 V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10,7,25));
2717
2718 gp_Pnt P(-12,8,-4);
2719 BRepBuilderAPI_MakeVertex MV(P);
2720 V3 = MV.Vertex();
2721
2722 Handle(AIS_Shape) Point1 = new AIS_Shape(V1);
2723 myAISContext->Display(Point1,Standard_False);
2724 Handle(AIS_Shape) Point2 = new AIS_Shape(V2);
2725 myAISContext->Display(Point2,Standard_False);
2726 Handle(AIS_Shape) Point3 = new AIS_Shape(V3);
2727 myAISContext->Display(Point3,Standard_False);
2728
2729 Fit();
2730
2731 TCollection_AsciiString Message ("\
2732 \n\
2733TopoDS_Vertex V1,V2,V3; \n\
2734 \n\
2735V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(0,0,0)); \n\
2736 \n\
2737V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10,7,25)); \n\
2738 \n\
2739gp_Pnt P(-12,8,-4); \n\
2740BRepBuilderAPI_MakeVertex MV(P); \n\
2741V3 = MV.Vertex(); \n\
2742 \n\
2743\n");
2744
2745 PocessTextInDialog("Make vertex from point ", Message);
2746
2747}
2748
2749void CModelingDoc::OnEdge()
2750{
2751
2752 AIS_ListOfInteractive aList;
2753 myAISContext->DisplayedObjects(aList);
2754 AIS_ListIteratorOfListOfInteractive aListIterator;
2755 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2756 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2757 }
2758
2759
2760 TopoDS_Edge BlueEdge,YellowEdge,WhiteEdge,RedEdge,GreenEdge;
2761 TopoDS_Vertex V1,V2,V3,V4;
2762
2763/////////////The blue edge
2764
2765 BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80,-50,-20),gp_Pnt(-30,-60,-60));
2766
2767/////////////The yellow edge
2768
2769 V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30));
2770 V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10,7,-25));
2771 YellowEdge = BRepBuilderAPI_MakeEdge(V1,V2);
2772
2773/////////////The white edge
2774
2775 gp_Lin line(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0)));
2776 WhiteEdge = BRepBuilderAPI_MakeEdge(line,-20,10);
2777
2778//////////////The red edge
2779
2780 gp_Elips Elips(gp_Ax2(gp_Pnt(10,0,0),gp_Dir(1,1,1)),60,30);
42e4630c 2781 RedEdge = BRepBuilderAPI_MakeEdge(Elips,0,M_PI/2);
7fd59977 2782
2783/////////////The green edge and the both extreme vertex
2784
2785 gp_Pnt P1(-15,200,10);
2786 gp_Pnt P2(5,204,0);
2787 gp_Pnt P3(15,200,0);
2788 gp_Pnt P4(-15,20,15);
2789 gp_Pnt P5(-5,20,0);
2790 gp_Pnt P6(15,20,0);
2791 gp_Pnt P7(24,120,0);
2792 gp_Pnt P8(-24,120,12.5);
2793 TColgp_Array1OfPnt array(1,8);
2794 array.SetValue(1,P1);
2795 array.SetValue(2,P2);
2796 array.SetValue(3,P3);
2797 array.SetValue(4,P4);
2798 array.SetValue(5,P5);
2799 array.SetValue(6,P6);
2800 array.SetValue(7,P7);
2801 array.SetValue(8,P8);
2802 Handle (Geom_BezierCurve) curve = new Geom_BezierCurve(array);
2803
2804 BRepBuilderAPI_MakeEdge ME (curve);
2805 GreenEdge = ME;
2806 V3 = ME.Vertex1();
2807 V4 = ME.Vertex2();
2808
2809//////////////Display
2810Handle(AIS_Shape) blue = new AIS_Shape(BlueEdge);
2811myAISContext->SetColor(blue,Quantity_NOC_MATRABLUE,Standard_False);
2812myAISContext->Display(blue,Standard_False);
2813
2814Handle(AIS_Shape) yellow = new AIS_Shape(YellowEdge);
2815myAISContext->SetColor(yellow,Quantity_NOC_YELLOW,Standard_False);
2816myAISContext->Display(yellow,Standard_False);
2817
2818Handle(AIS_Shape) white = new AIS_Shape(WhiteEdge);
2819myAISContext->SetColor(white,Quantity_NOC_WHITE,Standard_False);
2820myAISContext->Display(white,Standard_False);
2821
2822Handle(AIS_Shape) red = new AIS_Shape(RedEdge);
2823myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False);
2824myAISContext->Display(red,Standard_False);
2825
2826Handle(AIS_Shape) green = new AIS_Shape(GreenEdge);
2827myAISContext->SetColor(green,Quantity_NOC_GREEN,Standard_False);
2828myAISContext->Display(green,Standard_False);
2829
2830Handle(AIS_Shape) Point1 = new AIS_Shape(V3);
2831myAISContext->Display(Point1,Standard_False);
2832Handle(AIS_Shape) Point2 = new AIS_Shape(V4);
2833myAISContext->Display(Point2,Standard_False);
2834
2835Fit();
2836
2837 TCollection_AsciiString Message ("\
2838 \n\
2839TopoDS_Edge BlueEdge, YellowEdge, WhiteEdge, RedEdge, GreenEdge; \n\
2840TopoDS_Vertex V1,V2,V3,V4; \n\
2841 \n\
2842/////////////The blue edge \n\
2843 \n\
2844BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80,-50,-20),gp_Pnt(-30,-60,-60)); \n\
2845 \n\
2846/////////////The yellow edge \n\
2847 \n\
2848V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30)); \n\
2849V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10,7,-25)); \n\
2850YellowEdge = BRepBuilderAPI_MakeEdge(V1,V2); \n\
2851 \n\
2852/////////////The white edge \n\
2853 \n\
2854gp_Lin line(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0))); \n\
2855WhiteEdge = BRepBuilderAPI_MakeEdge(line,-20,10); \n\
2856 \n\
2857//////////////The red edge \n\
2858 \n\
2859gp_Elips Elips(gp_Ax2(gp_Pnt(10,0,0),gp_Dir(1,1,1)),60,30); \n\
2860RedEdge = BRepBuilderAPI_MakeEdge(Elips,0,PI/2); \n\
2861 \n\
2862/////////////The green edge and the both extreme vertex \n\
2863 \n\
2864gp_Pnt P1(-15,200,10); \n\
2865gp_Pnt P2(5,204,0); \n\
2866gp_Pnt P3(15,200,0); \n\
2867gp_Pnt P4(-15,20,15); \n\
2868gp_Pnt P5(-5,20,0); \n\
2869gp_Pnt P6(15,20,0); \n\
2870gp_Pnt P7(24,120,0); \n\
2871gp_Pnt P8(-24,120,12.5); \n\
2872TColgp_Array1OfPnt array(1,8); \n\
2873array.SetValue(1,P1); \n\
2874array.SetValue(2,P2); \n\
2875array.SetValue(3,P3); \n\
2876array.SetValue(4,P4); \n\
2877array.SetValue(5,P5); \n\
2878array.SetValue(6,P6); \n\
2879array.SetValue(7,P7); \n\
2880array.SetValue(8,P8); \n\
2881Handle (Geom_BezierCurve) curve = new Geom_BezierCurve(array); \n\
2882 \n\
2883BRepBuilderAPI_MakeEdge ME (curve); \n\
2884GreenEdge = ME; \n\
2885V3 = ME.Vertex1(); \n\
2886V4 = ME.Vertex2(); \n\
2887 \n\
2888\n");
2889
2890 PocessTextInDialog("Make edge", Message);
2891
2892}
2893
2894void CModelingDoc::OnWire()
2895{
2896 AIS_ListOfInteractive aList;
2897 myAISContext->DisplayedObjects(aList);
2898 AIS_ListIteratorOfListOfInteractive aListIterator;
2899 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 2900 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 2901 }
2902
2903 TopoDS_Wire RedWire,YellowWire,WhiteWire,
2904 ExistingWire, ExistingWire2;
2905
2906 TopoDS_Edge Edge1,Edge2,Edge3,Edge4,Edge5,Edge6,Edge7,LastEdge;
2907 TopoDS_Vertex LastVertex;
2908
2909////////////The red wire is build from a single edge
2910
2911 gp_Elips Elips(gp_Ax2(gp_Pnt(250,0,0),gp_Dir(1,1,1)),160,90);
42e4630c 2912 Edge1 = BRepBuilderAPI_MakeEdge(Elips,0,M_PI/2);
7fd59977 2913
2914 RedWire = BRepBuilderAPI_MakeWire(Edge1);
2915
2916///////////the yellow wire is build from an existing wire and an edge
2917
2918 gp_Circ circle(gp_Ax2(gp_Pnt(-300,0,0),gp_Dir(1,0,0)),80);
42e4630c 2919 Edge2 = BRepBuilderAPI_MakeEdge(circle,0,M_PI);
7fd59977 2920
2921 ExistingWire = BRepBuilderAPI_MakeWire(Edge2);
2922
2923 Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(-300,0,-80),gp_Pnt(-90,20,-30));
2924
2925 BRepBuilderAPI_MakeWire MW1(ExistingWire,Edge3);
2926 if (MW1.IsDone()) {
2927 YellowWire = MW1;
2928 }
2929
2930
2931//////////the white wire is built with an existing wire and 3 edges.
2932//////////we use the methods Add, Edge and Vertex from BRepBuilderAPI_MakeWire.
2933
2934 gp_Circ circle2(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,1,0)),200);
42e4630c 2935 Edge4 = BRepBuilderAPI_MakeEdge(circle2,0,M_PI);
7fd59977 2936
2937 ExistingWire2 = BRepBuilderAPI_MakeWire(Edge4);
2938
2939 gp_Pnt P1(0,0,-200);
2940 gp_Pnt P2(5,204,0);
2941 Edge5 = BRepBuilderAPI_MakeEdge(P1,P2);
2942
2943 gp_Pnt P3(-15,20,15);
2944 Edge6 = BRepBuilderAPI_MakeEdge(P2,P3);
2945 gp_Pnt P4(15,20,0);
2946 Edge7 = BRepBuilderAPI_MakeEdge(P3,P4);
2947
2948 BRepBuilderAPI_MakeWire MW;
2949 MW.Add(ExistingWire2);
2950 MW.Add(Edge5);
2951 MW.Add(Edge6);
2952 MW.Add(Edge7);
2953
2954 if (MW.IsDone()) {
2955 WhiteWire = MW.Wire();
2956 LastEdge = MW.Edge();
2957 LastVertex = MW.Vertex();
2958 }
2959
2960
2961Handle(AIS_Shape) red = new AIS_Shape(RedWire);
2962myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False);
2963myAISContext->Display(red,Standard_False);
2964
2965Handle(AIS_Shape) yellow = new AIS_Shape(YellowWire);
2966myAISContext->SetColor(yellow,Quantity_NOC_YELLOW,Standard_False);
2967myAISContext->Display(yellow,Standard_False);
2968
2969Handle(AIS_Shape) white = new AIS_Shape(WhiteWire);
2970myAISContext->SetColor(white,Quantity_NOC_WHITE,Standard_False);
2971myAISContext->Display(white,Standard_False);
2972
2973Handle(AIS_Shape) lastE = new AIS_Shape(LastEdge);
2974myAISContext->SetWidth(lastE,3,Standard_False);
2975myAISContext->SetColor(lastE,Quantity_NOC_RED,Standard_False);
2976myAISContext->Display(lastE,Standard_False);
2977
2978Handle(AIS_Shape) lastV = new AIS_Shape(LastVertex);
2979myAISContext->Display(lastV,Standard_False);
2980
2981Fit();
2982
2983 TCollection_AsciiString Message ("\
2984 \n\
2985TopoDS_Wire RedWire,YellowWire,WhiteWire, \n\
2986ExistingWire, ExistingWire2; \n\
2987 \n\
2988TopoDS_Edge Edge1,Edge2,Edge3,Edge4,Edge5,Edge6,Edge7,LastEdge; \n\
2989TopoDS_Vertex LastVertex; \n\
2990 \n\
2991////////////The red wire is build from a single edge \n\
2992 \n\
2993gp_Elips Elips(gp_Ax2(gp_Pnt(10,0,0),gp_Dir(1,1,1)),160,90); \n\
2994Edge1 = BRepBuilderAPI_MakeEdge(Elips,0,PI/2); \n\
2995 \n\
2996RedWire = BRepBuilderAPI_MakeWire(Edge1); \n\
2997 \n\
2998///////////the yellow wire is build from an existing wire and an edge \n\
2999 \n\
3000gp_Circ circle(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),80); \n\
3001Edge2 = BRepBuilderAPI_MakeEdge(circle,0,PI); \n\
3002 \n\
3003ExistingWire = BRepBuilderAPI_MakeWire(Edge2); \n\
3004 \n\
3005Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,-80),gp_Pnt(90,20,30)); \n\
3006 \n\
3007BRepBuilderAPI_MakeWire MW1(ExistingWire,Edge3); \n\
3008if (MW1.IsDone()) { \n\
3009 YellowWire = MW1; \n\
3010} \n\
3011 \n\
3012///the white wire is built with an existing wire and 3 edges. \n\
3013///we use the methods Add, Edge and Vertex from BRepBuilderAPI_MakeWire \n\
3014///in order to display the last edge and the last vertices we \n\
3015///add to the wire. \n\
3016 \n\
3017gp_Circ circle2(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,1,0)),200); \n\
3018Edge4 = BRepBuilderAPI_MakeEdge(circle2,0,PI); \n\
3019 \n\
3020ExistingWire2 = BRepBuilderAPI_MakeWire(Edge4); \n\
3021 \n\
3022gp_Pnt P1(0,0,-200); \n\
3023gp_Pnt P2(5,204,0); \n\
3024Edge5 = BRepBuilderAPI_MakeEdge(P1,P2); \n\
3025 \n\
3026gp_Pnt P3(-15,20,15); \n\
3027Edge6 = BRepBuilderAPI_MakeEdge(P2,P3); \n\
3028gp_Pnt P4(15,20,0); \n\
3029Edge7 = BRepBuilderAPI_MakeEdge(P3,P4); \n\
3030 \n\
3031BRepBuilderAPI_MakeWire MW; \n\
3032MW.Add(ExistingWire2); \n\
3033MW.Add(Edge5); \n\
3034MW.Add(Edge6); \n\
3035MW.Add(Edge7); \n\
3036 \n\
3037if (MW.IsDone()) { \n\
3038 WhiteWire = MW.Wire(); \n\
3039 LastEdge = MW.Edge(); \n\
3040 LastVertex = MW.Vertex(); \n\
3041} \n\
3042 \n\
3043\n");
3044
3045 PocessTextInDialog("Make wire ", Message);
3046}
3047
3048void CModelingDoc::OnFace()
3049{
3050 AIS_ListOfInteractive aList;
3051 myAISContext->DisplayedObjects(aList);
3052 AIS_ListIteratorOfListOfInteractive aListIterator;
3053 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 3054 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 3055 }
3056
3057
3058
3059 TopoDS_Face WhiteFace, BrownFace, RedFace, PinkFace;
3060 TopoDS_Edge Edge1, Edge2, Edge3, Edge4, Edge5, Edge6, Edge7;
3061 TopoDS_Wire Wire1;
3062 gp_Pnt P1, P2, P3, P4, P5, P6, P7;
3063
3064 gp_Sphere sphere (gp_Ax3(gp_Pnt(0,0,0),gp_Dir(1,0,0)),150);
3065
3066 WhiteFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9);
3067
3068//////////////////////////////////
3069
3070 P1.SetCoord(-15,200,10);
3071 P2.SetCoord(5,204,0);
3072 P3.SetCoord(15,200,0);
3073 P4.SetCoord(-15,20,15);
3074 P5.SetCoord(-5,20,0);
3075 P6.SetCoord(15,20,35);
3076 TColgp_Array2OfPnt array(1,3,1,2);
3077 array.SetValue(1,1,P1);
3078 array.SetValue(2,1,P2);
3079 array.SetValue(3,1,P3);
3080 array.SetValue(1,2,P4);
3081 array.SetValue(2,2,P5);
3082 array.SetValue(3,2,P6);
3083 Handle (Geom_BSplineSurface) curve = GeomAPI_PointsToBSplineSurface(array,3,8,GeomAbs_C2,0.001);
3084
9181b66d 3085 RedFace = BRepBuilderAPI_MakeFace(curve, Precision::Confusion());
7fd59977 3086
3087////////////////////
3088
3089 gp_Circ circle(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),80);
42e4630c 3090 Edge1 = BRepBuilderAPI_MakeEdge(circle,0,M_PI);
7fd59977 3091
3092 Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,-80),gp_Pnt(0,-10,40));
3093 Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,-10,40),gp_Pnt(0,0,80));
3094
3095 TopoDS_Wire YellowWire;
3096 BRepBuilderAPI_MakeWire MW1(Edge1,Edge2,Edge3);
3097 if (MW1.IsDone()) {
3098 YellowWire = MW1;
3099 }
3100
3101 BrownFace = BRepBuilderAPI_MakeFace(YellowWire);
3102
3103
3104/////////////
3105
3106 P1.SetCoord(35,-200,40);
3107 P2.SetCoord(50,-204,30);
3108 P3.SetCoord(65,-200,30);
3109 P4.SetCoord(35,-20,45);
3110 P5.SetCoord(45,-20,30);
3111 P6.SetCoord(65,-20,65);
3112 TColgp_Array2OfPnt array2(1,3,1,2);
3113 array2.SetValue(1,1,P1);
3114 array2.SetValue(2,1,P2);
3115 array2.SetValue(3,1,P3);
3116 array2.SetValue(1,2,P4);
3117 array2.SetValue(2,2,P5);
3118 array2.SetValue(3,2,P6);
3119
3120 Handle (Geom_BSplineSurface) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2,3,8,GeomAbs_C2,0.001);
3121
9181b66d 3122 TopoDS_Face aFace = BRepBuilderAPI_MakeFace(BSplineSurf, Precision::Confusion());
7fd59977 3123
3124 //2d lines
3125 gp_Pnt2d P12d(0.9,0.1);
3126 gp_Pnt2d P22d(0.2,0.7);
3127 gp_Pnt2d P32d(0.02,0.1);
3128
3129 Handle (Geom2d_Line) line1 = new Geom2d_Line(P12d,gp_Dir2d((0.2-0.9),(0.7-0.1)));
3130 Handle (Geom2d_Line) line2 = new Geom2d_Line(P22d,gp_Dir2d((0.02-0.2),(0.1-0.7)));
3131 Handle (Geom2d_Line) line3 = new Geom2d_Line(P32d,gp_Dir2d((0.9-0.02),(0.1-0.1)));
3132
3133
3134 //Edges are on the BSpline surface
3135 Edge1 = BRepBuilderAPI_MakeEdge(line1,BSplineSurf,0,P12d.Distance(P22d));
3136 Edge2 = BRepBuilderAPI_MakeEdge(line2,BSplineSurf,0,P22d.Distance(P32d));
3137 Edge3 = BRepBuilderAPI_MakeEdge(line3,BSplineSurf,0,P32d.Distance(P12d));
3138
3139 Wire1 = BRepBuilderAPI_MakeWire(Edge1,Edge2,Edge3);
3140 Wire1.Reverse();
3141 PinkFace = BRepBuilderAPI_MakeFace(aFace,Wire1);
3142 BRepLib::BuildCurves3d(PinkFace);
3143
3144 BRepTools::Write(PinkFace,"E:\\temp\\PinkFace.rle");
3145
3146
3147/////////////Display
3148 Handle(AIS_Shape) white = new AIS_Shape(WhiteFace);
3149 myAISContext->SetColor(white,Quantity_NOC_WHITE,Standard_False);
3150 myAISContext->SetMaterial(white,Graphic3d_NOM_PLASTIC,Standard_False);
3151 myAISContext->Display(white,Standard_False);
3152
3153 Handle(AIS_Shape) red = new AIS_Shape(RedFace);
3154 myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False);
3155 myAISContext->SetMaterial(red,Graphic3d_NOM_PLASTIC,Standard_False);
3156 myAISContext->Display(red,Standard_False);
3157
3158 Handle(AIS_Shape) brown = new AIS_Shape(BrownFace);
3159 myAISContext->SetColor(brown,Quantity_NOC_BROWN,Standard_False);
3160 myAISContext->SetMaterial(brown,Graphic3d_NOM_PLASTIC,Standard_False);
3161 myAISContext->Display(brown,Standard_False);
3162
3163 Handle(AIS_Shape) pink = new AIS_Shape(PinkFace);
3164 myAISContext->SetColor(pink,Quantity_NOC_HOTPINK,Standard_False);
3165 myAISContext->SetMaterial(pink,Graphic3d_NOM_PLASTIC,Standard_False);
3166 myAISContext->Display(pink,Standard_False);
3167
3168 Fit();
3169
3170
3171 TCollection_AsciiString Message ("\
3172 \n\
3173TopoDS_Face WhiteFace, BrownFace, RedFace, PinkFace; \n\
3174TopoDS_Edge Edge1, Edge2, Edge3, Edge4, Edge5, Edge6, Edge7; \n\
3175TopoDS_Wire Wire1; \n\
3176gp_Pnt P1, P2, P3, P4, P5, P6, P7; \n\
3177\n\
3178////////The white Face \n\
3179\n\
3180gp_Sphere sphere (gp_Ax3(gp_Pnt(0,0,0),gp_Dir(1,0,0)),150); \n\
3181\n\
3182WhiteFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9); \n\
3183\n\
3184////////The red face \n\
3185\n\
3186P1.SetCoord(-15,200,10); \n\
3187P2.SetCoord(5,204,0); \n\
3188P3.SetCoord(15,200,0); \n\
3189P4.SetCoord(-15,20,15); \n\
3190P5.SetCoord(-5,20,0); \n\
3191P6.SetCoord(15,20,35); \n\
3192TColgp_Array2OfPnt array(1,3,1,2); \n\
3193array.SetValue(1,1,P1); \n\
3194array.SetValue(2,1,P2); \n\
3195array.SetValue(3,1,P3); \n\
3196array.SetValue(1,2,P4); \n\
3197array.SetValue(2,2,P5); \n\
3198array.SetValue(3,2,P6); \n\
3199Handle (Geom_BSplineSurface) curve = GeomAPI_PointsToBSplineSurface(array,3,8,GeomAbs_C2,0.001); \n\
3200\n\
3201RedFace = BRepBuilderAPI_MakeFace(curve); \n\
3202\n\
3203////////The brown face \n\
3204\n\
3205gp_Circ circle(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),80); \n\
3206Edge1 = BRepBuilderAPI_MakeEdge(circle,0,PI); \n\
3207\n\
3208Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,0,-80),gp_Pnt(0,-10,40)); \n\
3209Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0,-10,40),gp_Pnt(0,0,80)); \n\
3210\n\
3211TopoDS_Wire YellowWire; \n\
3212BRepBuilderAPI_MakeWire MW1(Edge1,Edge2,Edge3); \n\
3213if (MW1.IsDone()) { \n\
3214 YellowWire = MW1; \n\
3215} \n\
3216\n\
3217BrownFace = BRepBuilderAPI_MakeFace(YellowWire); \n\
3218\n");
3219Message +=("\
3220////////The pink face \n\
3221\n\
3222P1.SetCoord(35,-200,40); \n\
3223P2.SetCoord(50,-204,30); \n\
3224P3.SetCoord(65,-200,30); \n\
3225P4.SetCoord(35,-20,45); \n\
3226P5.SetCoord(45,-20,30); \n\
3227P6.SetCoord(65,-20,65); \n\
3228TColgp_Array2OfPnt array2(1,3,1,2); \n\
3229array2.SetValue(1,1,P1); \n\
3230array2.SetValue(2,1,P2); \n\
3231array2.SetValue(3,1,P3); \n\
3232array2.SetValue(1,2,P4); \n\
3233array2.SetValue(2,2,P5); \n\
3234array2.SetValue(3,2,P6); \n\
3235 \n\
3236Handle (Geom_BSplineSurface) BSplineSurf = GeomAPI_PointsToBSplineSurface(array2,3,8,GeomAbs_C2,0.001); \n\
3237 \n\
3238TopoDS_Face aFace = BRepBuilderAPI_MakeFace(BSplineSurf); \n\
3239\n\
3240//2d lines \n\
3241gp_Pnt2d P12d(0.9,0.1); \n\
3242gp_Pnt2d P22d(0.2,0.7); \n\
3243gp_Pnt2d P32d(0.02,0.1); \n\
3244\n\
3245Handle (Geom2d_Line) line1= \n\
3246 new Geom2d_Line(P12d,gp_Dir2d((0.2-0.9),(0.7-0.1))); \n\
3247Handle (Geom2d_Line) line2= \n\
3248 new Geom2d_Line(P22d,gp_Dir2d((0.02-0.2),(0.1-0.7))); \n\
3249Handle (Geom2d_Line) line3= \n\
3250 new Geom2d_Line(P32d,gp_Dir2d((0.9-0.02),(0.1-0.1))); \n\
3251 \n\
3252//Edges are on the BSpline surface \n\
3253Edge1 = BRepBuilderAPI_MakeEdge(line1,BSplineSurf,0,P12d.Distance(P22d)); \n\
3254Edge2 = BRepBuilderAPI_MakeEdge(line2,BSplineSurf,0,P22d.Distance(P32d)); \n\
3255Edge3 = BRepBuilderAPI_MakeEdge(line3,BSplineSurf,0,P32d.Distance(P12d)); \n\
3256\n\
3257Wire1 = BRepBuilderAPI_MakeWire(Edge1,Edge2,Edge3); \n\
3258Wire1.Reverse(); \n\
3259PinkFace = BRepBuilderAPI_MakeFace(aFace,Wire1); \n\
3260BRepLib::BuildCurves3d(PinkFace); \n\
3261\n\
3262\n");
3263
576f8b11 3264PocessTextInDialog("Make face ", Message);
7fd59977 3265}
3266
3267void CModelingDoc::OnShell()
3268{
3269 AIS_ListOfInteractive aList;
3270 myAISContext->DisplayedObjects(aList);
3271 AIS_ListIteratorOfListOfInteractive aListIterator;
3272 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 3273 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 3274 }
3275
3276 TColgp_Array2OfPnt Poles(1,2,1,4);
3277 Poles.SetValue(1,1,gp_Pnt(0,0,0));
3278 Poles.SetValue(1,2,gp_Pnt(0,10,2));
3279 Poles.SetValue(1,3,gp_Pnt(0,20,10));
3280 Poles.SetValue(1,4,gp_Pnt(0,30,0));
3281 Poles.SetValue(2,1,gp_Pnt(10,0,5));
3282 Poles.SetValue(2,2,gp_Pnt(10,10,3));
3283 Poles.SetValue(2,3,gp_Pnt(10,20,20));
3284 Poles.SetValue(2,4,gp_Pnt(10,30,0));
3285
3286 TColStd_Array1OfReal UKnots(1,2);
3287 UKnots.SetValue(1,0);
3288 UKnots.SetValue(2,1);
3289
3290 TColStd_Array1OfInteger UMults(1,2);
3291 UMults.SetValue(1,2);
3292 UMults.SetValue(2,2);
3293
3294 TColStd_Array1OfReal VKnots(1,3);
3295 VKnots.SetValue(1,0);
3296 VKnots.SetValue(2,1);
3297 VKnots.SetValue(3,2);
3298
3299 TColStd_Array1OfInteger VMults(1,3);
3300 VMults.SetValue(1,3);
3301 VMults.SetValue(2,1);
3302 VMults.SetValue(3,3);
3303
3304 Standard_Integer UDegree(1);
3305 Standard_Integer VDegree(2);
3306
3307 Handle (Geom_BSplineSurface) BSpline = new Geom_BSplineSurface(Poles,UKnots,VKnots,UMults,VMults,UDegree,VDegree);
3308
9181b66d 3309 TopoDS_Face WhiteFace = BRepBuilderAPI_MakeFace(BSpline, Precision::Confusion());
7fd59977 3310
3311
3312 Handle(AIS_Shape) white = new AIS_Shape(WhiteFace);
0577ae8c 3313 myAISContext->SetColor (white, Quantity_NOC_WHITE, Standard_False);
7fd59977 3314 myAISContext->SetMaterial(white,Graphic3d_NOM_PLASTIC,Standard_False);
0577ae8c 3315 myAISContext->SetTransparency (white, 0.7, Standard_False);
7fd59977 3316 myAISContext->Display(white,Standard_False);
3317
3318
3319 TopoDS_Shell aShell = BRepBuilderAPI_MakeShell(BSpline);
3320 Handle(AIS_Shape) anAISShell = new AIS_Shape(aShell);
0577ae8c 3321 myAISContext->SetDisplayMode (anAISShell, 0, Standard_False);
7fd59977 3322 myAISContext->Display(anAISShell,Standard_False);
404c8936 3323 //myAISContext->SetSelected(anAISShell);
7fd59977 3324
3325 Fit();
3326
3327 TCollection_AsciiString Message ("\
3328 \n\
3329TColgp_Array2OfPnt Poles(1,2,1,4); \n\
3330Poles.SetValue(1,1,gp_Pnt(0,0,0)); \n\
3331Poles.SetValue(1,2,gp_Pnt(0,10,2)); \n\
3332Poles.SetValue(1,3,gp_Pnt(0,20,10)); \n\
3333Poles.SetValue(1,4,gp_Pnt(0,30,0)); \n\
3334Poles.SetValue(2,1,gp_Pnt(10,0,5)); \n\
3335Poles.SetValue(2,2,gp_Pnt(10,10,3)); \n\
3336Poles.SetValue(2,3,gp_Pnt(10,20,20)); \n\
3337Poles.SetValue(2,4,gp_Pnt(10,30,0)); \n\
3338\n\
3339TColStd_Array1OfReal UKnots(1,2); \n\
3340UKnots.SetValue(1,0); \n\
3341UKnots.SetValue(2,1); \n\
3342\n\
3343TColStd_Array1OfInteger UMults(1,2); \n\
3344UMults.SetValue(1,2); \n\
3345UMults.SetValue(2,2); \n\
3346\n\
3347TColStd_Array1OfReal VKnots(1,3); \n\
3348VKnots.SetValue(1,0); \n\
3349VKnots.SetValue(2,1); \n\
3350VKnots.SetValue(3,2); \n\
3351\n\
3352TColStd_Array1OfInteger VMults(1,3); \n\
3353VMults.SetValue(1,3); \n\
3354VMults.SetValue(2,1); \n\
3355VMults.SetValue(3,3); \n\
3356\n\
3357Standard_Integer UDegree(1); \n\
3358Standard_Integer VDegree(2); \n\
3359 \n\
3360Handle (Geom_BSplineSurface) BSpline = new Geom_BSplineSurface(Poles,UKnots,VKnots,UMults,VMults,UDegree,VDegree); \n\
3361 \n\
3362TopoDS_Shell aShell = BRepBuilderAPI_MakeShell(BSpline); \n\
3363\n\
3364\n");
3365
576f8b11 3366 PocessTextInDialog("Make shell", Message);
7fd59977 3367
3368}
3369
3370void CModelingDoc::OnCompound()
3371{
3372 AIS_ListOfInteractive aList;
3373 myAISContext->DisplayedObjects(aList);
3374 AIS_ListIteratorOfListOfInteractive aListIterator;
3375 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 3376 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 3377 }
3378
3379 BRep_Builder builder;
3380 TopoDS_Compound Comp;
3381 builder.MakeCompound(Comp);
3382
3383 TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30));
3384 builder.Add(Comp,aVertex);
3385
3386 gp_Lin line(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0)));
3387 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(line,-20,10);
3388 builder.Add(Comp,anEdge);
3389
3390 gp_Sphere sphere (gp_Ax3(gp_Pnt(-80,0,0),gp_Dir(1,0,0)),150);
3391 TopoDS_Face aFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9);
3392 builder.Add(Comp,aFace);
3393
576f8b11 3394 TopoDS_Shape aBox = BRepPrimAPI_MakeBox(gp_Pnt(-60, 0, 0), 30, 60, 40).Shape();
7fd59977 3395 builder.Add(Comp,aBox);
3396
3397 Handle(AIS_Shape) white = new AIS_Shape(Comp);
0577ae8c 3398 myAISContext->SetDisplayMode (white, 0, Standard_False);
7fd59977 3399 myAISContext->Display(white,Standard_False);
3400
3401 Fit();
3402
3403
3404 TCollection_AsciiString Message ("\
3405 \n\
3406BRep_Builder builder; \n\
3407TopoDS_Compound Comp; \n\
3408builder.MakeCompound(Comp); \n\
3409\n\
3410TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(-20,10,-30)); \n\
3411builder.Add(Comp,aVertex); \n\
3412 \n\
3413gp_Lin line(gp_Ax1(gp_Pnt(10,10,10),gp_Dir(1,0,0))); \n\
3414TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(line,-20,10); \n\
3415builder.Add(Comp,anEdge); \n\
3416 \n\
3417gp_Sphere sphere (gp_Ax3(gp_Pnt(-80,0,0),gp_Dir(1,0,0)),150); \n\
3418TopoDS_Face aFace = BRepBuilderAPI_MakeFace(sphere,0.1,0.7,0.2,0.9); \n\
3419builder.Add(Comp,aFace); \n\
3420 \n\
3421TopoDS_Shape aBox = BRepPrimAPI_MakeBox(gp_Pnt(-60,0,0),30,60,40); \n\
3422builder.Add(Comp,aBox); \n\
3423 \n\
3424\n");
3425
3426 PocessTextInDialog("Make compound ", Message);
3427
3428}
3429
3430
3431
3432
3433
3434void CModelingDoc::OnSewing()
3435{
3436 AIS_ListOfInteractive aList;
3437 myAISContext->DisplayedObjects(aList);
3438 AIS_ListIteratorOfListOfInteractive aListIterator;
3439 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 3440 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 3441 }
3442
3443 gp_Pnt P(0,0,0);
3444 gp_Vec V(0,0,1);
3445 Handle(Geom_Plane) Pi=new Geom_Plane(P,V);
3446 Handle(Geom_RectangularTrimmedSurface) GeometricSurface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.);
9181b66d 3447 TopoDS_Shape FirstShape = BRepBuilderAPI_MakeFace(GeometricSurface, Precision::Confusion());
7fd59977 3448
3449 Handle(AIS_Shape) white1 = new AIS_Shape(FirstShape);
3450
3451 myAISContext->SetColor(white1,Quantity_NOC_RED,Standard_False);
3452 myAISContext->SetMaterial(white1,Graphic3d_NOM_PLASTIC,Standard_False);
3453 myAISContext->SetTransparency(white1,0.4,Standard_False);
3454 myAISContext->Display(white1,Standard_False);
3455 //Sleep(1000);
3456
3457 gp_Pnt P1(0,0,0);
3458 gp_Pnt P2(50,0,0);
3459 gp_Pnt P3(100,0,0);
3460 gp_Pnt P4(25,12,85);
3461 gp_Pnt P5(100,0,80);
3462 gp_Pnt P6(135,-12,85);
3463
3464 TColgp_Array2OfPnt Array(1,3,1,2);
3465 Array.SetValue(1,1,P1);
3466 Array.SetValue(2,1,P2);
3467 Array.SetValue(3,1,P3);
3468 Array.SetValue(1,2,P4);
3469 Array.SetValue(2,2,P5);
3470 Array.SetValue(3,2,P6);
3471
3472 Handle (Geom_BSplineSurface) aSurf = GeomAPI_PointsToBSplineSurface(Array,3,8,GeomAbs_C2,0.00001);
9181b66d 3473 TopoDS_Shape SecondShape = BRepBuilderAPI_MakeFace(aSurf, Precision::Confusion());
7fd59977 3474
3475 Handle(AIS_Shape) white2 = new AIS_Shape(SecondShape);
3476
3477 myAISContext->SetColor(white2,Quantity_NOC_YELLOW,Standard_False);
3478 myAISContext->SetMaterial(white2,Graphic3d_NOM_PLASTIC,Standard_False);
3479 myAISContext->SetTransparency(white2,0.4,Standard_False);
3480 myAISContext->Display(white2,Standard_False);
3481
3482 //Sleep(1000);
3483
3484 BRepOffsetAPI_Sewing aMethod;
3485 aMethod.Add(FirstShape);
3486 aMethod.Add(SecondShape);
3487
3488 aMethod.Perform();
3489
3490 TopoDS_Shape sewedShape = aMethod.SewedShape();
3491
3492 Handle(AIS_Shape) result = new AIS_Shape(sewedShape);
3493 myAISContext->SetDisplayMode(result,0,Standard_False);
3494 myAISContext->Display(result,Standard_False);
3495
3496 Fit();
3497
3498 TCollection_AsciiString Message ("\
3499 \n\
3500///////The first shape \n\
3501 \n\
3502gp_Pnt P(0,0,0); \n\
3503gp_Vec V(0,0,1); \n\
3504Handle(Geom_Plane) Pi=new Geom_Plane(P,V); \n\
3505Handle(Geom_RectangularTrimmedSurface) GeometricSurface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.); \n\
3506TopoDS_Shape FirstShape = BRepBuilderAPI_MakeFace(GeometricSurface); \n\
3507 \n\
3508///////The second shape \n\
3509 \n\
3510gp_Pnt P1(0,0,0); \n\
3511gp_Pnt P2(50,0,0); \n\
3512gp_Pnt P3(100,0,0); \n\
3513gp_Pnt P4(25,12,85); \n\
3514gp_Pnt P5(100,0,80); \n\
3515gp_Pnt P6(135,-12,85); \n\
3516\n\
3517TColgp_Array2OfPnt Array(1,3,1,2); \n\
3518Array.SetValue(1,1,P1); \n\
3519Array.SetValue(2,1,P2); \n\
3520Array.SetValue(3,1,P3); \n\
3521Array.SetValue(1,2,P4); \n\
3522Array.SetValue(2,2,P5); \n\
3523Array.SetValue(3,2,P6); \n\
3524\n\
3525Handle (Geom_BSplineSurface) aSurf = GeomAPI_PointsToBSplineSurface(Array,3,8,GeomAbs_C2,0.00001); \n\
3526TopoDS_Shape SecondShape = BRepBuilderAPI_MakeFace(aSurf); \n\
3527 \n\
3528BRepOffsetAPI_Sewing aMethod; \n\
3529aMethod.Add(FirstShape); \n\
3530aMethod.Add(SecondShape); \n\
3531\n\
3532aMethod.Perform(); \n\
3533\n\
3534TopoDS_Shape sewedShape = aMethod.SewedShape(); \n\
3535 \n\
3536\n");
3537
3538 PocessTextInDialog("Sew faces ", Message);
3539
3540}
3541
3542
3543
3544
3545
3546
3547
3548void CModelingDoc::OnBuilder()
3549{
3550 AIS_ListOfInteractive aList;
3551 myAISContext->DisplayedObjects(aList);
3552 AIS_ListIteratorOfListOfInteractive aListIterator;
3553 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 3554 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 3555 }
3556
3557 //The tolerance is the tolerance of confusion
3558 Standard_Real precision = Precision::Confusion();
3559
3560 //The builder
3561 BRep_Builder B;
3562
3563 //Build the vertices
3564 TopoDS_Vertex V000, V001, V010, V011, V100, V101, V110, V111;
3565 B.MakeVertex(V000,gp_Pnt(0,0,0),precision);
3566 B.MakeVertex(V001,gp_Pnt(0,0,100),precision);
3567 B.MakeVertex(V010,gp_Pnt(0,150,0),precision);
3568 B.MakeVertex(V011,gp_Pnt(0,150,100),precision);
3569 B.MakeVertex(V100,gp_Pnt(200,0,0),precision);
3570 B.MakeVertex(V101,gp_Pnt(200,0,100),precision);
3571 B.MakeVertex(V110,gp_Pnt(200,150,0),precision);
3572 B.MakeVertex(V111,gp_Pnt(200,150,100),precision);
3573
3574 //Build the edges
3575 //the edges are oriented as the axis X,Y,Z
3576 TopoDS_Edge EX00, EX01, EX10, EX11;
3577 TopoDS_Edge EY00, EY01, EY10, EY11;
3578 TopoDS_Edge EZ00, EZ01, EZ10, EZ11;
3579 Handle (Geom_Line) L;
3580
3581 //Edge X00
3582 L = new Geom_Line(gp_Pnt(0,0,0),gp_Dir(1,0,0));
3583 B.MakeEdge(EX00,L,precision);
3584 V000.Orientation(TopAbs_FORWARD);
3585 V100.Orientation(TopAbs_REVERSED);
3586 B.Add(EX00,V000);
3587 B.Add(EX00,V100);
3588 //Parameters
3589 B.UpdateVertex(V000,0,EX00,precision);
3590 B.UpdateVertex(V100,200,EX00,precision);
3591
3592 //Edge X10
3593 L = new Geom_Line(gp_Pnt(0,150,0),gp_Dir(1,0,0));
3594 B.MakeEdge(EX10,L,precision);
3595 V010.Orientation(TopAbs_FORWARD);
3596 V110.Orientation(TopAbs_REVERSED);
3597 B.Add(EX10,V010);
3598 B.Add(EX10,V110);
3599 //Parameters
3600 B.UpdateVertex(V010,0,EX10,precision);
3601 B.UpdateVertex(V110,200,EX10,precision);
3602
3603 //Edge Y00
3604 L = new Geom_Line(gp_Pnt(0,0,0),gp_Dir(0,1,0));
3605 B.MakeEdge(EY00,L,precision);
3606 V000.Orientation(TopAbs_FORWARD);
3607 V010.Orientation(TopAbs_REVERSED);
3608 B.Add(EY00,V000);
3609 B.Add(EY00,V010);
3610 //Parameters
3611 B.UpdateVertex(V000,0,EY00,precision);
3612 B.UpdateVertex(V010,150,EY00,precision);
3613
3614 //Edge Y10
3615 L = new Geom_Line(gp_Pnt(200,0,0),gp_Dir(0,1,0));
3616 B.MakeEdge(EY10,L,precision);
3617 V100.Orientation(TopAbs_FORWARD);
3618 V110.Orientation(TopAbs_REVERSED);
3619 B.Add(EY10,V100);
3620 B.Add(EY10,V110);
3621 //Parameters
3622 B.UpdateVertex(V100,0,EY10,precision);
3623 B.UpdateVertex(V110,150,EY10,precision);
3624
3625 //Edge Y01
3626 L = new Geom_Line(gp_Pnt(0,0,100),gp_Dir(0,1,0));
3627 B.MakeEdge(EY01,L,precision);
3628 V001.Orientation(TopAbs_FORWARD);
3629 V011.Orientation(TopAbs_REVERSED);
3630 B.Add(EY01,V001);
3631 B.Add(EY01,V011);
3632 //Parameters
3633 B.UpdateVertex(V001,0,EY01,precision);
3634 B.UpdateVertex(V011,150,EY01,precision);
3635
3636 //Edge Y11
3637 L = new Geom_Line(gp_Pnt(200,0,100),gp_Dir(0,1,0));
3638 B.MakeEdge(EY11,L,precision);
3639 V101.Orientation(TopAbs_FORWARD);
3640 V111.Orientation(TopAbs_REVERSED);
3641 B.Add(EY11,V101);
3642 B.Add(EY11,V111);
3643 //Parameters
3644 B.UpdateVertex(V101,0,EY11,precision);
3645 B.UpdateVertex(V111,150,EY11,precision);
3646
3647 //Edge Z00
3648 L = new Geom_Line(gp_Pnt(0,0,0),gp_Dir(0,0,1));
3649 B.MakeEdge(EZ00,L,precision);
3650 V000.Orientation(TopAbs_FORWARD);
3651 V001.Orientation(TopAbs_REVERSED);
3652 B.Add(EZ00,V000);
3653 B.Add(EZ00,V001);
3654 //Parameters
3655 B.UpdateVertex(V000,0,EZ00,precision);
3656 B.UpdateVertex(V001,100,EZ00,precision);
3657
3658 //Edge Z01
3659 L = new Geom_Line(gp_Pnt(0,150,0),gp_Dir(0,0,1));
3660 B.MakeEdge(EZ01,L,precision);
3661 V010.Orientation(TopAbs_FORWARD);
3662 V011.Orientation(TopAbs_REVERSED);
3663 B.Add(EZ01,V010);
3664 B.Add(EZ01,V011);
3665 //Parameters
3666 B.UpdateVertex(V010,0,EZ01,precision);
3667 B.UpdateVertex(V011,100,EZ01,precision);
3668
3669 //Edge Z10
3670 L = new Geom_Line(gp_Pnt(200,0,0),gp_Dir(0,0,1));
3671 B.MakeEdge(EZ10,L,precision);
3672 V100.Orientation(TopAbs_FORWARD);
3673 V101.Orientation(TopAbs_REVERSED);
3674 B.Add(EZ10,V100);
3675 B.Add(EZ10,V101);
3676 //Parameters
3677 B.UpdateVertex(V100,0,EZ10,precision);
3678 B.UpdateVertex(V101,100,EZ10,precision);
3679
3680 //Edge Z11
3681 L = new Geom_Line(gp_Pnt(200,150,0),gp_Dir(0,0,1));
3682 B.MakeEdge(EZ11,L,precision);
3683 V110.Orientation(TopAbs_FORWARD);
3684 V111.Orientation(TopAbs_REVERSED);
3685 B.Add(EZ11,V110);
3686 B.Add(EZ11,V111);
3687 //Parameters
3688 B.UpdateVertex(V110,0,EZ11,precision);
3689 B.UpdateVertex(V111,100,EZ11,precision);
3690
3691
3692 //Circular Edges
3693 Handle (Geom_Circle) C;
5c573e69 3694 //Standard_Real R = 100;
7fd59977 3695
3696 //Edge EX01
3697 C = new Geom_Circle(gp_Ax2(gp_Pnt(100,0,100),gp_Dir(0,1,0),gp_Dir(-1,0,0)),100);
3698 B.MakeEdge(EX01,C,precision);
3699 V001.Orientation(TopAbs_FORWARD);
3700 V101.Orientation(TopAbs_REVERSED);
3701 B.Add(EX01,V001);
3702 B.Add(EX01,V101);
3703 //Parameters
3704 B.UpdateVertex(V001,0,EX01,precision);
42e4630c 3705 B.UpdateVertex(V101,M_PI,EX01,precision);
7fd59977 3706
3707 //Edge EX11
3708 C = new Geom_Circle(gp_Ax2(gp_Pnt(100,150,100),gp_Dir(0,1,0),gp_Dir(-1,0,0)),100);
3709 B.MakeEdge(EX11,C,precision);
3710 V011.Orientation(TopAbs_FORWARD);
3711 V111.Orientation(TopAbs_REVERSED);
3712 B.Add(EX11,V011);
3713 B.Add(EX11,V111);
3714 //Parameters
3715 B.UpdateVertex(V011,0,EX11,precision);
42e4630c 3716 B.UpdateVertex(V111,M_PI,EX11,precision);
7fd59977 3717
3718 //Build wire and faces
3719 //Faces normals are along the axis X,Y,Z
3720 TopoDS_Face FXMIN, FXMAX, FYMIN, FYMAX, FZMIN, FZMAX;
3721 TopoDS_Wire W;
3722 Handle (Geom_Plane) P;
3723 Handle (Geom2d_Line) L2d;
3724 Handle (Geom2d_Circle) C2d;
3725 Handle (Geom_CylindricalSurface) S;
3726
3727 //Face FXMAX
3728 P = new Geom_Plane(gp_Ax2(gp_Pnt(200,0,0),gp_Dir(1,0,0),gp_Dir(0,1,0)));
3729 B.MakeFace(FXMAX,P,precision);
3730 //the wire and the edges
3731 B.MakeWire (W);
3732
3733 EY10.Orientation(TopAbs_FORWARD);
3734 B.Add(W,EY10);
3735 //pcurve
3736 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
3737 B.UpdateEdge(EY10,L2d,FXMAX,precision);
3738
3739 EZ11.Orientation(TopAbs_FORWARD);
3740 B.Add(W,EZ11);
3741 //pcurve
3742 L2d = new Geom2d_Line(gp_Pnt2d(150,0),gp_Dir2d(0,1));
3743 B.UpdateEdge(EZ11,L2d,FXMAX,precision);
3744
3745 EY11.Orientation(TopAbs_REVERSED);
3746 B.Add(W,EY11);
3747 //pcurve
3748 L2d = new Geom2d_Line(gp_Pnt2d(0,100),gp_Dir2d(1,0));
3749 B.UpdateEdge(EY11,L2d,FXMAX,precision);
3750
3751 EZ10.Orientation(TopAbs_REVERSED);
3752 B.Add(W,EZ10);
3753 //pcurve
3754 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3755 B.UpdateEdge(EZ10,L2d,FXMAX,precision);
3756
3757 B.Add(FXMAX,W);
3758
3759 BRepTools::Write(FXMAX,"E:\\temp\\f1.rle");
3760
3761 //Face FXMIN
3762 P = new Geom_Plane(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(-1,0,0),gp_Dir(0,0,1)));
3763 B.MakeFace(FXMIN,P,precision);
3764 //the wire and the edges
3765 B.MakeWire (W);
3766
3767 EZ00.Orientation(TopAbs_FORWARD);
3768 B.Add(W,EZ00);
3769 //pcurve
3770 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
3771 B.UpdateEdge(EZ00,L2d,FXMIN,precision);
3772
3773 EY01.Orientation(TopAbs_FORWARD);
3774 B.Add(W,EY01);
3775 //pcurve
3776 L2d = new Geom2d_Line(gp_Pnt2d(100,0),gp_Dir2d(0,1));
3777 B.UpdateEdge(EY01,L2d,FXMIN,precision);
3778
3779 EZ01.Orientation(TopAbs_REVERSED);
3780 B.Add(W,EZ01);
3781 //pcurve
3782 L2d = new Geom2d_Line(gp_Pnt2d(0,150),gp_Dir2d(1,0));
3783 B.UpdateEdge(EZ01,L2d,FXMIN,precision);
3784
3785 EY00.Orientation(TopAbs_REVERSED);
3786 B.Add(W,EY00);
3787 //pcurve
3788 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3789 B.UpdateEdge(EY00,L2d,FXMIN,precision);
3790
3791
3792 B.Add(FXMIN,W);
3793
3794 //Face FYMAX
3795
3796 P = new Geom_Plane(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,1,0),gp_Dir(0,0,1)));
3797 B.MakeFace(FYMAX,P,precision);
3798 //the wire and the edges
3799 B.MakeWire (W);
3800
3801 EZ00.Orientation(TopAbs_FORWARD);
3802 B.Add(W,EZ00);
3803 //pcurve
3804 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
3805 B.UpdateEdge(EZ00,L2d,FYMAX,precision);
3806
3807 EX01.Orientation(TopAbs_FORWARD);
3808 B.Add(W,EX01);
3809 //pcurve
3810 C2d = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(100,100),gp_Dir2d(0,-1)),100);
3811 B.UpdateEdge(EX01,C2d,FYMAX,precision);
3812 B.UpdateVertex(V001,0,EX01,FYMAX,precision);
42e4630c 3813 B.UpdateVertex(V101,M_PI,EX01,FYMAX,precision);
7fd59977 3814
3815 EZ10.Orientation(TopAbs_REVERSED);
3816 B.Add(W,EZ10);
3817 //pcurve
3818 L2d = new Geom2d_Line(gp_Pnt2d(0,200),gp_Dir2d(1,0));
3819 B.UpdateEdge(EZ10,L2d,FYMAX,precision);
3820
3821 EX00.Orientation(TopAbs_REVERSED);
3822 B.Add(W,EX00);
3823 //pcurve
3824 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3825 B.UpdateEdge(EX00,L2d,FYMAX,precision);
3826
3827
3828 B.Add(FYMAX,W);
3829
3830
3831
3832 //Face FYMIN
3833 P = new Geom_Plane(gp_Ax2(gp_Pnt(0,150,0),gp_Dir(0,1,0),gp_Dir(0,0,1)));
3834 B.MakeFace(FYMIN,P,precision);
3835 //the wire and the edges
3836 B.MakeWire (W);
3837
3838 EZ01.Orientation(TopAbs_FORWARD);
3839 B.Add(W,EZ01);
3840 //pcurve
3841 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
3842 B.UpdateEdge(EZ01,L2d,FYMIN,precision);
3843
3844 EX11.Orientation(TopAbs_FORWARD);
3845 B.Add(W,EX11);
3846 //pcurve
3847 C2d = new Geom2d_Circle(gp_Ax2d(gp_Pnt2d(100,100),gp_Dir2d(0,-1)),100);
3848 B.UpdateEdge(EX11,C2d,FYMIN,precision);
3849 B.UpdateVertex(V011,0,EX11,FYMIN,precision);
42e4630c 3850 B.UpdateVertex(V111,M_PI,EX11,FYMIN,precision);
7fd59977 3851
3852 EZ11.Orientation(TopAbs_REVERSED);
3853 B.Add(W,EZ11);
3854 //pcurve
3855 L2d = new Geom2d_Line(gp_Pnt2d(0,200),gp_Dir2d(1,0));
3856 B.UpdateEdge(EZ11,L2d,FYMIN,precision);
3857
3858 EX10.Orientation(TopAbs_REVERSED);
3859 B.Add(W,EX10);
3860 //pcurve
3861 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3862 B.UpdateEdge(EX10,L2d,FYMIN,precision);
3863
3864 B.Add(FYMIN,W);
3865
3866 //Face FZMAX
3867 P = new Geom_Plane(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,-1),gp_Dir(0,1,0)));
3868 B.MakeFace(FZMAX,P,precision);
3869 //the wire and the edges
3870 B.MakeWire (W);
3871
3872 EY00.Orientation(TopAbs_FORWARD);
3873 B.Add(W,EY00);
3874 //pcurve
3875 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
3876 B.UpdateEdge(EY00,L2d,FZMAX,precision);
3877
3878 EX10.Orientation(TopAbs_FORWARD);
3879 B.Add(W,EX10);
3880 //pcurve
3881 L2d = new Geom2d_Line(gp_Pnt2d(150,0),gp_Dir2d(0,1));
3882 B.UpdateEdge(EX10,L2d,FZMAX,precision);
3883
3884 EY10.Orientation(TopAbs_REVERSED);
3885 B.Add(W,EY10);
3886 //pcurve
3887 L2d = new Geom2d_Line(gp_Pnt2d(0,200),gp_Dir2d(1,0));
3888 B.UpdateEdge(EY10,L2d,FZMAX,precision);
3889
3890 EX00.Orientation(TopAbs_REVERSED);
3891 B.Add(W,EX00);
3892 //pcurve
3893 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3894 B.UpdateEdge(EX00,L2d,FZMAX,precision);
3895
3896
3897 B.Add(FZMAX,W);
3898
3899 //Face FZMIN
3900 S = new Geom_CylindricalSurface(gp_Ax3(gp_Pnt(100,0,100),gp_Dir(0,1,0),gp_Dir(-1,0,0)),100);
3901 B.MakeFace(FZMIN,S,precision);
3902
3903 //the wire and the edges
3904 B.MakeWire (W);
3905
3906 EX01.Orientation(TopAbs_FORWARD);
3907 B.Add(W,EX01);
3908 //pcurve
3909 L2d = new Geom2d_Line(gp_Ax2d(gp_Pnt2d(0,0),gp_Dir2d(1,0)));
3910 B.UpdateEdge(EX01,L2d,FZMIN,precision);
3911 B.UpdateVertex(V001,0,EX01,FZMIN,precision);
42e4630c 3912 B.UpdateVertex(V101,M_PI,EX01,FZMIN,precision);
7fd59977 3913
3914 EY11.Orientation(TopAbs_FORWARD);
3915 B.Add(W,EY11);
3916 //pcurve
42e4630c 3917 L2d = new Geom2d_Line(gp_Pnt2d(M_PI,0),gp_Dir2d(0,1));
7fd59977 3918 B.UpdateEdge(EY11,L2d,FZMIN,precision);
3919
3920 EX11.Orientation(TopAbs_REVERSED);
3921 B.Add(W,EX11);
3922 //pcurve
3923 L2d = new Geom2d_Line(gp_Ax2d(gp_Pnt2d(0,150),gp_Dir2d(1,0)));
3924 B.UpdateEdge(EX11,L2d,FZMIN,precision);
42e4630c 3925 B.UpdateVertex(V111,M_PI,EX11,FZMIN,precision);
7fd59977 3926 B.UpdateVertex(V011,0,EX11,FZMIN,precision);
3927
3928 EY01.Orientation(TopAbs_REVERSED);
3929 B.Add(W,EY01);
3930 //pcurve
3931 L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
3932 B.UpdateEdge(EY01,L2d,FZMIN,precision);
3933
3934 B.Add(FZMIN,W);
3935
3936 FYMAX.Orientation(TopAbs_REVERSED);
3937
3938 BRepTools::Write(FZMIN,"E:\\temp\\f3.rle");
3939 BRepTools::Write(FYMAX,"E:\\temp\\f2.rle");
3940
3941 //Shell
3942 TopoDS_Shell Sh;
3943 B.MakeShell(Sh);
3944 B.Add(Sh,FXMAX);
3945 B.Add(Sh,FXMIN);
3946 B.Add(Sh,FYMAX);
3947 B.Add(Sh,FYMIN);
3948 B.Add(Sh,FZMAX);
3949 B.Add(Sh,FZMIN);
3950
3951 // Solid
3952 TopoDS_Solid Sol;
3953 B.MakeSolid(Sol);
3954 B.Add(Sol,Sh);
3955
3956 BRepTools::Write(Sol,"e://temp//solid");
3957 Handle(AIS_Shape) borne = new AIS_Shape(Sol);
0577ae8c 3958 myAISContext->SetDisplayMode (borne, 1, Standard_False);
3959 myAISContext->SetColor (borne, Quantity_NOC_RED, Standard_False);
7fd59977 3960 myAISContext->SetMaterial(borne,Graphic3d_NOM_PLASTIC,Standard_False);
3961 myAISContext->Display(borne,Standard_False);
3962
3963
3964 Fit();
3965 TCollection_AsciiString Message ("\
3966 \n\
3967//The tolerance is 0.01 \n\
3968Standard_Real precision(0.01); \n\
3969\n\
3970//The builder \n\
3971BRep_Builder B; \n\
3972\n\
3973//Build the vertices \n\
3974TopoDS_Vertex V000, V001, V010, V011, V100, V101, V110, V111; \n\
3975B.MakeVertex(V000,gp_Pnt(0,0,0),precision); \n\
3976B.MakeVertex(V001,gp_Pnt(0,0,100),precision); \n\
3977B.MakeVertex(V010,gp_Pnt(0,150,0),precision); \n\
3978B.MakeVertex(V011,gp_Pnt(0,150,100),precision); \n\
3979B.MakeVertex(V100,gp_Pnt(200,0,0),precision); \n\
3980B.MakeVertex(V101,gp_Pnt(200,0,100),precision); \n\
3981B.MakeVertex(V110,gp_Pnt(200,150,0),precision); \n\
3982B.MakeVertex(V111,gp_Pnt(200,150,100),precision); \n\
3983\n\
3984//Build the edges \n\
3985//the edges are oriented as the axis X,Y,Z \n\
3986TopoDS_Edge EX00, EX01, EX10, EX11; \n\
3987TopoDS_Edge EY00, EY01, EY10, EY11; \n\
3988TopoDS_Edge EZ00, EZ01, EZ10, EZ11; \n\
3989Handle (Geom_Line) L; \n\
3990\n\
3991//Edge X00 \n\
3992L = new Geom_Line(gp_Pnt(0,0,0),gp_Dir(1,0,0)); \n\
3993B.MakeEdge(EX00,L,precision); \n\
3994V000.Orientation(TopAbs_FORWARD); \n\
3995V100.Orientation(TopAbs_REVERSED); \n\
3996B.Add(EX00,V000); \n\
3997B.Add(EX00,V100); \n\
3998//Parameters \n\
3999B.UpdateVertex(V000,0,EX00,precision); \n\
4000B.UpdateVertex(V100,200,EX00,precision); \n\
4001\n\
4002//Idem for all the linear edges... \n\
4003\n\
4004//Circular Edges \n\
4005Handle (Geom_Circle) C; \n\
4006Standard_Real R = 100; \n\
4007\n\
4008//Edge EX01 \n\
4009C = new Geom_Circle(gp_Ax2(gp_Pnt(100,0,100),gp_Dir(0,1,0),gp_Dir(-1,0,0)),100); \n\
4010B.MakeEdge(EX01,C,precision); \n\
4011V001.Orientation(TopAbs_FORWARD); \n\
4012V101.Orientation(TopAbs_REVERSED); \n\
4013B.Add(EX01,V001); \n\
4014B.Add(EX01,V101); \n\
4015//Parameters \n\
4016B.UpdateVertex(V001,0,EX01,precision); \n\
4017B.UpdateVertex(V101,PI,EX01,precision); \n\
4018\n\
4019//Idem for EX11 \n\
4020\n\
4021//Build wire and faces \n\
4022//Faces normals are along the axis X,Y,Z \n\
4023TopoDS_Face FXMIN, FXMAX, FYMIN, FYMAX, FZMIN, FZMAX; \n\
4024TopoDS_Wire W; \n\
4025Handle (Geom_Plane) P; \n\
4026Handle (Geom2d_Line) L2d; \n\
4027Handle (Geom2d_Circle) C2d; \n\
4028Handle (Geom_CylindricalSurface) S; \n\
4029\n\
4030//Face FXMAX \n\
4031P = new Geom_Plane(gp_Ax2(gp_Pnt(200,0,0),gp_Dir(1,0,0),gp_Dir(0,1,0))); \n\
4032B.MakeFace(FXMAX,P,precision); \n\
4033//the wire and the edges \n\
4034B.MakeWire (W); \n");
4035Message += ("\
4036\n\
4037EY10.Orientation(TopAbs_FORWARD); \n\
4038B.Add(W,EY10); \n\
4039//pcurve \n\
4040L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0)); \n\
4041B.UpdateEdge(EY10,L2d,FXMAX,precision); \n\
4042 \n\
4043EZ11.Orientation(TopAbs_FORWARD); \n\
4044B.Add(W,EZ11); \n\
4045//pcurve \n\
4046L2d = new Geom2d_Line(gp_Pnt2d(150,0),gp_Dir2d(0,1)); \n\
4047B.UpdateEdge(EZ11,L2d,FXMAX,precision); \n\
4048 \n\
4049EY11.Orientation(TopAbs_REVERSED); \n\
4050B.Add(W,EY11); \n\
4051//pcurve \n\
4052L2d = new Geom2d_Line(gp_Pnt2d(0,100),gp_Dir2d(1,0)); \n\
4053B.UpdateEdge(EY11,L2d,FXMAX,precision); \n\
4054 \n\
4055EZ10.Orientation(TopAbs_REVERSED); \n\
4056B.Add(W,EZ10); \n\
4057//pcurve \n\
4058L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1)); \n\
4059B.UpdateEdge(EZ10,L2d,FXMAX,precision); \n\
4060\n\
4061B.Add(FXMAX,W); \n\
4062\n\
4063//Idem for other faces... \n\
4064\n\
4065//Shell \n\
4066TopoDS_Shell Sh; \n\
4067B.MakeShell(Sh); \n\
4068B.Add(Sh,FXMAX); \n\
4069B.Add(Sh,FXMIN); \n\
4070B.Add(Sh,FYMAX); \n\
4071B.Add(Sh,FYMIN); \n\
4072B.Add(Sh,FZMAX); \n\
4073B.Add(Sh,FZMIN); \n\
4074\n\
4075// Solid \n\
4076TopoDS_Solid Sol; \n\
4077B.MakeSolid(Sol); \n\
4078B.Add(Sol,Sh); \n\
4079\n\
4080\n");
4081
4082PocessTextInDialog("Make a shape with a builder", Message);
4083
4084}
4085
4086void CModelingDoc::OnGeometrie()
4087{
4088 AIS_ListOfInteractive aList;
4089 myAISContext->DisplayedObjects(aList);
4090 AIS_ListIteratorOfListOfInteractive aListIterator;
4091 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4092 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4093 }
4094
4095 //geometrie of a vertex
4096 TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0,120,70));
4097 gp_Pnt GeometricPoint = BRep_Tool::Pnt(aVertex);
4098
4099 Handle(AIS_Shape) vert = new AIS_Shape(aVertex);
4100 myAISContext->Display(vert,Standard_False);
4101 Fit();
4102 Sleep (500);
4103
4104 //geometrie of an edge
4105 TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(100,50,250),gp_Pnt(-30,-100,-50));
4106 Handle(AIS_Shape) yellow = new AIS_Shape(anEdge);
4107 myAISContext->SetWidth(yellow,2,Standard_False);
4108 myAISContext->Display(yellow,Standard_False);
4109 Fit();
4110 Sleep (500);
4111
4112 TopLoc_Location location;
4113 Standard_Real first, last;
4114 Handle (Geom_Curve) aCurve = BRep_Tool::Curve(anEdge,location,first,last);
4115 TopoDS_Edge anEdgeDS = BRepBuilderAPI_MakeEdge(aCurve);
4116
4117 Handle (Geom_Line) aLine = Handle (Geom_Line)::DownCast(aCurve);
4118 if (!aLine.IsNull()) {
4119 Handle (AIS_Line) DispLine = new AIS_Line(aLine);
4120 myAISContext->Display(DispLine,Standard_False);
4121 Fit();
4122 Sleep (500);
4123 }
4124
4125 //geometrie of a face
4126 gp_Pnt P(-20,-20,-20);
4127 gp_Vec V(0,0,1);
4128 Handle(Geom_Plane) Pi=new Geom_Plane(P,V);
4129 Handle(Geom_RectangularTrimmedSurface) Surface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.);
9181b66d 4130 TopoDS_Face RedFace = BRepBuilderAPI_MakeFace(Surface, Precision::Confusion());
7fd59977 4131
4132 Handle(AIS_Shape) red = new AIS_Shape(RedFace);
4133 myAISContext->SetColor(red,Quantity_NOC_RED,Standard_False);
4134 myAISContext->SetMaterial(red,Graphic3d_NOM_PLASTIC,Standard_False);
4135 myAISContext->Display(red,Standard_False);
4136 Fit();
4137 Sleep (500);
4138
4139 TopLoc_Location location2;
4140 Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(RedFace,location2);
4141
4142 Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface);
4143 if (!aPlane.IsNull()) {
4144 Handle (AIS_Plane) DispPlane = new AIS_Plane(aPlane);
4145 myAISContext->Display(DispPlane,Standard_False);
4146
4147 }
4148
4149
4150 Fit();
4151 Sleep (500);
4152
4153
4154 TCollection_AsciiString Message ("\
4155 \n\
4156///////geometrie of a vertex \n\
4157TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0,120,70)); \n\
4158gp_Pnt GeometricPoint = BRep_Tool::Pnt(aVertex); \n\
4159\n\
4160///////geometrie of an edge \n\
4161TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(100,50,250),gp_Pnt(-30,-100,-50)); \n\
4162\n\
4163TopLoc_Location location; \n\
4164Standard_Real first, last; \n\
4165Handle (Geom_Curve) aCurve = BRep_Tool::Curve(anEdge,location,first,last); \n\
4166TopoDS_Edge anEdgeDS = BRepBuilderAPI_MakeEdge(aCurve); \n\
4167\n\
4168Handle (Geom_Line) aLine = Handle (Geom_Line)::DownCast(aCurve); \n\
4169if (!aLine.IsNull()) { \n\
4170 Handle (AIS_Line) DispLine = new AIS_Line(aLine); \n\
4171} \n\
4172 \n\
4173///////geometrie of a face \n\
4174gp_Pnt P(-20,-20,-20); \n\
4175gp_Vec V(0,0,1); \n\
4176Handle(Geom_Plane) Pi=new Geom_Plane(P,V); \n\
4177Handle(Geom_RectangularTrimmedSurface) Surface=new Geom_RectangularTrimmedSurface(Pi,0.,100.,0.,100.); \n\
4178TopoDS_Face RedFace = BRepBuilderAPI_MakeFace(Surface); \n\
4179\n\
4180TopLoc_Location location2; \n\
4181Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(RedFace,location2); \n\
4182\n\
4183Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface); \n\
4184if (!aPlane.IsNull()) { \n\
4185 Handle (AIS_Plane) DispPlane = new AIS_Plane(aPlane); \n\
4186} \n\
4187\n\
4188\n");
4189
4190 PocessTextInDialog("Recover the geometrie of vertex, edge and face ", Message);
4191
4192
4193}
4194
4195void CModelingDoc::OnExplorer()
4196{
4197 AIS_ListOfInteractive aList;
4198 myAISContext->DisplayedObjects(aList);
4199 AIS_ListIteratorOfListOfInteractive aListIterator;
4200 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4201 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4202 }
4203
576f8b11 4204 TopoDS_Shape aBox = BRepPrimAPI_MakeBox(100, 100, 100).Shape();
7fd59977 4205 Standard_Integer j(8);
4206 Handle(AIS_Shape) theBox = new AIS_Shape(aBox);
4207 myAISContext->SetColor(theBox,Quantity_NOC_RED,Standard_False);
4208 myAISContext->SetMaterial(theBox,Graphic3d_NOM_PLASTIC,Standard_False);
4209 myAISContext->Display(theBox,Standard_False);
4210 Fit();
4211 Sleep(500);
4212
4213 for (TopExp_Explorer exp (aBox,TopAbs_FACE);exp.More();exp.Next()) {
4214 TopoDS_Face aCurrentFace = TopoDS::Face(exp.Current());
4215
4216 //test the orientation of the current face
4217 TopAbs_Orientation orient = aCurrentFace.Orientation();
4218
4219 //Recover the geometric plane
4220 TopLoc_Location location;
4221 Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(aCurrentFace,location);
4222
4223 Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface);
4224
4225 //Build an AIS_Shape with a new color
4226 Handle(AIS_Shape) theMovingFace = new AIS_Shape(aCurrentFace);
4227 Quantity_NameOfColor aCurrentColor = (Quantity_NameOfColor)j;
4228 myAISContext->SetColor(theMovingFace,aCurrentColor,Standard_False);
4229 myAISContext->SetMaterial(theMovingFace,Graphic3d_NOM_PLASTIC,Standard_False);
4230 //Find the normal vector of each face
4231 gp_Pln agpPlane = aPlane->Pln();
4232 gp_Ax1 norm = agpPlane.Axis();
4233 gp_Dir dir = norm.Direction();
4234 gp_Vec move(dir);
4235 //Connect
4236// new in 2.0 ... AIS_ConnectedInteractive wants a TopLoc_Location instead of a Geom_Transformation
4237// TopLoc_Location aLocation;
4238// Handle (AIS_ConnectedInteractive) theTransformedDisplay = new AIS_ConnectedInteractive();
4239// theTransformedDisplay->Connect(theMovingFace,theMove);
4240// theTransformedDisplay->Connect(theMovingFace, aLocation);
4241// Handle (Geom_Transformation) theMove = new Geom_Transformation(aLocation->Transformation());
4242// new in 2.0
4243// myAISContext->Display(theTransformedDisplay);
4244
4245 TopLoc_Location aLocation;
4246 Handle (AIS_ConnectedInteractive) theTransformedDisplay = new AIS_ConnectedInteractive();
4247 theTransformedDisplay->Connect(theMovingFace, aLocation);
4248
4249
4250 // = myAISContext->Location(theMovingFace);
4251 Handle (Geom_Transformation) theMove = new Geom_Transformation(aLocation.Transformation());
4252 myAISContext->Display(theTransformedDisplay,Standard_False);
4253 Fit();
4254 Sleep (500);
4255
4256 for (Standard_Integer i=1;i<=30;i++) {
4257
4258 //Build a transformation on the display
4259// theMove->SetTranslation(move*i);
4260
4261// if (orient==TopAbs_FORWARD) theTransformedDisplay->SetTransformation(theMove);
4262// else theTransformedDisplay->SetTransformation(theMove->Inverted());
4263
4264// myAISContext->Redisplay(theTransformedDisplay);
4265
4266// new in 2.0
4267 theMove->SetTranslation(move*i);
4268 if (orient==TopAbs_FORWARD) myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Trsf()));
4269 else myAISContext->SetLocation(theTransformedDisplay,TopLoc_Location(theMove->Inverted()->Trsf()));
4270
4271 myAISContext->Redisplay(theTransformedDisplay,Standard_False);
4272 }
4273 j+=15;
4274 }
4275 //myAISContext->Erase(theBox,Standard_True,Standard_False);
0577ae8c 4276 myAISContext->Remove(theBox, Standard_False);
7fd59977 4277 Fit();
4278 Sleep (500);
4279
4280 TCollection_AsciiString Message ("\
4281\n\
4282TopoDS_Shape aBox = BRepPrimAPI_MakeBox(100,100,100); \n\
4283\n\
4284for (TopExp_Explorer exp (aBox,TopAbs_FACE);exp.More();exp.Next()) { \n\
4285 TopoDS_Face aCurrentFace = TopoDS::Face(exp.Current()); \n\
4286\n\
4287 //Recover the geometric plane \n\
4288 TopLoc_Location location; \n\
4289 Handle (Geom_Surface) aGeometricSurface = BRep_Tool::Surface(aCurrentFace,location); \n\
4290\n\
4291 Handle (Geom_Plane) aPlane = Handle (Geom_Plane)::DownCast(aGeometricSurface); \n\
4292 \n\
4293\n");
4294 PocessTextInDialog("Explode a shape in faces ", Message);
4295
4296}
4297
4298/* =================================================================================
4299 ==================== A N A L Y S I S ========================================
4300 ================================================================================= */
4301
4302void CModelingDoc::OnValid()
4303{
4304 AIS_ListOfInteractive aList;
4305 myAISContext->DisplayedObjects(aList);
4306 AIS_ListIteratorOfListOfInteractive aListIterator;
4307 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4308 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4309 }
4310
576f8b11 4311 TopoDS_Shape S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape();
7fd59977 4312 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
4313 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
4314 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
4315 myAISContext->Display(ais1,Standard_False);
4316 Fit();
4317
4318 TCollection_AsciiString Message ("\
4319 \n\
4320TopoDS_Shape S = BRepPrimI_MakeBox(200.,300.,150.);\n\
4321Standard_Boolean theShapeIsValid = BRepAlgo::IsValid(S);\n\
4322if ( theShapeIsValid )\n\
4323{\n\
4324 MessageBox(\"The Shape Is Valid !! \",\"Checking Shape\");\n\
4325}\n\
4326else\n\
4327{\n\
4328 MessageBox(\"The Shape Is NOT Valid !! \",\"Checking Shape\");\n\
4329}\n\
4330\n");
4331 PocessTextInDialog("Check a shape", Message);
4332
4333 Standard_Boolean theShapeIsValid = BRepAlgo::IsValid(S);
576f8b11 4334 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, theShapeIsValid ? L"The Shape Is Valid !! " : L"The Shape Is NOT Valid !! ", L"Checking Shape", MB_OK);
7fd59977 4335}
4336
4337
4338void CModelingDoc::OnLinear()
4339{
4340 AIS_ListOfInteractive aList;
4341 myAISContext->DisplayedObjects(aList);
4342 AIS_ListIteratorOfListOfInteractive aListIterator;
4343 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4344 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4345 }
4346
4347
4348 TColgp_Array1OfPnt Points1(1,4);
4349 Points1.SetValue(1,gp_Pnt(0,0,0));
4350 Points1.SetValue(2,gp_Pnt(2,1,0));
4351 Points1.SetValue(3,gp_Pnt(4,0,0));
4352 Points1.SetValue(4,gp_Pnt(6,2,0));
4353 GeomAPI_PointsToBSpline PTBS1(Points1);
4354 Handle(Geom_BSplineCurve) BSC1 = PTBS1.Curve();
4355 TopoDS_Edge S = BRepBuilderAPI_MakeEdge(BSC1).Edge();
4356
4357 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
4358 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
4359 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
4360 myAISContext->Display(ais1,Standard_False);
4361 Fit();
4362
4363
4364 GProp_GProps System;
4365 BRepGProp::LinearProperties(S,System);
4366 gp_Pnt G = System.CentreOfMass ();
4367 Standard_Real Length = System.Mass();
4368 gp_Mat I = System.MatrixOfInertia();
4369
576f8b11 4370 TCollection_ExtendedString string("Length Of all the Edges =");
4371 TCollection_ExtendedString string1(Length);
7fd59977 4372
4373 string += string1;
4374 string += "\nCenterOfMass : \n X=";
4375 string1 = G.X();
4376 string += string1;
4377 string += " Y=";
4378 string1 = G.Y();
4379 string += string1;
4380 string += " Z=";
4381 string1 = G.Z();
4382 string += string1;
4383 string +="\n";
4384
4385 string += "Matrix of Inertia :\n ";
4386 string1 = I(1,1);
4387 string += string1;
4388 string += " " ;
4389 string1 = I(1,2);
4390 string += string1;
4391 string += " " ;
4392 string1 = I(1,3);
4393 string += string1;
4394 string += "\n " ;
4395 string1 = I(2,1);
4396 string += string1;
4397 string += " " ;
4398 string1 = I(2,2);
4399 string += string1;
4400 string += " " ;
4401 string1 = I(2,3);
4402 string += string1;
4403 string += "\n " ;
4404 string1 = I(3,1);
4405 string += string1;
4406 string += " " ;
4407 string1 = I(3,2);
4408 string += string1;
4409 string += " " ;
4410 string1 = I(3,3);
4411 string += string1;
4412 string += "\n" ;
576f8b11 4413
4414 TCollection_AsciiString Message ("\
7fd59977 4415 \n\
4416TColgp_Array1OfPnt Points1(1,4);\n\
4417Points1.SetValue(1,gp_Pnt(0,0,0));\n\
4418Points1.SetValue(2,gp_Pnt(2,1,0));\n\
4419Points1.SetValue(3,gp_Pnt(4,0,0));\n\
4420Points1.SetValue(4,gp_Pnt(6,2,0));\n\
4421GeomAPI_PointsToBSpline PTBS1(Points1);\n\
4422Handle(Geom_BSplineCurve) BSC1 = PTBS1.Curve();\n\
4423TopoDS_Shape S = BRepBuilderAPI_MakeEdge(BSC1).Edge();\n\
4424GProp_GProps System;\n\
4425BRepGProp::LinearProperties(S,System);\n\
4426gp_Pnt G = System.CentreOfMass ();\n\
4427Standard_Real Length = System.Mass();\n\
4428gp_Mat I = System.MatrixOfInertia();\n\
4429\n");
4430 PocessTextInDialog("Linear Properties", Message);
e620e285 4431 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, string.ToWideString(), L"Linear Properties", MB_OK);
7fd59977 4432}
4433
4434void CModelingDoc::OnSurface()
4435{
4436 AIS_ListOfInteractive aList;
4437 myAISContext->DisplayedObjects(aList);
4438 AIS_ListIteratorOfListOfInteractive aListIterator;
4439 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4440 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4441 }
4442
4443 TColgp_Array1OfPnt Pnts1(1,3);
4444 TColgp_Array1OfPnt Pnts2(1,3);
4445 TColgp_Array1OfPnt Pnts3(1,3);
4446 TColgp_Array1OfPnt Pnts4(1,3);
4447
4448 Pnts1(1) = gp_Pnt(0,0,0);
4449 Pnts1(2) = gp_Pnt(5,0,0);
4450 Pnts1(3) = gp_Pnt(10,10,0);
4451
4452 Pnts2(1) = gp_Pnt(10,10,0);
4453 Pnts2(2) = gp_Pnt(5,12,4);
4454 Pnts2(3) = gp_Pnt(0,15,10);
4455
4456 Pnts3(1) = gp_Pnt(0,15,10);
4457 Pnts3(2) = gp_Pnt(-12,10,11);
4458 Pnts3(3) = gp_Pnt(-10,5,13);
4459
4460 Pnts4(1) = gp_Pnt(-10,5,13);
4461 Pnts4(2) = gp_Pnt(-2,-2,2);
4462 Pnts4(3) = gp_Pnt(0,0,0);
4463
4464 GeomAPI_PointsToBSpline PTBS1(Pnts1);
4465 GeomAPI_PointsToBSpline PTBS2(Pnts2);
4466 GeomAPI_PointsToBSpline PTBS3(Pnts3);
4467 GeomAPI_PointsToBSpline PTBS4(Pnts4);
4468 Handle(Geom_BSplineCurve) C1 = PTBS1.Curve();
4469 Handle(Geom_BSplineCurve) C2 = PTBS2.Curve();
4470 Handle(Geom_BSplineCurve) C3 = PTBS3.Curve();
4471 Handle(Geom_BSplineCurve) C4 = PTBS4.Curve();
4472
4473 GeomFill_BSplineCurves fill;
4474 fill.Init(C1,C2,C3,C4,GeomFill_CoonsStyle);
4475 Handle(Geom_BSplineSurface) BSS = fill.Surface();
4476
9181b66d 4477 TopoDS_Shape S = BRepBuilderAPI_MakeFace(BSS, Precision::Confusion()).Face();
7fd59977 4478
4479 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
4480 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
4481 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
4482 myAISContext->Display(ais1,Standard_False);
4483 Fit();
4484
4485
4486 GProp_GProps System;
4487 BRepGProp::SurfaceProperties(S,System);
4488 gp_Pnt G = System.CentreOfMass ();
4489 Standard_Real Area = System.Mass();
4490 gp_Mat I = System.MatrixOfInertia();
4491
576f8b11 4492 TCollection_ExtendedString string("Area Of the Face =");
4493 TCollection_ExtendedString string1(Area);
7fd59977 4494
4495 string += string1;
4496 string += "\nCenterOfMass : \n X=";
4497 string1 = G.X();
4498 string += string1;
4499 string += " Y=";
4500 string1 = G.Y();
4501 string += string1;
4502 string += " Z=";
4503 string1 = G.Z();
4504 string += string1;
4505 string +="\n";
4506
4507 string += "Matrix of Inertia :\n ";
4508 string1 = I(1,1);
4509 string += string1;
4510 string += " " ;
4511 string1 = I(1,2);
4512 string += string1;
4513 string += " " ;
4514 string1 = I(1,3);
4515 string += string1;
4516 string += "\n " ;
4517 string1 = I(2,1);
4518 string += string1;
4519 string += " " ;
4520 string1 = I(2,2);
4521 string += string1;
4522 string += " " ;
4523 string1 = I(2,3);
4524 string += string1;
4525 string += "\n " ;
4526 string1 = I(3,1);
4527 string += string1;
4528 string += " " ;
4529 string1 = I(3,2);
4530 string += string1;
4531 string += " " ;
4532 string1 = I(3,3);
4533 string += string1;
4534 string += "\n" ;
576f8b11 4535
4536 TCollection_AsciiString Message ("\
7fd59977 4537 \n\
4538TopoDS_Shape S = BRepBuilderAPI_MakeFace(BSplineSurf).Face();\n\
4539GProp_GProps System;\n\
4540BRepGProp::SurfaceProperties(S,System);\n\
4541gp_Pnt G = System.CentreOfMass ();\n\
4542Standard_Real Area = System.Mass();\n\
4543gp_Mat I = System.MatrixOfInertia();\n\
4544\n");
576f8b11 4545 PocessTextInDialog("Surface Properties", Message);
e620e285 4546 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, string.ToWideString(), L"Surface Properties", MB_OK);
7fd59977 4547
4548}
4549
4550void CModelingDoc::OnVolume()
4551{
4552 AIS_ListOfInteractive aList;
4553 myAISContext->DisplayedObjects(aList);
4554 AIS_ListIteratorOfListOfInteractive aListIterator;
4555 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4556 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4557 }
4558
4559
576f8b11 4560 TopoDS_Shape S = BRepPrimAPI_MakeWedge(60.,100.,80.,20.).Shape();
7fd59977 4561 Handle(AIS_Shape) ais1 = new AIS_Shape(S);
4562 myAISContext->SetColor(ais1,Quantity_NOC_GREEN,Standard_False);
4563 myAISContext->SetMaterial(ais1,Graphic3d_NOM_PLASTIC,Standard_False);
4564 myAISContext->Display(ais1,Standard_False);
4565 Fit();
4566
4567
4568 GProp_GProps System;
4569 BRepGProp::VolumeProperties(S,System);
4570 gp_Pnt G = System.CentreOfMass ();
4571 Standard_Real Volume = System.Mass();
4572 gp_Mat I = System.MatrixOfInertia();
4573
576f8b11 4574 TCollection_ExtendedString string("Volume Of all the Shape =");
4575 TCollection_ExtendedString string1(Volume);
7fd59977 4576
4577 string += string1;
4578 string += "\nCenterOfMass : \n X=";
4579 string1 = G.X();
4580 string += string1;
4581 string += " Y=";
4582 string1 = G.Y();
4583 string += string1;
4584 string += " Z=";
4585 string1 = G.Z();
4586 string += string1;
4587 string +="\n";
4588
4589 string += "Matrix of Inertia :\n ";
4590 string1 = I(1,1);
4591 string += string1;
4592 string += " " ;
4593 string1 = I(1,2);
4594 string += string1;
4595 string += " " ;
4596 string1 = I(1,3);
4597 string += string1;
4598 string += "\n " ;
4599 string1 = I(2,1);
4600 string += string1;
4601 string += " " ;
4602 string1 = I(2,2);
4603 string += string1;
4604 string += " " ;
4605 string1 = I(2,3);
4606 string += string1;
4607 string += "\n " ;
4608 string1 = I(3,1);
4609 string += string1;
4610 string += " " ;
4611 string1 = I(3,2);
4612 string += string1;
4613 string += " " ;
4614 string1 = I(3,3);
4615 string += string1;
4616 string += "\n" ;
576f8b11 4617
7fd59977 4618 TCollection_AsciiString Message ("\
4619 \n\
4620TopoDS_Shape S = BRepBuilderAPI_MakeWedge(60.,100.,80.,20.);;\n\
4621GProp_GProps System;\n\
4622BRepGProp::VolumeProperties(S,System);\n\
4623gp_Pnt G = System.CentreOfMass ();\n\
4624Standard_Real Volume = System.Mass();\n\
4625gp_Mat I = System.MatrixOfInertia();\n\
4626\n");
576f8b11 4627 PocessTextInDialog("Volume Properties", Message);
e620e285 4628 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, string.ToWideString(), L"Volume Properties", MB_OK);
7fd59977 4629}
4630
4631
4632void CModelingDoc::OnButtonFill()
4633{
4634 // TODO: Add your command handler code here
404c8936 4635 myAISContext->InitSelected();
4636 if (myAISContext->MoreSelected()) {
4637 AIS1 = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive());
0577ae8c 4638 myAISContext->Unhilight (AIS1, Standard_True);
7fd59977 4639 myAISContext->Activate(AIS1,2);
4640 myState = SELECT_EDGE_PLATE;
4641 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select hole contour edges and then press right mouse button"); }
4642 else {
4643 AIS_ListOfInteractive LI;
4644 myAISContext->DisplayedObjects(LI);
4645 if(LI.IsEmpty()){
576f8b11 4646 if(OnFileImportBrep_WithInitDir (L"HoleFilling") == 1)
7fd59977 4647 return;
4648 myAISContext->DisplayedObjects(LI);
0577ae8c 4649 myAISContext->SetSelected(LI.First(), Standard_True);
7fd59977 4650 OnButtonFill();
4651 return;
4652 }
576f8b11 4653 AfxMessageBox (L"Select a shape before!");
7fd59977 4654 }
4655}
4656
4657void CModelingDoc::OnStopStop()
4658{
4659 // TODO: Add your command handler code here
4660 // Stop selection
4661 if (myState == SELECT_EDGE_PLATE ) {
4662 Standard_Integer nbedges = 0;
4663 for (myAISContext->InitSelected(); myAISContext->MoreSelected();
4664 myAISContext->NextSelected()) {
4665 nbedges++;
4666
4667 }
4668 Handle(GeomPlate_HArray1OfHCurveOnSurface) Fronts =
4669 new GeomPlate_HArray1OfHCurveOnSurface(1,nbedges);
4670 Handle(TColStd_HArray1OfInteger) Tang =
4671 new TColStd_HArray1OfInteger(1,nbedges);
4672 Handle(TColStd_HArray1OfInteger) NbPtsCur =
4673 new TColStd_HArray1OfInteger(1,nbedges);
4674 Standard_Integer i = 0;
4675 TopoDS_Shape S1 = AIS1->Shape();
4676 TopTools_IndexedDataMapOfShapeListOfShape M;
4677 TopExp::MapShapesAndAncestors(S1, TopAbs_EDGE, TopAbs_FACE, M);
4678
4679 for (myAISContext->InitSelected(); myAISContext->MoreSelected();myAISContext->NextSelected()) {
4680 i++;
4681 Tang->SetValue(i,1);
4682 NbPtsCur->SetValue(i,10);
4683 TopoDS_Edge E = TopoDS::Edge(myAISContext->SelectedShape());
4684 TopoDS_Face F = TopoDS::Face(M.FindFromKey(E).First());
4685
4686 BRepAdaptor_Surface S(F);
4687 GeomAdaptor_Surface aGAS = S.Surface();
4688 Handle(GeomAdaptor_HSurface) aHGAS = new GeomAdaptor_HSurface(aGAS);
4689
4690 Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d();
4691 C->ChangeCurve2d().Initialize(E,F);
4692
4693 Adaptor3d_CurveOnSurface ConS(C,aHGAS);
4694
4695 Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS);
4696 Fronts->SetValue(i,HConS);
4697 }
4698 GeomPlate_BuildPlateSurface abuildplate(NbPtsCur,Fronts,Tang,3);
4699 abuildplate.Perform();
4700 if (!abuildplate.IsDone()){ // New in 2.0
576f8b11 4701 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Build plate not valid!", L"CasCade Error", MB_ICONERROR);
7fd59977 4702 return;
4703 }
4704 Handle(GeomPlate_Surface) aplate = abuildplate.Surface();
4705
4706 GeomPlate_MakeApprox aMKS(aplate, Precision::Approximation(), 4, 7, 0.001, 1);
4707 Handle(Geom_BSplineSurface) support = aMKS.Surface();
4708 BRepBuilderAPI_MakeWire MW;
4709 TopTools_Array1OfShape tab(1,nbedges);
4710 for (i=1 ; i<=nbedges ; i++) {
4711 if (abuildplate.Sense()->Value(abuildplate.Order()->Value(i))==1) {
4712 BRepBuilderAPI_MakeEdge ME(abuildplate.Curves2d()->Value(abuildplate.Order()->Value(i)),
4713 support,
4714 Fronts->Value(abuildplate.Order()->Value(i))->LastParameter(),
4715 Fronts->Value(abuildplate.Order()->Value(i))->FirstParameter());
4716 TopoDS_Edge E = ME.Edge();
4717 BRepLib::BuildCurves3d(E);
4718 tab(abuildplate.Order()->Value(i)) = E;
4719 //MW.Add(E);
4720 }
4721 else {
4722 BRepBuilderAPI_MakeEdge ME(abuildplate.Curves2d()->Value(abuildplate.Order()->Value(i)),
4723 support,
4724 Fronts->Value(abuildplate.Order()->Value(i))->FirstParameter(),
4725 Fronts->Value(abuildplate.Order()->Value(i))->LastParameter());
4726 TopoDS_Edge E = ME.Edge();
4727 BRepLib::BuildCurves3d(E);
4728 tab(abuildplate.Order()->Value(i)) = E;
4729 }
4730 }
4731 for (i=1 ; i<=nbedges ; i++)
4732 MW.Add(TopoDS::Edge(tab(i)));
4733 TopoDS_Wire W;
4734 try{
4735 W=MW.Wire();
4736 }
4737
4738 catch(StdFail_NotDone)
4739 {
576f8b11 4740 AfxMessageBox (L"Can't build wire!");
7fd59977 4741 return;
4742 }
4743
4744 if (!(W.Closed())){
576f8b11 4745 AfxMessageBox (L"Wire is not closed!");
7fd59977 4746 return;
4747 //Standard_Failure::Raise("Wire is not closed");
4748
4749 }
4750 BRepBuilderAPI_MakeFace MF(support,W,Standard_True);
4751 TopoDS_Face aface;
4752 aface = MF.Face();
4753 BRepTopAdaptor_FClass2d clas2d(aface,Precision::Confusion());
4754 if (clas2d.PerformInfinitePoint() == TopAbs_IN) {
4755 W.Reverse();
4756 BRepBuilderAPI_MakeFace MF1(support,W,Standard_True);
4757 aface = MF1.Face();
4758 }
4759 if (!BRepAlgo::IsValid(aface))
576f8b11 4760 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : The plate face is not valid!", L"CasCade Error", MB_ICONERROR);
7fd59977 4761 myState = -1;
92efcf78 4762 Handle(AIS_Shape) anAISShape = new AIS_Shape(aface);
0577ae8c 4763 myAISContext->SetColor (anAISShape,Quantity_NOC_AZURE, Standard_False);
4764 myAISContext->SetMaterial (anAISShape, Graphic3d_NOM_SILVER, Standard_False);
4765 myAISContext->SetDisplayMode (anAISShape, 1, Standard_False);
4766 myAISContext->Display (anAISShape, Standard_True);
4767 }
7fd59977 4768}
4769
4770void CModelingDoc::OnFillwithtang()
4771{
4772 static BOOL flag = 0;
4773 if (flag == 1){
4774 flag = 0;
4775 Handle(AIS_InteractiveObject) aObject;
404c8936 4776 myAISContext ->InitSelected();
4777 if(myAISContext->MoreSelected())
4778 aObject = myAISContext->SelectedInteractive();
7fd59977 4779 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select a file with second face");
576f8b11 4780 if(OnFileImportBrep_WithInitDir (L"TangentSurface") == 1){
7fd59977 4781 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("");
4782 AIS_ListOfInteractive aList;
4783 myAISContext->DisplayedObjects(aList);
4784 AIS_ListIteratorOfListOfInteractive aListIterator;
4785 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4786 myAISContext->Remove (aListIterator.Value(), Standard_False);
7fd59977 4787 }
0577ae8c 4788 myAISContext->UpdateCurrentViewer();
7fd59977 4789 return;
4790 }
0577ae8c 4791 myAISContext->SetSelected(aObject, Standard_True);
7fd59977 4792 }
4793
404c8936 4794 myAISContext->InitSelected();
4795 if (myAISContext->MoreSelected()) {
4796 Handle(AIS_Shape) ashape = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive());
7fd59977 4797 try {
e0280ce9 4798 THE_F1 = TopoDS::Face(ashape->Shape());
7fd59977 4799 }
4800 catch(Standard_Failure){}
e0280ce9 4801 if (THE_F1.IsNull())
7fd59977 4802 {
576f8b11 4803 AfxMessageBox (L"Current object is not a face!\n\
7fd59977 4804Please, select a face to continue\nthe creation of a tangent surface.");
4805 return;
4806 }
7fd59977 4807 myAISContext->Activate(ashape,2);
4808 myState = SELECT_EDGE_PLATE_TGTES_1;
4809
4810 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select an edge on the first face");
4811 }
4812 else {
4813 AIS_ListOfInteractive LI;
4814 myAISContext->DisplayedObjects(LI);
4815 if(LI.IsEmpty()){
4816 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select a file with first face");
576f8b11 4817 if(OnFileImportBrep_WithInitDir (L"TangentSurface") == 1){
7fd59977 4818 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("");
4819 AIS_ListOfInteractive aList;
4820 myAISContext->DisplayedObjects(aList);
4821 AIS_ListIteratorOfListOfInteractive aListIterator;
4822 for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
0577ae8c 4823 myAISContext->Remove(aListIterator.Value(), Standard_False);
7fd59977 4824 }
0577ae8c 4825 myAISContext->UpdateCurrentViewer();
7fd59977 4826 return;
4827 }
4828 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("");
4829 myAISContext->DisplayedObjects(LI);
0577ae8c 4830 myAISContext->SetSelected (LI.First(), Standard_True);
7fd59977 4831 Sleep(700);
4832 flag = 1;
4833 OnFillwithtang();
4834 return;
4835 }
576f8b11 4836 AfxMessageBox (L"Select a face before");
7fd59977 4837 }
4838}
4839
5c573e69 4840void CModelingDoc::InputEvent(const Standard_Integer /*x*/,
4841 const Standard_Integer /*y*/,
4842 const Handle(V3d_View)& /*aView*/)
7fd59977 4843{
0577ae8c 4844 myAISContext->Select (Standard_True);
7fd59977 4845 if (myState == SELECT_EDGE_PLATE_TGTES_1) {
4846 myAISContext->InitSelected();
4847 if (myAISContext->MoreSelected()) {
e0280ce9 4848 THE_E1 = TopoDS::Edge(myAISContext->SelectedShape());
7fd59977 4849 myState = SELECT_EDGE_PLATE_TGTES_2;
4850
4851 AIS_ListOfInteractive aLI;
4852 myAISContext->DisplayedObjects(aLI);
4853 if(aLI.Extent() == 2){
4854 myState = SELECT_EDGE_PLATE_TGTES_2;
404c8936 4855 if (myAISContext->IsSelected(aLI.First()))
0577ae8c 4856 myAISContext->SetSelected (aLI.Last(), Standard_True);
7fd59977 4857 else
0577ae8c 4858 myAISContext->SetSelected (aLI.First(), Standard_True);
404c8936 4859 myAISContext->InitSelected();
4860 Handle(AIS_Shape) ashape = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive());
e0280ce9 4861 THE_F2 = TopoDS::Face(ashape->Shape());
7fd59977 4862 myAISContext->Activate(ashape,2);
4863 myState = SELECT_EDGE_PLATE_TGTES_3;
4864 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select an edge on the second face");
4865 return;
4866 }
4867
4868 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select second face");
4869 AIS_ListOfInteractive LI;
4870 myAISContext->DisplayedObjects(LI);
4871 if(LI.Extent() == 1){
576f8b11 4872 if(OnFileImportBrep_WithInitDir (L"TangentSurface") == 1)
7fd59977 4873 return;
4874 }
4875 }
4876 else
576f8b11 4877 AfxMessageBox (L"Select an edge on the face!");
7fd59977 4878
4879 }
4880 else if (myState == SELECT_EDGE_PLATE_TGTES_2) {
404c8936 4881 myAISContext->InitSelected();
4882 if (myAISContext->MoreSelected()) {
4883 Handle(AIS_Shape) ashape = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive());
4884 THE_F2 = TopoDS::Face(ashape->Shape());
7fd59977 4885 myAISContext->Activate(ashape,2);
4886 myState = SELECT_EDGE_PLATE_TGTES_3;
4887 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select an edge on the second face");
4888 }
4889 else
576f8b11 4890 AfxMessageBox (L"Select the second face!");
7fd59977 4891 }
4892 else if (myState == SELECT_EDGE_PLATE_TGTES_3) {
4893 myAISContext->InitSelected();
4894 if (myAISContext->MoreSelected()) {
e0280ce9 4895 THE_E2 = TopoDS::Edge(myAISContext->SelectedShape());
7fd59977 4896
4897 Standard_Integer i, nbPntsOnFaces=10;
4898 Standard_Real u,First, Last, Delta, Tol=0.001, TolProj;
4899 Plate_Plate aPlate;
4900 gp_Vec V1,V2,W1,W2;
4901 gp_Pnt2d P2d;
4902 gp_Pnt P, PP;
4903
4904 //get the pcurve, curve and surface
e0280ce9 4905 BRepAdaptor_Curve Curve3d1(THE_E1), Curve3d2(THE_E2);
4906 BRepAdaptor_Curve2d Curve2d1(THE_E1,THE_F1), Curve2d2(THE_E2,THE_F2);
4907 BRepAdaptor_Surface Surf1(THE_F1), Surf2(THE_F2);
7fd59977 4908
4909 //compute the average plane : initial surface
4910 Handle(TColgp_HArray1OfPnt) theTanPoints = new
4911 TColgp_HArray1OfPnt (1,2*nbPntsOnFaces );
4912
4913 Delta = (Curve3d1.LastParameter()-Curve3d1.FirstParameter())/(nbPntsOnFaces-1);
4914 for (u=Curve3d1.FirstParameter(),i=1;i<=nbPntsOnFaces; i++,u+=Delta)
4915 theTanPoints->SetValue(i,Curve3d1.Value(u));
4916
4917 Delta = (Curve3d2.LastParameter()-Curve3d2.FirstParameter())/(nbPntsOnFaces-1);
4918 for (u=Curve3d2.FirstParameter(),i=1;i<=nbPntsOnFaces; i++,u+=Delta)
4919 theTanPoints->SetValue(nbPntsOnFaces+i,Curve3d2.Value(u));
4920
4921 //Building an initial plane
4922 GeomPlate_BuildAveragePlane aMkPlane (theTanPoints,int(Tol),1,1,1);
4923 Handle(Geom_Plane) aPlane = aMkPlane.Plane();
4924 gp_Pln aPln = aPlane->Pln();
4925 gp_XYZ aNormale = aPln.Axis().Direction().XYZ();
4926 gp_Trsf aTrsf; // to compute the U and V of the points
4927 aTrsf.SetTransformation(aPln.Position());
4928
4929 aPlane->D1(0,0,P,W1,W2); // extract plane DU & DV
4930
4931 // 1st surface tangencies constraints
4932 Delta = (Curve3d1.LastParameter()-Curve3d1.FirstParameter())/(nbPntsOnFaces-1);
4933 for (u=Curve3d1.FirstParameter(),i=1; i<=nbPntsOnFaces; i++,u+=Delta) {
4934 P = Curve3d1.Value(u).Transformed(aTrsf);
4935 gp_XY UV(P.X(),P.Y());
4936 aPlate.Load(Plate_PinpointConstraint(UV,aNormale*P.Z()));
4937 Curve2d1.D0(u,P2d);
4938 Surf1.D1(P2d.X(),P2d.Y(),P,V1,V2); // extract surface UV of the point
4939 aPlate.Load(Plate_GtoCConstraint(UV,
4940 Plate_D1(W1.XYZ(),W2.XYZ()),
4941 Plate_D1(V1.XYZ(),V2.XYZ())));
4942 }
4943 // 2nd surface
4944 Delta = (Curve3d2.LastParameter()-Curve3d2.FirstParameter())/(nbPntsOnFaces-1);
4945 for (u=Curve3d2.FirstParameter(),i=1; i<=nbPntsOnFaces; i++,u+=Delta) {
4946 P = Curve3d2.Value(u).Transformed(aTrsf);
4947 gp_XY UV(P.X(),P.Y());
4948 aPlate.Load(Plate_PinpointConstraint(UV,aNormale*P.Z()));
4949
4950 Curve2d2.D0(u,P2d);
4951 Surf2.D1(P2d.X(),P2d.Y(),P,V1,V2);
4952 aPlate.Load(Plate_GtoCConstraint(UV,
4953 Plate_D1(W1.XYZ(),W2.XYZ()),
4954 Plate_D1(V1.XYZ()*-1,V2.XYZ()*-1)));
4955 }
4956
4957 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Select a file with passing points");
4958 //Some passing points
4959 CFileDialog dlg(TRUE,
4960 NULL,
4961 NULL,
4962 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
576f8b11 4963 L"Points Files (*.pass)|*.pass; |All Files (*.*)|*.*||",
4964 NULL);
7fd59977 4965
5c1f974e 4966 CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
576f8b11 4967 initdir += L"\\Data\\TangentSurface";
7fd59977 4968
4969 dlg.m_ofn.lpstrInitialDir = initdir;
4970
4971 if (dlg.DoModal() == IDOK)
4972 {
4973 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Building the tangent surface...");
4974 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
4975 CString filename = dlg.GetPathName();
4976 filebuf fic;
4977 istream in(&fic);
576f8b11 4978 if (!fic.open(filename, ios::in))
4979 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Unable to open file", L"CasCade Error", MB_ICONERROR);
7fd59977 4980 Standard_Real x,y,z;
4981 BRep_Builder B;
4982 TopoDS_Compound C;
4983 B.MakeCompound(C);
4984 while (!in.fail()|| !in.eof()){
4985 if (in >> x && in >> y && in >> z){
4986 PP = gp_Pnt(x, y, z);
4987 P = PP.Transformed(aTrsf);
4988 aPlate.Load(Plate_PinpointConstraint(gp_XY(P.X(),P.Y()),
4989 aNormale*P.Z()));
4990 BRepBuilderAPI_MakeVertex V(PP);
4991 B.Add(C,V.Vertex());
4992 }
4993 }
4994 fic.close();
4995 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
4996 myAISContext->Display(anAISCompound, Standard_False);
4997 Fit();
4998 Sleep(500);
4999 }
5000 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
5001 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("Building the tangent surface...");
5002 //Solving ...
5003 Standard_Integer Order = 3; // constraints continuity + 2
5004 aPlate.SolveTI(Order,1.);
5005 if (!aPlate.IsDone()){
576f8b11 5006 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : Build plate not valid!", L"CasCade Error", MB_ICONERROR);
7fd59977 5007 return;
5008 }
5009 //Plate Surface creation
5010 Handle(GeomPlate_Surface) aPlateSurface = new GeomPlate_Surface(aPlane,aPlate);
5011 //BSplineSurface approximation
5012 GeomPlate_MakeApprox aMkSurf(aPlateSurface,Tol,1,8,0.1,1);
5013 Handle(Geom_Surface) theSurface =aMkSurf.Surface();
5014
5015 // Face building ...
5016 Handle(Geom2d_Curve)C1,C2,C3,C4;
5017 Handle(Geom_Curve)C;
e0280ce9 5018 C = BRep_Tool::Curve(THE_E1,First,Last);
7fd59977 5019 TolProj = 0.01;
5020 C1 = GeomProjLib::Curve2d(C,First,Last,theSurface,TolProj);
5021 TopoDS_Edge Ed1 = BRepBuilderAPI_MakeEdge(C1,theSurface).Edge();
5022
e0280ce9 5023 C = BRep_Tool::Curve(THE_E2,First,Last);
7fd59977 5024 TolProj = 0.01;
5025 C3 = GeomProjLib::Curve2d(C,First,Last,theSurface,TolProj);
5026 TopoDS_Edge Ed3 = BRepBuilderAPI_MakeEdge(C3,theSurface).Edge();
5027
5028 C2 = GCE2d_MakeSegment(C1->Value(C1->FirstParameter()),
9e3ca93a 5029 C3->Value(C3->FirstParameter())).Value();
7fd59977 5030 TopoDS_Edge Ed2 = BRepBuilderAPI_MakeEdge(C2,theSurface).Edge();
5031 C4 = GCE2d_MakeSegment(C1->Value(C1->LastParameter()),
9e3ca93a 5032 C3->Value(C3->LastParameter())).Value();
7fd59977 5033 TopoDS_Edge Ed4 = BRepBuilderAPI_MakeEdge(C4,theSurface).Edge();
5034 Ed2.Reverse();
5035 Ed3.Reverse();
5036 TopoDS_Wire theWire = BRepBuilderAPI_MakeWire(Ed1,Ed2,Ed3,Ed4);
5037 TopoDS_Face theFace = BRepBuilderAPI_MakeFace(theWire);
5038 BRepLib::BuildCurves3d(theFace);
5039 if (!BRepAlgo::IsValid(theFace)){
5040 C2 = GCE2d_MakeSegment(C1->Value(C1->LastParameter()),
9e3ca93a 5041 C3->Value(C3->FirstParameter())).Value();
e0280ce9 5042 Ed2 = BRepBuilderAPI_MakeEdge(C2,theSurface).Edge();
7fd59977 5043 C4 = GCE2d_MakeSegment(C3->Value(C3->LastParameter()),
9e3ca93a 5044 C1->Value(C1->FirstParameter())).Value();
e0280ce9 5045 Ed4 = BRepBuilderAPI_MakeEdge(C4,theSurface).Edge();
7fd59977 5046 Ed3.Reverse();
5047 theWire = BRepBuilderAPI_MakeWire(Ed1,Ed2,Ed3,Ed4);
5048 theFace = BRepBuilderAPI_MakeFace(theWire);
5049 BRepLib::BuildCurves3d(theFace);
5050 if (!BRepAlgo::IsValid(theFace))
576f8b11 5051 MessageBoxW (AfxGetApp()->m_pMainWnd->m_hWnd, L"Error : The plate surface is not valid!!!", L"CasCade Error", MB_ICONERROR);
7fd59977 5052 }
5053
92efcf78 5054 Handle(AIS_Shape) anAISShape=new AIS_Shape(theFace);
0577ae8c 5055 myAISContext->SetColor (anAISShape, Quantity_NOC_BLUE1, Standard_False);
5056 myAISContext->SetMaterial (anAISShape, Graphic3d_NOM_SILVER, Standard_False);
5057 myAISContext->SetDisplayMode (anAISShape, 1, Standard_False);
5058 myAISContext->Display (anAISShape, Standard_False);
7fd59977 5059 myState = -1;
5060 }
5061 else
576f8b11 5062 AfxMessageBox (L"Select an edge on the second face!");
7fd59977 5063 ((OCC_MainFrame*)AfxGetMainWnd())->SetStatusMessage("");
5064
5065 }
5066}
5067
5068void CModelingDoc::Popup(const Standard_Integer x,
5069 const Standard_Integer y ,
5070 const Handle(V3d_View)& aView)
5071{
5072 Standard_Integer PopupMenuNumber=0;
404c8936 5073 myAISContext->InitSelected();
7fd59977 5074 if (myState == SELECT_EDGE_PLATE)
5075 PopupMenuNumber=2;
404c8936 5076 else if (myAISContext->MoreSelected())
7fd59977 5077 PopupMenuNumber=1;
5078
5079 CMenu menu;
5080 VERIFY(menu.LoadMenu(IDR_Popup3D));
5081 CMenu* pPopup = menu.GetSubMenu(PopupMenuNumber);
5082 ASSERT(pPopup != NULL);
5083
5084 if (PopupMenuNumber == 1) // more than 1 object.
5085 {
5086 bool OneOrMoreInShading = false;
404c8936 5087 for (myAISContext->InitSelected();myAISContext->MoreSelected ();myAISContext->NextSelected ())
5088 if (myAISContext->IsDisplayed(myAISContext->SelectedInteractive(),1)) OneOrMoreInShading=true;
7fd59977 5089 if(!OneOrMoreInShading)
5090 pPopup->EnableMenuItem(5, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
5091 }
5092
5093
5094 POINT winCoord = { x , y };
5095 Handle(WNT_Window) aWNTWindow=
5096 Handle(WNT_Window)::DownCast(aView->Window());
5097 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
5098 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
5099 AfxGetMainWnd());
42e4630c 5100}