From: nds Date: Fri, 6 Nov 2015 15:49:02 +0000 (+0300) Subject: #816 In multi-rotation, be able to put the total angle or the step angle (Rotation... X-Git-Tag: V_2.0.0_alfa1~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca6f311ba3e0cb7011ed452c0349f11827f13b56;p=modules%2Fshaper.git #816 In multi-rotation, be able to put the total angle or the step angle (Rotation only) It must also be possible to enter the full angle value of the multi-rotation, with a toggle button defining the semantic of the angle value (either full rotation or between two consecutive repetitions). For consistency, it should be the same for multi-translation. --- diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index cf582520c..25010c848 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -69,6 +69,7 @@ icons/angle_up_32x32.png icons/angle_up_down.png icons/angle_up_down_32x32.png + icons/angle_up_full_32x32.png icons/dimension_up_down.png icons/dimension_up_down_32x32.png icons/by_two_points_32x32.png diff --git a/src/PartSet/icons/angle_up_full_32x32.png b/src/PartSet/icons/angle_up_full_32x32.png new file mode 100755 index 000000000..fdcde01a5 Binary files /dev/null and b/src/PartSet/icons/angle_up_full_32x32.png differ diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index 6f3c0c8c7..e58b5d267 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -5,9 +5,11 @@ // Author: Artem ZHIDKOV #include "SketchPlugin_MultiRotation.h" +#include "SketchPlugin_Tools.h" #include #include +#include #include #include #include @@ -26,13 +28,17 @@ #define PI 3.1415926535897932 SketchPlugin_MultiRotation::SketchPlugin_MultiRotation() +: myBlockAngle(true) { } void SketchPlugin_MultiRotation::initAttributes() { data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); + + data()->addAttribute(ANGLE_TYPE(), ModelAPI_AttributeString::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ANGLE_FULL_ID(), ModelAPI_AttributeDouble::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()); @@ -59,11 +65,20 @@ void SketchPlugin_MultiRotation::execute() attribute(CENTER_ID())); if (!aCenter || !aCenter->isInitialized()) return; + + if (attribute(ANGLE_ID())->isInitialized() && !attribute(ANGLE_FULL_ID())->isInitialized()) { + myBlockAngle = true; + SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), + aNbCopies, true); + myBlockAngle = false; + } + // make a visible points SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0); double anAngle = std::dynamic_pointer_cast( - attribute(ANGLE_ID()))->value(); + attribute(ANGLE_ID()))->value(); + // Convert angle to radians anAngle *= PI / 180.0; @@ -310,4 +325,41 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); } } + else if (theID == ANGLE_ID() && !myBlockAngle) { + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockAngle = true; + SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), + aNbCopies, true); + myBlockAngle = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } + else if (theID == ANGLE_FULL_ID() && !myBlockAngle) { + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockAngle = true; + SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()), + aNbCopies, false); + myBlockAngle = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } + else if (theID == NUMBER_OF_OBJECTS_ID()) { + AttributeStringPtr aMethodTypeAttr = string(ANGLE_TYPE()); + std::string aMethodType = aMethodTypeAttr->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockAngle = true; + if (aMethodType == "SingleAngle") + SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), + aNbCopies, true); + else + SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()), + aNbCopies, false); + + myBlockAngle = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } } diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.h b/src/SketchPlugin/SketchPlugin_MultiRotation.h index 7fd3cf14a..416f477b1 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.h +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.h @@ -52,12 +52,26 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase static const std::string MY_CENTER_ID("MultiRotationCenter"); return MY_CENTER_ID; } + /// attribute name for first point + inline static const std::string& ANGLE_TYPE() + { + static const std::string ANGLE_TYPE_ATTR("AngleType"); + return ANGLE_TYPE_ATTR; + } + /// End point of translation inline static const std::string& ANGLE_ID() { static const std::string MY_ANGLE_ID("MultiRotationAngle"); return MY_ANGLE_ID; } + /// End point of translation + inline static const std::string& ANGLE_FULL_ID() + { + static const std::string MY_ANGLE_FULL_ID("MultiRotationFullAngle"); + return MY_ANGLE_FULL_ID; + } + /// Total number of objects, initial and translated objects inline static const std::string& NUMBER_OF_OBJECTS_ID() { @@ -85,6 +99,11 @@ private: ObjectPtr copyFeature(ObjectPtr theObject); void rotateFeature(ObjectPtr theInitial, ObjectPtr theTarget, double theCenterX, double theCenterY, double theAngle); + + bool updateFullAngleValue(); + +private: + bool myBlockAngle; /// a boolean state to avoid recusive angle change in attributeChanged }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 82c5a3f93..e73349ef3 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -101,4 +101,24 @@ void findCoincidences(const FeaturePtr theStartCoin, } } +void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute, + const AttributePtr& theSecondAngleAttribute, + const int& theNumberOfCopies, + const bool toFullAngle) +{ + if (theNumberOfCopies == 0) + return; + + AttributeDoublePtr aDoubleFirstAttr = std::dynamic_pointer_cast( + theFirstAngleAttribute); + double aValue = aDoubleFirstAttr->value(); + + AttributeDoublePtr aDoubleSecondAttr = std::dynamic_pointer_cast( + theSecondAngleAttribute); + if (toFullAngle) + aDoubleSecondAttr->setValue(aValue*theNumberOfCopies); + else + aDoubleSecondAttr->setValue(aValue/theNumberOfCopies); +} + } // namespace SketchPlugin_Tools diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index 9637b5d09..79a4d62b8 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -10,6 +10,7 @@ #include #include +#include namespace SketchPlugin_Tools { @@ -28,6 +29,17 @@ void findCoincidences(const FeaturePtr theStartCoin, const std::string& theAttr, std::set& theList); +/// Changes the second attribute value to full or single angle. If it is corrected to full +/// value, the first angle is miltipied to the number of copies otherwise it is separated by it. +/// \param theFirstAngleAttribute the source attribute +/// \param theSecondAngleAttribute the changed attribute +/// \param theNumberOfCopies a value for modification +/// \param toFullAngle a type of modification +void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute, + const AttributePtr& theSecondAngleAttribute, + const int& theNumberOfCopies, + const bool toFullAngle); + }; // namespace SketchPlugin_Tools #endif // SKETCHPLUGIN_TOOLS_H_ \ No newline at end of file diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index d8c4ede48..8d9939005 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -320,12 +320,23 @@ title="Center of rotation" tooltip="Center of rotation" default="0"/> - + + + + + + +