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