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