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