From c8c9358243b42722b276b90ce34ac05bce42607f 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 80737131f..49f2588d1 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -101,7 +101,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 68b928a8c..bb1d4a4d1 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -99,7 +99,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 8df4df97c..a67a74a93 100644 --- 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())) @@ -709,7 +709,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()); @@ -730,14 +730,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; + } + } } } } @@ -956,7 +967,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(); @@ -1099,7 +1110,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); @@ -1401,8 +1412,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 181378e04..6662ab7eb 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