]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Avoid the ability to cancel the current sketch when saving.
authornds <nds@opencascade.com>
Wed, 26 Apr 2017 14:19:15 +0000 (17:19 +0300)
committernds <nds@opencascade.com>
Wed, 26 Apr 2017 14:19:36 +0000 (17:19 +0300)
src/XGUI/XGUI_ContextMenuMgr.cpp
src/XGUI/XGUI_MenuMgr.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index c76241a294eca31d2c6d64a82f9f9d9ac9e757ff..6ff2bb78482e89f6e323e05322e4ae76188899da 100644 (file)
@@ -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);
index 4ac9ac6a2ce104446e85142e418a576e30690894..ecfb98f7434f88c434945d459d474bd89bdd20cf 100755 (executable)
@@ -85,7 +85,8 @@ void XGUI_MenuMgr::addFeature(const std::shared_ptr<Config_FeatureMessage>& 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<Config_FeatureMessage>&
     }
     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,
index 61adc99ea80937249f3c07a803ca494ad3c98561..ad5960727fb8fa7b870aab4d6241fb9a3658b2a4 100644 (file)
@@ -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();
index c8ccf9d08a7b2d1380db13cfe2f550e6f21ca277..cfce4bb02a4d41f2ff290c9cee7b8f93196fdc32 100755 (executable)
@@ -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.
index 77c4bd57f5fe53262f51e94266f7222cfc308378..56c551fdb4e84ddcb5d8aa14f2c85891c9f18ecb 100755 (executable)
@@ -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<std::string>&
   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());
index 9d67d191ec84944b7384f3addbbcaaecda90d759..97ab2b3cdea04f4d523b0f8392e97c2e350d8f01 100755 (executable)
@@ -247,20 +247,11 @@ Q_OBJECT
   */
   void saveDocument(const QString& theName, std::list<std::string>& 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