Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ILocalOperations.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 using namespace std;
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_ILocalOperations.hxx>
26
27 #include <GEOM_Function.hxx>
28 #include <GEOM_PythonDump.hxx>
29
30 #include <GEOMImpl_Types.hxx>
31
32 #include <GEOMImpl_FilletDriver.hxx>
33 #include <GEOMImpl_ChamferDriver.hxx>
34
35 #include <GEOMImpl_IFillet.hxx>
36 #include <GEOMImpl_IChamfer.hxx>
37
38 #include <GEOMImpl_IArchimede.hxx>
39 #include <GEOMImpl_ArchimedeDriver.hxx>
40
41 #include <GEOMImpl_Gen.hxx>
42 #include <GEOMImpl_IShapesOperations.hxx>
43
44 #include "utilities.h"
45 #include <OpUtil.hxx>
46 #include <Utils_ExceptHandlers.hxx>
47
48 #include <TFunction_DriverTable.hxx>
49 #include <TFunction_Driver.hxx>
50 #include <TFunction_Logbook.hxx>
51 #include <TDF_Tool.hxx>
52
53 #include <TopExp.hxx>
54 #include <TopoDS_TShape.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
56
57 #include <Standard_Failure.hxx>
58 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
59
60 //=============================================================================
61 /*!
62  *   constructor:
63  */
64 //=============================================================================
65 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
66 : GEOM_IOperations(theEngine, theDocID)
67 {
68   MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
69 }
70
71 //=============================================================================
72 /*!
73  *  destructor
74  */
75 //=============================================================================
76 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
77 {
78   MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
79 }
80
81
82 //=============================================================================
83 /*!
84  *  MakeFilletAll
85  */
86 //=============================================================================
87 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
88                                     (Handle(GEOM_Object) theShape, double theR)
89 {
90   SetErrorCode(KO);
91
92   //Add a new Fillet object
93   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
94
95   //Add a new Fillet function
96   Handle(GEOM_Function) aFunction =
97     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
98   if (aFunction.IsNull()) return NULL;
99
100   //Check if the function is set correctly
101   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
102
103   GEOMImpl_IFillet aCI (aFunction);
104
105   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
106   if (aRefShape.IsNull()) return NULL;
107
108   aCI.SetShape(aRefShape);
109   aCI.SetR(theR);
110
111   //Compute the Fillet value
112   try {
113 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
114     OCC_CATCH_SIGNALS;
115 #endif
116     if (!GetSolver()->ComputeFunction(aFunction)) {
117       SetErrorCode("Fillet driver failed");
118       return NULL;
119     }
120   }
121   catch (Standard_Failure) {
122     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
123     SetErrorCode(aFail->GetMessageString());
124     return NULL;
125   }
126
127   //Make a Python command
128   GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
129                                << theShape << ", " << theR << ")";
130
131   SetErrorCode(OK);
132   return aFillet;
133 }
134
135 //=============================================================================
136 /*!
137  *  MakeFilletEdges
138  */
139 //=============================================================================
140 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
141        (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
142 {
143   SetErrorCode(KO);
144
145   //Add a new Fillet object
146   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
147
148   //Add a new Fillet function
149   Handle(GEOM_Function) aFunction =
150     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
151   if (aFunction.IsNull()) return NULL;
152
153   //Check if the function is set correctly
154   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
155
156   GEOMImpl_IFillet aCI (aFunction);
157
158   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
159   if (aRefShape.IsNull()) return NULL;
160
161   aCI.SetShape(aRefShape);
162   aCI.SetR(theR);
163   int aLen = theEdges.size();
164   aCI.SetLength(aLen);
165
166   int ind = 1;
167   list<int>::iterator it = theEdges.begin();
168   for (; it != theEdges.end(); it++, ind++) {
169     aCI.SetEdge(ind, (*it));
170   }
171
172   //Compute the Fillet value
173   try {
174 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
175     OCC_CATCH_SIGNALS;
176 #endif
177     if (!GetSolver()->ComputeFunction(aFunction)) {
178       SetErrorCode("Fillet driver failed");
179       return NULL;
180     }
181   }
182   catch (Standard_Failure) {
183     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
184     SetErrorCode(aFail->GetMessageString());
185     return NULL;
186   }
187
188   //Make a Python command
189   GEOM::TPythonDump pd (aFunction);
190   pd << aFillet << " = geompy.MakeFillet(" << theShape
191     << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
192
193   it = theEdges.begin();
194   pd << (*it++);
195   while (it != theEdges.end()) {
196     pd << ", " << (*it++);
197   }
198   pd << "])";
199
200   SetErrorCode(OK);
201   return aFillet;
202 }
203
204 //=============================================================================
205 /*!
206  *  MakeFilletEdges R1 R2
207  */
208 //=============================================================================
209 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdgesR1R2
210        (Handle(GEOM_Object) theShape, double theR1, double theR2, list<int> theEdges)
211 {
212   SetErrorCode(KO);
213
214   //Add a new Fillet object
215   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
216
217   //Add a new Fillet function
218   Handle(GEOM_Function) aFunction =
219     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES_2R);
220   if (aFunction.IsNull()) return NULL;
221
222   //Check if the function is set correctly
223   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
224
225   GEOMImpl_IFillet aCI (aFunction);
226
227   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
228   if (aRefShape.IsNull()) return NULL;
229
230   aCI.SetShape(aRefShape);
231   aCI.SetR1(theR1);
232   aCI.SetR2(theR2);
233   int aLen = theEdges.size();
234   aCI.SetLength(aLen);
235
236   int ind = 1;
237   list<int>::iterator it = theEdges.begin();
238   for (; it != theEdges.end(); it++, ind++) {
239     aCI.SetEdge(ind, (*it));
240   }
241
242   //Compute the Fillet value
243   try {
244 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
245     OCC_CATCH_SIGNALS;
246 #endif
247     if (!GetSolver()->ComputeFunction(aFunction)) {
248       SetErrorCode("Fillet driver failed");
249       return NULL;
250     }
251   }
252   catch (Standard_Failure) {
253     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
254     SetErrorCode(aFail->GetMessageString());
255     return NULL;
256   }
257
258   //Make a Python command
259   GEOM::TPythonDump pd (aFunction);
260   pd << aFillet << " = geompy.MakeFilletR1R2(" << theShape
261     << ", " << theR1 << ", " <<theR2 << ", geompy.ShapeType[\"EDGE\"], [";
262
263   it = theEdges.begin();
264   pd << (*it++);
265   while (it != theEdges.end()) {
266     pd << ", " << (*it++);
267   }
268   pd << "])";
269
270   SetErrorCode(OK);
271   return aFillet;
272 }
273
274
275 //=============================================================================
276 /*!
277  *  MakeFilletFaces
278  */
279 //=============================================================================
280 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
281        (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
282 {
283   SetErrorCode(KO);
284
285   //Add a new Fillet object
286   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
287
288   //Add a new Fillet function
289   Handle(GEOM_Function) aFunction =
290     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
291   if (aFunction.IsNull()) return NULL;
292
293   //Check if the function is set correctly
294   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
295
296   GEOMImpl_IFillet aCI (aFunction);
297
298   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
299   if (aRefShape.IsNull()) return NULL;
300
301   aCI.SetShape(aRefShape);
302   aCI.SetR(theR);
303   int aLen = theFaces.size();
304   aCI.SetLength(aLen);
305
306   int ind = 1;
307   list<int>::iterator it = theFaces.begin();
308   for (; it != theFaces.end(); it++, ind++) {
309     aCI.SetFace(ind, (*it));
310   }
311
312   //Compute the Fillet value
313   try {
314 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
315     OCC_CATCH_SIGNALS;
316 #endif
317     if (!GetSolver()->ComputeFunction(aFunction)) {
318       SetErrorCode("Fillet driver failed");
319       return NULL;
320     }
321   }
322   catch (Standard_Failure) {
323     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
324     SetErrorCode(aFail->GetMessageString());
325     return NULL;
326   }
327
328   //Make a Python command
329   GEOM::TPythonDump pd (aFunction);
330   pd << aFillet << " = geompy.MakeFillet(" << theShape
331     << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
332
333   it = theFaces.begin();
334   pd << (*it++);
335   while (it != theFaces.end()) {
336     pd << ", " << (*it++);
337   }
338   pd << "])";
339
340   SetErrorCode(OK);
341   return aFillet;
342 }
343
344 //=============================================================================
345 /*!
346  *  MakeFilletFaces R1 R2
347  */
348 //=============================================================================
349 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFacesR1R2
350        (Handle(GEOM_Object) theShape, double theR1, double theR2, list<int> theFaces)
351 {
352   SetErrorCode(KO);
353
354   //Add a new Fillet object
355   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
356
357   //Add a new Fillet function
358   Handle(GEOM_Function) aFunction =
359     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES_2R);
360   if (aFunction.IsNull()) return NULL;
361
362   //Check if the function is set correctly
363   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
364
365   GEOMImpl_IFillet aCI (aFunction);
366
367   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
368   if (aRefShape.IsNull()) return NULL;
369
370   aCI.SetShape(aRefShape);
371   aCI.SetR1(theR1);
372   aCI.SetR2(theR2);
373   int aLen = theFaces.size();
374   aCI.SetLength(aLen);
375
376   int ind = 1;
377   list<int>::iterator it = theFaces.begin();
378   for (; it != theFaces.end(); it++, ind++) {
379     aCI.SetFace(ind, (*it));
380   }
381
382   //Compute the Fillet value
383   try {
384 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
385     OCC_CATCH_SIGNALS;
386 #endif
387     if (!GetSolver()->ComputeFunction(aFunction)) {
388       SetErrorCode("Fillet driver failed");
389       return NULL;
390     }
391   }
392   catch (Standard_Failure) {
393     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
394     SetErrorCode(aFail->GetMessageString());
395     return NULL;
396   }
397
398   //Make a Python command
399   GEOM::TPythonDump pd (aFunction);
400   pd << aFillet << " = geompy.MakeFilletR1R2(" << theShape
401     << ", " << theR1 << ", " << theR2 << ", geompy.ShapeType[\"FACE\"], [";
402
403   it = theFaces.begin();
404   pd << (*it++);
405   while (it != theFaces.end()) {
406     pd << ", " << (*it++);
407   }
408   pd << "])";
409
410   SetErrorCode(OK);
411   return aFillet;
412 }
413
414 //=============================================================================
415 /*!
416  *  MakeChamferAll
417  */
418 //=============================================================================
419 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
420 {
421   SetErrorCode(KO);
422
423   //Add a new Chamfer object
424   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
425
426   //Add a new Chamfer function
427   Handle(GEOM_Function) aFunction =
428     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
429   if (aFunction.IsNull()) return NULL;
430
431   //Check if the function is set correctly
432   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
433
434   GEOMImpl_IChamfer aCI (aFunction);
435
436   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
437   if (aRefShape.IsNull()) return NULL;
438
439   aCI.SetShape(aRefShape);
440   aCI.SetD(theD);
441
442   //Compute the Chamfer value
443   try {
444 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
445     OCC_CATCH_SIGNALS;
446 #endif
447     if (!GetSolver()->ComputeFunction(aFunction)) {
448       SetErrorCode("Chamfer driver failed");
449       return NULL;
450     }
451   }
452   catch (Standard_Failure) {
453     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
454     SetErrorCode(aFail->GetMessageString());
455     return NULL;
456   }
457
458   //Make a Python command
459   GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
460                                << theShape << ", " << theD << ")";
461
462   SetErrorCode(OK);
463   return aChamfer;
464 }
465
466 //=============================================================================
467 /*!
468  *  MakeChamferEdge
469  */
470 //=============================================================================
471 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
472                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
473                              int theFace1, int theFace2)
474 {
475   SetErrorCode(KO);
476
477   //Add a new Chamfer object
478   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
479
480   //Add a new Chamfer function
481   Handle(GEOM_Function) aFunction =
482     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
483   if (aFunction.IsNull()) return NULL;
484
485   //Check if the function is set correctly
486   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
487
488   GEOMImpl_IChamfer aCI (aFunction);
489
490   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
491   if (aRefShape.IsNull()) return NULL;
492
493   aCI.SetShape(aRefShape);
494   aCI.SetD1(theD1);
495   aCI.SetD2(theD2);
496   aCI.SetFace1(theFace1);
497   aCI.SetFace2(theFace2);
498
499   //Compute the Chamfer value
500   try {
501 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
502     OCC_CATCH_SIGNALS;
503 #endif
504     if (!GetSolver()->ComputeFunction(aFunction)) {
505       SetErrorCode("Chamfer driver failed");
506       return NULL;
507     }
508   }
509   catch (Standard_Failure) {
510     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
511     SetErrorCode(aFail->GetMessageString());
512     return NULL;
513   }
514
515   //Make a Python command
516   GEOM::TPythonDump(aFunction) << aChamfer
517     << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
518       << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
519
520   SetErrorCode(OK);
521   return aChamfer;
522 }
523
524 //=============================================================================
525 /*!
526  *  MakeChamferEdgeAD
527  */
528 //=============================================================================
529 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgeAD
530                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
531                              int theFace1, int theFace2)
532 {
533   SetErrorCode(KO);
534
535   //Add a new Chamfer object
536   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
537
538   //Add a new Chamfer function
539   Handle(GEOM_Function) aFunction =
540     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE_AD);
541   if (aFunction.IsNull()) return NULL;
542
543   //Check if the function is set correctly
544   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
545
546   GEOMImpl_IChamfer aCI (aFunction);
547
548   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
549   if (aRefShape.IsNull()) return NULL;
550
551   aCI.SetShape(aRefShape);
552   aCI.SetD(theD);
553   aCI.SetAngle(theAngle);
554   aCI.SetFace1(theFace1);
555   aCI.SetFace2(theFace2);
556
557   //Compute the Chamfer value
558   try {
559 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
560     OCC_CATCH_SIGNALS;
561 #endif
562     if (!GetSolver()->ComputeFunction(aFunction)) {
563       SetErrorCode("Chamfer driver failed");
564       return NULL;
565     }
566   }
567   catch (Standard_Failure) {
568     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
569     SetErrorCode(aFail->GetMessageString());
570     return NULL;
571   }
572
573   //Make a Python command
574   GEOM::TPythonDump(aFunction) << aChamfer
575     << " = geompy.MakeChamferEdgeAD(" << theShape << ", " << theD
576       << ", " << theAngle << ", " << theFace1 << ", " << theFace2 << ")";
577   SetErrorCode(OK);
578   return aChamfer;
579 }
580
581 //=============================================================================
582 /*!
583  *  MakeChamferFaces
584  */
585 //=============================================================================
586 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
587                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
588                              list<int> theFaces)
589 {
590   SetErrorCode(KO);
591
592   //Add a new Chamfer object
593   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
594
595   //Add a new Chamfer function
596   Handle(GEOM_Function) aFunction =
597     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
598   if (aFunction.IsNull()) return NULL;
599
600   //Check if the function is set correctly
601   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
602
603   GEOMImpl_IChamfer aCI (aFunction);
604
605   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
606   if (aRefShape.IsNull()) return NULL;
607
608   aCI.SetShape(aRefShape);
609   aCI.SetD1(theD1);
610   aCI.SetD2(theD2);
611   int aLen = theFaces.size();
612   aCI.SetLength(aLen);
613
614   int ind = 1;
615   list<int>::iterator it = theFaces.begin();
616   for (; it != theFaces.end(); it++, ind++) {
617     aCI.SetFace(ind, (*it));
618   }
619
620   //Compute the Chamfer value
621   try {
622 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
623     OCC_CATCH_SIGNALS;
624 #endif
625     if (!GetSolver()->ComputeFunction(aFunction)) {
626       SetErrorCode("Chamfer driver failed");
627       return NULL;
628     }
629   }
630   catch (Standard_Failure) {
631     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
632     SetErrorCode(aFail->GetMessageString());
633     return NULL;
634   }
635
636   //Make a Python command
637   GEOM::TPythonDump pd (aFunction);
638   pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
639     << ", " << theD1 << ", " << theD2 << ", [";
640
641   it = theFaces.begin();
642   pd << (*it++);
643   while (it != theFaces.end()) {
644     pd << ", " << (*it++);
645   }
646   pd << "])";
647
648   SetErrorCode(OK);
649   return aChamfer;
650 }
651
652 //=============================================================================
653 /*!
654  *  MakeChamferFacesAD
655  */
656 //=============================================================================
657 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFacesAD
658                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
659                              list<int> theFaces)
660 {
661   SetErrorCode(KO);
662
663   //Add a new Chamfer object
664   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
665
666   //Add a new Chamfer function
667   Handle(GEOM_Function) aFunction =
668     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES_AD);
669   if (aFunction.IsNull()) return NULL;
670
671   //Check if the function is set correctly
672   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
673
674   GEOMImpl_IChamfer aCI (aFunction);
675
676   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
677   if (aRefShape.IsNull()) return NULL;
678
679   aCI.SetShape(aRefShape);
680   aCI.SetD(theD);
681   aCI.SetAngle(theAngle);
682   int aLen = theFaces.size();
683   aCI.SetLength(aLen);
684
685   int ind = 1;
686   list<int>::iterator it = theFaces.begin();
687   for (; it != theFaces.end(); it++, ind++) {
688     aCI.SetFace(ind, (*it));
689   }
690
691   //Compute the Chamfer value
692   try {
693 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
694     OCC_CATCH_SIGNALS;
695 #endif
696     if (!GetSolver()->ComputeFunction(aFunction)) {
697       SetErrorCode("Chamfer driver failed");
698       return NULL;
699     }
700   }
701   catch (Standard_Failure) {
702     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
703     SetErrorCode(aFail->GetMessageString());
704     return NULL;
705   }
706
707   //Make a Python command
708   GEOM::TPythonDump pd (aFunction);
709   pd << aChamfer << " = geompy.MakeChamferFacesAD(" << theShape
710     << ", " << theD << ", " << theAngle << ", [";
711
712   it = theFaces.begin();
713   pd << (*it++);
714   while (it != theFaces.end()) {
715     pd << ", " << (*it++);
716   }
717   pd << "])";
718
719   SetErrorCode(OK);
720   return aChamfer;
721 }
722
723 //=============================================================================
724 /*!
725  *  MakeChamferEdges
726  */
727 //=============================================================================
728 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdges
729                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
730                              list<int> theEdges)
731 {
732   SetErrorCode(KO);
733
734   //Add a new Chamfer object
735   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
736
737   //Add a new Chamfer function
738   Handle(GEOM_Function) aFunction =
739     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES);
740   if (aFunction.IsNull()) { return NULL; cout << "Edges Function is NULL!!!" << endl; }
741
742   //Check if the function is set correctly
743   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
744         { return NULL; cout << "Chamfer Driver is NULL!!!" << endl; }
745
746   GEOMImpl_IChamfer aCI (aFunction);
747
748   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
749   if (aRefShape.IsNull()) { return NULL; cout << "Shape is NULL!!!" << endl; }
750
751   aCI.SetShape(aRefShape);
752   aCI.SetD1(theD1);
753   aCI.SetD2(theD2);
754   int aLen = theEdges.size();
755   aCI.SetLength(aLen);
756
757   int ind = 1;
758   list<int>::iterator it = theEdges.begin();
759   for (; it != theEdges.end(); it++, ind++) {
760     aCI.SetEdge(ind, (*it));
761   }
762
763   //Compute the Chamfer value
764   try {
765 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
766     OCC_CATCH_SIGNALS;
767 #endif
768     if (!GetSolver()->ComputeFunction(aFunction)) {
769       SetErrorCode("Chamfer driver failed");
770       return NULL;
771     }
772   }
773   catch (Standard_Failure) {
774     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
775     SetErrorCode(aFail->GetMessageString());
776     return NULL;
777   }
778
779   //Make a Python command
780   GEOM::TPythonDump pd (aFunction);
781   pd << aChamfer << " = geompy.MakeChamferEdges(" << theShape
782     << ", " << theD1 << ", " << theD2 << ", [";
783
784   it = theEdges.begin();
785   pd << (*it++);
786   while (it != theEdges.end()) {
787     pd << ", " << (*it++);
788   }
789   pd << "])";
790
791   SetErrorCode(OK);
792   return aChamfer;
793 }
794
795 //=============================================================================
796 /*!
797  *  MakeChamferEdgesAD
798  */
799 //=============================================================================
800 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgesAD
801                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
802                              list<int> theEdges)
803 {
804   SetErrorCode(KO);
805
806   //Add a new Chamfer object
807   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
808
809   //Add a new Chamfer function
810   Handle(GEOM_Function) aFunction =
811     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_AD);
812   if (aFunction.IsNull()) { return NULL; cout << "Edges Function is NULL!!!" << endl; }
813
814   //Check if the function is set correctly
815   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
816         { return NULL; cout << "Chamfer Driver is NULL!!!" << endl; }
817
818   GEOMImpl_IChamfer aCI (aFunction);
819
820   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
821   if (aRefShape.IsNull()) { return NULL; cout << "Shape is NULL!!!" << endl; }
822
823   aCI.SetShape(aRefShape);
824   aCI.SetD(theD);
825   aCI.SetAngle(theAngle);
826   int aLen = theEdges.size();
827   aCI.SetLength(aLen);
828
829   int ind = 1;
830   list<int>::iterator it = theEdges.begin();
831   for (; it != theEdges.end(); it++, ind++) {
832     aCI.SetEdge(ind, (*it));
833   }
834
835   //Compute the Chamfer value
836   try {
837 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
838     OCC_CATCH_SIGNALS;
839 #endif
840     if (!GetSolver()->ComputeFunction(aFunction)) {
841       SetErrorCode("Chamfer driver failed");
842       return NULL;
843     }
844   }
845   catch (Standard_Failure) {
846     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
847     SetErrorCode(aFail->GetMessageString());
848     return NULL;
849   }
850
851   //Make a Python command
852   GEOM::TPythonDump pd (aFunction);
853   pd << aChamfer << " = geompy.MakeChamferEdgesAD(" << theShape
854     << ", " << theD << ", " << theAngle << ", [";
855
856   it = theEdges.begin();
857   pd << (*it++);
858   while (it != theEdges.end()) {
859     pd << ", " << (*it++);
860   }
861   pd << "])";
862
863   SetErrorCode(OK);
864   return aChamfer;
865 }
866
867 //=============================================================================
868 /*!
869  *  Archimede
870  */
871 //=============================================================================
872 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
873                                                               double theWeight,
874                                                               double theWaterDensity,
875                                                               double theMeshingDeflection)
876 {
877   SetErrorCode(KO);
878
879   //Add a new Archimede object
880   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
881
882   //Add a new Archimede function
883   Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
884   if (aFunction.IsNull()) return NULL;
885
886   //Check if the function is set correctly
887   if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
888
889   GEOMImpl_IArchimede aAI (aFunction);
890
891   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
892   if (aRefShape.IsNull()) return NULL;
893
894   aAI.SetBasicShape(aRefShape);
895   aAI.SetWeight(theWeight);
896   aAI.SetDensity(theWaterDensity);
897   aAI.SetDeflection(theMeshingDeflection);
898
899   //Compute the Archimede value
900   try {
901 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
902     OCC_CATCH_SIGNALS;
903 #endif
904     if (!GetSolver()->ComputeFunction(aFunction)) {
905       SetErrorCode("Archimede driver failed");
906       return NULL;
907     }
908   }
909   catch (Standard_Failure) {
910     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
911     SetErrorCode(aFail->GetMessageString());
912     return NULL;
913   }
914
915   //Make a Python command
916   GEOM::TPythonDump(aFunction) << aChamfer
917     << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
918       << theWaterDensity << ", " << theMeshingDeflection << ")";
919
920   SetErrorCode(OK);
921   return aChamfer;
922 }
923
924 //=============================================================================
925 /*!
926  *  GetSubShape
927  */
928 //=============================================================================
929 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
930                                              TopoDS_Shape& theSubShape)
931 {
932   if (theShape.IsNull() || theIndex < 1)
933     return false;
934
935   TopTools_IndexedMapOfShape anIndices;
936   TopExp::MapShapes(theShape, anIndices);
937   if (theIndex > anIndices.Extent()) return false;
938   theSubShape = anIndices.FindKey(theIndex);
939
940   return true;
941 }
942
943 //=============================================================================
944 /*!
945  *  GetSubShapeIndex
946  */
947 //=============================================================================
948 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
949                                                               Handle(GEOM_Object) theSubShape)
950 {
951   SetErrorCode(KO);
952
953   Standard_Integer anInd = -1;
954   GEOM_Engine* anEngine = GetEngine();
955   //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
956   GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
957
958   if (aGen) {
959     GEOMImpl_IShapesOperations* anIShapesOperations =
960       aGen->GetIShapesOperations(GetDocID());
961     anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
962     SetErrorCode(anIShapesOperations->GetErrorCode());
963   }
964
965   return anInd;
966 }