Salome HOME
Issue #355 Delete: elements of sketch and constraints
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index a8f68277b5aa2266d32b6cb4f4d6c4b33730a9d8..fa74ed50313618c714699ef4699d11c6714564fe 100644 (file)
@@ -13,7 +13,7 @@
 #include <QKeyEvent>
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent)
-    : QObject(theParent), myIsValidationLock(false)
+    : QObject(theParent), myIsValidationLock(false), myIsApplyEnabled(false)
 {
 }
 
@@ -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<ModuleBase_Operation*>(sender());