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