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