From 5c6ce3deb5eee30d19852cf1f3c109e74b36b3fe Mon Sep 17 00:00:00 2001 From: epa Date: Fri, 27 Oct 2006 08:39:40 +0000 Subject: [PATCH] PAL 11107 - Make a rotation given an object and 3 points --- src/GEOMContext/GEOM_icons.po | 4 + src/GEOMGUI/GEOM_images.po | 4 + src/GEOMImpl/GEOMImpl_IRotate.hxx | 15 ++ .../GEOMImpl_ITransformOperations.cxx | 119 +++++++++++ .../GEOMImpl_ITransformOperations.hxx | 11 ++ src/GEOMImpl/GEOMImpl_RotateDriver.cxx | 26 +++ src/GEOMImpl/GEOMImpl_Types.hxx | 10 +- src/GEOM_I/GEOM_ITransformOperations_i.cc | 99 ++++++++++ src/GEOM_I/GEOM_ITransformOperations_i.hh | 11 ++ src/GEOM_I_Superv/GEOM_Superv_i.cc | 31 +++ src/GEOM_I_Superv/GEOM_Superv_i.hh | 11 ++ src/GEOM_SWIG/GEOM_TestAll.py | 20 +- src/GEOM_SWIG/batchmode_geompy.py | 6 + src/GEOM_SWIG/geompy.py | 15 ++ .../TransformationGUI_RotationDlg.cxx | 184 +++++++++++++++--- .../TransformationGUI_RotationDlg.h | 7 +- 16 files changed, 525 insertions(+), 48 deletions(-) diff --git a/src/GEOMContext/GEOM_icons.po b/src/GEOMContext/GEOM_icons.po index 996122d66..82eaeadd2 100644 --- a/src/GEOMContext/GEOM_icons.po +++ b/src/GEOMContext/GEOM_icons.po @@ -257,6 +257,10 @@ msgstr "translation.png" msgid "ICON_DLG_ROTATION" msgstr "rotate.png" +#RotationDlg +msgid "ICON_DLG_ROTATION_THREE_POINTS" +msgstr "rotatepnt.png" + #ScaleDlg msgid "ICON_DLG_SCALE" msgstr "scale.png" diff --git a/src/GEOMGUI/GEOM_images.po b/src/GEOMGUI/GEOM_images.po index e8132904a..130b32162 100644 --- a/src/GEOMGUI/GEOM_images.po +++ b/src/GEOMGUI/GEOM_images.po @@ -291,6 +291,10 @@ msgstr "translationVector.png" msgid "ICON_DLG_ROTATION" msgstr "rotate.png" +#RotationDlg +msgid "ICON_DLG_ROTATION_THREE_POINTS" +msgstr "rotatepnt.png" + #ScaleDlg msgid "ICON_DLG_SCALE" msgstr "scale.png" diff --git a/src/GEOMImpl/GEOMImpl_IRotate.hxx b/src/GEOMImpl/GEOMImpl_IRotate.hxx index 9d09aa487..2cdad4d5a 100644 --- a/src/GEOMImpl/GEOMImpl_IRotate.hxx +++ b/src/GEOMImpl/GEOMImpl_IRotate.hxx @@ -28,6 +28,9 @@ #define ROTATE_STEP1 4 #define ROTATE_NBITER1 5 #define ROTATE_NBITER2 6 +#define ROTATE_CENTRAL_POINT 7 +#define ROTATE_POINT1 8 +#define ROTATE_POINT2 9 class GEOMImpl_IRotate { @@ -35,6 +38,18 @@ class GEOMImpl_IRotate GEOMImpl_IRotate(Handle(GEOM_Function) theFunction): _func(theFunction) {} + void SetCentPoint(Handle(GEOM_Function) theCentPoint) { _func->SetReference(ROTATE_CENTRAL_POINT, theCentPoint); } + + Handle(GEOM_Function) GetCentPoint() { return _func->GetReference(ROTATE_CENTRAL_POINT); } + + void SetPoint1(Handle(GEOM_Function) thePoint1) { _func->SetReference(ROTATE_POINT1, thePoint1); } + + Handle(GEOM_Function) GetPoint1() { return _func->GetReference(ROTATE_POINT1); } + + void SetPoint2(Handle(GEOM_Function) thePoint2) { _func->SetReference(ROTATE_POINT2, thePoint2); } + + Handle(GEOM_Function) GetPoint2() { return _func->GetReference(ROTATE_POINT2); } + void SetAngle(Standard_Real theAngle) { _func->SetReal(ROTATE_ANGLE, theAngle); } Standard_Real GetAngle() { return _func->GetReal(ROTATE_ANGLE); } diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index 27ba4cb29..9bf0da1bf 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -1405,3 +1405,122 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::Rotate2D (Handle(GEOM_Object) SetErrorCode(OK); return aCopy; } + +//============================================================================= +/*! + * RotateThreePoints + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::RotateThreePoints (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theCentPoint, + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2) +{ + SetErrorCode(KO); + + if (theObject.IsNull() || theCentPoint.IsNull() || thePoint1.IsNull() || thePoint2.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 rotated + + // Get last functions of the arguments + Handle(GEOM_Function) aCPF = theCentPoint->GetLastFunction(); + Handle(GEOM_Function) aP1F = thePoint1->GetLastFunction(); + Handle(GEOM_Function) aP2F = thePoint2->GetLastFunction(); + + + //Add a rotate function + aFunction = theObject->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS); + + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL; + + GEOMImpl_IRotate aRI(aFunction); + aRI.SetCentPoint(aCPF); + aRI.SetPoint1(aP1F); + aRI.SetPoint2(aP2F); + aRI.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("Rotate 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.TrsfOp.RotateThreePoints(" << theObject + << ", " << theCentPoint << ", "<GetLastFunction(); + if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be rotated + + //Add a new Copy object + Handle(GEOM_Object) aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + + //Add a rotate function + aFunction = aCopy->AddFunction(GEOMImpl_RotateDriver::GetID(), ROTATE_THREE_POINTS_COPY); + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_RotateDriver::GetID()) return NULL; + + GEOMImpl_IRotate aRI(aFunction); + aRI.SetCentPoint(theCentPoint->GetLastFunction()); + aRI.SetPoint1(thePoint1->GetLastFunction()); + aRI.SetPoint2(thePoint2->GetLastFunction()); + aRI.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("Rotate 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.MakeRotationThreePoints(" << theObject + << ", " << theCentPoint << ", "<GetType(); Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal(); if(anOriginalFunction.IsNull()) return 0; @@ -102,6 +103,31 @@ Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); aShape = aTransformation.Shape(); } + else if(aType == ROTATE_THREE_POINTS || aType == ROTATE_THREE_POINTS_COPY) { + Handle(GEOM_Function) aCentPoint = RI.GetCentPoint(); + Handle(GEOM_Function) aPoint1 = RI.GetPoint1(); + Handle(GEOM_Function) aPoint2 = RI.GetPoint2(); + if(aCentPoint.IsNull() || aPoint1.IsNull() || aPoint2.IsNull()) return 0; + TopoDS_Shape aCV = aCentPoint->GetValue(); + TopoDS_Shape aV1 = aPoint1->GetValue(); + TopoDS_Shape aV2 = aPoint2->GetValue(); + if(aCV.IsNull() || aCV.ShapeType() != TopAbs_VERTEX) return 0; + if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0; + if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0; + + aCP = BRep_Tool::Pnt(TopoDS::Vertex(aCV)); + aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1)); + aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2)); + + gp_Vec aVec1(aCP, aP1); + gp_Vec aVec2(aCP, aP2); + gp_Dir aDir(aVec1 ^ aVec2); + gp_Ax1 anAx1(aCP, aDir); + Standard_Real anAngle = aVec1.Angle(aVec2); + aTrsf.SetRotation(anAx1, anAngle); + BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False); + aShape = aTransformation.Shape(); + } else if(aType == ROTATE_1D) { //Get direction Handle(GEOM_Function) anAxis = RI.GetAxis(); diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index cc0ebb563..4c436de29 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -115,10 +115,12 @@ #define TRANSLATE_XYZ 7 #define TRANSLATE_XYZ_COPY 8 -#define ROTATE 1 -#define ROTATE_COPY 2 -#define ROTATE_1D 3 -#define ROTATE_2D 4 +#define ROTATE 1 +#define ROTATE_COPY 2 +#define ROTATE_1D 3 +#define ROTATE_2D 4 +#define ROTATE_THREE_POINTS 5 +#define ROTATE_THREE_POINTS_COPY 6 #define MIRROR_PLANE 1 #define MIRROR_PLANE_COPY 2 diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index e19197e80..e914733f6 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -952,3 +952,102 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::MultiRotate2D (GEOM::GEOM_Obj return GetObject(anObject); } + +//============================================================================= +/*! + * RotateThreePoints + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::RotateThreePoints + (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + GEOM::GEOM_Object_var aGEOMObject; + + if (theCentPoint == NULL || thePoint1 == NULL || thePoint2 == NULL || theObject == NULL) return aGEOMObject._retn(); + + //check if the object is a subshape + if(!theObject->IsMainShape()) { + GetOperations()->SetErrorCode(SUBSHAPE_ERROR); + return aGEOMObject._retn(); + } + + aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject); + + //Get the object itself + Handle(GEOM_Object) anObject = + GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry()); + if (anObject.IsNull()) return aGEOMObject._retn(); + + //Get the central point of rotation + Handle(GEOM_Object) aCentPoint = + GetOperations()->GetEngine()->GetObject(theCentPoint->GetStudyID(), theCentPoint->GetEntry()); + if (aCentPoint.IsNull()) return aGEOMObject._retn(); + + //Get the first point + Handle(GEOM_Object) aPoint1 = + GetOperations()->GetEngine()->GetObject(thePoint1->GetStudyID(), thePoint1->GetEntry()); + if (aPoint1.IsNull()) return aGEOMObject._retn(); + + //Get the second point + Handle(GEOM_Object) aPoint2 = + GetOperations()->GetEngine()->GetObject(thePoint2->GetStudyID(), thePoint2->GetEntry()); + if (aPoint2.IsNull()) return aGEOMObject._retn(); + + //Perform the translation + GetOperations()->RotateThreePoints(anObject, aCentPoint, aPoint1, aPoint2); + + return aGEOMObject._retn(); +} + +//============================================================================= +/*! + * RotateThreePointsCopy + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::RotateThreePointsCopy + (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + if (theCentPoint == NULL || thePoint1 == NULL || thePoint2 == NULL || theObject == NULL) return aGEOMObject._retn(); + + //Get the object itself + Handle(GEOM_Object) aBasicObject = + GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry()); + if (aBasicObject.IsNull()) return aGEOMObject._retn(); + + //Get the central point of rotation + Handle(GEOM_Object) aCentPoint = + GetOperations()->GetEngine()->GetObject(theCentPoint->GetStudyID(), theCentPoint->GetEntry()); + if (aCentPoint.IsNull()) return aGEOMObject._retn(); + + //Get the first point + Handle(GEOM_Object) aPoint1 = + GetOperations()->GetEngine()->GetObject(thePoint1->GetStudyID(), thePoint1->GetEntry()); + if (aPoint1.IsNull()) return aGEOMObject._retn(); + + //Get the second point + Handle(GEOM_Object) aPoint2 = + GetOperations()->GetEngine()->GetObject(thePoint2->GetStudyID(), thePoint2->GetEntry()); + if (aPoint2.IsNull()) return aGEOMObject._retn(); + + //Perform the rotation + Handle(GEOM_Object) anObject = + GetOperations()->RotateThreePointsCopy(aBasicObject, aCentPoint, aPoint1, aPoint2); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.hh b/src/GEOM_I/GEOM_ITransformOperations_i.hh index 188642963..7c3fb3f40 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.hh +++ b/src/GEOM_I/GEOM_ITransformOperations_i.hh @@ -124,6 +124,17 @@ class GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr theStartLCS, GEOM::GEOM_Object_ptr theEndLCS); + GEOM::GEOM_Object_ptr RotateThreePoints (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2); + + GEOM::GEOM_Object_ptr RotateThreePointsCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2); + + ::GEOMImpl_ITransformOperations* GetOperations() { return (::GEOMImpl_ITransformOperations*)GetImpl(); } }; diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 894e4f358..6d289ff68 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -1278,6 +1278,37 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::RotateCopy (GEOM::GEOM_Object_ptr theObject endService( " GEOM_Superv_i::RotateCopy" ); return anObj; } +//============================================================================= +// RotateThreePoints: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::RotateThreePoints (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2) +{ + beginService( " GEOM_Superv_i::RotateThreePoints" ); + MESSAGE("GEOM_Superv_i::RotateThreePoints"); + getTransfOp(); + GEOM::GEOM_Object_ptr anObj = myTransfOp->RotateThreePoints(theObject, theCentPoint, thePoint1, thePoint2); + endService( " GEOM_Superv_i::RotateThreePoints" ); + return anObj; +} + +//============================================================================= +// RotateThreePointsCopy: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::RotateThreePointsCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2) +{ + beginService( " GEOM_Superv_i::RotateThreePointsCopy" ); + MESSAGE("GEOM_Superv_i::RotateThreePointsCopy"); + getTransfOp(); + GEOM::GEOM_Object_ptr anObj = myTransfOp->RotateThreePointsCopy(theObject, theCentPoint, thePoint1, thePoint2); + endService( " GEOM_Superv_i::RotateThreePointsCopy" ); + return anObj; +} //============================================================================= // MultiRotate1D: diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index 87422e14d..4dce89ebb 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -307,6 +307,17 @@ public: GEOM::GEOM_Object_ptr RotateCopy (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theAxis, CORBA::Double theAngle); + + GEOM::GEOM_Object_ptr RotateThreePoints (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2); + + GEOM::GEOM_Object_ptr RotateThreePointsCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr theCentPoint, + GEOM::GEOM_Object_ptr thePoint1, + GEOM::GEOM_Object_ptr thePoint2); + GEOM::GEOM_Object_ptr MultiRotate1D (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theAxis, CORBA::Long theNbTimes); diff --git a/src/GEOM_SWIG/GEOM_TestAll.py b/src/GEOM_SWIG/GEOM_TestAll.py index 236e187b3..ec0670186 100644 --- a/src/GEOM_SWIG/GEOM_TestAll.py +++ b/src/GEOM_SWIG/GEOM_TestAll.py @@ -156,15 +156,16 @@ def TestAll (geompy, math): Sewing = geompy.MakeSewing([Face, S], precision) #(List Of GEOM_Object_ptr, Double)->GEOM_Object_ptr #Transform objects - Translation = geompy.MakeTranslationTwoPoints(Box, px, pz) #(3 GEOM_Object_ptr)->GEOM_Object_ptr - TranslVect = geompy.MakeTranslationVector(Box, vxyz) #(2 GEOM_Object_ptr)->GEOM_Object_ptr - Rotation = geompy.MakeRotation(Box, vz, angle1) #(2 GEOM_Object_ptr, Double)->GEOM_Object_ptr - Scale = geompy.MakeScaleTransform(Box, p0, factor) # - Mirror = geompy.MakeMirrorByPlane(Box, Plane) #(2 GEOM_Object_ptr)->GEOM_Object_ptr - MirrorAxis = geompy.MakeMirrorByAxis(Box, Line1) # - MirrorPnt = geompy.MakeMirrorByPoint(Box, p200) # - Position = geompy.MakePosition(Box, cs1, cs2) #(3 GEOM_Object_ptr)->GEOM_Object_ptr - Offset = geompy.MakeOffset(Box, 10.) #(GEOM_Object_ptr, Double)->GEOM_Object_ptr + Translation = geompy.MakeTranslationTwoPoints(Box, px, pz) #(3 GEOM_Object_ptr)->GEOM_Object_ptr + TranslVect = geompy.MakeTranslationVector(Box, vxyz) #(2 GEOM_Object_ptr)->GEOM_Object_ptr + Rotation = geompy.MakeRotation(Box, vz, angle1) #(2 GEOM_Object_ptr, Double)->GEOM_Object_ptr + RotatPnt = geompy.MakeRotationThreePoints(Box, px, py, pz) #(4 GEOM_Object_ptr)->GEOM_Object_ptr + Scale = geompy.MakeScaleTransform(Box, p0, factor) # + Mirror = geompy.MakeMirrorByPlane(Box, Plane) #(2 GEOM_Object_ptr)->GEOM_Object_ptr + MirrorAxis = geompy.MakeMirrorByAxis(Box, Line1) # + MirrorPnt = geompy.MakeMirrorByPoint(Box, p200) # + Position = geompy.MakePosition(Box, cs1, cs2) #(3 GEOM_Object_ptr)->GEOM_Object_ptr + Offset = geompy.MakeOffset(Box, 10.) #(GEOM_Object_ptr, Double)->GEOM_Object_ptr Orientation = geompy.ChangeOrientation(Box) #IDList for Fillet/Chamfer @@ -292,6 +293,7 @@ def TestAll (geompy, math): id_Translation = geompy.addToStudy(Translation, "Translation") id_TranslVect = geompy.addToStudy(TranslVect , "Translation along vector") id_Rotation = geompy.addToStudy(Rotation, "Rotation") + id_RotatPnt = geompy.addToStudy(RotatPnt, "Rotation by three points") id_Scale = geompy.addToStudy(Scale, "Scale") id_Mirror = geompy.addToStudy(Mirror, "Mirror by Plane") id_MirrorAxis = geompy.addToStudy(MirrorAxis, "Mirror by Axis") diff --git a/src/GEOM_SWIG/batchmode_geompy.py b/src/GEOM_SWIG/batchmode_geompy.py index 52ccbdfff..0f91c8c9d 100644 --- a/src/GEOM_SWIG/batchmode_geompy.py +++ b/src/GEOM_SWIG/batchmode_geompy.py @@ -748,6 +748,12 @@ def MakeRotation(aShape,axis,angle): print "RotateCopy : ", TrsfOp.GetErrorCode() return anObj +def MakeRotationThreePoints(aShape, centpoint, point1, point2): + anObj = TrsfOp.RotateThreePointsCopy(aShape, centpoint, point1, point2) + if TrsfOp.IsDone() == 0: + print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode() + return anObj + def MakeScaleTransform(aShape,theCenterofScale,factor): anObj = TrsfOp.ScaleShapeCopy(aShape,theCenterofScale,factor) if TrsfOp.IsDone() == 0: diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 2247928c1..55f3659af 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -1446,6 +1446,21 @@ def MakeRotation(theObject, theAxis, theAngle): print "RotateCopy : ", TrsfOp.GetErrorCode() return anObj +## Rotate given object around vector perpendicular to plane +# containing three points, creating its copy before the rotatation. +# @param theObject The object to be rotated. +# @param theCentPoint central point - the axis is the vector perpendicular to the plane +# containing the three points. +# @param thePoint1 and thePoint2 - in a perpendicular plan of the axis. +# @return New GEOM_Object, containing the rotated object. +# +# Example: see GEOM_TestAll.py +def MakeRotationThreePoints(theObject, theCentPoint, thePoint1, thePoint2): + anObj = TrsfOp.RotateThreePointsCopy(theObject, theCentPoint, thePoint1, thePoint2) + if TrsfOp.IsDone() == 0: + print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode() + return anObj + ## Scale the given object by the factor, creating its copy before the scaling. # @param theObject The object to be scaled. # @param thePoint Center point for scaling. diff --git a/src/TransformationGUI/TransformationGUI_RotationDlg.cxx b/src/TransformationGUI/TransformationGUI_RotationDlg.cxx index c22db8006..f7ef55d89 100644 --- a/src/TransformationGUI/TransformationGUI_RotationDlg.cxx +++ b/src/TransformationGUI/TransformationGUI_RotationDlg.cxx @@ -54,26 +54,35 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION"))); - QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT"))); + SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT"))); + QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS"))); setCaption(tr("GEOM_ROTATION_TITLE")); /***************************************************************/ GroupConstructors->setTitle(tr("GEOM_ROTATION")); RadioButton1->setPixmap(image0); - RadioButton2->close(TRUE); + RadioButton2->setPixmap(image2); RadioButton3->close(TRUE); - GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints"); + GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints"); GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS")); GroupPoints->TextLabel2->setText(tr("GEOM_AXIS")); GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE")); + GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1")); + GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2")); + GroupPoints->LineEdit1->setReadOnly(true); GroupPoints->LineEdit2->setReadOnly(true); + GroupPoints->LineEdit4->setReadOnly(true); + GroupPoints->LineEdit5->setReadOnly(true); GroupPoints->PushButton1->setPixmap(image1); GroupPoints->PushButton2->setPixmap(image1); + GroupPoints->PushButton4->setPixmap(image1); + GroupPoints->PushButton5->setPixmap(image1); GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY")); GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE")); @@ -92,10 +101,13 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg /* signals and slots connections */ connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk())); connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply())); - + connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int))); + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - + connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); @@ -132,11 +144,53 @@ void TransformationGUI_RotationDlg::Init() myEditCurrentArgument = GroupPoints->LineEdit1; GroupPoints->LineEdit2->clear(); - myAxis = GEOM::GEOM_Object::_nil(); + myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); initName( tr( "GEOM_ROTATION" ) ); + ConstructorsClicked( 0 ); } +//================================================================================= +// function : ConstructorsClicked() +// purpose : Radio button management +//================================================================================= +void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId) +{ + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + + myEditCurrentArgument = GroupPoints->LineEdit1; + globalSelection(); + + switch (constructorId) + { + case 0: /* rotation an object angle and axis */ + { + GroupPoints->ShowRows(2,3,false); + resize(0,0); + GroupPoints->TextLabel2->setText(tr("GEOM_AXIS")); + GroupPoints->LineEdit2->clear(); + GroupPoints->ShowRows(4,4,true); + myAxis = GEOM::GEOM_Object::_nil(); + break; + } + case 1: /* rotation an object by 3 points */ + { + GroupPoints->ShowRows(4,4,false); + resize(0,0); + GroupPoints->ShowRows(2,3,true); + GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT")); + GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1")); + GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2")); + GroupPoints->LineEdit2->clear(); + myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); + break; + } + } + + myEditCurrentArgument->setFocus(); + connect(myGeomGUI->getApp()->selectionMgr(), + SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); +} //================================================================================= // function : ClickOnOk() @@ -184,18 +238,36 @@ void TransformationGUI_RotationDlg::SelectionIntoArgument() if (!myObjects.length()) return; } - else if(myEditCurrentArgument == GroupPoints->LineEdit2) + else { if(IObjectCount() != 1) { - myAxis = GEOM::GEOM_Object::_nil(); + if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) + myAxis = GEOM::GEOM_Object::_nil(); + else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) + myCentPoint = GEOM::GEOM_Object::_nil(); + else if(myEditCurrentArgument == GroupPoints->LineEdit4) + myPoint1 = GEOM::GEOM_Object::_nil(); + else if(myEditCurrentArgument == GroupPoints->LineEdit5) + myPoint2 = GEOM::GEOM_Object::_nil(); return; } + Standard_Boolean testResult = Standard_False; - myAxis = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult ); - if(!testResult || CORBA::is_nil( myAxis )) + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult ); + if(!testResult || CORBA::is_nil( aSelectedObject )) return; - aName = GEOMBase::GetName( myAxis ); + + if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) + myAxis = aSelectedObject; + else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) + myCentPoint = aSelectedObject; + else if(myEditCurrentArgument == GroupPoints->LineEdit4) + myPoint1 = aSelectedObject; + else if(myEditCurrentArgument == GroupPoints->LineEdit5) + myPoint2 = aSelectedObject; + + aName = GEOMBase::GetName( aSelectedObject ); } myEditCurrentArgument->setText( aName ); @@ -217,9 +289,20 @@ void TransformationGUI_RotationDlg::SetEditCurrentArgument() } else if(send == GroupPoints->PushButton2) { myEditCurrentArgument = GroupPoints->LineEdit2; - globalSelection( GEOM_LINE ); + getConstructorId() == 0 ? globalSelection( GEOM_LINE ) : + globalSelection( GEOM_POINT ); } - + else if (send == GroupPoints->PushButton4) + { + myEditCurrentArgument = GroupPoints->LineEdit4; + globalSelection( GEOM_POINT ); + } + else if (send == GroupPoints->PushButton5) + { + myEditCurrentArgument = GroupPoints->LineEdit5; + globalSelection( GEOM_POINT ); + } + myEditCurrentArgument->setFocus(); SelectionIntoArgument(); } @@ -250,11 +333,8 @@ void TransformationGUI_RotationDlg::ActivateThisDialog() GEOMBase_Skeleton::ActivateThisDialog(); connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); - globalSelection(); - GroupPoints->LineEdit1->setFocus(); - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit2->clear(); - myAxis = GEOM::GEOM_Object::_nil(); + + ConstructorsClicked( getConstructorId() ); } @@ -295,7 +375,20 @@ GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation() //================================================================================= bool TransformationGUI_RotationDlg::isValid( QString& msg ) { - return !(myObjects.length() == 0 || myAxis->_is_nil()); + switch (getConstructorId()) + { + case 0: + { + return !(myObjects.length() == 0 || myAxis->_is_nil()); + break; + } + case 1: + { + return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() ); + break; + } + default: return false; + } } @@ -306,24 +399,51 @@ bool TransformationGUI_RotationDlg::isValid( QString& msg ) bool TransformationGUI_RotationDlg::execute( ObjectList& objects ) { bool res = false; - + bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked(); + GEOM::GEOM_Object_var anObj; - if (GroupPoints->CheckButton1->isChecked() || IsPreview()) - for (int i = 0; i < myObjects.length(); i++) + switch ( getConstructorId() ) + { + case 0 : { - anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 ); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (toCreateCopy) + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 ); + if ( !anObj->_is_nil() ) + objects.push_back( anObj._retn() ); + } + else + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 ); + if ( !anObj->_is_nil() ) + objects.push_back( anObj._retn() ); + } + res = true; + break; } - else - for (int i = 0; i < myObjects.length(); i++) + case 1 : { - anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 ); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (toCreateCopy) + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 ); + if ( !anObj->_is_nil() ) + objects.push_back( anObj._retn() ); + } + else + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 ); + if ( !anObj->_is_nil() ) + objects.push_back( anObj._retn() ); + } + res = true; + break; } - res = true; + } return res; } diff --git a/src/TransformationGUI/TransformationGUI_RotationDlg.h b/src/TransformationGUI/TransformationGUI_RotationDlg.h index 482444450..4a18bbc1d 100644 --- a/src/TransformationGUI/TransformationGUI_RotationDlg.h +++ b/src/TransformationGUI/TransformationGUI_RotationDlg.h @@ -29,7 +29,7 @@ #define DIALOGBOX_ROTATION_H #include "GEOMBase_Skeleton.h" -#include "DlgRef_2Sel1Spin2Check.h" +#include "DlgRef_4Sel1Spin2Check.h" //================================================================================= // class : TransformationGUI_RotationDlg @@ -58,9 +58,9 @@ private: double GetAngle() const; GEOM::ListOfGO myObjects; - GEOM::GEOM_Object_var myAxis; + GEOM::GEOM_Object_var myAxis, myCentPoint, myPoint1, myPoint2; - DlgRef_2Sel1Spin2Check* GroupPoints; + DlgRef_4Sel1Spin2Check* GroupPoints; private slots: void ClickOnOk(); @@ -71,6 +71,7 @@ private slots: void SetEditCurrentArgument(); void ValueChangedInSpinBox(); void CreateCopyModeChanged(bool isCreateCopy); + void ConstructorsClicked(int constructorId); void onReverse(); }; -- 2.39.2