From fcffa8ae0017bd02ee04bd91de228c65d630d9a1 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 30 Oct 2015 10:27:58 +0300 Subject: [PATCH] LockMgr is removing, ModifiedInViewer widget value state is used instead of it. --- src/ModuleBase/ModuleBase_ModelWidget.cpp | 29 +++++-- src/ModuleBase/ModuleBase_ModelWidget.h | 18 ++++- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 1 + src/PartSet/CMakeLists.txt | 2 - src/PartSet/PartSet_LockApplyMgr.cpp | 78 ------------------- src/PartSet/PartSet_LockApplyMgr.h | 58 -------------- src/PartSet/PartSet_Module.cpp | 12 --- src/PartSet/PartSet_SketcherMgr.cpp | 6 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 12 ++- src/PartSet/PartSet_WidgetPoint2d.h | 2 - src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 12 +-- src/PartSet/PartSet_WidgetPoint2dDistance.h | 4 - src/PartSet/PartSet_WidgetSketchLabel.cpp | 1 + src/XGUI/XGUI_OperationMgr.cpp | 9 +-- src/XGUI/XGUI_OperationMgr.h | 9 --- src/XGUI/XGUI_Workshop.cpp | 2 +- 16 files changed, 54 insertions(+), 201 deletions(-) delete mode 100755 src/PartSet/PartSet_LockApplyMgr.cpp delete mode 100755 src/PartSet/PartSet_LockApplyMgr.h mode change 100644 => 100755 src/PartSet/PartSet_WidgetPoint2d.h mode change 100644 => 100755 src/XGUI/XGUI_OperationMgr.h diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index c84b8e646..7f7e1fa14 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -28,7 +28,8 @@ ModuleBase_ModelWidget::ModuleBase_ModelWidget(QWidget* theParent, : QWidget(theParent), myParentId(theParentId), myIsEditing(false), - myState(Stored) + myState(Stored), + myIsValueStateBlocked(false) { myDefaultValue = theData->getProperty(ATTR_DEFAULT); myUseReset = theData->getBooleanAttribute(ATTR_USE_RESET, true); @@ -128,6 +129,12 @@ void ModuleBase_ModelWidget::activate() activateCustom(); } +void ModuleBase_ModelWidget::deactivate() +{ + myIsValueStateBlocked = false; + myState = Stored; +} + void ModuleBase_ModelWidget::initializeValueByActivate() { if (isComputedDefault()) { @@ -178,13 +185,21 @@ bool ModuleBase_ModelWidget::storeValue() return isDone; } -void ModuleBase_ModelWidget::setValueState(const ValueState& theState) +ModuleBase_ModelWidget::ValueState ModuleBase_ModelWidget::setValueState(const ValueState& theState) { - if (myState == theState) - return; + ValueState aState = myState; + if (myState != theState && !myIsValueStateBlocked) { + myState = theState; + emit valueStateChanged(); + } + return aState; +} - myState = theState; - emit valueStateChanged(); +bool ModuleBase_ModelWidget::blockValueState(const bool theBlocked) +{ + bool isBlocked = myIsValueStateBlocked; + myIsValueStateBlocked = theBlocked; + return isBlocked; } bool ModuleBase_ModelWidget::restoreValue() @@ -256,7 +271,7 @@ void ModuleBase_ModelWidget::onWidgetValuesChanged() //************************************************************** void ModuleBase_ModelWidget::onWidgetValuesModified() { - setValueState(Modified); + setValueState(ModifiedInPP); } //************************************************************** diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index f1d257362..f85549673 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -35,8 +35,9 @@ 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 - Reset }; + ModifiedInPP, /// modification has not been finished and set to the model yet + ModifiedInViewer, /// modification performed by viewer events + Reset }; /// the value is reset /// Constructor /// \param theParent the parent object @@ -114,7 +115,7 @@ Q_OBJECT void activate(); /// The method called when widget is deactivated - virtual void deactivate() {} + virtual void deactivate(); /// Returns list of widget controls /// \return a control list @@ -222,8 +223,15 @@ protected: } /// Sets the current value state. If the value is changed, the signal is emitted + /// If the current value state is Blocked, this method do nothing /// \param theState a new state - void setValueState(const ValueState& theState); + /// \return the previous value state + ValueState setValueState(const ValueState& theState); + + /// Blocks the value state change. + /// \param theBlocked a block state + /// \return the previous value + bool blockValueState(const bool theBlocked); /// Compute the feature default value and fill the controls with it /// or store the control value to the feature @@ -288,6 +296,8 @@ private: /// the reset state. If it is false, the reset method of the widget is not performed bool myUseReset; + /// blocked flag of modification of the value state + bool myIsValueStateBlocked; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 268a2515f..130079870 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -166,6 +166,7 @@ bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrs& t //******************************************************************** void ModuleBase_WidgetSelector::deactivate() { + ModuleBase_ModelWidget::deactivate(); disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); activateSelection(false); activateFilters(false); diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 350924e1f..45ab6dc01 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -23,7 +23,6 @@ SET(PROJECT_HEADERS PartSet_WidgetShapeSelector.h PartSet_WidgetFileSelector.h PartSet_Filters.h - PartSet_LockApplyMgr.h PartSet_FilterInfinite.h PartSet_SketcherMgr.h PartSet_MenuMgr.h @@ -48,7 +47,6 @@ SET(PROJECT_SOURCES PartSet_WidgetShapeSelector.cpp PartSet_WidgetFileSelector.cpp PartSet_Filters.cpp - PartSet_LockApplyMgr.cpp PartSet_FilterInfinite.cpp PartSet_SketcherMgr.cpp PartSet_MenuMgr.cpp diff --git a/src/PartSet/PartSet_LockApplyMgr.cpp b/src/PartSet/PartSet_LockApplyMgr.cpp deleted file mode 100755 index 547d730a9..000000000 --- a/src/PartSet/PartSet_LockApplyMgr.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_LockApplyMgr.cpp -// Created: 25 Jun 2015 -// Author: Natalia Ermolaeva - -#include "PartSet_LockApplyMgr.h" -#include "PartSet_Module.h" - -#include -#include - -#include -#include -#include -#include - -PartSet_LockApplyMgr::PartSet_LockApplyMgr(QObject* theParent, - ModuleBase_IWorkshop* theWorkshop) -: QObject(theParent), myWorkshop(theWorkshop) -{ -} - -void PartSet_LockApplyMgr::activate() -{ - XGUI_ViewerProxy* aViewer = dynamic_cast(myWorkshop->viewer()); - connect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating())); - connect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating())); - - PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - if (aModule->isMouseOverWindow()) - onLockValidating(); -} - -void PartSet_LockApplyMgr::deactivate() -{ - XGUI_ViewerProxy* aViewer = dynamic_cast(myWorkshop->viewer()); - disconnect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating())); - disconnect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating())); - - onUnlockValidating(); -} - -void PartSet_LockApplyMgr::valuesChanged() -{ - operationMgr()->setLockValidating(false); -} - -void PartSet_LockApplyMgr::onLockValidating() -{ - XGUI_OperationMgr* anOperationMgr = operationMgr(); - - anOperationMgr->setLockValidating(true); - // the Ok button should be disabled in the property panel by moving the mouse point in the viewer - // this leads that the user does not try to click Ok and it avoids an incorrect situation that the - // line is moved to the cursor to the Ok button - //anOperationMgr->setApplyEnabled(false); -} - -void PartSet_LockApplyMgr::onUnlockValidating() -{ - XGUI_OperationMgr* anOperationMgr = operationMgr(); - - // it is important to restore the validity state in the property panel after leaving the - // view port. Unlock the validating. - if (anOperationMgr->isValidationLocked()) { - anOperationMgr->setLockValidating(false); - //anOperationMgr->onValidateOperation(); - } -} - -XGUI_OperationMgr* PartSet_LockApplyMgr::operationMgr() const -{ - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - - return aWorkshop->operationMgr(); -} diff --git a/src/PartSet/PartSet_LockApplyMgr.h b/src/PartSet/PartSet_LockApplyMgr.h deleted file mode 100755 index a73cb1437..000000000 --- a/src/PartSet/PartSet_LockApplyMgr.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_LockApplyMgr.h -// Created: 25 Jun 2015 -// Author: Natalia Ermolaeva - -#ifndef PartSet_LockApplyMgr_H -#define PartSet_LockApplyMgr_H - -#include "PartSet.h" - -#include - -class ModuleBase_IWorkshop; -class XGUI_OperationMgr; - -/** -* \ingroup Modules -* Customosation of ModuleBase_WidgetShapeSelector in order to provide -* working with sketch specific objects. -*/ -class PARTSET_EXPORT PartSet_LockApplyMgr : public QObject -{ - Q_OBJECT - -public: - /// Constructor - /// \param theParent a parent object - /// \param theWorkshop a reference to workshop - PartSet_LockApplyMgr(QObject* theParent, - ModuleBase_IWorkshop* theWorkshop); - - virtual ~PartSet_LockApplyMgr() {} - - /// Activates the object - void activate(); - - /// Deactivates the object - void deactivate(); - - /// Unlocks validation in operations manager - void valuesChanged(); - -protected slots: - /// Set lock validating in the operation manager. Set apply is disabled - void onLockValidating(); - - /// Set unlock validating in the operation manager. Call method to update the apply state. - void onUnlockValidating(); - -private: - XGUI_OperationMgr* operationMgr() const; - -private: - ModuleBase_IWorkshop* myWorkshop; // the current application workshop -}; - -#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3ff904eab..c7623e387 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -422,21 +422,9 @@ void PartSet_Module::updateViewerMenu(const QMap& theStdActio QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature) { QString anError = ModuleBase_IModule::getFeatureError(theFeature); - if (anError.isEmpty()) anError = sketchMgr()->getFeatureError(theFeature); - if (anError.isEmpty()) { - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr(); - - if (anOpMgr->isValidationLocked()) { - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (anOpMgr->currentOperation()); - if (!aFOperation || theFeature == aFOperation->feature()) - anError = "Validation is locked by the current operation"; - } - } return anError; } diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 9ea9e0596..03d2cb298 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -694,10 +694,14 @@ QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature) if (anAttr.get()) { QString anAttributeName = anAttr->id().c_str(); switch (aState) { - case ModuleBase_ModelWidget::Modified: + case ModuleBase_ModelWidget::ModifiedInPP: anError = "Attribute \"" + anAttributeName + "\" modification is not applyed. Please click \"Enter\" or \"Tab\"."; break; + case ModuleBase_ModelWidget::ModifiedInViewer: + anError = "Attribute \"" + anAttributeName + + "\" is locked by modification value in the viewer."; + break; case ModuleBase_ModelWidget::Reset: anError = "Attribute \"" + anAttributeName + "\" is not initialized."; break; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 9fbffa98c..8f62484fb 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -7,7 +7,6 @@ #include "PartSet_WidgetPoint2d.h" #include #include -#include #include #include @@ -66,7 +65,6 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, << SketchPlugin_Point::ID().c_str() << SketchPlugin_Circle::ID().c_str(); } - myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop); // the control should accept the focus, so the boolen flag is corrected to be true myIsObligatory = true; @@ -269,12 +267,11 @@ void PartSet_WidgetPoint2D::activateCustom() aModes << TopAbs_VERTEX; aModes << TopAbs_EDGE; myWorkshop->activateSubShapesSelection(aModes); - - myLockApplyMgr->activate(); } void PartSet_WidgetPoint2D::deactivate() { + ModuleBase_ModelWidget::deactivate(); ModuleBase_IViewer* aViewer = myWorkshop->viewer(); disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); @@ -282,8 +279,6 @@ void PartSet_WidgetPoint2D::deactivate() this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); myWorkshop->deactivateSubShapesSelection(); - - myLockApplyMgr->deactivate(); } bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, @@ -438,7 +433,11 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv double aX, anY; PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY); + // we need to block the value state change + bool isBlocked = blockValueState(true); setPoint(aX, anY); + blockValueState(isBlocked); + setValueState(ModifiedInViewer); } double PartSet_WidgetPoint2D::x() const @@ -477,7 +476,6 @@ bool PartSet_WidgetPoint2D::isFeatureContainsPoint(const FeaturePtr& theFeature, void PartSet_WidgetPoint2D::onValuesChanged() { - myLockApplyMgr->valuesChanged(); emit valuesChanged(); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h old mode 100644 new mode 100755 index e56da6bad..b4e45af67 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -22,7 +22,6 @@ class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; class GeomAPI_Pnt2d; class ModuleBase_IWorkshop; -class PartSet_LockApplyMgr; class QGroupBox; class QMouseEvent; @@ -146,7 +145,6 @@ protected: ModuleBase_IWorkshop* myWorkshop; private: - PartSet_LockApplyMgr* myLockApplyMgr; ///< a manager to lock/unlock Apply button in PP QGroupBox* myGroupBox; ///< the parent group box for all intenal widgets ModuleBase_ParamSpinBox* myXSpin; ///< the spin box for the X coordinate diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index 2e665cf97..d2f1a08aa 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -6,7 +6,6 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" -#include "PartSet_LockApplyMgr.h" #include #include @@ -31,8 +30,6 @@ PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, const std::string& theParentId) : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId), myWorkshop(theWorkshop) { - myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop); - myFirstPntName = theData->getProperty("first_point"); // Reconnect to local slot @@ -84,19 +81,16 @@ void PartSet_WidgetPoint2dDistance::activateCustom() this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); - - myLockApplyMgr->activate(); } void PartSet_WidgetPoint2dDistance::deactivate() { + ModuleBase_ModelWidget::deactivate(); ModuleBase_IViewer* aViewer = myWorkshop->viewer(); disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); - - myLockApplyMgr->deactivate(); } void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) @@ -132,12 +126,14 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); std::shared_ptr aPnt = std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); + bool isBlocked = blockValueState(true); setPoint(feature(), aPnt); + blockValueState(isBlocked); + setValueState(ModifiedInViewer); } void PartSet_WidgetPoint2dDistance::onValuesChanged() { - myLockApplyMgr->valuesChanged(); emit valuesChanged(); } diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index 857212aca..472561804 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -12,7 +12,6 @@ #include -class PartSet_LockApplyMgr; class GeomAPI_Pnt2d; class ModuleBase_IWorkshop; class ModuleBase_IViewWindow; @@ -96,9 +95,6 @@ protected: /// A reference to workshop ModuleBase_IWorkshop* myWorkshop; - /// A manager to lock/unlock Apply button in PP - PartSet_LockApplyMgr* myLockApplyMgr; - /// A name of the first point std::string myFirstPntName; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e4d837508..18324da4d 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -296,6 +296,7 @@ void PartSet_WidgetSketchLabel::activateCustom() void PartSet_WidgetSketchLabel::deactivate() { + ModuleBase_ModelWidget::deactivate(); erasePreviewPlanes(); activateSelection(false); diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 6732dec51..e169adcd5 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -27,8 +27,7 @@ XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) -: QObject(theParent), myIsValidationLock(false), myIsApplyEnabled(false), - myWorkshop(theWorkshop) +: QObject(theParent), myIsApplyEnabled(false), myWorkshop(theWorkshop) { } @@ -200,12 +199,6 @@ void XGUI_OperationMgr::onValidateOperation() setApplyEnabled(myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()); } -void XGUI_OperationMgr::setLockValidating(bool toLock) -{ - myIsValidationLock = toLock; - onValidateOperation(); -} - void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled) { myIsApplyEnabled = theEnabled; diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h old mode 100644 new mode 100755 index 66e14f732..0cda5543c --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -98,13 +98,6 @@ Q_OBJECT /// \param theOperation an aborted operation void abortOperation(ModuleBase_Operation* theOperation); - /// Blocking/unblocking enabling of Ok button in property panel. - /// It is used when operation can not be validated even all attributes are valid - void setLockValidating(bool toLock); - - /// Returns state of validation locking - bool isValidationLocked() const { return myIsValidationLock; } - /// Returns enable apply state /// \return theEnabled a boolean value bool isApplyEnabled() const; @@ -222,8 +215,6 @@ private: /// Current workshop ModuleBase_IWorkshop* myWorkshop; - /// Lock/Unlock access to Ok button in property panel - bool myIsValidationLock; /// Lock/Unlock access to Ok button in property panel bool myIsApplyEnabled; }; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index a36332730..ceb3f817d 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -874,7 +874,7 @@ void XGUI_Workshop::onValueStateChanged() if (aPanel) anActiveWidget = aPanel->activeWidget(); } - if (anActiveWidget && anActiveWidget->getValueState() != ModuleBase_ModelWidget::Stored) + if (anActiveWidget) operationMgr()->onValidateOperation(); ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule) { -- 2.39.2