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