Salome HOME
Fix for PAL8027. from bugzilla:
authorasv <asv@opencascade.com>
Mon, 7 Feb 2005 11:38:07 +0000 (11:38 +0000)
committerasv <asv@opencascade.com>
Mon, 7 Feb 2005 11:38:07 +0000 (11:38 +0000)
The following program behaviour was implemented for "Add node", "Insert file", "Paste node" operations: if the dataflow is being executed - user is asked to Kill the execution before operation or cancel the operation.
changes in the code: SUPERVGUI_Main::ReadyToModify() operation was introduced to handle checking and killing of execution.

src/SUPERVGUI/SUPERVGUI_Clipboard.cxx
src/SUPERVGUI/SUPERVGUI_Main.cxx
src/SUPERVGUI/SUPERVGUI_Main.h

index a9d4637a35b841aa61421204c22b14e980f83fd1..a26faf868e0c3e9e7acf92105a6db6442fa80ad4 100644 (file)
@@ -139,6 +139,9 @@ void SUPERVGUI_Clipboard::pasteNode() {
   SUPERVGUI_Main* aMain = Supervision.getMain();
   if ( !CORBA::is_nil( aNode ) && aMain ) {
     
+    if ( !aMain->ReadyToModify() ) // null dataflow or executing, ..
+      return;
+
     aMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> PAL7960
 
     SUPERV::Graph_var dataflow = aMain->getDataflow();
index d69ac8f54435c85d82906b33812430ca52d740de..33e2a18d3523673749bc6813774d8b599052e14b 100644 (file)
@@ -332,31 +332,33 @@ void SUPERVGUI_Main::showCanvas() {
 }
 
 void SUPERVGUI_Main::insertFile() {
-    Trace("SUPERVGUI_Main::insertFile");
-    if ((SUPERV_isNull(dataflow))) return;
+  Trace("SUPERVGUI_Main::insertFile");
+
+  if ( !ReadyToModify() ) // null dataflow or executing, ..
+    return;
 
-    QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                        "",
-                                        "*.xml",
-                                        tr("MSG_GRAPH_INSERT"),
-                                        true);
-    if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name
+  QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
+                                      "",
+                                      "*.xml",
+                                      tr("MSG_GRAPH_INSERT"),
+                                      true);
+  if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name
       
-      Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960
+    Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960
 
-      if (dataflow->Import(f.latin1())) {
-       if (myCurrentView == CANVASTABLE) {
-         myArray->destroy();
-         myArray->create();
-       }
-       else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
-         myCanvas->merge();
-       }
-       sync();
-      } else {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
+    if (dataflow->Import(f.latin1())) {
+      if (myCurrentView == CANVASTABLE) {
+       myArray->destroy();
+       myArray->create();
+      }
+      else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
+       myCanvas->merge();
       }
+      sync();
+    } else {
+      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
     }
+  }
 }
 
 void SUPERVGUI_Main::copy() {
@@ -595,18 +597,9 @@ void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le
 */
 void SUPERVGUI_Main::addNode() {
   Trace("SUPERVGUI_Main::addNode");
-  bool error = SUPERV_isNull( dataflow );
-  if ( error ) 
+  
+  if ( !ReadyToModify() ) // null dataflow or executing, ..
     return;
-
-  if ( dataflow->IsExecuting() ) {
-    error = QAD_MessageBox::warn2( QAD_Application::getDesktop(), // 0=Yes, 1=No
-      tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_NO" ), 0, 1, 0 );
-    if ( error ) // user selected NOT to kill dataflow and NOT to add new node
-      return;
-    else  // user selected to kill the dataflow and add new node after that
-      kill();
-  }
   
   //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
   Supervision.getBrowser()->choose();
@@ -1199,6 +1192,25 @@ void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
   }
 }
 
+/**
+ * ReadyToModify() must be called before any modification
+ * operation - asks to kill execution of dataflow.  If returns false - 
+ * modification (==Editing() ) is not allowed.
+ */
+bool SUPERVGUI_Main::ReadyToModify() {
+  if ( CORBA::is_nil( dataflow ) )
+    return false;
+  if ( dataflow->IsExecuting() ) {
+    bool quit = QAD_MessageBox::warn2( QAD_Application::getDesktop(), // 0=Yes, 1=No
+      tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
+    if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
+      return false;
+    else  if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
+      kill();   // checking again for IsExecuting to be sure that it was not finished while MB was up
+  }
+  return true;
+}
+
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
index 932157906a3ce063ba4f048a67c34afdfa315365..274a179848a2a189abcd66bd2562a18a3f6bcb8b 100644 (file)
@@ -124,6 +124,9 @@ class SUPERVGUI_Main: public SUPERVGraph_View {
 
     void Editing(); // any Editing operation is to be performed ->
                    // activate Editors data model in Engine
+    bool ReadyToModify(); // must be called before any modification
+                   // operation - asks to kill execution of dataflow.  If returns false -
+                   // modification (==Editing() ) is not allowed.
 
     void removeArrayChild(SUPERV::CNode_ptr theNode);