Salome HOME
report error when a major radius is less that a minor one
[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   if (it != theVertexes.end()) {
547     pd << (*it++);
548     while (it != theVertexes.end())
549       pd << ", " << (*it++);
550   }
551   pd << "])";
552
553   SetErrorCode(OK);
554   return aFillet1D;
555 }
556
557 //=============================================================================
558 /*!
559  *  MakeChamferAll
560  */
561 //=============================================================================
562 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
563 {
564   SetErrorCode(KO);
565
566   //Add a new Chamfer object
567   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
568
569   //Add a new Chamfer function
570   Handle(GEOM_Function) aFunction =
571     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
572   if (aFunction.IsNull()) return NULL;
573
574   //Check if the function is set correctly
575   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
576
577   GEOMImpl_IChamfer aCI (aFunction);
578
579   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
580   if (aRefShape.IsNull()) return NULL;
581
582   aCI.SetShape(aRefShape);
583   aCI.SetD(theD);
584
585   //Compute the Chamfer value
586   try {
587 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
588     OCC_CATCH_SIGNALS;
589 #endif
590     if (!GetSolver()->ComputeFunction(aFunction)) {
591       SetErrorCode("Chamfer driver failed");
592       return NULL;
593     }
594   }
595   catch (Standard_Failure) {
596     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
597     SetErrorCode(aFail->GetMessageString());
598     return NULL;
599   }
600
601   //Make a Python command
602   GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
603                                << theShape << ", " << theD << ")";
604
605   SetErrorCode(OK);
606   return aChamfer;
607 }
608
609 //=============================================================================
610 /*!
611  *  MakeChamferEdge
612  */
613 //=============================================================================
614 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
615                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
616                              int theFace1, int theFace2)
617 {
618   SetErrorCode(KO);
619
620   //Add a new Chamfer object
621   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
622
623   //Add a new Chamfer function
624   Handle(GEOM_Function) aFunction =
625     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
626   if (aFunction.IsNull()) return NULL;
627
628   //Check if the function is set correctly
629   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
630
631   GEOMImpl_IChamfer aCI (aFunction);
632
633   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
634   if (aRefShape.IsNull()) return NULL;
635
636   aCI.SetShape(aRefShape);
637   aCI.SetD1(theD1);
638   aCI.SetD2(theD2);
639   aCI.SetFace1(theFace1);
640   aCI.SetFace2(theFace2);
641
642   //Compute the Chamfer value
643   try {
644 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
645     OCC_CATCH_SIGNALS;
646 #endif
647     if (!GetSolver()->ComputeFunction(aFunction)) {
648       SetErrorCode("Chamfer driver failed");
649       return NULL;
650     }
651   }
652   catch (Standard_Failure) {
653     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
654     SetErrorCode(aFail->GetMessageString());
655     return NULL;
656   }
657
658   //Make a Python command
659   GEOM::TPythonDump(aFunction) << aChamfer
660     << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
661       << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
662
663   SetErrorCode(OK);
664   return aChamfer;
665 }
666
667 //=============================================================================
668 /*!
669  *  MakeChamferEdgeAD
670  */
671 //=============================================================================
672 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgeAD
673                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
674                              int theFace1, int theFace2)
675 {
676   SetErrorCode(KO);
677
678   //Add a new Chamfer object
679   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
680
681   //Add a new Chamfer function
682   Handle(GEOM_Function) aFunction =
683     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE_AD);
684   if (aFunction.IsNull()) return NULL;
685
686   //Check if the function is set correctly
687   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
688
689   GEOMImpl_IChamfer aCI (aFunction);
690
691   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
692   if (aRefShape.IsNull()) return NULL;
693
694   aCI.SetShape(aRefShape);
695   aCI.SetD(theD);
696   aCI.SetAngle(theAngle);
697   aCI.SetFace1(theFace1);
698   aCI.SetFace2(theFace2);
699
700   //Compute the Chamfer value
701   try {
702 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
703     OCC_CATCH_SIGNALS;
704 #endif
705     if (!GetSolver()->ComputeFunction(aFunction)) {
706       SetErrorCode("Chamfer driver failed");
707       return NULL;
708     }
709   }
710   catch (Standard_Failure) {
711     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
712     SetErrorCode(aFail->GetMessageString());
713     return NULL;
714   }
715
716   //Make a Python command
717   GEOM::TPythonDump(aFunction) << aChamfer
718     << " = geompy.MakeChamferEdgeAD(" << theShape << ", " << theD
719       << ", " << theAngle << ", " << theFace1 << ", " << theFace2 << ")";
720   SetErrorCode(OK);
721   return aChamfer;
722 }
723
724 //=============================================================================
725 /*!
726  *  MakeChamferFaces
727  */
728 //=============================================================================
729 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
730                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
731                              std::list<int> theFaces)
732 {
733   SetErrorCode(KO);
734
735   //Add a new Chamfer object
736   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
737
738   //Add a new Chamfer function
739   Handle(GEOM_Function) aFunction =
740     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
741   if (aFunction.IsNull()) return NULL;
742
743   //Check if the function is set correctly
744   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
745
746   GEOMImpl_IChamfer aCI (aFunction);
747
748   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
749   if (aRefShape.IsNull()) return NULL;
750
751   aCI.SetShape(aRefShape);
752   aCI.SetD1(theD1);
753   aCI.SetD2(theD2);
754   int aLen = theFaces.size();
755   aCI.SetLength(aLen);
756
757   int ind = 1;
758   std::list<int>::iterator it = theFaces.begin();
759   for (; it != theFaces.end(); it++, ind++) {
760     aCI.SetFace(ind, (*it));
761   }
762
763   //Compute the Chamfer value
764   try {
765 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
766     OCC_CATCH_SIGNALS;
767 #endif
768     if (!GetSolver()->ComputeFunction(aFunction)) {
769       SetErrorCode("Chamfer driver failed");
770       return NULL;
771     }
772   }
773   catch (Standard_Failure) {
774     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
775     SetErrorCode(aFail->GetMessageString());
776     return NULL;
777   }
778
779   //Make a Python command
780   GEOM::TPythonDump pd (aFunction);
781   pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
782     << ", " << theD1 << ", " << theD2 << ", [";
783
784   it = theFaces.begin();
785   pd << (*it++);
786   while (it != theFaces.end()) {
787     pd << ", " << (*it++);
788   }
789   pd << "])";
790
791   SetErrorCode(OK);
792   return aChamfer;
793 }
794
795 //=============================================================================
796 /*!
797  *  MakeChamferFacesAD
798  */
799 //=============================================================================
800 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFacesAD
801                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
802                              std::list<int> theFaces)
803 {
804   SetErrorCode(KO);
805
806   //Add a new Chamfer object
807   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
808
809   //Add a new Chamfer function
810   Handle(GEOM_Function) aFunction =
811     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES_AD);
812   if (aFunction.IsNull()) return NULL;
813
814   //Check if the function is set correctly
815   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
816
817   GEOMImpl_IChamfer aCI (aFunction);
818
819   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
820   if (aRefShape.IsNull()) return NULL;
821
822   aCI.SetShape(aRefShape);
823   aCI.SetD(theD);
824   aCI.SetAngle(theAngle);
825   int aLen = theFaces.size();
826   aCI.SetLength(aLen);
827
828   int ind = 1;
829   std::list<int>::iterator it = theFaces.begin();
830   for (; it != theFaces.end(); it++, ind++) {
831     aCI.SetFace(ind, (*it));
832   }
833
834   //Compute the Chamfer value
835   try {
836 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
837     OCC_CATCH_SIGNALS;
838 #endif
839     if (!GetSolver()->ComputeFunction(aFunction)) {
840       SetErrorCode("Chamfer driver failed");
841       return NULL;
842     }
843   }
844   catch (Standard_Failure) {
845     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
846     SetErrorCode(aFail->GetMessageString());
847     return NULL;
848   }
849
850   //Make a Python command
851   GEOM::TPythonDump pd (aFunction);
852   pd << aChamfer << " = geompy.MakeChamferFacesAD(" << theShape
853     << ", " << theD << ", " << theAngle << ", [";
854
855   it = theFaces.begin();
856   pd << (*it++);
857   while (it != theFaces.end()) {
858     pd << ", " << (*it++);
859   }
860   pd << "])";
861
862   SetErrorCode(OK);
863   return aChamfer;
864 }
865
866 //=============================================================================
867 /*!
868  *  MakeChamferEdges
869  */
870 //=============================================================================
871 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdges
872                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
873                              std::list<int> theEdges)
874 {
875   SetErrorCode(KO);
876
877   //Add a new Chamfer object
878   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
879
880   //Add a new Chamfer function
881   Handle(GEOM_Function) aFunction =
882     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES);
883   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL;}
884
885   //Check if the function is set correctly
886   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
887         { MESSAGE ( "Chamfer Driver is NULL!!!" ); return NULL; }
888
889   GEOMImpl_IChamfer aCI (aFunction);
890
891   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
892   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
893
894   aCI.SetShape(aRefShape);
895   aCI.SetD1(theD1);
896   aCI.SetD2(theD2);
897   int aLen = theEdges.size();
898   aCI.SetLength(aLen);
899
900   int ind = 1;
901   std::list<int>::iterator it = theEdges.begin();
902   for (; it != theEdges.end(); it++, ind++) {
903     aCI.SetEdge(ind, (*it));
904   }
905
906   //Compute the Chamfer value
907   try {
908 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
909     OCC_CATCH_SIGNALS;
910 #endif
911     if (!GetSolver()->ComputeFunction(aFunction)) {
912       SetErrorCode("Chamfer driver failed");
913       return NULL;
914     }
915   }
916   catch (Standard_Failure) {
917     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
918     SetErrorCode(aFail->GetMessageString());
919     return NULL;
920   }
921
922   //Make a Python command
923   GEOM::TPythonDump pd (aFunction);
924   pd << aChamfer << " = geompy.MakeChamferEdges(" << theShape
925     << ", " << theD1 << ", " << theD2 << ", [";
926
927   it = theEdges.begin();
928   pd << (*it++);
929   while (it != theEdges.end()) {
930     pd << ", " << (*it++);
931   }
932   pd << "])";
933
934   SetErrorCode(OK);
935   return aChamfer;
936 }
937
938 //=============================================================================
939 /*!
940  *  MakeChamferEdgesAD
941  */
942 //=============================================================================
943 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgesAD
944                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
945                              std::list<int> theEdges)
946 {
947   SetErrorCode(KO);
948
949   //Add a new Chamfer object
950   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
951
952   //Add a new Chamfer function
953   Handle(GEOM_Function) aFunction =
954     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_AD);
955   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL; }
956
957   //Check if the function is set correctly
958   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
959         { MESSAGE("Chamfer Driver is NULL!!!"); return NULL;}
960
961   GEOMImpl_IChamfer aCI (aFunction);
962
963   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
964   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
965
966   aCI.SetShape(aRefShape);
967   aCI.SetD(theD);
968   aCI.SetAngle(theAngle);
969   int aLen = theEdges.size();
970   aCI.SetLength(aLen);
971
972   int ind = 1;
973   std::list<int>::iterator it = theEdges.begin();
974   for (; it != theEdges.end(); it++, ind++) {
975     aCI.SetEdge(ind, (*it));
976   }
977
978   //Compute the Chamfer value
979   try {
980 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
981     OCC_CATCH_SIGNALS;
982 #endif
983     if (!GetSolver()->ComputeFunction(aFunction)) {
984       SetErrorCode("Chamfer driver failed");
985       return NULL;
986     }
987   }
988   catch (Standard_Failure) {
989     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
990     SetErrorCode(aFail->GetMessageString());
991     return NULL;
992   }
993
994   //Make a Python command
995   GEOM::TPythonDump pd (aFunction);
996   pd << aChamfer << " = geompy.MakeChamferEdgesAD(" << theShape
997     << ", " << theD << ", " << theAngle << ", [";
998
999   it = theEdges.begin();
1000   pd << (*it++);
1001   while (it != theEdges.end()) {
1002     pd << ", " << (*it++);
1003   }
1004   pd << "])";
1005
1006   SetErrorCode(OK);
1007   return aChamfer;
1008 }
1009
1010 //=============================================================================
1011 /*!
1012  *  Archimede
1013  */
1014 //=============================================================================
1015 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
1016                                                               double theWeight,
1017                                                               double theWaterDensity,
1018                                                               double theMeshingDeflection)
1019 {
1020   SetErrorCode(KO);
1021
1022   //Add a new Archimede object
1023   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
1024
1025   //Add a new Archimede function
1026   Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
1027   if (aFunction.IsNull()) return NULL;
1028
1029   //Check if the function is set correctly
1030   if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
1031
1032   GEOMImpl_IArchimede aAI (aFunction);
1033
1034   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1035   if (aRefShape.IsNull()) return NULL;
1036
1037   aAI.SetBasicShape(aRefShape);
1038   aAI.SetWeight(theWeight);
1039   aAI.SetDensity(theWaterDensity);
1040   aAI.SetDeflection(theMeshingDeflection);
1041
1042   //Compute the Archimede value
1043   try {
1044 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1045     OCC_CATCH_SIGNALS;
1046 #endif
1047     if (!GetSolver()->ComputeFunction(aFunction)) {
1048       SetErrorCode("Archimede driver failed");
1049       return NULL;
1050     }
1051   }
1052   catch (Standard_Failure) {
1053     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1054     SetErrorCode(aFail->GetMessageString());
1055     return NULL;
1056   }
1057
1058   //Make a Python command
1059   GEOM::TPythonDump(aFunction) << aChamfer
1060     << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
1061       << theWaterDensity << ", " << theMeshingDeflection << ")";
1062
1063   SetErrorCode(OK);
1064   return aChamfer;
1065 }
1066
1067 //=============================================================================
1068 /*!
1069  *  GetSubShape
1070  */
1071 //=============================================================================
1072 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
1073                                              TopoDS_Shape& theSubShape)
1074 {
1075   if (theShape.IsNull() || theIndex < 1)
1076     return false;
1077
1078   TopTools_IndexedMapOfShape anIndices;
1079   TopExp::MapShapes(theShape, anIndices);
1080   if (theIndex > anIndices.Extent()) return false;
1081   theSubShape = anIndices.FindKey(theIndex);
1082
1083   return true;
1084 }
1085
1086 //=============================================================================
1087 /*!
1088  *  GetSubShapeIndex
1089  */
1090 //=============================================================================
1091 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
1092                                                               Handle(GEOM_Object) theSubShape)
1093 {
1094   SetErrorCode(KO);
1095
1096   Standard_Integer anInd = -1;
1097   GEOM_Engine* anEngine = GetEngine();
1098   //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
1099   GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
1100
1101   if (aGen) {
1102     GEOMImpl_IShapesOperations* anIShapesOperations =
1103       aGen->GetIShapesOperations(GetDocID());
1104     anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
1105     SetErrorCode(anIShapesOperations->GetErrorCode());
1106   }
1107
1108   return anInd;
1109 }