Back to index

salome-geom  6.5.0
GEOMImpl_ILocalOperations.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_ILocalOperations.hxx>
00026 
00027 #include <GEOMImpl_Types.hxx>
00028 
00029 #include <GEOMImpl_FilletDriver.hxx>
00030 #include <GEOMImpl_Fillet1dDriver.hxx>
00031 #include <GEOMImpl_Fillet2dDriver.hxx>
00032 #include <GEOMImpl_ChamferDriver.hxx>
00033 
00034 #include <GEOMImpl_IFillet.hxx>
00035 #include <GEOMImpl_IFillet1d.hxx>
00036 #include <GEOMImpl_IFillet2d.hxx>
00037 #include <GEOMImpl_IChamfer.hxx>
00038 
00039 #include <GEOMImpl_IArchimede.hxx>
00040 #include <GEOMImpl_ArchimedeDriver.hxx>
00041 
00042 #include <GEOMImpl_Gen.hxx>
00043 #include <GEOMImpl_IShapesOperations.hxx>
00044 
00045 #include <GEOM_Function.hxx>
00046 #include <GEOM_PythonDump.hxx>
00047 
00048 #include <Basics_OCCTVersion.hxx>
00049 
00050 #include "utilities.h"
00051 #include <OpUtil.hxx>
00052 #include <Utils_ExceptHandlers.hxx>
00053 
00054 #include <TFunction_DriverTable.hxx>
00055 #include <TFunction_Driver.hxx>
00056 #include <TFunction_Logbook.hxx>
00057 #include <TDF_Tool.hxx>
00058 
00059 #include <TopExp.hxx>
00060 #include <TopoDS_TShape.hxx>
00061 #include <TopTools_IndexedMapOfShape.hxx>
00062 
00063 #include <Standard_Failure.hxx>
00064 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
00065 
00066 //=============================================================================
00070 //=============================================================================
00071 GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations (GEOM_Engine* theEngine, int theDocID)
00072 : GEOM_IOperations(theEngine, theDocID)
00073 {
00074   MESSAGE("GEOMImpl_ILocalOperations::GEOMImpl_ILocalOperations");
00075 }
00076 
00077 //=============================================================================
00081 //=============================================================================
00082 GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations()
00083 {
00084   MESSAGE("GEOMImpl_ILocalOperations::~GEOMImpl_ILocalOperations");
00085 }
00086 
00087 
00088 //=============================================================================
00092 //=============================================================================
00093 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletAll
00094                                     (Handle(GEOM_Object) theShape, double theR)
00095 {
00096   SetErrorCode(KO);
00097 
00098   //Add a new Fillet object
00099   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
00100 
00101   //Add a new Fillet function
00102   Handle(GEOM_Function) aFunction =
00103     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_ALL);
00104   if (aFunction.IsNull()) return NULL;
00105 
00106   //Check if the function is set correctly
00107   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
00108 
00109   GEOMImpl_IFillet aCI (aFunction);
00110 
00111   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00112   if (aRefShape.IsNull()) return NULL;
00113 
00114   aCI.SetShape(aRefShape);
00115   aCI.SetR(theR);
00116 
00117   //Compute the Fillet value
00118   try {
00119 #if OCC_VERSION_LARGE > 0x06010000
00120     OCC_CATCH_SIGNALS;
00121 #endif
00122     if (!GetSolver()->ComputeFunction(aFunction)) {
00123       SetErrorCode("Fillet driver failed");
00124       return NULL;
00125     }
00126   }
00127   catch (Standard_Failure) {
00128     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00129     SetErrorCode(aFail->GetMessageString());
00130     return NULL;
00131   }
00132 
00133   //Make a Python command
00134   GEOM::TPythonDump(aFunction) << aFillet << " = geompy.MakeFilletAll("
00135                                << theShape << ", " << theR << ")";
00136 
00137   SetErrorCode(OK);
00138   return aFillet;
00139 }
00140 
00141 //=============================================================================
00145 //=============================================================================
00146 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdges
00147        (Handle(GEOM_Object) theShape, double theR, std::list<int> theEdges)
00148 {
00149   SetErrorCode(KO);
00150 
00151   //Add a new Fillet object
00152   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
00153 
00154   //Add a new Fillet function
00155   Handle(GEOM_Function) aFunction =
00156     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES);
00157   if (aFunction.IsNull()) return NULL;
00158 
00159   //Check if the function is set correctly
00160   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
00161 
00162   GEOMImpl_IFillet aCI (aFunction);
00163 
00164   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00165   if (aRefShape.IsNull()) return NULL;
00166 
00167   aCI.SetShape(aRefShape);
00168   aCI.SetR(theR);
00169   int aLen = theEdges.size();
00170   aCI.SetLength(aLen);
00171 
00172   int ind = 1;
00173   std::list<int>::iterator it = theEdges.begin();
00174   for (; it != theEdges.end(); it++, ind++) {
00175     aCI.SetEdge(ind, (*it));
00176   }
00177 
00178   //Compute the Fillet value
00179   try {
00180 #if OCC_VERSION_LARGE > 0x06010000
00181     OCC_CATCH_SIGNALS;
00182 #endif
00183     if (!GetSolver()->ComputeFunction(aFunction)) {
00184       SetErrorCode("Fillet driver failed");
00185       return NULL;
00186     }
00187   }
00188   catch (Standard_Failure) {
00189     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00190     SetErrorCode(aFail->GetMessageString());
00191     return NULL;
00192   }
00193 
00194   //Make a Python command
00195   GEOM::TPythonDump pd (aFunction);
00196   pd << aFillet << " = geompy.MakeFillet(" << theShape
00197     << ", " << theR << ", geompy.ShapeType[\"EDGE\"], [";
00198 
00199   it = theEdges.begin();
00200   pd << (*it++);
00201   while (it != theEdges.end()) {
00202     pd << ", " << (*it++);
00203   }
00204   pd << "])";
00205 
00206   SetErrorCode(OK);
00207   return aFillet;
00208 }
00209 
00210 //=============================================================================
00214 //=============================================================================
00215 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletEdgesR1R2
00216        (Handle(GEOM_Object) theShape, double theR1, double theR2, std::list<int> theEdges)
00217 {
00218   SetErrorCode(KO);
00219 
00220   //Add a new Fillet object
00221   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
00222 
00223   //Add a new Fillet function
00224   Handle(GEOM_Function) aFunction =
00225     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_EDGES_2R);
00226   if (aFunction.IsNull()) return NULL;
00227 
00228   //Check if the function is set correctly
00229   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
00230 
00231   GEOMImpl_IFillet aCI (aFunction);
00232 
00233   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00234   if (aRefShape.IsNull()) return NULL;
00235 
00236   aCI.SetShape(aRefShape);
00237   aCI.SetR1(theR1);
00238   aCI.SetR2(theR2);
00239   int aLen = theEdges.size();
00240   aCI.SetLength(aLen);
00241 
00242   int ind = 1;
00243   std::list<int>::iterator it = theEdges.begin();
00244   for (; it != theEdges.end(); it++, ind++) {
00245     aCI.SetEdge(ind, (*it));
00246   }
00247 
00248   //Compute the Fillet value
00249   try {
00250 #if OCC_VERSION_LARGE > 0x06010000
00251     OCC_CATCH_SIGNALS;
00252 #endif
00253     if (!GetSolver()->ComputeFunction(aFunction)) {
00254       SetErrorCode("Fillet driver failed");
00255       return NULL;
00256     }
00257   }
00258   catch (Standard_Failure) {
00259     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00260     SetErrorCode(aFail->GetMessageString());
00261     return NULL;
00262   }
00263 
00264   //Make a Python command
00265   GEOM::TPythonDump pd (aFunction);
00266   pd << aFillet << " = geompy.MakeFilletR1R2(" << theShape
00267     << ", " << theR1 << ", " <<theR2 << ", geompy.ShapeType[\"EDGE\"], [";
00268 
00269   it = theEdges.begin();
00270   pd << (*it++);
00271   while (it != theEdges.end()) {
00272     pd << ", " << (*it++);
00273   }
00274   pd << "])";
00275 
00276   SetErrorCode(OK);
00277   return aFillet;
00278 }
00279 
00280 
00281 //=============================================================================
00285 //=============================================================================
00286 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFaces
00287        (Handle(GEOM_Object) theShape, double theR, std::list<int> theFaces)
00288 {
00289   SetErrorCode(KO);
00290 
00291   //Add a new Fillet object
00292   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
00293 
00294   //Add a new Fillet function
00295   Handle(GEOM_Function) aFunction =
00296     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES);
00297   if (aFunction.IsNull()) return NULL;
00298 
00299   //Check if the function is set correctly
00300   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
00301 
00302   GEOMImpl_IFillet aCI (aFunction);
00303 
00304   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00305   if (aRefShape.IsNull()) return NULL;
00306 
00307   aCI.SetShape(aRefShape);
00308   aCI.SetR(theR);
00309   int aLen = theFaces.size();
00310   aCI.SetLength(aLen);
00311 
00312   int ind = 1;
00313   std::list<int>::iterator it = theFaces.begin();
00314   for (; it != theFaces.end(); it++, ind++) {
00315     aCI.SetFace(ind, (*it));
00316   }
00317 
00318   //Compute the Fillet value
00319   try {
00320 #if OCC_VERSION_LARGE > 0x06010000
00321     OCC_CATCH_SIGNALS;
00322 #endif
00323     if (!GetSolver()->ComputeFunction(aFunction)) {
00324       SetErrorCode("Fillet driver failed");
00325       return NULL;
00326     }
00327   }
00328   catch (Standard_Failure) {
00329     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00330     SetErrorCode(aFail->GetMessageString());
00331     return NULL;
00332   }
00333 
00334   //Make a Python command
00335   GEOM::TPythonDump pd (aFunction);
00336   pd << aFillet << " = geompy.MakeFillet(" << theShape
00337     << ", " << theR << ", geompy.ShapeType[\"FACE\"], [";
00338 
00339   it = theFaces.begin();
00340   pd << (*it++);
00341   while (it != theFaces.end()) {
00342     pd << ", " << (*it++);
00343   }
00344   pd << "])";
00345 
00346   SetErrorCode(OK);
00347   return aFillet;
00348 }
00349 
00350 //=============================================================================
00354 //=============================================================================
00355 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFilletFacesR1R2
00356        (Handle(GEOM_Object) theShape, double theR1, double theR2, std::list<int> theFaces)
00357 {
00358   SetErrorCode(KO);
00359 
00360   //Add a new Fillet object
00361   Handle(GEOM_Object) aFillet = GetEngine()->AddObject(GetDocID(), GEOM_FILLET);
00362 
00363   //Add a new Fillet function
00364   Handle(GEOM_Function) aFunction =
00365     aFillet->AddFunction(GEOMImpl_FilletDriver::GetID(), FILLET_SHAPE_FACES_2R);
00366   if (aFunction.IsNull()) return NULL;
00367 
00368   //Check if the function is set correctly
00369   if (aFunction->GetDriverGUID() != GEOMImpl_FilletDriver::GetID()) return NULL;
00370 
00371   GEOMImpl_IFillet aCI (aFunction);
00372 
00373   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00374   if (aRefShape.IsNull()) return NULL;
00375 
00376   aCI.SetShape(aRefShape);
00377   aCI.SetR1(theR1);
00378   aCI.SetR2(theR2);
00379   int aLen = theFaces.size();
00380   aCI.SetLength(aLen);
00381 
00382   int ind = 1;
00383   std::list<int>::iterator it = theFaces.begin();
00384   for (; it != theFaces.end(); it++, ind++) {
00385     aCI.SetFace(ind, (*it));
00386   }
00387 
00388   //Compute the Fillet value
00389   try {
00390 #if OCC_VERSION_LARGE > 0x06010000
00391     OCC_CATCH_SIGNALS;
00392 #endif
00393     if (!GetSolver()->ComputeFunction(aFunction)) {
00394       SetErrorCode("Fillet driver failed");
00395       return NULL;
00396     }
00397   }
00398   catch (Standard_Failure) {
00399     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00400     SetErrorCode(aFail->GetMessageString());
00401     return NULL;
00402   }
00403 
00404   //Make a Python command
00405   GEOM::TPythonDump pd (aFunction);
00406   pd << aFillet << " = geompy.MakeFilletR1R2(" << theShape
00407     << ", " << theR1 << ", " << theR2 << ", geompy.ShapeType[\"FACE\"], [";
00408 
00409   it = theFaces.begin();
00410   pd << (*it++);
00411   while (it != theFaces.end()) {
00412     pd << ", " << (*it++);
00413   }
00414   pd << "])";
00415 
00416   SetErrorCode(OK);
00417   return aFillet;
00418 }
00419 
00420 //=============================================================================
00424 //=============================================================================
00425 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFillet2D
00426        (Handle(GEOM_Object) theShape, double theR, std::list<int> theVertexes)
00427 {
00428   SetErrorCode(KO);
00429 
00430   //Add a new Fillet object
00431   Handle(GEOM_Object) aFillet2D = GetEngine()->AddObject(GetDocID(), GEOM_FILLET_2D);
00432 
00433   //Add a new Fillet function
00434   Handle(GEOM_Function) aFunction =
00435     aFillet2D->AddFunction(GEOMImpl_Fillet2dDriver::GetID(), FILLET_2D_SHAPE_VERTEXES);
00436   if (aFunction.IsNull()) return NULL;
00437 
00438   //Check if the function is set correctly
00439   if (aFunction->GetDriverGUID() != GEOMImpl_Fillet2dDriver::GetID()) return NULL;
00440 
00441   GEOMImpl_IFillet2d aCI (aFunction);
00442 
00443   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00444   if (aRefShape.IsNull()) return NULL;
00445 
00446   aCI.SetShape(aRefShape);
00447   aCI.SetR(theR);
00448   int aLen = theVertexes.size();
00449   aCI.SetLength(aLen);
00450 
00451   int ind = 1;
00452   std::list<int>::iterator it = theVertexes.begin();
00453   for (; it != theVertexes.end(); it++, ind++) {
00454     aCI.SetVertex(ind, (*it));
00455   }
00456 
00457   //Compute the Fillet value
00458   try {
00459 #if OCC_VERSION_LARGE > 0x06010000
00460     OCC_CATCH_SIGNALS;
00461 #endif
00462     if (!GetSolver()->ComputeFunction(aFunction)) {
00463       SetErrorCode("2D Fillet driver failed");
00464       return NULL;
00465     }
00466   }
00467   catch (Standard_Failure) {
00468     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00469     SetErrorCode(aFail->GetMessageString());
00470     return NULL;
00471   }
00472 
00473   //Make a Python command
00474   GEOM::TPythonDump pd (aFunction);
00475   pd << aFillet2D << " = geompy.MakeFillet2D(" << theShape
00476     << ", " << theR << ", [";
00477 
00478   it = theVertexes.begin();
00479   pd << (*it++);
00480   while (it != theVertexes.end()) {
00481     pd << ", " << (*it++);
00482   }
00483   pd << "])";
00484 
00485   SetErrorCode(OK);
00486   return aFillet2D;
00487 }
00488 
00489 //=============================================================================
00493 //=============================================================================
00494 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeFillet1D
00495        (Handle(GEOM_Object) theShape, double theR, std::list<int> theVertexes)
00496 {
00497   SetErrorCode(KO);
00498 
00499   //Add a new Fillet object
00500   Handle(GEOM_Object) aFillet1D = GetEngine()->AddObject(GetDocID(), GEOM_FILLET_1D);
00501 
00502   //Add a new Fillet function
00503   Handle(GEOM_Function) aFunction =
00504     aFillet1D->AddFunction(GEOMImpl_Fillet1dDriver::GetID(), FILLET_1D_SHAPE_VERTEXES);
00505   if (aFunction.IsNull()) return NULL;
00506 
00507   //Check if the function is set correctly
00508   if (aFunction->GetDriverGUID() != GEOMImpl_Fillet1dDriver::GetID()) return NULL;
00509 
00510   GEOMImpl_IFillet1d aCI (aFunction);
00511 
00512   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00513   if (aRefShape.IsNull()) return NULL;
00514 
00515   aCI.SetShape(aRefShape);
00516   aCI.SetR(theR);
00517   int aLen = theVertexes.size();
00518   aCI.SetLength(aLen);
00519 
00520   int ind = 1;
00521   std::list<int>::iterator it = theVertexes.begin();
00522   for (; it != theVertexes.end(); it++, ind++) {
00523     aCI.SetVertex(ind, (*it));
00524   }
00525 
00526   //Compute the Fillet value
00527   try {
00528 #if OCC_VERSION_LARGE > 0x06010000
00529     OCC_CATCH_SIGNALS;
00530 #endif
00531     if (!GetSolver()->ComputeFunction(aFunction)) {
00532       SetErrorCode("1D Fillet driver failed");
00533       return NULL;
00534     }
00535   }
00536   catch (Standard_Failure) {
00537     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00538     SetErrorCode(aFail->GetMessageString());
00539     return NULL;
00540   }
00541 
00542   //Make a Python command
00543   GEOM::TPythonDump pd (aFunction);
00544   pd << aFillet1D << " = geompy.MakeFillet1D(" << theShape
00545     << ", " << theR << ", [";
00546 
00547   it = theVertexes.begin();
00548   if (it != theVertexes.end()) {
00549     pd << (*it++);
00550     while (it != theVertexes.end())
00551       pd << ", " << (*it++);
00552   }
00553   pd << "])";
00554 
00555   SetErrorCode(OK);
00556   return aFillet1D;
00557 }
00558 
00559 //=============================================================================
00563 //=============================================================================
00564 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferAll (Handle(GEOM_Object) theShape, double theD)
00565 {
00566   SetErrorCode(KO);
00567 
00568   //Add a new Chamfer object
00569   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00570 
00571   //Add a new Chamfer function
00572   Handle(GEOM_Function) aFunction =
00573     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_ALL);
00574   if (aFunction.IsNull()) return NULL;
00575 
00576   //Check if the function is set correctly
00577   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
00578 
00579   GEOMImpl_IChamfer aCI (aFunction);
00580 
00581   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00582   if (aRefShape.IsNull()) return NULL;
00583 
00584   aCI.SetShape(aRefShape);
00585   aCI.SetD(theD);
00586 
00587   //Compute the Chamfer value
00588   try {
00589 #if OCC_VERSION_LARGE > 0x06010000
00590     OCC_CATCH_SIGNALS;
00591 #endif
00592     if (!GetSolver()->ComputeFunction(aFunction)) {
00593       SetErrorCode("Chamfer driver failed");
00594       return NULL;
00595     }
00596   }
00597   catch (Standard_Failure) {
00598     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00599     SetErrorCode(aFail->GetMessageString());
00600     return NULL;
00601   }
00602 
00603   //Make a Python command
00604   GEOM::TPythonDump(aFunction) << aChamfer << " = geompy.MakeChamferAll("
00605                                << theShape << ", " << theD << ")";
00606 
00607   SetErrorCode(OK);
00608   return aChamfer;
00609 }
00610 
00611 //=============================================================================
00615 //=============================================================================
00616 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdge
00617                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
00618                              int theFace1, int theFace2)
00619 {
00620   SetErrorCode(KO);
00621 
00622   //Add a new Chamfer object
00623   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00624 
00625   //Add a new Chamfer function
00626   Handle(GEOM_Function) aFunction =
00627     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE);
00628   if (aFunction.IsNull()) return NULL;
00629 
00630   //Check if the function is set correctly
00631   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
00632 
00633   GEOMImpl_IChamfer aCI (aFunction);
00634 
00635   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00636   if (aRefShape.IsNull()) return NULL;
00637 
00638   aCI.SetShape(aRefShape);
00639   aCI.SetD1(theD1);
00640   aCI.SetD2(theD2);
00641   aCI.SetFace1(theFace1);
00642   aCI.SetFace2(theFace2);
00643 
00644   //Compute the Chamfer value
00645   try {
00646 #if OCC_VERSION_LARGE > 0x06010000
00647     OCC_CATCH_SIGNALS;
00648 #endif
00649     if (!GetSolver()->ComputeFunction(aFunction)) {
00650       SetErrorCode("Chamfer driver failed");
00651       return NULL;
00652     }
00653   }
00654   catch (Standard_Failure) {
00655     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00656     SetErrorCode(aFail->GetMessageString());
00657     return NULL;
00658   }
00659 
00660   //Make a Python command
00661   GEOM::TPythonDump(aFunction) << aChamfer
00662     << " = geompy.MakeChamferEdge(" << theShape << ", " << theD1
00663       << ", " << theD2 << ", " << theFace1 << ", " << theFace2 << ")";
00664 
00665   SetErrorCode(OK);
00666   return aChamfer;
00667 }
00668 
00669 //=============================================================================
00673 //=============================================================================
00674 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgeAD
00675                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
00676                              int theFace1, int theFace2)
00677 {
00678   SetErrorCode(KO);
00679 
00680   //Add a new Chamfer object
00681   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00682 
00683   //Add a new Chamfer function
00684   Handle(GEOM_Function) aFunction =
00685     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGE_AD);
00686   if (aFunction.IsNull()) return NULL;
00687 
00688   //Check if the function is set correctly
00689   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
00690 
00691   GEOMImpl_IChamfer aCI (aFunction);
00692 
00693   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00694   if (aRefShape.IsNull()) return NULL;
00695 
00696   aCI.SetShape(aRefShape);
00697   aCI.SetD(theD);
00698   aCI.SetAngle(theAngle);
00699   aCI.SetFace1(theFace1);
00700   aCI.SetFace2(theFace2);
00701 
00702   //Compute the Chamfer value
00703   try {
00704 #if OCC_VERSION_LARGE > 0x06010000
00705     OCC_CATCH_SIGNALS;
00706 #endif
00707     if (!GetSolver()->ComputeFunction(aFunction)) {
00708       SetErrorCode("Chamfer driver failed");
00709       return NULL;
00710     }
00711   }
00712   catch (Standard_Failure) {
00713     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00714     SetErrorCode(aFail->GetMessageString());
00715     return NULL;
00716   }
00717 
00718   //Make a Python command
00719   GEOM::TPythonDump(aFunction) << aChamfer
00720     << " = geompy.MakeChamferEdgeAD(" << theShape << ", " << theD
00721       << ", " << theAngle << ", " << theFace1 << ", " << theFace2 << ")";
00722   SetErrorCode(OK);
00723   return aChamfer;
00724 }
00725 
00726 //=============================================================================
00730 //=============================================================================
00731 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFaces
00732                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
00733                              std::list<int> theFaces)
00734 {
00735   SetErrorCode(KO);
00736 
00737   //Add a new Chamfer object
00738   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00739 
00740   //Add a new Chamfer function
00741   Handle(GEOM_Function) aFunction =
00742     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES);
00743   if (aFunction.IsNull()) return NULL;
00744 
00745   //Check if the function is set correctly
00746   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
00747 
00748   GEOMImpl_IChamfer aCI (aFunction);
00749 
00750   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00751   if (aRefShape.IsNull()) return NULL;
00752 
00753   aCI.SetShape(aRefShape);
00754   aCI.SetD1(theD1);
00755   aCI.SetD2(theD2);
00756   int aLen = theFaces.size();
00757   aCI.SetLength(aLen);
00758 
00759   int ind = 1;
00760   std::list<int>::iterator it = theFaces.begin();
00761   for (; it != theFaces.end(); it++, ind++) {
00762     aCI.SetFace(ind, (*it));
00763   }
00764 
00765   //Compute the Chamfer value
00766   try {
00767 #if OCC_VERSION_LARGE > 0x06010000
00768     OCC_CATCH_SIGNALS;
00769 #endif
00770     if (!GetSolver()->ComputeFunction(aFunction)) {
00771       SetErrorCode("Chamfer driver failed");
00772       return NULL;
00773     }
00774   }
00775   catch (Standard_Failure) {
00776     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00777     SetErrorCode(aFail->GetMessageString());
00778     return NULL;
00779   }
00780 
00781   //Make a Python command
00782   GEOM::TPythonDump pd (aFunction);
00783   pd << aChamfer << " = geompy.MakeChamferFaces(" << theShape
00784     << ", " << theD1 << ", " << theD2 << ", [";
00785 
00786   it = theFaces.begin();
00787   pd << (*it++);
00788   while (it != theFaces.end()) {
00789     pd << ", " << (*it++);
00790   }
00791   pd << "])";
00792 
00793   SetErrorCode(OK);
00794   return aChamfer;
00795 }
00796 
00797 //=============================================================================
00801 //=============================================================================
00802 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferFacesAD
00803                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
00804                              std::list<int> theFaces)
00805 {
00806   SetErrorCode(KO);
00807 
00808   //Add a new Chamfer object
00809   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00810 
00811   //Add a new Chamfer function
00812   Handle(GEOM_Function) aFunction =
00813     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_FACES_AD);
00814   if (aFunction.IsNull()) return NULL;
00815 
00816   //Check if the function is set correctly
00817   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID()) return NULL;
00818 
00819   GEOMImpl_IChamfer aCI (aFunction);
00820 
00821   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00822   if (aRefShape.IsNull()) return NULL;
00823 
00824   aCI.SetShape(aRefShape);
00825   aCI.SetD(theD);
00826   aCI.SetAngle(theAngle);
00827   int aLen = theFaces.size();
00828   aCI.SetLength(aLen);
00829 
00830   int ind = 1;
00831   std::list<int>::iterator it = theFaces.begin();
00832   for (; it != theFaces.end(); it++, ind++) {
00833     aCI.SetFace(ind, (*it));
00834   }
00835 
00836   //Compute the Chamfer value
00837   try {
00838 #if OCC_VERSION_LARGE > 0x06010000
00839     OCC_CATCH_SIGNALS;
00840 #endif
00841     if (!GetSolver()->ComputeFunction(aFunction)) {
00842       SetErrorCode("Chamfer driver failed");
00843       return NULL;
00844     }
00845   }
00846   catch (Standard_Failure) {
00847     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00848     SetErrorCode(aFail->GetMessageString());
00849     return NULL;
00850   }
00851 
00852   //Make a Python command
00853   GEOM::TPythonDump pd (aFunction);
00854   pd << aChamfer << " = geompy.MakeChamferFacesAD(" << theShape
00855     << ", " << theD << ", " << theAngle << ", [";
00856 
00857   it = theFaces.begin();
00858   pd << (*it++);
00859   while (it != theFaces.end()) {
00860     pd << ", " << (*it++);
00861   }
00862   pd << "])";
00863 
00864   SetErrorCode(OK);
00865   return aChamfer;
00866 }
00867 
00868 //=============================================================================
00872 //=============================================================================
00873 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdges
00874                             (Handle(GEOM_Object) theShape, double theD1, double theD2,
00875                              std::list<int> theEdges)
00876 {
00877   SetErrorCode(KO);
00878 
00879   //Add a new Chamfer object
00880   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00881 
00882   //Add a new Chamfer function
00883   Handle(GEOM_Function) aFunction =
00884     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES);
00885   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL;}
00886 
00887   //Check if the function is set correctly
00888   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
00889         { MESSAGE ( "Chamfer Driver is NULL!!!" ); return NULL; }
00890 
00891   GEOMImpl_IChamfer aCI (aFunction);
00892 
00893   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00894   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
00895 
00896   aCI.SetShape(aRefShape);
00897   aCI.SetD1(theD1);
00898   aCI.SetD2(theD2);
00899   int aLen = theEdges.size();
00900   aCI.SetLength(aLen);
00901 
00902   int ind = 1;
00903   std::list<int>::iterator it = theEdges.begin();
00904   for (; it != theEdges.end(); it++, ind++) {
00905     aCI.SetEdge(ind, (*it));
00906   }
00907 
00908   //Compute the Chamfer value
00909   try {
00910 #if OCC_VERSION_LARGE > 0x06010000
00911     OCC_CATCH_SIGNALS;
00912 #endif
00913     if (!GetSolver()->ComputeFunction(aFunction)) {
00914       SetErrorCode("Chamfer driver failed");
00915       return NULL;
00916     }
00917   }
00918   catch (Standard_Failure) {
00919     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00920     SetErrorCode(aFail->GetMessageString());
00921     return NULL;
00922   }
00923 
00924   //Make a Python command
00925   GEOM::TPythonDump pd (aFunction);
00926   pd << aChamfer << " = geompy.MakeChamferEdges(" << theShape
00927     << ", " << theD1 << ", " << theD2 << ", [";
00928 
00929   it = theEdges.begin();
00930   pd << (*it++);
00931   while (it != theEdges.end()) {
00932     pd << ", " << (*it++);
00933   }
00934   pd << "])";
00935 
00936   SetErrorCode(OK);
00937   return aChamfer;
00938 }
00939 
00940 //=============================================================================
00944 //=============================================================================
00945 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeChamferEdgesAD
00946                             (Handle(GEOM_Object) theShape, double theD, double theAngle,
00947                              std::list<int> theEdges)
00948 {
00949   SetErrorCode(KO);
00950 
00951   //Add a new Chamfer object
00952   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_CHAMFER);
00953 
00954   //Add a new Chamfer function
00955   Handle(GEOM_Function) aFunction =
00956     aChamfer->AddFunction(GEOMImpl_ChamferDriver::GetID(), CHAMFER_SHAPE_EDGES_AD);
00957   if (aFunction.IsNull()) { MESSAGE ( "Edges Function is NULL!!!" ); return NULL; }
00958 
00959   //Check if the function is set correctly
00960   if (aFunction->GetDriverGUID() != GEOMImpl_ChamferDriver::GetID())
00961         { MESSAGE("Chamfer Driver is NULL!!!"); return NULL;}
00962 
00963   GEOMImpl_IChamfer aCI (aFunction);
00964 
00965   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
00966   if (aRefShape.IsNull()) { MESSAGE ("Shape is NULL!!!"); return NULL;}
00967 
00968   aCI.SetShape(aRefShape);
00969   aCI.SetD(theD);
00970   aCI.SetAngle(theAngle);
00971   int aLen = theEdges.size();
00972   aCI.SetLength(aLen);
00973 
00974   int ind = 1;
00975   std::list<int>::iterator it = theEdges.begin();
00976   for (; it != theEdges.end(); it++, ind++) {
00977     aCI.SetEdge(ind, (*it));
00978   }
00979 
00980   //Compute the Chamfer value
00981   try {
00982 #if OCC_VERSION_LARGE > 0x06010000
00983     OCC_CATCH_SIGNALS;
00984 #endif
00985     if (!GetSolver()->ComputeFunction(aFunction)) {
00986       SetErrorCode("Chamfer driver failed");
00987       return NULL;
00988     }
00989   }
00990   catch (Standard_Failure) {
00991     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00992     SetErrorCode(aFail->GetMessageString());
00993     return NULL;
00994   }
00995 
00996   //Make a Python command
00997   GEOM::TPythonDump pd (aFunction);
00998   pd << aChamfer << " = geompy.MakeChamferEdgesAD(" << theShape
00999     << ", " << theD << ", " << theAngle << ", [";
01000 
01001   it = theEdges.begin();
01002   pd << (*it++);
01003   while (it != theEdges.end()) {
01004     pd << ", " << (*it++);
01005   }
01006   pd << "])";
01007 
01008   SetErrorCode(OK);
01009   return aChamfer;
01010 }
01011 
01012 //=============================================================================
01016 //=============================================================================
01017 Handle(GEOM_Object) GEOMImpl_ILocalOperations::MakeArchimede (Handle(GEOM_Object) theShape,
01018                                                               double theWeight,
01019                                                               double theWaterDensity,
01020                                                               double theMeshingDeflection)
01021 {
01022   SetErrorCode(KO);
01023 
01024   //Add a new Archimede object
01025   Handle(GEOM_Object) aChamfer = GetEngine()->AddObject(GetDocID(), GEOM_ARCHIMEDE);
01026 
01027   //Add a new Archimede function
01028   Handle(GEOM_Function) aFunction = aChamfer->AddFunction(GEOMImpl_ArchimedeDriver::GetID(), ARCHIMEDE_TYPE);
01029   if (aFunction.IsNull()) return NULL;
01030 
01031   //Check if the function is set correctly
01032   if (aFunction->GetDriverGUID() != GEOMImpl_ArchimedeDriver::GetID()) return NULL;
01033 
01034   GEOMImpl_IArchimede aAI (aFunction);
01035 
01036   Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
01037   if (aRefShape.IsNull()) return NULL;
01038 
01039   aAI.SetBasicShape(aRefShape);
01040   aAI.SetWeight(theWeight);
01041   aAI.SetDensity(theWaterDensity);
01042   aAI.SetDeflection(theMeshingDeflection);
01043 
01044   //Compute the Archimede value
01045   try {
01046 #if OCC_VERSION_LARGE > 0x06010000
01047     OCC_CATCH_SIGNALS;
01048 #endif
01049     if (!GetSolver()->ComputeFunction(aFunction)) {
01050       SetErrorCode("Archimede driver failed");
01051       return NULL;
01052     }
01053   }
01054   catch (Standard_Failure) {
01055     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
01056     SetErrorCode(aFail->GetMessageString());
01057     return NULL;
01058   }
01059 
01060   //Make a Python command
01061   GEOM::TPythonDump(aFunction) << aChamfer
01062     << " = geompy.Archimede(" << theShape << ", " << theWeight << ", "
01063       << theWaterDensity << ", " << theMeshingDeflection << ")";
01064 
01065   SetErrorCode(OK);
01066   return aChamfer;
01067 }
01068 
01069 //=============================================================================
01073 //=============================================================================
01074 bool GEOMImpl_ILocalOperations::GetSubShape (const TopoDS_Shape& theShape, const int theIndex,
01075                                              TopoDS_Shape& theSubShape)
01076 {
01077   if (theShape.IsNull() || theIndex < 1)
01078     return false;
01079 
01080   TopTools_IndexedMapOfShape anIndices;
01081   TopExp::MapShapes(theShape, anIndices);
01082   if (theIndex > anIndices.Extent()) return false;
01083   theSubShape = anIndices.FindKey(theIndex);
01084 
01085   return true;
01086 }
01087 
01088 //=============================================================================
01092 //=============================================================================
01093 Standard_Integer GEOMImpl_ILocalOperations::GetSubShapeIndex (Handle(GEOM_Object) theShape,
01094                                                               Handle(GEOM_Object) theSubShape)
01095 {
01096   SetErrorCode(KO);
01097 
01098   Standard_Integer anInd = -1;
01099   GEOM_Engine* anEngine = GetEngine();
01100   //GEOMImpl_Gen* aGen = dynamic_cast<GEOMImpl_Gen*>(anEngine);
01101   GEOMImpl_Gen* aGen = (GEOMImpl_Gen*)anEngine;
01102 
01103   if (aGen) {
01104     GEOMImpl_IShapesOperations* anIShapesOperations =
01105       aGen->GetIShapesOperations(GetDocID());
01106     anInd = anIShapesOperations->GetSubShapeIndex(theShape, theSubShape);
01107     SetErrorCode(anIShapesOperations->GetErrorCode());
01108   }
01109 
01110   return anInd;
01111 }