X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMImpl%2FGEOMImpl_ITransformOperations.cxx;h=07098c561bc9c9fa4c82428afa96af026b50f66e;hb=40cd2e5cb158e1fa2b0dbd11c9a1770ec5fb20f1;hp=541ed569c833a1fd27a8345ce466b37f937adee6;hpb=0b6826bc5f36b5420f41af1475e1a79371a25323;p=modules%2Fgeom.git diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index 541ed569c..07098c561 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -1,42 +1,32 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 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 +// 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 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. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include #include -#include "utilities.h" -#include -#include - -#include -#include -#include -#include - -#include -#include - #include #include +#include #include #include #include @@ -51,6 +41,32 @@ #include +#include +#include + +#include + +#include "utilities.h" +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC @@ -112,7 +128,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPoints //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -165,7 +181,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZ //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -221,7 +237,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateTwoPointsCopy //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -276,7 +292,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateDXDYDZCopy //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -331,7 +347,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVector //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -384,7 +400,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorCopy //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -445,7 +461,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::TranslateVectorDistance //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -507,7 +523,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate1D //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -559,7 +575,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Obje //Check if the function is set correctly if (aFunction->GetDriverGUID() != GEOMImpl_TranslateDriver::GetID()) return NULL; - GEOMImpl_ITranslate aTI(aFunction); + GEOMImpl_ITranslate aTI (aFunction); aTI.SetVector(theVector->GetLastFunction()); aTI.SetVector2(theVector2->GetLastFunction()); aTI.SetOriginal(aLastFunction); @@ -570,7 +586,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Obje //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -593,6 +609,148 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Translate2D (Handle(GEOM_Obje return aCopy; } +//============================================================================= +/*! + * TranslateShape1D + */ +//============================================================================= +/* +TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape1D (const TopoDS_Shape& theShape, + GEOMImpl_ITranslate* theTI) +{ + TopoDS_Shape aRes; + + // Vector + Handle(GEOM_Function) aVector = theTI->GetVector(); + if (aVector.IsNull()) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + TopoDS_Shape aV = aVector->GetValue(); + if (aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + TopoDS_Edge anEdge = TopoDS::Edge(aV); + + gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)); + gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge)); + if (aP1.Distance(aP2) < gp::Resolution()) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + + // Step and Nb.times + Standard_Real step = theTI->GetStep1(); + Standard_Integer nbtimes = theTI->GetNbIter1(); + + // Make multi-translation + gp_Trsf aTrsf; + gp_Vec aVec; + TopoDS_Compound aCompound; + BRep_Builder B; + B.MakeCompound(aCompound); + + gp_Vec Vec (aP1, aP2); + Vec.Normalize(); + + TopLoc_Location aLocOrig = theShape.Location(); + gp_Trsf aTrsfOrig = aLocOrig.Transformation(); + + for (int i = 0; i < nbtimes; i++) { + aVec = Vec * (i * step); + aTrsf.SetTranslation(aVec); + //NPAL18620: performance problem: multiple locations are accumulated + // in shape and need a great time to process + //BRepBuilderAPI_Transform aTransformation(theShape, aTrsf, Standard_False); + //B.Add(aCompound, aTransformation.Shape()); + TopLoc_Location aLocRes (aTrsf * aTrsfOrig); + B.Add(aCompound, theShape.Located(aLocRes)); + } + aRes = aCompound; + + return aRes; +} +*/ + +//============================================================================= +/*! + * TranslateShape2D + */ +//============================================================================= +/* +TopoDS_Shape GEOMImpl_ITransformOperations::TranslateShape2D (const TopoDS_Shape& theShape, + GEOMImpl_ITranslate* theTI) +{ + TopoDS_Shape aRes; + + // Vectors + Handle(GEOM_Function) aVector1 = theTI->GetVector(); + Handle(GEOM_Function) aVector2 = theTI->GetVector2(); + + if (aVector1.IsNull() || aVector2.IsNull()) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + + TopoDS_Shape aV1 = aVector1->GetValue(); + TopoDS_Shape aV2 = aVector2->GetValue(); + + if (aV1.IsNull() || aV1.ShapeType() != TopAbs_EDGE || + aV2.IsNull() || aV2.ShapeType() != TopAbs_EDGE) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + + TopoDS_Edge anEdge1 = TopoDS::Edge(aV1); + TopoDS_Edge anEdge2 = TopoDS::Edge(aV2); + + gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1)); + gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge1)); + gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2)); + gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge2)); + + if (aP11.Distance(aP12) < gp::Resolution() || + aP21.Distance(aP22) < gp::Resolution()) { + StdFail_NotDone::Raise("Invalid object is given for vector argument"); + } + + gp_Vec Vec1 (aP11, aP12); + gp_Vec Vec2 (aP21, aP22); + + Vec1.Normalize(); + Vec2.Normalize(); + + // Step and Nb.times + Standard_Real step1 = theTI->GetStep1(), step2 = theTI->GetStep2(); + Standard_Integer nbtimes1 = theTI->GetNbIter1(), nbtimes2 = theTI->GetNbIter2(); + + // Make multi-translation + gp_Trsf aTrsf; + gp_Vec aVec; + Standard_Real DX, DY, DZ; + TopoDS_Compound aCompound; + BRep_Builder B; + B.MakeCompound(aCompound); + + TopLoc_Location aLocOrig = theShape.Location(); + gp_Trsf aTrsfOrig = aLocOrig.Transformation(); + + for (int i = 0; i < nbtimes1; i++) { + for (int j = 0; j < nbtimes2; j++) { + DX = i * step1 * Vec1.X() + j * step2 * Vec2.X(); + DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y(); + DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z(); + aVec.SetCoord(DX, DY, DZ); + aTrsf.SetTranslation(aVec); + //NPAL18620: performance problem: multiple locations are accumulated + // in shape and need a great time to process + //BRepBuilderAPI_Transform aBRepTransformation(theShape, aTrsf, Standard_False); + //B.Add(aCompound, aBRepTransformation.Shape()); + TopLoc_Location aLocRes (aTrsf * aTrsfOrig); + B.Add(aCompound, theShape.Located(aLocRes)); + } + } + aRes = aCompound; + + return aRes; +} +*/ //============================================================================= /*! @@ -626,7 +784,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlane //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -679,7 +837,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPlaneCopy //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -733,7 +891,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPoint //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -786,7 +944,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorPointCopy //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -840,7 +998,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxis //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -893,7 +1051,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::MirrorAxisCopy //Compute the mirror try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -945,7 +1103,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShape //Compute the offset try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -999,7 +1157,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy //Compute the offset try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1022,6 +1180,60 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::OffsetShapeCopy } +//============================================================================= +/*! + * ProjectShapeCopy + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::ProjectShapeCopy + (Handle(GEOM_Object) theSource, Handle(GEOM_Object) theTarget) +{ + SetErrorCode(KO); + + if (theSource.IsNull() || theTarget.IsNull()) return NULL; + + Handle(GEOM_Function) aLastFunction = theSource->GetLastFunction(); + if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be projected + + //Add a new Projection object + Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), GEOM_PROJECTION); + + //Add a Projection function + Handle(GEOM_Function) aFunction = + aCopy->AddFunction(GEOMImpl_ProjectionDriver::GetID(), PROJECTION_COPY); + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_ProjectionDriver::GetID()) return NULL; + + GEOMImpl_IMirror aTI (aFunction); + aTI.SetPlane(theTarget->GetLastFunction()); + aTI.SetOriginal(aLastFunction); + + //Compute the Projection + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Projection 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) << aCopy << " = geompy.MakeProjection(" + << theSource << ", " << theTarget << ")"; + + SetErrorCode(OK); + return aCopy; +} + + //============================================================================= /*! * ScaleShape @@ -1058,7 +1270,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape //Compute the scale try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1119,7 +1331,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy //Compute the scale try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1190,7 +1402,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(G //Compute the scale try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1251,11 +1463,11 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShape aTI.SetShape(anOriginal); aTI.SetEndLCS(theEndLCS->GetLastFunction()); if (!theStartLCS.IsNull()) - aTI.SetStartLCS(theStartLCS->GetLastFunction()); + aTI.SetStartLCS(theObject == theStartLCS ? anOriginal : theStartLCS->GetLastFunction()); //Compute the Position try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1314,7 +1526,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy //Compute the position try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1342,7 +1554,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionShapeCopy */ //============================================================================= Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath - (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath, + (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePath, double theDistance, bool theCopy, bool theReverse) { SetErrorCode(KO); @@ -1376,7 +1588,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::PositionAlongPath //Compute the position try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1439,7 +1651,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) t //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1455,7 +1667,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate (Handle(GEOM_Object) t //Make a Python command GEOM::TPythonDump(aFunction) << "geompy.Rotate(" << theObject - << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)"; + << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)"; SetErrorCode(OK); return theObject; @@ -1492,7 +1704,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Objec //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1508,7 +1720,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateCopy (Handle(GEOM_Objec //Make a Python command GEOM::TPythonDump(aFunction) << aCopy << " = geompy.MakeRotation(" << theObject - << ", " << theAxis << ", " << theAngle * 180.0 / PI << "*math.pi/180.0)"; + << ", " << theAxis << ", " << theAngle * 180.0 / M_PI << "*math.pi/180.0)"; SetErrorCode(OK); return aCopy; @@ -1537,7 +1749,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_1D); if (aFunction.IsNull()) return NULL; - //Check if the function is set correctly + //Check if the function is set correctly if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL; GEOMImpl_IRotate aRI(aFunction); @@ -1547,7 +1759,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate1D (Handle(GEOM_Object) //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1608,7 +1820,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1637,7 +1849,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) */ //============================================================================= Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theCentPoint, + Handle(GEOM_Object) theCentPoint, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2) { @@ -1670,7 +1882,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEO //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1697,8 +1909,8 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEO * RotateThreePointsCopy */ //============================================================================= -Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theCentPoint, +Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theCentPoint, Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2) { @@ -1727,7 +1939,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle //Compute the translation try { -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 +#if OCC_VERSION_LARGE > 0x06010000 OCC_CATCH_SIGNALS; #endif if (!GetSolver()->ComputeFunction(aFunction)) { @@ -1749,3 +1961,148 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePointsCopy (Handle return aCopy; } +//============================================================================= +/*! + * TransformLikeOtherCopy + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::TransformLikeOtherCopy + (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theSample) +{ + SetErrorCode(KO); + + if (theObject.IsNull() || theSample.IsNull()) return NULL; + + Handle(GEOM_Function) aLastFunction = theObject->GetLastFunction(); + if (aLastFunction.IsNull()) return NULL; // There is no function which creates an object to be transformed + + Handle(GEOM_Function) aSampleFunc = theSample->GetLastFunction(); + if (aSampleFunc.IsNull()) return NULL; // There is no function which creates a sample object + + // Add a new Copy object + Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + + // Add a transform function (depends on theSample function) + Handle(GEOM_Function) aFunction = + aCopy->AddFunction(aSampleFunc->GetDriverGUID(), aSampleFunc->GetType()); + if (aFunction.IsNull()) return NULL; + + // Check if the function is set correctly + if (aFunction->GetDriverGUID() != aSampleFunc->GetDriverGUID()) return NULL; + + if (aSampleFunc->GetDriverGUID() == GEOMImpl_TranslateDriver::GetID()) { + switch (aSampleFunc->GetType()) { + case TRANSLATE_1D: + { + GEOMImpl_ITranslate aRI_sample (aSampleFunc); + GEOMImpl_ITranslate aRI_target (aFunction); + + aRI_target.SetVector(aRI_sample.GetVector()); + aRI_target.SetStep1(aRI_sample.GetStep1()); + aRI_target.SetNbIter1(aRI_sample.GetNbIter1()); + + aRI_target.SetOriginal(aLastFunction); + } + break; + case TRANSLATE_2D: + { + GEOMImpl_ITranslate aRI_sample (aSampleFunc); + GEOMImpl_ITranslate aRI_target (aFunction); + + aRI_target.SetVector(aRI_sample.GetVector()); + aRI_target.SetStep1(aRI_sample.GetStep1()); + aRI_target.SetNbIter1(aRI_sample.GetNbIter1()); + + aRI_target.SetVector2(aRI_sample.GetVector2()); + aRI_target.SetStep2(aRI_sample.GetStep2()); + aRI_target.SetNbIter2(aRI_sample.GetNbIter2()); + + aRI_target.SetOriginal(aLastFunction); + } + break; + default: + { + SetErrorCode("Not implemented case of TransformLikeOtherCopy"); + return NULL; + } + } + } + else if (aSampleFunc->GetDriverGUID() == GEOMImpl_RotateDriver::GetID()) { + switch (aSampleFunc->GetType()) { + case ROTATE_1D: + { + GEOMImpl_IRotate aRI_sample (aSampleFunc); + GEOMImpl_IRotate aRI_target (aFunction); + + aRI_target.SetAxis(aRI_sample.GetAxis()); + aRI_target.SetNbIter1(aRI_sample.GetNbIter1()); + + aRI_target.SetOriginal(aLastFunction); + } + break; + case ROTATE_2D: + { + GEOMImpl_IRotate aRI_sample (aSampleFunc); + GEOMImpl_IRotate aRI_target (aFunction); + + aRI_target.SetAxis(aRI_sample.GetAxis()); + + aRI_target.SetNbIter1(aRI_sample.GetNbIter1()); + aRI_target.SetNbIter2(aRI_sample.GetNbIter2()); + + aRI_target.SetAngle(aRI_sample.GetAngle()); + aRI_target.SetStep(aRI_sample.GetStep()); + + aRI_target.SetDir2(aRI_sample.GetDir2()); + + aRI_target.SetOriginal(aLastFunction); + } + break; + case ROTATE_THREE_POINTS_COPY: + { + GEOMImpl_IRotate aRI_sample (aSampleFunc); + GEOMImpl_IRotate aRI_target (aFunction); + + aRI_target.SetCentPoint(aRI_sample.GetCentPoint()); + aRI_target.SetPoint1(aRI_sample.GetPoint1()); + aRI_target.SetPoint2(aRI_sample.GetPoint2()); + + aRI_target.SetOriginal(aLastFunction); + } + break; + default: + { + SetErrorCode("Not implemented case of TransformLikeOtherCopy"); + return NULL; + } + } + } + else { + SetErrorCode("Not implemented case of TransformLikeOtherCopy"); + return NULL; + } + + // Compute the transformation + try { +#if OCC_VERSION_LARGE > 0x06010000 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("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) << aCopy << " = geompy.TransformLikeOtherCopy(" + // << theObject << ", " << theSample << ")"; + + SetErrorCode(OK); + return aCopy; +}