]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Somehow inform the user about the scale of the view
authornds <nds@opencascade.com>
Mon, 4 Jul 2016 07:32:12 +0000 (10:32 +0300)
committernds <nds@opencascade.com>
Mon, 4 Jul 2016 07:32:12 +0000 (10:32 +0300)
src/Config/Config_Keywords.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/PythonAddons/macros/rectangle/widget.xml
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/icons/distance_value.png [new file with mode: 0755]
src/SketchPlugin/plugin-Sketch.xml

index 58252b77ecf9a33add42b4d92610dd2a9060a850..0fc75262dd3a8789d26cc607fb4038799a059200 100644 (file)
@@ -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";
index b172e101e9ed7518e2a8bf99ec22fd4656808b7f..4420aff9a2e0e307c93798f40347a159d14db341 100644 (file)
@@ -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;
 }
 
index cc3438680f3fa8e5d4c3cba89469bb639b1ec95a..4c677a1f34f9d74a258359208db09f9dc305ae20 100644 (file)
@@ -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;
index 890e3e55ddcd58730055ae70892bbc6e5e48e741..d7c83bc86b7b1fcd16b0032d7e5da5ca68f572b4 100644 (file)
@@ -9,7 +9,7 @@
         tooltip="Create rectangle"
         icon="icons/Addons/rectangle.png">
         <sketch-2dpoint_selector id="RectStartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
-                                 enable_value="false"/>
+                                 enable_value="enable_by_preferences"/>
         <sketch-2dpoint_selector id="RectEndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
                                  enable_value="false"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
index c69b6019b66178402ed5428caee05798617e002a..1952e97aa5402b832d221b5bc2adbb57e249ee13 100644 (file)
@@ -10,6 +10,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 
@@ -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<GeomDataAPI_Point2D> anEndAttr = 
         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> 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);
+  }
 }
index 57363add5491597a8bf19d1e81d8cd87cab18cef..8891b3e3492c406f2b0ae2cb034092bb65ce07bf 100644 (file)
@@ -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 (executable)
index 0000000..b40da2e
Binary files /dev/null and b/src/SketchPlugin/icons/distance_value.png differ
index 89b6754ae5e2f305f54c5c73cdcb06ca0b021b70..282c142eb4c880009d50c2db3aeb67de84f52f42 100644 (file)
       <!-- SketchPoint -->
       <feature id="SketchPoint" title="Point" tooltip="Create point" icon="icons/Sketch/point.png">
         <sketch-2dpoint_selector id="PointCoordindates" accept_expressions="0" title="Point" tooltip="Point coordinates"
-                                 enable_value="false"/>
+                                 enable_value="enable_by_preferences"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
       </feature>
       
       <!-- SketchLine -->
       <feature id="SketchLine" title="Line" tooltip="Create line" icon="icons/Sketch/line.png">
         <sketch-2dpoint_selector id="StartPoint" accept_expressions="0" title="Start point" tooltip="Start point coordinates"
-                                 enable_value="false"/>
+                                 enable_value="enable_by_preferences"/>
         <sketch-2dpoint_selector id="EndPoint" accept_expressions="0" title="End point" tooltip="End point coordinates"
-                                 enable_value="false"/>
+                                 enable_value="enable_by_preferences"/>
+        <doublevalue id="LineLength" accept_expressions="0" label="Length:" default="computed" icon="icons/Sketch/distance_value.png"
+                     tooltip="Line length" obligatory="0" enable_value="false"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
         <validator id="GeomValidators_Different" parameters="StartPoint,EndPoint"/>
       </feature>
         <toolbox id="CircleType">
           <box id="CenterRadius" title="Center and radius" icon="icons/Sketch/circle_pt_rad_32x32.png">
             <sketch-2dpoint_selector id="CircleCenter" accept_expressions="0" title="Center" tooltip="Center coordinates"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <point2ddistance id="CircleRadius" accept_expressions="0" first_point="CircleCenter" label="Radius:" min="0" step="1.0"
                              default="0" icon="icons/Sketch/radius.png" tooltip="Set radius"
-                             enable_value="false">
+                             enable_value="enable_by_preferences">
               <validator id="GeomValidators_Positive"/>
             </point2ddistance>
           </box>
           <box id="ThreePoints" title="Three points" icon="icons/Sketch/circle_3pt_32x32.png">
             <sketch-2dpoint_selector id="FirstPoint" accept_expressions="0" title="First point" tooltip="First point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="SecondPoint" accept_expressions="0" title="Second point" tooltip="Second point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="ThirdPoint" accept_expressions="0" title="Third point" tooltip="Third point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
           </box>
         </toolbox>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"/>
         <toolbox id="ArcType">
           <box id="CenterStartEnd" title="Center and two points" icon="icons/Sketch/arc_base_32x32.png">
             <sketch-2dpoint_selector id="ArcCenter" accept_expressions="0" title="Center" tooltip="Center of a circle"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <validator id="GeomValidators_Different" parameters="ArcCenter,ArcStartPoint,ArcEndPoint"/>
           </box>
           <box id="ThreePoints" title="Three points on arc" icon="icons/Sketch/arc_3pt_32x32.png">
             <sketch-2dpoint_selector id="ArcStartPoint" accept_expressions="0" title="Start point" tooltip="Start point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <sketch-2dpoint_selector id="ArcPassedPoint" accept_expressions="0" title="Passed point" tooltip="Passed point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
             <validator id="GeomValidators_Different" parameters="ArcStartPoint,ArcEndPoint,ArcPassedPoint"/>
           </box>
           <box id="Tangent" title="Tangent with edge" icon="icons/Sketch/arc_tang_32x32.png">
               <validator id="SketchPlugin_ArcTangentPoint" parameters="" />
             </sketch_shape_selector>
             <sketch-2dpoint_selector id="ArcEndPoint" accept_expressions="0" title="End point" tooltip="End point"
-                                     enable_value="false"/>
+                                     enable_value="enable_by_preferences"/>
           </box>
         </toolbox>
         <doublevalue id="ArcRadius" accept_expressions="0" label="Radius:" default="computed" icon="icons/Sketch/radius.png"
-                     tooltip="Set radius" obligatory="0" enable_value="false">
+                     tooltip="Set radius" obligatory="0" enable_value="enable_by_preferences">
           <validator id="GeomValidators_Positive"/>
         </doublevalue>
         <doublevalue id="ArcAngle" label="Angle:" icon="icons/Sketch/angle.png" tooltip="Set angle" default="90" use_reset="false" obligatory="0"
-                     enable_value="false"/>
+                     enable_value="enable_by_preferences"/>
         <boolvalue id="Auxiliary" label="Auxiliary" default="false" tooltip="Construction element" obligatory="0"
-                   enable_value="false"/>
+                   enable_value="enable_by_preferences"/>
       </feature>
 
       <!--  SketchConstraintFillet  -->
           <validator id="SketchPlugin_FilletVertexValidator"/>
         </sketch_multi_selector>
         <doublevalue label="Radius" tooltip="Fillet arc radius" id="ConstraintValue" accept_expressions="0" min="0" use_reset="false"
-                     enable_value="false">
+                     enable_value="enable_by_preferences">
           <validator id="GeomValidators_Positive"/>
         </doublevalue>
         <validator id="PartSet_FilletSelection"/>