Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Main.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Main.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 #include "SALOMEDSClient.hxx"
29 #include "SALOMEDS_Study.hxx"
30 #include "SALOMEDS_SObject.hxx"
31
32 #include "NOTIFICATION.hxx"
33 #include "SALOME_Event.hxx"
34 #include "SUPERVGraph_ViewFrame.h"
35 #include "SUPERVGraph_ViewModel.h"
36
37 #include "LogWindow.h"
38 #include "OB_Browser.h"
39 #include "OB_ListItem.h"
40 #include "SalomeApp_Application.h"
41 #include "SalomeApp_ImportOperation.h"
42 #include "SalomeApp_Study.h"
43 #include "SUIT_FileDlg.h"
44 #include "SUIT_MessageBox.h"
45 #include "SUIT_Operation.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_Study.h"
48 #include "QtxDblSpinBox.h"
49
50 #include "SUPERVGUI.h"
51 #include "SUPERVGUI_Def.h"
52 #include "SUPERVGUI_Main.h"
53 #include "SUPERVGUI_Notification.h"
54 #include "SUPERVGUI_Information.h"
55 #include "SUPERVGUI_CanvasControlNode.h"
56 #include "SUPERVGUI_CanvasPort.h"
57
58 #include <qvalidator.h>
59 #include <qlabel.h>
60 #include <qlayout.h>
61 #include <qfile.h>
62 #include <qlineedit.h>
63 #include <qcombobox.h>
64
65 #include <boost/shared_ptr.hpp>
66 using namespace boost;
67
68 // mkr : PAL8150
69 #define SYNCPUTINSTUDY(NodesName)  \
70     for ( int n = 0; n < nodes->NodesName.length(); n++ ) { \
71       SUPERV_CNode aCNode = SUPERV::CNode::_narrow(nodes->NodesName[n]); \
72       SUPERV_Ports aPortList = aCNode->Ports(); \
73       for (int p = 0; p < aPortList->length(); p++) { \
74         SUPERV::Port_ptr aPort = aPortList[p].in(); \
75         if ( !aPort->IsInput() && !aPort->IsGate() ) { \
76           bool aInStudy = dynamic_cast<SUPERVGUI_CanvasPortOut*>( aMain->getCanvas()->getPort(aPort) )->isInStudy(); \
77           dynamic_cast<SUPERVGUI_CanvasPortOut*>( getCanvas()->getPort( getDataflow()->Node(aCNode->Name())->GetOutPort(aPort->Name()) ) )->setStudyState(aInStudy); \
78         } \
79       } \
80     }
81
82 SUPERVGUI_Main::SUPERVGUI_Main( SUPERVGraph_ViewFrame* theParent, 
83                                 SUIT_Desktop* theDesktop, SUPERV_Graph theDataFlow )
84      : SUPERVGraph_View(theParent),
85        myLogged( false ),
86        myFiltered( false ),
87        myLogFileName( QString::null ),
88        myLogFile( NULL ),
89        myWarning( false ),
90        myStep( false ),
91        myTrace( false ),
92        myVerbose( false )
93   //myExecuted( false )
94 {
95   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
96   setFocusPolicy( StrongFocus );  // mkr : IPAL11388
97   theParent->setViewWidget(this);
98   dataflow = theDataFlow;
99   if (SUPERV_isNull(dataflow)) {
100     QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
101     close();
102   } else {
103     init(theDesktop);
104   }
105
106   syncPutInStudy(); // mkr : PAL8150
107
108   // mkr : IPAL11362
109   connect(this, SIGNAL(EventToSync()), this, SLOT(onObjectCreatedDeleted()));
110 }
111
112 void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
113   Trace("SUPERVGUI_Main::init");
114   SUIT_Application* anActApp = SUIT_Session::session()->activeApplication();
115
116   if (theDesktop) 
117     myNService = dynamic_cast<SalomeApp_Application*>( anActApp )->namingService();
118   myHashCode = "New";
119   myCopyNum = 0;
120   choosing  = false;
121   myIsLocked = false;
122
123   myThread = new SUPERVGUI_Thread();
124   myThread->setMain(this);
125
126   myCurrentView = CANVAS;
127   myIsFromStudy = false;
128   myLastGraph = 0;
129   study = anActApp->activeStudy();
130
131   //mkr: Supervision module already connected to the 
132   //active study. So, we have to commented this code!
133   /*_PTR(Study) studyDoc = (( SalomeApp_Study* )study)->studyDS();
134   bool aLocked = studyDoc->GetProperties()->IsLocked();
135   _PTR(StudyBuilder) builder ( studyDoc->NewBuilder() );
136   _PTR(SComponent) father = studyDoc->FindComponent(STUDY_SUPERVISION);
137   if ( !father ) {
138     SUIT_Operation* op = new SalomeApp_ImportOperation( study->application() );
139     op->start();
140     if (aLocked) studyDoc->GetProperties()->SetLocked(false);
141     father = builder->NewComponent(STUDY_SUPERVISION);
142     _PTR(GenericAttribute) anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
143     _PTR(AttributeName) aName ( anAttr );
144     aName->SetValue( dynamic_cast<CAM_Application*>( study->application() )->moduleTitle( "SUPERV" ).latin1() );
145     
146     anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
147     _PTR(AttributePixMap) aPixmap ( anAttr );
148     aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
149     
150     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
151     if ( !aSupMod ) {
152       MESSAGE("NULL Supervision module!");
153       return;
154     }
155
156     builder->DefineComponentInstance(father, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
157                                              //dynamic_cast<SALOMEDS_Study*>( studyDoc )->ConvertObjectToIOR(aSupMod->getEngine()));
158     if (aLocked) studyDoc->GetProperties()->SetLocked(true);
159     op->commit();
160   };
161   */
162
163   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
164
165   objectBrowser = app->objectBrowser();
166
167   myArray = new SUPERVGUI_CanvasArray( this, resMgr() );
168   myArrayView = new SUPERVGUI_ArrayView( myArray, this );
169
170   myCanvas = new SUPERVGUI_Canvas( this, resMgr() );
171   myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
172
173   message = app->logWindow();
174   notification = new NOTIFICATION_Consumer();
175
176   QBoxLayout * layout = new QVBoxLayout(this);
177   layout->setMargin(0);
178   layout->setSpacing(0);
179   layout->addWidget(myCanvasView);
180   layout->addWidget(myArrayView);
181
182   if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
183     myCanvas->merge();
184   }
185
186   sync();
187   show();
188   if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
189     myLogFile = fopen( myLogFileName.latin1(), "a" );
190     if (  myLogFile == NULL )
191       myLogged = false;
192   }
193   myTimer = new QTimer( this );
194   connect( myTimer, SIGNAL(timeout()), this, SLOT(checkExecution()) );
195 }
196
197 SUPERVGUI_Main::~SUPERVGUI_Main() {
198   Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
199
200   // close all opened SubGraphs 
201   QMap<QString, SUIT_ViewWindow*/*QAD_StudyFrame**/>::iterator it;
202   for (it = mySubGraphs.begin(); it != mySubGraphs.end(); ++it) {
203     it.data()->removeEventFilter(this);
204     it.data()->disconnect();
205     //it.data()->close();
206
207     //QAD_Study* aStudy = it.data()->getStudy();
208     //aStudy->removeStudyFrame(it.data());
209     //remove view from internal view manager's list of views
210     //it.data()->getViewManager()->removeView(it.data());
211     SUIT_ViewManager* aVM = it.data()->getViewManager();
212     STD_Application* anApp = dynamic_cast<STD_Application*>( SUIT_Session::session()->activeApplication() );
213     if ( anApp ) anApp->removeViewManager(aVM);
214     //if ( aVM ) delete aVM; // mkr : IPAL11547
215     
216   }
217   mySubGraphs.clear();
218   mySubGraphMap.clear();
219   /*
220   QAD_StudyFrame* aSubGraph;
221   for (aSubGraph = mySubGraphs.first(); aSubGraph; aSubGraph = mySubGraphs.next()) {
222     aSubGraph->removeEventFilter(this);
223     aSubGraph->close();
224   }
225   */
226
227   if ( myLogFile != NULL) {
228     fclose( myLogFile );
229   }
230   
231   //  delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
232   notification->_remove_ref();  // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
233
234   delete myCanvas;
235   delete myArray;
236 }
237
238 SUIT_ResourceMgr* SUPERVGUI_Main::resMgr() const
239 {
240   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
241   return app ? app->resourceMgr() : 0;
242 }
243
244 void SUPERVGUI_Main::filterNotification() {
245   Trace("SUPERVGUI_Main::filterNotification");
246   SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
247   dlg->setFiltered( myFiltered );
248   dlg->setLogged( myLogged, myLogFileName );
249   dlg->setWarning( myWarning );
250   dlg->setStep( myStep );
251   dlg->setTrace( myTrace );
252   dlg->setVerbose( myVerbose );
253   if ( dlg->exec() == QDialog::Accepted ) {
254     myLogged      = dlg->getLogged();
255     myLogFileName = dlg->getLogFile();
256     myFiltered    = dlg->getFiltered();
257     myWarning     = dlg->getWarning();
258     myStep        = dlg->getStep();
259     myTrace       = dlg->getTrace();
260     myVerbose     = dlg->getVerbose();
261     delete dlg;
262     if ( myLogFile != NULL) {
263       fclose( myLogFile );
264     }
265     myLogFile = NULL;
266     if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
267       myLogFile = fopen( myLogFileName.latin1(), "a" );
268       if (  myLogFile == NULL ) {
269         myLogged = false;
270         QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
271       }
272     }
273   }
274 }
275
276 void SUPERVGUI_Main::changeDSGraphParameters() {
277   SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
278   if (aDlg->exec() )
279     sync();
280   delete aDlg;
281 }
282
283 void SUPERVGUI_Main::syncAsync() {
284   Trace("SUPERVGUI_Main::syncAsync");
285   QTimer::singleShot(1, this, SLOT(sync()));
286 }
287
288
289 /**
290  * Called by thread when dataflow is executing
291  */
292 void SUPERVGUI_Main::execute( char *  theNodeName, SUPERV::GraphState theNodeState ) {
293   if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
294     SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
295     if ( aNode ) {
296       aNode->sync();
297       emit EventToSync(); // mkr : IPAL11362
298     }
299   }
300   else if (myCurrentView == CANVASTABLE) {
301     SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
302     if (aNode) {
303       aNode->sync();
304       emit EventToSync(); // mkr : IPAL11362
305     }
306   }
307
308   // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a 
309   // CanvasPort the functionality was moved from SUPERVGUI_CanvasPortOut::sync() method please, see 
310   // comment in that method for details.
311   if ( theNodeState == SUPERV::DoneState ) {
312     SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
313     if ( aNode ) {
314       //cout << " *** theNode " << theNodeName << " received DONE_STATE *** " << endl;
315       SUPERVGUI_CanvasPortOut* aPortOut;
316       QObjectList* aPortList = aNode->queryList("SUPERVGUI_CanvasPortOut");
317       QObjectListIt aPortIt(*aPortList);
318       while ((aPortOut=(SUPERVGUI_CanvasPortOut*)aPortIt.current()) != 0) {
319         ++aPortIt;
320         if ( aPortOut->isInStudy() && aPortOut->getEngine()->State() == SUPERV::ReadyState ) {
321           //cout << " *** " << theNodeName << "[" << aPortOut->name() << "]--> goes into study *** " << endl;
322           putDataStudy( aPortOut->getEngine(), STUDY_PORT_OUT );
323         }
324       }
325       delete aPortList;      
326     } 
327     //else //normal case if Node is not found is when node is a graph!  it can receive DoneState as well!  
328     //  MESSAGE( "ERROR in SUPERVGUI_Main::execute() : CanvasNode \"" << theNodeName << "\" NOT FOUND in myCanvas" );
329   }
330 }
331
332
333 void SUPERVGUI_Main::sync() {
334   Trace("SUPERVGUI_Main::sync");
335   if ((SUPERV_isNull(dataflow))) 
336     return;
337   QString t = tr("GRAPH_TITLE");
338   
339   t += dataflow->Name();
340   setCaption(t);
341
342   //study->updateObjBrowser();
343   //mkr: we have to update object browser only if there are some ports datas in the study
344   //or if dataflow is in the study itself. It is done in the 
345   //1) putDataStudy(...) method (it called when we put in study data of port
346   //                             or if port is in study and execution is finished)
347   //2) addDataflowToStudy() method (it is called as a slot when we add in study dataflow itself).
348   //So, we commented updateObjBrowser function here!
349   //SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
350   //if ( aSupMod ) aSupMod->updateObjBrowser();
351   //else MESSAGE("NULL Supervision module!");
352
353   // update "Save" icon and menu state, if dataflow is published
354   _PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
355   _PTR(SObject)  aSO = aStudy->FindObjectIOR(dataflow->getIOR());
356   if (aSO) SUPERVGUI_Main::setModifiedFlag();  
357
358   if (myCurrentView == CANVASTABLE) {
359     myArray->sync();
360     myArray->update();
361   } else {
362     myCanvas->sync();
363     myCanvas->update();
364   }
365 }
366
367 void SUPERVGUI_Main::showCanvasTable() {
368   if (myCurrentView == CANVASTABLE) 
369     return;
370
371   if (myArray->create()) {
372     myCanvasView->hide();
373     myArrayView->show();
374     myCurrentView = CANVASTABLE;
375   }
376   sync();
377 }
378
379 void SUPERVGUI_Main::showContolFlow() {
380   bool merge = false;
381   if (myCurrentView == CANVASTABLE) {
382     myArrayView->hide();
383     myArray->destroy();
384     merge = true;
385   }
386   myCurrentView = CONTROLFLOW;
387   myCanvas->setControlView();
388   if (merge) {
389     myCanvas->merge();
390     myCanvasView->show();
391   }
392 }
393
394 void SUPERVGUI_Main::showCanvas() {
395   if (myCurrentView == CANVAS) 
396     return;
397
398   bool merge = false;
399   if (myCurrentView == CANVASTABLE) {
400     myArrayView->hide();
401     myArray->destroy();
402     merge = true;
403   }
404   myCurrentView = CANVAS;
405   myCanvas->setFullView();
406   if (merge) {
407     myCanvas->merge();
408     myCanvasView->show();
409   }
410 }
411
412 void SUPERVGUI_Main::insertFile() {
413   Trace("SUPERVGUI_Main::insertFile");
414
415   if ( !ReadyToModify() ) // null dataflow or executing, ..
416     return;
417
418   QString f = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
419                                         "",
420                                         "*.xml",
421                                         tr("MSG_GRAPH_INSERT"),
422                                         true);
423   if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name
424       
425     Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960
426
427     if (dataflow->Import(f.latin1())) {
428       if (myCurrentView == CANVASTABLE) {
429         myArray->destroy();
430         myArray->create();
431       }
432       else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
433         myCanvas->merge();
434       }
435       sync();
436     } else {
437       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
438     }
439   }
440 }
441
442 void SUPERVGUI_Main::copy() {
443   Trace("SUPERVGUI_Main::copy");
444   if (dataflow->ThreadsMax() == 0) {
445     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
446     return;
447   }
448   
449   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
450   if ( !aSupMod ) {
451     MESSAGE("NULL Supervision module!");
452     return;
453   }
454
455   SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aSupMod->createGraph() );
456   if( aViewFrame ) {
457     SUPERV_Graph aNewGraph; //  = dataflow->StreamCopy();
458     if ( dataflow->IsStreamGraph() ) {
459       SUPERV_StreamGraph aSGraph = dataflow->ToStreamGraph();
460       if ( SUPERV_isNull(aSGraph) ) {
461         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
462         return;
463       }
464       aNewGraph = aSGraph->StreamCopy();
465     }
466     else {
467       aNewGraph = dataflow->Copy();
468     }
469     QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
470     aNewName += dataflow->Name();
471     aNewGraph->SetName(aNewName);
472     /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame, 
473                                                aSupMod->application()->desktop(),//getDesktop(), 
474                                                aNewGraph);
475     aViewFrame->show();
476   }
477 }
478
479 void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
480 {
481   if (theNode->IsMacro()) {
482     // get SubGraph from MacroNode
483     SUPERV_Graph aMacro = SUPERV::Graph::_narrow(theNode);
484     SUPERV_Graph aGraph;
485     if (aMacro->IsStreamMacro())
486       aGraph = aMacro->StreamObjRef();
487     else
488       aGraph = aMacro->FlowObjRef();
489
490     // display SubGraph
491     if (SUPERV_isNull(aGraph)) {
492       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOACCESS"));
493       return;
494     }
495     else {
496       QString aGraphName = aGraph->Name();
497       SUIT_ViewWindow* aStudyFrame;
498       if (mySubGraphs.contains(aGraphName)) {
499         aStudyFrame = mySubGraphs[aGraphName];
500         aStudyFrame->setActiveWindow();
501         aStudyFrame->setFocus();
502       }
503       else {
504         SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
505         if ( !aSupMod ) {
506           MESSAGE("NULL Supervision module!");
507           return;
508         }
509         
510         aStudyFrame = aSupMod->createGraph();
511         if ( aStudyFrame ) {
512           SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aStudyFrame );
513           if( aViewFrame ) {
514             new SUPERVGUI_Main(aViewFrame, 
515                                aSupMod->application()->desktop(),//getDesktop(), 
516                                aGraph);
517             //    connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)), 
518             //            this,  SLOT(onSubGraphClosed(QAD_StudyFrame*)));
519             connect(aSupMod->application()->desktop(), SIGNAL(windowActivated( SUIT_ViewWindow* )), 
520                     this,  SLOT(onSubGraphActivated( SUIT_ViewWindow* )));
521             aStudyFrame->installEventFilter(this);
522
523             mySubGraphs.insert(aGraphName, aStudyFrame);
524             mySubGraphMap.insert(aGraphName, theNode->Name());
525
526           }
527         }
528       }
529       aStudyFrame->show();
530       if (!correct) myLastGraph = aStudyFrame;
531     }
532   }
533 }
534
535 // mkr : IPAL11549
536 void SUPERVGUI_Main::destroySubGraph(QString theSubGraphName)
537 {
538   if ( mySubGraphs.contains(theSubGraphName) ) {
539     SUIT_ViewWindow* aStudyFrame = mySubGraphs[theSubGraphName];
540     onSubGraphClosed(aStudyFrame);
541     SUIT_ViewManager* aVM = aStudyFrame->getViewManager();
542     STD_Application* anApp = dynamic_cast<STD_Application*>( SUIT_Session::session()->activeApplication() );
543     if ( anApp ) anApp->removeViewManager(aVM);
544   }
545 }
546
547 bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
548 {
549   // workaround to get close event
550   if (o->inherits("SUIT_ViewWindow"/*"QAD_StudyFrame"*/) && e->type() == QEvent::Close) {
551     SUIT_ViewWindow* aFrame = (SUIT_ViewWindow*) o;
552     onSubGraphClosed(aFrame);
553   }
554   return SUPERVGraph_View::eventFilter(o, e);
555 }
556
557 // workaround to fix PAL6255 -> opened SubGraph is not on top
558 void SUPERVGUI_Main::onSubGraphActivated(SUIT_ViewWindow* theStudyFrame)
559 {
560   if (myLastGraph) {
561     SUIT_ViewWindow* aFrame = myLastGraph;
562     myLastGraph = 0;
563     aFrame->setActiveWindow();
564     aFrame->setFocus();
565   }
566 }
567
568 void SUPERVGUI_Main::onSubGraphClosed(SUIT_ViewWindow* theStudyFrame)
569 {
570   if ( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( theStudyFrame ) ) {
571     theStudyFrame->removeEventFilter(this);
572     disconnect(theStudyFrame, 0, this, 0);
573
574     SUPERVGraph_View* view = supervFrame->getViewWidget();
575     SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
576     if (aGraph) {
577       QString aGraphName = aGraph->getDataflow()->Name();
578       QMap<QString, QString>::iterator it = mySubGraphMap.find(aGraphName);
579       if (it != mySubGraphMap.end()) {
580         QString aNodeName = it.data();
581         SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) 
582           myCanvas->child(aNodeName, "SUPERVGUI_CanvasNode");
583         if (aNode) {
584           aNode->merge();
585           myCanvas->update();
586         }
587         mySubGraphMap.remove(it);
588       }
589       mySubGraphs.remove(aGraphName);
590     }
591   }
592 }
593
594 void SUPERVGUI_Main::onShowToolbar()
595 {
596   SUPERVGraph_ViewFrame* aVF = (SUPERVGraph_ViewFrame*)this->parent();
597   if ( aVF )
598     aVF->getToolBar()->show();
599 }
600
601 // mkr : PAL8237 : synchronize many views of the same dataflow (objects creation/deletion)
602 void SUPERVGUI_Main::onObjectCreatedDeleted()
603 {
604   if ( study ) {
605     if ( LightApp_Application* app = dynamic_cast<LightApp_Application*>( study->application() ) ) {
606       ViewManagerList aVMList;
607       app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
608       SUIT_ViewManager* aVM;
609       for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
610         QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
611         for ( int i = 0; i < aVWList.count(); i++ ) {
612           SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
613           QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
614           if ( aMainList->count() == 1 ) {
615             SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
616             if ( aMain ) {
617               if (aMain != this &&
618                   !CORBA::is_nil(aMain->getDataflow()) &&
619                   !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR())) // equal dataflows
620                 aMain->getCanvas()->merge();
621             }
622           }
623         }
624       }
625
626       // update "Save" icon and menu state, if dataflow is published
627       //_PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
628       //_PTR(SObject)  aSO = aStudy->FindObjectIOR(dataflow->getIOR());
629       //if (aSO) SUPERVGUI_Main::setModifiedFlag();  
630     }
631   }
632 }
633
634 // mkr : PAL8150 : synchronize many views of the same dataflow ("Put In Study"/"Not In Study" operation)
635 void SUPERVGUI_Main::onPutInStudy( QString* theNodePortName )
636 {
637   if ( study ) {
638     if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
639       ViewManagerList aVMList;
640       app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
641       SUIT_ViewManager* aVM;
642       for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
643         QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
644         for ( int i = 0; i < aVWList.count(); i++ ) {
645           SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
646           QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
647           if ( aMainList->count() == 1 ) {
648             SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
649             if ( aMain )
650               if ( !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
651                    && 
652                    aMain != this ) { // not equal mains
653                 QString aNodeName = theNodePortName->left( theNodePortName->find('_') );
654                 QString aPortName = theNodePortName->right( theNodePortName->length() - theNodePortName->find('_') - 1 );
655                 bool anIsInStudy = dynamic_cast<SUPERVGUI_CanvasPortOut*>( getCanvas()->getPort( getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->isInStudy();
656                 dynamic_cast<SUPERVGUI_CanvasPortOut*>( aMain->getCanvas()->getPort( aMain->getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->setStudyState( anIsInStudy );
657               }
658           }
659         }
660       }
661       //SUPERVGUI_Main::setModifiedFlag();
662     }
663   }
664 }
665
666 // mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
667 void SUPERVGUI_Main::syncPutInStudy()
668 {
669   if ( study ) {
670     if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
671       ViewManagerList aVMList;
672       app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
673       SUIT_ViewManager* aVM;
674       for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
675         QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
676         for ( int i = 0; i < aVWList.count(); i++ ) {
677           SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
678           QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
679           if ( aMainList->count() == 1 ) {
680             SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
681             if ( aMain )
682               if ( !CORBA::is_nil( aMain->getDataflow() )
683                    &&
684                    !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
685                    && 
686                    aMain != this ) { // not equal mains
687         
688                 // check "myInStudy" field of output ports of original main (i.e. this main)
689                 // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
690                 SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
691                 
692                 SYNCPUTINSTUDY(CNodes);
693                 SYNCPUTINSTUDY(FNodes);
694                 SYNCPUTINSTUDY(INodes);
695                 SYNCPUTINSTUDY(GNodes);
696                 SYNCPUTINSTUDY(LNodes);
697                 SYNCPUTINSTUDY(ELNodes);
698                 SYNCPUTINSTUDY(SNodes);
699                 SYNCPUTINSTUDY(ESNodes);
700                 SYNCPUTINSTUDY(Graphs);
701
702                 setRunTime( aMain->getRunTime() );
703
704                 break;
705               }
706           }
707         }
708       }
709     }
710   }
711 }
712
713 void SUPERVGUI_Main::run( const bool andSuspend ) {
714   Trace("SUPERVGUI_Main::run");
715   if ( SUPERV_isNull(dataflow) ) 
716     return;
717   
718   if ( dataflow->IsEditing() ) { // not currently Executing
719
720     // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
721     Editing(); // remove old executor, update GUI (all nodes to "No Status")
722
723     if ( !dataflow->IsValid() ) {
724       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
725     } 
726     else if (!dataflow->IsExecutable()) {
727       QString aMessage = QString(dataflow->Messages());
728       if ( aMessage.isEmpty() ) // mkr : IPAL11471
729         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
730       else
731         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
732     } 
733     else if (myCanvasView->isAnyLinkCreating()) {
734       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
735     } 
736     else {
737       myRunTime = QDateTime::currentDateTime();
738       const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
739       if ( !result ) {
740         // PAL12902
741         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE") + QString(" : ") + QString(dataflow->Messages()));
742         if ( dataflow->State() == SUPERV::ErrorState ) {
743           // PAL12902
744           if ( !dataflow->IsEditing() ) kill();
745         }
746       } 
747       else {
748         //myExecuted = true; // set to true on first execution. for correct publishing in Study
749         myThread->startThread(tr("MSG_GRAPH_STARTED"));
750       }
751     }
752   } 
753   else {
754     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
755   }
756 }
757
758
759 void SUPERVGUI_Main::kill() {
760   Trace("SUPERVGUI_Main::kill");
761   if ((SUPERV_isNull(dataflow))) 
762     return;
763
764   if (dataflow->IsEditing()) {
765     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
766   } 
767   else if (dataflow->Kill()) {
768     // IPAL9273, 9369, 9731 : to avoid two equal messages about killing dataflow
769     //                        execution in the Message Console
770     //getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
771     sync();
772   } 
773   else {
774     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
775   }
776 }
777
778 void SUPERVGUI_Main::suspendResume() {
779     Trace("SUPERVGUI_Main::suspendResume");
780
781     if ((SUPERV_isNull(dataflow))) return;
782
783     if (dataflow->IsEditing()) {
784         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
785     } else if (dataflow->State() == SUPERV_Suspend) {
786       if (dataflow->Resume()) {
787         myThread->startThread(tr("MSG_DF_RESUMED"));
788       } else {
789         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
790       }
791     } else {
792       if (dataflow->Suspend()) {
793         sync();
794         getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
795       } else {
796         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
797       }
798     }
799 }
800 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
801    the comment from kloss below may be explaining it, but it's in French and I do not understand it..
802    It also calls deprecated method of Engine: ReStart(). 
803 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
804     Trace("SUPERVGUI_Main::stopRestart");
805     if ((SUPERV_isNull(dataflow))) return;
806
807     if (dataflow->IsEditing()) {
808         QMessageBox::warning(0, tr("ERROR"),  tr("MSG_DF_NOTRUNNING"));
809     } else if (dataflow->State() == SUPERV_Stop) {
810         if (dataflow->ReStart()) {
811             message->setMessage(tr("MSG_DF_RESTARTED"));
812             sync();
813         } else {
814             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
815         };
816     } else {
817         if (dataflow->Stop()) {
818             sync();
819         } else {
820             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
821         };
822     };
823 }
824 */
825 void SUPERVGUI_Main::addNode() {
826   Trace("SUPERVGUI_Main::addNode");
827   
828   if ( !ReadyToModify() ) // null dataflow or executing, ..
829     return;
830   
831   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
832   if ( !aSupMod ) {
833     MESSAGE("NULL Supervision module!");
834     return;
835   }
836
837   //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
838   aSupMod->getBrowser()->choose();
839 }
840
841 /**
842  * Add Computation node
843  */
844 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
845   switch (myCurrentView) {
846   case CANVASTABLE:
847     myArray->destroy();
848     myArray->create();
849     break;  
850   case CANVAS:
851   case CONTROLFLOW: 
852     {
853       SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasComputeNode::Create(resMgr(), myCanvas, this, theNode);
854       aNode->move(theNode->X(), theNode->Y());
855       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
856       aNode->show();
857       myCanvas->update();
858     }
859     break;
860   }
861 }
862
863 /**
864  * Add GOTO node
865  */
866 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
867   switch (myCurrentView) {
868   case CANVASTABLE:
869     myArray->destroy();
870     myArray->create();
871     break;
872   case CANVAS:
873   case CONTROLFLOW: 
874     {
875       SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasGotoNode::Create(resMgr(), myCanvas, this, theNode);
876       aNode->move(theNode->X(), theNode->Y());
877       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
878       aNode->show();
879       myCanvas->update();
880     }
881     break;
882   }
883 }
884
885 /**
886  * Add Control node
887  */
888 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update)
889 {
890   switch (myCurrentView) {
891   case CANVASTABLE:
892     myArray->destroy();
893     myArray->create();
894     break;
895   case CANVAS:
896   case CONTROLFLOW: 
897     {
898       SUPERVGUI_CanvasStartNode* aStartNode =
899         SUPERVGUI_CanvasStartNode::Create(resMgr(), myCanvas, this, theStartNode);
900       aStartNode->move(theStartNode->X(), theStartNode->Y());
901       if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
902
903       SUPERVGUI_CanvasEndNode* aEndNode =
904         SUPERVGUI_CanvasEndNode::Create(resMgr(), myCanvas, this, theEndNode, aStartNode);
905       aEndNode->move(theEndNode->X(), theEndNode->Y());
906       if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
907
908       aStartNode->show();
909       aEndNode->show();
910       myCanvas->update();
911     }
912     break;
913   }
914 }
915
916
917 /**
918  * Add Macro node
919  */
920 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
921   switch (myCurrentView) {
922   case CANVASTABLE:
923     myArray->destroy();
924     myArray->create();
925     break;
926   case CANVAS:
927   case CONTROLFLOW: 
928     {
929       SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasMacroNode::Create(resMgr(), myCanvas, this, theNode);
930       aNode->move(theNode->X(), theNode->Y());
931       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
932       aNode->show();
933       myCanvas->update();
934     }
935     break;
936   }
937 }
938
939 SUPERVGUI_CanvasArray*  SUPERVGUI_Main::getCanvasArray() {
940   Trace("SUPERVGUI_Main::getCanvasArray");
941   return(myArray);
942 }
943
944 SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
945   Trace("SUPERVGUI_Main::getArrayView");
946   return(myArrayView);
947 }
948
949 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
950   Trace("SUPERVGUI_Main::getCanvas");
951   return(myCanvas);
952 }
953
954 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
955     Trace("SUPERVGUI_Main::getCanvasView");
956     return(myCanvasView);
957 }
958
959 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
960   Trace("SUPERVGUI_Main::getDataflow");
961   return(dataflow);
962 }
963
964 LogWindow* SUPERVGUI_Main::getMessage() {
965   Trace("SUPERVGUI_Main::getMessage");
966   return(message);
967 }
968
969 SUIT_Study* SUPERVGUI_Main::getStudy() {
970   Trace("SUPERVGUI_Main::getStudy");
971   return(study);
972 }
973
974 bool SUPERVGUI_Main::isArrayShown() {
975   Trace("SUPERVGUI_Main::isArrayShown");
976   return(myCurrentView == CANVASTABLE);  
977 }
978
979 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
980   Trace("SUPERVGUI_Main::showPopup");
981   // To check is Supervision active?
982   if (myIsLocked) return;
983   //if (dataflow->IsExecuting()) return;
984
985   CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
986   if ( !anApp->activeModule() ) return;
987   if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
988
989   if (e->button() == RightButton) {
990     p->exec(e->globalPos());
991   }
992 }
993
994 void SUPERVGUI_Main::changeInformation() {
995   SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
996   if (aDlg->exec() )
997     sync();
998   delete aDlg;
999 }
1000
1001 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
1002     Trace("SUPERVGUI_Main::chooseData");
1003     if (choosing) {
1004       QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
1005       if (!id.isEmpty()) {
1006         _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
1007         _PTR(GenericAttribute) anAttr;
1008         if (object->FindAttribute(anAttr, "AttributeIOR")) {
1009           _PTR(AttributeIOR) anIOR ( anAttr );
1010           
1011           // asv : 13.12.04 : commented out use of portIn field, but it seems that it 
1012           // should be replaced with some analogious code... selection of IOR was done -
1013           // put its value into port.
1014           //portIn->setValue(ior);
1015           
1016           SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1017           if ( !aSupMod ) {
1018             MESSAGE("NULL Supervision module!");
1019             return;
1020           }
1021
1022           // stop selection
1023           choosing = false;
1024           setCursor(aSupMod->getCursor());
1025           objectBrowser->setCursor(aSupMod->getCursor());
1026           aSupMod->putInfo("");
1027         }
1028       }
1029     }
1030 }
1031
1032 _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
1033                                         _PTR(StudyBuilder) const theBuilder,
1034                                         _PTR(SObject) const theSO,
1035                                         const char* theName,
1036                                         bool* theDoneSomething ) {
1037   _PTR(SObject) aResult;
1038   _PTR(AttributeName) aName;
1039   _PTR(GenericAttribute) anAttr;
1040   _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
1041   for (; anIterator->More(); anIterator->Next()) {
1042     if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1043       aName = _PTR(AttributeName) ( anAttr );
1044       if (strcmp(aName->Value().c_str(), theName) == 0) {
1045         aResult = anIterator->Value();
1046         break;
1047       }
1048     }
1049   }
1050
1051   // if aResule was found then theDoneSomething=false and we return
1052   *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
1053   if ( !*theDoneSomething )
1054     return aResult;
1055
1056   // add new SObject
1057   aResult = theBuilder->NewObject( theSO );
1058   anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1059   aName = _PTR(AttributeName) ( anAttr );
1060   aName->SetValue(theName);
1061   return aResult;
1062 }
1063     
1064 /**
1065  * Return true if dataflow is already in the study
1066  */
1067 bool SUPERVGUI_Main::isDataflowInStudy() const {
1068   _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1069   _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
1070   return ( aSO ? true : false );
1071 }
1072
1073 /**
1074  * Create a "Supervision" object in the Study and a "dataflow" object under it
1075  * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
1076  */
1077 _PTR(SObject) createDataflowSObj( SUIT_Study* study, 
1078                                   SUPERV::Graph_var dataflow, 
1079                                   _PTR(StudyBuilder) aBuilder,
1080                                   bool& aDoneSomething ) {
1081   _PTR(Study)            aStudy = (( SalomeApp_Study* )study)->studyDS();
1082   _PTR(GenericAttribute) anAttr;
1083   _PTR(AttributeName)    aName;
1084
1085   // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1086   _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
1087   if ( !aSO ) { // dataflow SObject not found in the study
1088     aDoneSomething = true; 
1089     _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1090     if ( !aComponent ) { // is supervision component not found, then create it
1091       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1092       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1093       aName = _PTR(AttributeName) ( anAttr );
1094       aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
1095         
1096       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1097       _PTR(AttributePixMap) aPixmap ( anAttr );
1098       aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1099
1100       SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1101       if ( aSupMod )
1102         aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
1103                                                     //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
1104       else MESSAGE("NULL Supervision module!");
1105       
1106     }
1107     // create dataflow SObject ("aNewDataflow_1") 
1108     aSO = aBuilder->NewObject(aComponent);
1109     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1110     aName = _PTR(AttributeName) ( anAttr );
1111     aName->SetValue(dataflow->Name());
1112     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1113     _PTR(AttributeIOR) anIORAttr ( anAttr );
1114     anIORAttr->SetValue(dataflow->getIOR());
1115   }
1116
1117   return aSO;
1118 }
1119
1120 void SUPERVGUI_Main::addDataflowToStudy() {
1121   bool isCreated;
1122   _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
1123   aBuilder->NewCommand();
1124   _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
1125   if ( aDF ) {
1126     aBuilder->CommitCommand();
1127     // what is this register/unregister?? don't know..
1128     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1129     if ( !aSupMod ) {
1130       MESSAGE("NULL Supervision module!");
1131       return;
1132     }
1133     aSupMod->unregisterGraph(this);
1134     aSupMod->registerGraph(dataflow->getIOR(), this);
1135
1136     if ( !myThread->running() )
1137       aSupMod->updateObjBrowser();
1138
1139     aSupMod->getApp()->updateActions();  
1140   }
1141   else {
1142     MESSAGE( "ERROR: failed to find or create dataflow SObject" );
1143     aBuilder->AbortCommand();
1144   }
1145 }
1146
1147 bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
1148   Trace("SUPERVGUI_Main::putDataStudy");
1149
1150   bool PublishOtherComponent = false;
1151
1152   // static variable to ensure that only one instance (thread) is executing this function 
1153   static bool isIn = false;
1154   if (isIn)   return true; 
1155   else        isIn = true;
1156
1157   _PTR(Study)        aStudy = (( SalomeApp_Study* )study)->studyDS();
1158   const bool         aLocked = aStudy->GetProperties()->IsLocked();
1159   _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
1160   bool                           aDoneSomething = false;
1161
1162   // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
1163   if ( aLocked ) {
1164     MESSAGE( "The study is locked and can not be modified!" );
1165     isIn = false;
1166     return false;
1167   }
1168
1169   // check if the port and its node are good
1170   if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
1171     MESSAGE( "putInStudy ERROR: port or node are NULL!" );
1172     isIn = false;
1173     return false;
1174   }
1175
1176   // open new command.  Commit or Abort it depending on aDoneSomething variable or error
1177   aBuilder->NewCommand();
1178   
1179   // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1180   _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
1181
1182   if ( !aSO ) {
1183     MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" ); 
1184     aBuilder->AbortCommand();
1185     isIn = false;
1186     return false;
1187   }
1188
1189   // Create "Run -> Time and date, etc." SObjects
1190   if  ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
1191
1192     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
1193     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
1194     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
1195     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
1196
1197     // create IOR attribute for port SObject (usually with "return" name)
1198     _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
1199     _PTR(AttributeIOR) anIORAttr  ( anAttr );
1200
1201     // if we have not created anything (all SObject already existed) and we have the same IORAttribute
1202     // on the needed SObject -> then don't do anything! it's already there!
1203     if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
1204       aBuilder->AbortCommand();
1205       isIn = false;
1206       return true;
1207     }
1208
1209     aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
1210
1211     // set object value to the study: if object is external, then put it with
1212     //  help of the specific component - owner
1213     if ( p->IsIOR() ) {
1214       // get according component driver for result object
1215       SALOME_LifeCycleCORBA aLCC( myNService );
1216       SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
1217       if ( !aFNode->_is_nil() ) {
1218         Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
1219         SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
1220         if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
1221           CORBA::Object_ptr anObject = new CORBA::Object();
1222           CORBA::Any* anAny = p->ToAny();
1223           (*anAny) >>= anObject;
1224         
1225           if ( aDriver->CanPublishInStudy( anObject ) ) {
1226             SALOMEDS::SObject_var aTmpSO;// = aSO;
1227             SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
1228             if ( !aSStudy ) return false;
1229             try {
1230               aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
1231               aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
1232               PublishOtherComponent = true;
1233             }
1234             catch ( ... ) { // mkr : PAL8150
1235             }
1236           } 
1237           else { // can't publish object: abort transaction
1238             MESSAGE( "CanPublishInStudy() returned FALSE.  ok, AbortCommand.." );
1239             aBuilder->AbortCommand();
1240             isIn = false;
1241             return false;
1242           }
1243         }
1244         else { // component has no driver, but could store IORs (like Calculator)
1245           _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1246           if ( anIORSO ) {
1247             aBuilder->Addreference(aSO, anIORSO);
1248             // mkr : IPAL9672
1249             PublishOtherComponent = true;
1250           }
1251           else { // Hm... the object (==port value) was not found, so we don't publish it.
1252             MESSAGE( "The object (==port value) was not found, so we don't publish it" );
1253             aBuilder->AbortCommand();
1254             isIn = false;
1255             return false;
1256           }
1257         }
1258       }
1259       else { // FNode is NULL -> bad
1260         MESSAGE( "FNode is NULL." );
1261         if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
1262           _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1263           if ( anIORSO )
1264             aBuilder->Addreference(aSO, anIORSO);
1265         }
1266         else {
1267           MESSAGE( "FNode and INode are NULL.  Not good at all.  Aborting command." );
1268           aBuilder->AbortCommand();
1269           isIn = false;
1270           return false;
1271         }
1272       }
1273     } 
1274     else {
1275       anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
1276     }
1277   }
1278
1279   if ( aDoneSomething )
1280     aBuilder->CommitCommand();
1281   else
1282     aBuilder->AbortCommand();
1283
1284   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1285   if ( aSupMod ) {
1286     if ( PublishOtherComponent )
1287       dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
1288     else
1289       aSupMod->updateObjBrowser();
1290   }
1291   else MESSAGE("NULL Supervision module!");
1292
1293   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
1294   if(app) app->updateActions();  
1295   isIn = false;
1296   return true;
1297 }
1298
1299
1300 void SUPERVGUI_Main::ActivatePanning()
1301 {
1302   if (myCanvasView->isVisible()) {
1303     myCanvasView->ActivatePanning();
1304   } else if (myArrayView->isVisible()) {
1305     myArrayView->ActivatePanning();
1306   }
1307 }
1308
1309
1310 void SUPERVGUI_Main::ResetView()
1311 {
1312   if (myCanvasView->isVisible()) {
1313     myCanvasView->ResetView();
1314   } else if (myArrayView->isVisible()) {
1315     myArrayView->ResetView();
1316   }
1317 }
1318
1319 void SUPERVGUI_Main::syncNotification() {
1320   char* graph;
1321   char* node;
1322   char* type;
1323   char* message;
1324   char* sender;
1325   long  counter;
1326   char* date;
1327   long  stamp;
1328
1329   while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1330     if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) { // mkr : PAL7037
1331       QString mess("");
1332       mess += "NOTIF: "; mess += graph;
1333       mess += " / "    ; mess += node;
1334       mess += " / "    ; mess += type;
1335       mess += " / "    ; mess += message;
1336       getMessage()->putMessage(mess.latin1());
1337     };
1338   };
1339 }
1340   
1341 bool SUPERVGUI_Main::isFiltered(char* graph,  char* node,   char* type, char* message, 
1342                                 char* sender, long counter, char* date, long stamp) {
1343   Trace("SUPERVGUI_Main::isFiltered");
1344   bool b = false;
1345   if (strcmp(getDataflow()->Name(), graph) == 0) {
1346     SUPERVGUI_CanvasNode* n;
1347     QObjectList* nodes;
1348     // mkr : PAL7037 -->
1349     if (myCurrentView == CANVASTABLE)
1350       nodes = myArray->queryList("SUPERVGUI_CanvasNode");
1351     else
1352       nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
1353     // mkr : PAL7037 <--
1354     QObjectListIt i(*nodes);
1355     while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
1356       ++i;
1357       if (strcmp(n->name(), node) == 0) {
1358         if (strcmp(type, NOTIF_WARNING) == 0) {
1359           b = n->isWarning();
1360         } else if (strcmp(type, NOTIF_STEP) == 0) {
1361           b = n->isStep();
1362         } else if (strcmp(type, NOTIF_TRACE) == 0) {
1363           b = n->isTrace();
1364         } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1365           b = n->isVerbose();
1366         };
1367         break;
1368       };
1369     };
1370     delete nodes;
1371     if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1372       fprintf( myLogFile, "NOTIF %ld\t%s\t%s\t%ld\t%s\t%s\t%s\t%s\n", stamp, date, sender, counter, graph, node, type, message );
1373       fflush( myLogFile );
1374     };
1375   };
1376   return( b );
1377 }
1378
1379 void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
1380   e->accept();
1381 }
1382
1383
1384 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) { 
1385
1386   myCanvas->setBackgroundColor(color);
1387   myCanvasView->setPaletteBackgroundColor(color.light());
1388   myArray->setBackgroundColor(color);
1389   myArrayView->setPaletteBackgroundColor(color.light());
1390   
1391   SUPERVGraph_View::setPaletteBackgroundColor(color); 
1392 }
1393
1394 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1395   return myEventNodes;
1396 }
1397
1398 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1399   myEventNodes = theEventNodes;
1400 }
1401
1402 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1403   return myStates;
1404 }
1405
1406 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1407   myStates = theStates;
1408 }
1409
1410 int SUPERVGUI_Main::getNodesNumber() {
1411   //create a list of nodes of the graph
1412   SUPERV_Nodes nodes = getDataflow()->Nodes();
1413   int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1414                nodes->INodes.length() + nodes->GNodes.length() +
1415                nodes->LNodes.length() + nodes->SNodes.length();
1416   return RetVal;
1417 }
1418
1419 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1420   return myThread;
1421 }
1422
1423 void SUPERVGUI_Main::startTimer() {
1424   myTimer->start(500);
1425 }
1426
1427 void SUPERVGUI_Main::executionFinished() {
1428   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1429   if ( aSupMod ) 
1430     //aSupMod->updateObjBrowser();
1431     // PAL10611: update all modules data
1432     aSupMod->getApp()->updateObjectBrowser(true);
1433   else MESSAGE("NULL Supervision module!");
1434   
1435   myCanvas->update();
1436   myArray->update();
1437 }
1438
1439 void SUPERVGUI_Main::checkExecution() {
1440   if (myThread->finished()) {
1441     myTimer->stop();
1442     executionFinished();
1443   }
1444 }
1445
1446 /**
1447  * Editing() is to be called by any operation in GUI before modification of a datamodel
1448  * (add/remove ports or nodes, etc.).  It is used to resolve inconsistancies between 2 data models
1449  * in Engine: Editor and Executor.  During and after execution, the values of ports and statuses of nodes
1450  * are taken from Executor data model.  But when user starts editing the graph - these changes must
1451  * be applied to Editor data model.  This function destroys Executor data model and moves to Editor.   
1452  */ 
1453 void SUPERVGUI_Main::Editing() {
1454   if ( !SUPERV_isNull( dataflow ) )
1455     dataflow->Editing();
1456   
1457   // updata GUI, Nodes' statuses and Ports' values could change.
1458   sync();
1459 }
1460
1461 void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
1462 {
1463   // mkr: since the deletion of the node allow only in CANVAS view,
1464   // it is necessary to remove the CanvasArray's children, which
1465   // have the same CNode engine as deleting node. This CNode is given
1466   // as argument
1467   if (myArray) {
1468     const QObjectList* aChList = myArray->children();
1469     if ( aChList ) { // asv 27.01.05 : fix for 7817
1470       QObjectListIt aItChList(*aChList);
1471       SUPERVGUI_CanvasNode* anObjNode;
1472       while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
1473         ++aItChList;
1474         if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
1475           myArray->removeChild(anObjNode);
1476           delete anObjNode;
1477         }
1478       }
1479     } // end of if ( ChList )
1480   }
1481 }
1482
1483 /**
1484  * ReadyToModify() must be called before any modification
1485  * operation - asks to kill execution of dataflow.  If returns false - 
1486  * modification (==Editing() ) is not allowed.
1487  */
1488 bool SUPERVGUI_Main::ReadyToModify() {
1489   if ( CORBA::is_nil( dataflow ) )
1490     return false;
1491   if ( dataflow->IsExecuting() ) {
1492     bool quit = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 0=Yes, 1=No
1493       tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
1494     if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
1495       return false;
1496     else  if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
1497       kill();   // checking again for IsExecuting to be sure that it was not finished while MB was up
1498   }
1499   return true;
1500 }
1501
1502 void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
1503 {
1504   if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
1505     if ( getCanvas()->width() < theEvent->size().width()
1506          ||
1507          getCanvas()->height() < theEvent->size().height() )
1508       getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
1509   if ( myCurrentView == CANVASTABLE && getCanvasArray() )
1510     if ( getCanvasArray()->width() < theEvent->size().width()
1511          ||
1512          getCanvasArray()->height() < theEvent->size().height() )
1513       getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
1514 }
1515
1516 /*!
1517   Sets a modified flag in an active study
1518  */
1519 void SUPERVGUI_Main::setModifiedFlag()
1520 {
1521   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1522   if(app) {
1523     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1524     if(study) {
1525       _PTR(Study) studyDS = study->studyDS();
1526       _PTR(SComponent) sco = studyDS->FindComponent(STUDY_SUPERVISION);
1527       if(sco) {
1528         _PTR(StudyBuilder) builder = studyDS->NewBuilder();
1529         _PTR(GenericAttribute) ga;
1530         ga = builder->FindOrCreateAttribute(sco, "AttributeParameter");
1531         _PTR(AttributeParameter) ap(ga);
1532         if(ap) {
1533           ap->SetBool("SUPERVISOR_MODIFIED_FLAG",1);
1534           app->updateActions();
1535         }
1536       }
1537     }
1538   }
1539 }
1540
1541
1542 /******************************* SUPERVGUI_Thread class ****************************************/
1543 SUPERVGUI_Thread::SUPERVGUI_Thread()
1544      :QThread()
1545 {
1546   myIsActive = false;
1547 }
1548
1549 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1550 {
1551   //it is a virtual destructor and needs to be determine here
1552 }
1553
1554 void SUPERVGUI_Thread::startThread(const char* m)
1555 {
1556   if (!myIsActive) {
1557     myIsActive = true;
1558     
1559     myMain->getMessage()->putMessage(m); 
1560     myMain->sync();
1561
1562     start();
1563   }
1564 }
1565
1566 void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
1567 {
1568   myMain = theMain;
1569 }
1570
1571 void SUPERVGUI_Thread::KillThread( bool theValue )
1572 {
1573   myMutex.lock();
1574   myIsActive = !(theValue);
1575   myMutex.unlock();
1576 }
1577
1578 template<class TObject, typename TArg, typename TArg1, typename TArg2,
1579          typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
1580 class TVoidMemFun3ArgEvent: public SALOME_Event{
1581 public:
1582   typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
1583   TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
1584     myObject(theObject),
1585     myAction(theAction),
1586     myArg(theArg),
1587     myArg1(theArg1),
1588     myArg2(theArg2)
1589   {}
1590   virtual void Execute(){
1591     (myObject->*myAction)(myArg,myArg1,myArg2);
1592   }
1593 private:
1594   TObject* myObject;
1595   TAction myAction;
1596   TStoreArg myArg;
1597   TStoreArg1 myArg1;
1598   TStoreArg2 myArg2;
1599 };
1600
1601 typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
1602
1603 /**
1604  * main_thread_run must be executed in the qt main thread
1605  * It is activated by calling ProcessVoidEvent
1606  */
1607 void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
1608 {
1609     // in case node "said" something during changing state through notification mechanism - output it
1610     myMain->syncNotification();
1611     myMain->sync(); // mkr : NPAL14881
1612     
1613     // "kill" or undefined event came
1614     if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
1615        ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
1616        ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
1617
1618       myIsActive = false;
1619     }
1620     else { // a "normal" execution event came
1621       char* aName = NULL;
1622       if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
1623        aName = aNode->Name();      
1624
1625       // What follow is not quite sure. The entire function is posted to the main qt thread.
1626       // So all executions are serialized. Is it really possible to call execute when another
1627       // execute is running. I don't think so (C Caremoli)
1628       // this function is asynchronious.  The call does NOT wait when SUPERVGUI_Main::execute finishes
1629       // handling the event.  So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
1630       // on the next loop iteration, BEFORE  previous SUPERVGUI_Main::execute finished.
1631       myMain->execute(aName, aState );
1632     }    
1633
1634     // execution is finished.  just set a "finished" message(s)
1635     if ( !myIsActive ) {
1636       QString aMess;
1637       switch ( myMain->getDataflow()->State() ) {
1638       case SUPERV_Editing :     
1639        myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()? 
1640                                         tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
1641        break;  
1642       case SUPERV_Suspend : 
1643        myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
1644        break; 
1645       case SUPERV_Done : 
1646        myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
1647        break;  
1648       case SUPERV_Error :
1649        myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
1650        // PAL12866 -->
1651        aMess = QString(myMain->getDataflow()->Messages());
1652        if ( !aMess.isEmpty() ) {
1653          myMain->getMessage()->putMessage( tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess );
1654          QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), 
1655                               tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess);
1656        }
1657        // PAL12866 <--
1658        break;  
1659       case SUPERV_Kill:
1660        myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
1661        break;
1662       } // end of switch
1663
1664       // asv 03.02.05 : fix for PAL6859, not very good, but works..
1665       myMain->sync();
1666     } // end of if !myIsActive
1667 }
1668
1669 void SUPERVGUI_Thread::run()
1670 {
1671   myMain->startTimer();
1672   
1673   // GUI cycle to handle events coming for Engine
1674   while ( myIsActive ) {
1675     
1676     SUPERV_CNode aNode = NULL;
1677     SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1678     SUPERV::GraphState aState = SUPERV::UndefinedState ;
1679
1680     // blocking function of Engine.  Return from there only after anEvent happens on node aNode
1681     myMain->getDataflow()->Event(aNode, aEvent, aState);
1682
1683     ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
1684     
1685   } // end of while( myIsActive )
1686   
1687   QThread::exit();
1688 }
1689
1690 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1691 /*!
1692   Constructor
1693 */
1694 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1695      : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
1696 {
1697   Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1698   setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1699   setSizeGripEnabled( true );
1700   myGraph = theGraph;
1701
1702   QGridLayout* TopLayout = new QGridLayout( this );
1703   TopLayout->setSpacing( 6 );
1704   TopLayout->setMargin( 11 );
1705     
1706   QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1707   TopGroup->setColumnLayout(0, Qt::Vertical );
1708   TopGroup->layout()->setSpacing( 0 );
1709   TopGroup->layout()->setMargin( 0 );
1710   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1711   TopGroupLayout->setAlignment( Qt::AlignTop );
1712   TopGroupLayout->setSpacing( 6 );
1713   TopGroupLayout->setMargin( 11 );
1714
1715   // DeltaTime
1716   QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );  
1717   TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1718   
1719   myDeltaTime = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
1720   myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1721   TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1722
1723   // TimeOut
1724   QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup); 
1725   TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1726
1727   myTimeOut = new QLineEdit( TopGroup );
1728   myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1729   myTimeOut->setValidator( new QIntValidator(this) );
1730   myTimeOut->setMinimumSize( 100, 0 );
1731   myTimeOut->setReadOnly( isReadOnly );
1732   TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1733
1734   // DataStreamTrace
1735   QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup); 
1736   TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1737
1738   myDataStreamTrace = new QComboBox( TopGroup );
1739   myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1740   myDataStreamTrace->insertItem("WithoutTrace");
1741   myDataStreamTrace->insertItem("SummaryTrace");
1742   myDataStreamTrace->insertItem("DetailedTrace");
1743   TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1744
1745   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1746   GroupButtons->setColumnLayout(0, Qt::Vertical );
1747   GroupButtons->layout()->setSpacing( 0 );
1748   GroupButtons->layout()->setMargin( 0 );
1749   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1750   GroupButtonsLayout->setAlignment( Qt::AlignTop );
1751   GroupButtonsLayout->setSpacing( 6 );
1752   GroupButtonsLayout->setMargin( 11 );
1753   
1754   QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
1755   QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1756
1757   GroupButtonsLayout->addWidget( okB, 0, 0 );
1758   GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1759   GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1760
1761   TopLayout->addWidget( TopGroup,     0, 0 );
1762   TopLayout->addWidget( GroupButtons, 1, 0 );
1763
1764   connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
1765   connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1766
1767   setData();
1768 }
1769
1770 /*!
1771   Destructor
1772 */
1773 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1774   Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1775 }
1776
1777 /*!
1778   Sets data function
1779 */
1780 void SUPERVGUI_DSGraphParameters::setData() {
1781   CORBA::Double aDeltaTime;
1782   CORBA::Long aTimeOut;
1783   SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1784
1785 //  myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1786   if (myGraph->IsStreamGraph()) {
1787     SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1788     if (!SUPERV_isNull(aSGraph)) 
1789       aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1790   }
1791
1792   myDeltaTime->setValue(aDeltaTime);
1793   myTimeOut->setText(QString("%1").arg(aTimeOut));
1794   myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1795 }
1796
1797 /*!
1798   <OK> button slot
1799 */
1800 void SUPERVGUI_DSGraphParameters::accept() {
1801 //   myGraph->SetStreamParams( myTimeOut->text().toLong(),
1802 //                          (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1803 //                          myDeltaTime->value());
1804   if (myGraph->IsStreamGraph()) {
1805     SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1806     if (!SUPERV_isNull(aSGraph)) 
1807       aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1808                                 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1809                                 myDeltaTime->value());
1810   }
1811   QDialog::accept();
1812 }
1813