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