Back to index

salome-geom  6.5.0
GEOMImpl_IHealingOperations.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 #ifdef WNT
00024 #pragma warning( disable:4786 )
00025 #endif
00026 
00027 #include <Standard_Version.hxx>
00028 #include <Standard_Stream.hxx>
00029 
00030 #include <GEOMImpl_IHealingOperations.hxx>
00031 
00032 #include <GEOM_PythonDump.hxx>
00033 
00034 #include <GEOMImpl_HealingDriver.hxx>
00035 #include <GEOMImpl_Types.hxx>
00036 #include <GEOMImpl_IHealing.hxx>
00037 #include <GEOMImpl_IVector.hxx>
00038 #include <GEOMImpl_VectorDriver.hxx>
00039 #include <GEOMImpl_CopyDriver.hxx>
00040 
00041 #include <Basics_OCCTVersion.hxx>
00042 
00043 #include "utilities.h"
00044 #include <OpUtil.hxx>
00045 #include <Utils_ExceptHandlers.hxx>
00046 
00047 #include <ShHealOper_ShapeProcess.hxx>
00048 
00049 #include <ShapeAnalysis_FreeBounds.hxx>
00050 
00051 #include <TopoDS_Compound.hxx>
00052 #include <TopExp_Explorer.hxx>
00053 
00054 #include <TColStd_HArray1OfExtendedString.hxx>
00055 #include <TColStd_HSequenceOfTransient.hxx>
00056 #include <TCollection_AsciiString.hxx>
00057 
00058 #include <TDF_Tool.hxx>
00059 
00060 #include <Standard_Failure.hxx>
00061 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
00062 
00063 //=============================================================================
00067 //=============================================================================
00068 GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine, int theDocID)
00069 : GEOM_IOperations(theEngine, theDocID)
00070 {
00071   MESSAGE("GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations");
00072 }
00073 
00074 //=============================================================================
00078 //=============================================================================
00079 GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations()
00080 {
00081   MESSAGE("GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations");
00082 }
00083 
00084 
00085 //=============================================================================
00089 //=============================================================================
00090 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Object) theObject,
00091                                   const Handle(TColStd_HArray1OfExtendedString)& theOperators,
00092                                   const Handle(TColStd_HArray1OfExtendedString)& theParams,
00093                                   const Handle(TColStd_HArray1OfExtendedString)& theValues)
00094 {
00095   // set error code, check parameters
00096   SetErrorCode(KO);
00097 
00098   if (theObject.IsNull())
00099     return NULL;
00100 
00101   if (theOperators.IsNull() || theOperators->Length() <= 0) {
00102     SetErrorCode("No operators requested");
00103     return NULL;
00104   }
00105 
00106   Standard_Integer nbParams = 0, nbValues = 0;
00107   if (!theParams.IsNull()) {
00108     nbParams = theParams->Length();
00109   }
00110   if (!theValues.IsNull()) {
00111     nbValues = theValues->Length();
00112   }
00113 
00114   if (nbParams != nbValues) {
00115     SetErrorCode("Number of parameter values must be equal to the number of parameters");
00116     return NULL;
00117   }
00118 
00119   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00120   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00121 
00122   // Add a new object
00123   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00124 
00125   //Add the function
00126   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SHAPE_PROCESS);
00127 
00128   if (aFunction.IsNull()) return NULL;
00129 
00130   //Check if the function is set correctly
00131   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00132 
00133   // prepare "data container" class IHealing
00134   GEOMImpl_IHealing HI(aFunction);
00135   HI.SetOriginal(aLastFunction);
00136   HI.SetOperators( theOperators );
00137   if (nbParams > 0) {
00138     HI.SetParameters( theParams );
00139     HI.SetValues( theValues );
00140   }
00141 
00142   //Compute the translation
00143   try {
00144 #if OCC_VERSION_LARGE > 0x06010000
00145     OCC_CATCH_SIGNALS;
00146 #endif
00147     if (!GetSolver()->ComputeFunction(aFunction))
00148     {
00149       SetErrorCode("Shape Healing algorithm failed");
00150       return NULL;
00151     }
00152   }
00153   catch (Standard_Failure)
00154   {
00155     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00156     SetErrorCode(aFail->GetMessageString());
00157     return NULL;
00158   }
00159 
00160   //Make a Python command
00161   GEOM::TPythonDump pd (aFunction);
00162   pd << aNewObject << " = geompy.ProcessShape(" << theObject << ", [";
00163 
00164   // list of operators
00165   int i = theOperators->Lower(), nb = theOperators->Upper();
00166   for ( ; i <= nb; i++) {
00167     pd << "\"" << TCollection_AsciiString(theOperators->Value( i )).ToCString()
00168       << (( i < nb ) ? "\", " : "\"");
00169   }
00170   pd << "], [";
00171   // list of parameters
00172   i = theParams->Lower(); nb = theParams->Upper();
00173   for ( ; i <= nb; i++) {
00174     pd << "\"" << TCollection_AsciiString(theParams->Value( i )).ToCString()
00175       << (( i < nb ) ? "\", " : "\"");
00176   }
00177   pd << "], [";
00178   // list of values
00179   i = theValues->Lower(); nb = theValues->Upper();
00180   for ( ; i <= nb; i++) {
00181     pd << "\"" << TCollection_AsciiString(theValues->Value( i )).ToCString()
00182       << (( i < nb ) ? "\", " : "\"");
00183   }
00184   pd << "])";
00185 
00186   SetErrorCode(OK);
00187   return aNewObject;
00188 }
00189 
00190 //=============================================================================
00194 //=============================================================================
00195 void GEOMImpl_IHealingOperations::GetShapeProcessParameters (std::list<std::string>& theOperations,
00196                                                              std::list<std::string>& theParams,
00197                                                              std::list<std::string>& theValues)
00198 {
00199   ShHealOper_ShapeProcess aHealer;
00200   TColStd_SequenceOfAsciiString anOperators;
00201   int nbOperatorErrors( 0 );
00202   if ( aHealer.GetOperators( anOperators ) )
00203   {
00204     for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
00205     {
00206       std::string anOperation = anOperators.Value( i ).ToCString();
00207       if ( GetOperatorParameters( anOperation, theParams, theValues ) )
00208         theOperations.push_back( anOperation );
00209       else
00210         nbOperatorErrors++;
00211     }
00212   }
00213   else
00214   {
00215     SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
00216   }
00217 
00218   if ( nbOperatorErrors ) {
00219     TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
00220     aMsg += TCollection_AsciiString( nbOperatorErrors );
00221     MESSAGE(aMsg.ToCString());
00222   }
00223 }
00224 
00225 //=============================================================================
00229 //=============================================================================
00230 bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string theOperation,
00231                                                          std::list<std::string>& theParams,
00232                                                          std::list<std::string>& theValues )
00233 {
00234   ShHealOper_ShapeProcess aHealer;
00235   int nbParamValueErrors( 0 );
00236   std::list<std::string> aParams;
00237   if ( GetParameters( theOperation, aParams ) ) {
00238     for ( std::list<std::string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
00239       TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
00240       TCollection_AsciiString aValue;
00241       if ( aHealer.GetParameter( aParam, aValue ) ) {
00242         theParams.push_back( aParam.ToCString() );
00243         theValues.push_back( aValue.ToCString() );
00244       }
00245       else
00246         nbParamValueErrors++;
00247     }
00248   }
00249   else
00250     return false;
00251 
00252   if ( nbParamValueErrors ) {
00253     TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameter values (GEOMImpl_IHealingOperations): nbParamValueErrors = ");
00254     aMsg += TCollection_AsciiString( nbParamValueErrors );
00255     MESSAGE(aMsg.ToCString());
00256   }
00257 
00258   return true;
00259 }
00260 
00261 //=============================================================================
00265 //=============================================================================
00266 bool GEOMImpl_IHealingOperations::GetParameters (const std::string theOperation,
00267                                                  std::list<std::string>& theParams)
00268 {
00269   if ( theOperation == "SplitAngle" ) {
00270     theParams.push_back( "SplitAngle.Angle" );
00271     theParams.push_back( "SplitAngle.MaxTolerance" );
00272 
00273   } else if ( theOperation == "SplitClosedFaces" ) {
00274     theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
00275 
00276   } else if ( theOperation == "FixFaceSize" ) {
00277     theParams.push_back( "FixFaceSize.Tolerance" );
00278 
00279   } else if( theOperation == "DropSmallEdges" ) {
00280     theParams.push_back( "DropSmallEdges.Tolerance3d" );
00281 
00282   } else if( theOperation == "BSplineRestriction" ) {
00283     theParams.push_back( "BSplineRestriction.SurfaceMode" );
00284     theParams.push_back( "BSplineRestriction.Curve3dMode" );
00285     theParams.push_back( "BSplineRestriction.Curve2dMode" );
00286     theParams.push_back( "BSplineRestriction.Tolerance3d" );
00287     theParams.push_back( "BSplineRestriction.Tolerance2d" );
00288     theParams.push_back( "BSplineRestriction.RequiredDegree" );
00289     theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
00290     theParams.push_back( "BSplineRestriction.Continuity3d" );
00291     theParams.push_back( "BSplineRestriction.Continuity2d" );
00292 
00293   } else if( theOperation == "SplitContinuity" ) {
00294     theParams.push_back( "SplitContinuity.Tolerance3d" );
00295     theParams.push_back( "SplitContinuity.SurfaceContinuity" );
00296     theParams.push_back( "SplitContinuity.CurveContinuity" );
00297 
00298   } else if( theOperation == "ToBezier" ) {
00299     theParams.push_back( "ToBezier.SurfaceMode" );
00300     theParams.push_back( "ToBezier.Curve3dMode" );
00301     theParams.push_back( "ToBezier.Curve2dMode" );
00302     theParams.push_back( "ToBezier.MaxTolerance" );
00303 
00304   } else if( theOperation == "SameParameter" ) {
00305     theParams.push_back( "SameParameter.Tolerance3d" );
00306 
00307   } else if( theOperation == "FixShape" ) {
00308     theParams.push_back( "FixShape.Tolerance3d" );
00309     theParams.push_back( "FixShape.MaxTolerance3d" );
00310 
00311   } else {
00312     return false;
00313   }
00314 
00315   return true;
00316 }
00317 
00318 //=============================================================================
00322 //=============================================================================
00323 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
00324        (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theFaces)
00325 {
00326   // set error code, check parameters
00327   SetErrorCode(KO);
00328 
00329   if (theObject.IsNull()) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
00330     return NULL;
00331 
00332   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00333   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00334 
00335   // Add a new object
00336   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
00337 
00338   //Add the function
00339   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
00340 
00341   if (aFunction.IsNull()) return NULL;
00342 
00343   //Check if the function is set correctly
00344   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00345 
00346   // prepare "data container" class IHealing
00347   GEOMImpl_IHealing HI (aFunction);
00348   HI.SetFaces(theFaces);
00349   HI.SetOriginal(aLastFunction);
00350 
00351   //Compute the translation
00352   try {
00353 #if OCC_VERSION_LARGE > 0x06010000
00354     OCC_CATCH_SIGNALS;
00355 #endif
00356     if (!GetSolver()->ComputeFunction(aFunction))
00357     {
00358       SetErrorCode("Healing driver failed");
00359       return NULL;
00360     }
00361   }
00362   catch (Standard_Failure)
00363   {
00364     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00365     SetErrorCode(aFail->GetMessageString());
00366     return NULL;
00367   }
00368 
00369   //Make a Python command
00370   GEOM::TPythonDump pd (aFunction);
00371   pd << aNewObject << " = geompy.SuppressFaces(" << theObject << ", [";
00372 
00373   // list of face ids
00374   int i = theFaces->Lower(), nb = theFaces->Upper();
00375   for ( ; i <= nb; i++)
00376     pd << theFaces->Value( i ) << (( i < nb ) ? ", " : "])");
00377 
00378   SetErrorCode(OK);
00379   return aNewObject;
00380 }
00381 
00382 //=============================================================================
00386 //=============================================================================
00387 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
00388                     (Handle(GEOM_Object) theObject,
00389                      const Handle(TColStd_HArray1OfInteger)& theWires,
00390                      bool isCommonVertex)
00391 {
00392   // set error code, check parameters
00393   SetErrorCode(KO);
00394 
00395   if (theObject.IsNull())
00396   {
00397     SetErrorCode("NULL object given");
00398     return NULL;
00399   }
00400 
00401   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00402   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00403 
00404   // Add a new object
00405   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00406 
00407   //Add the function
00408   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CLOSE_CONTOUR);
00409 
00410   if (aFunction.IsNull()) return NULL;
00411 
00412   //Check if the function is set correctly
00413   if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00414 
00415   // prepare "data container" class IHealing
00416   GEOMImpl_IHealing HI(aFunction);
00417   HI.SetWires( theWires );
00418   HI.SetIsCommonVertex( isCommonVertex );
00419   HI.SetOriginal( aLastFunction );
00420 
00421   //Compute the translation
00422   try {
00423 #if OCC_VERSION_LARGE > 0x06010000
00424     OCC_CATCH_SIGNALS;
00425 #endif
00426     if (!GetSolver()->ComputeFunction(aFunction))
00427     {
00428       SetErrorCode("Healing driver failed");
00429       return NULL;
00430     }
00431   }
00432   catch (Standard_Failure)
00433   {
00434         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00435     SetErrorCode(aFail->GetMessageString());
00436     return NULL;
00437   }
00438 
00439   //Make a Python command
00440   GEOM::TPythonDump pd (aFunction);
00441   pd << aNewObject << " = geompy.CloseContour(" << theObject << ", [";
00442 
00443   // list of wire ids
00444   if (!theWires.IsNull())
00445   {
00446     int i = theWires->Lower(), nb = theWires->Upper();
00447     pd << theWires->Value(i++);
00448     while (i <= nb)
00449       pd << ", " << theWires->Value(i++);
00450   }
00451   pd << "], " << (int)isCommonVertex << ")";
00452 
00453   SetErrorCode(OK);
00454   return aNewObject;
00455 }
00456 
00457 //=============================================================================
00461 //=============================================================================
00462 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires
00463        (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theWires)
00464 {
00465   // set error code, check parameters
00466   SetErrorCode(KO);
00467 
00468   if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
00469     return NULL;
00470 
00471   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00472   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00473 
00474   // Add a new object
00475   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00476 
00477   //Add the function
00478   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
00479 
00480   if (aFunction.IsNull()) return NULL;
00481 
00482   //Check if the function is set correctly
00483   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00484 
00485   // prepare "data container" class IHealing
00486   GEOMImpl_IHealing HI(aFunction);
00487   HI.SetWires( theWires );
00488   HI.SetOriginal( aLastFunction );
00489 
00490   //Compute the translation
00491   try {
00492 #if OCC_VERSION_LARGE > 0x06010000
00493     OCC_CATCH_SIGNALS;
00494 #endif
00495     if (!GetSolver()->ComputeFunction(aFunction))
00496     {
00497       SetErrorCode("Healing driver failed");
00498       return NULL;
00499     }
00500   }
00501   catch (Standard_Failure)
00502   {
00503     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00504     SetErrorCode(aFail->GetMessageString());
00505     return NULL;
00506   }
00507 
00508   //Make a Python command
00509   GEOM::TPythonDump pd (aFunction);
00510   pd << aNewObject << " = geompy.SuppressInternalWires(" << theObject << ", [";
00511 
00512   // list of wire ids
00513   if (!theWires.IsNull()) {
00514     int i = theWires->Lower(), nb = theWires->Upper();
00515     for ( ; i <= nb; i++)
00516       pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
00517   } else {
00518     pd << "])";
00519   }
00520 
00521   SetErrorCode(OK);
00522   return aNewObject;
00523 }
00524 
00525 //=============================================================================
00529 //=============================================================================
00530 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
00531                                                             const Handle(TColStd_HArray1OfInteger)& theWires)
00532 {
00533   // set error code, check parameters
00534   SetErrorCode(KO);
00535 
00536   if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
00537     return NULL;
00538 
00539   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00540   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00541 
00542   // Add a new object
00543   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00544 
00545   //Add the function
00546   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
00547 
00548   if (aFunction.IsNull()) return NULL;
00549 
00550   //Check if the function is set correctly
00551   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00552 
00553   // prepare "data container" class IHealing
00554   GEOMImpl_IHealing HI(aFunction);
00555   HI.SetWires( theWires );
00556   HI.SetOriginal( aLastFunction );
00557 
00558   //Compute the translation
00559   try {
00560 #if OCC_VERSION_LARGE > 0x06010000
00561     OCC_CATCH_SIGNALS;
00562 #endif
00563     if (!GetSolver()->ComputeFunction(aFunction))
00564     {
00565       SetErrorCode("Healing driver failed");
00566       return NULL;
00567     }
00568   }
00569   catch (Standard_Failure)
00570   {
00571         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00572     SetErrorCode(aFail->GetMessageString());
00573     return NULL;
00574   }
00575 
00576   //Make a Python command
00577   GEOM::TPythonDump pd (aFunction);
00578   pd << aNewObject << " = geompy.SuppressHoles(" << theObject << ", [";
00579 
00580   // list of wire ids
00581   if ( theWires.IsNull() )
00582     pd << "])";
00583   else {
00584     int i = theWires->Lower(), nb = theWires->Upper();
00585     for ( ; i <= nb; i++)
00586       pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
00587   }
00588 
00589   SetErrorCode(OK);
00590   return aNewObject;
00591 }
00592 
00593 //=============================================================================
00597 //=============================================================================
00598 Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObject,
00599                                                       double theTolerance)
00600 {
00601   // set error code, check parameters
00602   SetErrorCode(KO);
00603 
00604   if (theObject.IsNull())
00605     return NULL;
00606 
00607   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00608   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00609 
00610   // Add a new object
00611   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00612 
00613   //Add the function
00614   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SEWING);
00615 
00616   if (aFunction.IsNull()) return NULL;
00617 
00618   //Check if the function is set correctly
00619   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00620 
00621   // prepare "data container" class IHealing
00622   GEOMImpl_IHealing HI(aFunction);
00623   HI.SetTolerance( theTolerance );
00624   HI.SetOriginal( aLastFunction );
00625 
00626   //Compute the translation
00627   try {
00628 #if OCC_VERSION_LARGE > 0x06010000
00629     OCC_CATCH_SIGNALS;
00630 #endif
00631     if (!GetSolver()->ComputeFunction(aFunction))
00632     {
00633       SetErrorCode("Healing driver failed");
00634       return NULL;
00635     }
00636   }
00637   catch (Standard_Failure)
00638   {
00639         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00640     SetErrorCode(aFail->GetMessageString());
00641     return NULL;
00642   }
00643 
00644   //Make a Python command
00645   GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.Sew("
00646                                << theObject << ", " << theTolerance << ")";
00647 
00648   SetErrorCode(OK);
00649   return aNewObject;
00650 }
00651 
00652 //=============================================================================
00656 //=============================================================================
00657 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
00658                                                              int theIndex,
00659                                                              double theValue,
00660                                                              bool isByParameter)
00661 {
00662   // set error code, check parameters
00663   SetErrorCode(KO);
00664 
00665   if (theObject.IsNull())
00666     return NULL;
00667 
00668   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00669   if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
00670 
00671   // Add a new object
00672   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
00673 
00674   //Add the function
00675   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
00676 
00677   if (aFunction.IsNull()) return NULL;
00678 
00679   //Check if the function is set correctly
00680   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00681 
00682   // prepare "data container" class IHealing
00683   GEOMImpl_IHealing HI(aFunction);
00684   HI.SetIndex( theIndex );
00685   HI.SetDevideEdgeValue( theValue );
00686   HI.SetIsByParameter( isByParameter );
00687   HI.SetOriginal( aLastFunction );
00688 
00689   //Compute the translation
00690   try {
00691 #if OCC_VERSION_LARGE > 0x06010000
00692     OCC_CATCH_SIGNALS;
00693 #endif
00694     if (!GetSolver()->ComputeFunction(aFunction))
00695     {
00696       SetErrorCode("Healing driver failed");
00697       return NULL;
00698     }
00699   }
00700   catch (Standard_Failure)
00701   {
00702         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00703     SetErrorCode(aFail->GetMessageString());
00704     return NULL;
00705   }
00706 
00707   //Make a Python command
00708   GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.DivideEdge(" << theObject
00709     << ", " << theIndex << ", " << theValue << ", " << (int)isByParameter << ")";
00710 
00711   SetErrorCode(OK);
00712   return aNewObject;
00713 }
00714 
00715 //=============================================================================
00719 //=============================================================================
00720 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
00721                                                    Handle(TColStd_HSequenceOfTransient)& theClosed,
00722                                                    Handle(TColStd_HSequenceOfTransient)& theOpen )
00723 {
00724   // set error code, check parameters
00725   SetErrorCode(KO);
00726 
00727   if ( theObject.IsNull() || theClosed.IsNull() || theOpen.IsNull() )
00728     return false;
00729 
00730   TopoDS_Shape aShape = theObject->GetValue();
00731   if ( aShape.IsNull() )
00732     return false;
00733 
00734   // get free boundary shapes
00735 
00736 #if OCC_VERSION_LARGE > 0x06030008
00737   ShapeAnalysis_FreeBounds anAnalizer(aShape, Standard_False,
00738                                       Standard_True, Standard_True);
00739 #else
00740   ShapeAnalysis_FreeBounds anAnalizer(aShape);
00741 #endif
00742   TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
00743   TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
00744 
00745   // iterate through shapes and append them to the return sequence
00746   Handle(GEOM_Object) anObj;
00747   Handle(GEOM_Function) aFunction;
00748   TopExp_Explorer anExp;
00749   for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
00750   {
00751     anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
00752     aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
00753     TopoDS_Shape aValueShape = anExp.Current();
00754     aFunction->SetValue( aValueShape );
00755     theClosed->Append(anObj);
00756   }
00757   for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
00758   {
00759     anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
00760     aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
00761     TopoDS_Shape aValueShape = anExp.Current();
00762     aFunction->SetValue( aValueShape );
00763     theOpen->Append(anObj);
00764   }
00765 
00766   if(!aFunction.IsNull()) {
00767 
00768     //Make a Python command
00769     GEOM::TPythonDump pd (aFunction);
00770 
00771     Standard_Integer i, aLen = theClosed->Length();
00772     if (aLen > 0) {
00773       pd << "(isDone, [";
00774       for (i = 1; i <= aLen; i++) {
00775         Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i));
00776         pd << anObj_i << ((i < aLen) ? ", " : "");
00777       }
00778       pd << "], ";
00779     } else {
00780       pd << "(isDone, empty_list, ";
00781     }
00782 
00783     aLen = theOpen->Length();
00784     if (aLen > 0) {
00785       pd << "[";
00786       for (i = 1; i <= aLen; i++) {
00787         Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i));
00788         pd << anObj_i << ((i < aLen) ? ", " : "");
00789       }
00790       pd << "]";
00791     } else {
00792       pd << "empty_list";
00793     }
00794 
00795     pd << ") = geompy.GetFreeBoundary(" << theObject << ")";
00796   }
00797 
00798   SetErrorCode(OK);
00799   return true;
00800 }
00801 
00802 
00803 //=============================================================================
00807 //=============================================================================
00808 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_Object) theObject)
00809 {
00810   // set error code, check parameters
00811   SetErrorCode(KO);
00812 
00813   if (theObject.IsNull())
00814     return NULL;
00815 
00816   if (!theObject->IsMainShape()) {
00817     SetErrorCode("Sub-shape cannot be transformed - need to create a copy");
00818     return NULL;
00819   }
00820 
00821   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00822   if (aLastFunction.IsNull())
00823     return NULL; //There is no function which creates an object to be processed
00824 
00825   if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
00826     //Add the function
00827     aFunction = theObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
00828 
00829     //Check if the function is set correctly
00830     if (aFunction.IsNull()) return NULL;
00831     if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
00832 
00833     // prepare "data container" class IVector
00834     GEOMImpl_IVector aVI (aFunction);
00835     aVI.SetCurve(aLastFunction);
00836   }
00837   else {
00838     //Add the function
00839     aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
00840 
00841     //Check if the function is set correctly
00842     if (aFunction.IsNull()) return NULL;
00843     if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00844 
00845     // prepare "data container" class IHealing
00846     GEOMImpl_IHealing HI (aFunction);
00847     HI.SetOriginal(aLastFunction);
00848   }
00849 
00850   //Compute the translation
00851   try {
00852 #if OCC_VERSION_LARGE > 0x06010000
00853     OCC_CATCH_SIGNALS;
00854 #endif
00855     if (!GetSolver()->ComputeFunction(aFunction)) {
00856       SetErrorCode("Healing driver failed");
00857       return NULL;
00858     }
00859   }
00860   catch (Standard_Failure) {
00861     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00862     SetErrorCode(aFail->GetMessageString());
00863     return NULL;
00864   }
00865 
00866   //Make a Python command
00867   GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell("
00868                                << theObject << ")";
00869 
00870   SetErrorCode(OK);
00871   return theObject;
00872 }
00873 
00874 //=============================================================================
00878 //=============================================================================
00879 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(GEOM_Object) theObject)
00880 {
00881   // set error code, check parameters
00882   SetErrorCode(KO);
00883 
00884   if (theObject.IsNull())
00885     return NULL;
00886 
00887   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00888   if (aLastFunction.IsNull())
00889     return NULL; //There is no function which creates an object to be processed
00890 
00891   // Add a new object
00892   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
00893 
00894   if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
00895     //Add the function
00896     aFunction = aNewObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
00897 
00898     //Check if the function is set correctly
00899     if (aFunction.IsNull()) return NULL;
00900     if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
00901 
00902     // prepare "data container" class IVector
00903     GEOMImpl_IVector aVI (aFunction);
00904     aVI.SetCurve(aLastFunction);
00905   }
00906   else {
00907     //Add the function
00908     aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
00909 
00910     //Check if the function is set correctly
00911     if (aFunction.IsNull()) return NULL;
00912     if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00913 
00914     // prepare "data container" class IHealing
00915     GEOMImpl_IHealing aHI (aFunction);
00916     aHI.SetOriginal(aLastFunction);
00917   }
00918 
00919   // Compute the result
00920   try {
00921 #if OCC_VERSION_LARGE > 0x06010000
00922     OCC_CATCH_SIGNALS;
00923 #endif
00924     if (!GetSolver()->ComputeFunction(aFunction)) {
00925       SetErrorCode("Healing driver failed");
00926       return NULL;
00927     }
00928   }
00929   catch (Standard_Failure) {
00930     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00931     SetErrorCode(aFail->GetMessageString());
00932     return NULL;
00933   }
00934 
00935   //Make a Python command
00936   GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.ChangeOrientationShellCopy("
00937                                << theObject << ")";
00938 
00939   SetErrorCode(OK);
00940   return aNewObject;
00941 }
00942 
00943 //=============================================================================
00947 //=============================================================================
00948 Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject,
00949                                                                  double theTolerance)
00950 {
00951   // Set error code, check parameters
00952   SetErrorCode(KO);
00953 
00954   if (theObject.IsNull())
00955     return NULL;
00956 
00957   Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
00958   if (aLastFunction.IsNull())
00959     return NULL; // There is no function which creates an object to be processed
00960 
00961   // Add a new object
00962   Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
00963 
00964   // Add the function
00965   aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE);
00966 
00967   if (aFunction.IsNull())
00968     return NULL;
00969 
00970   // Check if the function is set correctly
00971   if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
00972 
00973   // Prepare "data container" class IHealing
00974   GEOMImpl_IHealing HI (aFunction);
00975   HI.SetOriginal(aLastFunction);
00976   HI.SetTolerance(theTolerance);
00977 
00978   // Compute
00979   try {
00980 #if OCC_VERSION_LARGE > 0x06010000
00981     OCC_CATCH_SIGNALS;
00982 #endif
00983     if (!GetSolver()->ComputeFunction(aFunction)) {
00984       SetErrorCode("Healing driver failed");
00985       return NULL;
00986     }
00987   }
00988   catch (Standard_Failure) {
00989     Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00990     SetErrorCode(aFail->GetMessageString());
00991     return NULL;
00992   }
00993 
00994   // Make a Python command
00995   GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance("
00996                                << theObject << ", " << theTolerance << ")";
00997 
00998   SetErrorCode(OK);
00999   return aNewObject;
01000 }