Salome HOME
726b8271953b55958d581b6f85ea00d82866aadc
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ILocalOperations.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <GEOMImpl_ILocalOperations.hxx>
26
27 #include <GEOMImpl_Types.hxx>
28
29 #include <GEOMImpl_FilletDriver.hxx>
30 #include <GEOMImpl_Fillet1dDriver.hxx>
31 #include <GEOMImpl_Fillet2dDriver.hxx>
32 #include <GEOMImpl_ChamferDriver.hxx>
33
34 #include <GEOMImpl_IFillet.hxx>
35 #include <GEOMImpl_IFillet1d.hxx>
36 #include <GEOMImpl_IFillet2d.hxx>
37 #include <GEOMImpl_IChamfer.hxx>
38
39 #include <GEOMImpl_IArchimede.hxx>
40 #include <GEOMImpl_ArchimedeDriver.hxx>
41
42 #include <GEOMImpl_Gen.hxx>
43 #include <GEOMImpl_IShapesOperations.hxx>
44
45 #include <GEOM_Function.hxx>
46 #include <GEOM_PythonDump.hxx>
47
48 #include <Basics_OCCTVersion.hxx>
49
50 #include "utilities.h"
51 #include <OpUtil.hxx>
52 #include <Utils_ExceptHandlers.hxx>
53
54 #include <TFunction_DriverTable.hxx>
55 #include <TFunction_Driver.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)
71 : GEOM_IOperations(theEngine)
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(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     OCC_CATCH_SIGNALS;
119     if (!GetSolver()->ComputeFunction(aFunction)) {
120       SetErrorCode("Fillet driver failed");
121       return NULL;
122     }
123   }
124   catch (Standard_Failure) {
125     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
126     SetErrorCode(aFail->GetMessageString());
127     return NULL;
128   }
129
130   //Make a Python command
131   GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
132                                << theShape << ", " << theR << ")";
133
134   SetErrorCode(OK);
135   return aFillet;
136 }
137
138 //=============================================================================
139 /*!
140  *  MakeFilletEdges
141  */
142 //=============================================================================
143 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
144        (Handle(GEOM_Object) theShape, double theR, std::list<int> theEdges)
145 {
146   SetErrorCode(KO);
147
148   //Add a new Fillet object
149   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GEOM_FILLET);
150
151   //Add a new Fillet function
152   Handle(GEOM_Function) aFunction =
153     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
154   if (aFunction.IsNull()) return NULL;
155
156   //Check if the function is set correctly
157   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
158
159   GEOMImpl_IFillet aCI (aFunction);
160
161   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
162   if (aRefShape.IsNull()) return NULL;
163
164   aCI.SetShape(aRefShape);
165   aCI.SetR(theR);
166   int aLen = theEdges.size();
167   aCI.SetLength(aLen);
168
169   int ind = 1;
170   std::list<int>::iterator it = theEdges.begin();
171   for (; it != theEdges.end(); it++, ind++) {
172     aCI.SetEdge(ind, (*it));
173   }
174
175   //Compute the Fillet value
176   try {
177     OCC_CATCH_SIGNALS;
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, std::list<int> theEdges)
212 {
213   SetErrorCode(KO);
214
215   //Add a new Fillet object
216   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(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   std::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     OCC_CATCH_SIGNALS;
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(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     OCC_CATCH_SIGNALS;
314     if (!GetSolver()->ComputeFunction(aFunction)) {
315       SetErrorCode("Fillet driver failed");
316       return NULL;
317     }
318   }
319   catch (Standard_Failure) {
320     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
321     SetErrorCode(aFail->GetMessageString());
322     return NULL;
323   }
324
325   //Make a Python command
326   GEOM::TPythonDump pd (aFunction);
327   pd << aFillet << " = geompy.MakeFillet(" << theShape
328     << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
329
330   it = theFaces.begin();
331   pd << (*it++);
332   while (it != theFaces.end()) {
333     pd << ", " << (*it++);
334   }
335   pd << "])";
336
337   SetErrorCode(OK);
338   return aFillet;
339 }
340
341 //=============================================================================
342 /*!
343  *  MakeFilletFaces R1 R2
344  */
345 //=============================================================================
346 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFacesR1R2
347        (Handle(GEOM_Object) theShape, double theR1, double theR2, std::list<int> theFaces)
348 {
349   SetErrorCode(KO);
350
351   //Add a new Fillet object
352   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GEOM_FILLET);
353
354   //Add a new Fillet function
355   Handle(GEOM_Function) aFunction =
356     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES_2R);
357   if (aFunction.IsNull()) return NULL;
358
359   //Check if the function is set correctly
360   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
361
362   GEOMImpl_IFillet aCI (aFunction);
363
364   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
365   if (aRefShape.IsNull()) return NULL;
366
367   aCI.SetShape(aRefShape);
368   aCI.SetR1(theR1);
369   aCI.SetR2(theR2);
370   int aLen = theFaces.size();
371   aCI.SetLength(aLen);
372
373   int ind = 1;
374   std::list<int>::iterator it = theFaces.begin();
375   for (; it != theFaces.end(); it++, ind++) {
376     aCI.SetFace(ind, (*it));
377   }
378
379   //Compute the Fillet value
380   try {
381     OCC_CATCH_SIGNALS;
382     if (!GetSolver()->ComputeFunction(aFunction)) {
383       SetErrorCode("Fillet driver failed");
384       return NULL;
385     }
386   }
387   catch (Standard_Failure) {
388     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
389     SetErrorCode(aFail->GetMessageString());
390     return NULL;
391   }
392
393   //Make a Python command
394   GEOM::TPythonDump pd (aFunction);
395   pd << aFillet << " = geompy.MakeFilletR1R2(" << theShape
396     << ", " << theR1 << ", " << theR2 << ", geompy.ShapeType[\"FACE\"], [";
397
398   it = theFaces.begin();
399   pd << (*it++);
400   while (it != theFaces.end()) {
401     pd << ", " << (*it++);
402   }
403   pd << "])";
404
405   SetErrorCode(OK);
406   return aFillet;
407 }
408
409 //=============================================================================
410 /*!
411  *  MakeFillet2D
412  */
413 //=============================================================================
414 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFillet2D
415        (Handle(GEOM_Object) theShape, double theR, std::list<int> theVertexes)
416 {
417   SetErrorCode(KO);
418
419   //Add a new Fillet object
420   Handle(GEOM_Object) aFillet2D = GetEngine()->AddObject(GEOM_FILLET_2D);
421
422   //Add a new Fillet function
423   Handle(GEOM_Function) aFunction =
424     aFillet2D->AddFunction(GEOMImpl_Fillet2dDriver::GetID(), FILLET_2D_SHAPE_VERTEXES);
425   if (aFunction.IsNull()) return NULL;
426
427   //Check if the function is set correctly
428   if (aFunction->GetDriverGUID() != GEOMImpl_Fillet2dDriver::GetID()) return NULL;
429
430   GEOMImpl_IFillet2d aCI (aFunction);
431
432   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
433   if (aRefShape.IsNull()) return NULL;
434
435   aCI.SetShape(aRefShape);
436   aCI.SetR(theR);
437   int aLen = theVertexes.size();
438   aCI.SetLength(aLen);
439
440   int ind = 1;
441   std::list<int>::iterator it = theVertexes.begin();
442   for (; it != theVertexes.end(); it++, ind++) {
443     aCI.SetVertex(ind, (*it));
444   }
445
446   //Compute the Fillet value
447   try {
448     OCC_CATCH_SIGNALS;
449     if (!GetSolver()->ComputeFunction(aFunction)) {
450       SetErrorCode("2D Fillet driver failed");
451       return NULL;
452     }
453   }
454   catch (Standard_Failure) {
455     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
456     SetErrorCode(aFail->GetMessageString());
457     return NULL;
458   }
459
460   //Make a Python command
461   GEOM::TPythonDump pd (aFunction);
462   pd << aFillet2D << " = geompy.MakeFillet2D(" << theShape
463     << ", " << theR << ", [";
464
465   it = theVertexes.begin();
466   pd << (*it++);
467   while (it != theVertexes.end()) {
468     pd << ", " << (*it++);
469   }
470   pd << "])";
471
472   SetErrorCode(OK);
473   return aFillet2D;
474 }
475
476 //=============================================================================
477 /*!
478  *  MakeFillet1D
479  */
480 //=============================================================================
481 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFillet1D
482                       (Handle(GEOM_Object) theShape, double theR,
483                        std::list<int> theVertexes, bool doIgnoreSecantVertices)
484 {
485   SetErrorCode(KO);
486
487   //Add a new Fillet object
488   Handle(GEOM_Object) aFillet1D = GetEngine()->AddObject(GEOM_FILLET_1D);
489
490   //Add a new Fillet function
491   Handle(GEOM_Function) aFunction =
492     aFillet1D->AddFunction(GEOMImpl_Fillet1dDriver::GetID(), FILLET_1D_SHAPE_VERTEXES);
493   if (aFunction.IsNull()) return NULL;
494
495   //Check if the function is set correctly
496   if (aFunction->GetDriverGUID() != GEOMImpl_Fillet1dDriver::GetID()) return NULL;
497
498   GEOMImpl_IFillet1d aCI (aFunction);
499
500   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
501   if (aRefShape.IsNull()) return NULL;
502
503   aCI.SetShape(aRefShape);
504   aCI.SetR(theR);
505   aCI.SetFlag(doIgnoreSecantVertices);
506   int aLen = theVertexes.size();
507   aCI.SetLength(aLen);
508
509   int ind = 1;
510   std::list<int>::iterator it = theVertexes.begin();
511   for (; it != theVertexes.end(); it++, ind++) {
512     aCI.SetVertex(ind, (*it));
513   }
514
515   //Compute the Fillet value
516   try {
517     OCC_CATCH_SIGNALS;
518     if (!GetSolver()->ComputeFunction(aFunction)) {
519       SetErrorCode("1D Fillet driver failed");
520       return NULL;
521     }
522   }
523   catch (Standard_Failure) {
524     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
525     SetErrorCode(aFail->GetMessageString());
526     return NULL;
527   }
528
529   //Make a Python command
530   GEOM::TPythonDump pd (aFunction);
531   pd << aFillet1D << " = geompy.MakeFillet1D(" << theShape
532     << ", " << theR << ", [";
533
534   it = theVertexes.begin();
535   if (it != theVertexes.end()) {
536     pd << (*it++);
537     while (it != theVertexes.end())
538       pd << ", " << (*it++);
539   }
540   pd << "])";
541
542   SetErrorCode(OK);
543   return aFillet1D;
544 }
545
546 //=============================================================================
547 /*!
548  *  MakeChamferAll
549  */
550 //=============================================================================
551 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
552 {
553   SetErrorCode(KO);
554
555   //Add a new Chamfer object
556   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
557
558   //Add a new Chamfer function
559   Handle(GEOM_Function) aFunction =
560     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
561   if (aFunction.IsNull()) return NULL;
562
563   //Check if the function is set correctly
564   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
565
566   GEOMImpl_IChamfer aCI (aFunction);
567
568   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
569   if (aRefShape.IsNull()) return NULL;
570
571   aCI.SetShape(aRefShape);
572   aCI.SetD(theD);
573
574   //Compute the Chamfer value
575   try {
576     OCC_CATCH_SIGNALS;
577     if (!GetSolver()->ComputeFunction(aFunction)) {
578       SetErrorCode("Chamfer driver failed");
579       return NULL;
580     }
581   }
582   catch (Standard_Failure) {
583     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
584     SetErrorCode(aFail->GetMessageString());
585     return NULL;
586   }
587
588   //Make a Python command
589   GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
590                                << theShape << ", " << theD << ")";
591
592   SetErrorCode(OK);
593   return aChamfer;
594 }
595
596 //=============================================================================
597 /*!
598  *  MakeChamferEdge
599  */
600 //=============================================================================
601 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
602                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
603                              int theFace1, int theFace2)
604 {
605   SetErrorCode(KO);
606
607   //Add a new Chamfer object
608   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
609
610   //Add a new Chamfer function
611   Handle(GEOM_Function) aFunction =
612     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
613   if (aFunction.IsNull()) return NULL;
614
615   //Check if the function is set correctly
616   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
617
618   GEOMImpl_IChamfer aCI (aFunction);
619
620   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
621   if (aRefShape.IsNull()) return NULL;
622
623   aCI.SetShape(aRefShape);
624   aCI.SetD1(theD1);
625   aCI.SetD2(theD2);
626   aCI.SetFace1(theFace1);
627   aCI.SetFace2(theFace2);
628
629   //Compute the Chamfer value
630   try {
631     OCC_CATCH_SIGNALS;
632     if (!GetSolver()->ComputeFunction(aFunction)) {
633       SetErrorCode("Chamfer driver failed");
634       return NULL;
635     }
636   }
637   catch (Standard_Failure) {
638     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
639     SetErrorCode(aFail->GetMessageString());
640     return NULL;
641   }
642
643   //Make a Python command
644   GEOM::TPythonDump(aFunction) << aChamfer
645     << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
646       << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
647
648   SetErrorCode(OK);
649   return aChamfer;
650 }
651
652 //=============================================================================
653 /*!
654  *  MakeChamferEdgeAD
655  */
656 //=============================================================================
657 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgeAD
658                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
659                              int theFace1, int theFace2)
660 {
661   SetErrorCode(KO);
662
663   //Add a new Chamfer object
664   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
665
666   //Add a new Chamfer function
667   Handle(GEOM_Function) aFunction =
668     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE_AD);
669   if (aFunction.IsNull()) return NULL;
670
671   //Check if the function is set correctly
672   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
673
674   GEOMImpl_IChamfer aCI (aFunction);
675
676   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
677   if (aRefShape.IsNull()) return NULL;
678
679   aCI.SetShape(aRefShape);
680   aCI.SetD(theD);
681   aCI.SetAngle(theAngle);
682   aCI.SetFace1(theFace1);
683   aCI.SetFace2(theFace2);
684
685   //Compute the Chamfer value
686   try {
687     OCC_CATCH_SIGNALS;
688     if (!GetSolver()->ComputeFunction(aFunction)) {
689       SetErrorCode("Chamfer driver failed");
690       return NULL;
691     }
692   }
693   catch (Standard_Failure) {
694     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
695     SetErrorCode(aFail->GetMessageString());
696     return NULL;
697   }
698
699   //Make a Python command
700   GEOM::TPythonDump(aFunction) << aChamfer
701     << " = geompy.MakeChamferEdgeAD(" << theShape << ", " << theD
702       << ", " << theAngle << ", " << theFace1 << ", " << theFace2 << ")";
703   SetErrorCode(OK);
704   return aChamfer;
705 }
706
707 //=============================================================================
708 /*!
709  *  MakeChamferFaces
710  */
711 //=============================================================================
712 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
713                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
714                              std::list<int> theFaces)
715 {
716   SetErrorCode(KO);
717
718   //Add a new Chamfer object
719   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
720
721   //Add a new Chamfer function
722   Handle(GEOM_Function) aFunction =
723     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
724   if (aFunction.IsNull()) return NULL;
725
726   //Check if the function is set correctly
727   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
728
729   GEOMImpl_IChamfer aCI (aFunction);
730
731   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
732   if (aRefShape.IsNull()) return NULL;
733
734   aCI.SetShape(aRefShape);
735   aCI.SetD1(theD1);
736   aCI.SetD2(theD2);
737   int aLen = theFaces.size();
738   aCI.SetLength(aLen);
739
740   int ind = 1;
741   std::list<int>::iterator it = theFaces.begin();
742   for (; it != theFaces.end(); it++, ind++) {
743     aCI.SetFace(ind, (*it));
744   }
745
746   //Compute the Chamfer value
747   try {
748     OCC_CATCH_SIGNALS;
749     if (!GetSolver()->ComputeFunction(aFunction)) {
750       SetErrorCode("Chamfer driver failed");
751       return NULL;
752     }
753   }
754   catch (Standard_Failure) {
755     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
756     SetErrorCode(aFail->GetMessageString());
757     return NULL;
758   }
759
760   //Make a Python command
761   GEOM::TPythonDump pd (aFunction);
762   pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
763     << ", " << theD1 << ", " << theD2 << ", [";
764
765   it = theFaces.begin();
766   pd << (*it++);
767   while (it != theFaces.end()) {
768     pd << ", " << (*it++);
769   }
770   pd << "])";
771
772   SetErrorCode(OK);
773   return aChamfer;
774 }
775
776 //=============================================================================
777 /*!
778  *  MakeChamferFacesAD
779  */
780 //=============================================================================
781 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFacesAD
782                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
783                              std::list<int> theFaces)
784 {
785   SetErrorCode(KO);
786
787   //Add a new Chamfer object
788   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
789
790   //Add a new Chamfer function
791   Handle(GEOM_Function) aFunction =
792     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES_AD);
793   if (aFunction.IsNull()) return NULL;
794
795   //Check if the function is set correctly
796   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
797
798   GEOMImpl_IChamfer aCI (aFunction);
799
800   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
801   if (aRefShape.IsNull()) return NULL;
802
803   aCI.SetShape(aRefShape);
804   aCI.SetD(theD);
805   aCI.SetAngle(theAngle);
806   int aLen = theFaces.size();
807   aCI.SetLength(aLen);
808
809   int ind = 1;
810   std::list<int>::iterator it = theFaces.begin();
811   for (; it != theFaces.end(); it++, ind++) {
812     aCI.SetFace(ind, (*it));
813   }
814
815   //Compute the Chamfer value
816   try {
817     OCC_CATCH_SIGNALS;
818     if (!GetSolver()->ComputeFunction(aFunction)) {
819       SetErrorCode("Chamfer driver failed");
820       return NULL;
821     }
822   }
823   catch (Standard_Failure) {
824     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
825     SetErrorCode(aFail->GetMessageString());
826     return NULL;
827   }
828
829   //Make a Python command
830   GEOM::TPythonDump pd (aFunction);
831   pd << aChamfer << " = geompy.MakeChamferFacesAD(" << theShape
832     << ", " << theD << ", " << theAngle << ", [";
833
834   it = theFaces.begin();
835   pd << (*it++);
836   while (it != theFaces.end()) {
837     pd << ", " << (*it++);
838   }
839   pd << "])";
840
841   SetErrorCode(OK);
842   return aChamfer;
843 }
844
845 //=============================================================================
846 /*!
847  *  MakeChamferEdges
848  */
849 //=============================================================================
850 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdges
851                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
852                              std::list<int> theEdges)
853 {
854   SetErrorCode(KO);
855
856   //Add a new Chamfer object
857   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
858
859   //Add a new Chamfer function
860   Handle(GEOM_Function) aFunction =
861     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES);
862   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL;}
863
864   //Check if the function is set correctly
865   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
866         { MESSAGE ( "Chamfer Driver is NULL!!!" ); return NULL; }
867
868   GEOMImpl_IChamfer aCI (aFunction);
869
870   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
871   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
872
873   aCI.SetShape(aRefShape);
874   aCI.SetD1(theD1);
875   aCI.SetD2(theD2);
876   int aLen = theEdges.size();
877   aCI.SetLength(aLen);
878
879   int ind = 1;
880   std::list<int>::iterator it = theEdges.begin();
881   for (; it != theEdges.end(); it++, ind++) {
882     aCI.SetEdge(ind, (*it));
883   }
884
885   //Compute the Chamfer value
886   try {
887     OCC_CATCH_SIGNALS;
888     if (!GetSolver()->ComputeFunction(aFunction)) {
889       SetErrorCode("Chamfer driver failed");
890       return NULL;
891     }
892   }
893   catch (Standard_Failure) {
894     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
895     SetErrorCode(aFail->GetMessageString());
896     return NULL;
897   }
898
899   //Make a Python command
900   GEOM::TPythonDump pd (aFunction);
901   pd << aChamfer << " = geompy.MakeChamferEdges(" << theShape
902     << ", " << theD1 << ", " << theD2 << ", [";
903
904   it = theEdges.begin();
905   pd << (*it++);
906   while (it != theEdges.end()) {
907     pd << ", " << (*it++);
908   }
909   pd << "])";
910
911   SetErrorCode(OK);
912   return aChamfer;
913 }
914
915 //=============================================================================
916 /*!
917  *  MakeChamferEdgesAD
918  */
919 //=============================================================================
920 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgesAD
921                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
922                              std::list<int> theEdges)
923 {
924   SetErrorCode(KO);
925
926   //Add a new Chamfer object
927   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_CHAMFER);
928
929   //Add a new Chamfer function
930   Handle(GEOM_Function) aFunction =
931     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_AD);
932   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL; }
933
934   //Check if the function is set correctly
935   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
936         { MESSAGE("Chamfer Driver is NULL!!!"); return NULL;}
937
938   GEOMImpl_IChamfer aCI (aFunction);
939
940   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
941   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
942
943   aCI.SetShape(aRefShape);
944   aCI.SetD(theD);
945   aCI.SetAngle(theAngle);
946   int aLen = theEdges.size();
947   aCI.SetLength(aLen);
948
949   int ind = 1;
950   std::list<int>::iterator it = theEdges.begin();
951   for (; it != theEdges.end(); it++, ind++) {
952     aCI.SetEdge(ind, (*it));
953   }
954
955   //Compute the Chamfer value
956   try {
957     OCC_CATCH_SIGNALS;
958     if (!GetSolver()->ComputeFunction(aFunction)) {
959       SetErrorCode("Chamfer driver failed");
960       return NULL;
961     }
962   }
963   catch (Standard_Failure) {
964     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
965     SetErrorCode(aFail->GetMessageString());
966     return NULL;
967   }
968
969   //Make a Python command
970   GEOM::TPythonDump pd (aFunction);
971   pd << aChamfer << " = geompy.MakeChamferEdgesAD(" << theShape
972     << ", " << theD << ", " << theAngle << ", [";
973
974   it = theEdges.begin();
975   pd << (*it++);
976   while (it != theEdges.end()) {
977     pd << ", " << (*it++);
978   }
979   pd << "])";
980
981   SetErrorCode(OK);
982   return aChamfer;
983 }
984
985 //=============================================================================
986 /*!
987  *  Archimede
988  */
989 //=============================================================================
990 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
991                                                               double theWeight,
992                                                               double theWaterDensity,
993                                                               double theMeshingDeflection)
994 {
995   SetErrorCode(KO);
996
997   //Add a new Archimede object
998   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GEOM_ARCHIMEDE);
999
1000   //Add a new Archimede function
1001   Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
1002   if (aFunction.IsNull()) return NULL;
1003
1004   //Check if the function is set correctly
1005   if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
1006
1007   GEOMImpl_IArchimede aAI (aFunction);
1008
1009   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
1010   if (aRefShape.IsNull()) return NULL;
1011
1012   aAI.SetBasicShape(aRefShape);
1013   aAI.SetWeight(theWeight);
1014   aAI.SetDensity(theWaterDensity);
1015   aAI.SetDeflection(theMeshingDeflection);
1016
1017   //Compute the Archimede value
1018   try {
1019     OCC_CATCH_SIGNALS;
1020     if (!GetSolver()->ComputeFunction(aFunction)) {
1021       SetErrorCode("Archimede driver failed");
1022       return NULL;
1023     }
1024   }
1025   catch (Standard_Failure) {
1026     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1027     SetErrorCode(aFail->GetMessageString());
1028     return NULL;
1029   }
1030
1031   //Make a Python command
1032   GEOM::TPythonDump(aFunction) << aChamfer
1033     << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
1034       << theWaterDensity << ", " << theMeshingDeflection << ")";
1035
1036   SetErrorCode(OK);
1037   return aChamfer;
1038 }
1039
1040 //=============================================================================
1041 /*!
1042  *  GetSubShape
1043  */
1044 //=============================================================================
1045 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
1046                                              TopoDS_Shape& theSubShape)
1047 {
1048   if (theShape.IsNull() || theIndex < 1)
1049     return false;
1050
1051   TopTools_IndexedMapOfShape anIndices;
1052   TopExp::MapShapes(theShape, anIndices);
1053   if (theIndex > anIndices.Extent()) return false;
1054   theSubShape = anIndices.FindKey(theIndex);
1055
1056   return true;
1057 }
1058
1059 //=============================================================================
1060 /*!
1061  *  GetSubShapeIndex
1062  */
1063 //=============================================================================
1064 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
1065                                                               Handle(GEOM_Object) theSubShape)
1066 {
1067   SetErrorCode(KO);
1068
1069   Standard_Integer anInd = -1;
1070   GEOM_Engine* anEngine = GetEngine();
1071   //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
1072   GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
1073
1074   if (aGen) {
1075     GEOMImpl_IShapesOperations* anIShapesOperations =
1076       aGen->GetIShapesOperations();
1077     anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
1078     SetErrorCode(anIShapesOperations->GetErrorCode());
1079   }
1080
1081   return anInd;
1082 }