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