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