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