1 #include <Standard_Stream.hxx>
3 #include <GEOMImpl_ILocalOperations.hxx>
5 #include <GEOM_Function.hxx>
6 #include <GEOM_PythonDump.hxx>
8 #include <GEOMImpl_Types.hxx>
10 #include <GEOMImpl_FilletDriver.hxx>
11 #include <GEOMImpl_ChamferDriver.hxx>
13 #include <GEOMImpl_IFillet.hxx>
14 #include <GEOMImpl_IChamfer.hxx>
16 #include <GEOMImpl_IArchimede.hxx>
17 #include <GEOMImpl_ArchimedeDriver.hxx>
19 #include "utilities.h"
21 #include <Utils_ExceptHandlers.hxx>
23 #include <TFunction_DriverTable.hxx>
24 #include <TFunction_Driver.hxx>
25 #include <TFunction_Logbook.hxx>
26 #include <TDF_Tool.hxx>
29 #include <TopoDS_TShape.hxx>
30 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
34 //=============================================================================
38 //=============================================================================
39 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
40 : GEOM_IOperations(theEngine, theDocID)
42 MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
45 //=============================================================================
49 //=============================================================================
50 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
52 MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
56 //=============================================================================
60 //=============================================================================
61 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
62 (Handle(GEOM_Object) theShape, double theR)
66 //Add a new Fillet object
67 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
69 //Add a new Fillet function
70 Handle(GEOM_Function) aFunction =
71 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
72 if (aFunction.IsNull()) return NULL;
74 //Check if the function is set correctly
75 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
77 GEOMImpl_IFillet aCI (aFunction);
79 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
80 if (aRefShape.IsNull()) return NULL;
82 aCI.SetShape(aRefShape);
85 //Compute the Fillet value
87 if (!GetSolver()->ComputeFunction(aFunction)) {
88 SetErrorCode("Fillet driver failed");
92 catch (Standard_Failure) {
93 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
94 SetErrorCode(aFail->GetMessageString());
98 //Make a Python command
99 GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
100 << theShape << ", " << theR << ")";
106 //=============================================================================
110 //=============================================================================
111 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
112 (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
116 //Add a new Fillet object
117 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
119 //Add a new Fillet function
120 Handle(GEOM_Function) aFunction =
121 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
122 if (aFunction.IsNull()) return NULL;
124 //Check if the function is set correctly
125 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
127 GEOMImpl_IFillet aCI (aFunction);
129 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
130 if (aRefShape.IsNull()) return NULL;
132 aCI.SetShape(aRefShape);
134 int aLen = theEdges.size();
138 list<int>::iterator it = theEdges.begin();
139 for (; it != theEdges.end(); it++, ind++) {
140 aCI.SetEdge(ind, (*it));
143 //Compute the Fillet value
145 if (!GetSolver()->ComputeFunction(aFunction)) {
146 SetErrorCode("Fillet driver failed");
150 catch (Standard_Failure) {
151 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
152 SetErrorCode(aFail->GetMessageString());
156 //Make a Python command
157 GEOM::TPythonDump pd (aFunction);
158 pd << aFillet << " = geompy.MakeFillet(" << theShape
159 << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
161 it = theEdges.begin();
163 while (it != theEdges.end()) {
164 pd << ", " << (*it++);
172 //=============================================================================
176 //=============================================================================
177 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
178 (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
182 //Add a new Fillet object
183 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
185 //Add a new Fillet function
186 Handle(GEOM_Function) aFunction =
187 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
188 if (aFunction.IsNull()) return NULL;
190 //Check if the function is set correctly
191 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
193 GEOMImpl_IFillet aCI (aFunction);
195 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
196 if (aRefShape.IsNull()) return NULL;
198 aCI.SetShape(aRefShape);
200 int aLen = theFaces.size();
204 list<int>::iterator it = theFaces.begin();
205 for (; it != theFaces.end(); it++, ind++) {
206 aCI.SetFace(ind, (*it));
209 //Compute the Fillet value
211 if (!GetSolver()->ComputeFunction(aFunction)) {
212 SetErrorCode("Fillet driver failed");
216 catch (Standard_Failure) {
217 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
218 SetErrorCode(aFail->GetMessageString());
222 //Make a Python command
223 GEOM::TPythonDump pd (aFunction);
224 pd << aFillet << " = geompy.MakeFillet(" << theShape
225 << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
227 it = theFaces.begin();
229 while (it != theFaces.end()) {
230 pd << ", " << (*it++);
238 //=============================================================================
242 //=============================================================================
243 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
247 //Add a new Chamfer object
248 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
250 //Add a new Chamfer function
251 Handle(GEOM_Function) aFunction =
252 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
253 if (aFunction.IsNull()) return NULL;
255 //Check if the function is set correctly
256 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
258 GEOMImpl_IChamfer aCI (aFunction);
260 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
261 if (aRefShape.IsNull()) return NULL;
263 aCI.SetShape(aRefShape);
266 //Compute the Chamfer value
268 if (!GetSolver()->ComputeFunction(aFunction)) {
269 SetErrorCode("Chamfer driver failed");
273 catch (Standard_Failure) {
274 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
275 SetErrorCode(aFail->GetMessageString());
279 //Make a Python command
280 GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
281 << theShape << ", " << theD << ")";
287 //=============================================================================
291 //=============================================================================
292 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
293 (Handle(GEOM_Object) theShape, double theD1, double theD2,
294 int theFace1, int theFace2)
298 //Add a new Chamfer object
299 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
301 //Add a new Chamfer function
302 Handle(GEOM_Function) aFunction =
303 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
304 if (aFunction.IsNull()) return NULL;
306 //Check if the function is set correctly
307 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
309 GEOMImpl_IChamfer aCI (aFunction);
311 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
312 if (aRefShape.IsNull()) return NULL;
314 aCI.SetShape(aRefShape);
317 aCI.SetFace1(theFace1);
318 aCI.SetFace2(theFace2);
320 //Compute the Chamfer value
322 if (!GetSolver()->ComputeFunction(aFunction)) {
323 SetErrorCode("Chamfer driver failed");
327 catch (Standard_Failure) {
328 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
329 SetErrorCode(aFail->GetMessageString());
333 //Make a Python command
334 GEOM::TPythonDump(aFunction) << aChamfer
335 << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
336 << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
342 //=============================================================================
346 //=============================================================================
347 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
348 (Handle(GEOM_Object) theShape, double theD1, double theD2,
353 //Add a new Chamfer object
354 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
356 //Add a new Chamfer function
357 Handle(GEOM_Function) aFunction =
358 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
359 if (aFunction.IsNull()) return NULL;
361 //Check if the function is set correctly
362 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
364 GEOMImpl_IChamfer aCI (aFunction);
366 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
367 if (aRefShape.IsNull()) return NULL;
369 aCI.SetShape(aRefShape);
372 int aLen = theFaces.size();
376 list<int>::iterator it = theFaces.begin();
377 for (; it != theFaces.end(); it++, ind++) {
378 aCI.SetFace(ind, (*it));
381 //Compute the Chamfer value
383 if (!GetSolver()->ComputeFunction(aFunction)) {
384 SetErrorCode("Chamfer driver failed");
388 catch (Standard_Failure) {
389 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
390 SetErrorCode(aFail->GetMessageString());
394 //Make a Python command
395 GEOM::TPythonDump pd (aFunction);
396 pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
397 << ", " << theD1 << ", " << theD2 << ", [";
399 it = theFaces.begin();
401 while (it != theFaces.end()) {
402 pd << ", " << (*it++);
410 //=============================================================================
414 //=============================================================================
415 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
417 double theWaterDensity,
418 double theMeshingDeflection)
422 //Add a new Archimede object
423 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
425 //Add a new Archimede function
426 Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
427 if (aFunction.IsNull()) return NULL;
429 //Check if the function is set correctly
430 if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
432 GEOMImpl_IArchimede aAI (aFunction);
434 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
435 if (aRefShape.IsNull()) return NULL;
437 aAI.SetBasicShape(aRefShape);
438 aAI.SetWeight(theWeight);
439 aAI.SetDensity(theWaterDensity);
440 aAI.SetDeflection(theMeshingDeflection);
442 //Compute the Archimede value
444 if (!GetSolver()->ComputeFunction(aFunction)) {
445 SetErrorCode("Archimede driver failed");
449 catch (Standard_Failure) {
450 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
451 SetErrorCode(aFail->GetMessageString());
455 //Make a Python command
456 GEOM::TPythonDump(aFunction) << aChamfer
457 << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
458 << theWaterDensity << ", " << theMeshingDeflection << ")";
464 //=============================================================================
468 //=============================================================================
469 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
470 TopoDS_Shape& theSubShape)
472 if (theShape.IsNull() || theIndex < 1)
475 TopTools_IndexedMapOfShape anIndices;
476 TopExp::MapShapes(theShape, anIndices);
477 if (theIndex > anIndices.Extent()) return false;
478 theSubShape = anIndices.FindKey(theIndex);
483 //=============================================================================
487 //=============================================================================
488 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
489 Handle(GEOM_Object) theSubShape)
493 TopoDS_Shape aShape = theShape->GetValue();
494 TopoDS_Shape aSubShape = theSubShape->GetValue();
496 if (aShape.IsNull() || aSubShape.IsNull()) return -1;
498 TopTools_IndexedMapOfShape anIndices;
499 TopExp::MapShapes(aShape, anIndices);
500 if (anIndices.Contains(aSubShape)) {
502 return anIndices.FindIndex(aSubShape);