From: nds Date: Fri, 6 Nov 2015 08:42:03 +0000 (+0300) Subject: Issue #995: Checkbox 'Make a copy' during translation and rotation operations X-Git-Tag: V_2.0.0_alfa1~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa7989f7a1aff79777404200842d8bc905ee8a45;p=modules%2Fshaper.git Issue #995: Checkbox 'Make a copy' during translation and rotation operations Correction from a list of improvements: For compatibility with old GEOM, we must ask for the total number of objects, not the number of copies, as currently (for information, it's like that too in SolidWorks). --- diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index 726ffe4dd..6f3c0c8c7 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -33,7 +33,7 @@ void SketchPlugin_MultiRotation::initAttributes() { data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(ROTATION_LIST_ID(), ModelAPI_AttributeRefList::typeId()); @@ -50,7 +50,9 @@ void SketchPlugin_MultiRotation::execute() } AttributeRefListPtr aRotationObjectRefs = reflist(ROTATION_LIST_ID()); - int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies <= 0) + return; // Obtain center and angle of rotation std::shared_ptr aCenter = std::dynamic_pointer_cast( @@ -279,7 +281,10 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) if (theID == ROTATION_LIST_ID()) { AttributeRefListPtr aRotationObjectRefs = reflist(ROTATION_LIST_ID()); if (aRotationObjectRefs->size() == 0) { - int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value()-1; + if (aNbCopies <= 0) + return; + // Clear list of objects AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast( data()->attribute(SketchPlugin_Constraint::ENTITY_B())); diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.h b/src/SketchPlugin/SketchPlugin_MultiRotation.h index 245ffb980..7fd3cf14a 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.h +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.h @@ -19,10 +19,9 @@ * SketchPlugin_Constraint::ENTITY_A() for initial list of objects and * SketchPlugin_Constraint::ENTITY_B() for the list of created objects * - * The list of created objects contains a number of copies of each object given in - * the NUMBER_OF_COPIES_ID() attribute plus 1 (the initial objects are stored into this - * attribute too). At the start of the list, there are collected N copies - * of first object from initial list, then N copies of second object etc. + * The list of created objects contains initial and copied objects of each object given. The + * number copies is the NUMBER_OF_OBJECTS_ID() minus 1. At the start of the list, there are + * collected N copies of first object from initial list, then N copies of second object etc. */ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase { @@ -59,11 +58,11 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase static const std::string MY_ANGLE_ID("MultiRotationAngle"); return MY_ANGLE_ID; } - /// Number of translated objects - inline static const std::string& NUMBER_OF_COPIES_ID() + /// Total number of objects, initial and translated objects + inline static const std::string& NUMBER_OF_OBJECTS_ID() { - static const std::string MY_NUMBER_OF_COPIES_ID("MultiRotationCopies"); - return MY_NUMBER_OF_COPIES_ID; + static const std::string MY_NUMBER_OF_OBJECTS_ID("MultiRotationObjects"); + return MY_NUMBER_OF_OBJECTS_ID; } /// \brief Creates a new part document if needed diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index 3e6a702b6..0db1082a1 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -27,7 +27,7 @@ void SketchPlugin_MultiTranslation::initAttributes() { data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeInteger::typeId()); + data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(TRANSLATION_LIST_ID(), ModelAPI_AttributeRefList::typeId()); @@ -44,7 +44,9 @@ void SketchPlugin_MultiTranslation::execute() } AttributeRefListPtr aTranslationObjectRefs = reflist(TRANSLATION_LIST_ID()); - int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value()-1; + if (aNbCopies <= 0) + return; // Calculate shift vector std::shared_ptr aStart = std::dynamic_pointer_cast( @@ -222,7 +224,9 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID) if (theID == TRANSLATION_LIST_ID()) { AttributeRefListPtr aTranslationObjectRefs = reflist(TRANSLATION_LIST_ID()); if (aTranslationObjectRefs->size() == 0) { - int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value()-1; + if (aNbCopies <= 0) + return; // Clear list of objects AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( data()->attribute(SketchPlugin_Constraint::ENTITY_B())); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.h b/src/SketchPlugin/SketchPlugin_MultiTranslation.h index 5bebd1882..967c60d18 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.h +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.h @@ -19,10 +19,9 @@ * SketchPlugin_Constraint::ENTITY_A() for initial list of objects and * SketchPlugin_Constraint::ENTITY_B() for the list of created objects * - * The list of created objects contains a number of copies of each object given in - * the NUMBER_OF_COPIES_ID() attribute plus 1 (the initial objects are stored into this - * attribute too). At the start of the list, there are collected N copies - * of first object from initial list, then N copies of second object etc. + * The list of created objects contains initial and copied objects of each object given. The + * number copies is the NUMBER_OF_OBJECTS_ID() minus 1. At the start of the list, there are + * collected N copies of first object from initial list, then N copies of second object etc. */ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase { @@ -59,11 +58,11 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase static const std::string MY_END_POINT_ID("MultiTranslationEndPoint"); return MY_END_POINT_ID; } - /// Number of translated objects - inline static const std::string& NUMBER_OF_COPIES_ID() + /// Total number of objects, initial and translated objects + inline static const std::string& NUMBER_OF_OBJECTS_ID() { - static const std::string MY_NUMBER_OF_COPIES_ID("MultiTranslationCopies"); - return MY_NUMBER_OF_COPIES_ID; + static const std::string MY_NUMBER_OF_OBJECTS_ID("MultiTranslationObjects"); + return MY_NUMBER_OF_OBJECTS_ID; } /// \brief Creates a new part document if needed diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 3891315ef..d8c4ede48 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -295,10 +295,10 @@ title="End point" tooltip="Final point of translation"/> - + @@ -326,10 +326,10 @@ icon=":icons/angle.png" tooltip="Rotation angle" default="90"/> - + diff --git a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp index b1de57dc2..5be0d2fe5 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMulti.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMulti.cpp @@ -64,8 +64,8 @@ void SketchSolver_ConstraintMulti::update(ConstraintPtr theConstraint) if (!theConstraint || theConstraint == myBaseConstraint) { AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributeIntegerPtr aNbCopies = myBaseConstraint->integer(nameNbCopies()); - if (anInitialRefList->size() != myNumberOfObjects || aNbCopies->value() != myNumberOfCopies) { + AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects()); + if (anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies) { remove(myBaseConstraint); process(); return; diff --git a/src/SketchSolver/SketchSolver_ConstraintMulti.h b/src/SketchSolver/SketchSolver_ConstraintMulti.h index 8d30da0e6..4786ee430 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMulti.h +++ b/src/SketchSolver/SketchSolver_ConstraintMulti.h @@ -72,8 +72,8 @@ protected: virtual void updateLocal() = 0; /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature - virtual const std::string& nameNbCopies() = 0; - + virtual const std::string& nameNbObjects() = 0; + protected: /// \brief Convert absolute coordinates to relative coordinates virtual void getRelative(double theAbsX, double theAbsY, double& theRelX, double& theRelY) = 0; diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index ed1550d41..7608460c4 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -40,7 +40,9 @@ void SketchSolver_ConstraintMultiRotation::getAttributes( AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::ENTITY_A())); myNumberOfObjects = anInitialRefList->size(); - myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID())->value(); + myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID())->value() - 1; + if (myNumberOfCopies <= 0) + return; AttributeRefListPtr aRefList = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!aRefList) { @@ -205,7 +207,7 @@ void SketchSolver_ConstraintMultiRotation::transformRelative(double& theX, doubl theX = aTemp; } -const std::string& SketchSolver_ConstraintMultiRotation::nameNbCopies() +const std::string& SketchSolver_ConstraintMultiRotation::nameNbObjects() { - return SketchPlugin_MultiRotation::NUMBER_OF_COPIES_ID(); + return SketchPlugin_MultiRotation::NUMBER_OF_OBJECTS_ID(); } diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h index 5206c6b9f..86966e522 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h @@ -54,7 +54,7 @@ private: private: /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature - virtual const std::string& nameNbCopies(); + virtual const std::string& nameNbObjects(); private: Slvs_hEntity myRotationCenter; ///< ID of center of rotation diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp index 381c8641b..02b872c6e 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp @@ -46,7 +46,10 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes( AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast( aData->attribute(SketchPlugin_Constraint::ENTITY_A())); myNumberOfObjects = anInitialRefList->size(); - myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID())->value(); + myNumberOfCopies = (size_t) aData->integer(SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID())->value() - 1; + if (myNumberOfCopies <= 0) + return; + AttributeRefListPtr aRefList = std::dynamic_pointer_cast( myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!aRefList) { @@ -199,7 +202,7 @@ void SketchSolver_ConstraintMultiTranslation::transformRelative(double& theX, do theY += myDelta[1]; } -const std::string& SketchSolver_ConstraintMultiTranslation::nameNbCopies() +const std::string& SketchSolver_ConstraintMultiTranslation::nameNbObjects() { - return SketchPlugin_MultiTranslation::NUMBER_OF_COPIES_ID(); + return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID(); } diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h index c3188afa3..c9f10147d 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h @@ -56,7 +56,7 @@ private: private: /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature - virtual const std::string& nameNbCopies(); + virtual const std::string& nameNbObjects(); private: Slvs_hEntity myTranslationLine; ///< ID of translation line