Salome HOME
4e4079ba9c29245c1e125bcf0d26b5bc4750192a
[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       SUPERVGUI_Main::setModifiedFlag();  
653     }
654   }
655 }
656
657 // mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
658 void SUPERVGUI_Main::syncPutInStudy()
659 {
660   if ( study ) {
661     if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
662       ViewManagerList aVMList;
663       app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
664       SUIT_ViewManager* aVM;
665       for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
666         QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
667         for ( int i = 0; i < aVWList.count(); i++ ) {
668           SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
669           QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
670           if ( aMainList->count() == 1 ) {
671             SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
672             if ( aMain )
673               if ( !CORBA::is_nil( aMain->getDataflow() )
674                    &&
675                    !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
676                    && 
677                    aMain != this ) { // not equal mains
678         
679                 // check "myInStudy" field of output ports of original main (i.e. this main)
680                 // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
681                 SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
682                 
683                 SYNCPUTINSTUDY(CNodes);
684                 SYNCPUTINSTUDY(FNodes);
685                 SYNCPUTINSTUDY(INodes);
686                 SYNCPUTINSTUDY(GNodes);
687                 SYNCPUTINSTUDY(LNodes);
688                 SYNCPUTINSTUDY(ELNodes);
689                 SYNCPUTINSTUDY(SNodes);
690                 SYNCPUTINSTUDY(ESNodes);
691                 SYNCPUTINSTUDY(Graphs);
692
693                 setRunTime( aMain->getRunTime() );
694
695                 break;
696               }
697           }
698         }
699       }
700     }
701   }
702 }
703
704 void SUPERVGUI_Main::run( const bool andSuspend ) {
705   Trace("SUPERVGUI_Main::run");
706   if ( SUPERV_isNull(dataflow) ) 
707     return;
708   
709   if ( dataflow->IsEditing() ) { // not currently Executing
710
711     // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
712     Editing(); // remove old executor, update GUI (all nodes to "No Status")
713
714     if ( !dataflow->IsValid() ) {
715       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
716     } 
717     else if (!dataflow->IsExecutable()) {
718       QString aMessage = QString(dataflow->Messages());
719       if ( aMessage.isEmpty() ) // mkr : IPAL11471
720         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
721       else
722         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
723     } 
724     else if (myCanvasView->isAnyLinkCreating()) {
725       QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
726     } 
727     else {
728       myRunTime = QDateTime::currentDateTime();
729       const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
730       if ( !result ) {
731         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
732         if ( dataflow->State() == SUPERV::ErrorState ) {
733           kill();
734         }
735       } 
736       else {
737         //myExecuted = true; // set to true on first execution. for correct publishing in Study
738         myThread->startThread(tr("MSG_GRAPH_STARTED"));
739       }
740     }
741   } 
742   else {
743     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
744   }
745 }
746
747
748 void SUPERVGUI_Main::kill() {
749   Trace("SUPERVGUI_Main::kill");
750   if ((SUPERV_isNull(dataflow))) 
751     return;
752
753   if (dataflow->IsEditing()) {
754     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
755   } 
756   else if (dataflow->Kill()) {
757     getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
758     sync();
759   } 
760   else {
761     QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
762   }
763 }
764
765 void SUPERVGUI_Main::suspendResume() {
766     Trace("SUPERVGUI_Main::suspendResume");
767
768     if ((SUPERV_isNull(dataflow))) return;
769
770     if (dataflow->IsEditing()) {
771         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
772     } else if (dataflow->State() == SUPERV_Suspend) {
773       if (dataflow->Resume()) {
774         myThread->startThread(tr("MSG_DF_RESUMED"));
775       } else {
776         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
777       }
778     } else {
779       if (dataflow->Suspend()) {
780         sync();
781         getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
782       } else {
783         QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
784       }
785     }
786 }
787 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
788    the comment from kloss below may be explaining it, but it's in French and I do not understand it..
789    It also calls deprecated method of Engine: ReStart(). 
790 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
791     Trace("SUPERVGUI_Main::stopRestart");
792     if ((SUPERV_isNull(dataflow))) return;
793
794     if (dataflow->IsEditing()) {
795         QMessageBox::warning(0, tr("ERROR"),  tr("MSG_DF_NOTRUNNING"));
796     } else if (dataflow->State() == SUPERV_Stop) {
797         if (dataflow->ReStart()) {
798             message->setMessage(tr("MSG_DF_RESTARTED"));
799             sync();
800         } else {
801             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
802         };
803     } else {
804         if (dataflow->Stop()) {
805             sync();
806         } else {
807             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
808         };
809     };
810 }
811 */
812 void SUPERVGUI_Main::addNode() {
813   Trace("SUPERVGUI_Main::addNode");
814   
815   if ( !ReadyToModify() ) // null dataflow or executing, ..
816     return;
817   
818   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
819   if ( !aSupMod ) {
820     MESSAGE("NULL Supervision module!");
821     return;
822   }
823
824   //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
825   aSupMod->getBrowser()->choose();
826 }
827
828 /**
829  * Add Computation node
830  */
831 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
832   switch (myCurrentView) {
833   case CANVASTABLE:
834     myArray->destroy();
835     myArray->create();
836     break;  
837   case CANVAS:
838   case CONTROLFLOW: 
839     {
840       SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode( resMgr(), myCanvas, this, theNode);
841       aNode->move(theNode->X(), theNode->Y());
842       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
843       aNode->show();
844       myCanvas->update();
845     }
846     break;
847   }
848 }
849
850 /**
851  * Add GOTO node
852  */
853 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
854   switch (myCurrentView) {
855   case CANVASTABLE:
856     myArray->destroy();
857     myArray->create();
858     break;
859   case CANVAS:
860   case CONTROLFLOW: 
861     {
862       SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode( resMgr(), myCanvas, this, theNode);
863       aNode->move(theNode->X(), theNode->Y());
864       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
865       aNode->show();
866       myCanvas->update();
867     }
868     break;
869   }
870 }
871
872 /**
873  * Add Control node
874  */
875 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
876   switch (myCurrentView) {
877   case CANVASTABLE:
878     myArray->destroy();
879     myArray->create();
880     break;
881   case CANVAS:
882   case CONTROLFLOW: 
883     {
884       SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode( resMgr(), myCanvas, this, theStartNode);
885       aStartNode->move(theStartNode->X(), theStartNode->Y());
886       if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
887
888       SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode( resMgr(), myCanvas, this, theEndNode, aStartNode);
889       aEndNode->move(theEndNode->X(), theEndNode->Y());
890       if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
891
892       aStartNode->show();
893       aEndNode->show();
894       myCanvas->update();
895     }
896     break;
897   }
898 }
899
900
901 /**
902  * Add Macro node
903  */
904 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
905   switch (myCurrentView) {
906   case CANVASTABLE:
907     myArray->destroy();
908     myArray->create();
909     break;
910   case CANVAS:
911   case CONTROLFLOW: 
912     {
913       SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode( resMgr(), myCanvas, this, theNode);
914       aNode->move(theNode->X(), theNode->Y());
915       if (myCurrentView == CONTROLFLOW) aNode->hideAll();
916       aNode->show();
917       myCanvas->update();
918     }
919     break;
920   }
921 }
922
923 SUPERVGUI_CanvasArray*  SUPERVGUI_Main::getCanvasArray() {
924   Trace("SUPERVGUI_Main::getCanvasArray");
925   return(myArray);
926 }
927
928 SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
929   Trace("SUPERVGUI_Main::getArrayView");
930   return(myArrayView);
931 }
932
933 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
934   Trace("SUPERVGUI_Main::getCanvas");
935   return(myCanvas);
936 }
937
938 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
939     Trace("SUPERVGUI_Main::getCanvasView");
940     return(myCanvasView);
941 }
942
943 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
944   Trace("SUPERVGUI_Main::getDataflow");
945   return(dataflow);
946 }
947
948 LogWindow* SUPERVGUI_Main::getMessage() {
949   Trace("SUPERVGUI_Main::getMessage");
950   return(message);
951 }
952
953 SUIT_Study* SUPERVGUI_Main::getStudy() {
954   Trace("SUPERVGUI_Main::getStudy");
955   return(study);
956 }
957
958 bool SUPERVGUI_Main::isArrayShown() {
959   Trace("SUPERVGUI_Main::isArrayShown");
960   return(myCurrentView == CANVASTABLE);  
961 }
962
963 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
964   Trace("SUPERVGUI_Main::showPopup");
965   // To check is Supervision active?
966   if (myIsLocked) return;
967   //if (dataflow->IsExecuting()) return;
968
969   CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
970   if ( !anApp->activeModule() ) return;
971   if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
972
973   if (e->button() == RightButton) {
974     p->exec(e->globalPos());
975   }
976 }
977
978 void SUPERVGUI_Main::changeInformation() {
979   SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
980   if (aDlg->exec() )
981     sync();
982   delete aDlg;
983 }
984
985 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
986     Trace("SUPERVGUI_Main::chooseData");
987     if (choosing) {
988       QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
989       if (!id.isEmpty()) {
990         _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
991         _PTR(GenericAttribute) anAttr;
992         if (object->FindAttribute(anAttr, "AttributeIOR")) {
993           _PTR(AttributeIOR) anIOR ( anAttr );
994           
995           // asv : 13.12.04 : commented out use of portIn field, but it seems that it 
996           // should be replaced with some analogious code... selection of IOR was done -
997           // put its value into port.
998           //portIn->setValue(ior);
999           
1000           SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1001           if ( !aSupMod ) {
1002             MESSAGE("NULL Supervision module!");
1003             return;
1004           }
1005
1006           // stop selection
1007           choosing = false;
1008           setCursor(aSupMod->getCursor());
1009           objectBrowser->setCursor(aSupMod->getCursor());
1010           aSupMod->putInfo("");
1011         }
1012       }
1013     }
1014 }
1015
1016 _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
1017                                         _PTR(StudyBuilder) const theBuilder,
1018                                         _PTR(SObject) const theSO,
1019                                         const char* theName,
1020                                         bool* theDoneSomething ) {
1021   _PTR(SObject) aResult;
1022   _PTR(AttributeName) aName;
1023   _PTR(GenericAttribute) anAttr;
1024   _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
1025   for (; anIterator->More(); anIterator->Next()) {
1026     if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1027       aName = _PTR(AttributeName) ( anAttr );
1028       if (strcmp(aName->Value().c_str(), theName) == 0) {
1029         aResult = anIterator->Value();
1030         break;
1031       }
1032     }
1033   }
1034
1035   // if aResule was found then theDoneSomething=false and we return
1036   *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
1037   if ( !*theDoneSomething )
1038     return aResult;
1039
1040   // add new SObject
1041   aResult = theBuilder->NewObject( theSO );
1042   anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1043   aName = _PTR(AttributeName) ( anAttr );
1044   aName->SetValue(theName);
1045   return aResult;
1046 }
1047     
1048 /**
1049  * Return true if dataflow is already in the study
1050  */
1051 bool SUPERVGUI_Main::isDataflowInStudy() const {
1052   _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1053   _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
1054   return ( aSO ? true : false );
1055 }
1056
1057 /**
1058  * Create a "Supervision" object in the Study and a "dataflow" object under it
1059  * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
1060  */
1061 _PTR(SObject) createDataflowSObj( SUIT_Study* study, 
1062                                   SUPERV::Graph_var dataflow, 
1063                                   _PTR(StudyBuilder) aBuilder,
1064                                   bool& aDoneSomething ) {
1065   _PTR(Study)            aStudy = (( SalomeApp_Study* )study)->studyDS();
1066   _PTR(GenericAttribute) anAttr;
1067   _PTR(AttributeName)    aName;
1068
1069   // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1070   _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
1071   if ( !aSO ) { // dataflow SObject not found in the study
1072     aDoneSomething = true; 
1073     _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1074     if ( !aComponent ) { // is supervision component not found, then create it
1075       aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1076       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1077       aName = _PTR(AttributeName) ( anAttr );
1078       aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
1079         
1080       anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1081       _PTR(AttributePixMap) aPixmap ( anAttr );
1082       aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1083
1084       SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1085       if ( aSupMod )
1086         aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
1087                                                     //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
1088       else MESSAGE("NULL Supervision module!");
1089       
1090     }
1091     // create dataflow SObject ("aNewDataflow_1") 
1092     aSO = aBuilder->NewObject(aComponent);
1093     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1094     aName = _PTR(AttributeName) ( anAttr );
1095     aName->SetValue(dataflow->Name());
1096     anAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1097     _PTR(AttributeIOR) anIORAttr ( anAttr );
1098     anIORAttr->SetValue(dataflow->getIOR());
1099   }
1100
1101   return aSO;
1102 }
1103
1104 void SUPERVGUI_Main::addDataflowToStudy() {
1105   bool isCreated;
1106   _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
1107   aBuilder->NewCommand();
1108   _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
1109   if ( aDF ) {
1110     aBuilder->CommitCommand();
1111     // what is this register/unregister?? don't know..
1112     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1113     if ( !aSupMod ) {
1114       MESSAGE("NULL Supervision module!");
1115       return;
1116     }
1117     aSupMod->unregisterGraph(this);
1118     aSupMod->registerGraph(dataflow->getIOR(), this);
1119
1120     if ( !myThread->running() )
1121       aSupMod->updateObjBrowser();
1122   }
1123   else {
1124     MESSAGE( "ERROR: failed to find or create dataflow SObject" );
1125     aBuilder->AbortCommand();
1126   }
1127 }
1128
1129 bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
1130   Trace("SUPERVGUI_Main::putDataStudy");
1131
1132   bool PublishOtherComponent = false;
1133
1134   // static variable to ensure that only one instance (thread) is executing this function 
1135   static bool isIn = false;
1136   if (isIn)   return true; 
1137   else        isIn = true;
1138
1139   _PTR(Study)        aStudy = (( SalomeApp_Study* )study)->studyDS();
1140   const bool         aLocked = aStudy->GetProperties()->IsLocked();
1141   _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
1142   bool                           aDoneSomething = false;
1143
1144   // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
1145   if ( aLocked ) {
1146     MESSAGE( "The study is locked and can not be modified!" );
1147     isIn = false;
1148     return false;
1149   }
1150
1151   // check if the port and its node are good
1152   if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
1153     MESSAGE( "putInStudy ERROR: port or node are NULL!" );
1154     isIn = false;
1155     return false;
1156   }
1157
1158   // open new command.  Commit or Abort it depending on aDoneSomething variable or error
1159   aBuilder->NewCommand();
1160   
1161   // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1162   _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
1163
1164   if ( !aSO ) {
1165     MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" ); 
1166     aBuilder->AbortCommand();
1167     isIn = false;
1168     return false;
1169   }
1170
1171   // Create "Run -> Time and date, etc." SObjects
1172   if  ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
1173
1174     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
1175     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
1176     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
1177     aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
1178
1179     // create IOR attribute for port SObject (usually with "return" name)
1180     _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
1181     _PTR(AttributeIOR) anIORAttr  ( anAttr );
1182
1183     // if we have not created anything (all SObject already existed) and we have the same IORAttribute
1184     // on the needed SObject -> then don't do anything! it's already there!
1185     if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
1186       aBuilder->AbortCommand();
1187       isIn = false;
1188       return true;
1189     }
1190
1191     aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
1192
1193     // set object value to the study: if object is external, then put it with
1194     //  help of the specific component - owner
1195     if ( p->IsIOR() ) {
1196       // get according component driver for result object
1197       SALOME_LifeCycleCORBA aLCC( myNService );
1198       SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
1199       if ( !aFNode->_is_nil() ) {
1200         Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
1201         SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
1202         if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
1203           CORBA::Object_ptr anObject = new CORBA::Object();
1204           CORBA::Any* anAny = p->ToAny();
1205           (*anAny) >>= anObject;
1206         
1207           if ( aDriver->CanPublishInStudy( anObject ) ) {
1208             SALOMEDS::SObject_var aTmpSO;// = aSO;
1209             SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
1210             if ( !aSStudy ) return false;
1211             try {
1212               aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
1213               aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
1214               PublishOtherComponent = true;
1215             }
1216             catch ( ... ) { // mkr : PAL8150
1217             }
1218           } 
1219           else { // can't publish object: abort transaction
1220             MESSAGE( "CanPublishInStudy() returned FALSE.  ok, AbortCommand.." );
1221             aBuilder->AbortCommand();
1222             isIn = false;
1223             return false;
1224           }
1225         }
1226         else { // component has no driver, but could store IORs (like Calculator)
1227           _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1228           if ( anIORSO ) {
1229             aBuilder->Addreference(aSO, anIORSO);
1230             // mkr : IPAL9672
1231             PublishOtherComponent = true;
1232           }
1233           else { // Hm... the object (==port value) was not found, so we don't publish it.
1234             MESSAGE( "The object (==port value) was not found, so we don't publish it" );
1235             aBuilder->AbortCommand();
1236             isIn = false;
1237             return false;
1238           }
1239         }
1240       }
1241       else { // FNode is NULL -> bad
1242         MESSAGE( "FNode is NULL." );
1243         if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
1244           _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1245           if ( anIORSO )
1246             aBuilder->Addreference(aSO, anIORSO);
1247         }
1248         else {
1249           MESSAGE( "FNode and INode are NULL.  Not good at all.  Aborting command." );
1250           aBuilder->AbortCommand();
1251           isIn = false;
1252           return false;
1253         }
1254       }
1255     } 
1256     else {
1257       anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
1258     }
1259   }
1260
1261   if ( aDoneSomething )
1262     aBuilder->CommitCommand();
1263   else
1264     aBuilder->AbortCommand();
1265
1266   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1267   if ( aSupMod ) {
1268     if ( PublishOtherComponent )
1269       dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
1270     else
1271       aSupMod->updateObjBrowser();
1272   }
1273   else MESSAGE("NULL Supervision module!");
1274
1275   SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
1276   if(app) app->updateActions();  
1277   isIn = false;
1278   return true;
1279 }
1280
1281
1282 void SUPERVGUI_Main::ActivatePanning()
1283 {
1284   if (myCanvasView->isVisible()) {
1285     myCanvasView->ActivatePanning();
1286   } else if (myArrayView->isVisible()) {
1287     myArrayView->ActivatePanning();
1288   }
1289 }
1290
1291
1292 void SUPERVGUI_Main::ResetView()
1293 {
1294   if (myCanvasView->isVisible()) {
1295     myCanvasView->ResetView();
1296   } else if (myArrayView->isVisible()) {
1297     myArrayView->ResetView();
1298   }
1299 }
1300
1301 void SUPERVGUI_Main::syncNotification() {
1302   char* graph;
1303   char* node;
1304   char* type;
1305   char* message;
1306   char* sender;
1307   long  counter;
1308   char* date;
1309   long  stamp;
1310
1311   while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1312     if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) { // mkr : PAL7037
1313       QString mess("");
1314       mess += "NOTIF: "; mess += graph;
1315       mess += " / "    ; mess += node;
1316       mess += " / "    ; mess += type;
1317       mess += " / "    ; mess += message;
1318       getMessage()->putMessage(mess.latin1());
1319     };
1320   };
1321 }
1322   
1323 bool SUPERVGUI_Main::isFiltered(char* graph,  char* node,   char* type, char* message, 
1324                                 char* sender, long counter, char* date, long stamp) {
1325   Trace("SUPERVGUI_Main::isFiltered");
1326   bool b = false;
1327   if (strcmp(getDataflow()->Name(), graph) == 0) {
1328     SUPERVGUI_CanvasNode* n;
1329     QObjectList* nodes;
1330     // mkr : PAL7037 -->
1331     if (myCurrentView == CANVASTABLE)
1332       nodes = myArray->queryList("SUPERVGUI_CanvasNode");
1333     else
1334       nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
1335     // mkr : PAL7037 <--
1336     QObjectListIt i(*nodes);
1337     while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
1338       ++i;
1339       if (strcmp(n->name(), node) == 0) {
1340         if (strcmp(type, NOTIF_WARNING) == 0) {
1341           b = n->isWarning();
1342         } else if (strcmp(type, NOTIF_STEP) == 0) {
1343           b = n->isStep();
1344         } else if (strcmp(type, NOTIF_TRACE) == 0) {
1345           b = n->isTrace();
1346         } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1347           b = n->isVerbose();
1348         };
1349         break;
1350       };
1351     };
1352     delete nodes;
1353     if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1354       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 );
1355       fflush( myLogFile );
1356     };
1357   };
1358   return( b );
1359 }
1360
1361 void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
1362   e->accept();
1363 }
1364
1365
1366 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) { 
1367
1368   myCanvas->setBackgroundColor(color);
1369   myCanvasView->setPaletteBackgroundColor(color.light());
1370   myArray->setBackgroundColor(color);
1371   myArrayView->setPaletteBackgroundColor(color.light());
1372   
1373   SUPERVGraph_View::setPaletteBackgroundColor(color); 
1374 }
1375
1376 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1377   return myEventNodes;
1378 }
1379
1380 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1381   myEventNodes = theEventNodes;
1382 }
1383
1384 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1385   return myStates;
1386 }
1387
1388 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1389   myStates = theStates;
1390 }
1391
1392 int SUPERVGUI_Main::getNodesNumber() {
1393   //create a list of nodes of the graph
1394   SUPERV_Nodes nodes = getDataflow()->Nodes();
1395   int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1396                nodes->INodes.length() + nodes->GNodes.length() +
1397                nodes->LNodes.length() + nodes->SNodes.length();
1398   return RetVal;
1399 }
1400
1401 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1402   return myThread;
1403 }
1404
1405 void SUPERVGUI_Main::startTimer() {
1406   myTimer->start(500);
1407 }
1408
1409 void SUPERVGUI_Main::executionFinished() {
1410   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1411   if ( aSupMod ) 
1412     //aSupMod->updateObjBrowser();
1413     // PAL10611: update all modules data
1414     aSupMod->getApp()->updateObjectBrowser(true);
1415   else MESSAGE("NULL Supervision module!");
1416   
1417   myCanvas->update();
1418   myArray->update();
1419 }
1420
1421 void SUPERVGUI_Main::checkExecution() {
1422   if (myThread->finished()) {
1423     myTimer->stop();
1424     executionFinished();
1425   }
1426 }
1427
1428 /**
1429  * Editing() is to be called by any operation in GUI before modification of a datamodel
1430  * (add/remove ports or nodes, etc.).  It is used to resolve inconsistancies between 2 data models
1431  * in Engine: Editor and Executor.  During and after execution, the values of ports and statuses of nodes
1432  * are taken from Executor data model.  But when user starts editing the graph - these changes must
1433  * be applied to Editor data model.  This function destroys Executor data model and moves to Editor.   
1434  */ 
1435 void SUPERVGUI_Main::Editing() {
1436   if ( !SUPERV_isNull( dataflow ) )
1437     dataflow->Editing();
1438   
1439   // updata GUI, Nodes' statuses and Ports' values could change.
1440   sync();
1441 }
1442
1443 void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
1444 {
1445   // mkr: since the deletion of the node allow only in CANVAS view,
1446   // it is necessary to remove the CanvasArray's children, which
1447   // have the same CNode engine as deleting node. This CNode is given
1448   // as argument
1449   if (myArray) {
1450     const QObjectList* aChList = myArray->children();
1451     if ( aChList ) { // asv 27.01.05 : fix for 7817
1452       QObjectListIt aItChList(*aChList);
1453       SUPERVGUI_CanvasNode* anObjNode;
1454       while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
1455         ++aItChList;
1456         if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
1457           myArray->removeChild(anObjNode);
1458           delete anObjNode;
1459         }
1460       }
1461     } // end of if ( ChList )
1462   }
1463 }
1464
1465 /**
1466  * ReadyToModify() must be called before any modification
1467  * operation - asks to kill execution of dataflow.  If returns false - 
1468  * modification (==Editing() ) is not allowed.
1469  */
1470 bool SUPERVGUI_Main::ReadyToModify() {
1471   if ( CORBA::is_nil( dataflow ) )
1472     return false;
1473   if ( dataflow->IsExecuting() ) {
1474     bool quit = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 0=Yes, 1=No
1475       tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
1476     if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
1477       return false;
1478     else  if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
1479       kill();   // checking again for IsExecuting to be sure that it was not finished while MB was up
1480   }
1481   return true;
1482 }
1483
1484 void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
1485 {
1486   if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
1487     if ( getCanvas()->width() < theEvent->size().width()
1488          ||
1489          getCanvas()->height() < theEvent->size().height() )
1490       getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
1491   if ( myCurrentView == CANVASTABLE && getCanvasArray() )
1492     if ( getCanvasArray()->width() < theEvent->size().width()
1493          ||
1494          getCanvasArray()->height() < theEvent->size().height() )
1495       getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
1496 }
1497
1498 /*!
1499   Sets a modified flag in an active study
1500  */
1501 void SUPERVGUI_Main::setModifiedFlag()
1502 {
1503   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1504   if(app) {
1505     SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1506     if(study) {
1507       _PTR(Study) studyDS = study->studyDS();
1508       _PTR(SComponent) sco = studyDS->FindComponent(STUDY_SUPERVISION);
1509       if(sco) {
1510         _PTR(StudyBuilder) builder = studyDS->NewBuilder();
1511         _PTR(GenericAttribute) ga;
1512         ga = builder->FindOrCreateAttribute(sco, "AttributeParameter");
1513         _PTR(AttributeParameter) ap(ga);
1514         if(ap) {
1515           ap->SetBool("SUPERVISOR_MODIFIED_FLAG",1);
1516           app->updateActions();
1517         }
1518       }
1519     }
1520   }
1521 }
1522
1523
1524 /******************************* SUPERVGUI_Thread class ****************************************/
1525 SUPERVGUI_Thread::SUPERVGUI_Thread()
1526      :QThread()
1527 {
1528   myIsActive = false;
1529 }
1530
1531 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1532 {
1533   //it is a virtual destructor and needs to be determine here
1534 }
1535
1536 void SUPERVGUI_Thread::startThread(const char* m)
1537 {
1538   if (!myIsActive) {
1539     myIsActive = true;
1540     
1541     myMain->getMessage()->putMessage(m); 
1542     myMain->sync();
1543
1544     start();
1545   }
1546 }
1547
1548 void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
1549 {
1550   myMain = theMain;
1551 }
1552
1553 void SUPERVGUI_Thread::KillThread( bool theValue )
1554 {
1555   myMutex.lock();
1556   myIsActive = !(theValue);
1557   myMutex.unlock();
1558 }
1559
1560 template<class TObject, typename TArg, typename TArg1, typename TArg2,
1561          typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
1562 class TVoidMemFun3ArgEvent: public SALOME_Event{
1563 public:
1564   typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
1565   TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
1566     myObject(theObject),
1567     myAction(theAction),
1568     myArg(theArg),
1569     myArg1(theArg1),
1570     myArg2(theArg2)
1571   {}
1572   virtual void Execute(){
1573     (myObject->*myAction)(myArg,myArg1,myArg2);
1574   }
1575 private:
1576   TObject* myObject;
1577   TAction myAction;
1578   TStoreArg myArg;
1579   TStoreArg1 myArg1;
1580   TStoreArg2 myArg2;
1581 };
1582
1583 typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
1584
1585 /**
1586  * main_thread_run must be executed in the qt main thread
1587  * It is activated by calling ProcessVoidEvent
1588  */
1589 void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
1590 {
1591     // in case node "said" something during changing state through notification mechanism - output it
1592     myMain->syncNotification();
1593     
1594     // "kill" or undefined event came
1595     if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
1596        ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
1597        ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
1598
1599       myIsActive = false;
1600     }
1601     else { // a "normal" execution event came
1602       char* aName = NULL;
1603       if ( aNode != NULL && !CORBA::is_nil( aNode ) ) 
1604        aName = aNode->Name();      
1605
1606       // What follow is not quite sure. The entire function is posted to the main qt thread.
1607       // So all executions are serialized. Is it really possible to call execute when another
1608       // execute is running. I don't think so (C Caremoli)
1609       // this function is asynchronious.  The call does NOT wait when SUPERVGUI_Main::execute finishes
1610       // handling the event.  So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
1611       // on the next loop iteration, BEFORE  previous SUPERVGUI_Main::execute finished.
1612       myMain->execute(aName, aState );
1613     }    
1614
1615     // execution is finished.  just set a "finished" message(s)
1616     if ( !myIsActive ) {
1617       switch ( myMain->getDataflow()->State() ) {
1618       case SUPERV_Editing :     
1619        myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()? 
1620                                         tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
1621        break;  
1622       case SUPERV_Suspend : 
1623        myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
1624        break; 
1625       case SUPERV_Done : 
1626        myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
1627        break;  
1628       case SUPERV_Error :
1629        myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
1630        break;  
1631       case SUPERV_Kill:
1632        myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
1633        break;
1634       } // end of switch
1635
1636       // asv 03.02.05 : fix for PAL6859, not very good, but works..
1637       myMain->sync();
1638     } // end of if !myIsActive
1639 }
1640
1641 void SUPERVGUI_Thread::run()
1642 {
1643   myMain->startTimer();
1644   
1645   // GUI cycle to handle events coming for Engine
1646   while ( myIsActive ) {
1647     
1648     SUPERV_CNode aNode = NULL;
1649     SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1650     SUPERV::GraphState aState = SUPERV::UndefinedState ;
1651
1652     // blocking function of Engine.  Return from there only after anEvent happens on node aNode
1653     myMain->getDataflow()->Event(aNode, aEvent, aState);
1654
1655     ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
1656     
1657   } // end of while( myIsActive )
1658   
1659   QThread::exit();
1660 }
1661
1662 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1663 /*!
1664   Constructor
1665 */
1666 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1667      : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ) 
1668 {
1669   Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1670   setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1671   setSizeGripEnabled( true );
1672   myGraph = theGraph;
1673
1674   QGridLayout* TopLayout = new QGridLayout( this );
1675   TopLayout->setSpacing( 6 );
1676   TopLayout->setMargin( 11 );
1677     
1678   QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1679   TopGroup->setColumnLayout(0, Qt::Vertical );
1680   TopGroup->layout()->setSpacing( 0 );
1681   TopGroup->layout()->setMargin( 0 );
1682   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1683   TopGroupLayout->setAlignment( Qt::AlignTop );
1684   TopGroupLayout->setSpacing( 6 );
1685   TopGroupLayout->setMargin( 11 );
1686
1687   // DeltaTime
1688   QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );  
1689   TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1690   
1691   myDeltaTime = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
1692   myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1693   TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1694
1695   // TimeOut
1696   QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup); 
1697   TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1698
1699   myTimeOut = new QLineEdit( TopGroup );
1700   myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1701   myTimeOut->setValidator( new QIntValidator(this) );
1702   myTimeOut->setMinimumSize( 100, 0 );
1703   myTimeOut->setReadOnly( isReadOnly );
1704   TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1705
1706   // DataStreamTrace
1707   QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup); 
1708   TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1709
1710   myDataStreamTrace = new QComboBox( TopGroup );
1711   myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1712   myDataStreamTrace->insertItem("WithoutTrace");
1713   myDataStreamTrace->insertItem("SummaryTrace");
1714   myDataStreamTrace->insertItem("DetailedTrace");
1715   TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1716
1717   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1718   GroupButtons->setColumnLayout(0, Qt::Vertical );
1719   GroupButtons->layout()->setSpacing( 0 );
1720   GroupButtons->layout()->setMargin( 0 );
1721   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1722   GroupButtonsLayout->setAlignment( Qt::AlignTop );
1723   GroupButtonsLayout->setSpacing( 6 );
1724   GroupButtonsLayout->setMargin( 11 );
1725   
1726   QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
1727   QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1728
1729   GroupButtonsLayout->addWidget( okB, 0, 0 );
1730   GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1731   GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1732
1733   TopLayout->addWidget( TopGroup,     0, 0 );
1734   TopLayout->addWidget( GroupButtons, 1, 0 );
1735
1736   connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
1737   connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1738
1739   setData();
1740 }
1741
1742 /*!
1743   Destructor
1744 */
1745 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1746   Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1747 }
1748
1749 /*!
1750   Sets data function
1751 */
1752 void SUPERVGUI_DSGraphParameters::setData() {
1753   CORBA::Double aDeltaTime;
1754   CORBA::Long aTimeOut;
1755   SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1756
1757 //  myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1758   if (myGraph->IsStreamGraph()) {
1759     SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1760     if (!SUPERV_isNull(aSGraph)) 
1761       aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1762   }
1763
1764   myDeltaTime->setValue(aDeltaTime);
1765   myTimeOut->setText(QString("%1").arg(aTimeOut));
1766   myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1767 }
1768
1769 /*!
1770   <OK> button slot
1771 */
1772 void SUPERVGUI_DSGraphParameters::accept() {
1773 //   myGraph->SetStreamParams( myTimeOut->text().toLong(),
1774 //                          (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1775 //                          myDeltaTime->value());
1776   if (myGraph->IsStreamGraph()) {
1777     SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1778     if (!SUPERV_isNull(aSGraph)) 
1779       aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1780                                 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1781                                 myDeltaTime->value());
1782   }
1783   QDialog::accept();
1784 }
1785