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