Salome HOME
Issue #115 The "computed" xml attribute processing
authorsbh <sergey.belash@opencascade.com>
Wed, 10 Sep 2014 16:24:45 +0000 (20:24 +0400)
committersbh <sergey.belash@opencascade.com>
Wed, 10 Sep 2014 16:24:45 +0000 (20:24 +0400)
src/Config/Config_Keywords.h
src/Config/Config_WidgetAPI.h
src/ModelAPI/ModelAPI_Attribute.h
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/ModuleBase/ModuleBase_WidgetFactory.cpp
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_Workshop.cpp

index 32b1e00b370660869dc172d2e24922bb746fbabd..8fbcd49a3bf85fe8932612ff718675b37f72f802 100644 (file)
@@ -63,7 +63,8 @@ const static char* INFO_WDG_TOOLTIP = FEATURE_TOOLTIP;
 const static char* DOUBLE_WDG_MIN = "min";
 const static char* DOUBLE_WDG_MAX = "max";
 const static char* DOUBLE_WDG_STEP = "step";
-const static char* DOUBLE_WDG_DFLT = "default";
+const static char* DOUBLE_WDG_DEFAULT = "default";
+const static char* DOUBLE_WDG_DEFAULT_COMPUTED = "computed";
 
 //toolbox/switch properties
 const static char* CONTAINER_PAGE_NAME = "title";
index ad084049f76e147a9b0e468684e9a7694fceccaf..02131a2debd86ef7c9d8867c873676be6b6820fe 100644 (file)
@@ -28,14 +28,8 @@ struct _xmlDoc;
 class CONFIG_EXPORT Config_WidgetAPI
 {
  public:
-  Config_WidgetAPI(std::string theRawXml);
   virtual ~Config_WidgetAPI();
 
-  //TODO(sbh): Make these fields protected, accessible only for WidgetFactory
-  bool toNextWidget();
-  bool toChildWidget();
-  bool toParentWidget();
-
   std::string widgetType() const;
   bool isContainerWidget() const;
   bool isPagedWidget() const;
@@ -47,10 +41,20 @@ class CONFIG_EXPORT Config_WidgetAPI
 
   std::string getProperty(const char* thePropName) const;
 
+  bool isComputedDefault() const;
+
+ protected:
+  /// These fields are accessible for ModuleBase_WidgetFactory only
+  Config_WidgetAPI(std::string theRawXml);
+  bool toNextWidget();
+  bool toChildWidget();
+  bool toParentWidget();
+
  private:
   xmlDocPtr myDoc;
   xmlNodePtr myCurrentNode;
 
+  friend class ModuleBase_WidgetFactory;
 };
 
 #endif /* CONFIG_WIDGETAPI_H_ */
index a73044d4a1ebcd57319cc2cd3548bb3ef7e55f9f..e868e0d31b3a73d461eb385989a301f33d82ae4d 100644 (file)
@@ -22,6 +22,7 @@ class ModelAPI_Attribute
  protected:
   // accessible from the attributes
   bool myIsInitialized;
+  bool myIsComputedDefault;
   bool myIsArgument;
  public:
 
@@ -57,6 +58,19 @@ class ModelAPI_Attribute
     myIsInitialized = true;
   }
 
+  /// Returns true if attribute's default value was computed
+  MODELAPI_EXPORT bool isComputedDefault()
+  {
+    return myIsComputedDefault;
+  }
+
+  /// Tells that attribute's default value was computed
+  MODELAPI_EXPORT void setComputedDefault()
+  {
+    myIsComputedDefault = true;
+    myIsInitialized = false;
+  }
+
   /// Set this attribute is argument for result (change of this attribute requires update of result).
   /// By default it is true.
   MODELAPI_EXPORT void setIsArgument(const bool theFlag)
@@ -75,6 +89,7 @@ class ModelAPI_Attribute
   ModelAPI_Attribute()
   {
     myIsInitialized = false;
+    myIsComputedDefault = false;
     myIsArgument = true;
   }
 
index 6ad8f52054e0d506b402cffcfeb092dcceccf833..11d5f15fc8f4fba2d437622e1307ae110888dd25 100644 (file)
@@ -19,6 +19,7 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QObject* theParent, const Config_
     : QObject(theParent),
       myParentId(theParentId)
 {
+  myIsComputedDefault = false;
   myAttributeID = theData ? theData->widgetId() : "";
 }
 
@@ -27,6 +28,12 @@ bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const
   return theObject->data()->attribute(attributeID())->isInitialized();
 }
 
+void ModuleBase_ModelWidget::setAttributeComputedState(ObjectPtr theObject) const
+{
+  if(myIsComputedDefault)
+    theObject->data()->attribute(attributeID())->setComputedDefault();
+}
+
 bool ModuleBase_ModelWidget::focusTo()
 {
   QList<QWidget*> aControls = getControls();
index 4b1940ad5f3961ef94ade0a56fcfbd5eda2f1ffc..9e790a3361c3490c56f22638d599e6e4c80bf5c2 100644 (file)
@@ -52,6 +52,13 @@ Q_OBJECT
   /// \return the boolean result
   bool isInitialized(ObjectPtr theObject) const;
 
+  void setAttributeComputedState(ObjectPtr theObject) const;
+
+  bool isComputedDefault()
+  {
+    return myIsComputedDefault;
+  }
+
   /// Saves the internal parameters to the given feature
   /// \param theObject a model feature to be changed
   virtual bool storeValue() const = 0;
@@ -88,6 +95,8 @@ Q_OBJECT
   void setFeature(const FeaturePtr& theFeature)
   {
     myFeature = theFeature;
+    if(theFeature)
+     setAttributeComputedState(theFeature);
   }
 
 signals:
@@ -114,6 +123,8 @@ signals:
   std::string myAttributeID;  /// the attribute name of the model feature
   std::string myParentId;    /// name of parent
   FeaturePtr myFeature;
+
+  bool myIsComputedDefault;
 };
 
 #endif
index 35641c2a50e8e6ba0ef8dd452465fa239db6b1bb..692c949042868d2433ff502cc6d84177c21f347e 100644 (file)
@@ -67,10 +67,12 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
     mySpinBox->setSingleStep(aStepVal);
   }
 
-  aProp = theData->getProperty(DOUBLE_WDG_DFLT);
+  aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
   double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
   if (isOk) {
     mySpinBox->setValue(aDefVal);
+  } else if (aProp == DOUBLE_WDG_DEFAULT_COMPUTED){
+    myIsComputedDefault = true;
   }
 
   QString aTTip = QString::fromStdString(theData->widgetTooltip());
index b42e8401797c260b8450242e57db5a550f19b9a7..e010f40d062656997bc27c63a33357cf501b9fdf 100644 (file)
@@ -31,13 +31,6 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
 {
 }
 
-ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
-                                                 const std::string& theAttribute)
-    : ModuleBase_WidgetDoubleValue(theParent, 0, "")
-{
-  setAttributeID(theAttribute);
-}
-
 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
 }
index cbe5a9939e34712f06d310b761d88c7ab6adc993..0da092c300e1121ba9509b7dbe05a0a064c081dc 100644 (file)
@@ -143,9 +143,6 @@ QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType
   } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
     result = doubleValueEditor(theParent);
 
-  } else if (theType == WDG_DOUBLEVALUE_EDITOR) {
-    result = doubleValueEditor(theParent);
-
   } else if (theType == WDG_POINT2D_DISTANCE) {
     result = point2dDistanceControl(theParent);
 
index a077a466cc7a1e48273d86acbd007b14f58e1b2f..4a0088d51e27bcba6eb266a9e40c8a54e35348a2 100644 (file)
@@ -60,7 +60,7 @@
           <validator id="SketchPlugin_ResultArcValidator"/>
         </feature_selector>
         <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
-        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue"/>
+        <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
         <validator id="PartSet_RadiusValidator"/>
       </feature>
       
index d6d88a0da5b193b485a53421902aba06abbaae04..0668917e20e15d1c373136e67c467b8286b81a4e 100644 (file)
@@ -428,12 +428,9 @@ void XGUI_Workshop::onOperationStarted()
     for (; anIt != aLast; anIt++) {
       aWidget = *anIt;
       aWidget->setFeature(aOperation->feature());
-      //QObject::connect(aWidget, SIGNAL(valuesChanged()),  aOperation, SLOT(storeCustomValue()));
       QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
       // Init default values
-      if (!aOperation->isEditOperation()) {
-        //aWidget->storeValue(aOperation->feature());
-
+      if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
         aWidget->storeValue();
       }
     }