From ca6f311ba3e0cb7011ed452c0349f11827f13b56 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 6 Nov 2015 18:49:02 +0300 Subject: [PATCH] #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. --- src/PartSet/PartSet_icons.qrc | 1 + src/PartSet/icons/angle_up_full_32x32.png | Bin 0 -> 1095 bytes .../SketchPlugin_MultiRotation.cpp | 54 +++++++++++++++++- src/SketchPlugin/SketchPlugin_MultiRotation.h | 19 ++++++ src/SketchPlugin/SketchPlugin_Tools.cpp | 20 +++++++ src/SketchPlugin/SketchPlugin_Tools.h | 12 ++++ src/SketchPlugin/plugin-Sketch.xml | 13 ++++- 7 files changed, 117 insertions(+), 2 deletions(-) create mode 100755 src/PartSet/icons/angle_up_full_32x32.png 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 0000000000000000000000000000000000000000..fdcde01a565efb430c634d6d73b13b8f40263f2f GIT binary patch literal 1095 zcmV-N1i1T&P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGvt^fcVt^tf)bNB!N02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv000BFNklPRqR zGdosT>3YqWneLjZB9qu5k+2epjRlFFm57x@!qSM1SlO}ie#Tn}!eT^ZMm%OPG3`Iq zecQRGZ$AhYU#hFlIrsj3?>VP#6`Ux&$~axERtu7X=gm`Lwp&H%#iawuGHzQ@+B)9} z)5nOdYE+nB;Xdsk0gXWLL^`+wS>W_%542A)NpNB!k*Vl}3wLm1%CrN*&YoZfFwF>usYYJ%Ha|gsnype|7xIJ8)k`$y;F`Usy^O z*(Pd*DIiSW;QGRNCaDRSa(rBcO$G52*DsIQCTfLTfp6lz83<4$AWVK3&*?rFR+&;> ze8KgH*V!hNNCD5V?E444HvnerlSB&&%owB)c8xo zA03c7q4afvp;f4o=cb7ADd|UaEx--3Ey5QSk)$?X0wpKO2S7(YcuT4Yp&(h-Y*ZKuaxr#%+mbgK`9k+SIZ&9djTb zz_hnbJPoZHe9t$^pxSODe?8-MEMhpbXyYe&OiKZn92xt| zMtRWgpiw`Vm@S&2!jT!}m!};s-pS*v0w}|2LT;l<;DH+a<3Vaj+?Rv6dq~1*T@7wf z+0Wyx0&tc4*OYj5kupIWhg`2I%!UcL6@@C_X`3 zPhMfHXL$AyJOYm)AQKbnd%8;7->1F;=0x~5Fz){)YzzL+KQ>9LKLNzT>ZJ2_iGBb8 N002ovPDHLkV1l`w@^1hD literal 0 HcmV?d00001 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"/> - + + + + + + +