3 #include "GEOMImpl_ILocalOperations.hxx"
5 #include "GEOM_Function.hxx"
6 #include "GEOMImpl_Types.hxx"
8 #include "GEOMImpl_FilletDriver.hxx"
9 #include "GEOMImpl_ChamferDriver.hxx"
11 #include "GEOMImpl_IFillet.hxx"
12 #include "GEOMImpl_IChamfer.hxx"
14 #include "GEOMImpl_IArchimede.hxx"
15 #include "GEOMImpl_ArchimedeDriver.hxx"
17 #include "utilities.h"
19 #include "Utils_ExceptHandlers.hxx"
21 #include <TFunction_DriverTable.hxx>
22 #include <TFunction_Driver.hxx>
23 #include <TFunction_Logbook.hxx>
24 #include <TDF_Tool.hxx>
27 #include <TopoDS_TShape.hxx>
28 #include <TopTools_IndexedMapOfShape.hxx>
30 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
32 //=============================================================================
36 //=============================================================================
37 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
38 : GEOM_IOperations(theEngine, theDocID)
40 MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
43 //=============================================================================
47 //=============================================================================
48 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
50 MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
54 //=============================================================================
58 //=============================================================================
59 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
60 (Handle(GEOM_Object) theShape, double theR)
64 //Add a new Fillet object
65 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
67 //Add a new Fillet function
68 Handle(GEOM_Function) aFunction =
69 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
70 if (aFunction.IsNull()) return NULL;
72 //Check if the function is set correctly
73 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
75 GEOMImpl_IFillet aCI (aFunction);
77 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
78 if (aRefShape.IsNull()) return NULL;
80 aCI.SetShape(aRefShape);
83 //Compute the Fillet value
85 if (!GetSolver()->ComputeFunction(aFunction)) {
86 SetErrorCode("Fillet driver failed");
90 catch (Standard_Failure) {
91 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
92 SetErrorCode(aFail->GetMessageString());
96 //Make a Python command
97 TCollection_AsciiString anEntry, aDescr("");
98 TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
99 aDescr = anEntry + " = ILocalOperations.MakeFilletAll(";
100 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
101 aDescr += (anEntry+", ");
102 aDescr += (TCollection_AsciiString(theR)+")");
104 aFunction->SetDescription(aDescr);
110 //=============================================================================
114 //=============================================================================
115 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
116 (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
120 //Add a new Fillet object
121 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
123 //Add a new Fillet function
124 Handle(GEOM_Function) aFunction =
125 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
126 if (aFunction.IsNull()) return NULL;
128 //Check if the function is set correctly
129 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
131 GEOMImpl_IFillet aCI (aFunction);
133 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
134 if (aRefShape.IsNull()) return NULL;
136 aCI.SetShape(aRefShape);
138 int aLen = theEdges.size();
142 list<int>::iterator it = theEdges.begin();
143 for (; it != theEdges.end(); it++, ind++) {
144 aCI.SetEdge(ind, (*it));
147 //Compute the Fillet value
149 if (!GetSolver()->ComputeFunction(aFunction)) {
150 SetErrorCode("Fillet driver failed");
154 catch (Standard_Failure) {
155 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
156 SetErrorCode(aFail->GetMessageString());
160 //Make a Python command
161 TCollection_AsciiString anEntry, aDescr("");
162 TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
163 aDescr = anEntry + " = ILocalOperations.MakeFilletEdges(";
164 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
165 aDescr += (anEntry+", ");
166 aDescr += (TCollection_AsciiString(theR)+", [");
167 it = theEdges.begin();
168 aDescr += (TCollection_AsciiString(*it)+", ");
170 for (; it != theEdges.end(); it++) {
172 aDescr += TCollection_AsciiString(*it);
176 aFunction->SetDescription(aDescr);
182 //=============================================================================
186 //=============================================================================
187 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
188 (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
192 //Add a new Fillet object
193 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
195 //Add a new Fillet function
196 Handle(GEOM_Function) aFunction =
197 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
198 if (aFunction.IsNull()) return NULL;
200 //Check if the function is set correctly
201 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
203 GEOMImpl_IFillet aCI (aFunction);
205 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
206 if (aRefShape.IsNull()) return NULL;
208 aCI.SetShape(aRefShape);
210 int aLen = theFaces.size();
214 list<int>::iterator it = theFaces.begin();
215 for (; it != theFaces.end(); it++, ind++) {
216 aCI.SetFace(ind, (*it));
219 //Compute the Fillet value
221 if (!GetSolver()->ComputeFunction(aFunction)) {
222 SetErrorCode("Fillet driver failed");
226 catch (Standard_Failure) {
227 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
228 SetErrorCode(aFail->GetMessageString());
232 //Make a Python command
233 TCollection_AsciiString anEntry, aDescr("");
234 TDF_Tool::Entry(aFillet->GetEntry(), anEntry);
235 aDescr = anEntry + " = ILocalOperations.MakeFilletFaces(";
236 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
237 aDescr += (anEntry+", ");
238 aDescr += (TCollection_AsciiString(theR)+", [");
239 it = theFaces.begin();
240 aDescr += (TCollection_AsciiString(*it)+", ");
242 for (; it != theFaces.end(); it++) {
244 aDescr += TCollection_AsciiString(*it);
248 aFunction->SetDescription(aDescr);
254 //=============================================================================
258 //=============================================================================
259 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
263 //Add a new Chamfer object
264 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
266 //Add a new Chamfer function
267 Handle(GEOM_Function) aFunction =
268 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
269 if (aFunction.IsNull()) return NULL;
271 //Check if the function is set correctly
272 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
274 GEOMImpl_IChamfer aCI (aFunction);
276 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
277 if (aRefShape.IsNull()) return NULL;
279 aCI.SetShape(aRefShape);
282 //Compute the Chamfer value
284 if (!GetSolver()->ComputeFunction(aFunction)) {
285 SetErrorCode("Chamfer driver failed");
289 catch (Standard_Failure) {
290 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
291 SetErrorCode(aFail->GetMessageString());
295 //Make a Python command
296 TCollection_AsciiString anEntry, aDescr("");
297 TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
299 aDescr += " = ILocalOperations.MakeChamferAll(";
300 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
301 aDescr += (anEntry+", ");
302 aDescr += (TCollection_AsciiString(theD)+")");
304 aFunction->SetDescription(aDescr);
310 //=============================================================================
314 //=============================================================================
315 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
316 (Handle(GEOM_Object) theShape, double theD1, double theD2,
317 int theFace1, int theFace2)
321 //Add a new Chamfer object
322 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
324 //Add a new Chamfer function
325 Handle(GEOM_Function) aFunction =
326 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
327 if (aFunction.IsNull()) return NULL;
329 //Check if the function is set correctly
330 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
332 GEOMImpl_IChamfer aCI (aFunction);
334 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
335 if (aRefShape.IsNull()) return NULL;
337 aCI.SetShape(aRefShape);
340 aCI.SetFace1(theFace1);
341 aCI.SetFace2(theFace2);
343 //Compute the Chamfer value
345 if (!GetSolver()->ComputeFunction(aFunction)) {
346 SetErrorCode("Chamfer driver failed");
350 catch (Standard_Failure) {
351 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
352 SetErrorCode(aFail->GetMessageString());
356 //Make a Python command
357 TCollection_AsciiString anEntry, aDescr("");
358 TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
360 aDescr += " = ILocalOperations.MakeChamferEdge(";
361 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
362 aDescr += (anEntry+", ");
363 aDescr += (TCollection_AsciiString(theD1)+", ");
364 aDescr += (TCollection_AsciiString(theD2)+", ");
365 aDescr += (TCollection_AsciiString(theFace1)+", ");
366 aDescr += (TCollection_AsciiString(theFace2)+")");
368 aFunction->SetDescription(aDescr);
374 //=============================================================================
378 //=============================================================================
379 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
380 (Handle(GEOM_Object) theShape, double theD1, double theD2,
385 //Add a new Chamfer object
386 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
388 //Add a new Chamfer function
389 Handle(GEOM_Function) aFunction =
390 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
391 if (aFunction.IsNull()) return NULL;
393 //Check if the function is set correctly
394 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
396 GEOMImpl_IChamfer aCI (aFunction);
398 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
399 if (aRefShape.IsNull()) return NULL;
401 aCI.SetShape(aRefShape);
404 int aLen = theFaces.size();
408 list<int>::iterator it = theFaces.begin();
409 for (; it != theFaces.end(); it++, ind++) {
410 aCI.SetFace(ind, (*it));
413 //Compute the Chamfer value
415 if (!GetSolver()->ComputeFunction(aFunction)) {
416 SetErrorCode("Chamfer driver failed");
420 catch (Standard_Failure) {
421 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
422 SetErrorCode(aFail->GetMessageString());
426 //Make a Python command
427 TCollection_AsciiString anEntry, aDescr("");
428 TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
430 aDescr += " = ILocalOperations.MakeChamferFaces(";
431 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
432 aDescr += (anEntry+", ");
433 aDescr += (TCollection_AsciiString(theD1)+", ");
434 aDescr += (TCollection_AsciiString(theD2)+", [");
435 it = theFaces.begin();
436 aDescr += (TCollection_AsciiString(*it)+", ");
438 for (; it != theFaces.end(); it++) {
440 aDescr += TCollection_AsciiString(*it);
444 aFunction->SetDescription(aDescr);
450 //=============================================================================
454 //=============================================================================
455 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
457 double theWaterDensity,
458 double theMeshingDeflection)
462 //Add a new Archimede object
463 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
465 //Add a new Archimede function
466 Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
467 if (aFunction.IsNull()) return NULL;
469 //Check if the function is set correctly
470 if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
472 GEOMImpl_IArchimede aAI (aFunction);
474 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
475 if (aRefShape.IsNull()) return NULL;
477 aAI.SetBasicShape(aRefShape);
478 aAI.SetWeight(theWeight);
479 aAI.SetDensity(theWaterDensity);
480 aAI.SetDeflection(theMeshingDeflection);
482 //Compute the Archimede value
484 if (!GetSolver()->ComputeFunction(aFunction)) {
485 SetErrorCode("Archimede driver failed");
489 catch (Standard_Failure) {
490 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
491 SetErrorCode(aFail->GetMessageString());
495 //Make a Python command
496 TCollection_AsciiString anEntry, aDescr("");
497 TDF_Tool::Entry(aChamfer->GetEntry(), anEntry);
499 aDescr += " = ILocalOperations.MakeArchimede(";
500 TDF_Tool::Entry(theShape->GetEntry(), anEntry);
501 aDescr += (anEntry+", ");
502 aDescr += (TCollection_AsciiString(theWeight)+", ");
503 aDescr += (TCollection_AsciiString(theWaterDensity)+", ");
504 aDescr += (TCollection_AsciiString(theMeshingDeflection)+")");
506 aFunction->SetDescription(aDescr);
512 //=============================================================================
516 //=============================================================================
517 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
518 TopoDS_Shape& theSubShape)
520 if (theShape.IsNull() || theIndex < 1)
523 TopTools_IndexedMapOfShape anIndices;
524 TopExp::MapShapes(theShape, anIndices);
525 if (theIndex > anIndices.Extent()) return false;
526 theSubShape = anIndices.FindKey(theIndex);
531 //=============================================================================
535 //=============================================================================
536 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
537 Handle(GEOM_Object) theSubShape)
541 TopoDS_Shape aShape = theShape->GetValue();
542 TopoDS_Shape aSubShape = theSubShape->GetValue();
544 if (aShape.IsNull() || aSubShape.IsNull()) return -1;
546 TopTools_IndexedMapOfShape anIndices;
547 TopExp::MapShapes(aShape, anIndices);
548 if (anIndices.Contains(aSubShape)) {
550 return anIndices.FindIndex(aSubShape);