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