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