X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_IHealingOperations.cxx;h=9caef8a39d725ebfd7d98ca59e9fd2a5c73446ff;hb=4b1dcba7c7d21a118f8698a31070d67a55923b78;hp=a87816fb3e46bf5358e247c880f9cd337881b193;hpb=732211808796539fcf1de34e06038e7fb015ece9;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx index a87816fb3..9caef8a39 100644 --- a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx @@ -1,19 +1,44 @@ -using namespace std; - -#include "GEOMImpl_IHealingOperations.hxx" - -#include "GEOM_PythonDump.hxx" - -#include "GEOMImpl_HealingDriver.hxx" -#include "GEOMImpl_Types.hxx" -#include "GEOMImpl_IHealing.hxx" -#include "GEOMImpl_CopyDriver.hxx" - -#include "ShHealOper_ShapeProcess.hxx" +// Copyright (C) 2007-2008 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 + +#include +#include +#include +#include + +#include #include "utilities.h" -#include "OpUtil.hxx" -#include "Utils_ExceptHandlers.hxx" +#include +#include #include @@ -26,8 +51,11 @@ using namespace std; #include +#include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +using namespace std; + //============================================================================= /*! @@ -111,8 +139,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Objec } //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Shape Healing algorithm failed"); @@ -318,8 +348,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -361,7 +393,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour SetErrorCode(KO); if (theObject.IsNull()) + { + SetErrorCode("NULL object given"); 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 @@ -384,8 +419,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -404,11 +441,14 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour pd << aNewObject << " = geompy.CloseContour(" << theObject << ", ["; // list of wire ids - int i = theWires->Lower(), nb = theWires->Upper(); - for ( ; i <= nb; i++) - pd << theWires->Value( i ) << (( i < nb ) ? ", " : "], "); - - pd << (int)isCommonVertex << ")"; + if (!theWires.IsNull()) + { + int i = theWires->Lower(), nb = theWires->Upper(); + pd << theWires->Value(i++); + while (i <= nb) + pd << ", " << theWires->Value(i++); + } + pd << "], " << (int)isCommonVertex << ")"; SetErrorCode(OK); return aNewObject; @@ -448,8 +488,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -514,8 +556,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -534,9 +578,13 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) pd << aNewObject << " = geompy.SuppressHoles(" << theObject << ", ["; // list of wire ids - int i = theWires->Lower(), nb = theWires->Upper(); - for ( ; i <= nb; i++) - pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])"); + if ( theWires.IsNull() ) + pd << "])"; + else { + int i = theWires->Lower(), nb = theWires->Upper(); + for ( ; i <= nb; i++) + pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])"); + } SetErrorCode(OK); return aNewObject; @@ -576,8 +624,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObj HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -637,8 +687,10 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) HI.SetOriginal( aLastFunction ); //Compute the translation - try - { + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif if (!GetSolver()->ComputeFunction(aFunction)) { SetErrorCode("Healing driver failed"); @@ -705,35 +757,157 @@ bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject theOpen->Append(anObj); } - //Make a Python command - GEOM::TPythonDump pd (aFunction); + if(!aFunction.IsNull()) { + + //Make a Python command + GEOM::TPythonDump pd (aFunction); + + Standard_Integer i, aLen = theClosed->Length(); + if (aLen > 0) { + pd << "(isDone, ["; + for (i = 1; i <= aLen; i++) { + Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i)); + pd << anObj_i << ((i < aLen) ? ", " : ""); + } + pd << "], "; + } else { + pd << "(isDone, empty_list, "; + } - Standard_Integer i, aLen = theClosed->Length(); - if (aLen > 0) { - pd << "(isDone, ["; - for (i = 1; i <= aLen; i++) { - Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i)); - pd << anObj_i << ((i < aLen) ? ", " : ""); + aLen = theOpen->Length(); + if (aLen > 0) { + pd << "["; + for (i = 1; i <= aLen; i++) { + Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i)); + pd << anObj_i << ((i < aLen) ? ", " : ""); + } + pd << "]"; + } else { + pd << "empty_list"; } - pd << "], "; - } else { - pd << "(isDone, empty_list, "; + + pd << ") = geompy.GetFreeBoundary(" << theObject << ")"; } - aLen = theOpen->Length(); - if (aLen > 0) { - pd << "["; - for (i = 1; i <= aLen; i++) { - Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i)); - pd << anObj_i << ((i < aLen) ? ", " : ""); + 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 + + //Add the function + aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION); + + 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 ); + + //Compute the translation + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Healing driver failed"); + return NULL; } - pd << "]"; - } else { - pd << "empty_list"; + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; } - pd << ") = geompy.GetFreeBoundary(" << theObject << ")"; + //Make a Python command + GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell(" + << theObject << ")"; SetErrorCode(OK); - return true; + 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(), GEOM_COPY ); + + //Add the function + aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION); + + 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 ); + + //Compute the translation + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + 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; +} +