From d72b7ebbff5ac4553ae464dafb864255efe4b8f7 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 10 Jul 2008 12:19:34 +0000 Subject: [PATCH] Improvement 0019703: deform (scale along axes) a shape. --- doc/salome/gui/GEOM/input/scale_operation.doc | 14 +- doc/salome/gui/GEOM/input/tui_test_all.doc | 6 + idl/GEOM_Gen.idl | 53 +- idl/GEOM_Superv.idl | 10 + resources/Makefile.am | 1 + resources/scale_along_axes.png | Bin 0 -> 513 bytes src/BasicGUI/BasicGUI_CurveDlg.cxx | 97 ++-- src/GEOMGUI/GEOM_images.po | 4 + src/GEOMGUI/GEOM_msg_en.po | 9 + src/GEOMImpl/GEOMImpl_IScale.hxx | 10 + .../GEOMImpl_ITransformOperations.cxx | 102 +++- .../GEOMImpl_ITransformOperations.hxx | 124 +++-- src/GEOMImpl/GEOMImpl_ScaleDriver.cxx | 76 ++- src/GEOMImpl/GEOMImpl_Types.hxx | 2 + src/GEOM_I/GEOM_ITransformOperations_i.cc | 120 +++- src/GEOM_I/GEOM_ITransformOperations_i.hh | 12 + src/GEOM_I_Superv/GEOM_Superv_i.cc | 36 ++ src/GEOM_I_Superv/GEOM_Superv_i.hh | 10 + src/GEOM_SWIG/GEOM_TestAll.py | 26 +- src/GEOM_SWIG/geompyDC.py | 24 +- .../TransformationGUI_ScaleDlg.cxx | 521 ++++++++++++------ .../TransformationGUI_ScaleDlg.h | 52 +- 22 files changed, 972 insertions(+), 337 deletions(-) create mode 100644 resources/scale_along_axes.png diff --git a/doc/salome/gui/GEOM/input/scale_operation.doc b/doc/salome/gui/GEOM/input/scale_operation.doc index 236940231..9e13ba52b 100644 --- a/doc/salome/gui/GEOM/input/scale_operation.doc +++ b/doc/salome/gui/GEOM/input/scale_operation.doc @@ -7,13 +7,23 @@ \n This operation creates a scaled shape basing on the initial shape. For this, you need to define the \b Shape to be scaled, the -Central Point of scale and the Scale Factor. +Central Point of scale and the Scale Factor(s). \n The \b Result will be a \b GEOM_Object. \n TUI Command: geompy.MakeScaleTransform(Shape, CenterOfScale, Factor) \n Arguments: Name + 1 shape(s) + 1 vertex + 1 Scale Factor. +\n TUI Command: geompy.MakeScaleAlongAxes(Shape, CenterOfScale, FactorX, FactorY, FactorZ) +\n Arguments: Name + 1 shape(s) + 1 vertex + 3 Scale Factors. \n Advanced option: \ref restore_presentation_parameters_page "Set presentation parameters and subshapes from arguments". +\note If Central Point is not defined, the scaling will be +performed relatively the origin of global coordinate system. + +\note Scaling by a factor is a simple transformation, it does not modify +geometry of the shape, while scaling by different factors along axes +is a general transformation, which can modify geometry, for example, a +circle can be transformed into an ellipse. + \image html transformation10.png \n Example: @@ -23,6 +33,6 @@ shape. For this, you need to define the \b Shape to be scaled, the \image html scale_transformsn2.png Our TUI Scripts provide you with useful examples of the use of -\ref tui_scale "Transformation Operations". +\ref tui_scale "Scale Transformation" and of \ref swig_scale "Scale Along Axes Transformation" */ diff --git a/doc/salome/gui/GEOM/input/tui_test_all.doc b/doc/salome/gui/GEOM/input/tui_test_all.doc index 209b2b231..caeae7be8 100644 --- a/doc/salome/gui/GEOM/input/tui_test_all.doc +++ b/doc/salome/gui/GEOM/input/tui_test_all.doc @@ -43,6 +43,12 @@ \until MakeSewing \anchor swig_all_trsf +\until RotatPnt + +\anchor swig_scale +\until Scale4 + +\anchor swig_all_trsf_more \until MakeOffset \anchor swig_ChangeOrientation diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 21e36cd84..26a9368dc 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -11,8 +11,8 @@ // 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 +// 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 @@ -36,7 +36,7 @@ module GEOM * Topological types of shapes (like Open Cascade types) */ enum shape_type { COMPOUND, COMPSOLID, SOLID, SHELL, - FACE, WIRE, EDGE, VERTEX, SHAPE }; + FACE, WIRE, EDGE, VERTEX, SHAPE }; /*! @@ -332,13 +332,13 @@ module GEOM */ GEOM_Object MakePointOnLinesIntersection (in GEOM_Object theRefLine1, in GEOM_Object theRefLine2); - + /*! * Create a vector, corresponding to tangent to the given parameter on the given curve. * \param theRefCurve The referenced curve. * \param theParameter Value of parameter on the referenced curve.This value should be have value * \between 0. and 1.. Value of 0. corresponds first parameter of curve value 1. corresponds - * \last parameter of curve. + * \last parameter of curve. * \return New GEOM_Object, containing the created point. */ GEOM_Object MakeTangentOnCurve (in GEOM_Object theRefCurve, @@ -432,11 +432,11 @@ module GEOM GEOM_Object MakeMarker (in double theOX , in double theOY , in double theOZ, in double theXDX, in double theXDY, in double theXDZ, in double theYDX, in double theYDY, in double theYDZ); - + /*! * Create a tangent plane to specified face in the point with specified parameters. * Values of parameters should be between 0. and 1.0 - * \param theFace - face for which tangent plane shuold be built. + * \param theFace - face for which tangent plane shuold be built. * \param theParameterU - value of parameter by U * \param theParameterV - value of parameter Vthe * \param theTrimSize - defines sizes of created face @@ -735,6 +735,33 @@ module GEOM GEOM_Object ScaleShapeCopy (in GEOM_Object theObject, in GEOM_Object thePoint, in double theFactor); + /*! + * Scale the given object by different factors along coordinate axes. + * \param theObject The object to be scaled. + * \param thePoint Center point for scaling. + * \param theFactorX,theFactorY,theFactorZ Scaling factors along each axis. + * \return theObject. + */ + GEOM_Object ScaleShapeAlongAxes (in GEOM_Object theObject, + in GEOM_Object thePoint, + in double theFactorX, + in double theFactorY, + in double theFactorZ); + + /*! + * Scale the given object by different factors along coordinate axes, + * creating its copy before the scaling. + * \param theObject The object to be scaled. + * \param thePoint Center point for scaling. + * \param theFactorX,theFactorY,theFactorZ Scaling factors along each axis. + * \return New GEOM_Object, containing the scaled shape. + */ + GEOM_Object ScaleShapeAlongAxesCopy (in GEOM_Object theObject, + in GEOM_Object thePoint, + in double theFactorX, + in double theFactorY, + in double theFactorZ); + /*! * Modify the Location of the given object by LCS. * \param theObject The object to be displaced. @@ -989,7 +1016,7 @@ module GEOM in GEOM_Object thePath, in boolean theWithContact , in boolean theWithCorrection ); - + /*! * Create a shape by extrusion of the profile shape along * the path shape. The path shape can be a shell or a face. @@ -1323,7 +1350,7 @@ module GEOM in long theShapeType, in GEOM_Object theAx1, in shape_state theState); - + /*! * Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively * the specified plane by the certain way, defined through \a theState parameter. @@ -1331,7 +1358,7 @@ module GEOM * \param theShapeType Type of sub-shapes to be retrieved. * \param theAx1 Vector (or line, or linear edge), specifying normal * direction of the plane to find shapes on. - * \param thePnt Point specifying location of the plane to find shapes on. + * \param thePnt Point specifying location of the plane to find shapes on. * \param theState The state of the subshapes to find. * \return List of IDs of all found sub-shapes. */ @@ -2128,7 +2155,7 @@ module GEOM GEOM_Object MakeChamferEdge (in GEOM_Object theShape, in double theD1, in double theD2, in long theFace1, in long theFace2); - /*! + /*! * The Same but with params theD = Chamfer Lenght * and theAngle = Chamfer Angle (Angle in radians) */ @@ -2152,7 +2179,7 @@ module GEOM GEOM_Object MakeChamferFaces (in GEOM_Object theShape, in double theD1, in double theD2, in ListOfLong theFaces); - /*! + /*! * The Same but with params theD = Chamfer Lenght * and theAngle = Chamfer Angle (Angle in radians) */ @@ -2171,7 +2198,7 @@ module GEOM GEOM_Object MakeChamferEdges (in GEOM_Object theShape, in double theD1, in double theD2, in ListOfLong theEdges); - /*! + /*! * The Same but with params theD = Chamfer Lenght * and theAngle = Chamfer Angle (Angle in radians) */ diff --git a/idl/GEOM_Superv.idl b/idl/GEOM_Superv.idl index a19c8cd9c..d0f2f4034 100644 --- a/idl/GEOM_Superv.idl +++ b/idl/GEOM_Superv.idl @@ -309,6 +309,16 @@ module GEOM GEOM_Object ScaleShapeCopy (in GEOM_Object theObject, in GEOM_Object thePoint, in double theFactor) ; + GEOM_Object ScaleShapeAlongAxes (in GEOM_Object theObject, + in GEOM_Object thePoint, + in double theFactorX, + in double theFactorY, + in double theFactorZ); + GEOM_Object ScaleShapeAlongAxesCopy (in GEOM_Object theObject, + in GEOM_Object thePoint, + in double theFactorX, + in double theFactorY, + in double theFactorZ); GEOM_Object PositionShape (in GEOM_Object theObject, in GEOM_Object theStartLCS, in GEOM_Object theEndLCS) ; diff --git a/resources/Makefile.am b/resources/Makefile.am index b626ff86d..cce9daad6 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -127,6 +127,7 @@ revol.png \ rotate.png \ rotatepnt.png \ scale.png \ +scale_along_axes.png \ section.png \ select1.png \ sewing.png \ diff --git a/resources/scale_along_axes.png b/resources/scale_along_axes.png new file mode 100644 index 0000000000000000000000000000000000000000..06a38911c0e0ee7d96ae12e685e5560c77bc2dba GIT binary patch literal 513 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VXMsm#F#`j)FbFd;%$g$s6l6(v z^mSxl*w|O|J8&|PuaN8!lzDUUYGe0~n0<#h z(i}of{dXT};JuRevhn5G+1reOO70x^@1geo>eavRYknHtFmQ8o+tapCnoGdJhsTA% zsZDV;BZtBw9u-!g(yP2I911+ljt|>?CUY?`aman#kini9u&Hq)r>b}fkAOo&vZU;q z=>6~h|2BUw8Mmj>@j@*F;}NE010#b+AzP-VYBQ_zt2eU<2r&VLoqSdl6ciY6FerAY zu>eg|&Tc%+>t5!uYxBxu_NfhXzIlTk*4ktL0P90Hce+)78&qol`;+0Gfcc=>Px# literal 0 HcmV?d00001 diff --git a/src/BasicGUI/BasicGUI_CurveDlg.cxx b/src/BasicGUI/BasicGUI_CurveDlg.cxx index 49d8bf5cc..33f3c9f44 100644 --- a/src/BasicGUI/BasicGUI_CurveDlg.cxx +++ b/src/BasicGUI/BasicGUI_CurveDlg.cxx @@ -294,56 +294,57 @@ void BasicGUI_CurveDlg::SelectionIntoArgument() SALOME_ListIO selected; aSelMgr->selectedObjects( selected, QString::null, false ); - for ( SALOME_ListIteratorOfListIO anIt( selected ); anIt.More(); anIt.Next() ) + for (SALOME_ListIteratorOfListIO anIt (selected); anIt.More(); anIt.Next()) + { + GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes ); + + if (!CORBA::is_nil(aSelectedObject) && aRes) { - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value(), aRes ); - - if ( !CORBA::is_nil( aSelectedObject ) && aRes ) - { - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) - { - aSelMgr->GetIndexes( anIt.Value(), aMapIndexes ); - - if ( aMapIndexes.Extent() > 0 ) - { - for (int ii=1; ii <= aMapIndexes.Extent(); ii++) { - anIndex = aMapIndexes(ii); - QString aName = GEOMBase::GetName( aSelectedObject ); - aName = aName + ":vertex_" + QString::number( anIndex ); - anObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); - //Find Object in study - _PTR(SObject) obj ( aDStudy->FindObjectID( anIt.Value()->getEntry() ) ); - bool inStudy = false; - for (_PTR(ChildIterator) iit (aDStudy->NewChildIterator(obj)); iit->More(); iit->Next()) { - _PTR(SObject) child (iit->Value()); - QString aChildName = child->GetName(); - if (aChildName == aName) { - inStudy = true; - CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value()); - anObject = GEOM::GEOM_Object::_narrow( corbaObj ); - } - } - - if (!inStudy) - GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy), - anObject, aName, aSelectedObject); - - int pos = isPointInList(myOrderedSel, anObject); - if (pos==-1) { - myOrderedSel.push_back(anObject); - } - // if (!inStudy) - aList.push_back(anObject); - } - } else { // aMap.Extent() == 0 - int pos = isPointInList(myOrderedSel,aSelectedObject); - if(pos==-1) - myOrderedSel.push_back(aSelectedObject); - aList.push_back(aSelectedObject); - } - } - } + if (GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull()) + { + aSelMgr->GetIndexes( anIt.Value(), aMapIndexes ); + + if (aMapIndexes.Extent() > 0) + { + for (int ii=1; ii <= aMapIndexes.Extent(); ii++) { + anIndex = aMapIndexes(ii); + QString aName = GEOMBase::GetName( aSelectedObject ); + aName = aName + ":vertex_" + QString::number( anIndex ); + anObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); + //Find Object in study + _PTR(SObject) obj ( aDStudy->FindObjectID( anIt.Value()->getEntry() ) ); + bool inStudy = false; + _PTR(ChildIterator) iit (aDStudy->NewChildIterator(obj)); + for (; iit->More() && !inStudy; iit->Next()) { + _PTR(SObject) child (iit->Value()); + QString aChildName = child->GetName(); + if (aChildName == aName) { + inStudy = true; + CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(iit->Value()); + anObject = GEOM::GEOM_Object::_narrow( corbaObj ); + } + } + + if (!inStudy) + GeometryGUI::GetGeomGen()->AddInStudy(GeometryGUI::ClientStudyToStudy(aDStudy), + anObject, aName, aSelectedObject); + + int pos = isPointInList(myOrderedSel, anObject); + if (pos==-1) { + myOrderedSel.push_back(anObject); + } + // if (!inStudy) + aList.push_back(anObject); + } + } else { // aMap.Extent() == 0 + int pos = isPointInList(myOrderedSel,aSelectedObject); + if (pos==-1) + myOrderedSel.push_back(aSelectedObject); + aList.push_back(aSelectedObject); + } + } } + } myPoints->length( aList.size() ); diff --git a/src/GEOMGUI/GEOM_images.po b/src/GEOMGUI/GEOM_images.po index d98a54226..475db68ab 100644 --- a/src/GEOMGUI/GEOM_images.po +++ b/src/GEOMGUI/GEOM_images.po @@ -331,6 +331,10 @@ msgstr "rotatepnt.png" msgid "ICON_DLG_SCALE" msgstr "scale.png" +#ScaleDlg +msgid "ICON_DLG_SCALE_ALONG_AXES" +msgstr "scale_along_axes.png" + #OffsetDlg msgid "ICON_DLG_OFFSET" msgstr "offset.png" diff --git a/src/GEOMGUI/GEOM_msg_en.po b/src/GEOMGUI/GEOM_msg_en.po index 9d252109d..500ae02b0 100644 --- a/src/GEOMGUI/GEOM_msg_en.po +++ b/src/GEOMGUI/GEOM_msg_en.po @@ -1280,6 +1280,15 @@ msgstr "Offset Surface" msgid "GEOM_SCALE_FACTOR" msgstr "Scale Factor :" +msgid "GEOM_SCALE_FACTOR_X" +msgstr "Scale Factor X :" + +msgid "GEOM_SCALE_FACTOR_Y" +msgstr "Scale Factor Y :" + +msgid "GEOM_SCALE_FACTOR_Z" +msgstr "Scale Factor Z :" + #: GeometryGUI_SectionDlg.cxx:50 msgid "GEOM_SECTION_TITLE" msgstr "BOOLEAN : Section Of Two Objects" diff --git a/src/GEOMImpl/GEOMImpl_IScale.hxx b/src/GEOMImpl/GEOMImpl_IScale.hxx index 9a7e904a2..e2bad90e6 100644 --- a/src/GEOMImpl/GEOMImpl_IScale.hxx +++ b/src/GEOMImpl/GEOMImpl_IScale.hxx @@ -25,6 +25,8 @@ #define SCALE_ARG_SHAPE 1 #define SCALE_ARG_VALUE 2 #define SCALE_ARG_POINT 3 +#define SCALE_ARG_VALUE_Y 4 +#define SCALE_ARG_VALUE_Z 5 class GEOMImpl_IScale { @@ -44,6 +46,14 @@ class GEOMImpl_IScale Handle(GEOM_Function) GetPoint() { return _func->GetReference(SCALE_ARG_POINT); } + void SetFactorX(double theValue) { _func->SetReal(SCALE_ARG_VALUE , theValue); } + void SetFactorY(double theValue) { _func->SetReal(SCALE_ARG_VALUE_Y, theValue); } + void SetFactorZ(double theValue) { _func->SetReal(SCALE_ARG_VALUE_Z, theValue); } + + double GetFactorX() { return _func->GetReal(SCALE_ARG_VALUE ); } + double GetFactorY() { return _func->GetReal(SCALE_ARG_VALUE_Y); } + double GetFactorZ() { return _func->GetReal(SCALE_ARG_VALUE_Z); } + private: Handle(GEOM_Function) _func; diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx index 19bd62a1f..957197365 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.cxx @@ -1030,14 +1030,11 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape { SetErrorCode(KO); - if (theObject.IsNull() || thePoint.IsNull()) return NULL; + if (theObject.IsNull()) return NULL; Handle(GEOM_Function) anOriginal = theObject->GetLastFunction(); if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled - // Get last functions of the arguments - Handle(GEOM_Function) aPF = thePoint->GetLastFunction(); - //Add a scale function Handle(GEOM_Function) aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE); @@ -1046,11 +1043,17 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShape //Check if the function is set correctly if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL; + // Set arguments GEOMImpl_IScale aTI (aFunction); aTI.SetShape(anOriginal); - aTI.SetPoint(aPF); aTI.SetFactor(theFactor); + // Set point argument + if (!thePoint.IsNull()) { + Handle(GEOM_Function) aPF = thePoint->GetLastFunction(); + aTI.SetPoint(aPF); + } + //Compute the scale try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 @@ -1085,7 +1088,7 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy { SetErrorCode(KO); - if (theObject.IsNull() || thePoint.IsNull()) return NULL; + if (theObject.IsNull()) return NULL; Handle(GEOM_Function) anOriginal = theObject->GetLastFunction(); if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled @@ -1101,11 +1104,17 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy //Check if the function is set correctly if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL; + // Set arguments GEOMImpl_IScale aTI (aFunction); aTI.SetShape(anOriginal); - aTI.SetPoint(thePoint->GetLastFunction()); aTI.SetFactor(theFactor); + // Set point argument + if (!thePoint.IsNull()) { + Handle(GEOM_Function) aPF = thePoint->GetLastFunction(); + aTI.SetPoint(aPF); + } + //Compute the scale try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 @@ -1130,6 +1139,85 @@ Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeCopy return aCopy; } +//============================================================================= +/*! + * ScaleShapeAlongAxes + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_ITransformOperations::ScaleShapeAlongAxes (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) thePoint, + double theFactorX, + double theFactorY, + double theFactorZ, + bool doCopy) +{ + SetErrorCode(KO); + + if (theObject.IsNull()) return NULL; + + Handle(GEOM_Function) anOriginal = theObject->GetLastFunction(); + if (anOriginal.IsNull()) return NULL; //There is no function which creates an object to be scaled + + //Add a scale function + Handle(GEOM_Object) aCopy; //Add a new Copy object + Handle(GEOM_Function) aFunction; + if (doCopy) { + aCopy = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + aFunction = aCopy->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES_COPY); + } + else { + aFunction = theObject->AddFunction(GEOMImpl_ScaleDriver::GetID(), SCALE_SHAPE_AXES); + } + if (aFunction.IsNull()) return NULL; + + //Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_ScaleDriver::GetID()) return NULL; + + // Set arguments + GEOMImpl_IScale aTI (aFunction); + aTI.SetShape(anOriginal); + aTI.SetFactorX(theFactorX); + aTI.SetFactorY(theFactorY); + aTI.SetFactorZ(theFactorZ); + + // Set point (optional argument) + if (!thePoint.IsNull()) { + Handle(GEOM_Function) aPF = thePoint->GetLastFunction(); + aTI.SetPoint(aPF); + } + + //Compute the scale + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Scale driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + SetErrorCode(OK); + + //Make a Python command + if (doCopy) { + GEOM::TPythonDump(aFunction) << "geompy.MakeScaleAlongAxes(" + << theObject << ", " << thePoint << ", " + << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")"; + return aCopy; + } + + GEOM::TPythonDump(aFunction) << "geompy.TrsfOp.ScaleShapeAlongAxes(" + << theObject << ", " << thePoint << ", " + << theFactorX << ", " << theFactorY << ", " << theFactorZ << ")"; + return theObject; +} + //============================================================================= /*! * PositionShape diff --git a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx index ad2a6f510..c949641aa 100644 --- a/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_ITransformOperations.hxx @@ -27,99 +27,125 @@ #include "GEOM_Object.hxx" #include -class GEOMImpl_ITransformOperations : public GEOM_IOperations { +class GEOMImpl_ITransformOperations : public GEOM_IOperations +{ public: Standard_EXPORT GEOMImpl_ITransformOperations(GEOM_Engine* theEngine, int theDocID); Standard_EXPORT ~GEOMImpl_ITransformOperations(); Standard_EXPORT Handle(GEOM_Object) TranslateTwoPoints (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2); + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2); Standard_EXPORT Handle(GEOM_Object) TranslateTwoPointsCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2); + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2); - Standard_EXPORT Handle(GEOM_Object) TranslateDXDYDZ (Handle(GEOM_Object) theObject, double theX, double theY, double theZ); + Standard_EXPORT Handle(GEOM_Object) TranslateDXDYDZ (Handle(GEOM_Object) theObject, + double theX, double theY, double theZ); - Standard_EXPORT Handle(GEOM_Object) TranslateDXDYDZCopy (Handle(GEOM_Object) theObject, double theX, double theY, double theZ); + Standard_EXPORT Handle(GEOM_Object) TranslateDXDYDZCopy (Handle(GEOM_Object) theObject, + double theX, double theY, double theZ); Standard_EXPORT Handle(GEOM_Object) TranslateVector (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theVector); + Handle(GEOM_Object) theVector); Standard_EXPORT Handle(GEOM_Object) TranslateVectorCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theVector); + Handle(GEOM_Object) theVector); Standard_EXPORT Handle(GEOM_Object) TranslateVectorDistance (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theVector, double theDistance, bool theCopy); - - Standard_EXPORT Handle(GEOM_Object) Translate1D (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theStep, Standard_Integer theNbTimes); - - Standard_EXPORT Handle(GEOM_Object) Translate2D (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theVector, double theStep1, Standard_Integer theNbTimes1, - Handle(GEOM_Object) theVector2, double theStep2, Standard_Integer theNbTimes2); + Handle(GEOM_Object) theVector, + double theDistance, + bool theCopy); + + Standard_EXPORT Handle(GEOM_Object) Translate1D (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theVector, + double theStep, + Standard_Integer theNbTimes); + + Standard_EXPORT Handle(GEOM_Object) Translate2D (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theVector, + double theStep1, + Standard_Integer theNbTimes1, + Handle(GEOM_Object) theVector2, + double theStep2, + Standard_Integer theNbTimes2); Standard_EXPORT Handle(GEOM_Object) MirrorPlane (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePlane); + Handle(GEOM_Object) thePlane); Standard_EXPORT Handle(GEOM_Object) MirrorPlaneCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePlane); + Handle(GEOM_Object) thePlane); Standard_EXPORT Handle(GEOM_Object) MirrorAxis (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theAxis); + Handle(GEOM_Object) theAxis); Standard_EXPORT Handle(GEOM_Object) MirrorAxisCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theAxis); + Handle(GEOM_Object) theAxis); Standard_EXPORT Handle(GEOM_Object) MirrorPoint (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint); + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) MirrorPointCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint); + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) OffsetShape (Handle(GEOM_Object) theObject, - double theOffset); + double theOffset); Standard_EXPORT Handle(GEOM_Object) OffsetShapeCopy (Handle(GEOM_Object) theObject, - double theOffset); + double theOffset); Standard_EXPORT Handle(GEOM_Object) ScaleShape (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint, - double theFactor); + Handle(GEOM_Object) thePoint, + double theFactor); Standard_EXPORT Handle(GEOM_Object) ScaleShapeCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) thePoint, - double theFactor); + Handle(GEOM_Object) thePoint, + double theFactor); + + Standard_EXPORT Handle(GEOM_Object) ScaleShapeAlongAxes (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) thePoint, + double theFactorX, + double theFactorY, + double theFactorZ, + bool doCopy); Standard_EXPORT Handle(GEOM_Object) PositionShape (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theStartLCS, - Handle(GEOM_Object) theEndLCS); + Handle(GEOM_Object) theStartLCS, + Handle(GEOM_Object) theEndLCS); Standard_EXPORT Handle(GEOM_Object) PositionShapeCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theStartLCS, - Handle(GEOM_Object) theEndLCS); + Handle(GEOM_Object) theStartLCS, + Handle(GEOM_Object) theEndLCS); + + Standard_EXPORT Handle(GEOM_Object) Rotate (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theAxis, + double theAngle); - Standard_EXPORT Handle(GEOM_Object) Rotate (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle); + Standard_EXPORT Handle(GEOM_Object) RotateCopy (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theAxis, + double theAngle); - Standard_EXPORT Handle(GEOM_Object) RotateCopy (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, double theAngle); + Standard_EXPORT Handle(GEOM_Object) Rotate1D (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theAxis, + Standard_Integer theNbTimes); - Standard_EXPORT Handle(GEOM_Object) Rotate1D (Handle(GEOM_Object) theObject, Handle(GEOM_Object) theAxis, Standard_Integer theNbTimes); - - Standard_EXPORT Handle(GEOM_Object) Rotate2D (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theAxis, - double theAngle, - Standard_Integer theNbTimes1, - double theStep, - Standard_Integer theNbTimes2); + Standard_EXPORT Handle(GEOM_Object) Rotate2D (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theAxis, + double theAngle, + Standard_Integer theNbTimes1, + double theStep, + Standard_Integer theNbTimes2); Standard_EXPORT Handle(GEOM_Object) RotateThreePoints (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theCentPoint, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2); - - Standard_EXPORT Handle(GEOM_Object) RotateThreePointsCopy (Handle(GEOM_Object) theObject, - Handle(GEOM_Object) theCentPoint, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2); + Handle(GEOM_Object) theCentPoint, + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2); + + Standard_EXPORT Handle(GEOM_Object) RotateThreePointsCopy (Handle(GEOM_Object) theObject, + Handle(GEOM_Object) theCentPoint, + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2); }; diff --git a/src/GEOMImpl/GEOMImpl_ScaleDriver.cxx b/src/GEOMImpl/GEOMImpl_ScaleDriver.cxx index 88342f057..8dc4967d2 100644 --- a/src/GEOMImpl/GEOMImpl_ScaleDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_ScaleDriver.cxx @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,8 @@ #include #include +#include +#include //======================================================================= //function : GetID @@ -73,11 +76,17 @@ Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); - Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); - TopoDS_Shape aShapePnt = aRefPoint->GetValue(); - if (aShapeBase.IsNull() || aShapePnt.IsNull()) return 0; - if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; + if (aShapeBase.IsNull()) return 0; + + gp_Pnt aP (0,0,0); + Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); + if (!aRefPoint.IsNull()) { + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.IsNull()) return 0; + if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; + aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + } // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; @@ -94,12 +103,67 @@ Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const } // Perform Scaling - gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); gp_Trsf aTrsf; aTrsf.SetScale(aP, aCI.GetFactor()); BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False); aShape = aBRepTrsf.Shape(); - } else { + } + else if (aType == SCALE_SHAPE_AXES || aType == SCALE_SHAPE_AXES_COPY) { + Handle(GEOM_Function) aRefShape = aCI.GetShape(); + TopoDS_Shape aShapeBase = aRefShape->GetValue(); + if (aShapeBase.IsNull()) return 0; + + bool isP = false; + gp_Pnt aP (0,0,0); + Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); + if (!aRefPoint.IsNull()) { + TopoDS_Shape aShapePnt = aRefPoint->GetValue(); + if (aShapePnt.IsNull()) return 0; + if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; + aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); + isP = true; + } + + // Bug 6839: Check for standalone (not included in faces) degenerated edges + TopTools_IndexedDataMapOfShapeListOfShape aEFMap; + TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); + Standard_Integer i, nbE = aEFMap.Extent(); + for (i = 1; i <= nbE; i++) { + TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); + if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { + const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); + if (aFaces.IsEmpty()) + Standard_ConstructionError::Raise + ("Scaling aborted : cannot scale standalone degenerated edge"); + } + } + + // Perform Scaling + gp_GTrsf aGTrsf; + gp_Mat rot (aCI.GetFactorX(), 0, 0, + 0, aCI.GetFactorY(), 0, + 0, 0, aCI.GetFactorZ()); + aGTrsf.SetVectorialPart(rot); + + if (isP) { + gp_Pnt anO (0,0,0); + if (anO.Distance(aP) > Precision::Confusion()) { + gp_GTrsf aGTrsfP0; + aGTrsfP0.SetTranslationPart(anO.XYZ() - aP.XYZ()); + gp_GTrsf aGTrsf0P; + aGTrsf0P.SetTranslationPart(aP.XYZ()); + //aGTrsf = aGTrsf0P * aGTrsf * aGTrsfP0; + aGTrsf = aGTrsf0P.Multiplied(aGTrsf); + aGTrsf = aGTrsf.Multiplied(aGTrsfP0); + } + } + + BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False); + if (!aBRepGTrsf.IsDone()) + Standard_ConstructionError::Raise("Scaling not done"); + aShape = aBRepGTrsf.Shape(); + } + else { } if (aShape.IsNull()) return 0; diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index 987315159..54b156448 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -144,6 +144,8 @@ #define SCALE_SHAPE 1 #define SCALE_SHAPE_COPY 2 +#define SCALE_SHAPE_AXES 3 +#define SCALE_SHAPE_AXES_COPY 4 #define POSITION_SHAPE 1 #define POSITION_SHAPE_COPY 2 diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.cc b/src/GEOM_I/GEOM_ITransformOperations_i.cc index 589c892ec..1dff38932 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.cc +++ b/src/GEOM_I/GEOM_ITransformOperations_i.cc @@ -310,9 +310,9 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::TranslateVectorDistance { GEOM::GEOM_Object_var aGEOMObject; GetOperations()->SetNotDone(); //Set a not done flag - + if (theObject == NULL || theVector == NULL) return aGEOMObject._retn(); - + //check if the object is a subshape if (!theCopy && !theObject->IsMainShape()) { GetOperations()->SetErrorCode(SUBSHAPE_ERROR); @@ -728,14 +728,14 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::OffsetShapeCopy GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShape (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr thePoint, - CORBA::Double theFactor) + CORBA::Double theFactor) { GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject); //Set a not done flag GetOperations()->SetNotDone(); - if (thePoint == NULL || theObject == NULL) return aGEOMObject._retn(); + if (theObject->_is_nil()) return aGEOMObject._retn(); //check if the object is a subshape if (!theObject->IsMainShape()) { @@ -750,10 +750,12 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShape if (anObject.IsNull()) return aGEOMObject._retn(); //Get the point - CORBA::String_var aPntEntry = thePoint->GetEntry(); - Handle(GEOM_Object) aPoint = - GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); - if (aPoint.IsNull()) return aGEOMObject._retn(); + Handle(GEOM_Object) aPoint; + if (!thePoint->_is_nil()) { + CORBA::String_var aPntEntry = thePoint->GetEntry(); + aPoint = GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); + if (aPoint.IsNull()) return aGEOMObject._retn(); + } //Perform the scale GetOperations()->ScaleShape(anObject, aPoint, theFactor); @@ -769,14 +771,14 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShape GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeCopy (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr thePoint, - CORBA::Double theFactor) + CORBA::Double theFactor) { GEOM::GEOM_Object_var aGEOMObject; //Set a not done flag GetOperations()->SetNotDone(); - if (thePoint == NULL || theObject == NULL) return aGEOMObject._retn(); + if (theObject->_is_nil()) return aGEOMObject._retn(); //Get the basic object CORBA::String_var anEntry = theObject->GetEntry(); @@ -785,10 +787,12 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeCopy if (aBasicObject.IsNull()) return aGEOMObject._retn(); //Get the point - CORBA::String_var aPntEntry = thePoint->GetEntry(); - Handle(GEOM_Object) aPoint = - GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); - if (aPoint.IsNull()) return aGEOMObject._retn(); + Handle(GEOM_Object) aPoint; + if (!thePoint->_is_nil()) { + CORBA::String_var aPntEntry = thePoint->GetEntry(); + aPoint = GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); + if (aPoint.IsNull()) return aGEOMObject._retn(); + } //Perform the scale Handle(GEOM_Object) anObject = @@ -799,6 +803,94 @@ GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeCopy return GetObject(anObject); } +//============================================================================= +/*! + * ScaleShapeAlongAxes + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeAlongAxes + (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ) +{ + GEOM::GEOM_Object_var aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject); + + //Set a not done flag + GetOperations()->SetNotDone(); + + if (theObject->_is_nil()) return aGEOMObject._retn(); + + //check if the object is a subshape + if (!theObject->IsMainShape()) { + GetOperations()->SetErrorCode(SUBSHAPE_ERROR); + return aGEOMObject._retn(); + } + + //Get the object itself + CORBA::String_var anEntry = theObject->GetEntry(); + Handle(GEOM_Object) anObject = + GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), anEntry); + if (anObject.IsNull()) return aGEOMObject._retn(); + + //Get the point + Handle(GEOM_Object) aPoint; + if (!thePoint->_is_nil()) { + CORBA::String_var aPntEntry = thePoint->GetEntry(); + aPoint = GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); + if (aPoint.IsNull()) return aGEOMObject._retn(); + } + + //Perform the scale + GetOperations()->ScaleShapeAlongAxes + (anObject, aPoint, theFactorX, theFactorY, theFactorZ, /*doCopy*/false); + + return aGEOMObject._retn(); +} + +//============================================================================= +/*! + * ScaleShapeAlongAxesCopy + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_ITransformOperations_i::ScaleShapeAlongAxesCopy + (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ) +{ + GEOM::GEOM_Object_var aGEOMObject; + + //Set a not done flag + GetOperations()->SetNotDone(); + + if (theObject->_is_nil()) return aGEOMObject._retn(); + + //Get the basic object + CORBA::String_var anEntry = theObject->GetEntry(); + Handle(GEOM_Object) aBasicObject = + GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), anEntry); + if (aBasicObject.IsNull()) return aGEOMObject._retn(); + + //Get the point + Handle(GEOM_Object) aPoint; + if (!thePoint->_is_nil()) { + CORBA::String_var aPntEntry = thePoint->GetEntry(); + aPoint = GetOperations()->GetEngine()->GetObject(thePoint->GetStudyID(), aPntEntry); + if (aPoint.IsNull()) return aGEOMObject._retn(); + } + + //Perform the scale + Handle(GEOM_Object) anObject = GetOperations()->ScaleShapeAlongAxes + (aBasicObject, aPoint, theFactorX, theFactorY, theFactorZ, /*doCopy*/true); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * PositionShape diff --git a/src/GEOM_I/GEOM_ITransformOperations_i.hh b/src/GEOM_I/GEOM_ITransformOperations_i.hh index 87b375c12..848e5077b 100644 --- a/src/GEOM_I/GEOM_ITransformOperations_i.hh +++ b/src/GEOM_I/GEOM_ITransformOperations_i.hh @@ -121,6 +121,18 @@ class GEOM_I_EXPORT GEOM_ITransformOperations_i : GEOM::GEOM_Object_ptr thePoint, CORBA::Double theFactor); + GEOM::GEOM_Object_ptr ScaleShapeAlongAxes (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ); + + GEOM::GEOM_Object_ptr ScaleShapeAlongAxesCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ); + GEOM::GEOM_Object_ptr PositionShape (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theStartLCS, GEOM::GEOM_Object_ptr theEndLCS); diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 85cea16c1..461ef2d96 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -1634,6 +1634,42 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::ScaleShapeCopy (GEOM::GEOM_Object_ptr theOb return anObj; } +//============================================================================= +// ScaleShapeAlongAxes: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::ScaleShapeAlongAxes (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ) +{ + beginService( " GEOM_Superv_i::ScaleShapeAlongAxes" ); + MESSAGE("GEOM_Superv_i::ScaleShapeAlongAxes"); + getTransfOp(); + GEOM::GEOM_Object_ptr anObj = myTransfOp->ScaleShapeAlongAxes + (theObject, thePoint, theFactorX, theFactorY, theFactorZ); + endService( " GEOM_Superv_i::ScaleShapeAlongAxes" ); + return anObj; +} + +//============================================================================= +// ScaleShapeAlongAxesCopy: +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_Superv_i::ScaleShapeAlongAxesCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ) +{ + beginService( " GEOM_Superv_i::ScaleShapeAlongAxesCopy" ); + MESSAGE("GEOM_Superv_i::ScaleShapeAlongAxesCopy"); + getTransfOp(); + GEOM::GEOM_Object_ptr anObj = myTransfOp->ScaleShapeAlongAxesCopy + (theObject, thePoint, theFactorX, theFactorY, theFactorZ); + endService( " GEOM_Superv_i::ScaleShapeAlongAxesCopy" ); + return anObj; +} + //============================================================================= // PositionShape: //============================================================================= diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index 4a49ebac9..bdeadb12d 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -377,6 +377,16 @@ public: GEOM::GEOM_Object_ptr ScaleShapeCopy (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr thePoint, CORBA::Double theFactor); + GEOM::GEOM_Object_ptr ScaleShapeAlongAxes (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ); + GEOM::GEOM_Object_ptr ScaleShapeAlongAxesCopy (GEOM::GEOM_Object_ptr theObject, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Double theFactorX, + CORBA::Double theFactorY, + CORBA::Double theFactorZ); GEOM::GEOM_Object_ptr PositionShape (GEOM::GEOM_Object_ptr theObject, GEOM::GEOM_Object_ptr theStartLCS, GEOM::GEOM_Object_ptr theEndLCS); diff --git a/src/GEOM_SWIG/GEOM_TestAll.py b/src/GEOM_SWIG/GEOM_TestAll.py index e4125406d..46fb32260 100644 --- a/src/GEOM_SWIG/GEOM_TestAll.py +++ b/src/GEOM_SWIG/GEOM_TestAll.py @@ -184,12 +184,21 @@ def TestAll (geompy, math): TranslVectD = geompy.MakeTranslationVectorDistance(Box, vxyz, 50.0) #(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 + + #Scale by factor relatively given point + Scale1 = geompy.MakeScaleTransform(Box, pxyz, factor) #(2 GEOM_Object_ptr, Double)->GEOM_Object_ptr + #Scale by factor relatively the origin of global CS + Scale2 = geompy.MakeScaleTransform(Box, None, factor) # + #Scale along axes of global CS by different factors. Scale relatively given point + Scale3 = geompy.MakeScaleAlongAxes(Box, pxyz, 1.5, 0.5, 3) #(2 GEOM_Object_ptr, 3 Doubles)->GEOM_Object_ptr + #Scale along axes of global CS by different factors. Scale relatively the origin of global CS + Scale4 = geompy.MakeScaleAlongAxes(Box, None, 1.5, 0.5, 3) # + + 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 @@ -338,7 +347,10 @@ def TestAll (geompy, math): id_TranslVectD = geompy.addToStudy(TranslVectD, "Translation along vector with defined distance") id_Rotation = geompy.addToStudy(Rotation, "Rotation") id_RotatPnt = geompy.addToStudy(RotatPnt, "Rotation by three points") - id_Scale = geompy.addToStudy(Scale, "Scale") + id_Scale1 = geompy.addToStudy(Scale1, "Scale1") + id_Scale2 = geompy.addToStudy(Scale2, "Scale2") + id_Scale3 = geompy.addToStudy(Scale3, "Scale3") + id_Scale4 = geompy.addToStudy(Scale4, "Scale4") id_Mirror = geompy.addToStudy(Mirror, "Mirror by Plane") id_MirrorAxis = geompy.addToStudy(MirrorAxis, "Mirror by Axis") id_MirrorPnt = geompy.addToStudy(MirrorPnt, "Mirror by Point") diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index d91a4b339..65fde5c8a 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -217,8 +217,6 @@ class geompyDC(GEOM._objref_GEOM_Gen): ## Publish sub-shapes, standing for arguments and sub-shapes of arguments # To be used from python scripts out of geompy.addToStudy (non-default usage) - # \param theStudy the study, in which theObject is published already, - # and in which the arguments will be published # \param theObject published GEOM object, arguments of which will be published # \param theArgs list of GEOM_Object, operation arguments to be published. # If this list is empty, all operation arguments will be published @@ -1683,9 +1681,8 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("DivideEdge", self.HealOp) return anObj - ## Change orientation of the given object. + ## Change orientation of the given object. Updates given shape. # @param theObject Shape to be processed. - # @update given shape # # @ref swig_todo "Example" def ChangeOrientationShell(self,theObject): @@ -2008,16 +2005,33 @@ class geompyDC(GEOM._objref_GEOM_Gen): ## 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. + # Passing None for it means scaling relatively the origin of global CS. # @param theFactor Scaling factor value. # @return New GEOM_Object, containing the scaled shape. # # @ref tui_scale "Example" - def MakeScaleTransform(self,theObject, thePoint, theFactor): + def MakeScaleTransform(self, theObject, thePoint, theFactor): # Example: see GEOM_TestAll.py anObj = self.TrsfOp.ScaleShapeCopy(theObject, thePoint, theFactor) RaiseIfFailed("ScaleShapeCopy", self.TrsfOp) return anObj + ## Scale the given object by different factors along coordinate axes, + # creating its copy before the scaling. + # @param theObject The object to be scaled. + # @param thePoint Center point for scaling. + # Passing None for it means scaling relatively the origin of global CS. + # @param theFactorX,theFactorY,theFactorZ Scaling factors along each axis. + # @return New GEOM_Object, containing the scaled shape. + # + # @ref swig_scale "Example" + def MakeScaleAlongAxes(self, theObject, thePoint, theFactorX, theFactorY, theFactorZ): + # Example: see GEOM_TestAll.py + anObj = self.TrsfOp.ScaleShapeAlongAxesCopy(theObject, thePoint, + theFactorX, theFactorY, theFactorZ) + RaiseIfFailed("MakeScaleAlongAxes", self.TrsfOp) + return anObj + ## Create an object, symmetrical # to the given one relatively the given plane. # @param theObject The object to be mirrored. diff --git a/src/TransformationGUI/TransformationGUI_ScaleDlg.cxx b/src/TransformationGUI/TransformationGUI_ScaleDlg.cxx index c9fbf946b..967a66212 100644 --- a/src/TransformationGUI/TransformationGUI_ScaleDlg.cxx +++ b/src/TransformationGUI/TransformationGUI_ScaleDlg.cxx @@ -10,13 +10,13 @@ // // 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 -// +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // @@ -39,6 +39,8 @@ #include #include +#include "DlgRef_SpinBox.h" + #include #include @@ -55,74 +57,174 @@ using namespace std; // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(GeometryGUI* theGeometryGUI, QWidget* parent, - const char* name, bool modal, WFlags fl) - :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) +TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent, + const char* name, bool modal, WFlags fl) + : 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_SCALE"))); - QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT"))); + SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr(); + QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE"))); + QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_SCALE_ALONG_AXES"))); + QPixmap image3 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT"))); setCaption(tr("GEOM_SCALE_TITLE")); - /***************************************************************/ + // Constructors GroupConstructors->setTitle(tr("GEOM_SCALE")); - RadioButton1->setPixmap(image0); - RadioButton2->close(TRUE); + RadioButton1->setPixmap(image1); + RadioButton2->setPixmap(image2); RadioButton3->close(TRUE); - GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints"); - GroupPoints->CheckButton2->hide(); - GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); - GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS")); - GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT")); - GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR")); - GroupPoints->LineEdit1->setReadOnly( true ); - GroupPoints->LineEdit2->setReadOnly( true ); - GroupPoints->PushButton1->setPixmap(image1); - GroupPoints->PushButton2->setPixmap(image1); - GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY")); - - // san -- modification of an exisitng object by offset is not allowed - GroupPoints->CheckButton1->hide(); - - Layout1->addWidget(GroupPoints, 2, 0); - /***************************************************************/ + // Own widgets + GroupBox1 = new QGroupBox (this, "GroupBox1"); + GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupBox1->setColumnLayout(0, Qt::Vertical); + GroupBox1->layout()->setSpacing(6); + GroupBox1->layout()->setMargin(11); + + TextLabel1 = new QLabel (GroupBox1, "TextLabel1"); + TextLabel1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, TextLabel1->sizePolicy().hasHeightForWidth())); + + TextLabel2 = new QLabel (GroupBox1, "TextLabel2"); + TextLabel2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, TextLabel2->sizePolicy().hasHeightForWidth())); + + PushButton1 = new QPushButton(GroupBox1, "PushButton1"); + PushButton1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, PushButton1->sizePolicy().hasHeightForWidth())); + + PushButton2 = new QPushButton( GroupBox1, "PushButton2" ); + PushButton2->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, PushButton2->sizePolicy().hasHeightForWidth())); + + LineEdit1 = new QLineEdit (GroupBox1, "LineEdit1"); + LineEdit2 = new QLineEdit (GroupBox1, "LineEdit2"); + + TextLabel3 = new QLabel (GroupBox1, "TextLabel3"); + TextLabel3->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, TextLabel3->sizePolicy().hasHeightForWidth())); + + TextLabel4 = new QLabel (GroupBox1, "TextLabel4"); + TextLabel4->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, TextLabel3->sizePolicy().hasHeightForWidth())); + + TextLabel5 = new QLabel (GroupBox1, "TextLabel5"); + TextLabel5->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, + 0, 0, TextLabel3->sizePolicy().hasHeightForWidth())); + + SpinBox_FX = new DlgRef_SpinBox(GroupBox1, "SpinBox_FX"); + SpinBox_FY = new DlgRef_SpinBox(GroupBox1, "SpinBox_FY"); + SpinBox_FZ = new DlgRef_SpinBox(GroupBox1, "SpinBox_FZ"); + + CheckBoxCopy = new QCheckBox (GroupBox1, "CheckBoxCopy"); + + QSpacerItem* spacer = new QSpacerItem(0, 316, QSizePolicy::Minimum, QSizePolicy::Expanding); + + // Layouting + OwnLayout = new QGridLayout (0, 1, 1, 0, 6, "Layout1"); + + OwnLayout->addWidget(TextLabel1, 0, 0); + OwnLayout->addWidget(TextLabel2, 1, 0); + + OwnLayout->addWidget(PushButton1, 0, 1); + OwnLayout->addWidget(PushButton2, 1, 1); + + OwnLayout->addMultiCellWidget(LineEdit1, 0, 0, 2, 3); + OwnLayout->addMultiCellWidget(LineEdit2, 1, 1, 2, 3); + + OwnLayout->addWidget(TextLabel3, 2, 0); + OwnLayout->addWidget(TextLabel4, 3, 0); + OwnLayout->addWidget(TextLabel5, 4, 0); + + OwnLayout->addWidget(SpinBox_FX, 2, 2); + OwnLayout->addWidget(SpinBox_FY, 3, 2); + OwnLayout->addWidget(SpinBox_FZ, 4, 2); + + OwnLayout->addMultiCellWidget(CheckBoxCopy, 5, 5, 0, 3); + + OwnLayout->addItem(spacer, 6, 2); + + GroupBox1Layout = new QGridLayout (GroupBox1->layout()); + GroupBox1Layout->setAlignment(Qt::AlignTop); + GroupBox1Layout->addLayout(OwnLayout, 0, 0); + + Layout1->addWidget(GroupBox1, 2, 0); + + // Text and pictures for own widgets + TextLabel1->setText(tr("GEOM_OBJECTS")); + TextLabel2->setText(tr("GEOM_CENTRAL_POINT")); + + PushButton1->setPixmap(image3); + PushButton2->setPixmap(image3); + + LineEdit1->setReadOnly( true ); + LineEdit2->setReadOnly( true ); + + TextLabel3->setText(tr("GEOM_SCALE_FACTOR")); + TextLabel4->setText(tr("GEOM_SCALE_FACTOR_Y")); + TextLabel5->setText(tr("GEOM_SCALE_FACTOR_Z")); + + // Min, max, step and decimals for spin boxes & initial values double aFactor = 2.0; double SpecificStep = 0.5; - /* min, max, step and decimals for spin boxes & initial values */ - GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY); - GroupPoints->SpinBox_DX->SetValue(aFactor); + SpinBox_FX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY); + SpinBox_FY->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY); + SpinBox_FZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY); + SpinBox_FX->SetValue(aFactor); + SpinBox_FY->SetValue(aFactor); + SpinBox_FZ->SetValue(aFactor); + + // Tab order + setTabOrder(PushButton1, LineEdit1); + setTabOrder(LineEdit1, PushButton2); + setTabOrder(PushButton2, LineEdit2); + setTabOrder(LineEdit2 , SpinBox_FX); + setTabOrder(SpinBox_FX, SpinBox_FY); + setTabOrder(SpinBox_FY, SpinBox_FZ); + setTabOrder(SpinBox_FZ, CheckBoxCopy); + setTabOrder(CheckBoxCopy, CheckBoxRestoreSS); + + // Modification of an existing object by offset is not allowed + CheckBoxCopy->hide(); // Activate Create a Copy mode - GroupPoints->CheckButton1->setChecked(true); + CheckBoxCopy->setText(tr("GEOM_CREATE_COPY")); + CheckBoxCopy->setChecked(true); CreateCopyModeChanged(true); + // Allowed inheritance of children and visual properties by the scaling result GroupBoxPublish->show(); - /* signals and slots connections */ + // 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(PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); - connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); + connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); - connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); - connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double))); - connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool))); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FX, SLOT(SetStep(double))); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FY, SLOT(SetStep(double))); + connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), SpinBox_FZ, SLOT(SetStep(double))); + + connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool))); connect(myGeomGUI->getApp()->selectionMgr(), - SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ; + SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ; setHelpFileName("scale_operation_page.html"); Init(); } - //================================================================================= // function : ~TransformationGUI_ScaleDlg() // purpose : Destroys the object and frees any allocated resources @@ -132,21 +234,57 @@ TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg() /* no need to delete child widgets, Qt does it all for us */ } - //================================================================================= // function : Init() // purpose : //================================================================================= void TransformationGUI_ScaleDlg::Init() { - myEditCurrentArgument = GroupPoints->LineEdit1; - GroupPoints->LineEdit2->clear(); + myEditCurrentArgument = LineEdit1; + LineEdit2->clear(); myPoint = GEOM::GEOM_Object::_nil(); - initName( tr( "GEOM_SCALE" ) ); + initName(tr("GEOM_SCALE")); + + ConstructorsClicked(0); } +//================================================================================= +// function : ConstructorsClicked() +// purpose : Radio button management +//================================================================================= +void TransformationGUI_ScaleDlg::ConstructorsClicked(int constructorId) +{ + erasePreview(); + + switch (constructorId) + { + case 0: /* translation an object by dx, dy, dz */ + TextLabel3->setText(tr("GEOM_SCALE_FACTOR")); + TextLabel4->hide(); + TextLabel5->hide(); + SpinBox_FY->hide(); + SpinBox_FZ->hide(); + resize(0,0); + break; + case 1: /* translation an object by 2 points */ + TextLabel3->setText(tr("GEOM_SCALE_FACTOR_X")); + TextLabel4->show(); + TextLabel5->show(); + SpinBox_FY->show(); + SpinBox_FZ->show(); + resize(0,0); + break; + default: + break; + } + + //qApp->processEvents(); + //updateGeometry(); + //resize(minimumSize()); + displayPreview(); +} //================================================================================= // function : ClickOnOk() @@ -154,100 +292,98 @@ void TransformationGUI_ScaleDlg::Init() //================================================================================= void TransformationGUI_ScaleDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } - //================================================================================= // function : ClickOnApply() // purpose : //================================================================================= bool TransformationGUI_ScaleDlg::ClickOnApply() { - if ( !onAccept(GroupPoints->CheckButton1->isChecked()) ) + if (!onAccept(CheckBoxCopy->isChecked())) return false; - Init(); + //Init(); + initName(tr("GEOM_SCALE")); return true; } - //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection as changed or other case //================================================================================= void TransformationGUI_ScaleDlg::SelectionIntoArgument() { + erasePreview(); myEditCurrentArgument->setText(""); QString aName; - if(myEditCurrentArgument == GroupPoints->LineEdit1) + if (myEditCurrentArgument == LineEdit1) + { + int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName); + if (aNbSel < 1) { - int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName); - if(aNbSel < 1) - { - myObjects.length(0); - return; - } - GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects); - if (!myObjects.length()) - return; + myObjects.length(0); + return; } - else if(myEditCurrentArgument == GroupPoints->LineEdit2) + GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects); + if (!myObjects.length()) + return; + } + else if (myEditCurrentArgument == LineEdit2) + { + GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil(); + if (IObjectCount() == 1) { - if(IObjectCount() != 1) - { - myPoint = GEOM::GEOM_Object::_nil(); - return; - } Standard_Boolean testResult = Standard_False; - GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult ); - aName = GEOMBase::GetName( aSelectedObject ); - - TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) - { - LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); - TColStd_IndexedMapOfInteger aMap; - aSelMgr->GetIndexes( firstIObject(), aMap ); - if ( aMap.Extent() == 1 ) - { - int anIndex = aMap( 1 ); - aName += QString(":vertex_%1").arg(anIndex); - - //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName); - - if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study - GEOM::GEOM_IShapesOperations_var aShapesOp = - getGeomEngine()->GetIShapesOperations( getStudyId() ); - aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); - aSelMgr->clearSelected(); - } - else - aSelectedObject = aFindedObject; // get Object from study - } - else { - if (aShape.ShapeType() != TopAbs_VERTEX) { - aSelectedObject = GEOM::GEOM_Object::_nil(); - aName = ""; - } - } - } - - myPoint = aSelectedObject; - - if(!testResult || CORBA::is_nil( myPoint )) - return; - + aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult); + if (testResult) + { + aName = GEOMBase::GetName(aSelectedObject); + + TopoDS_Shape aShape; + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) + { + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + TColStd_IndexedMapOfInteger aMap; + aSelMgr->GetIndexes(firstIObject(), aMap); + if (aMap.Extent() == 1) + { + int anIndex = aMap( 1 ); + aName += QString(":vertex_%1").arg(anIndex); + + //Find SubShape Object in Father + GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName); + + if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study + GEOM::GEOM_IShapesOperations_var aShapesOp = + getGeomEngine()->GetIShapesOperations( getStudyId() ); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); + aSelMgr->clearSelected(); + } + else + aSelectedObject = aFindedObject; // get Object from study + } + else + { + if (aShape.ShapeType() != TopAbs_VERTEX) { + aSelectedObject = GEOM::GEOM_Object::_nil(); + aName = ""; + } + } + } + } } - myEditCurrentArgument->setText( aName ); + myPoint = aSelectedObject; + } + + myEditCurrentArgument->setText(aName); displayPreview(); } - //================================================================================= // function : LineEditReturnPressed() // purpose : @@ -255,15 +391,13 @@ void TransformationGUI_ScaleDlg::SelectionIntoArgument() void TransformationGUI_ScaleDlg::LineEditReturnPressed() { QLineEdit* send = (QLineEdit*)sender(); - if(send == GroupPoints->LineEdit1 || - send == GroupPoints->LineEdit2) - { - myEditCurrentArgument = send; - GEOMBase_Skeleton::LineEditReturnPressed(); - } + if (send == LineEdit1 || send == LineEdit2) + { + myEditCurrentArgument = send; + GEOMBase_Skeleton::LineEditReturnPressed(); + } } - //================================================================================= // function : SetEditCurrentArgument() // purpose : @@ -273,19 +407,18 @@ void TransformationGUI_ScaleDlg::SetEditCurrentArgument() QPushButton* send = (QPushButton*)sender(); globalSelection(); - if(send == GroupPoints->PushButton1) { - myEditCurrentArgument = GroupPoints->LineEdit1; + if (send == PushButton1) { + myEditCurrentArgument = LineEdit1; } - else if(send == GroupPoints->PushButton2) { - myEditCurrentArgument = GroupPoints->LineEdit2; - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + else if (send == PushButton2) { + myEditCurrentArgument = LineEdit2; + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } myEditCurrentArgument->setFocus(); SelectionIntoArgument(); } - //================================================================================= // function : ActivateThisDialog() // purpose : @@ -293,25 +426,26 @@ void TransformationGUI_ScaleDlg::SetEditCurrentArgument() void TransformationGUI_ScaleDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - connect(myGeomGUI->getApp()->selectionMgr(), - SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + globalSelection(); - GroupPoints->LineEdit1->setFocus(); - myEditCurrentArgument = GroupPoints->LineEdit1; + myEditCurrentArgument->setFocus(); + if (myEditCurrentArgument == LineEdit2) { + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); + } } - //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void TransformationGUI_ScaleDlg::enterEvent(QEvent* e) +void TransformationGUI_ScaleDlg::enterEvent (QEvent* e) { - if( !GroupConstructors->isEnabled() ) + if (!GroupConstructors->isEnabled()) ActivateThisDialog(); } - //================================================================================= // function : ValueChangedInSpinBox() // purpose : @@ -321,54 +455,101 @@ void TransformationGUI_ScaleDlg::ValueChangedInSpinBox() displayPreview(); } - //================================================================================= // function : createOperation // purpose : //================================================================================= -GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation() +GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation() { - return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() ); + return myGeomGUI->GetGeomGen()->GetITransformOperations(getStudyId()); } //================================================================================= // function : isValid // purpose : //================================================================================= -bool TransformationGUI_ScaleDlg::isValid( QString& msg ) +bool TransformationGUI_ScaleDlg::isValid (QString& msg) { - return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001); + if (myObjects.length() > 0 && fabs(SpinBox_FX->GetValue()) > 0.00001) + { + // && !myPoint->_is_nil() + if (getConstructorId() == 0) + return true; + if (fabs(SpinBox_FY->GetValue()) > 0.00001 && + fabs(SpinBox_FZ->GetValue()) > 0.00001) + return true; + } + return false; } - //================================================================================= // function : execute // purpose : //================================================================================= -bool TransformationGUI_ScaleDlg::execute( ObjectList& objects ) +bool TransformationGUI_ScaleDlg::execute (ObjectList& objects) { bool res = false; + bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked(); GEOM::GEOM_Object_var anObj; - if (GroupPoints->CheckButton1->isChecked() || IsPreview()) - for (int i = 0; i < myObjects.length(); i++) + switch (getConstructorId()) + { + case 0: + { + if (toCreateCopy) { - anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )-> - ScaleShapeCopy( myObjects[i], myPoint, GetFactor() ); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())-> + ScaleShapeCopy(myObjects[i], myPoint, SpinBox_FX->GetValue()); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + } } - else - for (int i = 0; i < myObjects.length(); i++) + else { - anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )-> - ScaleShape( myObjects[i], myPoint, GetFactor() ); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())-> + ScaleShape(myObjects[i], myPoint, SpinBox_FX->GetValue()); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + } } - res = true; + } + break; + case 1: + { + if (toCreateCopy) + { + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())-> + ScaleShapeAlongAxesCopy(myObjects[i], myPoint, SpinBox_FX->GetValue(), + SpinBox_FY->GetValue(), SpinBox_FZ->GetValue()); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + } + } + else + { + for (int i = 0; i < myObjects.length(); i++) + { + anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())-> + ScaleShapeAlongAxes(myObjects[i], myPoint, SpinBox_FX->GetValue(), + SpinBox_FY->GetValue(), SpinBox_FZ->GetValue()); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); + } + } + } + break; + default: + break; + } + res = true; return res; } @@ -387,37 +568,29 @@ void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr theStud } } -//================================================================================= -// function : GetFactor() -// purpose : -//================================================================================= -double TransformationGUI_ScaleDlg::GetFactor() const -{ - return GroupPoints->SpinBox_DX->GetValue(); -} - - //================================================================================= // function : CreateCopyModeChanged() // purpose : //================================================================================= -void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy) +void TransformationGUI_ScaleDlg::CreateCopyModeChanged (bool isCreateCopy) { - this->GroupBoxName->setEnabled(isCreateCopy); + GroupBoxName->setEnabled(isCreateCopy); } //================================================================================= -// function : addSubshapeToStudy +// function : addSubshapesToStudy // purpose : virtual method to add new SubObjects if local selection //================================================================================= void TransformationGUI_ScaleDlg::addSubshapesToStudy() { - bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked(); - if (toCreateCopy) { - QMap objMap; - - objMap[GroupPoints->LineEdit2->text()] = myPoint; - - addSubshapesToFather( objMap ); + bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked(); + if (toCreateCopy) + { + if (!myPoint->_is_nil()) + { + QMap objMap; + objMap[LineEdit2->text()] = myPoint; + addSubshapesToFather(objMap); + } } } diff --git a/src/TransformationGUI/TransformationGUI_ScaleDlg.h b/src/TransformationGUI/TransformationGUI_ScaleDlg.h index ac700aac4..87c48dce2 100644 --- a/src/TransformationGUI/TransformationGUI_ScaleDlg.h +++ b/src/TransformationGUI/TransformationGUI_ScaleDlg.h @@ -13,10 +13,10 @@ // 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 // // @@ -29,8 +29,14 @@ #define DIALOGBOX_SCALE_H #include "GEOMBase_Skeleton.h" -#include "DlgRef_2Sel1Spin2Check.h" +class QGridLayout; +class QCheckBox; +class QGroupBox; +class QLabel; +class QLineEdit; +class QPushButton; +class DlgRef_SpinBox; //================================================================================= // class : TransformationGUI_ScaleDlg @@ -42,26 +48,47 @@ class TransformationGUI_ScaleDlg : public GEOMBase_Skeleton public: TransformationGUI_ScaleDlg(GeometryGUI* theGeometryGUI, QWidget* parent = 0, - const char* name = 0, bool modal = FALSE, WFlags fl = 0); + const char* name = 0, bool modal = FALSE, WFlags fl = 0); ~TransformationGUI_ScaleDlg(); protected: // redefined from GEOMBase_Helper virtual GEOM::GEOM_IOperations_ptr createOperation(); - virtual bool isValid( QString& ); - virtual bool execute( ObjectList& objects ); + virtual bool isValid (QString&); + virtual bool execute (ObjectList& objects); virtual void addSubshapesToStudy(); virtual void restoreSubShapes (SALOMEDS::Study_ptr, SALOMEDS::SObject_ptr); private : void Init(); - void enterEvent(QEvent* e); - double GetFactor() const; + void enterEvent (QEvent* e); GEOM::ListOfGO myObjects; GEOM::GEOM_Object_var myPoint; /* Central Point */ - DlgRef_2Sel1Spin2Check* GroupPoints; + QGroupBox* GroupBox1; + + QLabel* TextLabel1; + QLabel* TextLabel2; + + QPushButton* PushButton1; + QPushButton* PushButton2; + + QLineEdit* LineEdit1; + QLineEdit* LineEdit2; + + QLabel* TextLabel3; + QLabel* TextLabel4; + QLabel* TextLabel5; + + DlgRef_SpinBox* SpinBox_FX; + DlgRef_SpinBox* SpinBox_FY; + DlgRef_SpinBox* SpinBox_FZ; + + QCheckBox* CheckBoxCopy; + + QGridLayout* GroupBox1Layout; + QGridLayout* OwnLayout; private slots: void ClickOnOk(); @@ -70,8 +97,9 @@ private slots: void LineEditReturnPressed(); void SelectionIntoArgument(); void SetEditCurrentArgument(); + void ConstructorsClicked (int constructorId); void ValueChangedInSpinBox(); - void CreateCopyModeChanged(bool isCreateCopy); + void CreateCopyModeChanged (bool isCreateCopy); }; #endif // DIALOGBOX_SCALE_H -- 2.39.2