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