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