From c0b3029f31fc1e6885a6cbe1314b97d22cbd8388 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 28 Jan 2015 09:30:04 +0300 Subject: [PATCH] Issue #368 move constraint problem The operation should be applyed if the apply state is true in the operation manager, otherwise, it is aborted. The isOkEnabled, setOkEnabled methods should not be avaialabe in the property panel because this state is updated according to operation manager state by workshop object. canAbortOperation is renamed to canStopOperation, because it is possible that the given operation is commited or aborted. --- src/ModuleBase/ModuleBase_IPropertyPanel.h | 7 --- src/PartSet/PartSet_Module.cpp | 2 +- src/PartSet/PartSet_WidgetPoint2d.cpp | 3 +- src/PartSet/PartSet_WidgetPoint2dDistance.cpp | 2 +- src/XGUI/XGUI_OperationMgr.cpp | 57 ++++++++++++------- src/XGUI/XGUI_OperationMgr.h | 23 +++++--- src/XGUI/XGUI_PropertyPanel.cpp | 12 ---- src/XGUI/XGUI_PropertyPanel.h | 7 --- src/XGUI/XGUI_Workshop.cpp | 2 +- 9 files changed, 54 insertions(+), 61 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index 224691890..22648e998 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -41,13 +41,6 @@ public: /// \return State of editing mode flag bool isEditingMode() const { return myIsEditing; } - /// Set Enable/Disable state of Ok button - /// \param theEnabled Enable/Disable state of Ok button - virtual void setOkEnabled(bool theEnabled) = 0; - - /// \return Enable/disable state of Ok button - virtual bool isOkEnabled() const = 0; - /// Set Enable/Disable state of Cancel button /// \param theEnabled Enable/Disable state of Cancel button virtual void setCancelEnabled(bool theEnabled) = 0; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 66a4e52da..c0ea09cd9 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -212,7 +212,7 @@ void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation) aPnt2dWgt->setPoint(aPoint->x(), aPoint->y()); PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(), aWgt->attributeID(), aPoint->x(), aPoint->y()); - theOperation->propertyPanel()->activateNextWidget(aPnt2dWgt); + aPanel->activateNextWidget(aPnt2dWgt); } } } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 249fd9a0e..1e061643c 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -285,7 +284,7 @@ void PartSet_WidgetPoint2D::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEv // 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 - myWorkshop->propertyPanel()->setOkEnabled(false); + myWorkshop->operationMgr()->setApplyEnabled(false); gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); diff --git a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp index b67ca1413..c3cba967b 100644 --- a/src/PartSet/PartSet_WidgetPoint2dDistance.cpp +++ b/src/PartSet/PartSet_WidgetPoint2dDistance.cpp @@ -94,7 +94,7 @@ void PartSet_WidgetPoint2dDistance::onMouseRelease(ModuleBase_IViewWindow* theWn void PartSet_WidgetPoint2dDistance::onMouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { myWorkshop->operationMgr()->setLockValidating(true); - myWorkshop->propertyPanel()->setOkEnabled(false); + myWorkshop->operationMgr()->setApplyEnabled(false); gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView()); diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index a8f68277b..859c0da92 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -140,11 +140,38 @@ void XGUI_OperationMgr::onValidateOperation() return; ModuleBase_Operation* anOperation = currentOperation(); if(anOperation && (!myIsValidationLock)) { - bool isValid = anOperation->isValid(); - emit operationValidated(isValid); + setApplyEnabled(anOperation->isValid()); } } +void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled) +{ + myIsApplyEnabled = theEnabled; + emit applyEnableChanged(theEnabled); +} + +bool XGUI_OperationMgr::isApplyEnabled() const +{ + return myIsApplyEnabled; +} + +bool XGUI_OperationMgr::canStopOperation() +{ + ModuleBase_Operation* anOperation = currentOperation(); + if(operationsCount() > 1) //in case of nested (sketch) operation no confirmation needed + return true; + if (anOperation && anOperation->isModified()) { + QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id()); + int anAnswer = QMessageBox::question(qApp->activeWindow(), + tr("Abort operation"), + aMessage, + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel); + return anAnswer == QMessageBox::Ok; + } + return true; +} + bool XGUI_OperationMgr::commitOperation() { if (hasOperation() && currentOperation()->isValid()) { @@ -165,8 +192,11 @@ bool XGUI_OperationMgr::canStartOperation(QString theId) ModuleBase_Operation* aCurrentOp = currentOperation(); if (aCurrentOp) { if (!aCurrentOp->isGranted(theId)) { - if (canAbortOperation()) { - aCurrentOp->abort(); + if (canStopOperation()) { + if (myIsApplyEnabled) + aCurrentOp->commit(); + else + aCurrentOp->abort(); } else { aCanStart = false; } @@ -185,28 +215,11 @@ void XGUI_OperationMgr::onCommitOperation() void XGUI_OperationMgr::onAbortOperation() { - if (hasOperation() && canAbortOperation()) { + if (hasOperation() && canStopOperation()) { currentOperation()->abort(); } } -bool XGUI_OperationMgr::canAbortOperation() -{ - ModuleBase_Operation* anOperation = currentOperation(); - if(operationsCount() > 1) //in case of nested (sketch) operation no confirmation needed - return true; - if (anOperation && anOperation->isModified()) { - QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id()); - int anAnswer = QMessageBox::question(qApp->activeWindow(), - tr("Abort operation"), - aMessage, - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel); - return anAnswer == QMessageBox::Ok; - } - return true; -} - void XGUI_OperationMgr::onOperationStarted() { ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 1cf7dcefc..f5683f81a 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -77,11 +77,6 @@ Q_OBJECT /// \param theId id of the operation which is going to start bool canStartOperation(QString theId); - bool canStopOperation(); - - /// Returns true if the operation can be aborted - bool canAbortOperation(); - /// 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; } @@ -89,7 +84,15 @@ Q_OBJECT /// Returns state of validation locking bool isValidationLocked() const { return myIsValidationLock; } - public slots: + /// 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; + + public slots: /// Slot that commits the current operation. void onCommitOperation(); /// Slot that aborts the current operation. @@ -114,8 +117,8 @@ signals: /// Emitted when current operation is aborted void operationAborted(ModuleBase_Operation* theOperation); - /// Signal is emitted after the validate methods calls. - void operationValidated(bool); + /// Signal is emitted after the apply enable state changed. + void applyEnableChanged(bool); /// Signal is emitted after the current operation is filled with existing preselection. void operationActivatedByPreselection(); @@ -125,6 +128,8 @@ signals: protected: + /// Returns true if the operation can be aborted + bool canStopOperation(); /// Commits the current operatin if it is valid bool commitOperation(); @@ -156,6 +161,8 @@ signals: /// Lock/Unlock access to Ok button in property panel bool myIsValidationLock; + /// Lock/Unlock access to Ok button in property panel + bool myIsApplyEnabled; }; #endif diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index fc337bc63..d5d213691 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -226,18 +226,6 @@ void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget) emit noMoreWidgets(); } -void XGUI_PropertyPanel::setOkEnabled(bool theEnabled) -{ - QPushButton* anOkBtn = findChild(PROP_PANEL_OK); - anOkBtn->setEnabled(theEnabled); -} - -bool XGUI_PropertyPanel::isOkEnabled() const -{ - QPushButton* anOkBtn = findChild(PROP_PANEL_OK); - return anOkBtn->isEnabled(); -} - void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled) { QPushButton* anCancelBtn = findChild(PROP_PANEL_CANCEL); diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 6e89ac0d6..e632fe28d 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -70,13 +70,6 @@ Q_OBJECT /// \brief Enable/Disable stretch area in the panel void setStretchEnabled(bool isEnabled); - /// Set Enable/Disable state of Ok button - /// \param theEnabled Enable/Disable state of Ok button - virtual void setOkEnabled(bool theEnabled); - - /// \return Enable/disable state of Ok button - virtual bool isOkEnabled() const; - /// Set Enable/Disable state of Cancel button /// \param theEnabled Enable/Disable state of Cancel button virtual void setCancelEnabled(bool theEnabled); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 77acb88d5..7b234a365 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1106,7 +1106,7 @@ void XGUI_Workshop::createDockWidgets() connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation())); connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr, SLOT(onKeyReleased(QKeyEvent*))); - connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel, + connect(myOperationMgr, SIGNAL(applyEnableChanged(bool)), myPropertyPanel, SLOT(setAcceptEnabled(bool))); } -- 2.39.2