From 6ba91abafa6c5c5b22931229b16cf6146ada809d Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 16 Oct 2015 08:08:25 +0300 Subject: [PATCH] Reset value state is provided in ModelWidget to remove 'myIsResetCurrentValue' in sketch manager. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 9 ++++ src/ModuleBase/ModuleBase_ModelWidget.h | 13 ++++-- .../ModuleBase_WidgetDoubleValue.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetDoubleValue.h | 7 ++-- src/ModuleBase/ModuleBase_WidgetIntValue.cpp | 2 +- src/ModuleBase/ModuleBase_WidgetIntValue.h | 8 ++-- src/PartSet/PartSet_SketcherMgr.cpp | 41 ++++++++++++------- src/PartSet/PartSet_WidgetPoint2d.cpp | 2 +- src/PartSet/PartSet_WidgetPoint2d.h | 7 ++-- 9 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index b094366d5..66fe88f12 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -40,6 +40,15 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, connect(this, SIGNAL(valuesModified()), this, SLOT(onWidgetValuesModified())); } +bool ModuleBase_ModelWidget::reset() +{ + bool aResult = resetCustom(); + if (aResult) + setValueState(Reset); + + return aResult; +} + bool ModuleBase_ModelWidget::isInitialized(ObjectPtr theObject) const { return theObject->data()->attribute(attributeID())->isInitialized(); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index edfd1bec2..8804fdbeb 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -35,8 +35,8 @@ Q_OBJECT public: /// State of the widget enum ValueState { Stored, /// modification is finished and applyed to the model - Modified /// modification has not been finished and set to the model yet - }; + Modified, /// modification has not been finished and set to the model yet + Reset }; /// Constructor /// \param theParent the parent object @@ -49,9 +49,10 @@ Q_OBJECT { } - /// Fills the widget with default values + /// Fills the widget with default values. It calls the resetCustom method and change + /// the widget state to Reset if the reset is performed. /// \return true if the widget current value is reset - virtual bool reset() { return false; }; + bool reset(); /// Returns the state whether the attribute of the feature is initialized /// \param theObject a model feature to be checked @@ -227,6 +228,10 @@ protected: /// Restore value from attribute data to the widget's control virtual bool restoreValueCustom() = 0; + /// Fills the widget with default values + /// \return true if the widget current value is reset + virtual bool resetCustom() { return false; }; + /// The method called when widget is activated virtual void activateCustom() {}; diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 5f9dc8a5b..997554cc1 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -102,7 +102,7 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue() { } -bool ModuleBase_WidgetDoubleValue::reset() +bool ModuleBase_WidgetDoubleValue::resetCustom() { bool aDone = false; if (!isUseReset() || isComputedDefault() || mySpinBox->hasVariable()) { diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 04e871795..ec3daae2c 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -37,9 +37,6 @@ Q_OBJECT virtual ~ModuleBase_WidgetDoubleValue(); - /// Fills the widget with default values - virtual bool reset(); - /// Returns list of widget controls /// \return a control list virtual QList getControls() const; @@ -61,6 +58,10 @@ protected: // \return True in success virtual bool restoreValueCustom(); + /// Fills the widget with default values + /// \return true if the widget current value is reset + virtual bool resetCustom(); + protected: /// Label of the widget QLabel* myLabel; diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp index 005a45100..cb6986301 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -100,7 +100,7 @@ ModuleBase_WidgetIntValue::~ModuleBase_WidgetIntValue() { } -bool ModuleBase_WidgetIntValue::reset() +bool ModuleBase_WidgetIntValue::resetCustom() { bool aDone = false; if (!isUseReset() || isComputedDefault()) { diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.h b/src/ModuleBase/ModuleBase_WidgetIntValue.h index 255e71603..8fd1ef5d8 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.h +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.h @@ -37,14 +37,10 @@ Q_OBJECT virtual ~ModuleBase_WidgetIntValue(); - /// Fills the widget with default values - virtual bool reset(); - /// Returns list of widget controls /// \return a control list virtual QList getControls() const; - protected: /// Saves the internal parameters to the given feature /// \return True in success @@ -54,6 +50,10 @@ protected: // \return True in success virtual bool restoreValueCustom(); + /// Fills the widget with default values + /// \return true if the widget current value is reset + virtual bool resetCustom(); + protected: /// Label of the widget QLabel* myLabel; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index b8374fd4e..f89de6f2d 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -152,7 +152,7 @@ void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner, PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), - myIsResetCurrentValue(false), myIsMouseOverWindow(false), + /*myIsResetCurrentValue(false), */myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), myIsPopupMenuActive(false), myIsConstraintsShown(true) { @@ -191,7 +191,7 @@ void PartSet_SketcherMgr::onEnterViewPort() // the mouse move and use the cursor position to update own values. If the presentaion is // redisplayed before this update, the feature presentation jumps from reset value to current. myIsMouseOverWindow = true; - myIsResetCurrentValue = false; + //myIsResetCurrentValue = false; //myIsCurrentValueUnderModification = false; // it is important to validate operation here only if sketch entity create operation is active // because at this operation we reacts to the mouse leave/enter view port @@ -263,7 +263,7 @@ void PartSet_SketcherMgr::onLeaveViewPort() bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false); ModuleBase_ModelWidget* anActiveWidget = getActiveWidget(); if (anActiveWidget && anActiveWidget->reset()) { - myIsResetCurrentValue = true; + //myIsResetCurrentValue = true; } aDisplayer->enableUpdateViewer(isEnableUpdateViewer); @@ -293,7 +293,7 @@ void PartSet_SketcherMgr::onValueStateChanged() void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel() { - myIsResetCurrentValue = false; + //myIsResetCurrentValue = false; //myIsCurrentValueUnderModification = false; if (isNestedCreateOperation(getCurrentOperation())) @@ -716,7 +716,7 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR()); anError = aAttributeString->value().c_str(); } - else if (myIsResetCurrentValue /*|| myIsCurrentValueUnderModification*/) { + /*else if (myIsResetCurrentValue /*|| myIsCurrentValueUnderModification*+/) { // this flags do not allow commit of the current operation ModuleBase_OperationFeature* aFOperation = dynamic_cast (getCurrentOperation()); @@ -737,14 +737,25 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) //} } } - } + }*/ else { ModuleBase_ModelWidget* anActiveWidget = getActiveWidget(); - if (anActiveWidget && anActiveWidget->getValueState() != ModuleBase_ModelWidget::Stored) { - AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID()); - if (anAttr.get()) { - QString anAttributeName = anAttr->id().c_str(); - anError = "Attribute \"" + anAttributeName + "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; + if (anActiveWidget) { + ModuleBase_ModelWidget::ValueState aState = anActiveWidget->getValueState(); + if (aState != ModuleBase_ModelWidget::Stored) { + AttributePtr anAttr = anActiveWidget->feature()->attribute(anActiveWidget->attributeID()); + if (anAttr.get()) { + QString anAttributeName = anAttr->id().c_str(); + switch (aState) { + case ModuleBase_ModelWidget::Modified: + anError = "Attribute \"" + anAttributeName + + "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; + break; + case ModuleBase_ModelWidget::Reset: + anError = "Attribute \"" + anAttributeName + "\" is not initialized."; + break; + } + } } } } @@ -963,7 +974,7 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) { connectToPropertyPanel(false); - myIsResetCurrentValue = false; + //myIsResetCurrentValue = false; //myIsCurrentValueUnderModification = false; myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); @@ -1106,7 +1117,7 @@ bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const if (!aCanDisplay) { ModuleBase_ModelWidget* anActiveWidget = getActiveWidget(); bool isValueStored = anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored; - aCanDisplay = !myIsResetCurrentValue && isValueStored; + aCanDisplay = /*!myIsResetCurrentValue &&*/isValueStored; } return aCanDisplay; //return myIsMouseOverWindow || (!myIsResetCurrentValue && !myIsCurrentValueUnderModification); @@ -1408,8 +1419,8 @@ void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn) QString PartSet_SketcherMgr::mouseOverWindowFlagsInfo() const { - return QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2") - .arg(myIsResetCurrentValue).arg(myIsMouseOverWindow); + return "";//QString("myIsResetCurrentValue = %1, myIsMouseOverWindow = %2") + //.arg(myIsResetCurrentValue).arg(myIsMouseOverWindow); } XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 09dff2d14..e69c62cc3 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -123,7 +123,7 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, setLayout(aLayout); } -bool PartSet_WidgetPoint2D::reset() +bool PartSet_WidgetPoint2D::resetCustom() { bool aDone = false; if (!isUseReset() || isComputedDefault() || myXSpin->hasVariable() || myYSpin->hasVariable()) { diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 93921a544..ae3ca08b2 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -50,9 +50,6 @@ Q_OBJECT /// Destructor virtual ~PartSet_WidgetPoint2D(); - /// Fills the widget with default values - virtual bool reset(); - /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValues the wrapped widget values @@ -113,6 +110,10 @@ protected: virtual bool restoreValueCustom(); + /// Fills the widget with default values + /// \return true if the widget current value is reset + virtual bool resetCustom(); + /// The methiod called when widget is activated virtual void activateCustom(); -- 2.39.2