From: nds Date: Wed, 26 Apr 2017 14:19:15 +0000 (+0300) Subject: Avoid the ability to cancel the current sketch when saving. X-Git-Tag: V_2.7.1.1~3^2~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a75228f773396c277c2d965e6ba83bc147648961;p=modules%2Fshaper.git Avoid the ability to cancel the current sketch when saving. --- diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index c76241a29..6ff2bb784 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -679,7 +679,7 @@ QStringList XGUI_ContextMenuMgr::actionObjectGroups(const QString& theName) void XGUI_ContextMenuMgr::onRename() { QObjectPtrList anObjects = myWorkshop->selector()->selection()->selectedObjects(); - if (!myWorkshop->abortAllOperations()) + if (!myWorkshop->operationMgr()->abortAllOperations()) return; // restore selection in case if dialog box was shown myWorkshop->objectBrowser()->setObjectsSelected(anObjects); diff --git a/src/XGUI/XGUI_MenuMgr.cpp b/src/XGUI/XGUI_MenuMgr.cpp index 4ac9ac6a2..ecfb98f74 100755 --- a/src/XGUI/XGUI_MenuMgr.cpp +++ b/src/XGUI/XGUI_MenuMgr.cpp @@ -85,7 +85,8 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr& theM } if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll); - QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); + QObject::connect(anAction, SIGNAL(triggered()), + anOperationMgr, SLOT(onAbortAllOperations())); aNestedActList << anAction; } } @@ -195,7 +196,8 @@ QAction* XGUI_MenuMgr::buildAction(const std::shared_ptr& } if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) { QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll); - QObject::connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations())); + QObject::connect(anAction, SIGNAL(triggered()), + anOperationMgr, SLOT(onAbortAllOperations())); aNestedActList << anAction; } anAction = aSalomeConnector->addFeatureOfNested(theWchName.c_str(), aFeatureInfo, diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 61adc99ea..ad5960727 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -208,7 +208,12 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) return isStarted; } -bool XGUI_OperationMgr::abortAllOperations() +void XGUI_OperationMgr::onAbortAllOperations() +{ + abortAllOperations(); +} + +bool XGUI_OperationMgr::abortAllOperations(const XGUI_MessageKind& theMessageKind) { bool aResult = true; if(!hasOperation()) @@ -216,18 +221,29 @@ bool XGUI_OperationMgr::abortAllOperations() if (operationsCount() == 1) { ModuleBase_Operation* aCurrentOperation = currentOperation(); - if (canStopOperation(aCurrentOperation)) { + if (canStopOperation(aCurrentOperation, theMessageKind)) { abortOperation(aCurrentOperation); } else aResult = false; } else { - aResult = QMessageBox::question(qApp->activeWindow(), - tr("Abort operation"), - tr("All active operations will be aborted."), - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel) == QMessageBox::Ok; + if (theMessageKind == XGUI_AbortOperationMessage) { + aResult = QMessageBox::question(qApp->activeWindow(), + tr("Abort operation"), + tr("All active operations will be aborted."), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel) == QMessageBox::Ok; + } + else if (theMessageKind == XGUI_InformationMessage) { + QString aMessage = tr("Please validate all your active operations before saving."); + QMessageBox::question(qApp->activeWindow(), + tr("Validate operation"), + aMessage, + QMessageBox::Ok, + QMessageBox::Ok); + aResult = false; // do not perform abort + } while(aResult && hasOperation()) { abortOperation(currentOperation()); } @@ -241,7 +257,7 @@ bool XGUI_OperationMgr::commitAllOperations() while (hasOperation()) { ModuleBase_Operation* anOperation = currentOperation(); if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) { - anOperationProcessed = onCommitOperation(); + anOperationProcessed = commitOperation(); } else { abortOperation(anOperation); anOperationProcessed = true; @@ -295,33 +311,35 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati onValidateOperation(); } -bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation) +bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation, + const XGUI_OperationMgr::XGUI_MessageKind& theMessageKind) { //in case of nested (sketch) operation no confirmation needed if (isGrantedOperation(theOperation->id())) return true; if (theOperation && theOperation->isModified()) { - QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id()); - int anAnswer = QMessageBox::question(qApp->activeWindow(), - tr("Abort operation"), - aMessage, - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel); - return anAnswer == QMessageBox::Ok; + if (theMessageKind == XGUI_AbortOperationMessage) { + QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id()); + int anAnswer = QMessageBox::question(qApp->activeWindow(), + tr("Abort operation"), + aMessage, + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel); + return anAnswer == QMessageBox::Ok; + } + else if (theMessageKind == XGUI_InformationMessage) { + QString aMessage = tr("Please validate your %1 before saving.").arg(theOperation->id()); + QMessageBox::question(qApp->activeWindow(), + tr("Validate operation"), + aMessage, + QMessageBox::Ok, + QMessageBox::Ok); + return false; + } } return true; } -bool XGUI_OperationMgr::commitOperation() -{ - //if (hasOperation() && currentOperation()->isValid()) { - // onCommitOperation(); - // return true; - //} - //return false; - return onCommitOperation(); -} - void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation) { theOperation->resume(); @@ -413,7 +431,7 @@ void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation) } } -bool XGUI_OperationMgr::onCommitOperation() +bool XGUI_OperationMgr::commitOperation() { bool isCommitted = false; ModuleBase_Operation* anOperation = currentOperation(); diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index c8ccf9d08..cfce4bb02 100755 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -34,7 +34,15 @@ class XGUI_ShortCutListener; class XGUI_EXPORT XGUI_OperationMgr : public QObject { Q_OBJECT - public: +public: + /// Enumeration of kind of message that is used when trying to stop the active operation + enum XGUI_MessageKind + { + XGUI_AbortOperationMessage, //< warns and give possibility to abort current operation + XGUI_InformationMessage //< ask to apply the current operation before performing something + }; + +public: /// Constructor /// \param theParent the parent /// \param theWorkshop a reference to workshop @@ -73,7 +81,9 @@ Q_OBJECT /// Returns true if the operation can be aborted. If the operation is modified, /// the warning message box is shown. /// \param theOperation an operation which is checked on stop - bool canStopOperation(ModuleBase_Operation* theOperation); + /// \param theMessageKind a kind of message in warning message box + bool canStopOperation(ModuleBase_Operation* theOperation, + const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage); /// Find and return operation by its Id. ModuleBase_Operation* findOperation(const QString& theId) const; @@ -115,8 +125,7 @@ Q_OBJECT /// \param theOperation an aborted operation void abortOperation(ModuleBase_Operation* theOperation); - /// Slot that commits the current operation. - bool onCommitOperation(); + bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage); public slots: /// Slot that aborts the current operation. @@ -126,7 +135,10 @@ public slots: /// Commit all operations bool commitAllOperations(); /// Abort all operations - bool abortAllOperations(); + void onAbortAllOperations(); + +protected slots: + signals: /// Signal about an operation is stopped. It is emitted after the stop() of operation is done. diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 77c4bd57f..56c551fdb 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -491,7 +491,7 @@ void XGUI_Workshop::onAcceptActionClicked() (anOperationMgr->currentOperation()); if (aFOperation) { //if (errorMgr()->canProcessClick(anAction, aFOperation->feature())) - myOperationMgr->onCommitOperation(); + myOperationMgr->commitOperation(); } } } @@ -759,12 +759,6 @@ void XGUI_Workshop::saveDocument(const QString& theName, std::list& QApplication::restoreOverrideCursor(); } -//****************************************************** -bool XGUI_Workshop::abortAllOperations() -{ - return myOperationMgr->abortAllOperations(); -} - //****************************************************** void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation) { @@ -780,7 +774,7 @@ void XGUI_Workshop::operationStarted(ModuleBase_Operation* theOperation) //****************************************************** void XGUI_Workshop::onOpen() { - if(!abortAllOperations()) + if(!myOperationMgr->abortAllOperations()) return; //save current file before close if modified SessionPtr aSession = ModelAPI_Session::get(); @@ -910,7 +904,7 @@ void XGUI_Workshop::onTrihedronVisibilityChanged(bool theState) //****************************************************** bool XGUI_Workshop::onSave() { - if(!abortAllOperations()) + if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) return false; if (myCurrentDir.isEmpty()) { return onSaveAs(); @@ -927,7 +921,7 @@ bool XGUI_Workshop::onSave() //****************************************************** bool XGUI_Workshop::onSaveAs() { - if(!abortAllOperations()) + if(!myOperationMgr->abortAllOperations(XGUI_OperationMgr::XGUI_InformationMessage)) return false; QFileDialog dialog(desktop()); dialog.setWindowTitle(tr("Select directory to save files...")); @@ -1453,7 +1447,7 @@ void XGUI_Workshop::deleteObjects() } QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); - if (!abortAllOperations()) + if (!myOperationMgr->abortAllOperations()) return; bool hasResult = false; @@ -1520,7 +1514,7 @@ void addRefsToFeature(const FeaturePtr& theFeature, //************************************************************** void XGUI_Workshop::cleanHistory() { - if (!abortAllOperations()) + if (!myOperationMgr->abortAllOperations()) return; QObjectPtrList anObjects = mySelector->selection()->selectedObjects(); @@ -1646,7 +1640,7 @@ void XGUI_Workshop::cleanHistory() //************************************************************** void XGUI_Workshop::moveObjects() { - if (!abortAllOperations()) + if (!myOperationMgr->abortAllOperations()) return; SessionPtr aMgr = ModelAPI_Session::get(); @@ -1887,7 +1881,7 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) if (aColor.size() != 3) return; - if (!abortAllOperations()) + if (!myOperationMgr->abortAllOperations()) return; // 2. show the dialog to change the value XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(desktop()); @@ -1977,7 +1971,7 @@ void XGUI_Workshop::changeDeflection(const QObjectPtrList& theObjects) if (aDeflection < 0) return; - if (!abortAllOperations()) + if (!myOperationMgr->abortAllOperations()) return; // 2. show the dialog to change the value XGUI_DeflectionDialog* aDlg = new XGUI_DeflectionDialog(desktop()); diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 9d67d191e..97ab2b3cd 100755 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -247,20 +247,11 @@ Q_OBJECT */ void saveDocument(const QString& theName, std::list& theFileNames); - /** - * If there is an active (uncommitted) operation shows a prompt to abort it - * and performs abortion if user agreed. Returns true if - * - operation aborted successfully - * - there is no active operation - */ - bool abortAllOperations(); - /// Updates workshop state according to the started operation, e.g. visualizes the property panel /// and connect to it. /// \param theOpertion a started operation void operationStarted(ModuleBase_Operation* theOperation); - //! Delete features. Delete the referenced features. There can be a question with a list of //! referenced objects. //! \param theFeatures a list of objects to be deleted