Salome HOME
Updates for stability of application
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index aeb0ed3c06533a771a44873994117795ae04193f..2a27188c9e9447073a6147681c192c4fe67bcc04 100644 (file)
@@ -22,6 +22,16 @@ ModuleBase_Operation* XGUI_OperationMgr::currentOperation() const
   return myOperations.count() > 0 ? myOperations.last() : 0;
 }
 
+bool XGUI_OperationMgr::hasOperation() const
+{
+  return (myOperations.count() > 0) && (myOperations.last() != NULL);
+}
+
+int XGUI_OperationMgr::operationsCount() const
+{
+  return myOperations.count();
+}
+
 bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
 {
   if (!canStartOperation(theOperation))
@@ -31,28 +41,73 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
 
   connect(theOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
   connect(theOperation, SIGNAL(started()), this, SIGNAL(operationStarted()));
+  connect(theOperation, SIGNAL(resumed()), this, SIGNAL(operationResumed()));
 
   theOperation->start();
   return true;
 }
 
+bool XGUI_OperationMgr::abortOperation()
+{
+  ModuleBase_Operation* aCurrentOp = currentOperation();
+  if (!aCurrentOp || !canStopOperation())
+    return false; 
+
+  aCurrentOp->abort();
+  return true;
+}
+
+QStringList XGUI_OperationMgr::operationList()
+{
+  QStringList result;
+  foreach(ModuleBase_Operation* eachOperation, myOperations) {
+    result << eachOperation->id();
+  }
+  return result;
+}
+
+void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
+{
+  theOperation->resume();
+}
+
 bool XGUI_OperationMgr::canStartOperation(ModuleBase_Operation* theOperation)
 {
   bool aCanStart = true;
   ModuleBase_Operation* aCurrentOp = currentOperation();
-  if (aCurrentOp && !theOperation->isGranted())
+  if (aCurrentOp && !theOperation->isGranted(aCurrentOp))
   {
-    int anAnswer = QMessageBox::question(0, tr("Operation launch"),
-                                tr("Previous operation is not finished and will be aborted"),
-                                QMessageBox::Ok, QMessageBox::Cancel);
-    if (anAnswer == QMessageBox::Ok)
+    if (canStopOperation()) {
       aCurrentOp->abort();
-    else
+    } else {
       aCanStart = false;
+    }
   }
   return aCanStart;
 }
 
+bool XGUI_OperationMgr::canStopOperation()
+{
+  int anAnswer = QMessageBox::question(0, tr("Operation launch"),
+                              tr("Previous operation is not finished and will be aborted"),
+                              QMessageBox::Ok, QMessageBox::Cancel);
+  return anAnswer == QMessageBox::Ok;
+}
+
+void XGUI_OperationMgr::onCommitOperation()
+{
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation)
+    anOperation->commit();
+}
+
+void XGUI_OperationMgr::onAbortOperation()
+{
+  ModuleBase_Operation* anOperation = currentOperation();
+  if (anOperation)
+    anOperation->abort();
+}
+
 void XGUI_OperationMgr::onOperationStopped()
 {
   ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
@@ -60,11 +115,11 @@ void XGUI_OperationMgr::onOperationStopped()
   if (!aSenderOperation || !anOperation || aSenderOperation != anOperation )
     return;
 
-  emit operationStopped(anOperation);
-
   myOperations.removeAll(anOperation);
   anOperation->deleteLater();
 
+  emit operationStopped(anOperation);
+
   // get last operation which can be resumed
   ModuleBase_Operation* aResultOp = 0;
   QListIterator<ModuleBase_Operation*> anIt(myOperations);
@@ -78,5 +133,5 @@ void XGUI_OperationMgr::onOperationStopped()
     }
   }
   if (aResultOp)
-    startOperation(aResultOp);
+    resumeOperation(aResultOp);
 }