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