From: nds Date: Mon, 4 Jul 2016 07:32:12 +0000 (+0300) Subject: Somehow inform the user about the scale of the view X-Git-Tag: V_2.5.0~246 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b37c9aff0b0da0629986abf46ea6ea5c5f54d676;p=modules%2Fshaper.git Somehow inform the user about the scale of the view --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 58252b77e..0fc75262d 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -89,6 +89,9 @@ const static char* DOUBLE_WDG_STEP = "step"; const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed"; const static char* DOUBLE_WDG_ACCEPT_EXPRESSIONS = "accept_expressions"; const static char* DOUBLE_WDG_ENABLE_VALUE = "enable_value"; + +const static char* DOUBLE_WDG_ENABLE_VALUE_BY_PREFERENCES = "enable_by_preferences"; + // WDG_TOOLBOX/WDG_SWITCH properties const static char* CONTAINER_PAGE_NAME = "title"; const static char* CONTAINER_PAGE_ICON = "icon"; diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index b172e101e..4420aff9a 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -54,7 +54,12 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, myAttributeID = theData ? theData->widgetId() : ""; myIsObligatory = theData->getBooleanAttribute(ATTR_OBLIGATORY, true); - myIsValueEnabled = theData->getBooleanAttribute(DOUBLE_WDG_ENABLE_VALUE, true); + myIsValueEnabled = On; // not defined or "true" + std::string anEnableValue = theData->getProperty(DOUBLE_WDG_ENABLE_VALUE); + if (anEnableValue == "false") + myIsValueEnabled = Off; + if (anEnableValue == DOUBLE_WDG_ENABLE_VALUE_BY_PREFERENCES) + myIsValueEnabled = DefinedInPreferences; connect(this, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged())); connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified())); @@ -84,9 +89,13 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const bool ModuleBase_ModelWidget::isValueEnabled() const { bool anEnabled = true; - bool aCanDisable = Config_PropManager::boolean("Sketch planes", "disable_input_fields", "true"); - if (aCanDisable) - anEnabled = myIsValueEnabled; + if (myIsValueEnabled == DefinedInPreferences) { + bool aCanDisable = Config_PropManager::boolean("Sketch planes", "disable_input_fields", "true"); + if (aCanDisable) + anEnabled = false; + } + else if (myIsValueEnabled == Off) + anEnabled = false; return anEnabled; } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index cc3438680..4c677a1f3 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -40,6 +40,10 @@ Q_OBJECT ModifiedInViewer, /// modification performed by viewer events Reset }; /// the value is reset + enum EnableState { On, /// the widget value is always enabled + Off, /// the widget value is always disabled + DefinedInPreferences }; /// the widget value enable state is defined in preferences + /// Constructor /// \param theParent the parent object /// \param theData the widget configuration. The attribute of the model widget is obtained from @@ -316,7 +320,7 @@ protected slots: bool myIsObligatory; /// Flag about value of the control is enabled (can be modified) - bool myIsValueEnabled; + EnableState myIsValueEnabled; /// The widget value state ValueState myState; diff --git a/src/PythonAddons/macros/rectangle/widget.xml b/src/PythonAddons/macros/rectangle/widget.xml index 890e3e55d..d7c83bc86 100644 --- a/src/PythonAddons/macros/rectangle/widget.xml +++ b/src/PythonAddons/macros/rectangle/widget.xml @@ -9,7 +9,7 @@ tooltip="Create rectangle" icon="icons/Addons/rectangle.png"> + enable_value="enable_by_preferences"/> diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index c69b6019b..1952e97aa 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ void SketchPlugin_Line::initDerivedClassAttributes() data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); } @@ -123,6 +125,22 @@ void SketchPlugin_Line::attributeChanged(const std::string& theID) { std::shared_ptr anEndAttr = std::dynamic_pointer_cast(attribute(END_ID())); anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint())); + updateLenghtValue(); } } + else if (theID == START_ID() || theID == END_ID()) { + updateLenghtValue(); + } +} + +void SketchPlugin_Line::updateLenghtValue() +{ + std::shared_ptr aStartAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(START_ID())); + std::shared_ptr anEndAttr = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(data()->attribute(END_ID())); + if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) { + double aDistance = aStartAttr->pnt()->distance(anEndAttr->pnt()); + data()->real(LENGTH_ID())->setValue(aDistance); + } } diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 57363add5..8891b3e34 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -40,6 +40,13 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity return MY_END_ID; } + /// Line length. + static const std::string& LENGTH_ID() + { + static const std::string MY_LENGTH("LineLength"); + return MY_LENGTH; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind(); @@ -64,6 +71,10 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity /// Use plugin manager for features creation SketchPlugin_Line(); +private: + /// Calculates the lenght of the line and fill the lenght attribute with the value + void updateLenghtValue(); + protected: /// \brief Initializes attributes of derived class. virtual void initDerivedClassAttributes(); diff --git a/src/SketchPlugin/icons/distance_value.png b/src/SketchPlugin/icons/distance_value.png new file mode 100755 index 000000000..b40da2e2d Binary files /dev/null and b/src/SketchPlugin/icons/distance_value.png differ diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 89b6754ae..282c142eb 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -21,16 +21,18 @@ + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + @@ -45,20 +47,20 @@ + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> @@ -73,20 +75,20 @@ + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> @@ -94,17 +96,17 @@ + enable_value="enable_by_preferences"/> + tooltip="Set radius" obligatory="0" enable_value="enable_by_preferences"> + enable_value="enable_by_preferences"/> + enable_value="enable_by_preferences"/> @@ -122,7 +124,7 @@ + enable_value="enable_by_preferences">