Salome HOME
Patch from Christian CAREMOLI for bug PAL10339 : random GUI freeze.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 5b67e63e3d89ee137161cd3654716fbf6c7a7844..4bbdb9e5e2ba19273902f20ef74d800f66793daf 100644 (file)
 
 using namespace std;
 
-#include "QAD_Splitter.h"
-#include "QAD_LeftFrame.h"
-#include "QAD_ObjectBrowser.h"
-#include "QAD_ObjectBrowserItem.h"
-#include "QAD_PyEditor.h"
-#include "QAD_Message.h"
-#include "QAD_FileDlg.h"
-#include "QAD_Application.h"
-#include "QAD_RightFrame.h"
-#include "QAD_SpinBoxDbl.h"
-#include "QAD_MessageBox.h"
+#include "SALOMEDSClient.hxx"
+#include "SALOMEDS_Study.hxx"
+#include "SALOMEDS_SObject.hxx"
+#include <boost/shared_ptr.hpp>
+using namespace boost;
 
 #include "NOTIFICATION.hxx"
 #include "SALOME_Event.hxx"
-#include "SALOMEGUI_ImportOperation.h"
 #include "SUPERVGraph_ViewFrame.h"
 
+#include "LogWindow.h"
+#include "OB_Browser.h"
+#include "OB_ListItem.h"
+#include "SalomeApp_Application.h"
+#include "SalomeApp_ImportOperation.h"
+#include "SalomeApp_Study.h"
+#include "SUIT_FileDlg.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_Operation.h"
+#include "SUIT_Session.h"
+#include "SUIT_Study.h"
+#include "QtxDblSpinBox.h"
+
 #include "SUPERVGUI.h"
 #include "SUPERVGUI_Def.h"
 #include "SUPERVGUI_Main.h"
@@ -53,13 +59,13 @@ using namespace std;
 #include "SUPERVGUI_CanvasPort.h"
 
 #include <qvalidator.h>
+#include <qlabel.h>
 #include <qlayout.h>
 #include <qfile.h>
 #include <qlineedit.h>
 #include <qcombobox.h>
 
-
-SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph theDataFlow )
+SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, SUIT_Desktop* theDesktop, SUPERV_Graph theDataFlow )
      : SUPERVGraph_View(theParent),
        myLogged( false ),
        myFiltered( false ),
@@ -68,8 +74,8 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
        myWarning( false ),
        myStep( false ),
        myTrace( false ),
-       myVerbose( false ),
-       myGUIEventLoopFinished( true )
+       myVerbose( false )
+     //myExecuted( false )
 {
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
   theParent->setViewWidget(this);  
@@ -82,9 +88,12 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
   }
 }
 
-void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
+void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
   Trace("SUPERVGUI_Main::init");
-  if (theDesktop) myNService = theDesktop->getNameService();
+  SUIT_Application* anActApp = SUIT_Session::session()->activeApplication();
+
+  if (theDesktop) 
+    myNService = dynamic_cast<SalomeApp_Application*>( anActApp )->namingService();
   myHashCode = "New";
   myCopyNum = 0;
   choosing  = false;
@@ -96,34 +105,41 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   myCurrentView = CANVAS;
   myIsFromStudy = false;
   myLastGraph = 0;
-  study     = theDesktop->getActiveStudy();
-  
-  SALOMEDS::Study_var studyDoc = study->getStudyDocument();
+  study = anActApp->activeStudy();
+
+  //mkr: Supervision module already connected to the 
+  //active study. So, we have to commented this code!
+  /*_PTR(Study) studyDoc = (( SalomeApp_Study* )study)->studyDS();
   bool aLocked = studyDoc->GetProperties()->IsLocked();
-  SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
-  SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
-  SALOMEDS::GenericAttribute_var anAttr;
-  SALOMEDS::AttributeName_var    aName;
-  SALOMEDS::AttributePixMap_var  aPixmap;
-  if (father->_is_nil()) {
-    QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
+  _PTR(StudyBuilder) builder ( studyDoc->NewBuilder() );
+  _PTR(SComponent) father = studyDoc->FindComponent(STUDY_SUPERVISION);
+  if ( !father ) {
+    SUIT_Operation* op = new SalomeApp_ImportOperation( study->application() );
     op->start();
     if (aLocked) studyDoc->GetProperties()->SetLocked(false);
     father = builder->NewComponent(STUDY_SUPERVISION);
-    anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
-    aName = SALOMEDS::AttributeName::_narrow(anAttr);
-    aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
+    _PTR(GenericAttribute) anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
+    _PTR(AttributeName) aName ( anAttr );
+    aName->SetValue( dynamic_cast<CAM_Application*>( study->application() )->moduleTitle( "SUPERV" ).latin1() );
     
     anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
-    aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
+    _PTR(AttributePixMap) aPixmap ( anAttr );
     aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
     
-    builder->DefineComponentInstance(father, Supervision.getEngine());
+    SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+    if ( !aSupMod ) {
+      MESSAGE("NULL Supervision module!");
+      return;
+    }
+
+    builder->DefineComponentInstance(father, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
+                                             //dynamic_cast<SALOMEDS_Study*>( studyDoc )->ConvertObjectToIOR(aSupMod->getEngine()));
     if (aLocked) studyDoc->GetProperties()->SetLocked(true);
-    op->finish();
+    op->commit();
   };
+  */
 
-  objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
+  objectBrowser = dynamic_cast<SalomeApp_Application*>( study->application() )->objectBrowser();
     
   myArray = new SUPERVGUI_CanvasArray(this);
   myArrayView = new SUPERVGUI_ArrayView(myArray, this);
@@ -131,7 +147,7 @@ void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
   myCanvas = new SUPERVGUI_Canvas(this);
   myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
   
-  message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
+  message = dynamic_cast<SalomeApp_Application*>( study->application() )->logWindow();
   notification = new NOTIFICATION_Consumer();
 
   QBoxLayout * layout = new QVBoxLayout(this);
@@ -159,14 +175,21 @@ SUPERVGUI_Main::~SUPERVGUI_Main() {
   Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
 
   // close all opened SubGraphs 
-  QMap<QString, QAD_StudyFrame*>::iterator it;
+  QMap<QString, SUIT_ViewWindow*/*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());
+    //it.data()->close();
+
+    //QAD_Study* aStudy = it.data()->getStudy();
+    //aStudy->removeStudyFrame(it.data());
+    //remove view from internal view manager's list of views
+    //it.data()->getViewManager()->removeView(it.data());
+    SUIT_ViewManager* aVM = it.data()->getViewManager();
+    STD_Application* anApp = dynamic_cast<STD_Application*>( SUIT_Session::session()->activeApplication() );
+    if ( anApp ) anApp->removeViewManager(aVM);
+    if ( aVM ) delete aVM;
+    
   }
   mySubGraphs.clear();
   mySubGraphMap.clear();
@@ -215,15 +238,22 @@ void SUPERVGUI_Main::filterNotification() {
       myLogFile = fopen( myLogFileName.latin1(), "a" );
       if (  myLogFile == NULL ) {
        myLogged = false;
-       QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
+       QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
       }
     }
   }
 }
 
+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()));
+  Trace("SUPERVGUI_Main::syncAsync");
+  QTimer::singleShot(1, this, SLOT(sync()));
 }
 
 
@@ -233,13 +263,13 @@ void SUPERVGUI_Main::syncAsync() {
 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 ) {
+    if ( aNode )
       aNode->sync();
-    }
   }
   else if (myCurrentView == CANVASTABLE) {
     SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
-    if (aNode) aNode->sync();
+    if (aNode) 
+      aNode->sync();
   }
 
   // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a 
@@ -276,7 +306,17 @@ void SUPERVGUI_Main::sync() {
   t += dataflow->Name();
   setCaption(t);
 
-  study->updateObjBrowser();
+  //study->updateObjBrowser();
+  //mkr: we have to update object browser only if there are some ports datas in the study
+  //or if dataflow is in the study itself. It is done in the 
+  //1) putDataStudy(...) method (it called when we put in study data of port
+  //                             or if port is in study and execution is finished)
+  //2) addDataflowToStudy() method (it is called as a slot when we add in study dataflow itself).
+  //So, we commented updateObjBrowser function here!
+  //SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  //if ( aSupMod ) aSupMod->updateObjBrowser();
+  //else MESSAGE("NULL Supervision module!");
+
   if (myCurrentView == CANVASTABLE) {
     myArray->sync();
     myArray->update();
@@ -332,47 +372,55 @@ 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 = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
+                                       "",
+                                       "*.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(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
     }
+  }
 }
 
 void SUPERVGUI_Main::copy() {
   Trace("SUPERVGUI_Main::copy");
   if (dataflow->ThreadsMax() == 0) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
+    return;
+  }
+  
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
     return;
   }
-  QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
-  SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
-    (aStudyFrame->getRightFrame()->getViewFrame());
-  if(aViewFrame){
+
+  SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aSupMod->createGraph() );
+  if( aViewFrame ) {
     SUPERV_Graph aNewGraph; //  = dataflow->StreamCopy();
-    if (dataflow->IsStreamGraph()) {
+    if ( dataflow->IsStreamGraph() ) {
       SUPERV_StreamGraph aSGraph = dataflow->ToStreamGraph();
-      if (SUPERV_isNull(aSGraph)) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
+      if ( SUPERV_isNull(aSGraph) ) {
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
        return;
       }
       aNewGraph = aSGraph->StreamCopy();
@@ -384,9 +432,9 @@ void SUPERVGUI_Main::copy() {
     aNewName += dataflow->Name();
     aNewGraph->SetName(aNewName);
     /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
-                                          Supervision.getDesktop(), 
-                                          aNewGraph);
-    study->showFrame(aStudyFrame);
+                                              aSupMod->application()->desktop(),//getDesktop(), 
+                                              aNewGraph);
+    aViewFrame->show();
   }
 }
 
@@ -403,30 +451,35 @@ void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
 
     // display SubGraph
     if (SUPERV_isNull(aGraph)) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOACCESS"));
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOACCESS"));
       return;
     }
     else {
       QString aGraphName = aGraph->Name();
-      QAD_StudyFrame* aStudyFrame;
+      SUIT_ViewWindow* 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* aSupMod = SUPERVGUI::Supervision();
+       if ( !aSupMod ) {
+         MESSAGE("NULL Supervision module!");
+         return;
+       }
+       
+       aStudyFrame = aSupMod->createGraph();
+       if ( aStudyFrame ) {
+         SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aStudyFrame );
+         if( aViewFrame ) {
            /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
-                                                  Supervision.getDesktop(), 
-                                                  aGraph);
+                                                      aSupMod->application()->desktop(),//getDesktop(), 
+                                                      aGraph);
            //    connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)), 
            //            this,  SLOT(onSubGraphClosed(QAD_StudyFrame*)));
-           connect(aStudyFrame, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*)), 
-                   this,  SLOT(onSubGraphActivated(QAD_StudyFrame*)));
+           connect(aSupMod->application()->desktop(), SIGNAL(windowActivated( SUIT_ViewWindow* )), 
+                   this,  SLOT(onSubGraphActivated( SUIT_ViewWindow* )));
            aStudyFrame->installEventFilter(this);
 
            mySubGraphs.insert(aGraphName, aStudyFrame);
@@ -435,7 +488,7 @@ void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
          }
        }
       }
-      study->showFrame(aStudyFrame);
+      aStudyFrame->show();
       if (!correct) myLastGraph = aStudyFrame;
     }
   }
@@ -444,28 +497,27 @@ void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
 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;
+  if (o->inherits("SUIT_ViewWindow"/*"QAD_StudyFrame"*/) && e->type() == QEvent::Close) {
+    SUIT_ViewWindow* aFrame = (SUIT_ViewWindow*) 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)
+void SUPERVGUI_Main::onSubGraphActivated(SUIT_ViewWindow* theStudyFrame)
 {
   if (myLastGraph) {
-    QAD_StudyFrame* aFrame = myLastGraph;
+    SUIT_ViewWindow* aFrame = myLastGraph;
     myLastGraph = 0;
     aFrame->setActiveWindow();
     aFrame->setFocus();
   }
 }
 
-void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame)
+void SUPERVGUI_Main::onSubGraphClosed(SUIT_ViewWindow* theStudyFrame)
 {
-  QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
-  if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
+  if ( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( theStudyFrame ) ) {
     theStudyFrame->removeEventFilter(this);
     disconnect(theStudyFrame, 0, this, 0);
 
@@ -489,66 +541,42 @@ void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame)
   }
 }
 
-void SUPERVGUI_Main::run() {
+void SUPERVGUI_Main::run( const bool andSuspend ) {
   Trace("SUPERVGUI_Main::run");
-    if ((SUPERV_isNull(dataflow))) return;
+  if ( SUPERV_isNull(dataflow) ) 
+    return;
   
-  if (dataflow->IsEditing()) {
-    if (!dataflow->IsValid()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
+  if ( dataflow->IsEditing() ) { // not currently Executing
+
+    // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
+    Editing(); // remove old executor, update GUI (all nodes to "No Status")
+
+    if ( !dataflow->IsValid() ) {
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
     } 
     else if (!dataflow->IsExecutable()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
     } 
     else if (myCanvasView->isAnyLinkCreating()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
     } 
     else {
       myRunTime = QDateTime::currentDateTime();
-      if ( !dataflow->Run() ) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+      const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
+      if ( !result ) {
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
        if ( dataflow->State() == SUPERV::ErrorState ) {
          kill();
        }
       } 
       else {
+       //myExecuted = true; // set to true on first execution. for correct publishing in Study
        myThread->startThread(tr("MSG_GRAPH_STARTED"));
       }
     }
   } 
   else {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
-  }
-}
-
-
-
-void 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()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
-    } 
-    else if (myCanvasView->isAnyLinkCreating()) {
-      QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
-    } 
-    else {
-      myRunTime = QDateTime::currentDateTime();
-      if (!dataflow->Start()) {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
-      } 
-      else {
-       myThread->startThread(tr("MSG_GRAPH_STARTED"));
-      }
-    }
-  } 
-  else {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
   }
 }
 
@@ -559,14 +587,14 @@ void SUPERVGUI_Main::kill() {
     return;
 
   if (dataflow->IsEditing()) {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
   } 
   else if (dataflow->Kill()) {
-    myThread->stopThread(tr("MSG_GRAPH_KILLED"));
+    getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
     sync();
   } 
   else {
-    QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
+    QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
   }
 }
 
@@ -575,19 +603,19 @@ void SUPERVGUI_Main::suspendResume() {
     if ((SUPERV_isNull(dataflow))) return;
 
     if (dataflow->IsEditing()) {
-        QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
+        QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
     } else if (dataflow->State() == SUPERV_Suspend) {
       if (dataflow->Resume()) {
        myThread->startThread(tr("MSG_DF_RESUMED"));
       } else {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
       }
     } else {
       if (dataflow->Suspend()) {
        sync();
-       myThread->stopThread(tr("MSG_GRAPH_SUSPENDED"));
+       getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
       } else {
-       QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
       }
     }
 }
@@ -618,22 +646,18 @@ 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 
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( !aSupMod ) {
+    MESSAGE("NULL Supervision module!");
+    return;
+  }
 
-  Supervision.getBrowser()->choose();
+  //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
+  aSupMod->getBrowser()->choose();
 }
 
 /**
@@ -756,12 +780,12 @@ SUPERV_Graph SUPERVGUI_Main::getDataflow() {
   return(dataflow);
 }
 
-QAD_Message* SUPERVGUI_Main::getMessage() {
+LogWindow* SUPERVGUI_Main::getMessage() {
   Trace("SUPERVGUI_Main::getMessage");
   return(message);
 }
 
-QAD_Study* SUPERVGUI_Main::getStudy() {
+SUIT_Study* SUPERVGUI_Main::getStudy() {
   Trace("SUPERVGUI_Main::getStudy");
   return(study);
 }
@@ -777,17 +801,14 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
   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;
+  CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
+  if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
 
-  checkIsInStudy();
   if (e->button() == RightButton) {
     p->exec(e->globalPos());
   }
 }
 
-
-
 void SUPERVGUI_Main::changeInformation() {
   SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
   if (aDlg->exec() )
@@ -795,246 +816,292 @@ void SUPERVGUI_Main::changeInformation() {
   delete aDlg;
 }
 
-// returns false, if can't add dataflow into the study
-bool SUPERVGUI_Main::addStudy() {
-  Trace("SUPERVGUI_Main::addStudy");
-  if (myIsFromStudy) return false;
-  if ((SUPERV_isNull(dataflow))) return false;
+void SUPERVGUI_Main::chooseData(QListViewItem* item) {
+    Trace("SUPERVGUI_Main::chooseData");
+    if (choosing) {
+      QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
+      if (!id.isEmpty()) {
+       _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
+       _PTR(GenericAttribute) anAttr;
+       if (object->FindAttribute(anAttr, "AttributeIOR")) {
+         _PTR(AttributeIOR) anIOR ( anAttr );
+         
+         // 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);
+         
+         SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+         if ( !aSupMod ) {
+           MESSAGE("NULL Supervision module!");
+           return;
+         }
 
-  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;
-  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();
-      //if (aLocked) aStudy->GetProperties()->SetLocked(false);
+         // stop selection
+         choosing = false;
+         setCursor(aSupMod->getCursor());
+         objectBrowser->setCursor(aSupMod->getCursor());
+         aSupMod->putInfo("");
+       }
+      }
+    }
+}
+
+_PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
+                                       _PTR(StudyBuilder) const theBuilder,
+                                       _PTR(SObject) const theSO,
+                                       const char* theName,
+                                       bool* theDoneSomething ) {
+  _PTR(SObject) aResult;
+  _PTR(AttributeName) aName;
+  _PTR(GenericAttribute) anAttr;
+  _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
+  for (; anIterator->More(); anIterator->Next()) {
+    if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
+      aName = anAttr;
+      if (strcmp(aName->Value().c_str(), theName) == 0) {
+       aResult = anIterator->Value();
+       break;
+      }
+    }
+  }
+
+  // if aResule was found then theDoneSomething=false and we return
+  *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
+  if ( !*theDoneSomething )
+    return aResult;
+
+  // add new SObject
+  aResult = theBuilder->NewObject( theSO );
+  anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
+  aName = anAttr;
+  aName->SetValue(theName);
+  return aResult;
+}
+    
+/**
+ * Return true if dataflow is already in the study
+ */
+bool SUPERVGUI_Main::isDataflowInStudy() const {
+  _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
+  _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
+  return ( aSO ? true : false );
+}
+
+/**
+ * Create a "Supervision" object in the Study and a "dataflow" object under it
+ * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
+ */
+_PTR(SObject) createDataflowSObj( SUIT_Study* study, 
+                                 SUPERV::Graph_var dataflow, 
+                                 _PTR(StudyBuilder) aBuilder,
+                                 bool& aDoneSomething ) {
+  _PTR(Study)            aStudy = (( SalomeApp_Study* )study)->studyDS();
+  _PTR(GenericAttribute) anAttr;
+  _PTR(AttributeName)    aName;
+
+  // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
+  _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
+  if ( !aSO ) { // dataflow SObject not found in the study
+    aDoneSomething = true; 
+    _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
+    if ( !aComponent ) { // is supervision component not found, then create it
       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
-      aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      //aName->SetValue(STUDY_SUPERVISION);
-      aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
+      aName = anAttr;
+      aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
+       
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
-      aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
+      _PTR(AttributePixMap) aPixmap ( anAttr );
       aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
-      aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
-      //if (aLocked) aStudy->GetProperties()->SetLocked(true);
-      anOperation->finish();
+
+      SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+      if ( aSupMod )
+       aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
+                                                    //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
+      else MESSAGE("NULL Supervision module!");
+      
     }
-    op->start();
+    // create dataflow SObject ("aNewDataflow_1") 
     aSO = aBuilder->NewObject(aComponent);
     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
-    aName = SALOMEDS::AttributeName::_narrow(anAttr);
+    aName = anAttr;
     aName->SetValue(dataflow->Name());
     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
-    anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
+    _PTR(AttributeIOR) anIORAttr ( anAttr );
     anIORAttr->SetValue(dataflow->getIOR());
-    op->finish();
-    //if (aLocked) return false;
   }
 
-  sync();
-  Supervision.unregisterGraph(this);
-  Supervision.registerGraph(dataflow->getIOR(), this);
-  myIsFromStudy = true;
-  return true;
+  return aSO;
 }
 
-
-void SUPERVGUI_Main::chooseData(QListViewItem* item) {
-    Trace("SUPERVGUI_Main::chooseData");
-    if (choosing) {
-        QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
-        if (!id.isEmpty()) {
-            SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
-            SALOMEDS::GenericAttribute_var anAttr;
-            SALOMEDS::AttributeIOR_var     anIOR;
-            Standard_CString      ior    = "";
-            if (object->FindAttribute(anAttr, "AttributeIOR")) {
-              anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-             ior = anIOR->Value();
-             
-             // 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;
-             setCursor(Supervision.getCursor());
-             objectBrowser->setCursor(Supervision.getCursor());
-             Supervision.putInfo("");
-           }
-        }
+void SUPERVGUI_Main::addDataflowToStudy() {
+  bool isCreated;
+  _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
+  aBuilder->NewCommand();
+  _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
+  if ( aDF ) {
+    aBuilder->CommitCommand();
+    // what is this register/unregister?? don't know..
+    SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+    if ( !aSupMod ) {
+      MESSAGE("NULL Supervision module!");
+      return;
     }
-}
+    aSupMod->unregisterGraph(this);
+    aSupMod->registerGraph(dataflow->getIOR(), this);
 
-SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
-                                              const SALOMEDS::SObject_var theSO,
-                                              const char* theName,
-                                              //QAD_Operation* theOperation,
-                                              bool* theStarted) {
-  SALOMEDS::SObject_var aResult;
-  SALOMEDS::AttributeName_var aName;
-  SALOMEDS::GenericAttribute_var anAttr;
-  if (!*theStarted) { // optimisation
-    SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
-    for (; anIterator->More(); anIterator->Next()) {
-      if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
-       aName = SALOMEDS::AttributeName::_narrow(anAttr);
-       if (strcmp(aName->Value(), theName) == 0) {
-         aResult = anIterator->Value();
-         break;
-       }
-      }
-    }
+    if ( !myThread->running() )
+      aSupMod->updateObjBrowser();
   }
-  if (!aResult->_is_nil()) return aResult;
-  // add new SObject
-  SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
-  if (!*theStarted) {
-    *theStarted = true;
-    //theOperation->start();
-    aBuilder->NewCommand();
+  else {
+    MESSAGE( "ERROR: failed to find or create dataflow SObject" );
+    aBuilder->AbortCommand();
   }
-  aResult = aBuilder->NewObject(theSO);
-  anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
-  aName = SALOMEDS::AttributeName::_narrow(anAttr);
-  aName->SetValue(theName);
-  return aResult;
 }
 
-bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
+bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
   Trace("SUPERVGUI_Main::putDataStudy");
 
+  bool PublishOtherComponent = false;
+
   // static variable to ensure that only one instance (thread) is executing this function 
   static bool isIn = false;
-  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 (isIn)   return true; 
+  else        isIn = true;
+
+  _PTR(Study)        aStudy = (( SalomeApp_Study* )study)->studyDS();
+  const bool         aLocked = aStudy->GetProperties()->IsLocked();
+  _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
+  bool                           aDoneSomething = false;
+
+  // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
   if ( aLocked ) {
+    MESSAGE( "The study is locked and can not be modified!" );
     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;
-  
-  // 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
-      aBuilder->NewCommand();
-      //if (aLocked) aStudy->GetProperties()->SetLocked(false);
-      aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
-      anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
-      aName = SALOMEDS::AttributeName::_narrow(anAttr);
-      //aName->SetValue(STUDY_SUPERVISION);
-      aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
-       
-      anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
-      aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
-      aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
-      aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
-      //if (aLocked) aStudy->GetProperties()->SetLocked(true);
-      aBuilder->CommitCommand();
-    }
-    aTransaction = true;
-    aBuilder->NewCommand();
-    aSO = aBuilder->NewObject(aComponent);
-    anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
-    aName = SALOMEDS::AttributeName::_narrow(anAttr);
-    aName->SetValue(dataflow->Name());
-    anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
-    anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
-    anIORAttr->SetValue(dataflow->getIOR());
+  // check if the port and its node are good
+  if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
+    MESSAGE( "putInStudy ERROR: port or node are NULL!" );
+    isIn = false;
+    return false;
   }
 
-  aSO = SearchOrCreateSOWithName(aStudy, aSO,  // get run time SO
-                                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();
+  // open new command.  Commit or Abort it depending on aDoneSomething variable or error
+  aBuilder->NewCommand();
+  
+  // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
+  _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
 
-  anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
-  anIORAttr  = SALOMEDS::AttributeIOR::_narrow(anAttr);
-  if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
+  if ( !aSO ) {
+    MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" ); 
+    aBuilder->AbortCommand();
     isIn = false;
-    return true;
+    return false;
   }
-  // set object value to the study: if object is external, then put it with
-  //                                 help of the specific component - owner
-  if (p->IsIOR()) {
-    // get according component driver for result object
-    SALOME_LifeCycleCORBA aLCC(myNService);
-    SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
-    if (!aFNode->_is_nil()) {
-      Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
-                                                                   aFNode->GetComponentName());
-      SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
-      if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
-       CORBA::Object_ptr anObject = new CORBA::Object();
-       CORBA::Any* anAny = p->ToAny();
-       (*anAny) >>= anObject;
+
+  // Create "Run -> Time and date, etc." SObjects
+  if  ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
+
+    aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
+    aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
+    aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
+    aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
+
+    // create IOR attribute for port SObject (usually with "return" name)
+    _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
+    _PTR(AttributeIOR) anIORAttr  ( anAttr );
+
+    // if we have not created anything (all SObject already existed) and we have the same IORAttribute
+    // on the needed SObject -> then don't do anything! it's already there!
+    if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
+      aBuilder->AbortCommand();
+      isIn = false;
+      return true;
+    }
+
+    aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
+
+    // set object value to the study: if object is external, then put it with
+    //  help of the specific component - owner
+    if ( p->IsIOR() ) {
+      // get according component driver for result object
+      SALOME_LifeCycleCORBA aLCC( myNService );
+      SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
+      if ( !aFNode->_is_nil() ) {
+       Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
+       SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
+       if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
+         CORBA::Object_ptr anObject = new CORBA::Object();
+         CORBA::Any* anAny = p->ToAny();
+         (*anAny) >>= anObject;
        
-       if (aDriver->CanPublishInStudy(anObject)) {
-         SALOMEDS::SObject_var aTmpSO;
-         if (!aTransaction) {
-           aTmpSO = aSO;
-           aTransaction = true;
-           aBuilder->NewCommand();
+         if ( aDriver->CanPublishInStudy( anObject ) ) {
+           SALOMEDS::SObject_var aTmpSO;// = aSO;
+           SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
+           if ( !aSStudy ) return false;
+           aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
+           aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
+           PublishOtherComponent = true;
+         } 
+         else { // can't publish object: abort transaction
+           MESSAGE( "CanPublishInStudy() returned FALSE.  ok, AbortCommand.." );
+           aBuilder->AbortCommand();
+           isIn = false;
+           return false;
          }
-           aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, /*anObject->Name()*/"");
-         aBuilder->Addreference(aSO, aTmpSO);
-       } else { // can't publish object: abort transaction
-         if (aTransaction) aBuilder->AbortCommand();
+       }
+       else { // component has no driver, but could store IORs (like Calculator)
+         _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
+         if ( anIORSO ) {
+           aBuilder->Addreference(aSO, anIORSO);
+           // mkr : IPAL9672
+           PublishOtherComponent = true;
+         }
+         else { // Hm... the object (==port value) was not found, so we don't publish it.
+           MESSAGE( "The object (==port value) was not found, so we don't publish it" );
+           aBuilder->AbortCommand();
+           isIn = false;
+           return false;
+         }
+       }
+      }
+      else { // FNode is NULL -> bad
+       MESSAGE( "FNode is NULL." );
+       if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
+         _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
+         if ( anIORSO )
+           aBuilder->Addreference(aSO, anIORSO);
+       }
+       else {
+         MESSAGE( "FNode and INode are NULL.  Not good at all.  Aborting command." );
+         aBuilder->AbortCommand();
          isIn = false;
          return false;
        }
-      } else { // component has no drivel, but could store IORs (like Calculator)
-       SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
-       if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
       }
+    } 
+    else {
+      anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
     }
-  } else {
-    if (!aTransaction) {
-      aTransaction = true;
-      aBuilder->NewCommand();
-    }
-    anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
   }
-  
-  if (aTransaction) 
+
+  if ( aDoneSomething )
     aBuilder->CommitCommand();
-  if (!myThread->running())
-    study->updateObjBrowser();
+  else
+    aBuilder->AbortCommand();
+
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( aSupMod ) {
+    if ( PublishOtherComponent )
+      dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
+    else
+      aSupMod->updateObjBrowser();
+  }
+  else MESSAGE("NULL Supervision module!");
+  
   isIn = false;
   return true;
 }
@@ -1059,34 +1126,6 @@ void SUPERVGUI_Main::ResetView()
   }
 }
 
-
-void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
-  myIsFromStudy = theToStudy;
-  myCanvas->setAsFromStudy(theToStudy);
-}
-
-void SUPERVGUI_Main::checkIsInStudy() {
-  if (!myIsFromStudy) return;
-
-  SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
-  SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
-  SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
-  SALOMEDS::SObject_var aDataflowLbl;
-  SALOMEDS::GenericAttribute_var anAttr;
-
-  for (; aChildIterator->More(); aChildIterator->Next()) {
-    aDataflowLbl = aChildIterator->Value();
-    if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
-      continue;
-
-    SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
-    if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
-  }
-  // This Graph considered as in study but in study it is not exists
-  Supervision.unregisterGraph(this);
-  setAsFromStudy(false);
-}
-
 void SUPERVGUI_Main::syncNotification() {
   char* graph;
   char* node;
@@ -1098,14 +1137,14 @@ void SUPERVGUI_Main::syncNotification() {
   long  stamp;
   
   while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
-    if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
+//    if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
       QString mess("");
       mess += "NOTIF: "; mess += graph;
       mess += " / "    ; mess += node;
       mess += " / "    ; mess += type;
       mess += " / "    ; mess += message;
-      getMessage()->setMessage(mess.latin1());
-    };
+      getMessage()->putMessage(mess.latin1());
+//    };
   };
 }
   
@@ -1190,7 +1229,11 @@ void SUPERVGUI_Main::startTimer() {
 }
 
 void SUPERVGUI_Main::executionFinished() {
-  getStudy()->updateObjBrowser();
+  SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
+  if ( aSupMod ) 
+    aSupMod->updateObjBrowser();
+  else MESSAGE("NULL Supervision module!");
+  
   myCanvas->update();
   myArray->update();
 }
@@ -1225,16 +1268,51 @@ void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
   // as argument
   if (myArray) {
     const QObjectList* aChList = myArray->children();
-    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;
+    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 )
+  }
+}
+
+/**
+ * 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 = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 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;
+}
+
+void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
+{
+  if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
+    if ( getCanvas()->width() < theEvent->size().width()
+        ||
+        getCanvas()->height() < theEvent->size().height() )
+      getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
+  if ( myCurrentView == CANVASTABLE && getCanvasArray() )
+    if ( getCanvasArray()->width() < theEvent->size().width()
+        ||
+        getCanvasArray()->height() < theEvent->size().height() )
+      getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
 }
 
 /******************************* SUPERVGUI_Thread class ****************************************/
@@ -1253,165 +1331,125 @@ void SUPERVGUI_Thread::startThread(const char* m)
 {
   if (!myIsActive) {
     myIsActive = true;
-    //QThread::start();
-    this->start();
-    myMain->getMessage()->setMessage(m); 
+    
+    myMain->getMessage()->putMessage(m); 
     myMain->sync();
-  }
-}
 
-void SUPERVGUI_Thread::stopThread(const char* m)
-{
-  myMain->getMessage()->setMessage(m);
+    start();
+  }
 }
 
-void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
+void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
 {
   myMain = theMain;
 }
 
-void SUPERVGUI_Thread::KillThread(bool theValue)
+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;
-  SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
-  SUPERV::GraphState aState = SUPERV::UndefinedState ;
-
-  SUPERV_CNode aPrevNode = NULL;
-  SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ;
-  SUPERV::GraphState aPrevState = SUPERV::UndefinedState ;
-
-  char * aName;
-  char * aPrevName;
-
-  QPtrList< char * > anEventNodes;
-  QPtrList< SUPERV::GraphState > aStates;
-
-  myMain->startTimer();
+template<class TObject, typename TArg, typename TArg1, typename TArg2,
+        typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
+class TVoidMemFun3ArgEvent: public SALOME_Event{
+public:
+  typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
+  TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
+    myObject(theObject),
+    myAction(theAction),
+    myArg(theArg),
+    myArg1(theArg1),
+    myArg2(theArg2)
+  {}
+  virtual void Execute(){
+    (myObject->*myAction)(myArg,myArg1,myArg2);
+  }
+private:
+  TObject* myObject;
+  TAction myAction;
+  TStoreArg myArg;
+  TStoreArg1 myArg1;
+  TStoreArg2 myArg2;
+};
 
-  myMain->myGUIEventLoopFinished = false;
+typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
 
-  while(myIsActive) {
-    myMain->getDataflow()->Event(aNode, aEvent, aState);
+/**
+ * main_thread_run must be executed in the qt main thread
+ * It is activated by calling ProcessVoidEvent
+ */
+void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
+{
+    // in case node "said" something during changing state through notification mechanism - output it
+    myMain->syncNotification();
     
-    if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
-       ||
-       aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
-       ||
-       aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
-
-      if (myMain->getEventNodes().count()) {
-       myMain->removeEventNodes();
-      }    
-      if (myMain->getStates().count()) {
-       myMain->removeStates();
-      }    
+    // "kill" or undefined event came
+    if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
+       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
+       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
+
       myIsActive = false;
     }
-    else {    
-      if ( aNode != NULL && !CORBA::is_nil( aNode ) ) {
-       aName = aNode->Name();
-      }
-
-      if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) {  //first initialize aPrev... variables
-       anEventNodes = myMain->getEventNodes();
-       anEventNodes.append( &aName ) ;
-       myMain->setEventNodes(anEventNodes);
-       
-       aStates = myMain->getStates();
-       aStates.append( &aState ) ;
-       myMain->setStates(aStates);
-      }
-      else {
-       if ( aEvent == aPrevEvent && aState == aPrevState) {
-         QString aNameStr = aName;
-         QString aPrevNameStr = aPrevName;
-         if ( aNameStr != aPrevNameStr ) {
-           anEventNodes = myMain->getEventNodes();
-           anEventNodes.append( &aName ) ;
-           myMain->setEventNodes(anEventNodes);
-           
-           aStates = myMain->getStates();
-           aStates.append( &aState ) ;
-           myMain->setStates(aStates);
-         }
-       }
-       else {
-         anEventNodes = myMain->getEventNodes();
-         anEventNodes.append( &aName ) ;
-         myMain->setEventNodes(anEventNodes);
-         
-         aStates = myMain->getStates();
-         aStates.append( &aState ) ;
-         myMain->setStates(aStates);
-       }
-      }
-    }      
-    if (!myIsActive) {
-      switch (myMain->getDataflow()->State()) {
+    else { // a "normal" execution event came
+      char* aName = NULL;
+      if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
+       aName = aNode->Name();      
+
+      // What follow is not quite sure. The entire function is posted to the main qt thread.
+      // So all executions are serialized. Is it really possible to call execute when another
+      // execute is running. I don't think so (C Caremoli)
+      // this function is asynchronious.  The call does NOT wait when SUPERVGUI_Main::execute finishes
+      // handling the event.  So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
+      // on the next loop iteration, BEFORE  previous SUPERVGUI_Main::execute finished.
+      myMain->execute(aName, aState );
+    }    
+
+    // execution is finished.  just set a "finished" message(s)
+    if ( !myIsActive ) {
+      switch ( myMain->getDataflow()->State() ) {
       case SUPERV_Editing :     
-       stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
-       break;
-       
+       myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()? 
+                                        tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
+       break;  
       case SUPERV_Suspend : 
-       stopThread(tr("MSG_GRAPH_SUSPENDED"));
-       break;
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
+       break; 
       case SUPERV_Done : 
-       stopThread(tr("MSG_GRAPH_FINISHED"));
-       break;
-       
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
+       break;  
       case SUPERV_Error :
-       stopThread(tr("MSG_GRAPH_ABORTED"));
-       break;
-       
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
+       break;  
       case SUPERV_Kill:
-       stopThread(tr("MSG_GRAPH_KILLED"));
-       break;
-      }
-
-      break;
-    }
-    if ( myMain->getEventNodes().count() ) {    
-      //if list not empty call execute() -> sync()
-      char * aNodeName = *(myMain->getEventNodes().getFirst());
-      SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
-
-      // 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->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
+       break;
+      } // end of switch
 
-      myMain->removeFirstEN();
-      myMain->removeFirstS();
-    }
-
-    aPrevNode = aNode;
-    aPrevEvent = aEvent;
-    aPrevState = aState;
+      // asv 03.02.05 : fix for PAL6859, not very good, but works..
+      myMain->sync();
+    } // end of if !myIsActive
+}
 
-    if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) 
-      aPrevName = "";
-    else 
-      aPrevName = aPrevNode->Name();
+void SUPERVGUI_Thread::run()
+{
+  myMain->startTimer();
+  
+  // GUI cycle to handle events coming for Engine
+  while ( myIsActive ) {
     
-    //usleep(10);
-    //msleep(5);
-  }
-  // VSR: 04/12/03 ---> update object browser ufter finishing
-//   qApp->lock();
-//   myMain->getStudy()->updateObjBrowser();
-//   qApp->unlock();
-  // VSR: 04/12/03 <---    
-
-  myMain->myGUIEventLoopFinished = true;
-
+    SUPERV_CNode aNode = NULL;
+    SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
+    SUPERV::GraphState aState = SUPERV::UndefinedState ;
+    
+    // blocking function of Engine.  Return from there only after anEvent happens on node aNode
+    myMain->getDataflow()->Event(aNode, aEvent, aState);
+    
+    ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
+    
+  } // end of while( myIsActive )
+  
   QThread::exit();
 }
 
@@ -1420,7 +1458,7 @@ void SUPERVGUI_Thread::run()
   Constructor
 */
 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
-     : QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
+     : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
 {
   Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
   setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
@@ -1444,7 +1482,7 @@ SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph,
   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 = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
   myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   TopGroupLayout->addWidget( myDeltaTime, 0, 1 );