From: nds Date: Mon, 9 Nov 2015 08:46:13 +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~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ee089fbd0d64d718380bdc443f0e3b7dfec39b26;p=modules%2Fshaper.git #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. --- 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 000000000..28f064bd7 Binary files /dev/null and b/src/PartSet/icons/translate_32x32.png differ diff --git a/src/PartSet/icons/translate_full_32x32.png b/src/PartSet/icons/translate_full_32x32.png new file mode 100755 index 000000000..2f876889b Binary files /dev/null and b/src/PartSet/icons/translate_full_32x32.png differ 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; } }