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