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