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