From cc7dddbfef7793f198de90ec08978e07132e0237 Mon Sep 17 00:00:00 2001 From: sbh Date: Wed, 10 Sep 2014 20:24:45 +0400 Subject: [PATCH] Issue #115 The "computed" xml attribute processing --- src/Config/Config_Keywords.h | 3 ++- src/Config/Config_WidgetAPI.h | 16 ++++++++++------ src/ModelAPI/ModelAPI_Attribute.h | 15 +++++++++++++++ src/ModuleBase/ModuleBase_ModelWidget.cpp | 7 +++++++ src/ModuleBase/ModuleBase_ModelWidget.h | 11 +++++++++++ src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp | 4 +++- src/ModuleBase/ModuleBase_WidgetEditor.cpp | 7 ------- src/ModuleBase/ModuleBase_WidgetFactory.cpp | 3 --- src/SketchPlugin/plugin-Sketch.xml | 2 +- src/XGUI/XGUI_Workshop.cpp | 5 +---- 10 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index 32b1e00b3..8fbcd49a3 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -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"; diff --git a/src/Config/Config_WidgetAPI.h b/src/Config/Config_WidgetAPI.h index ad084049f..02131a2de 100644 --- a/src/Config/Config_WidgetAPI.h +++ b/src/Config/Config_WidgetAPI.h @@ -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_ */ diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index a73044d4a..e868e0d31 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -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; } diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 6ad8f5205..11d5f15fc 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -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 aControls = getControls(); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 4b1940ad5..9e790a336 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 35641c2a5..692c94904 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -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()); diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index b42e84017..e010f40d0 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -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() { } diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index cbe5a9939..0da092c30 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -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); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index a077a466c..4a0088d51 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -60,7 +60,7 @@ - + diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d6d88a0da..0668917e2 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(); } } -- 2.39.2