Salome HOME
A new dialog class for edition of Ports of an InLine nodes is introduced. This funct...
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 284888742e361908d88b5c8c0cc8ffef74784f66..aa397a8c17f7bf91e69e0dd94b8967fc07afad61 100644 (file)
@@ -36,6 +36,7 @@ using namespace std;
 #include "QAD_Application.h"
 #include "SUPERVGUI_Def.h"
 #include "QAD_RightFrame.h"
+#include "SALOME_Event.hxx"
 #include "SUPERVGraph_ViewFrame.h"
 #include <qlayout.h>
 #include <qfile.h>
@@ -47,8 +48,12 @@ using namespace std;
 #include "SUPERVGUI_Notification.h"
 #include "SALOMEGUI_ImportOperation.h"
 #include "SUPERVGUI_Information.h"
+#include "SUPERVGUI_CanvasControlNode.h"
+#include <qvalidator.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 ),
@@ -76,7 +81,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
     if (obj->FindAttribute(anAttr, "AttributeIOR")) {
       SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
       Standard_CString ior = anIOR->Value();
-      dataflow = Supervision.getEngine()->getGraph(ior);
+      dataflow = Supervision.getEngine()->getStreamGraph(ior);
       if (SUPERV_isNull(dataflow)) {
        QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
        close();
@@ -88,7 +93,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
       close();
     }
   } else {
-    dataflow = Supervision.getEngine()->Graph(MAIN_NEW);
+    dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
     if (SUPERV_isNull(dataflow)) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
       close();
@@ -112,9 +117,9 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
     theParent->setViewWidget(this);  
   if (isModify) {
-    dataflow = Supervision.getEngine()->Graph(f);
+    dataflow = Supervision.getEngine()->StreamGraph(f);
   } else {
-    dataflow = Supervision.getEngine()->GraphE(f);
+    dataflow = Supervision.getEngine()->StreamGraphE(f);
   }
   if (SUPERV_isNull(dataflow)) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
@@ -123,8 +128,9 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
     init(theDesktop);
   }
 }
+*/
 
-SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph cp)
+SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph theDataFlow )
      : SUPERVGraph_View(theParent),
        myLogged( false ),
        myFiltered( false ),
@@ -137,8 +143,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
 {
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
   theParent->setViewWidget(this);  
-  //  dataflow = cp->Copy();
-  dataflow = cp;
+  dataflow = theDataFlow;
   if (SUPERV_isNull(dataflow)) {
     QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
     close();
@@ -159,9 +164,9 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   myThread->setMain(this);
 
   myIsKilled = false;
-  //myIsRunned = false;
-  myCurrentView = GRAPH;
+  myCurrentView = CANVAS;
   myIsFromStudy = false;
+  myLastGraph = 0;
   study     = theDesktop->getActiveStudy();
   
   SALOMEDS::Study_var studyDoc = study->getStudyDocument();
@@ -178,7 +183,6 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
     father = builder->NewComponent(STUDY_SUPERVISION);
     anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
     aName = SALOMEDS::AttributeName::_narrow(anAttr);
-    //aName->SetValue("Supervision");
     aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
     
     anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
@@ -194,7 +198,11 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
     
 
   graph = new SUPERVGUI_Graph(this);
+  graph->hide();
   array = new SUPERVGUI_Array(this);
+
+  myCanvas = new SUPERVGUI_Canvas(this);
+  myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
   
   message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
   notification = new NOTIFICATION_Consumer();
@@ -204,7 +212,11 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   layout->setSpacing(0);
   layout->addWidget(graph);
   layout->addWidget(array);
+  layout->addWidget(myCanvasView);
 
+  if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
+    myCanvas->merge();
+  }
   sync();
   show();
   if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
@@ -218,21 +230,36 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
 
 SUPERVGUI_Main::~SUPERVGUI_Main() {
   Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
+
+  // close all opened SubGraphs 
+  QMap<QString, QAD_StudyFrame*>::iterator it;
+  for (it = mySubGraphs.begin(); it != mySubGraphs.end(); ++it) {
+    it.data()->removeEventFilter(this);
+    it.data()->disconnect();
+    it.data()->close();
+
+    QAD_Study* aStudy = it.data()->getStudy();
+    aStudy->removeStudyFrame(it.data());
+  }
+  mySubGraphs.clear();
+  mySubGraphMap.clear();
+  /*
+  QAD_StudyFrame* aSubGraph;
+  for (aSubGraph = mySubGraphs.first(); aSubGraph; aSubGraph = mySubGraphs.next()) {
+    aSubGraph->removeEventFilter(this);
+    aSubGraph->close();
+  }
+  */
+
   if ( myLogFile != NULL) {
     fclose( myLogFile );
   }
   graph->removeLinks();
-  delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
-  if (!SUPERV_isNull(dataflow)) {
-    if (dataflow->IsExecuting()) {
-      if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
-                              tr("MSG_DF_RUNNING"), 
-                              tr("MSG_DF_EXECUTION"), 
-                              tr("MSG_DF_KILL")) == 1) {
-       dataflow->Kill();
-      }
-    }
-  }
+  //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;
 }
 
 void SUPERVGUI_Main::filterNotification() {
@@ -267,6 +294,13 @@ 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")
     QTimer::singleShot(1, this, SLOT(sync()));
@@ -277,27 +311,30 @@ void SUPERVGUI_Main::syncAsync() {
  * Called by thread when dataflow is executing
  */
 void SUPERVGUI_Main::execute(char *  theNodeName, SUPERV::GraphState theNodeState) {
-  
-  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 (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
+    SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
+    if (aNode) aNode->sync();
   }
-  if (aGraphNodePrs) {
-    aGraphNodePrs->sync();
-  }
-  else if (aNodePrs) {
-    //aNodePrs->sync();
-    aNodePrs->syncOnEvent(theNodeState);
+  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);
+    }
   }
 }
 
 
-
 void SUPERVGUI_Main::sync() {
     Trace("SUPERVGUI_Main::sync")
     if ((SUPERV_isNull(dataflow))) return;
@@ -308,9 +345,12 @@ void SUPERVGUI_Main::sync() {
 
     study->updateObjBrowser();
     if (myCurrentView == TABLE) {
-        array->sync();
+      array->sync();
+    } else if (myCurrentView == GRAPH) {
+      graph->sync();
     } else {
-        graph->sync();
+      myCanvas->sync();
+      myCanvas->update();
     }
 }
 
@@ -319,8 +359,11 @@ void SUPERVGUI_Main::showTable() {
   if (myCurrentView == TABLE) return;
 
   if (array->create()) {
+    if (myCurrentView == GRAPH)
+      graph->hide();
+    else
+      myCanvasView->hide();
     myCurrentView = TABLE;
-    graph->hide();
   }
   sync();
 }
@@ -331,6 +374,10 @@ void SUPERVGUI_Main::showFullGraph() {
     array->destroy();
     graph->show();    
   }
+  else if (myCurrentView != GRAPH) { // (myCurrentView == CANVAS) {
+    myCanvasView->hide();
+    graph->show();
+  }
   myCurrentView = GRAPH;
   graph->sync();
   graph->setFullView();
@@ -338,27 +385,41 @@ void SUPERVGUI_Main::showFullGraph() {
 
 
 void SUPERVGUI_Main::showContolFlow() {
+  bool merge = false;
   if (myCurrentView == TABLE) {
     array->destroy();
-    graph->show();    
+    merge = true;
+  }
+  else if (myCurrentView == GRAPH) {
+    graph->hide();
+    merge = true;
   }
   myCurrentView = CONTROLFLOW;
-  graph->sync();
-  graph->setControlView();
+  myCanvas->setControlView();
+  if (merge) {
+    myCanvas->merge();
+    myCanvasView->show();
+  }
 }
 
+void SUPERVGUI_Main::showCanvas() {
+  if (myCurrentView == CANVAS) return;
 
-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;
-    }
+  bool merge = false;
+  if (myCurrentView == TABLE) {
+    array->destroy();
+    merge = true;
+  }
+  else if (myCurrentView == GRAPH) {
+    graph->hide();
+    merge = true;
+  }
+  myCurrentView = CANVAS;
+  myCanvas->setFullView();
+  if (merge) {
+    myCanvas->merge();
+    myCanvasView->show();
   }
-  return true;
 }
 
 void SUPERVGUI_Main::insertFile() {
@@ -376,6 +437,9 @@ void SUPERVGUI_Main::insertFile() {
            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));
@@ -393,17 +457,127 @@ void SUPERVGUI_Main::copy() {
   SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
     (aStudyFrame->getRightFrame()->getViewFrame());
   if(aViewFrame){
-    SUPERV_Graph aNewGraph = dataflow->Copy();
+    SUPERV_Graph aNewGraph; //  = dataflow->StreamCopy();
+    if (dataflow->IsStreamGraph()) {
+      SUPERV_StreamGraph aSGraph = dataflow->ToStreamGraph();
+      if (SUPERV_isNull(aSGraph)) {
+       QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
+       return;
+      }
+      aNewGraph = aSGraph->StreamCopy();
+    }
+    else {
+      aNewGraph = dataflow->Copy();
+    }
     QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
     aNewName += dataflow->Name();
     aNewGraph->SetName(aNewName);
-    SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame, 
+    /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
                                           Supervision.getDesktop(), 
                                           aNewGraph);
     study->showFrame(aStudyFrame);
   }
 }
 
+void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
+{
+  if (theNode->IsMacro()) {
+    // get SubGraph from MacroNode
+    SUPERV_Graph aMacro = SUPERV::Graph::_narrow(theNode);
+    SUPERV_Graph aGraph;
+    if (aMacro->IsStreamMacro())
+      aGraph = aMacro->StreamObjRef();
+    else
+      aGraph = aMacro->FlowObjRef();
+
+    // display SubGraph
+    if (SUPERV_isNull(aGraph)) {
+      QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOACCESS"));
+      return;
+    }
+    else {
+      QString aGraphName = aGraph->Name();
+      QAD_StudyFrame* aStudyFrame;
+      if (mySubGraphs.contains(aGraphName)) {
+       aStudyFrame = mySubGraphs[aGraphName];
+       aStudyFrame->setActiveWindow();
+       aStudyFrame->setFocus();
+      }
+      else {
+       aStudyFrame = Supervision.createGraph();
+       if (aStudyFrame) {
+         SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
+           (aStudyFrame->getRightFrame()->getViewFrame());
+         if(aViewFrame) {
+           /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
+                                                  Supervision.getDesktop(), 
+                                                  aGraph);
+           //    connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)), 
+           //            this,  SLOT(onSubGraphClosed(QAD_StudyFrame*)));
+           connect(aStudyFrame, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*)), 
+                   this,  SLOT(onSubGraphActivated(QAD_StudyFrame*)));
+           aStudyFrame->installEventFilter(this);
+
+           mySubGraphs.insert(aGraphName, aStudyFrame);
+           mySubGraphMap.insert(aGraphName, theNode->Name());
+
+         }
+       }
+      }
+      study->showFrame(aStudyFrame);
+      if (!correct) myLastGraph = aStudyFrame;
+    }
+  }
+}
+
+bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
+{
+  // workaround to get close event
+  if (o->inherits("QAD_StudyFrame") && e->type() == QEvent::Close) {
+    QAD_StudyFrame* aFrame = (QAD_StudyFrame*) o;
+    onSubGraphClosed(aFrame);
+  }
+  return SUPERVGraph_View::eventFilter(o, e);
+}
+
+// workaround to fix PAL6255 -> opened SubGraph is not on top
+void SUPERVGUI_Main::onSubGraphActivated(QAD_StudyFrame* theStudyFrame)
+{
+  if (myLastGraph) {
+    QAD_StudyFrame* aFrame = myLastGraph;
+    myLastGraph = 0;
+    aFrame->setActiveWindow();
+    aFrame->setFocus();
+  }
+}
+
+void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame)
+{
+  QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
+  if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
+    theStudyFrame->removeEventFilter(this);
+    disconnect(theStudyFrame, 0, this, 0);
+
+    SUPERVGraph_View* view = supervFrame->getViewWidget();
+    SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
+    if (aGraph) {
+      QString aGraphName = aGraph->getDataflow()->Name();
+      QMap<QString, QString>::iterator it = mySubGraphMap.find(aGraphName);
+      if (it != mySubGraphMap.end()) {
+       QString aNodeName = it.data();
+       SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) 
+         myCanvas->child(aNodeName, "SUPERVGUI_CanvasNode");
+       if (aNode) {
+         aNode->merge();
+         myCanvas->update();
+       }
+       mySubGraphMap.remove(it);
+      }
+      mySubGraphs.remove(aGraphName);
+    }
+  }
+}
+
 void SUPERVGUI_Main::run() {
   Trace("SUPERVGUI_Main::run")
     if ((SUPERV_isNull(dataflow))) return;
@@ -413,7 +587,7 @@ void SUPERVGUI_Main::run() {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
     } else if (!dataflow->IsExecutable()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
-    } else if (graph->isAnyLinkCreating()) {
+    } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
     } else {
       myRunTime = QDateTime::currentDateTime();
@@ -421,18 +595,21 @@ void SUPERVGUI_Main::run() {
       //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"));
-         //syncNotification();
          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"));
-         //syncNotification();
-         //myIsRunned = true;
          sync();
        }
       }
@@ -453,7 +630,7 @@ void SUPERVGUI_Main::startExecute() {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
     } else if (!dataflow->IsExecutable()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
-    } else if (graph->isAnyLinkCreating()) {
+    } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
     } else {
       myRunTime = QDateTime::currentDateTime();
@@ -463,7 +640,6 @@ void SUPERVGUI_Main::startExecute() {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
        }
       }
       else {
@@ -471,7 +647,6 @@ void SUPERVGUI_Main::startExecute() {
          QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
        } else {
          myThread->startThread(tr("MSG_GRAPH_STARTED"));
-         //syncNotification();
        }
       }
     }
@@ -556,8 +731,6 @@ void SUPERVGUI_Main::addNode() {
   Supervision.getBrowser()->choose();
 }
 
-
-
 /**
  * Add Computation node
  */
@@ -572,19 +745,20 @@ void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
       aNode->sync();
     }
     break;
-  case CONTROLFLOW: 
-    {
-      SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
-      aNode->hideAll();
-      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 CANVAS:
+  case CONTROLFLOW: 
+    {
+      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode(myCanvas, this, theNode);
+      aNode->move(theNode->X(), theNode->Y());
+      if (myCurrentView == CONTROLFLOW) aNode->hideAll();
+      aNode->show();
+      myCanvas->update();
+    }
+    break;
   }
 }
 
@@ -601,19 +775,20 @@ void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
       aNode->sync();
     }
     break;
-  case CONTROLFLOW: 
-    {
-      SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
-      aNode->hideAll();
-      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 CANVAS:
+  case CONTROLFLOW: 
+    {
+      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode(myCanvas, this, theNode);
+      aNode->move(theNode->X(), theNode->Y());
+      if (myCurrentView == CONTROLFLOW) aNode->hideAll();
+      aNode->show();
+      myCanvas->update();
+    }
+    break;
   }
 }
 
@@ -642,38 +817,62 @@ void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theE
       graph->repaintContents();
     }
     break;
+  case TABLE:
+    array->destroy();
+    array->create();
+    break;
+  case CANVAS:
   case CONTROLFLOW: 
     {
-      SUPERVGUI_StartControlNode* aStartPrs = 
-       new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
-      SUPERVGUI_EndControlNode* aEndPrs = 
-       new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
-      
-      aStartPrs->hideAll();
-      aEndPrs->hideAll();
-      
-      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();
+      SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode(myCanvas, this, theStartNode);
+      aStartNode->move(theStartNode->X(), theStartNode->Y());
+      if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
+
+      SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode(myCanvas, this, theEndNode, aStartNode);
+      aEndNode->move(theEndNode->X(), theEndNode->Y());
+      if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
+
+      aStartNode->show();
+      aEndNode->show();
+      myCanvas->update();
+    }
+    break;
+  }
+}
+
+
+/**
+ * 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();
     break;
+  case CANVAS:
+  case CONTROLFLOW: 
+    {
+      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode(myCanvas, this, theNode);
+      aNode->move(theNode->X(), theNode->Y());
+      if (myCurrentView == CONTROLFLOW) aNode->hideAll();
+      aNode->show();
+      myCanvas->update();
+    }
+    break;
   }
 }
 
 
-
 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
     Trace("SUPERVGUI_Main::getGraph")
     return(graph);
@@ -684,6 +883,16 @@ SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
     return(array);
 }
 
+SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
+    Trace("SUPERVGUI_Main::getCanvas")
+    return(myCanvas);
+}
+
+SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
+    Trace("SUPERVGUI_Main::getCanvasView")
+      return(myCanvasView);
+}
+
 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
     Trace("SUPERVGUI_Main::getDataflow")
     return(dataflow);
@@ -708,6 +917,7 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
   Trace("SUPERVGUI_Main::showPopup");
   // To check is Supervision active?
   if (myIsLocked) return;
+  //if (dataflow->IsExecuting()) return;
 
   //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
   if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
@@ -985,6 +1195,8 @@ void SUPERVGUI_Main::ActivatePanning()
     graph->ActivatePanning();
   } else if (array->isVisible()) {
     array->ActivatePanning();
+  } else if (myCanvasView->isVisible()) {
+    myCanvasView->ActivatePanning();
   }
 }
 
@@ -995,6 +1207,8 @@ void SUPERVGUI_Main::ResetView()
     graph->ResetView();
   } else if (array->isVisible()) {
     array->ResetView();
+  } else if (myCanvasView->isVisible()) {
+    myCanvasView->ResetView();
   }
 }
 
@@ -1003,6 +1217,7 @@ void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
   myIsFromStudy = theToStudy;
   graph->setAsFromStudy(theToStudy);
   array->setAsFromStudy(theToStudy);
+  myCanvas->setAsFromStudy(theToStudy);
 }
 
 void SUPERVGUI_Main::checkIsInStudy() {
@@ -1081,11 +1296,17 @@ bool SUPERVGUI_Main::isFiltered(char* graph,  char* node,   char* type, char* me
   return( b );
 }
 
+void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
+  e->accept();
+}
 
 
 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) { 
+
   array->setPaletteBackgroundColor(color);
   graph->setPaletteBackgroundColor(color);
+  myCanvas->setBackgroundColor(color);
+  myCanvasView->setPaletteBackgroundColor(color.light());
   
   SUPERVGraph_View::setPaletteBackgroundColor(color); 
 }
@@ -1125,6 +1346,7 @@ void SUPERVGUI_Main::startTimer() {
 
 void SUPERVGUI_Main::executionFinished() {
   getStudy()->updateObjBrowser();
+  myCanvas->update();
 }
 
 void SUPERVGUI_Main::checkExecution() {
@@ -1134,8 +1356,6 @@ void SUPERVGUI_Main::checkExecution() {
   }
 }
 
-
-
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
@@ -1152,7 +1372,8 @@ void SUPERVGUI_Thread::startThread(const char* m)
 {
   if (!myIsActive) {
     myIsActive = true;
-    QThread::start();
+    //QThread::start();
+    this->start();
     myMain->getMessage()->setMessage(m); 
     myMain->sync();
   }
@@ -1160,8 +1381,6 @@ void SUPERVGUI_Thread::startThread(const char* m)
 
 void SUPERVGUI_Thread::stopThread(const char* m)
 {
-  //myIsActive = false;
-  //myMain->sync();
   myMain->getMessage()->setMessage(m);
 }
 
@@ -1170,6 +1389,15 @@ void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
   myMain = theMain;
 }
 
+void SUPERVGUI_Thread::KillThread(bool theValue)
+{
+  myMutex.lock();
+  myIsActive = !(theValue);
+  myMutex.unlock();
+}
+
+typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
+
 void SUPERVGUI_Thread::run()
 {
   SUPERV_CNode aNode = NULL;
@@ -1189,24 +1417,27 @@ void SUPERVGUI_Thread::run()
   myMain->startTimer();
   while(myIsActive) {
     myMain->getDataflow()->Event(aNode, aEvent, aState);
-      
+    
     if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
        ||
-       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState) {
+       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
+       ||
+       aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
+
       if (myMain->getEventNodes().count()) {
        myMain->removeEventNodes();
-      }
+      }    
       if (myMain->getStates().count()) {
        myMain->removeStates();
-      }
+      }    
       myIsActive = false;
     }
-    else {
-      if ( aNode != NULL) {
+    else {    
+      if ( aNode != NULL && !CORBA::is_nil( aNode ) ) {
        aName = aNode->Name();
       }
 
-      if ( aPrevNode == NULL ) {  //first initialize aPrev... variables
+      if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) {  //first initialize aPrev... variables
        anEventNodes = myMain->getEventNodes();
        anEventNodes.append( &aName ) ;
        myMain->setEventNodes(anEventNodes);
@@ -1239,10 +1470,10 @@ void SUPERVGUI_Thread::run()
          myMain->setStates(aStates);
        }
       }
-    }
+    }      
     if (!myIsActive) {
       switch (myMain->getDataflow()->State()) {
-      case SUPERV_Editing : 
+      case SUPERV_Editing :     
        stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
        break;
        
@@ -1254,21 +1485,25 @@ void SUPERVGUI_Thread::run()
        stopThread(tr("MSG_GRAPH_FINISHED"));
        break;
        
-      case SUPERV_Error : 
+      case SUPERV_Error :
        stopThread(tr("MSG_GRAPH_ABORTED"));
        break;
+       
+      case SUPERV_Kill:
+       stopThread(tr("MSG_GRAPH_KILLED"));
+       break;
       }
 
       break;
     }
-
-    if (myMain->getEventNodes().count()) {
+    if ( myMain->getEventNodes().count() ) {    
       //if list not empty call execute() -> sync()
       char * aNodeName = *(myMain->getEventNodes().getFirst());
       SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
-      qApp->lock();
-      myMain->execute(aNodeName,aNodeState);  //this is from main
-      qApp->unlock();
+
+      // It is PROHIBITED to deal with widgets in a secondary thread, so event posting is used here
+      ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aNodeName, aNodeState ) );
+
       myMain->removeFirstEN();
       myMain->removeFirstS();
     }
@@ -1276,7 +1511,11 @@ void SUPERVGUI_Thread::run()
     aPrevNode = aNode;
     aPrevEvent = aEvent;
     aPrevState = aState;
-    aPrevName = aPrevNode->Name();
+
+    if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) 
+      aPrevName = "";
+    else 
+      aPrevName = aPrevNode->Name();
     
     //usleep(10);
     //msleep(5);
@@ -1285,7 +1524,131 @@ void SUPERVGUI_Thread::run()
 //   qApp->lock();
 //   myMain->getStudy()->updateObjBrowser();
 //   qApp->unlock();
-  // VSR: 04/12/03 <---
+  // VSR: 04/12/03 <---    
+
   QThread::exit();
 }
 
+/******************************* SUPERVGUI_DSGraphParameters class ****************************************/
+/*!
+  Constructor
+*/
+SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
+     : QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
+{
+  Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
+  setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
+  setSizeGripEnabled( true );
+  myGraph = theGraph;
+
+  QGridLayout* TopLayout = new QGridLayout( this );
+  TopLayout->setSpacing( 6 );
+  TopLayout->setMargin( 11 );
+    
+  QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
+  TopGroup->setColumnLayout(0, Qt::Vertical );
+  TopGroup->layout()->setSpacing( 0 );
+  TopGroup->layout()->setMargin( 0 );
+  QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
+  TopGroupLayout->setAlignment( Qt::AlignTop );
+  TopGroupLayout->setSpacing( 6 );
+  TopGroupLayout->setMargin( 11 );
+
+  // DeltaTime
+  QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );  
+  TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
+  
+  myDeltaTime = new QAD_SpinBoxDbl( TopGroup, 0.0, 1.0, 0.1);
+  myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
+
+  // TimeOut
+  QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup); 
+  TopGroupLayout->addWidget( TimeOutL, 1, 0 );
+
+  myTimeOut = new QLineEdit( TopGroup );
+  myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myTimeOut->setValidator( new QIntValidator(this) );
+  myTimeOut->setMinimumSize( 100, 0 );
+  myTimeOut->setReadOnly( isReadOnly );
+  TopGroupLayout->addWidget( myTimeOut, 1, 1 );
+
+  // DataStreamTrace
+  QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup); 
+  TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
+
+  myDataStreamTrace = new QComboBox( TopGroup );
+  myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  myDataStreamTrace->insertItem("WithoutTrace");
+  myDataStreamTrace->insertItem("SummaryTrace");
+  myDataStreamTrace->insertItem("DetailedTrace");
+  TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
+
+  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
+  GroupButtons->setColumnLayout(0, Qt::Vertical );
+  GroupButtons->layout()->setSpacing( 0 );
+  GroupButtons->layout()->setMargin( 0 );
+  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  GroupButtonsLayout->setAlignment( Qt::AlignTop );
+  GroupButtonsLayout->setSpacing( 6 );
+  GroupButtonsLayout->setMargin( 11 );
+  
+  QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
+  QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
+
+  GroupButtonsLayout->addWidget( okB, 0, 0 );
+  GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
+  GroupButtonsLayout->addWidget( cancelB, 0, 2 );
+
+  TopLayout->addWidget( TopGroup,     0, 0 );
+  TopLayout->addWidget( GroupButtons, 1, 0 );
+
+  connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
+
+  setData();
+}
+
+/*!
+  Destructor
+*/
+SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
+  Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
+}
+
+/*!
+  Sets data function
+*/
+void SUPERVGUI_DSGraphParameters::setData() {
+  double aDeltaTime;
+  long aTimeOut;
+  SUPERV::KindOfDataStreamTrace aDataStreamTrace;
+
+//  myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
+  if (myGraph->IsStreamGraph()) {
+    SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
+    if (!SUPERV_isNull(aSGraph)) 
+      aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
+  }
+
+  myDeltaTime->setValue(aDeltaTime);
+  myTimeOut->setText(QString("%1").arg(aTimeOut));
+  myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
+}
+
+/*!
+  <OK> button slot
+*/
+void SUPERVGUI_DSGraphParameters::accept() {
+//   myGraph->SetStreamParams( myTimeOut->text().toLong(),
+//                         (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
+//                         myDeltaTime->value());
+  if (myGraph->IsStreamGraph()) {
+    SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
+    if (!SUPERV_isNull(aSGraph)) 
+      aSGraph->SetStreamParams( myTimeOut->text().toLong(),
+                               (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
+                               myDeltaTime->value());
+  }
+  QDialog::accept();
+}