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