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