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