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