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