From: jfa Date: Wed, 15 Dec 2010 11:43:32 +0000 (+0000) Subject: Mantis issue 0021020: RestoreSubShapes in multi- translation/rotation. X-Git-Tag: V6_2_0a2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca21beb73c2fd2f032bfa7f29cb7a002f0f3bbbd;p=modules%2Fgeom.git Mantis issue 0021020: RestoreSubShapes in multi- translation/rotation. --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index d6be57c54..13c258f39 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -111,7 +111,12 @@ module GEOM FSM_GetShapesOnShape, /*! Use GetInPlaceByHistory method (can work only after Partition) */ - FSM_GetInPlaceByHistory + FSM_GetInPlaceByHistory, + + /*! To be used only for multi-transformation result. + * Only this method can be used after multi-transformation. + */ + FSM_MultiTransformed }; /*! @@ -967,13 +972,23 @@ module GEOM * \param theCopy is a true or false parameter. true is to reverse direction, false is to move normal direction. * \return New GEOM_Object, containing the displaced shape. */ - GEOM_Object PositionAlongPath (in GEOM_Object theObject, in GEOM_Object thePath, in double theDistance, in boolean theCopy, in boolean theReverse); + /*! + * Transform the shape in the same way what was used for the sample shape creation. + * \param theObject The object to be transformed. + * \param theSample The object containing information about required transformation. + * \note Implementation of this method is limited by multi-transformations now. + * \note Internal method. + * \return New GEOM_Object, containing the transformed shape. + */ + GEOM_Object TransformLikeOtherCopy (in GEOM_Object theObject, + in GEOM_Object theSample); + /*! * Recompute the shape from its arguments. * \param theObject The object to be recomputed. diff --git a/src/GEOMImpl/GEOMImpl_IRotate.hxx b/src/GEOMImpl/GEOMImpl_IRotate.hxx index c60ad507b..002b25c4d 100644 --- a/src/GEOMImpl/GEOMImpl_IRotate.hxx +++ b/src/GEOMImpl/GEOMImpl_IRotate.hxx @@ -18,21 +18,25 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -//NOTE: This is an intreface to a function for the Rotate operation. -// +// NOTE: This is an interface to a function for the Rotate operation. + #include "GEOM_Function.hxx" +#include + #define ROTATE_ANGLE 1 #define ROTATE_AXIS 2 #define ROTATE_ORGN 3 #define ROTATE_STEP1 4 -#define ROTATE_NBITER1 5 -#define ROTATE_NBITER2 6 +#define ROTATE_NBITER1 5 +#define ROTATE_NBITER2 6 #define ROTATE_CENTRAL_POINT 7 #define ROTATE_POINT1 8 #define ROTATE_POINT2 9 +#define ROTATE_DIR2_X 10 +#define ROTATE_DIR2_Y 11 +#define ROTATE_DIR2_Z 12 class GEOMImpl_IRotate { @@ -64,7 +68,7 @@ class GEOMImpl_IRotate Handle(GEOM_Function) GetOriginal() { return _func->GetReference(ROTATE_ORGN); } - void SetStep(double theStep) { return _func->SetReal(ROTATE_STEP1, theStep); } + void SetStep(double theStep) { _func->SetReal(ROTATE_STEP1, theStep); } double GetStep() { return _func->GetReal(ROTATE_STEP1); } @@ -76,6 +80,21 @@ class GEOMImpl_IRotate int GetNbIter2() { return _func->GetInteger(ROTATE_NBITER2); } + void SetDir2 (gp_XYZ theDir2) + { + _func->SetReal(ROTATE_DIR2_X, theDir2.X()); + _func->SetReal(ROTATE_DIR2_Y, theDir2.Y()); + _func->SetReal(ROTATE_DIR2_Z, theDir2.Z()); + } + + gp_XYZ GetDir2() + { + gp_XYZ aRes (0., 0., 0.); + aRes.SetX(_func->GetReal(ROTATE_DIR2_X)); + aRes.SetY(_func->GetReal(ROTATE_DIR2_Y)); + aRes.SetZ(_func->GetReal(ROTATE_DIR2_Z)); + return aRes; + } private: diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 6e34f80a0..e916f4232 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -3271,7 +3271,7 @@ namespace { */ //================================================================================ - gp_Vec GetNormal(const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema) + gp_Vec GetNormal (const TopoDS_Face& face, const BRepExtrema_DistShapeShape& extrema) { gp_Vec defaultNorm(1,0,0); // to have same normals on different faces try { @@ -3304,12 +3304,35 @@ namespace { } return defaultNorm; } + + //================================================================================ + /*! + * \brief Return type of shape for explode. In case of compound it will be a type of sub shape. + */ + //================================================================================ + + TopAbs_ShapeEnum GetTypeOfSimplePart (const TopoDS_Shape& theShape) + { + TopAbs_ShapeEnum aType = theShape.ShapeType(); + if (aType == TopAbs_VERTEX) return TopAbs_VERTEX; + else if (aType == TopAbs_EDGE || aType == TopAbs_WIRE) return TopAbs_EDGE; + else if (aType == TopAbs_FACE || aType == TopAbs_SHELL) return TopAbs_FACE; + else if (aType == TopAbs_SOLID || aType == TopAbs_COMPSOLID) return TopAbs_SOLID; + else if (aType == TopAbs_COMPOUND) { + // Only the iType of the first shape in the compound is taken into account + TopoDS_Iterator It (theShape, Standard_False, Standard_False); + if (It.More()) { + return GetTypeOfSimplePart(It.Value()); + } + } + return TopAbs_SHAPE; + } } //============================================================================= /*! - case GetInPlace: - default: + * case GetInPlace: + * default: */ //============================================================================= Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) theShapeWhere, @@ -3344,8 +3367,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) Handle(GEOM_Object) aResult; bool isFound = false; - Standard_Integer iType = TopAbs_SOLID; - Standard_Integer compType = TopAbs_SOLID; + TopAbs_ShapeEnum iType = TopAbs_SOLID; //Standard_Real aWhat_Mass = 0., aWhere_Mass = 0.; Standard_Real tab_aWhat[4], tab_aWhere[4]; Standard_Real dl_l = 1e-3; @@ -3356,6 +3378,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) GProp_GProps aProps; // Find the iType of the aWhat shape + /* if ( aWhat.ShapeType() == TopAbs_VERTEX ) iType = TopAbs_VERTEX; else if ( aWhat.ShapeType() == TopAbs_EDGE || aWhat.ShapeType() == TopAbs_WIRE ) iType = TopAbs_EDGE; else if ( aWhat.ShapeType() == TopAbs_FACE || aWhat.ShapeType() == TopAbs_SHELL ) iType = TopAbs_FACE; @@ -3367,7 +3390,7 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) SetErrorCode("Error: theShapeWhat is an empty COMPOUND."); return NULL; } - compType = It.Value().ShapeType(); + TopAbs_ShapeEnum compType = It.Value().ShapeType(); if ( compType == TopAbs_VERTEX ) iType = TopAbs_VERTEX; else if ( compType == TopAbs_EDGE || compType == TopAbs_WIRE ) iType = TopAbs_EDGE; else if ( compType == TopAbs_FACE || compType == TopAbs_SHELL) iType = TopAbs_FACE; @@ -3377,10 +3400,16 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetInPlace (Handle(GEOM_Object) SetErrorCode("Error: An attempt to extract a shape of not supported type."); return NULL; } + */ + iType = GetTypeOfSimplePart(aWhat); + if (iType == TopAbs_SHAPE) { + SetErrorCode("Error: An attempt to extract a shape of not supported type."); + return NULL; + } - TopExp_Explorer Exp_aWhat( aWhat, TopAbs_ShapeEnum( iType ) ); - TopExp_Explorer Exp_aWhere( aWhere, TopAbs_ShapeEnum( iType ) ); - TopExp_Explorer Exp_Edge( aWhere, TopAbs_EDGE ); + TopExp_Explorer Exp_aWhat ( aWhat, iType ); + TopExp_Explorer Exp_aWhere ( aWhere, iType ); + TopExp_Explorer Exp_Edge ( aWhere, TopAbs_EDGE ); // Find the shortest edge in theShapeWhere shape BRepBndLib::Add(aWhere, BoundingBox); diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index 42ab3f44f..b5731bfc1 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -28,11 +27,6 @@ #include #include -#include -#include -#include -#include - #include #include @@ -52,6 +46,23 @@ #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 @@ -560,7 +571,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); @@ -594,6 +605,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; +} +*/ //============================================================================= /*! @@ -1538,7 +1691,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); @@ -1750,3 +1903,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_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + 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; +} diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx index 8ac9ad4d9..bdac1b1bd 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOMImpl_ITransformOperations_HXX_ #define _GEOMImpl_ITransformOperations_HXX_ @@ -27,7 +26,12 @@ #include "GEOM_IOperations.hxx" #include "GEOM_Engine.hxx" #include "GEOM_Object.hxx" + #include +#include + +class GEOMImpl_ITranslate; +class GEOMImpl_IRotate; class GEOMImpl_ITransformOperations : public GEOM_IOperations { @@ -73,6 +77,14 @@ class GEOMImpl_ITransformOperations : public GEOM_IOperations double theStep2, Standard_Integer theNbTimes2); + /* + Standard_EXPORT static TopoDS_Shape TranslateShape1D (const TopoDS_Shape& theShape, + GEOMImpl_ITranslate* theTI); + + Standard_EXPORT static TopoDS_Shape TranslateShape2D (const TopoDS_Shape& theShape, + GEOMImpl_ITranslate* theTI); + */ + Standard_EXPORT Handle(GEOM_Object) MirrorPlane (Handle(GEOM_Object) theObject, Handle(GEOM_Object) thePlane); @@ -155,6 +167,9 @@ class GEOMImpl_ITransformOperations : public GEOM_IOperations Handle(GEOM_Object) thePoint1, Handle(GEOM_Object) thePoint2); + Standard_EXPORT Handle(GEOM_Object) TransformLikeOtherCopy (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theSample); + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_RotateDriver.cxx b/src/GEOMImpl/GEOMImpl_RotateDriver.cxx index 914fcc952..a11e17b0c 100644 --- a/src/GEOMImpl/GEOMImpl_RotateDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_RotateDriver.cxx @@ -205,35 +205,45 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const gp_Ax1 AX1(aP1, D); - gp_Trsf aTrsf1; gp_Trsf aTrsf2; - gp_Pnt P1; - GProp_GProps System; - if (anOriginal.ShapeType() == TopAbs_VERTEX) { - P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal )); - } - else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) { - BRepGProp::LinearProperties(anOriginal, System); - P1 = System.CentreOfMass(); - } - else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) { - BRepGProp::SurfaceProperties(anOriginal, System); - P1 = System.CentreOfMass(); - } - else { - BRepGProp::VolumeProperties(anOriginal, System); - P1 = System.CentreOfMass(); - } + gp_XYZ aDir2 = RI.GetDir2(); // can be set by previous execution + if (aDir2.Modulus() < gp::Resolution()) { + // Calculate direction as vector from the axis to the shape's center + gp_Pnt P1; + GProp_GProps System; + + if (anOriginal.ShapeType() == TopAbs_VERTEX) { + P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal )); + } + else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) { + BRepGProp::LinearProperties(anOriginal, System); + P1 = System.CentreOfMass(); + } + else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) { + BRepGProp::SurfaceProperties(anOriginal, System); + P1 = System.CentreOfMass(); + } + else { + BRepGProp::VolumeProperties(anOriginal, System); + P1 = System.CentreOfMass(); + } - Handle(Geom_Line) Line = new Geom_Line(AX1); - GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ); - gp_Pnt P2 = aPrjTool.NearestPoint(); + Handle(Geom_Line) Line = new Geom_Line(AX1); + GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ); + gp_Pnt P2 = aPrjTool.NearestPoint(); - if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0; + if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0; + + aDir2 = gp_XYZ(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()); + + // Attention: this abnormal action is done for good working of + // TransformLikeOther(), used by RestoreSubShapes functionality + RI.SetDir2(aDir2); + } - gp_Vec Vec (P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()); + gp_Vec Vec (aDir2); Vec.Normalize(); Standard_Integer nbtimes2 = RI.GetNbIter2(); diff --git a/src/GEOMImpl/GEOMImpl_TranslateDriver.cxx b/src/GEOMImpl/GEOMImpl_TranslateDriver.cxx index f6d4fb0eb..a3b54774b 100644 --- a/src/GEOMImpl/GEOMImpl_TranslateDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_TranslateDriver.cxx @@ -18,12 +18,12 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include #include #include +#include #include #include @@ -79,7 +79,7 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const if (aFunction.IsNull()) return 0; - GEOMImpl_ITranslate TI(aFunction); + GEOMImpl_ITranslate TI (aFunction); gp_Trsf aTrsf; gp_Pnt aP1, aP2; Standard_Integer aType = aFunction->GetType(); @@ -197,6 +197,7 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const B.Add(aCompound, anOriginal.Located(aLocRes)); } aShape = aCompound; + //aShape = GEOMImpl_ITransformOperations::TranslateShape1D(anOriginal, &TI); } else if (aType == TRANSLATE_2D) { Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2(); @@ -242,7 +243,8 @@ Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const B.Add(aCompound, anOriginal.Located(aLocRes)); } } - aShape = aCompound; + aShape = aCompound; + //aShape = GEOMImpl_ITransformOperations::TranslateShape2D(anOriginal, &TI); } else return 0; diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 49292bda4..5606d8bfc 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -966,8 +966,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, } else { // Get interface, containing method, which we will use to reconstruct sub-shapes - GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); - GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct arguments and tree of sub-shapes of the arguments CORBA::String_var anIOR; @@ -996,6 +997,64 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, aSubO = aShapesOp->GetInPlace(theObject, anArgO); } break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); + } + /* + Handle(GEOM_Function) anOFun = theObject->GetLastFunction(); + if (!anOFun.IsNull()) { + CORBA::String_var entryArg = anArgO->GetEntry(); + Handle(GEOM_Object) anArgOImpl = _impl->GetObject(anArgO->GetStudyID(), entryArg); + if (!anArgOImpl.IsNull()) { + TopoDS_Shape anArgOShape = anArgOImpl->GetValue(); + TopoDS_Shape aMultiArgShape; + //GEOM::GEOM_Object_var anArgOMulti; // ??? + switch (anOFun->GetType()) { + case TRANSLATE_1D: + { + GEOMImpl_ITranslate aTI (anOFun); + aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape1D(anArgOShape, &aTI); + //anArgOMulti = aTrsfOp->Translate1D(anArgO, , , ); + } + break; + case TRANSLATE_2D: + { + GEOMImpl_ITranslate aTI (anOFun); + aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + case ROTATE_1D: + { + GEOMImpl_IRotate aTI (anOFun); + //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + case ROTATE_2D: + { + GEOMImpl_IRotate aTI (anOFun); + //aMultiArgShape = GEOMImpl_ITransformOperations::TranslateShape2D(anArgOShape, &aTI); + } + break; + default: + {} + } + GEOM::GEOM_Object_var anArgOMulti = (aMultiArgShape); // TODO + Handle(GEOM_Function) anArgOMultiFun = anArgOMulti->GetLastFunction(); + anArgOMultiFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOMulti); + } + } + */ + } + break; case GEOM::FSM_Transformed: { // transformation, cannot use GetInPlace, operate with indices @@ -1183,6 +1242,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapes(SALOMEDS::Study_ptr theStudy, switch (theFindMethod) { case GEOM::FSM_GetInPlace: pd << "FSM_GetInPlace"; break; + case GEOM::FSM_MultiTransformed: + pd << "FSM_MultiTransformed"; break; case GEOM::FSM_Transformed: pd << "FSM_Transformed"; break; case GEOM::FSM_GetSame: @@ -1221,8 +1282,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); // Get interface, containing method, which we will use to reconstruct sub-shapes - GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); - GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct published sub-shapes SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); @@ -1253,6 +1315,19 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr th aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO); } break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); + } + } + break; case GEOM::FSM_Transformed: { // transformation, cannot use GetInPlace, operate with indices @@ -1482,8 +1557,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu } else { // Get interface, containing method, which we will use to reconstruct sub-shapes - GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); - GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct arguments and tree of sub-shapes of the arguments CORBA::String_var anIOR; @@ -1512,6 +1588,19 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu aSubO = aShapesOp->GetInPlace(theObject, anArgO); } break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anArgO, theObject); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aSubO = aShapesOp->GetInPlace(theObject, anArgOTrsf); + } + } + break; case GEOM::FSM_Transformed: { // transformation, cannot use GetInPlace, operate with indices @@ -1691,6 +1780,8 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapes(SALOMEDS::Study_ptr theStu switch (theFindMethod) { case GEOM::FSM_GetInPlace: pd << "FSM_GetInPlace"; break; + case GEOM::FSM_MultiTransformed: + pd << "FSM_MultiTransformed"; break; case GEOM::FSM_Transformed: pd << "FSM_Transformed"; break; case GEOM::FSM_GetSame: @@ -1729,8 +1820,9 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); // Get interface, containing method, which we will use to reconstruct sub-shapes - GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); - GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId()); + GEOM::GEOM_IGroupOperations_var aGroupOp = GetIGroupOperations(theStudy->StudyId()); + GEOM::GEOM_ITransformOperations_var aTrsfOp = GetITransformOperations(theStudy->StudyId()); // Reconstruct published sub-shapes SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO); @@ -1769,6 +1861,19 @@ GEOM::ListOfGO* GEOM_Gen_i::RestoreGivenSubShapesOneLevel (SALOMEDS::Study_ptr aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO); } break; + case GEOM::FSM_MultiTransformed: + { + // Only for Multi-transformations + GEOM::GEOM_Object_var anArgOTrsf = aTrsfOp->TransformLikeOtherCopy(anOldSubO, theNewO); + if (!CORBA::is_nil(anArgOTrsf)) { + CORBA::String_var anArgOTrsfEntry = anArgOTrsf->GetEntry(); + Handle(GEOM_Object) anArgOTrsfImpl = _impl->GetObject(anArgOTrsf->GetStudyID(), anArgOTrsfEntry); + Handle(GEOM_Function) anArgOTrsfFun = anArgOTrsfImpl->GetLastFunction(); + anArgOTrsfFun->SetDescription(""); + aNewSubO = aShapesOp->GetInPlace(theNewO, anArgOTrsf); + } + } + break; case GEOM::FSM_Transformed: { // transformation, cannot use GetInPlace, operate with indices diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index ef9b61ea6..568c0e010 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -1130,6 +1129,37 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::RotateThreePointsCopy return GetObject(anObject); } +//============================================================================= +/*! + * TransformLikeOtherCopy + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TransformLikeOtherCopy + (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theSample) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the object itself + Handle(GEOM_Object) anObject = GetObjectImpl(theObject); + if (anObject.IsNull()) return aGEOMObject._retn(); + + //Get the sample object + Handle(GEOM_Object) aSample = GetObjectImpl(theSample); + if (aSample.IsNull()) return aGEOMObject._retn(); + + //Perform the transformation + Handle(GEOM_Object) aResObject = + GetOperations()->TransformLikeOtherCopy(anObject, aSample); + if (!GetOperations()->IsDone() || aResObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(aResObject); +} + //============================================================================= /*! * RecomputeObject diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.hh b/src/GEOM_I/GEOM_ITransformOperations_i.hh index 5c1a40038..a26d3db54 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.hh +++ b/src/GEOM_I/GEOM_ITransformOperations_i.hh @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOM_ITransformOperations_i_HeaderFile #define _GEOM_ITransformOperations_i_HeaderFile @@ -51,10 +50,12 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr thePoint1, GEOM::GEOM_Object_ptr thePoint2); - GEOM::GEOM_Object_ptr TranslateDXDYDZ (GEOM::GEOM_Object_ptr theObject, CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ); + GEOM::GEOM_Object_ptr TranslateDXDYDZ (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ); - GEOM::GEOM_Object_ptr TranslateDXDYDZCopy (GEOM::GEOM_Object_ptr theObject, CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ); + GEOM::GEOM_Object_ptr TranslateDXDYDZCopy (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theDX, CORBA::Double theDY, CORBA::Double theDZ); GEOM::GEOM_Object_ptr TranslateVector (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theVector); @@ -67,10 +68,15 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : CORBA::Double theDistance, CORBA::Boolean theCopy); - GEOM::GEOM_Object_ptr MultiTranslate1D (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theVector, CORBA::Double theStep, CORBA::Long theNbTimes); + GEOM::GEOM_Object_ptr MultiTranslate1D (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theVector, + CORBA::Double theStep, CORBA::Long theNbTimes); - GEOM::GEOM_Object_ptr MultiTranslate2D (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theVector1, CORBA::Double theStep1, CORBA::Long theNbTimes1, - GEOM::GEOM_Object_ptr theVector2, CORBA::Double theStep2, CORBA::Long theNbTimes2); + GEOM::GEOM_Object_ptr MultiTranslate2D (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theVector1, + CORBA::Double theStep1, CORBA::Long theNbTimes1, + GEOM::GEOM_Object_ptr theVector2, + CORBA::Double theStep2, CORBA::Long theNbTimes2); GEOM::GEOM_Object_ptr Rotate (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theAxis, @@ -159,6 +165,9 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr thePoint1, GEOM::GEOM_Object_ptr thePoint2); + GEOM::GEOM_Object_ptr TransformLikeOtherCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theSample); + GEOM::GEOM_Object_ptr RecomputeObject (GEOM::GEOM_Object_ptr theObject); diff --git a/src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx b/src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx index 8916a8b74..f1fbc770a 100644 --- a/src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx +++ b/src/TransformationGUI/TransformationGUI_MultiRotationDlg.cxx @@ -637,8 +637,8 @@ void TransformationGUI_MultiRotationDlg::restoreSubShapes (SALOMEDS::Study_ptr anArgs->length(1); anArgs[0] = myBase; getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs, - /*theFindMethod=*/GEOM::FSM_GetInPlace, - /*theInheritFirstArg=*/false, + /*theFindMethod=*/GEOM::FSM_MultiTransformed, + /*theInheritFirstArg=*/true, mainFrame()->CheckBoxAddPrefix->isChecked()); } } diff --git a/src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx b/src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx index fdb8ca0e1..77c4a7bb5 100644 --- a/src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx +++ b/src/TransformationGUI/TransformationGUI_MultiTranslationDlg.cxx @@ -761,8 +761,8 @@ void TransformationGUI_MultiTranslationDlg::restoreSubShapes (SALOMEDS::Study_pt anArgs->length(1); anArgs[0] = myBase; getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs, - /*theFindMethod=*/GEOM::FSM_GetInPlace, - /*theInheritFirstArg=*/false, + /*theFindMethod=*/GEOM::FSM_MultiTransformed, + /*theInheritFirstArg=*/true, mainFrame()->CheckBoxAddPrefix->isChecked()); } }