]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/SUPERVGUI/SUPERVGUI_Main.cxx
Salome HOME
fix for 7817: in removeArrayChild() the returned list of children of myArray is check...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 59344f1d5f8cd103a3c0b06ac24a108d3b4b8535..e7317460b29ac65c494ec039d415999c36315a4b 100644 (file)
@@ -26,6 +26,7 @@
 //  Module : SUPERV
 
 using namespace std;
+
 #include "QAD_Splitter.h"
 #include "QAD_LeftFrame.h"
 #include "QAD_ObjectBrowser.h"
@@ -34,101 +35,29 @@ using namespace std;
 #include "QAD_Message.h"
 #include "QAD_FileDlg.h"
 #include "QAD_Application.h"
-#include "SUPERVGUI_Def.h"
 #include "QAD_RightFrame.h"
+#include "QAD_SpinBoxDbl.h"
+#include "QAD_MessageBox.h"
+
+#include "NOTIFICATION.hxx"
 #include "SALOME_Event.hxx"
+#include "SALOMEGUI_ImportOperation.h"
 #include "SUPERVGraph_ViewFrame.h"
-#include <qlayout.h>
-#include <qfile.h>
-#include "SUPERVGUI_Main.h"
+
 #include "SUPERVGUI.h"
-#include "SUPERVGUI_ComputeNode.h"
-#include "SUPERVGUI_ControlNode.h"
-#include "NOTIFICATION.hxx"
+#include "SUPERVGUI_Def.h"
+#include "SUPERVGUI_Main.h"
 #include "SUPERVGUI_Notification.h"
-#include "SALOMEGUI_ImportOperation.h"
 #include "SUPERVGUI_Information.h"
 #include "SUPERVGUI_CanvasControlNode.h"
+#include "SUPERVGUI_CanvasPort.h"
+
 #include <qvalidator.h>
+#include <qlayout.h>
+#include <qfile.h>
+#include <qlineedit.h>
+#include <qcombobox.h>
 
-/*
-asv 20.10.04: removed 2 SUPERVGUI_Main constructors.  there is only ONE way 
-to create a Main object now: with a non-null DataFlow as a 3d parameter
-SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool fromIOR)
-     : SUPERVGraph_View(theParent), 
-       myLogged( false ),
-       myFiltered( false ),
-       myLogFileName( QString::null ),
-       myLogFile( NULL ),
-       myWarning( false ),
-       myStep( false ),
-       myTrace( false ),
-       myVerbose( false )
-{
-  Trace("SUPERVGUI_Main::SUPERVGUI_Main (new)");
-  theParent->setViewWidget(this); 
-  if (fromIOR) {
-    //SUPERVGUI_Main* am = Supervision.getMain();
-    QAD_ObjectBrowser* ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
-    //        if (am == 0) {
-    //  ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
-    //} else {
-    //ob = am->objectBrowser;
-    //}; 
-    QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(ob->getListView()->currentItem());
-    SALOMEDS::SObject_var obj = theDesktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
-    SALOMEDS::GenericAttribute_var anAttr;
-    if (obj->FindAttribute(anAttr, "AttributeIOR")) {
-      SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-      Standard_CString ior = anIOR->Value();
-      dataflow = Supervision.getEngine()->getStreamGraph(ior);
-      if (SUPERV_isNull(dataflow)) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
-       close();
-      } else {
-       init(theDesktop);
-      }
-    } else {
-      QMessageBox::warning(0, tr("ERROR"), tr("MSG_NOACCESS_BY_IOR"));
-      close();
-    }
-  } else {
-    dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
-    if (SUPERV_isNull(dataflow)) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
-      close();
-    } else {
-      init(theDesktop);
-    }
-  }
-}
-
-SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool isModify, const char* f)
-     : SUPERVGraph_View(theParent),
-       myLogged( false ),
-       myFiltered( false ),
-       myLogFileName( QString::null ),
-       myLogFile( NULL ),
-       myWarning( false ),
-       myStep( false ),
-       myTrace( false ),
-       myVerbose( false )
-{
-  Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
-    theParent->setViewWidget(this);  
-  if (isModify) {
-    dataflow = Supervision.getEngine()->StreamGraph(f);
-  } else {
-    dataflow = Supervision.getEngine()->StreamGraphE(f);
-  }
-  if (SUPERV_isNull(dataflow)) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
-    close();
-  } else {
-    init(theDesktop);
-  }
-}
-*/
 
 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph theDataFlow )
      : SUPERVGraph_View(theParent),
@@ -139,7 +68,8 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
        myWarning( false ),
        myStep( false ),
        myTrace( false ),
-       myVerbose( false )
+       myVerbose( false ),
+       myGUIEventLoopFinished( true )
 {
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
   theParent->setViewWidget(this);  
@@ -163,7 +93,6 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   myThread = new SUPERVGUI_Thread();
   myThread->setMain(this);
 
-  myIsKilled = false;
   myCurrentView = CANVAS;
   myIsFromStudy = false;
   myLastGraph = 0;
@@ -196,10 +125,8 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
 
   objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
     
-
-  graph = new SUPERVGUI_Graph(this);
-  graph->hide();
-  array = new SUPERVGUI_Array(this);
+  myArray = new SUPERVGUI_CanvasArray(this);
+  myArrayView = new SUPERVGUI_ArrayView(myArray, this);
 
   myCanvas = new SUPERVGUI_Canvas(this);
   myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
@@ -210,13 +137,13 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   QBoxLayout * layout = new QVBoxLayout(this);
   layout->setMargin(0);
   layout->setSpacing(0);
-  layout->addWidget(graph);
-  layout->addWidget(array);
   layout->addWidget(myCanvasView);
+  layout->addWidget(myArrayView);
 
   if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
     myCanvas->merge();
   }
+
   sync();
   show();
   if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
@@ -254,12 +181,12 @@ SUPERVGUI_Main::~SUPERVGUI_Main() {
   if ( myLogFile != NULL) {
     fclose( myLogFile );
   }
-  graph->removeLinks();
-  //delete myCanvas;
+  
   //  delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
   notification->_remove_ref();  // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
 
   delete myCanvas;
+  delete myArray;
 }
 
 void SUPERVGUI_Main::filterNotification() {
@@ -294,15 +221,8 @@ void SUPERVGUI_Main::filterNotification() {
   }
 }
 
-void SUPERVGUI_Main::changeDSGraphParameters() {
-  SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
-  if (aDlg->exec() )
-    sync();
-  delete aDlg;
-}
-
 void SUPERVGUI_Main::syncAsync() {
-    Trace("SUPERVGUI_Main::syncAsync")
+    Trace("SUPERVGUI_Main::syncAsync");
     QTimer::singleShot(1, this, SLOT(sync()));
 }
 
@@ -310,88 +230,79 @@ void SUPERVGUI_Main::syncAsync() {
 /**
  * Called by thread when dataflow is executing
  */
-void SUPERVGUI_Main::execute(char *  theNodeName, SUPERV::GraphState theNodeState) {
+void SUPERVGUI_Main::execute( char *  theNodeName, SUPERV::GraphState theNodeState ) {
   if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
     SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
+    if ( aNode ) {
+      aNode->sync();
+    }
+  }
+  else if (myCurrentView == CANVASTABLE) {
+    SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
     if (aNode) aNode->sync();
   }
-  else {
-    SUPERVGUI_Node* aNodePrs; 
-    SUPERVGUI_GraphNode* aGraphNodePrs;
-    if (myCurrentView == TABLE) {
-      aNodePrs = (SUPERVGUI_Node*) array->child(theNodeName, "SUPERVGUI_Node");
-      aGraphNodePrs = (SUPERVGUI_GraphNode*) array->child(theNodeName, "SUPERVGUI_GraphNode");
-    } else {
-      aNodePrs = (SUPERVGUI_Node*) graph->child(theNodeName, "SUPERVGUI_Node");
-      aGraphNodePrs = (SUPERVGUI_GraphNode*) graph->child(theNodeName, "SUPERVGUI_GraphNode");
-    }
-    if (aGraphNodePrs) {
-      aGraphNodePrs->sync();
-    }
-    else if (aNodePrs) {
-      aNodePrs->syncOnEvent(theNodeState);
-    }
+
+  // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a 
+  // CanvasPort the functionality was moved from SUPERVGUI_CanvasPortOut::sync() method please, see 
+  // comment in that method for details.
+  if ( theNodeState == SUPERV::DoneState ) {
+    SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
+    if ( aNode ) {
+      //cout << " *** theNode " << theNodeName << " received DONE_STATE *** " << endl;
+      SUPERVGUI_CanvasPortOut* aPortOut;
+      QObjectList* aPortList = aNode->queryList("SUPERVGUI_CanvasPortOut");
+      QObjectListIt aPortIt(*aPortList);
+      while ((aPortOut=(SUPERVGUI_CanvasPortOut*)aPortIt.current()) != 0) {
+       ++aPortIt;
+       if ( aPortOut->isInStudy() && aPortOut->getEngine()->State() == SUPERV::ReadyState ) {
+         //cout << " *** " << theNodeName << "[" << aPortOut->name() << "]--> goes into study *** " << endl;
+         putDataStudy( aPortOut->getEngine(), STUDY_PORT_OUT );
+       }
+      }
+      delete aPortList;      
+    } 
+    //else //normal case if Node is not found is when node is a graph!  it can receive DoneState as well!  
+    //  MESSAGE( "ERROR in SUPERVGUI_Main::execute() : CanvasNode \"" << theNodeName << "\" NOT FOUND in myCanvas" );
   }
 }
 
 
 void SUPERVGUI_Main::sync() {
-    Trace("SUPERVGUI_Main::sync")
-    if ((SUPERV_isNull(dataflow))) return;
-    QString t = tr("GRAPH_TITLE");
-    
-    t += dataflow->Name();
-    setCaption(t);
-
-    study->updateObjBrowser();
-    if (myCurrentView == TABLE) {
-      array->sync();
-    } else if (myCurrentView == GRAPH) {
-      graph->sync();
-    } else {
-      myCanvas->sync();
-      myCanvas->update();
-    }
-}
-
-
-void SUPERVGUI_Main::showTable() {
-  if (myCurrentView == TABLE) return;
+  Trace("SUPERVGUI_Main::sync");
+  if ((SUPERV_isNull(dataflow))) 
+    return;
+  QString t = tr("GRAPH_TITLE");
+  
+  t += dataflow->Name();
+  setCaption(t);
 
-  if (array->create()) {
-    if (myCurrentView == GRAPH)
-      graph->hide();
-    else
-      myCanvasView->hide();
-    myCurrentView = TABLE;
+  study->updateObjBrowser();
+  if (myCurrentView == CANVASTABLE) {
+    myArray->sync();
+    myArray->update();
+  } else {
+    myCanvas->sync();
+    myCanvas->update();
   }
-  sync();
 }
 
+void SUPERVGUI_Main::showCanvasTable() {
+  if (myCurrentView == CANVASTABLE) 
+    return;
 
-void SUPERVGUI_Main::showFullGraph() {
-  if (myCurrentView == TABLE) {
-    array->destroy();
-    graph->show();    
-  }
-  else if (myCurrentView != GRAPH) { // (myCurrentView == CANVAS) {
+  if (myArray->create()) {
     myCanvasView->hide();
-    graph->show();
+    myArrayView->show();
+    myCurrentView = CANVASTABLE;
   }
-  myCurrentView = GRAPH;
-  graph->sync();
-  graph->setFullView();
+  sync();
 }
 
-
 void SUPERVGUI_Main::showContolFlow() {
   bool merge = false;
-  if (myCurrentView == TABLE) {
-    array->destroy();
-    merge = true;
-  }
-  else if (myCurrentView == GRAPH) {
-    graph->hide();
+  if (myCurrentView == CANVASTABLE) {
+    myArrayView->hide();
+    myArray->destroy();
     merge = true;
   }
   myCurrentView = CONTROLFLOW;
@@ -403,15 +314,13 @@ void SUPERVGUI_Main::showContolFlow() {
 }
 
 void SUPERVGUI_Main::showCanvas() {
-  if (myCurrentView == CANVAS) return;
+  if (myCurrentView == CANVAS) 
+    return;
 
   bool merge = false;
-  if (myCurrentView == TABLE) {
-    array->destroy();
-    merge = true;
-  }
-  else if (myCurrentView == GRAPH) {
-    graph->hide();
+  if (myCurrentView == CANVASTABLE) {
+    myArrayView->hide();
+    myArray->destroy();
     merge = true;
   }
   myCurrentView = CANVAS;
@@ -422,43 +331,31 @@ void SUPERVGUI_Main::showCanvas() {
   }
 }
 
-
-bool SUPERVGUI_Main::exportDataflow(QString theFile) {
-  Trace("SUPERVGUI_Main::exportDataflow");
-  if ((SUPERV_isNull(dataflow))) return false;
-
-  if (!theFile.isEmpty()) {
-    if (!dataflow->Export(theFile.latin1())) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
-      return false;
-    }
-  }
-  return true;
-}
-
 void SUPERVGUI_Main::insertFile() {
-    Trace("SUPERVGUI_Main::insertFile")
+    Trace("SUPERVGUI_Main::insertFile");
     if ((SUPERV_isNull(dataflow))) return;
 
+    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 == TABLE) {
-           array->destroy();
-           array->create();
-         }
-         else if (myCurrentView != GRAPH) { // (myCurrentView == CANVAS) {
-           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() {
@@ -593,42 +490,33 @@ void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame)
 }
 
 void SUPERVGUI_Main::run() {
-  Trace("SUPERVGUI_Main::run")
+  Trace("SUPERVGUI_Main::run");
     if ((SUPERV_isNull(dataflow))) return;
   
   if (dataflow->IsEditing()) {
     if (!dataflow->IsValid()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
-    } else if (!dataflow->IsExecutable()) {
+    } 
+    else if (!dataflow->IsExecutable()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
-    } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
+    } 
+    else if (myCanvasView->isAnyLinkCreating()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
-    } else {
+    } 
+    else {
       myRunTime = QDateTime::currentDateTime();
-      if (myIsKilled) {
-      //if (myIsRunned) {
-       if (!dataflow->ReRun()) {
-         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
-         if (dataflow->State() == SUPERV::ErrorState) {
-           kill();
-         }
-       } else {
-         myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         sync();
-       }
-      } else {
-       if (!dataflow->Run()) {
-         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
-         if (dataflow->State() == SUPERV::ErrorState) {
-           kill();
-         }
-       } else {
-         myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         sync();
+      if ( !dataflow->Run() ) {
+       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+       if ( dataflow->State() == SUPERV::ErrorState ) {
+         kill();
        }
+      } 
+      else {
+       myThread->startThread(tr("MSG_GRAPH_STARTED"));
       }
     }
-  } else {
+  } 
+  else {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
   }
 }
@@ -636,57 +524,54 @@ void SUPERVGUI_Main::run() {
 
 
 void SUPERVGUI_Main::startExecute() {
-  Trace("SUPERVGUI_Main::startExecute")
+  Trace("SUPERVGUI_Main::startExecute");
   if ((SUPERV_isNull(dataflow))) return;
   
   if (dataflow->IsEditing()) {
     if (!dataflow->IsValid()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
-    } else if (!dataflow->IsExecutable()) {
+    } 
+    else if (!dataflow->IsExecutable()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
-    } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
+    } 
+    else if (myCanvasView->isAnyLinkCreating()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
-    } else {
+    } 
+    else {
       myRunTime = QDateTime::currentDateTime();
-      if (myIsKilled) {
-      //if (myIsRunned) {
-       if (!dataflow->ReStart()) {
-         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
-       } else {
-         myThread->startThread(tr("MSG_GRAPH_STARTED"));
-       }
-      }
+      if (!dataflow->Start()) {
+       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+      } 
       else {
-       if (!dataflow->Start()) {
-         QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
-       } else {
-         myThread->startThread(tr("MSG_GRAPH_STARTED"));
-       }
+       myThread->startThread(tr("MSG_GRAPH_STARTED"));
       }
     }
-  } else {
+  } 
+  else {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
   }
 }
 
 
 void SUPERVGUI_Main::kill() {
-    Trace("SUPERVGUI_Main::kill")
-    if ((SUPERV_isNull(dataflow))) return;
+  Trace("SUPERVGUI_Main::kill");
+  if ((SUPERV_isNull(dataflow))) 
+    return;
 
-    if (dataflow->IsEditing()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
-    } else if (dataflow->Kill()) {
-      myIsKilled = true;
-      myThread->stopThread(tr("MSG_GRAPH_KILLED"));
-      sync();
-    } else {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
-    }
+  if (dataflow->IsEditing()) {
+    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
+  } 
+  else if (dataflow->Kill()) {
+    myThread->stopThread(tr("MSG_GRAPH_KILLED"));
+    sync();
+  } 
+  else {
+    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
+  }
 }
 
 void SUPERVGUI_Main::suspendResume() {
-    Trace("SUPERVGUI_Main::suspendResume")
+    Trace("SUPERVGUI_Main::suspendResume");
     if ((SUPERV_isNull(dataflow))) return;
 
     if (dataflow->IsEditing()) {
@@ -706,9 +591,11 @@ void SUPERVGUI_Main::suspendResume() {
       }
     }
 }
-
+/* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
+   the comment from kloss below may be explaining it, but it's in French and I do not understand it..
+   It also calls deprecated method of Engine: ReStart(). 
 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
-    Trace("SUPERVGUI_Main::stopRestart")
+    Trace("SUPERVGUI_Main::stopRestart");
     if ((SUPERV_isNull(dataflow))) return;
 
     if (dataflow->IsEditing()) {
@@ -728,20 +615,24 @@ void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le
         };
     };
 }
-
+*/
 void SUPERVGUI_Main::addNode() {
   Trace("SUPERVGUI_Main::addNode");
-  if (SUPERV_isNull(dataflow)) return;
+  bool error = SUPERV_isNull( dataflow );
+  if ( error ) 
+    return;
 
-  if (dataflow->IsExecuting()) {
-    if (QMessageBox::warning(QAD_Application::getDesktop(), 
-                            tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
-                            QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
-      return;       
-    } else {
+  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 
+
   Supervision.getBrowser()->choose();
 }
 
@@ -749,20 +640,11 @@ void SUPERVGUI_Main::addNode() {
  * Add Computation node
  */
 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
-  //cout<<"### X="<<theNode->X()<<"  Y="<<theNode->Y()<<endl;
   switch (myCurrentView) {
-  case GRAPH:
-    {
-      SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
-      graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
-      graph->addChild(aNode, theNode->X(), theNode->Y());
-      aNode->sync();
-    }
-    break;
-  case TABLE:
-    array->destroy();
-    array->create();
-    break;
+  case CANVASTABLE:
+    myArray->destroy();
+    myArray->create();
+    break;  
   case CANVAS:
   case CONTROLFLOW: 
     {
@@ -781,17 +663,9 @@ void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
  */
 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
   switch (myCurrentView) {
-  case GRAPH:
-    {
-      SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
-      graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
-      graph->addChild(aNode, theNode->X(), theNode->Y());
-      aNode->sync();
-    }
-    break;
-  case TABLE:
-    array->destroy();
-    array->create();
+  case CANVASTABLE:
+    myArray->destroy();
+    myArray->create();
     break;
   case CANVAS:
   case CONTROLFLOW: 
@@ -811,29 +685,9 @@ void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
  */
 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
   switch (myCurrentView) {
-  case GRAPH:
-    {
-      SUPERVGUI_StartControlNode* aStartPrs = 
-       new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
-      SUPERVGUI_EndControlNode* aEndPrs = 
-       new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
-
-      graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());            
-      graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
-      graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
-      graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
-      if (Update) {
-       aStartPrs->updateLinksPrs();
-       aEndPrs->updateLinksPrs();
-      }
-      aStartPrs->sync();
-      aEndPrs->sync();
-      graph->repaintContents();
-    }
-    break;
-  case TABLE:
-    array->destroy();
-    array->create();
+  case CANVASTABLE:
+    myArray->destroy();
+    myArray->create();
     break;
   case CANVAS:
   case CONTROLFLOW: 
@@ -859,19 +713,10 @@ void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theE
  * Add Macro node
  */
 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
-  //cout<<"### X="<<theNode->X()<<"  Y="<<theNode->Y()<<endl;
   switch (myCurrentView) {
-  case GRAPH:
-    {
-      SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
-      graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
-      graph->addChild(aNode, theNode->X(), theNode->Y());
-      aNode->sync();
-    }
-    break;
-  case TABLE:
-    array->destroy();
-    array->create();
+  case CANVASTABLE:
+    myArray->destroy();
+    myArray->create();
     break;
   case CANVAS:
   case CONTROLFLOW: 
@@ -886,45 +731,44 @@ void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
   }
 }
 
-
-SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
-    Trace("SUPERVGUI_Main::getGraph")
-    return(graph);
+SUPERVGUI_CanvasArray*  SUPERVGUI_Main::getCanvasArray() {
+  Trace("SUPERVGUI_Main::getCanvasArray");
+  return(myArray);
 }
 
-SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
-    Trace("SUPERVGUI_Main::getArray")
-    return(array);
+SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
+  Trace("SUPERVGUI_Main::getArrayView");
+  return(myArrayView);
 }
 
 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
-    Trace("SUPERVGUI_Main::getCanvas")
-    return(myCanvas);
+  Trace("SUPERVGUI_Main::getCanvas");
+  return(myCanvas);
 }
 
 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
-    Trace("SUPERVGUI_Main::getCanvasView")
-      return(myCanvasView);
+    Trace("SUPERVGUI_Main::getCanvasView");
+    return(myCanvasView);
 }
 
 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
-    Trace("SUPERVGUI_Main::getDataflow")
-    return(dataflow);
+  Trace("SUPERVGUI_Main::getDataflow");
+  return(dataflow);
 }
 
 QAD_Message* SUPERVGUI_Main::getMessage() {
-    Trace("SUPERVGUI_Main::getMessage")
-    return(message);
+  Trace("SUPERVGUI_Main::getMessage");
+  return(message);
 }
 
 QAD_Study* SUPERVGUI_Main::getStudy() {
-    Trace("SUPERVGUI_Main::getStudy")
-    return(study);
+  Trace("SUPERVGUI_Main::getStudy");
+  return(study);
 }
 
 bool SUPERVGUI_Main::isArrayShown() {
-    Trace("SUPERVGUI_Main::isArrayShown")
-    return(myCurrentView == TABLE);
+  Trace("SUPERVGUI_Main::isArrayShown");
+  return(myCurrentView == CANVASTABLE);  
 }
 
 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
@@ -949,10 +793,6 @@ void SUPERVGUI_Main::changeInformation() {
   if (aDlg->exec() )
     sync();
   delete aDlg;
-  /*    Trace("SUPERVGUI_Main::changeInformation")
-    if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
-      sync();
-      }*/
 }
 
 // returns false, if can't add dataflow into the study
@@ -960,14 +800,19 @@ bool SUPERVGUI_Main::addStudy() {
   Trace("SUPERVGUI_Main::addStudy");
   if (myIsFromStudy) return false;
   if ((SUPERV_isNull(dataflow))) return false;
-  
+
   SALOMEDS::Study_var            aStudy = study->getStudyDocument();
+  bool                           aLocked = aStudy->GetProperties()->IsLocked();
+  // asv : 23.11.04 : if the study is locked -- then we can't put anything in it.
+  //       fix for PAL6852.
+  if ( aLocked ) 
+    return false;
+  
   SALOMEDS::StudyBuilder_var     aBuilder  = aStudy->NewBuilder();
   SALOMEDS::GenericAttribute_var anAttr;
   SALOMEDS::AttributeName_var    aName;
   SALOMEDS::AttributeIOR_var     anIORAttr;
   SALOMEDS::AttributePixMap_var  aPixmap;
-  bool                           aLocked = aStudy->GetProperties()->IsLocked();
   QAD_Operation*                 op = new SALOMEGUI_ImportOperation( study );
   
   // searching dataflow
@@ -977,7 +822,7 @@ bool SUPERVGUI_Main::addStudy() {
     if (aComponent->_is_nil()) { // is supervision component not found, then create it
       QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
       anOperation->start();
-      if (aLocked) aStudy->GetProperties()->SetLocked(false);
+      //if (aLocked) aStudy->GetProperties()->SetLocked(false);
       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
       aName = SALOMEDS::AttributeName::_narrow(anAttr);
@@ -987,7 +832,7 @@ bool SUPERVGUI_Main::addStudy() {
       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
       aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
       aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
-      if (aLocked) aStudy->GetProperties()->SetLocked(true);
+      //if (aLocked) aStudy->GetProperties()->SetLocked(true);
       anOperation->finish();
     }
     op->start();
@@ -999,7 +844,7 @@ bool SUPERVGUI_Main::addStudy() {
     anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
     anIORAttr->SetValue(dataflow->getIOR());
     op->finish();
-    if (aLocked) return false;
+    //if (aLocked) return false;
   }
 
   sync();
@@ -1011,7 +856,7 @@ bool SUPERVGUI_Main::addStudy() {
 
 
 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
-    Trace("SUPERVGUI_Main::chooseData")
+    Trace("SUPERVGUI_Main::chooseData");
     if (choosing) {
         QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
         if (!id.isEmpty()) {
@@ -1022,7 +867,11 @@ void SUPERVGUI_Main::chooseData(QListViewItem* item) {
             if (object->FindAttribute(anAttr, "AttributeIOR")) {
               anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
              ior = anIOR->Value();
-             portIn->setValue(ior);
+             
+             // asv : 13.12.04 : commented out use of portIn field, but it seems that it 
+             // should be replaced with some analogious code... selection of IOR was done -
+             // put its value into port.
+             //portIn->setValue(ior);
 
              // stop selection
              choosing = false;
@@ -1034,15 +883,6 @@ void SUPERVGUI_Main::chooseData(QListViewItem* item) {
     }
 }
 
-void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
-    Trace("SUPERVGUI_Main::setData")
-    portIn   = p;
-    choosing = true;
-    setCursor(forbiddenCursor);
-    objectBrowser->setCursor(pointingHandCursor);
-    Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
-}
-
 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
                                               const SALOMEDS::SObject_var theSO,
                                               const char* theName,
@@ -1081,28 +921,36 @@ SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStud
 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
   Trace("SUPERVGUI_Main::putDataStudy");
 
+  // static variable to ensure that only one instance (thread) is executing this function 
   static bool isIn = false;
-  if (isIn) return true; else isIn = true;
+  if (isIn) 
+    return true; 
+  else 
+    isIn = true;
 
   SALOMEDS::Study_var            aStudy = study->getStudyDocument();
+  bool                           aLocked = aStudy->GetProperties()->IsLocked();
+  // asv : 23.11.04 : if the study is locked -- then we can't put anything in it.
+  //       fix for PAL6852.
+  if ( aLocked ) {
+    isIn = false;
+    return false;
+  }
+
   SALOMEDS::StudyBuilder_var     aBuilder  = aStudy->NewBuilder();
   SALOMEDS::GenericAttribute_var anAttr;
   SALOMEDS::AttributeName_var    aName;
   SALOMEDS::AttributeIOR_var     anIORAttr;
   SALOMEDS::AttributePixMap_var  aPixmap;
   bool                           aTransaction = false;
-  bool                           aLocked = aStudy->GetProperties()->IsLocked();
-  //  QAD_Operation*                 op = new SALOMEGUI_ImportOperation( study );
   
   // searching dataflow
   SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
   if (aSO->_is_nil()) { // create new dataflow SObject
     SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
     if (aComponent->_is_nil()) { // is supervision component not found, then create it
-      //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
-      //anOperation->start();
       aBuilder->NewCommand();
-      if (aLocked) aStudy->GetProperties()->SetLocked(false);
+      //if (aLocked) aStudy->GetProperties()->SetLocked(false);
       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
       aName = SALOMEDS::AttributeName::_narrow(anAttr);
@@ -1113,12 +961,10 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
       aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
       aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
-      if (aLocked) aStudy->GetProperties()->SetLocked(true);
-      //      anOperation->finish();
+      //if (aLocked) aStudy->GetProperties()->SetLocked(true);
       aBuilder->CommitCommand();
     }
     aTransaction = true;
-    //op->start();
     aBuilder->NewCommand();
     aSO = aBuilder->NewObject(aComponent);
     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
@@ -1128,19 +974,14 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
     anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
     anIORAttr->SetValue(dataflow->getIOR());
   }
-  //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
+
   aSO = SearchOrCreateSOWithName(aStudy, aSO,  // get run time SO
-                                QString("Run ") + myRunTime.toString() /*, anOperation*/, &aTransaction);
-  aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name()/*, anOperation*/, &aTransaction); // get node SO
-  aSO = SearchOrCreateSOWithName(aStudy, aSO, inout/*, anOperation*/, &aTransaction); // get in/out SO
-  aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name()/*, anOperation*/, &aTransaction); // get port SO
-
-  if (aLocked) {
-    if (aTransaction) aBuilder->CommitCommand();
-      //op->finish();
-    isIn = false;
-    return false;
-  }
+                                QString("Run ") + myRunTime.toString(), &aTransaction);
+  aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name(), &aTransaction); // get node SO
+  aSO = SearchOrCreateSOWithName(aStudy, aSO, inout, &aTransaction); // get in/out SO
+  aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name(), &aTransaction); // get port SO
+
+  if (aTransaction) aBuilder->CommitCommand();
 
   anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
   anIORAttr  = SALOMEDS::AttributeIOR::_narrow(anAttr);
@@ -1168,14 +1009,12 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
          if (!aTransaction) {
            aTmpSO = aSO;
            aTransaction = true;
-           //op->start();
            aBuilder->NewCommand();
          }
-         aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
+           aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, /*anObject->Name()*/"");
          aBuilder->Addreference(aSO, aTmpSO);
        } else { // can't publish object: abort transaction
          if (aTransaction) aBuilder->AbortCommand();
-         //op->abort();
          isIn = false;
          return false;
        }
@@ -1187,14 +1026,12 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
   } else {
     if (!aTransaction) {
       aTransaction = true;
-      //      op->start();
       aBuilder->NewCommand();
     }
     anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
   }
   
   if (aTransaction) 
-    //op->finish();
     aBuilder->CommitCommand();
   if (!myThread->running())
     study->updateObjBrowser();
@@ -1205,32 +1042,26 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
 
 void SUPERVGUI_Main::ActivatePanning()
 {
-  if (graph->isVisible()) {
-    graph->ActivatePanning();
-  } else if (array->isVisible()) {
-    array->ActivatePanning();
-  } else if (myCanvasView->isVisible()) {
+  if (myCanvasView->isVisible()) {
     myCanvasView->ActivatePanning();
+  } else if (myArrayView->isVisible()) {
+    myArrayView->ActivatePanning();
   }
 }
 
 
 void SUPERVGUI_Main::ResetView()
 {
-  if (graph->isVisible()) {
-    graph->ResetView();
-  } else if (array->isVisible()) {
-    array->ResetView();
-  } else if (myCanvasView->isVisible()) {
+  if (myCanvasView->isVisible()) {
     myCanvasView->ResetView();
+  } else if (myArrayView->isVisible()) {
+    myArrayView->ResetView();
   }
 }
 
 
 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
   myIsFromStudy = theToStudy;
-  graph->setAsFromStudy(theToStudy);
-  array->setAsFromStudy(theToStudy);
   myCanvas->setAsFromStudy(theToStudy);
 }
 
@@ -1283,10 +1114,10 @@ bool SUPERVGUI_Main::isFiltered(char* graph,  char* node,   char* type, char* me
   Trace("SUPERVGUI_Main::isFiltered");
   bool b = false;
   if (strcmp(getDataflow()->Name(), graph) == 0) {
-    SUPERVGUI_Node* n;
-    QObjectList* nodes = queryList("SUPERVGUI_Node");
+    SUPERVGUI_CanvasNode* n;
+    QObjectList* nodes = queryList("SUPERVGUI_CanvasNode");
     QObjectListIt i(*nodes);
-    while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
+    while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
       ++i;
       if (strcmp(n->name(), node) == 0) {
        if (strcmp(type, NOTIF_WARNING) == 0) {
@@ -1317,10 +1148,10 @@ void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
 
 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) { 
 
-  array->setPaletteBackgroundColor(color);
-  graph->setPaletteBackgroundColor(color);
   myCanvas->setBackgroundColor(color);
   myCanvasView->setPaletteBackgroundColor(color.light());
+  myArray->setBackgroundColor(color);
+  myArrayView->setPaletteBackgroundColor(color.light());
   
   SUPERVGraph_View::setPaletteBackgroundColor(color); 
 }
@@ -1361,6 +1192,7 @@ void SUPERVGUI_Main::startTimer() {
 void SUPERVGUI_Main::executionFinished() {
   getStudy()->updateObjBrowser();
   myCanvas->update();
+  myArray->update();
 }
 
 void SUPERVGUI_Main::checkExecution() {
@@ -1370,6 +1202,43 @@ void SUPERVGUI_Main::checkExecution() {
   }
 }
 
+/**
+ * Editing() is to be called by any operation in GUI before modification of a datamodel
+ * (add/remove ports or nodes, etc.).  It is used to resolve inconsistancies between 2 data models
+ * in Engine: Editor and Executor.  During and after execution, the values of ports and statuses of nodes
+ * are taken from Executor data model.  But when user starts editing the graph - these changes must
+ * be applied to Editor data model.  This function destroys Executor data model and moves to Editor.   
+ */ 
+void SUPERVGUI_Main::Editing() {
+  if ( !SUPERV_isNull( dataflow ) )
+    dataflow->Editing();
+  
+  // updata GUI, Nodes' statuses and Ports' values could change.
+  sync();
+}
+
+void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
+{
+  // mkr: since the deletion of the node allow only in CANVAS view,
+  // it is necessary to remove the CanvasArray's children, which
+  // have the same CNode engine as deleting node. This CNode is given
+  // as argument
+  if (myArray) {
+    const QObjectList* aChList = myArray->children();
+    if ( aChList ) { // asv 27.01.05 : fix for 7817
+      QObjectListIt aItChList(*aChList);
+      SUPERVGUI_CanvasNode* anObjNode;
+      while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
+       ++aItChList;
+       if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
+         myArray->removeChild(anObjNode);
+         delete anObjNode;
+       }
+      }
+    } // end of if ( ChList )
+  }
+}
+
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
@@ -1429,6 +1298,9 @@ void SUPERVGUI_Thread::run()
   QPtrList< SUPERV::GraphState > aStates;
 
   myMain->startTimer();
+
+  myMain->myGUIEventLoopFinished = false;
+
   while(myIsActive) {
     myMain->getDataflow()->Event(aNode, aEvent, aState);
     
@@ -1540,6 +1412,8 @@ void SUPERVGUI_Thread::run()
 //   qApp->unlock();
   // VSR: 04/12/03 <---    
 
+  myMain->myGUIEventLoopFinished = true;
+
   QThread::exit();
 }