Salome HOME
Memory Leaks
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 6facd78b49bd46933246273098a907d64c16328d..33e2a18d3523673749bc6813774d8b599052e14b 100644 (file)
@@ -332,30 +332,33 @@ void SUPERVGUI_Main::showCanvas() {
 }
 
 void SUPERVGUI_Main::insertFile() {
-    Trace("SUPERVGUI_Main::insertFile");
-    if ((SUPERV_isNull(dataflow))) return;
+  Trace("SUPERVGUI_Main::insertFile");
 
-    Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
-
-    QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
-                                        "",
-                                        "*.xml",
-                                        tr("MSG_GRAPH_INSERT"),
-                                        true);
-    if (!f.isEmpty()) {
-      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 ( !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
+      
+    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));
     }
+  }
 }
 
 void SUPERVGUI_Main::copy() {
@@ -594,21 +597,11 @@ 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 
-
+  //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()