Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
index 494dd7e5cf2e080693f1a7078f659e7cefec166f..c0dd3ea434f4a7108a5fcac8b5992b326cd95bcd 100644 (file)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software 
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
 // 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 //  Author : Francis KLOSS
 //  Module : SUPERV
 
-using namespace std;
-
 #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 "SUPERVGraph_ViewFrame.h"
+#include "SUPERVGraph_ViewModel.h"
 
 #include "LogWindow.h"
 #include "OB_Browser.h"
@@ -65,7 +62,25 @@ using namespace boost;
 #include <qlineedit.h>
 #include <qcombobox.h>
 
-SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, SUIT_Desktop* theDesktop, SUPERV_Graph theDataFlow )
+#include <boost/shared_ptr.hpp>
+using namespace boost;
+
+// mkr : PAL8150
+#define SYNCPUTINSTUDY(NodesName)  \
+    for ( int n = 0; n < nodes->NodesName.length(); n++ ) { \
+      SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[n]); \
+      SUPERV_Ports aPortList = aCNode->Ports(); \
+      for (int p = 0; p < aPortList->length(); p++) { \
+        SUPERV::Port_ptr aPort = aPortList[p].in(); \
+        if ( !aPort->IsInput() && !aPort->IsGate() ) { \
+          bool aInStudy = dynamic_cast<SUPERVGUI_CanvasPortOut*>( aMain->getCanvas()->getPort(aPort) )->isInStudy(); \
+          dynamic_cast<SUPERVGUI_CanvasPortOut*>( getCanvas()->getPort( getDataflow()->Node(aCNode->Name())->GetOutPort(aPort->Name()) ) )->setStudyState(aInStudy); \
+        } \
+      } \
+    }
+
+SUPERVGUI_Main::SUPERVGUI_Main( SUPERVGraph_ViewFrame* theParent, 
+                               SUIT_Desktop* theDesktop, SUPERV_Graph theDataFlow )
      : SUPERVGraph_View(theParent),
        myLogged( false ),
        myFiltered( false ),
@@ -75,10 +90,11 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, SUIT_Desktop* t
        myStep( false ),
        myTrace( false ),
        myVerbose( false )
-     //myExecuted( false )
+  //myExecuted( false )
 {
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
-  theParent->setViewWidget(this);  
+  setFocusPolicy( StrongFocus );  // mkr : IPAL11388
+  theParent->setViewWidget(this);
   dataflow = theDataFlow;
   if (SUPERV_isNull(dataflow)) {
     QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
@@ -86,6 +102,11 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, SUIT_Desktop* t
   } else {
     init(theDesktop);
   }
+
+  syncPutInStudy(); // mkr : PAL8150
+
+  // mkr : IPAL11362
+  connect(this, SIGNAL(EventToSync()), this, SLOT(onObjectCreatedDeleted()));
 }
 
 void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
@@ -139,15 +160,17 @@ void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
   };
   */
 
-  objectBrowser = dynamic_cast<SalomeApp_Application*>( study->application() )->objectBrowser();
-    
-  myArray = new SUPERVGUI_CanvasArray(this);
-  myArrayView = new SUPERVGUI_ArrayView(myArray, this);
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
+
+  objectBrowser = app->objectBrowser();
 
-  myCanvas = new SUPERVGUI_Canvas(this);
+  myArray = new SUPERVGUI_CanvasArray( this, resMgr() );
+  myArrayView = new SUPERVGUI_ArrayView( myArray, this );
+
+  myCanvas = new SUPERVGUI_Canvas( this, resMgr() );
   myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
-  
-  message = dynamic_cast<SalomeApp_Application*>( study->application() )->logWindow();
+
+  message = app->logWindow();
   notification = new NOTIFICATION_Consumer();
 
   QBoxLayout * layout = new QVBoxLayout(this);
@@ -162,7 +185,7 @@ void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
 
   sync();
   show();
-  if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
+  if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
     myLogFile = fopen( myLogFileName.latin1(), "a" );
     if (  myLogFile == NULL )
       myLogged = false;
@@ -188,7 +211,7 @@ SUPERVGUI_Main::~SUPERVGUI_Main() {
     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;
+    //if ( aVM ) delete aVM; // mkr : IPAL11547
     
   }
   mySubGraphs.clear();
@@ -212,6 +235,12 @@ SUPERVGUI_Main::~SUPERVGUI_Main() {
   delete myArray;
 }
 
+SUIT_ResourceMgr* SUPERVGUI_Main::resMgr() const
+{
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
+  return app ? app->resourceMgr() : 0;
+}
+
 void SUPERVGUI_Main::filterNotification() {
   Trace("SUPERVGUI_Main::filterNotification");
   SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
@@ -234,7 +263,7 @@ void SUPERVGUI_Main::filterNotification() {
       fclose( myLogFile );
     }
     myLogFile = NULL;
-    if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
+    if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
       myLogFile = fopen( myLogFileName.latin1(), "a" );
       if (  myLogFile == NULL ) {
        myLogged = false;
@@ -263,13 +292,17 @@ 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();
+      emit EventToSync(); // mkr : IPAL11362
+    }
   }
   else if (myCurrentView == CANVASTABLE) {
     SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
-    if (aNode) 
+    if (aNode) {
       aNode->sync();
+      emit EventToSync(); // mkr : IPAL11362
+    }
   }
 
   // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a 
@@ -317,6 +350,11 @@ void SUPERVGUI_Main::sync() {
   //if ( aSupMod ) aSupMod->updateObjBrowser();
   //else MESSAGE("NULL Supervision module!");
 
+  // update "Save" icon and menu state, if dataflow is published
+  _PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
+  _PTR(SObject)  aSO = aStudy->FindObjectIOR(dataflow->getIOR());
+  if (aSO) SUPERVGUI_Main::setModifiedFlag();  
+
   if (myCurrentView == CANVASTABLE) {
     myArray->sync();
     myArray->update();
@@ -473,9 +511,9 @@ void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
        if ( aStudyFrame ) {
          SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aStudyFrame );
          if( aViewFrame ) {
-           /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
-                                                      aSupMod->application()->desktop(),//getDesktop(), 
-                                                      aGraph);
+           new SUPERVGUI_Main(aViewFrame, 
+                              aSupMod->application()->desktop(),//getDesktop(), 
+                              aGraph);
            //    connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)), 
            //            this,  SLOT(onSubGraphClosed(QAD_StudyFrame*)));
            connect(aSupMod->application()->desktop(), SIGNAL(windowActivated( SUIT_ViewWindow* )), 
@@ -494,6 +532,18 @@ void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
   }
 }
 
+// mkr : IPAL11549
+void SUPERVGUI_Main::destroySubGraph(QString theSubGraphName)
+{
+  if ( mySubGraphs.contains(theSubGraphName) ) {
+    SUIT_ViewWindow* aStudyFrame = mySubGraphs[theSubGraphName];
+    onSubGraphClosed(aStudyFrame);
+    SUIT_ViewManager* aVM = aStudyFrame->getViewManager();
+    STD_Application* anApp = dynamic_cast<STD_Application*>( SUIT_Session::session()->activeApplication() );
+    if ( anApp ) anApp->removeViewManager(aVM);
+  }
+}
+
 bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
 {
   // workaround to get close event
@@ -541,6 +591,125 @@ void SUPERVGUI_Main::onSubGraphClosed(SUIT_ViewWindow* theStudyFrame)
   }
 }
 
+void SUPERVGUI_Main::onShowToolbar()
+{
+  SUPERVGraph_ViewFrame* aVF = (SUPERVGraph_ViewFrame*)this->parent();
+  if ( aVF )
+    aVF->getToolBar()->show();
+}
+
+// mkr : PAL8237 : synchronize many views of the same dataflow (objects creation/deletion)
+void SUPERVGUI_Main::onObjectCreatedDeleted()
+{
+  if ( study ) {
+    if ( LightApp_Application* app = dynamic_cast<LightApp_Application*>( study->application() ) ) {
+      ViewManagerList aVMList;
+      app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
+      SUIT_ViewManager* aVM;
+      for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
+       QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
+       for ( int i = 0; i < aVWList.count(); i++ ) {
+         SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
+         QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
+         if ( aMainList->count() == 1 ) {
+           SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
+           if ( aMain ) {
+             if (aMain != this &&
+                  !CORBA::is_nil(aMain->getDataflow()) &&
+                  !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR())) // equal dataflows
+               aMain->getCanvas()->merge();
+            }
+         }
+       }
+      }
+
+      // update "Save" icon and menu state, if dataflow is published
+      //_PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
+      //_PTR(SObject)  aSO = aStudy->FindObjectIOR(dataflow->getIOR());
+      //if (aSO) SUPERVGUI_Main::setModifiedFlag();  
+    }
+  }
+}
+
+// mkr : PAL8150 : synchronize many views of the same dataflow ("Put In Study"/"Not In Study" operation)
+void SUPERVGUI_Main::onPutInStudy( QString* theNodePortName )
+{
+  if ( study ) {
+    if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
+      ViewManagerList aVMList;
+      app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
+      SUIT_ViewManager* aVM;
+      for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
+       QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
+       for ( int i = 0; i < aVWList.count(); i++ ) {
+         SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
+         QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
+         if ( aMainList->count() == 1 ) {
+           SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
+           if ( aMain )
+             if ( !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
+                  && 
+                  aMain != this ) { // not equal mains
+               QString aNodeName = theNodePortName->left( theNodePortName->find('_') );
+               QString aPortName = theNodePortName->right( theNodePortName->length() - theNodePortName->find('_') - 1 );
+               bool anIsInStudy = dynamic_cast<SUPERVGUI_CanvasPortOut*>( getCanvas()->getPort( getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->isInStudy();
+               dynamic_cast<SUPERVGUI_CanvasPortOut*>( aMain->getCanvas()->getPort( aMain->getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->setStudyState( anIsInStudy );
+             }
+         }
+       }
+      }
+      //SUPERVGUI_Main::setModifiedFlag();
+    }
+  }
+}
+
+// mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
+void SUPERVGUI_Main::syncPutInStudy()
+{
+  if ( study ) {
+    if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
+      ViewManagerList aVMList;
+      app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
+      SUIT_ViewManager* aVM;
+      for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
+       QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
+       for ( int i = 0; i < aVWList.count(); i++ ) {
+         SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
+         QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
+         if ( aMainList->count() == 1 ) {
+           SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
+           if ( aMain )
+             if ( !CORBA::is_nil( aMain->getDataflow() )
+                  &&
+                  !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
+                  && 
+                  aMain != this ) { // not equal mains
+       
+               // check "myInStudy" field of output ports of original main (i.e. this main)
+               // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
+               SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
+               
+               SYNCPUTINSTUDY(CNodes);
+               SYNCPUTINSTUDY(FNodes);
+               SYNCPUTINSTUDY(INodes);
+               SYNCPUTINSTUDY(GNodes);
+               SYNCPUTINSTUDY(LNodes);
+               SYNCPUTINSTUDY(ELNodes);
+               SYNCPUTINSTUDY(SNodes);
+               SYNCPUTINSTUDY(ESNodes);
+               SYNCPUTINSTUDY(Graphs);
+
+               setRunTime( aMain->getRunTime() );
+
+               break;
+             }
+         }
+       }
+      }
+    }
+  }
+}
+
 void SUPERVGUI_Main::run( const bool andSuspend ) {
   Trace("SUPERVGUI_Main::run");
   if ( SUPERV_isNull(dataflow) ) 
@@ -552,10 +721,14 @@ void SUPERVGUI_Main::run( const bool andSuspend ) {
     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"));
+      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
     } 
     else if (!dataflow->IsExecutable()) {
-      QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
+      QString aMessage = QString(dataflow->Messages());
+      if ( aMessage.isEmpty() ) // mkr : IPAL11471
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
+      else
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
     } 
     else if (myCanvasView->isAnyLinkCreating()) {
       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
@@ -564,9 +737,11 @@ void SUPERVGUI_Main::run( const bool andSuspend ) {
       myRunTime = QDateTime::currentDateTime();
       const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
       if ( !result ) {
-       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
+       // PAL12902
+       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE") + QString(" : ") + QString(dataflow->Messages()));
        if ( dataflow->State() == SUPERV::ErrorState ) {
-         kill();
+         // PAL12902
+         if ( !dataflow->IsEditing() ) kill();
        }
       } 
       else {
@@ -590,7 +765,9 @@ void SUPERVGUI_Main::kill() {
     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
   } 
   else if (dataflow->Kill()) {
-    getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
+    // IPAL9273, 9369, 9731 : to avoid two equal messages about killing dataflow
+    //                        execution in the Message Console
+    //getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
     sync();
   } 
   else {
@@ -600,6 +777,7 @@ void SUPERVGUI_Main::kill() {
 
 void SUPERVGUI_Main::suspendResume() {
     Trace("SUPERVGUI_Main::suspendResume");
+
     if ((SUPERV_isNull(dataflow))) return;
 
     if (dataflow->IsEditing()) {
@@ -672,7 +850,7 @@ void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
   case CANVAS:
   case CONTROLFLOW: 
     {
-      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode(myCanvas, this, theNode);
+      SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasComputeNode::Create(resMgr(), myCanvas, this, theNode);
       aNode->move(theNode->X(), theNode->Y());
       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
       aNode->show();
@@ -694,7 +872,7 @@ void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
   case CANVAS:
   case CONTROLFLOW: 
     {
-      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode(myCanvas, this, theNode);
+      SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasGotoNode::Create(resMgr(), myCanvas, this, theNode);
       aNode->move(theNode->X(), theNode->Y());
       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
       aNode->show();
@@ -707,7 +885,8 @@ void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
 /**
  * Add Control node
  */
-void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
+void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update)
+{
   switch (myCurrentView) {
   case CANVASTABLE:
     myArray->destroy();
@@ -716,11 +895,13 @@ void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theE
   case CANVAS:
   case CONTROLFLOW: 
     {
-      SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode(myCanvas, this, theStartNode);
+      SUPERVGUI_CanvasStartNode* aStartNode =
+        SUPERVGUI_CanvasStartNode::Create(resMgr(), myCanvas, this, theStartNode);
       aStartNode->move(theStartNode->X(), theStartNode->Y());
       if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
 
-      SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode(myCanvas, this, theEndNode, aStartNode);
+      SUPERVGUI_CanvasEndNode* aEndNode =
+        SUPERVGUI_CanvasEndNode::Create(resMgr(), myCanvas, this, theEndNode, aStartNode);
       aEndNode->move(theEndNode->X(), theEndNode->Y());
       if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
 
@@ -745,7 +926,7 @@ void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
   case CANVAS:
   case CONTROLFLOW: 
     {
-      SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode(myCanvas, this, theNode);
+      SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasMacroNode::Create(resMgr(), myCanvas, this, theNode);
       aNode->move(theNode->X(), theNode->Y());
       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
       aNode->show();
@@ -802,6 +983,7 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
   //if (dataflow->IsExecuting()) return;
 
   CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
+  if ( !anApp->activeModule() ) return;
   if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
 
   if (e->button() == RightButton) {
@@ -858,7 +1040,7 @@ _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
   _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
   for (; anIterator->More(); anIterator->Next()) {
     if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
-      aName = anAttr;
+      aName = _PTR(AttributeName) ( anAttr );
       if (strcmp(aName->Value().c_str(), theName) == 0) {
        aResult = anIterator->Value();
        break;
@@ -874,7 +1056,7 @@ _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
   // add new SObject
   aResult = theBuilder->NewObject( theSO );
   anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
-  aName = anAttr;
+  aName = _PTR(AttributeName) ( anAttr );
   aName->SetValue(theName);
   return aResult;
 }
@@ -908,7 +1090,7 @@ _PTR(SObject) createDataflowSObj( SUIT_Study* study,
     if ( !aComponent ) { // is supervision component not found, then create it
       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
-      aName = anAttr;
+      aName = _PTR(AttributeName) ( anAttr );
       aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
        
       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
@@ -925,7 +1107,7 @@ _PTR(SObject) createDataflowSObj( SUIT_Study* study,
     // create dataflow SObject ("aNewDataflow_1") 
     aSO = aBuilder->NewObject(aComponent);
     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
-    aName = anAttr;
+    aName = _PTR(AttributeName) ( anAttr );
     aName->SetValue(dataflow->Name());
     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
     _PTR(AttributeIOR) anIORAttr ( anAttr );
@@ -953,6 +1135,8 @@ void SUPERVGUI_Main::addDataflowToStudy() {
 
     if ( !myThread->running() )
       aSupMod->updateObjBrowser();
+
+    aSupMod->getApp()->updateActions();  
   }
   else {
     MESSAGE( "ERROR: failed to find or create dataflow SObject" );
@@ -1042,9 +1226,13 @@ bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
            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;
+           try {
+             aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
+             aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
+             PublishOtherComponent = true;
+           }
+           catch ( ... ) { // mkr : PAL8150
+           }
          } 
          else { // can't publish object: abort transaction
            MESSAGE( "CanPublishInStudy() returned FALSE.  ok, AbortCommand.." );
@@ -1069,10 +1257,18 @@ bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
        }
       }
       else { // FNode is NULL -> bad
-       MESSAGE( "FNode is NULL.  Not good at all.  Aborting command." );
-       aBuilder->AbortCommand();
-       isIn = false;
-       return false;
+       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 {
@@ -1093,7 +1289,9 @@ bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
       aSupMod->updateObjBrowser();
   }
   else MESSAGE("NULL Supervision module!");
-  
+
+  SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
+  if(app) app->updateActions();  
   isIn = false;
   return true;
 }
@@ -1127,16 +1325,16 @@ void SUPERVGUI_Main::syncNotification() {
   long  counter;
   char* date;
   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)) { // mkr : PAL7037
       QString mess("");
       mess += "NOTIF: "; mess += graph;
       mess += " / "    ; mess += node;
       mess += " / "    ; mess += type;
       mess += " / "    ; mess += message;
       getMessage()->putMessage(mess.latin1());
-//    };
+    };
   };
 }
   
@@ -1146,7 +1344,13 @@ bool SUPERVGUI_Main::isFiltered(char* graph,  char* node,   char* type, char* me
   bool b = false;
   if (strcmp(getDataflow()->Name(), graph) == 0) {
     SUPERVGUI_CanvasNode* n;
-    QObjectList* nodes = queryList("SUPERVGUI_CanvasNode");
+    QObjectList* nodes;
+    // mkr : PAL7037 -->
+    if (myCurrentView == CANVASTABLE)
+      nodes = myArray->queryList("SUPERVGUI_CanvasNode");
+    else
+      nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
+    // mkr : PAL7037 <--
     QObjectListIt i(*nodes);
     while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
       ++i;
@@ -1223,7 +1427,9 @@ void SUPERVGUI_Main::startTimer() {
 void SUPERVGUI_Main::executionFinished() {
   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
   if ( aSupMod ) 
-    aSupMod->updateObjBrowser();
+    //aSupMod->updateObjBrowser();
+    // PAL10611: update all modules data
+    aSupMod->getApp()->updateObjectBrowser(true);
   else MESSAGE("NULL Supervision module!");
   
   myCanvas->update();
@@ -1293,6 +1499,46 @@ bool SUPERVGUI_Main::ReadyToModify() {
   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() );
+}
+
+/*!
+  Sets a modified flag in an active study
+ */
+void SUPERVGUI_Main::setModifiedFlag()
+{
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
+  if(app) {
+    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
+    if(study) {
+      _PTR(Study) studyDS = study->studyDS();
+      _PTR(SComponent) sco = studyDS->FindComponent(STUDY_SUPERVISION);
+      if(sco) {
+       _PTR(StudyBuilder) builder = studyDS->NewBuilder();
+       _PTR(GenericAttribute) ga;
+       ga = builder->FindOrCreateAttribute(sco, "AttributeParameter");
+       _PTR(AttributeParameter) ap(ga);
+       if(ap) {
+         ap->SetBool("SUPERVISOR_MODIFIED_FLAG",1);
+         app->updateActions();
+       }
+      }
+    }
+  }
+}
+
+
 /******************************* SUPERVGUI_Thread class ****************************************/
 SUPERVGUI_Thread::SUPERVGUI_Thread()
      :QThread()
@@ -1329,69 +1575,115 @@ void SUPERVGUI_Thread::KillThread( bool theValue )
   myMutex.unlock();
 }
 
-typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
-
-void SUPERVGUI_Thread::run()
-{
-  myMain->startTimer();
-
-  // GUI cycle to handle events coming for Engine
-  while ( myIsActive ) {
+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;
+};
 
-    SUPERV_CNode aNode = NULL;
-    SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
-    SUPERV::GraphState aState = SUPERV::UndefinedState ;
+typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
 
-    // blocking function of Engine.  Return from there only after anEvent happens on node aNode
-    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();
+    myMain->sync(); // mkr : NPAL14881
     
     // "kill" or undefined event came
     if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
-       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
-       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
+       ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
+       ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
 
       myIsActive = false;
     }
     else { // a "normal" execution event came
       char* aName = NULL;
       if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
-       aName = aNode->Name();      
+       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.
-      ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aName, aState ) );
+      myMain->execute(aName, aState );
     }    
-  
+
     // execution is finished.  just set a "finished" message(s)
     if ( !myIsActive ) {
+      QString aMess;
       switch ( myMain->getDataflow()->State() ) {
       case SUPERV_Editing :     
-       myMain->getMessage()->putMessage( 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 : 
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
-       break; 
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
+       break; 
       case SUPERV_Done : 
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
-       break;  
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
+       break;  
       case SUPERV_Error :
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
-       break;  
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
+       // PAL12866 -->
+       aMess = QString(myMain->getDataflow()->Messages());
+       if ( !aMess.isEmpty() ) {
+        myMain->getMessage()->putMessage( tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess );
+        QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), 
+                             tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess);
+       }
+       // PAL12866 <--
+       break;  
       case SUPERV_Kill:
-       myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
-       break;
+       myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
+       break;
       } // end of switch
 
       // asv 03.02.05 : fix for PAL6859, not very good, but works..
       myMain->sync();
     } // end of if !myIsActive
-  } // end of while( myIsActive )
+}
 
+void SUPERVGUI_Thread::run()
+{
+  myMain->startTimer();
+  
+  // GUI cycle to handle events coming for Engine
+  while ( myIsActive ) {
+    
+    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();
 }
 
@@ -1486,8 +1778,8 @@ SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
   Sets data function
 */
 void SUPERVGUI_DSGraphParameters::setData() {
-  double aDeltaTime;
-  long aTimeOut;
+  CORBA::Double aDeltaTime;
+  CORBA::Long aTimeOut;
   SUPERV::KindOfDataStreamTrace aDataStreamTrace;
 
 //  myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
@@ -1518,3 +1810,4 @@ void SUPERVGUI_DSGraphParameters::accept() {
   }
   QDialog::accept();
 }
+