X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_IHealingOperations.cxx;h=265a35f6cf926ae57200f367ea257eda1dbd1ad8;hb=de2617e3f55fc12bac2da61fcbaf2d96f1e38926;hp=5e86fbacc1f5c292d14949c13ec3251b0964df07;hpb=3a675cc5c05dd6d74d9b371b2db3b0e0c8ff53e3;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx index 5e86fbacc..265a35f6c 100644 --- a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx @@ -1,7 +1,29 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + #ifdef WNT #pragma warning( disable:4786 ) #endif +#include #include #include @@ -11,14 +33,18 @@ #include #include #include +#include +#include #include -#include +#include #include "utilities.h" #include #include +#include + #include #include @@ -30,15 +56,14 @@ #include +#include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC - //============================================================================= /*! * constructor: */ //============================================================================= - GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine, int theDocID) : GEOM_IOperations(theEngine, theDocID) { @@ -50,7 +75,6 @@ GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine * destructor */ //============================================================================= - GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations() { MESSAGE("GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations"); @@ -115,8 +139,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec } //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Shape Healing algorithm failed"); @@ -165,9 +191,9 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec * ShapeProcess */ //============================================================================= -void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list& theOperations, - list& theParams, - list& theValues) +void GEOMImpl_IHealingOperations::GetShapeProcessParameters (std::list& theOperations, + std::list& theParams, + std::list& theValues) { ShHealOper_ShapeProcess aHealer; TColStd_SequenceOfAsciiString anOperators; @@ -176,9 +202,9 @@ void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list& theOp { for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ ) { - string anOperation = anOperators.Value( i ).ToCString(); + std::string anOperation = anOperators.Value( i ).ToCString(); if ( GetOperatorParameters( anOperation, theParams, theValues ) ) - theOperations.push_back( anOperation ); + theOperations.push_back( anOperation ); else nbOperatorErrors++; } @@ -200,23 +226,23 @@ void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list& theOp * GetOperatorParameters */ //============================================================================= -bool GEOMImpl_IHealingOperations::GetOperatorParameters( const string theOperation, - list& theParams, - list& theValues ) +bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string theOperation, + std::list& theParams, + std::list& theValues ) { ShHealOper_ShapeProcess aHealer; int nbParamValueErrors( 0 ); - list aParams; + std::list aParams; if ( GetParameters( theOperation, aParams ) ) { - for ( list::iterator it = aParams.begin(); it != aParams.end(); ++it ) { + for ( std::list::iterator it = aParams.begin(); it != aParams.end(); ++it ) { TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() ); TCollection_AsciiString aValue; if ( aHealer.GetParameter( aParam, aValue ) ) { - theParams.push_back( aParam.ToCString() ); - theValues.push_back( aValue.ToCString() ); + theParams.push_back( aParam.ToCString() ); + theValues.push_back( aValue.ToCString() ); } else - nbParamValueErrors++; + nbParamValueErrors++; } } else @@ -236,8 +262,8 @@ bool GEOMImpl_IHealingOperations::GetOperatorParameters( const string theOperati * GetParameters */ //============================================================================= -bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation, - list& theParams) +bool GEOMImpl_IHealingOperations::GetParameters (const std::string theOperation, + std::list& theParams) { if ( theOperation == "SplitAngle" ) { theParams.push_back( "SplitAngle.Angle" ); @@ -299,31 +325,33 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces // set error code, check parameters SetErrorCode(KO); - if ( theObject.IsNull() ) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed.. + if (theObject.IsNull()) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed.. return NULL; Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction(); - if(aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed + if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed // Add a new object - Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY ); + Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY); //Add the function aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES); - if(aFunction.IsNull()) return NULL; + if (aFunction.IsNull()) return NULL; //Check if the function is set correctly - if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; // prepare "data container" class IHealing - GEOMImpl_IHealing HI(aFunction); - HI.SetFaces( theFaces ); - HI.SetOriginal( aLastFunction ); + GEOMImpl_IHealing HI (aFunction); + HI.SetFaces(theFaces); + HI.SetOriginal(aLastFunction); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -332,7 +360,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces } catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); return NULL; } @@ -350,7 +378,6 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces return aNewObject; } - //============================================================================= /*! * CloseContour @@ -391,8 +418,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -401,7 +430,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour } catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); return NULL; } @@ -458,8 +487,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -524,8 +555,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -534,7 +567,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) } catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); return NULL; } @@ -590,8 +623,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -600,7 +635,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj } catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); return NULL; } @@ -651,8 +686,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -661,7 +698,7 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) } catch (Standard_Failure) { - Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); SetErrorCode(aFail->GetMessageString()); return NULL; } @@ -680,8 +717,8 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) */ //============================================================================= bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject, - Handle(TColStd_HSequenceOfTransient)& theClosed, - Handle(TColStd_HSequenceOfTransient)& theOpen ) + Handle(TColStd_HSequenceOfTransient)& theClosed, + Handle(TColStd_HSequenceOfTransient)& theOpen ) { // set error code, check parameters SetErrorCode(KO); @@ -694,7 +731,13 @@ bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject return false; // get free boundary shapes - ShapeAnalysis_FreeBounds anAnalizer( aShape ); + +#if OCC_VERSION_LARGE > 0x06030008 + ShapeAnalysis_FreeBounds anAnalizer(aShape, Standard_False, + Standard_True, Standard_True); +#else + ShapeAnalysis_FreeBounds anAnalizer(aShape); +#endif TopoDS_Compound aClosed = anAnalizer.GetClosedWires(); TopoDS_Compound anOpen = anAnalizer.GetOpenWires(); @@ -754,3 +797,203 @@ bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject SetErrorCode(OK); return true; } + + +//============================================================================= +/*! + * ChangeOrientation + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_Object) theObject) +{ + // set error code, check parameters + SetErrorCode(KO); + + if (theObject.IsNull()) + return NULL; + + if (!theObject->IsMainShape()) { + SetErrorCode("Sub shape cannot be transformed - need to create a copy"); + return NULL; + } + + Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction(); + if (aLastFunction.IsNull()) + return NULL; //There is no function which creates an object to be processed + + if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066 + //Add the function + aFunction = theObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE); + + //Check if the function is set correctly + if (aFunction.IsNull()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL; + + // prepare "data container" class IVector + GEOMImpl_IVector aVI (aFunction); + aVI.SetCurve(aLastFunction); + } + else { + //Add the function + aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION); + + //Check if the function is set correctly + if (aFunction.IsNull()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; + + // prepare "data container" class IHealing + GEOMImpl_IHealing HI (aFunction); + HI.SetOriginal(aLastFunction); + } + + //Compute the translation + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Healing driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell(" + << theObject << ")"; + + SetErrorCode(OK); + return theObject; +} + +//============================================================================= +/*! + * ChangeOrientationCopy + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(GEOM_Object) theObject) +{ + // set error code, check parameters + SetErrorCode(KO); + + if (theObject.IsNull()) + return NULL; + + Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction(); + if (aLastFunction.IsNull()) + return NULL; //There is no function which creates an object to be processed + + // Add a new object + Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + + if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066 + //Add the function + aFunction = aNewObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE); + + //Check if the function is set correctly + if (aFunction.IsNull()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL; + + // prepare "data container" class IVector + GEOMImpl_IVector aVI (aFunction); + aVI.SetCurve(aLastFunction); + } + else { + //Add the function + aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION); + + //Check if the function is set correctly + if (aFunction.IsNull()) return NULL; + if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; + + // prepare "data container" class IHealing + GEOMImpl_IHealing aHI (aFunction); + aHI.SetOriginal(aLastFunction); + } + + // Compute the result + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Healing driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + //Make a Python command + GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.ChangeOrientationShellCopy(" + << theObject << ")"; + + SetErrorCode(OK); + return aNewObject; +} + +//============================================================================= +/*! + * LimitTolerance + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject, + double theTolerance) +{ + // Set error code, check parameters + SetErrorCode(KO); + + if (theObject.IsNull()) + return NULL; + + Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction(); + if (aLastFunction.IsNull()) + return NULL; // There is no function which creates an object to be processed + + // Add a new object + Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + + // Add the function + aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE); + + if (aFunction.IsNull()) + return NULL; + + // Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; + + // Prepare "data container" class IHealing + GEOMImpl_IHealing HI (aFunction); + HI.SetOriginal(aLastFunction); + HI.SetTolerance(theTolerance); + + // Compute + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Healing driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + // Make a Python command + GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance(" + << theObject << ", " << theTolerance << ")"; + + SetErrorCode(OK); + return aNewObject; +}