From ee089fbd0d64d718380bdc443f0e3b7dfec39b26 Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 9 Nov 2015 11:46:13 +0300 Subject: [PATCH] #816 In multi-rotation, be able to put the total angle or the step angle (Rotation only) Realization for Translation WidgetPoint2d is corrected because multi translation can have equal points -> single end point value = full end point value when number of objects = 2. --- src/PartSet/PartSet_WidgetPoint2d.cpp | 4 ++ src/PartSet/PartSet_icons.qrc | 2 + src/PartSet/icons/translate_32x32.png | Bin 0 -> 867 bytes src/PartSet/icons/translate_full_32x32.png | Bin 0 -> 983 bytes .../SketchPlugin_MultiTranslation.cpp | 63 +++++++++++++++++- .../SketchPlugin_MultiTranslation.h | 17 +++++ src/SketchPlugin/SketchPlugin_Tools.cpp | 33 +++++++++ src/SketchPlugin/SketchPlugin_Tools.h | 11 +++ src/SketchPlugin/plugin-Sketch.xml | 36 +++++++--- src/XGUI/XGUI_PropertyPanel.cpp | 12 +++- 10 files changed, 166 insertions(+), 12 deletions(-) create mode 100755 src/PartSet/icons/translate_32x32.png create mode 100755 src/PartSet/icons/translate_full_32x32.png diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 53b403e60..8d9f07d31 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -440,6 +440,10 @@ bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature, double theX, double theY) { bool aPointIsFound = false; + + if (feature()->getKind() != SketchPlugin_Line::ID()) + return aPointIsFound; + AttributePtr aWidgetAttribute = myFeature->attribute(attributeID()); std::shared_ptr aPnt2d = diff --git a/src/PartSet/PartSet_icons.qrc b/src/PartSet/PartSet_icons.qrc index 25010c848..13a0a428f 100644 --- a/src/PartSet/PartSet_icons.qrc +++ b/src/PartSet/PartSet_icons.qrc @@ -55,6 +55,8 @@ icons/coincedence.png icons/mirror.png icons/translate.png + icons/translate_32x32.png + icons/translate_full_32x32.png icons/rotate.png icons/exec_state_failed.png icons/exec_state_invalid_parameters.png diff --git a/src/PartSet/icons/translate_32x32.png b/src/PartSet/icons/translate_32x32.png new file mode 100755 index 0000000000000000000000000000000000000000..28f064bd79ea2198b174c6f9b48489e6e0d8ea37 GIT binary patch literal 867 zcmV-p1DyPcP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGvt^fcVt^tf)bNB!N02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0008gNkln$1;0VRLGdp1B8rF}1T8hj|E|wFJ2QQE zcM{Xx#0Q?;+3n2x{B~wCv=Ya$auJD8-iBYpKjB#WJKWJ-ax!@~*ER|YVaI~t;VRcQ zN(f;yL-25wYa1nnu$druxXQJSIS66@gy7*S*EZ%PgiVFu;VRcQ=A@=CPa^Cd{09CF zryzK^%C(JxI=iuPq8<*bb$@V9gpm}1+=iba>>chS_!oyTS)~DL-D@jeD7#)5-GraQ zy9js-|9~lUjPQM!W+Jy7r2xD@UV$H=&?jvwY621m@=yeuecbQjIkzWD0jz}4c@)`W z1@jK%3*pPF)F022H)aulW+-cL3k9Y?M2}a)!D&5YB7_AH?cPP*cP0@;!yn!fK{R3o zjlaP68)3ApyDQ;c4uS#n$)d8gwWRw`RO530lxX$W(Ep|I2M2)QKR5Dw(UD=JyP2zn zzoj6u02R-=muefCaIe+-i2ft^DWtow7+i}4G2c*Y;v_2(i0l7XOxJtj#M=u+m($Lg!w{X=*k z-f4!B2e)w^JORKRJuD{!U}l0YG;J2bYvln_Uw#x$AiMCk?uLySRad)FT|Z700Vo&^ zU?Cc7g9;gimoOX4A{bTybtCiTCVZ#v4{N&SvBUwKCloog+iA@+;ks5KaRB!T1+i%# z%`=?D0h}ik+?h1(x<)Bk020D-5LoxmDm<~>?a7GpN&%2k5J$oE)fArE?emZY;1nr{ z%yQ^1cAy!@pNlxTFd=LzM7BU#Czp&6HW4CQpsbUNLkRmX5cwBO2wOOW`=wUqU+jhK t3Fk|f5x9_Px#1ZP1_K>z@;j|==^1poj532;bRa{vGvt^fcVt^tf)bNB!N02*{fSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+qQF!XYv0009^z zd6T4Rd*IC6d2{bQ=Y3?_%4jq)oCjf?-Ur`ILHE$&rot?tz@ z?x$gtZi3HI^9lDM_(%0QbhXBT8bsm%Ja7w%+C&hit3lkq3qAv1Anzmi3nbA4h;M_m z5{2#Hej-ZX7zsV_EtoR_nnDJizgp5e&dV63`(d=6;Qj#5g)#hL;lE#J2gtx>jVZGJ6 z7e@V|9n<^{KCZ|8Mcc*zV+9k+K%(QYvazvX>q<=^-U(aXJ($oxH{$28oyPUmb?L#t zyPSzK1C>D7F?YAnu$c_OA29J#nfM333)<-otC@r8uX@o#;WJ4FToQC4#jOzgqL zQ|$X|8VjQI$;DPr_Fseg6Sx-zaG&;K?-b{8;L)(!%)u2pf62z=q%%5BcEMPSj!>Ct@jt=L{yaf%4+OvbREiUZ26}LUI1`4Pt^bsKkxp5>GOknB08S#w!;IjRp}h?oV} z2#_=`9t+c~Nt|ZBX;THg&tNE*_xhL`+O$aXeJ=d9-M(?1H5ImKY@DBP2G4FQxa%bnL@*irY)g*I_Q@sEH002ovPDHLk FV1mi|xm5rF literal 0 HcmV?d00001 diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index 0db1082a1..9c7994384 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -5,6 +5,7 @@ // Author: Artem ZHIDKOV #include "SketchPlugin_MultiTranslation.h" +#include "SketchPlugin_Tools.h" #include #include @@ -13,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -20,13 +22,17 @@ #include SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation() +: myBlockValue(false) { } void SketchPlugin_MultiTranslation::initAttributes() { + data()->addAttribute(VALUE_TYPE(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::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()); @@ -56,9 +62,23 @@ void SketchPlugin_MultiTranslation::execute() if (!aStart || !aEnd || !aStart->isInitialized() || !aEnd->isInitialized()) return; + if (attribute(END_POINT_ID())->isInitialized() && !attribute(END_FULL_POINT_ID())->isInitialized()) { + myBlockValue = true; + SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), + attribute(END_FULL_POINT_ID()), aNbCopies, true); + myBlockValue = false; + } + + // make a visible points SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0); - SketchPlugin_Sketch::createPoint2DResult(this, sketch(), END_POINT_ID(), 1); + + std::string aSecondPointAttributeID = END_POINT_ID(); + AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE()); + std::string aMethodType = aMethodTypeAttr->value(); + if (aMethodType != "SingleValue") + aSecondPointAttributeID = END_FULL_POINT_ID(); + SketchPlugin_Sketch::createPoint2DResult(this, sketch(), aSecondPointAttributeID, 1); std::shared_ptr aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y())); @@ -252,4 +272,45 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID) data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); } } + else if (theID == END_POINT_ID() && !myBlockValue) { + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockValue = true; + SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), + attribute(END_FULL_POINT_ID()), aNbCopies, true); + myBlockValue = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } + else if (theID == END_FULL_POINT_ID() && !myBlockValue) { + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockValue = true; + SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()), + attribute(END_POINT_ID()), aNbCopies, false); + myBlockValue = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } + else if (theID == NUMBER_OF_OBJECTS_ID()) { + if (attribute(NUMBER_OF_OBJECTS_ID())->isInitialized() && + attribute(END_POINT_ID())->isInitialized() && + attribute(VALUE_TYPE())->isInitialized()) { + AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE()); + std::string aMethodType = aMethodTypeAttr->value(); + int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; + if (aNbCopies > 0) { + myBlockValue = true; + if (aMethodType == "SingleValue") + SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()), + attribute(END_FULL_POINT_ID()), aNbCopies, true); + else { + SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()), + attribute(END_POINT_ID()), aNbCopies, false); + } + myBlockValue = false; + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + } + } + } } diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.h b/src/SketchPlugin/SketchPlugin_MultiTranslation.h index 967c60d18..ed9a8f878 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.h +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.h @@ -46,6 +46,13 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase return MY_TRANSLATION_LIST_ID; } + /// attribute name for first point + inline static const std::string& VALUE_TYPE() + { + static const std::string VALUE_TYPE_ATTR("ValueType"); + return VALUE_TYPE_ATTR; + } + /// Start point of translation inline static const std::string& START_POINT_ID() { @@ -58,6 +65,13 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase static const std::string MY_END_POINT_ID("MultiTranslationEndPoint"); return MY_END_POINT_ID; } + /// End point of translation + inline static const std::string& END_FULL_POINT_ID() + { + static const std::string MY_END_FULL_POINT_ID("MultiTranslationFullEndPoint"); + return MY_END_FULL_POINT_ID; + } + /// Total number of objects, initial and translated objects inline static const std::string& NUMBER_OF_OBJECTS_ID() { @@ -83,6 +97,9 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase private: ObjectPtr copyFeature(ObjectPtr theObject); + +private: + bool myBlockValue; /// a boolean state to avoid recusive value change in attributeChanged }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 28d78bbd4..a9aa9d90c 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -121,4 +121,37 @@ void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute, aDoubleSecondAttr->setValue(aValue/theValue); } +void updateMultiAttribute(const AttributePtr& theFirstAttribute, + const AttributePtr& theSecondAttribute, + const AttributePtr& theModifiedAttribute, + const int& theValue, + const bool toMultiply) +{ + if (theValue == 0 || !theFirstAttribute->isInitialized() + || !theSecondAttribute->isInitialized()) + return; + + std::shared_ptr aFirstPoint = + std::dynamic_pointer_cast(theFirstAttribute); + std::shared_ptr aSecondPoint = + std::dynamic_pointer_cast(theSecondAttribute); + std::shared_ptr aModifiedPoint = + std::dynamic_pointer_cast(theModifiedAttribute); + + if (!aFirstPoint.get() || !aSecondPoint.get() || !aModifiedPoint.get()) + return; + + if (aFirstPoint->pnt()->isEqual(aSecondPoint->pnt())) + aModifiedPoint->setValue(aFirstPoint->pnt()); + else { + double aDx = aSecondPoint->x() - aFirstPoint->x(); + double aDy = aSecondPoint->y() - aFirstPoint->y(); + + double aX = toMultiply ? aDx * theValue : aDx / theValue; + double anY = toMultiply ? aDy * theValue : aDy / theValue; + + aModifiedPoint->setValue(aFirstPoint->x() + aX, aFirstPoint->y() + anY); + } +} + } // namespace SketchPlugin_Tools diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index 17ab8b58f..6b242532b 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -39,6 +39,17 @@ void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute, const int& theValue, const bool toMultiply); +/// Changes the second attribute value to be multiplied or divided by the given value. +/// \param theFirstAngleAttribute the source attribute +/// \param theSecondAngleAttribute the changed attribute +/// \param theValue a value for modification +/// \param toMultiply a type of modification +void updateMultiAttribute(const AttributePtr& theFirstAttribute, + const AttributePtr& theSecondAttribute, + const AttributePtr& theModifiedAttribute, + const int& theValue, + const bool toMultiply); + }; // 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 8d9939005..e728cf7cc 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -285,16 +285,32 @@ use_external="true"> - - - - + + + + + + + + + + + + + + #include +#include +#include + #include #include #include @@ -154,12 +157,19 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget) activateWidget(NULL); return; } + ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); + QList::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end(); bool isFoundWidget = false; activateWindow(); for (; anIt != aLast; anIt++) { + ModuleBase_ModelWidget* aCurrentWidget = *anIt; if (isFoundWidget || !theWidget) { - if ((*anIt)->focusTo()) { + + if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID())) + continue; // this attribute is not participated in the current case + + if (aCurrentWidget->focusTo()) { return; } } -- 2.39.2