From 1a8c8a00b92c34aafcecb6109865fc44d94c09af Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 26 Jun 2015 10:36:17 +0300 Subject: [PATCH] Apply disable state correction in distance/angle controls. --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_LockApplyMgr.cpp | 78 +++++++++++++++++++ src/PartSet/PartSet_LockApplyMgr.h | 52 +++++++++++++ src/PartSet/PartSet_Module.cpp | 27 +++---- src/PartSet/PartSet_WidgetPoint2d.cpp | 63 +++++---------- src/PartSet/PartSet_WidgetPoint2d.h | 22 ++---- src/PartSet/PartSet_WidgetPoint2dAngle.cpp | 3 +- src/PartSet/PartSet_WidgetPoint2dAngle.h | 7 +- src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 31 ++++---- src/PartSet/PartSet_WidgetPoint2dDistance.h | 21 +++-- src/XGUI/XGUI_OperationMgr.cpp | 10 ++- src/XGUI/XGUI_OperationMgr.h | 10 +-- 12 files changed, 216 insertions(+), 110 deletions(-) create mode 100755 src/PartSet/PartSet_LockApplyMgr.cpp create mode 100755 src/PartSet/PartSet_LockApplyMgr.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 8148df0a0..f86ae4385 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -20,6 +20,7 @@ SET(PROJECT_HEADERS PartSet_WidgetShapeSelector.h PartSet_WidgetFileSelector.h PartSet_Filters.h + PartSet_LockApplyMgr.h PartSet_FilterInfinite.h PartSet_SketcherMgr.h PartSet_MenuMgr.h @@ -43,6 +44,7 @@ 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 new file mode 100755 index 000000000..547d730a9 --- /dev/null +++ b/src/PartSet/PartSet_LockApplyMgr.cpp @@ -0,0 +1,78 @@ +// 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 new file mode 100755 index 000000000..bf6fed7dd --- /dev/null +++ b/src/PartSet/PartSet_LockApplyMgr.h @@ -0,0 +1,52 @@ +// 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 theExternal the external state + /// \param theDefaultValue the default value for the external object using + PartSet_LockApplyMgr(QObject* theParent, + ModuleBase_IWorkshop* theWorkshop); + + virtual ~PartSet_LockApplyMgr() {} + + void activate(); + void deactivate(); + 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 096c090f2..d90aec240 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -477,48 +477,49 @@ void PartSet_Module::onVertexSelected() ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, Config_WidgetAPI* theWidgetApi, std::string theParentId) { - XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); - XGUI_Workshop* aWorkshop = aConnector->workshop(); + ModuleBase_IWorkshop* aWorkshop = workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Workshop* aXUIWorkshop = aConnector->workshop(); ModuleBase_ModelWidget* aWgt = NULL; if (theType == "sketch-start-label") { PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId, mySketchMgr->isConstraintsShown()); - aLabelWgt->setWorkshop(aWorkshop); + aLabelWgt->setWorkshop(aXUIWorkshop); connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr&)), mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr&))); connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)), mySketchMgr, SLOT(onShowConstraintsToggle(bool))); aWgt = aLabelWgt; } else if (theType == "sketch-2dpoint_selector") { - PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId); - aPointWgt->setWorkshop(aWorkshop); + PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop, + theWidgetApi, theParentId); aPointWgt->setSketch(mySketchMgr->activeSketch()); connect(aPointWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected())); aWgt = aPointWgt; } else if (theType == "point2ddistance") { - PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId); - aDistanceWgt->setWorkshop(aWorkshop); + PartSet_WidgetPoint2dDistance* aDistanceWgt = new PartSet_WidgetPoint2dDistance(theParent, + aWorkshop, theWidgetApi, theParentId); aDistanceWgt->setSketch(mySketchMgr->activeSketch()); aWgt = aDistanceWgt; } else if(theType == "point2dangle") { - PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, theWidgetApi, theParentId); - anAngleWgt->setWorkshop(aWorkshop); + PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, + aWorkshop, theWidgetApi, theParentId); anAngleWgt->setSketch(mySketchMgr->activeSketch()); aWgt = anAngleWgt; } else if (theType == "sketch_shape_selector") { PartSet_WidgetShapeSelector* aShapeSelectorWgt = - new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId); + new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId); aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); aWgt = aShapeSelectorWgt; } else if (theType == "sketch_multi_selector") { PartSet_WidgetMultiSelector* aShapeSelectorWgt = - new PartSet_WidgetMultiSelector(theParent, workshop(), theWidgetApi, theParentId); + new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi, theParentId); aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); aWgt = aShapeSelectorWgt; } else if (theType == WDG_DOUBLEVALUE_EDITOR) { - aWgt = new PartSet_WidgetEditor(theParent, workshop(), theWidgetApi, theParentId); + aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi, theParentId); } else if (theType == "export_file_selector") { - aWgt = new PartSet_WidgetFileSelector(theParent, workshop(), theWidgetApi, theParentId); + aWgt = new PartSet_WidgetFileSelector(theParent, aWorkshop, theWidgetApi, theParentId); } else if (theType == "sketch_launcher") { aWgt = new PartSet_WidgetSketchCreator(theParent, this, theWidgetApi, theParentId); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 964303fcd..6ad84d8fe 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -7,17 +7,13 @@ #include "PartSet_WidgetPoint2d.h" #include #include - -#include -#include -#include -#include -#include -#include +#include #include #include +#include #include +#include #include #include @@ -52,10 +48,13 @@ const double MaxCoordinate = 1e12; PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId), myWorkshop(theWorkshop) { + myLockApplyMgr = new PartSet_LockApplyMgr(theParent, myWorkshop); + // the control should accept the focus, so the boolen flag is corrected to be true myIsObligatory = true; //myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM); @@ -211,36 +210,31 @@ QList PartSet_WidgetPoint2D::getControls() const void PartSet_WidgetPoint2D::activateCustom() { - XGUI_ViewerProxy* aViewer = myWorkshop->viewer(); + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); - connect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating())); - connect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating())); QIntList aModes; aModes << TopAbs_VERTEX; aModes << TopAbs_EDGE; - myWorkshop->moduleConnector()->activateSubShapesSelection(aModes); + myWorkshop->activateSubShapesSelection(aModes); - PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); - if (aModule->isMouseOverWindow()) - onLockValidating(); + myLockApplyMgr->activate(); } void PartSet_WidgetPoint2D::deactivate() { ModuleBase_IViewer* aViewer = myWorkshop->viewer(); - disconnect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + 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*))); - disconnect(aViewer, SIGNAL(enterViewPort()), this, SLOT(onLockValidating())); - disconnect(aViewer, SIGNAL(leaveViewPort()), this, SLOT(onUnlockValidating())); - myWorkshop->moduleConnector()->deactivateSubShapesSelection(); - onUnlockValidating(); + myWorkshop->deactivateSubShapesSelection(); + + myLockApplyMgr->deactivate(); } bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, @@ -268,7 +262,7 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous if (theEvent->button() != Qt::LeftButton) return; - XGUI_Selection* aSelection = myWorkshop->selector()->selection(); + ModuleBase_ISelection* aSelection = myWorkshop->selection(); Handle(V3d_View) aView = theWnd->v3dView(); // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing. NCollection_List aShapes; @@ -357,27 +351,6 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv setPoint(aX, anY); } -void PartSet_WidgetPoint2D::onLockValidating() -{ - XGUI_OperationMgr* anOperationMgr = myWorkshop->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_WidgetPoint2D::onUnlockValidating() -{ - // it is important to restore the validity state in the property panel after leaving the - // view port. Unlock the validating. - XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); - if (anOperationMgr->isValidationLocked()) { - anOperationMgr->setLockValidating(false); - anOperationMgr->onValidateOperation(); - } -} - double PartSet_WidgetPoint2D::x() const { return myXSpin->value(); @@ -390,6 +363,6 @@ double PartSet_WidgetPoint2D::y() const void PartSet_WidgetPoint2D::onValuesChanged() { - myWorkshop->operationMgr()->setLockValidating(false); + myLockApplyMgr->valuesChanged(); emit valuesChanged(); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 21f9738b4..473eccfed 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -21,7 +21,8 @@ class ModuleBase_IWorkshop; class ModuleBase_ParamSpinBox; class ModuleBase_IViewWindow; class GeomAPI_Pnt2d; -class XGUI_Workshop; +class ModuleBase_IWorkshop; +class PartSet_LockApplyMgr; class QGroupBox; class QMouseEvent; @@ -40,9 +41,11 @@ Q_OBJECT public: /// Constructor /// \param theParent the parent object + /// \param theWorkshop a current workshop /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute - PartSet_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, + PartSet_WidgetPoint2D(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId); /// Destructor virtual ~PartSet_WidgetPoint2D(); @@ -66,12 +69,6 @@ Q_OBJECT /// The methiod called when widget is deactivated virtual void deactivate(); - /// Return workshop - XGUI_Workshop* workshop() const { return myWorkshop; } - - /// Set workshop - void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } - /// \returns the sketch instance CompositeFeaturePtr sketch() const { return mySketch; } @@ -106,12 +103,6 @@ protected slots: /// \param theEvent a mouse event void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent); - // 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(); - protected: /// Saves the internal parameters to the given feature /// \return True in success @@ -133,7 +124,8 @@ private slots: bool getPoint2d(const Handle(V3d_View)& theView, const TopoDS_Shape& theShape, double& theX, double& theY) const; - XGUI_Workshop* myWorkshop; + ModuleBase_IWorkshop* myWorkshop; + 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_WidgetPoint2dAngle.cpp b/src/PartSet/PartSet_WidgetPoint2dAngle.cpp index b014d34b4..06e9b4386 100644 --- a/src/PartSet/PartSet_WidgetPoint2dAngle.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dAngle.cpp @@ -24,9 +24,10 @@ #define PI 3.1415926535897932 PartSet_WidgetPoint2dAngle::PartSet_WidgetPoint2dAngle(QWidget* theParent, + ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, const std::string& theParentId) -: PartSet_WidgetPoint2dDistance(theParent, theData, theParentId) +: PartSet_WidgetPoint2dDistance(theParent, theWorkshop, theData, theParentId) { } diff --git a/src/PartSet/PartSet_WidgetPoint2dAngle.h b/src/PartSet/PartSet_WidgetPoint2dAngle.h index 6dac991b2..93e4fdd78 100644 --- a/src/PartSet/PartSet_WidgetPoint2dAngle.h +++ b/src/PartSet/PartSet_WidgetPoint2dAngle.h @@ -12,6 +12,8 @@ #include +class ModuleBase_IWorkshop; + class GeomAPI_Pnt2d; /** @@ -25,10 +27,11 @@ Q_OBJECT public: /// Constructor /// \param theParent the parent object + /// \param theWorkshop a current workshop /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute - PartSet_WidgetPoint2dAngle(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); + PartSet_WidgetPoint2dAngle(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~PartSet_WidgetPoint2dAngle(); diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index f4c5bc6d1..3dfefe349 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -6,16 +6,14 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include "PartSet_LockApplyMgr.h" #include +#include #include +#include #include -#include -#include -#include -#include - #include #include #include @@ -26,10 +24,13 @@ #include PartSet_WidgetPoint2dDistance::PartSet_WidgetPoint2dDistance(QWidget* theParent, - const Config_WidgetAPI* theData, - const std::string& theParentId) - : ModuleBase_WidgetDoubleValue(theParent, theData, theParentId) + ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + 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 @@ -78,11 +79,13 @@ double PartSet_WidgetPoint2dDistance::computeValue(const std::shared_ptrviewer(); - connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), + ModuleBase_IViewer* aViewer = myWorkshop->viewer(); + connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 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() @@ -92,7 +95,8 @@ void PartSet_WidgetPoint2dDistance::deactivate() this, SLOT(onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*))); disconnect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), this, SLOT(onMouseRelease(ModuleBase_IViewWindow*, QMouseEvent*))); - myWorkshop->operationMgr()->setLockValidating(false); + + myLockApplyMgr->deactivate(); } void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) @@ -122,9 +126,6 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, if (mySpinBox->hasVariable()) return; - myWorkshop->operationMgr()->setLockValidating(true); - myWorkshop->operationMgr()->setApplyEnabled(false); - gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); double aX, aY; @@ -136,7 +137,7 @@ void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, void PartSet_WidgetPoint2dDistance::onValuesChanged() { - myWorkshop->operationMgr()->setLockValidating(false); + myLockApplyMgr->valuesChanged(); emit valuesChanged(); } diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.h b/src/PartSet/PartSet_WidgetPoint2dDistance.h index c3020e3a9..5db72e573 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.h +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.h @@ -12,8 +12,9 @@ #include +class PartSet_LockApplyMgr; class GeomAPI_Pnt2d; -class XGUI_Workshop; +class ModuleBase_IWorkshop; class ModuleBase_IViewWindow; class QMouseEvent; @@ -40,10 +41,12 @@ Q_OBJECT public: /// Constructor /// \param theParent the parent object + /// \param theWorkshop a current workshop /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute - PartSet_WidgetPoint2dDistance(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); + PartSet_WidgetPoint2dDistance(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, + const Config_WidgetAPI* theData, + const std::string& theParentId); virtual ~PartSet_WidgetPoint2dDistance(); @@ -53,13 +56,6 @@ Q_OBJECT /// The methiod called when widget is deactivated virtual void deactivate(); - /// Returns workshop - XGUI_Workshop* workshop() const { return myWorkshop; } - - /// Set workshop - /// \param theWork a pointer to workshop - void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; } - /// \returns the sketch instance CompositeFeaturePtr sketch() const { return mySketch; } @@ -97,9 +93,10 @@ private slots: void onValuesChanged(); protected: - XGUI_Workshop* myWorkshop; - std::string myFirstPntName; + ModuleBase_IWorkshop* myWorkshop; + PartSet_LockApplyMgr* myLockApplyMgr; ///< a manager to lock/unlock Apply button in PP + std::string myFirstPntName; CompositeFeaturePtr mySketch; }; diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 5256eb7db..65e76b68c 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -152,11 +152,17 @@ void XGUI_OperationMgr::onValidateOperation() if (!hasOperation()) return; ModuleBase_Operation* anOperation = currentOperation(); - if(anOperation && (!myIsValidationLock)) { - setApplyEnabled(anOperation->isValid()); + if(anOperation) { + setApplyEnabled(!myIsValidationLock && anOperation->isValid()); } } +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 index bf132446a..812c61c3d 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -81,15 +81,11 @@ Q_OBJECT /// 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) { myIsValidationLock = toLock; } + void setLockValidating(bool toLock); /// Returns state of validation locking bool isValidationLocked() const { return myIsValidationLock; } - /// Sets apply state to the value and emit signal about this state is changed - /// \param theEnabled the state value - void setApplyEnabled(const bool theEnabled); - /// Returns enable apply state /// \return theEnabled a boolean value bool isApplyEnabled() const; @@ -136,6 +132,10 @@ signals: void keyEnterReleased(); protected: + /// Sets apply state to the value and emit signal about this state is changed + /// \param theEnabled the state value + void setApplyEnabled(const bool theEnabled); + /// Commits the current operatin if it is valid bool commitOperation(); -- 2.39.2