1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_ILocalOperations.hxx>
24 #include <GEOM_Function.hxx>
25 #include <GEOM_PythonDump.hxx>
27 #include <GEOMImpl_Types.hxx>
29 #include <GEOMImpl_FilletDriver.hxx>
30 #include <GEOMImpl_ChamferDriver.hxx>
32 #include <GEOMImpl_IFillet.hxx>
33 #include <GEOMImpl_IChamfer.hxx>
35 #include <GEOMImpl_IArchimede.hxx>
36 #include <GEOMImpl_ArchimedeDriver.hxx>
38 #include "utilities.h"
40 #include <Utils_ExceptHandlers.hxx>
42 #include <TFunction_DriverTable.hxx>
43 #include <TFunction_Driver.hxx>
44 #include <TFunction_Logbook.hxx>
45 #include <TDF_Tool.hxx>
48 #include <TopoDS_TShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
53 //=============================================================================
57 //=============================================================================
58 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
59 : GEOM_IOperations(theEngine, theDocID)
61 MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
64 //=============================================================================
68 //=============================================================================
69 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
71 MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
75 //=============================================================================
79 //=============================================================================
80 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
81 (Handle(GEOM_Object) theShape, double theR)
85 //Add a new Fillet object
86 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
88 //Add a new Fillet function
89 Handle(GEOM_Function) aFunction =
90 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
91 if (aFunction.IsNull()) return NULL;
93 //Check if the function is set correctly
94 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
96 GEOMImpl_IFillet aCI (aFunction);
98 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
99 if (aRefShape.IsNull()) return NULL;
101 aCI.SetShape(aRefShape);
104 //Compute the Fillet value
106 if (!GetSolver()->ComputeFunction(aFunction)) {
107 SetErrorCode("Fillet driver failed");
111 catch (Standard_Failure) {
112 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
113 SetErrorCode(aFail->GetMessageString());
117 //Make a Python command
118 GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
119 << theShape << ", " << theR << ")";
125 //=============================================================================
129 //=============================================================================
130 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
131 (Handle(GEOM_Object) theShape, double theR, list<int> theEdges)
135 //Add a new Fillet object
136 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
138 //Add a new Fillet function
139 Handle(GEOM_Function) aFunction =
140 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
141 if (aFunction.IsNull()) return NULL;
143 //Check if the function is set correctly
144 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
146 GEOMImpl_IFillet aCI (aFunction);
148 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
149 if (aRefShape.IsNull()) return NULL;
151 aCI.SetShape(aRefShape);
153 int aLen = theEdges.size();
157 list<int>::iterator it = theEdges.begin();
158 for (; it != theEdges.end(); it++, ind++) {
159 aCI.SetEdge(ind, (*it));
162 //Compute the Fillet value
164 if (!GetSolver()->ComputeFunction(aFunction)) {
165 SetErrorCode("Fillet driver failed");
169 catch (Standard_Failure) {
170 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
171 SetErrorCode(aFail->GetMessageString());
175 //Make a Python command
176 GEOM::TPythonDump pd (aFunction);
177 pd << aFillet << " = geompy.MakeFillet(" << theShape
178 << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
180 it = theEdges.begin();
182 while (it != theEdges.end()) {
183 pd << ", " << (*it++);
191 //=============================================================================
195 //=============================================================================
196 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
197 (Handle(GEOM_Object) theShape, double theR, list<int> theFaces)
201 //Add a new Fillet object
202 Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
204 //Add a new Fillet function
205 Handle(GEOM_Function) aFunction =
206 aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
207 if (aFunction.IsNull()) return NULL;
209 //Check if the function is set correctly
210 if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
212 GEOMImpl_IFillet aCI (aFunction);
214 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
215 if (aRefShape.IsNull()) return NULL;
217 aCI.SetShape(aRefShape);
219 int aLen = theFaces.size();
223 list<int>::iterator it = theFaces.begin();
224 for (; it != theFaces.end(); it++, ind++) {
225 aCI.SetFace(ind, (*it));
228 //Compute the Fillet value
230 if (!GetSolver()->ComputeFunction(aFunction)) {
231 SetErrorCode("Fillet driver failed");
235 catch (Standard_Failure) {
236 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
237 SetErrorCode(aFail->GetMessageString());
241 //Make a Python command
242 GEOM::TPythonDump pd (aFunction);
243 pd << aFillet << " = geompy.MakeFillet(" << theShape
244 << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
246 it = theFaces.begin();
248 while (it != theFaces.end()) {
249 pd << ", " << (*it++);
257 //=============================================================================
261 //=============================================================================
262 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
266 //Add a new Chamfer object
267 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
269 //Add a new Chamfer function
270 Handle(GEOM_Function) aFunction =
271 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
272 if (aFunction.IsNull()) return NULL;
274 //Check if the function is set correctly
275 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
277 GEOMImpl_IChamfer aCI (aFunction);
279 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
280 if (aRefShape.IsNull()) return NULL;
282 aCI.SetShape(aRefShape);
285 //Compute the Chamfer value
287 if (!GetSolver()->ComputeFunction(aFunction)) {
288 SetErrorCode("Chamfer driver failed");
292 catch (Standard_Failure) {
293 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
294 SetErrorCode(aFail->GetMessageString());
298 //Make a Python command
299 GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
300 << theShape << ", " << theD << ")";
306 //=============================================================================
310 //=============================================================================
311 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
312 (Handle(GEOM_Object) theShape, double theD1, double theD2,
313 int theFace1, int theFace2)
317 //Add a new Chamfer object
318 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
320 //Add a new Chamfer function
321 Handle(GEOM_Function) aFunction =
322 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
323 if (aFunction.IsNull()) return NULL;
325 //Check if the function is set correctly
326 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
328 GEOMImpl_IChamfer aCI (aFunction);
330 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
331 if (aRefShape.IsNull()) return NULL;
333 aCI.SetShape(aRefShape);
336 aCI.SetFace1(theFace1);
337 aCI.SetFace2(theFace2);
339 //Compute the Chamfer value
341 if (!GetSolver()->ComputeFunction(aFunction)) {
342 SetErrorCode("Chamfer driver failed");
346 catch (Standard_Failure) {
347 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
348 SetErrorCode(aFail->GetMessageString());
352 //Make a Python command
353 GEOM::TPythonDump(aFunction) << aChamfer
354 << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
355 << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
361 //=============================================================================
365 //=============================================================================
366 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
367 (Handle(GEOM_Object) theShape, double theD1, double theD2,
372 //Add a new Chamfer object
373 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
375 //Add a new Chamfer function
376 Handle(GEOM_Function) aFunction =
377 aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
378 if (aFunction.IsNull()) return NULL;
380 //Check if the function is set correctly
381 if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
383 GEOMImpl_IChamfer aCI (aFunction);
385 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
386 if (aRefShape.IsNull()) return NULL;
388 aCI.SetShape(aRefShape);
391 int aLen = theFaces.size();
395 list<int>::iterator it = theFaces.begin();
396 for (; it != theFaces.end(); it++, ind++) {
397 aCI.SetFace(ind, (*it));
400 //Compute the Chamfer value
402 if (!GetSolver()->ComputeFunction(aFunction)) {
403 SetErrorCode("Chamfer driver failed");
407 catch (Standard_Failure) {
408 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
409 SetErrorCode(aFail->GetMessageString());
413 //Make a Python command
414 GEOM::TPythonDump pd (aFunction);
415 pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
416 << ", " << theD1 << ", " << theD2 << ", [";
418 it = theFaces.begin();
420 while (it != theFaces.end()) {
421 pd << ", " << (*it++);
429 //=============================================================================
433 //=============================================================================
434 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
436 double theWaterDensity,
437 double theMeshingDeflection)
441 //Add a new Archimede object
442 Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
444 //Add a new Archimede function
445 Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
446 if (aFunction.IsNull()) return NULL;
448 //Check if the function is set correctly
449 if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
451 GEOMImpl_IArchimede aAI (aFunction);
453 Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
454 if (aRefShape.IsNull()) return NULL;
456 aAI.SetBasicShape(aRefShape);
457 aAI.SetWeight(theWeight);
458 aAI.SetDensity(theWaterDensity);
459 aAI.SetDeflection(theMeshingDeflection);
461 //Compute the Archimede value
463 if (!GetSolver()->ComputeFunction(aFunction)) {
464 SetErrorCode("Archimede driver failed");
468 catch (Standard_Failure) {
469 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
470 SetErrorCode(aFail->GetMessageString());
474 //Make a Python command
475 GEOM::TPythonDump(aFunction) << aChamfer
476 << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
477 << theWaterDensity << ", " << theMeshingDeflection << ")";
483 //=============================================================================
487 //=============================================================================
488 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
489 TopoDS_Shape& theSubShape)
491 if (theShape.IsNull() || theIndex < 1)
494 TopTools_IndexedMapOfShape anIndices;
495 TopExp::MapShapes(theShape, anIndices);
496 if (theIndex > anIndices.Extent()) return false;
497 theSubShape = anIndices.FindKey(theIndex);
502 //=============================================================================
506 //=============================================================================
507 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
508 Handle(GEOM_Object) theSubShape)
512 TopoDS_Shape aShape = theShape->GetValue();
513 TopoDS_Shape aSubShape = theSubShape->GetValue();
515 if (aShape.IsNull() || aSubShape.IsNull()) return -1;
517 TopTools_IndexedMapOfShape anIndices;
518 TopExp::MapShapes(aShape, anIndices);
519 if (anIndices.Contains(aSubShape)) {
521 return anIndices.FindIndex(aSubShape);