1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SUPERVGUI_Main.cxx
25 // Author : Francis KLOSS
28 #include "SALOMEDSClient.hxx"
29 #include "SALOMEDS_Study.hxx"
30 #include "SALOMEDS_SObject.hxx"
32 #include "NOTIFICATION.hxx"
33 #include "SALOME_Event.hxx"
34 #include "SUPERVGraph_ViewFrame.h"
35 #include "SUPERVGraph_ViewModel.h"
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"
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"
58 #include <qvalidator.h>
62 #include <qlineedit.h>
63 #include <qcombobox.h>
65 #include <boost/shared_ptr.hpp>
66 using namespace boost;
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())->GetOutPort(aPort->Name()) ) )->setStudyState(aInStudy); \
82 SUPERVGUI_Main::SUPERVGUI_Main( SUPERVGraph_ViewFrame* theParent,
83 SUIT_Desktop* theDesktop, SUPERV_Graph theDataFlow )
84 : SUPERVGraph_View(theParent),
87 myLogFileName( QString::null ),
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"));
106 syncPutInStudy(); // mkr : PAL8150
109 connect(this, SIGNAL(EventToSync()), this, SLOT(onObjectCreatedDeleted()));
112 void SUPERVGUI_Main::init(SUIT_Desktop* theDesktop) {
113 Trace("SUPERVGUI_Main::init");
114 SUIT_Application* anActApp = SUIT_Session::session()->activeApplication();
117 myNService = dynamic_cast<SalomeApp_Application*>( anActApp )->namingService();
123 myThread = new SUPERVGUI_Thread();
124 myThread->setMain(this);
126 myCurrentView = CANVAS;
127 myIsFromStudy = false;
129 study = anActApp->activeStudy();
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);
138 SUIT_Operation* op = new SalomeApp_ImportOperation( study->application() );
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() );
146 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
147 _PTR(AttributePixMap) aPixmap ( anAttr );
148 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
150 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
152 MESSAGE("NULL Supervision module!");
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);
163 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
165 objectBrowser = app->objectBrowser();
167 myArray = new SUPERVGUI_CanvasArray( this, resMgr() );
168 myArrayView = new SUPERVGUI_ArrayView( myArray, this );
170 myCanvas = new SUPERVGUI_Canvas( this, resMgr() );
171 myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
173 message = app->logWindow();
174 notification = new NOTIFICATION_Consumer();
176 QBoxLayout * layout = new QVBoxLayout(this);
177 layout->setMargin(0);
178 layout->setSpacing(0);
179 layout->addWidget(myCanvasView);
180 layout->addWidget(myArrayView);
182 if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
188 if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
189 myLogFile = fopen( myLogFileName.latin1(), "a" );
190 if ( myLogFile == NULL )
193 myTimer = new QTimer( this );
194 connect( myTimer, SIGNAL(timeout()), this, SLOT(checkExecution()) );
197 SUPERVGUI_Main::~SUPERVGUI_Main() {
198 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
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();
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
218 mySubGraphMap.clear();
220 QAD_StudyFrame* aSubGraph;
221 for (aSubGraph = mySubGraphs.first(); aSubGraph; aSubGraph = mySubGraphs.next()) {
222 aSubGraph->removeEventFilter(this);
227 if ( myLogFile != NULL) {
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
238 SUIT_ResourceMgr* SUPERVGUI_Main::resMgr() const
240 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( study->application() );
241 return app ? app->resourceMgr() : 0;
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();
262 if ( myLogFile != NULL) {
266 if ( myLogged && !myLogFileName.isEmpty() /*&& QFile::exists( myLogFileName )*/ ) { // mkr : PAL7037
267 myLogFile = fopen( myLogFileName.latin1(), "a" );
268 if ( myLogFile == NULL ) {
270 QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
276 void SUPERVGUI_Main::changeDSGraphParameters() {
277 SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
283 void SUPERVGUI_Main::syncAsync() {
284 Trace("SUPERVGUI_Main::syncAsync");
285 QTimer::singleShot(1, this, SLOT(sync()));
290 * Called by thread when dataflow is executing
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");
297 emit EventToSync(); // mkr : IPAL11362
300 else if (myCurrentView == CANVASTABLE) {
301 SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode");
304 emit EventToSync(); // mkr : IPAL11362
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");
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) {
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 );
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" );
333 void SUPERVGUI_Main::sync() {
334 Trace("SUPERVGUI_Main::sync");
335 if ((SUPERV_isNull(dataflow)))
337 QString t = tr("GRAPH_TITLE");
339 t += dataflow->Name();
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!");
353 // update "Save" icon and menu state, if dataflow is published
354 _PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
355 _PTR(SObject) aSO = aStudy->FindObjectIOR(dataflow->getIOR());
356 if (aSO) SUPERVGUI_Main::setModifiedFlag();
358 if (myCurrentView == CANVASTABLE) {
367 void SUPERVGUI_Main::showCanvasTable() {
368 if (myCurrentView == CANVASTABLE)
371 if (myArray->create()) {
372 myCanvasView->hide();
374 myCurrentView = CANVASTABLE;
379 void SUPERVGUI_Main::showContolFlow() {
381 if (myCurrentView == CANVASTABLE) {
386 myCurrentView = CONTROLFLOW;
387 myCanvas->setControlView();
390 myCanvasView->show();
394 void SUPERVGUI_Main::showCanvas() {
395 if (myCurrentView == CANVAS)
399 if (myCurrentView == CANVASTABLE) {
404 myCurrentView = CANVAS;
405 myCanvas->setFullView();
408 myCanvasView->show();
412 void SUPERVGUI_Main::insertFile() {
413 Trace("SUPERVGUI_Main::insertFile");
415 if ( !ReadyToModify() ) // null dataflow or executing, ..
418 QString f = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
421 tr("MSG_GRAPH_INSERT"),
423 if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name
425 Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960
427 if (dataflow->Import(f.latin1())) {
428 if (myCurrentView == CANVASTABLE) {
432 else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
437 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
442 void SUPERVGUI_Main::copy() {
443 Trace("SUPERVGUI_Main::copy");
444 if (dataflow->ThreadsMax() == 0) {
445 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
449 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
451 MESSAGE("NULL Supervision module!");
455 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aSupMod->createGraph() );
457 SUPERV_Graph aNewGraph; // = dataflow->StreamCopy();
458 if ( dataflow->IsStreamGraph() ) {
459 SUPERV_StreamGraph aSGraph = dataflow->ToStreamGraph();
460 if ( SUPERV_isNull(aSGraph) ) {
461 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
464 aNewGraph = aSGraph->StreamCopy();
467 aNewGraph = dataflow->Copy();
469 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
470 aNewName += dataflow->Name();
471 aNewGraph->SetName(aNewName);
472 /*SUPERVGUI_Main* m = */new SUPERVGUI_Main(aViewFrame,
473 aSupMod->application()->desktop(),//getDesktop(),
479 void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
481 if (theNode->IsMacro()) {
482 // get SubGraph from MacroNode
483 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(theNode);
485 if (aMacro->IsStreamMacro())
486 aGraph = aMacro->StreamObjRef();
488 aGraph = aMacro->FlowObjRef();
491 if (SUPERV_isNull(aGraph)) {
492 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOACCESS"));
496 QString aGraphName = aGraph->Name();
497 SUIT_ViewWindow* aStudyFrame;
498 if (mySubGraphs.contains(aGraphName)) {
499 aStudyFrame = mySubGraphs[aGraphName];
500 aStudyFrame->setActiveWindow();
501 aStudyFrame->setFocus();
504 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
506 MESSAGE("NULL Supervision module!");
510 aStudyFrame = aSupMod->createGraph();
512 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aStudyFrame );
514 new SUPERVGUI_Main(aViewFrame,
515 aSupMod->application()->desktop(),//getDesktop(),
517 // connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)),
518 // this, SLOT(onSubGraphClosed(QAD_StudyFrame*)));
519 connect(aSupMod->application()->desktop(), SIGNAL(windowActivated( SUIT_ViewWindow* )),
520 this, SLOT(onSubGraphActivated( SUIT_ViewWindow* )));
521 aStudyFrame->installEventFilter(this);
523 mySubGraphs.insert(aGraphName, aStudyFrame);
524 mySubGraphMap.insert(aGraphName, theNode->Name());
530 if (!correct) myLastGraph = aStudyFrame;
536 void SUPERVGUI_Main::destroySubGraph(QString theSubGraphName)
538 if ( mySubGraphs.contains(theSubGraphName) ) {
539 SUIT_ViewWindow* aStudyFrame = mySubGraphs[theSubGraphName];
540 onSubGraphClosed(aStudyFrame);
541 SUIT_ViewManager* aVM = aStudyFrame->getViewManager();
542 STD_Application* anApp = dynamic_cast<STD_Application*>( SUIT_Session::session()->activeApplication() );
543 if ( anApp ) anApp->removeViewManager(aVM);
547 bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
549 // workaround to get close event
550 if (o->inherits("SUIT_ViewWindow"/*"QAD_StudyFrame"*/) && e->type() == QEvent::Close) {
551 SUIT_ViewWindow* aFrame = (SUIT_ViewWindow*) o;
552 onSubGraphClosed(aFrame);
554 return SUPERVGraph_View::eventFilter(o, e);
557 // workaround to fix PAL6255 -> opened SubGraph is not on top
558 void SUPERVGUI_Main::onSubGraphActivated(SUIT_ViewWindow* theStudyFrame)
561 SUIT_ViewWindow* aFrame = myLastGraph;
563 aFrame->setActiveWindow();
568 void SUPERVGUI_Main::onSubGraphClosed(SUIT_ViewWindow* theStudyFrame)
570 if ( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( theStudyFrame ) ) {
571 theStudyFrame->removeEventFilter(this);
572 disconnect(theStudyFrame, 0, this, 0);
574 SUPERVGraph_View* view = supervFrame->getViewWidget();
575 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
577 QString aGraphName = aGraph->getDataflow()->Name();
578 QMap<QString, QString>::iterator it = mySubGraphMap.find(aGraphName);
579 if (it != mySubGraphMap.end()) {
580 QString aNodeName = it.data();
581 SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)
582 myCanvas->child(aNodeName, "SUPERVGUI_CanvasNode");
587 mySubGraphMap.remove(it);
589 mySubGraphs.remove(aGraphName);
594 void SUPERVGUI_Main::onShowToolbar()
596 SUPERVGraph_ViewFrame* aVF = (SUPERVGraph_ViewFrame*)this->parent();
598 aVF->getToolBar()->show();
601 // mkr : PAL8237 : synchronize many views of the same dataflow (objects creation/deletion)
602 void SUPERVGUI_Main::onObjectCreatedDeleted()
605 if ( LightApp_Application* app = dynamic_cast<LightApp_Application*>( study->application() ) ) {
606 ViewManagerList aVMList;
607 app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
608 SUIT_ViewManager* aVM;
609 for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
610 QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
611 for ( int i = 0; i < aVWList.count(); i++ ) {
612 SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
613 QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
614 if ( aMainList->count() == 1 ) {
615 SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
618 !CORBA::is_nil(aMain->getDataflow()) &&
619 !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR())) // equal dataflows
620 aMain->getCanvas()->merge();
626 // update "Save" icon and menu state, if dataflow is published
627 //_PTR(Study) aStudy = ((SalomeApp_Study*)study)->studyDS();
628 //_PTR(SObject) aSO = aStudy->FindObjectIOR(dataflow->getIOR());
629 //if (aSO) SUPERVGUI_Main::setModifiedFlag();
634 // mkr : PAL8150 : synchronize many views of the same dataflow ("Put In Study"/"Not In Study" operation)
635 void SUPERVGUI_Main::onPutInStudy( QString* theNodePortName )
638 if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
639 ViewManagerList aVMList;
640 app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
641 SUIT_ViewManager* aVM;
642 for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
643 QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
644 for ( int i = 0; i < aVWList.count(); i++ ) {
645 SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
646 QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
647 if ( aMainList->count() == 1 ) {
648 SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
650 if ( !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
652 aMain != this ) { // not equal mains
653 QString aNodeName = theNodePortName->left( theNodePortName->find('_') );
654 QString aPortName = theNodePortName->right( theNodePortName->length() - theNodePortName->find('_') - 1 );
655 bool anIsInStudy = dynamic_cast<SUPERVGUI_CanvasPortOut*>( getCanvas()->getPort( getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->isInStudy();
656 dynamic_cast<SUPERVGUI_CanvasPortOut*>( aMain->getCanvas()->getPort( aMain->getDataflow()->Node( aNodeName )->GetOutPort( aPortName ) ) )->setStudyState( anIsInStudy );
661 //SUPERVGUI_Main::setModifiedFlag();
666 // mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
667 void SUPERVGUI_Main::syncPutInStudy()
670 if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
671 ViewManagerList aVMList;
672 app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
673 SUIT_ViewManager* aVM;
674 for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
675 QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
676 for ( int i = 0; i < aVWList.count(); i++ ) {
677 SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
678 QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
679 if ( aMainList->count() == 1 ) {
680 SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
682 if ( !CORBA::is_nil( aMain->getDataflow() )
684 !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
686 aMain != this ) { // not equal mains
688 // check "myInStudy" field of output ports of original main (i.e. this main)
689 // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
690 SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
692 SYNCPUTINSTUDY(CNodes);
693 SYNCPUTINSTUDY(FNodes);
694 SYNCPUTINSTUDY(INodes);
695 SYNCPUTINSTUDY(GNodes);
696 SYNCPUTINSTUDY(LNodes);
697 SYNCPUTINSTUDY(ELNodes);
698 SYNCPUTINSTUDY(SNodes);
699 SYNCPUTINSTUDY(ESNodes);
700 SYNCPUTINSTUDY(Graphs);
702 setRunTime( aMain->getRunTime() );
713 void SUPERVGUI_Main::run( const bool andSuspend ) {
714 Trace("SUPERVGUI_Main::run");
715 if ( SUPERV_isNull(dataflow) )
718 if ( dataflow->IsEditing() ) { // not currently Executing
720 // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
721 Editing(); // remove old executor, update GUI (all nodes to "No Status")
723 if ( !dataflow->IsValid() ) {
724 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
726 else if (!dataflow->IsExecutable()) {
727 QString aMessage = QString(dataflow->Messages());
728 if ( aMessage.isEmpty() ) // mkr : IPAL11471
729 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
731 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
733 else if (myCanvasView->isAnyLinkCreating()) {
734 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
737 myRunTime = QDateTime::currentDateTime();
738 const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
741 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE") + QString(" : ") + QString(dataflow->Messages()));
742 if ( dataflow->State() == SUPERV::ErrorState ) {
744 if ( !dataflow->IsEditing() ) kill();
748 //myExecuted = true; // set to true on first execution. for correct publishing in Study
749 myThread->startThread(tr("MSG_GRAPH_STARTED"));
754 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
759 void SUPERVGUI_Main::kill() {
760 Trace("SUPERVGUI_Main::kill");
761 if ((SUPERV_isNull(dataflow)))
764 if (dataflow->IsEditing()) {
765 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
767 else if (dataflow->Kill()) {
768 // IPAL9273, 9369, 9731 : to avoid two equal messages about killing dataflow
769 // execution in the Message Console
770 //getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
774 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
778 void SUPERVGUI_Main::suspendResume() {
779 Trace("SUPERVGUI_Main::suspendResume");
781 if ((SUPERV_isNull(dataflow))) return;
783 if (dataflow->IsEditing()) {
784 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
785 } else if (dataflow->State() == SUPERV_Suspend) {
786 if (dataflow->Resume()) {
787 myThread->startThread(tr("MSG_DF_RESUMED"));
789 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
792 if (dataflow->Suspend()) {
794 getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
796 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
800 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
801 the comment from kloss below may be explaining it, but it's in French and I do not understand it..
802 It also calls deprecated method of Engine: ReStart().
803 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
804 Trace("SUPERVGUI_Main::stopRestart");
805 if ((SUPERV_isNull(dataflow))) return;
807 if (dataflow->IsEditing()) {
808 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
809 } else if (dataflow->State() == SUPERV_Stop) {
810 if (dataflow->ReStart()) {
811 message->setMessage(tr("MSG_DF_RESTARTED"));
814 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
817 if (dataflow->Stop()) {
820 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
825 void SUPERVGUI_Main::addNode() {
826 Trace("SUPERVGUI_Main::addNode");
828 if ( !ReadyToModify() ) // null dataflow or executing, ..
831 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
833 MESSAGE("NULL Supervision module!");
837 //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
838 aSupMod->getBrowser()->choose();
842 * Add Computation node
844 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
845 switch (myCurrentView) {
853 SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasComputeNode::Create(resMgr(), myCanvas, this, theNode);
854 aNode->move(theNode->X(), theNode->Y());
855 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
866 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
867 switch (myCurrentView) {
875 SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasGotoNode::Create(resMgr(), myCanvas, this, theNode);
876 aNode->move(theNode->X(), theNode->Y());
877 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
888 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update)
890 switch (myCurrentView) {
898 SUPERVGUI_CanvasStartNode* aStartNode =
899 SUPERVGUI_CanvasStartNode::Create(resMgr(), myCanvas, this, theStartNode);
900 aStartNode->move(theStartNode->X(), theStartNode->Y());
901 if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
903 SUPERVGUI_CanvasEndNode* aEndNode =
904 SUPERVGUI_CanvasEndNode::Create(resMgr(), myCanvas, this, theEndNode, aStartNode);
905 aEndNode->move(theEndNode->X(), theEndNode->Y());
906 if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
920 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
921 switch (myCurrentView) {
929 SUPERVGUI_CanvasNode* aNode = SUPERVGUI_CanvasMacroNode::Create(resMgr(), myCanvas, this, theNode);
930 aNode->move(theNode->X(), theNode->Y());
931 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
939 SUPERVGUI_CanvasArray* SUPERVGUI_Main::getCanvasArray() {
940 Trace("SUPERVGUI_Main::getCanvasArray");
944 SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
945 Trace("SUPERVGUI_Main::getArrayView");
949 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
950 Trace("SUPERVGUI_Main::getCanvas");
954 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
955 Trace("SUPERVGUI_Main::getCanvasView");
956 return(myCanvasView);
959 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
960 Trace("SUPERVGUI_Main::getDataflow");
964 LogWindow* SUPERVGUI_Main::getMessage() {
965 Trace("SUPERVGUI_Main::getMessage");
969 SUIT_Study* SUPERVGUI_Main::getStudy() {
970 Trace("SUPERVGUI_Main::getStudy");
974 bool SUPERVGUI_Main::isArrayShown() {
975 Trace("SUPERVGUI_Main::isArrayShown");
976 return(myCurrentView == CANVASTABLE);
979 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
980 Trace("SUPERVGUI_Main::showPopup");
981 // To check is Supervision active?
982 if (myIsLocked) return;
983 //if (dataflow->IsExecuting()) return;
985 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
986 if ( !anApp->activeModule() ) return;
987 if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
989 if (e->button() == RightButton) {
990 p->exec(e->globalPos());
994 void SUPERVGUI_Main::changeInformation() {
995 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
1001 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
1002 Trace("SUPERVGUI_Main::chooseData");
1004 QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
1005 if (!id.isEmpty()) {
1006 _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
1007 _PTR(GenericAttribute) anAttr;
1008 if (object->FindAttribute(anAttr, "AttributeIOR")) {
1009 _PTR(AttributeIOR) anIOR ( anAttr );
1011 // asv : 13.12.04 : commented out use of portIn field, but it seems that it
1012 // should be replaced with some analogious code... selection of IOR was done -
1013 // put its value into port.
1014 //portIn->setValue(ior);
1016 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1018 MESSAGE("NULL Supervision module!");
1024 setCursor(aSupMod->getCursor());
1025 objectBrowser->setCursor(aSupMod->getCursor());
1026 aSupMod->putInfo("");
1032 _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
1033 _PTR(StudyBuilder) const theBuilder,
1034 _PTR(SObject) const theSO,
1035 const char* theName,
1036 bool* theDoneSomething ) {
1037 _PTR(SObject) aResult;
1038 _PTR(AttributeName) aName;
1039 _PTR(GenericAttribute) anAttr;
1040 _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
1041 for (; anIterator->More(); anIterator->Next()) {
1042 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1043 aName = _PTR(AttributeName) ( anAttr );
1044 if (strcmp(aName->Value().c_str(), theName) == 0) {
1045 aResult = anIterator->Value();
1051 // if aResule was found then theDoneSomething=false and we return
1052 *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
1053 if ( !*theDoneSomething )
1057 aResult = theBuilder->NewObject( theSO );
1058 anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1059 aName = _PTR(AttributeName) ( anAttr );
1060 aName->SetValue(theName);
1065 * Return true if dataflow is already in the study
1067 bool SUPERVGUI_Main::isDataflowInStudy() const {
1068 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1069 _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
1070 return ( aSO ? true : false );
1074 * Create a "Supervision" object in the Study and a "dataflow" object under it
1075 * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
1077 _PTR(SObject) createDataflowSObj( SUIT_Study* study,
1078 SUPERV::Graph_var dataflow,
1079 _PTR(StudyBuilder) aBuilder,
1080 bool& aDoneSomething ) {
1081 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1082 _PTR(GenericAttribute) anAttr;
1083 _PTR(AttributeName) aName;
1085 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1086 _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
1087 if ( !aSO ) { // dataflow SObject not found in the study
1088 aDoneSomething = true;
1089 _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1090 if ( !aComponent ) { // is supervision component not found, then create it
1091 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1092 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1093 aName = _PTR(AttributeName) ( anAttr );
1094 aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
1096 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1097 _PTR(AttributePixMap) aPixmap ( anAttr );
1098 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1100 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1102 aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
1103 //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
1104 else MESSAGE("NULL Supervision module!");
1107 // create dataflow SObject ("aNewDataflow_1")
1108 aSO = aBuilder->NewObject(aComponent);
1109 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1110 aName = _PTR(AttributeName) ( anAttr );
1111 aName->SetValue(dataflow->Name());
1112 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1113 _PTR(AttributeIOR) anIORAttr ( anAttr );
1114 anIORAttr->SetValue(dataflow->getIOR());
1120 void SUPERVGUI_Main::addDataflowToStudy() {
1122 _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
1123 aBuilder->NewCommand();
1124 _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
1126 aBuilder->CommitCommand();
1127 // what is this register/unregister?? don't know..
1128 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1130 MESSAGE("NULL Supervision module!");
1133 aSupMod->unregisterGraph(this);
1134 aSupMod->registerGraph(dataflow->getIOR(), this);
1136 if ( !myThread->running() )
1137 aSupMod->updateObjBrowser();
1139 aSupMod->getApp()->updateActions();
1142 MESSAGE( "ERROR: failed to find or create dataflow SObject" );
1143 aBuilder->AbortCommand();
1147 bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
1148 Trace("SUPERVGUI_Main::putDataStudy");
1150 bool PublishOtherComponent = false;
1152 // static variable to ensure that only one instance (thread) is executing this function
1153 static bool isIn = false;
1154 if (isIn) return true;
1157 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1158 const bool aLocked = aStudy->GetProperties()->IsLocked();
1159 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
1160 bool aDoneSomething = false;
1162 // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
1164 MESSAGE( "The study is locked and can not be modified!" );
1169 // check if the port and its node are good
1170 if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
1171 MESSAGE( "putInStudy ERROR: port or node are NULL!" );
1176 // open new command. Commit or Abort it depending on aDoneSomething variable or error
1177 aBuilder->NewCommand();
1179 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1180 _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
1183 MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" );
1184 aBuilder->AbortCommand();
1189 // Create "Run -> Time and date, etc." SObjects
1190 if ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
1192 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
1193 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
1194 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
1195 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
1197 // create IOR attribute for port SObject (usually with "return" name)
1198 _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
1199 _PTR(AttributeIOR) anIORAttr ( anAttr );
1201 // if we have not created anything (all SObject already existed) and we have the same IORAttribute
1202 // on the needed SObject -> then don't do anything! it's already there!
1203 if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
1204 aBuilder->AbortCommand();
1209 aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
1211 // set object value to the study: if object is external, then put it with
1212 // help of the specific component - owner
1214 // get according component driver for result object
1215 SALOME_LifeCycleCORBA aLCC( myNService );
1216 SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
1217 if ( !aFNode->_is_nil() ) {
1218 Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
1219 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
1220 if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
1221 CORBA::Object_ptr anObject = new CORBA::Object();
1222 CORBA::Any* anAny = p->ToAny();
1223 (*anAny) >>= anObject;
1225 if ( aDriver->CanPublishInStudy( anObject ) ) {
1226 SALOMEDS::SObject_var aTmpSO;// = aSO;
1227 SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
1228 if ( !aSStudy ) return false;
1230 aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
1231 aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
1232 PublishOtherComponent = true;
1234 catch ( ... ) { // mkr : PAL8150
1237 else { // can't publish object: abort transaction
1238 MESSAGE( "CanPublishInStudy() returned FALSE. ok, AbortCommand.." );
1239 aBuilder->AbortCommand();
1244 else { // component has no driver, but could store IORs (like Calculator)
1245 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1247 aBuilder->Addreference(aSO, anIORSO);
1249 PublishOtherComponent = true;
1251 else { // Hm... the object (==port value) was not found, so we don't publish it.
1252 MESSAGE( "The object (==port value) was not found, so we don't publish it" );
1253 aBuilder->AbortCommand();
1259 else { // FNode is NULL -> bad
1260 MESSAGE( "FNode is NULL." );
1261 if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
1262 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1264 aBuilder->Addreference(aSO, anIORSO);
1267 MESSAGE( "FNode and INode are NULL. Not good at all. Aborting command." );
1268 aBuilder->AbortCommand();
1275 anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
1279 if ( aDoneSomething )
1280 aBuilder->CommitCommand();
1282 aBuilder->AbortCommand();
1284 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1286 if ( PublishOtherComponent )
1287 dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
1289 aSupMod->updateObjBrowser();
1291 else MESSAGE("NULL Supervision module!");
1293 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
1294 if(app) app->updateActions();
1300 void SUPERVGUI_Main::ActivatePanning()
1302 if (myCanvasView->isVisible()) {
1303 myCanvasView->ActivatePanning();
1304 } else if (myArrayView->isVisible()) {
1305 myArrayView->ActivatePanning();
1310 void SUPERVGUI_Main::ResetView()
1312 if (myCanvasView->isVisible()) {
1313 myCanvasView->ResetView();
1314 } else if (myArrayView->isVisible()) {
1315 myArrayView->ResetView();
1319 void SUPERVGUI_Main::syncNotification() {
1329 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1330 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) { // mkr : PAL7037
1332 mess += "NOTIF: "; mess += graph;
1333 mess += " / " ; mess += node;
1334 mess += " / " ; mess += type;
1335 mess += " / " ; mess += message;
1336 getMessage()->putMessage(mess.latin1());
1341 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1342 char* sender, long counter, char* date, long stamp) {
1343 Trace("SUPERVGUI_Main::isFiltered");
1345 if (strcmp(getDataflow()->Name(), graph) == 0) {
1346 SUPERVGUI_CanvasNode* n;
1348 // mkr : PAL7037 -->
1349 if (myCurrentView == CANVASTABLE)
1350 nodes = myArray->queryList("SUPERVGUI_CanvasNode");
1352 nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
1353 // mkr : PAL7037 <--
1354 QObjectListIt i(*nodes);
1355 while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
1357 if (strcmp(n->name(), node) == 0) {
1358 if (strcmp(type, NOTIF_WARNING) == 0) {
1360 } else if (strcmp(type, NOTIF_STEP) == 0) {
1362 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1364 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1371 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1372 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 );
1373 fflush( myLogFile );
1379 void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
1384 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1386 myCanvas->setBackgroundColor(color);
1387 myCanvasView->setPaletteBackgroundColor(color.light());
1388 myArray->setBackgroundColor(color);
1389 myArrayView->setPaletteBackgroundColor(color.light());
1391 SUPERVGraph_View::setPaletteBackgroundColor(color);
1394 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1395 return myEventNodes;
1398 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1399 myEventNodes = theEventNodes;
1402 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1406 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1407 myStates = theStates;
1410 int SUPERVGUI_Main::getNodesNumber() {
1411 //create a list of nodes of the graph
1412 SUPERV_Nodes nodes = getDataflow()->Nodes();
1413 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1414 nodes->INodes.length() + nodes->GNodes.length() +
1415 nodes->LNodes.length() + nodes->SNodes.length();
1419 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1423 void SUPERVGUI_Main::startTimer() {
1424 myTimer->start(500);
1427 void SUPERVGUI_Main::executionFinished() {
1428 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1430 //aSupMod->updateObjBrowser();
1431 // PAL10611: update all modules data
1432 aSupMod->getApp()->updateObjectBrowser(true);
1433 else MESSAGE("NULL Supervision module!");
1439 void SUPERVGUI_Main::checkExecution() {
1440 if (myThread->finished()) {
1442 executionFinished();
1447 * Editing() is to be called by any operation in GUI before modification of a datamodel
1448 * (add/remove ports or nodes, etc.). It is used to resolve inconsistancies between 2 data models
1449 * in Engine: Editor and Executor. During and after execution, the values of ports and statuses of nodes
1450 * are taken from Executor data model. But when user starts editing the graph - these changes must
1451 * be applied to Editor data model. This function destroys Executor data model and moves to Editor.
1453 void SUPERVGUI_Main::Editing() {
1454 if ( !SUPERV_isNull( dataflow ) )
1455 dataflow->Editing();
1457 // updata GUI, Nodes' statuses and Ports' values could change.
1461 void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
1463 // mkr: since the deletion of the node allow only in CANVAS view,
1464 // it is necessary to remove the CanvasArray's children, which
1465 // have the same CNode engine as deleting node. This CNode is given
1468 const QObjectList* aChList = myArray->children();
1469 if ( aChList ) { // asv 27.01.05 : fix for 7817
1470 QObjectListIt aItChList(*aChList);
1471 SUPERVGUI_CanvasNode* anObjNode;
1472 while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
1474 if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
1475 myArray->removeChild(anObjNode);
1479 } // end of if ( ChList )
1484 * ReadyToModify() must be called before any modification
1485 * operation - asks to kill execution of dataflow. If returns false -
1486 * modification (==Editing() ) is not allowed.
1488 bool SUPERVGUI_Main::ReadyToModify() {
1489 if ( CORBA::is_nil( dataflow ) )
1491 if ( dataflow->IsExecuting() ) {
1492 bool quit = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 0=Yes, 1=No
1493 tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
1494 if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
1496 else if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
1497 kill(); // checking again for IsExecuting to be sure that it was not finished while MB was up
1502 void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
1504 if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
1505 if ( getCanvas()->width() < theEvent->size().width()
1507 getCanvas()->height() < theEvent->size().height() )
1508 getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
1509 if ( myCurrentView == CANVASTABLE && getCanvasArray() )
1510 if ( getCanvasArray()->width() < theEvent->size().width()
1512 getCanvasArray()->height() < theEvent->size().height() )
1513 getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
1517 Sets a modified flag in an active study
1519 void SUPERVGUI_Main::setModifiedFlag()
1521 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1523 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1525 _PTR(Study) studyDS = study->studyDS();
1526 _PTR(SComponent) sco = studyDS->FindComponent(STUDY_SUPERVISION);
1528 _PTR(StudyBuilder) builder = studyDS->NewBuilder();
1529 _PTR(GenericAttribute) ga;
1530 ga = builder->FindOrCreateAttribute(sco, "AttributeParameter");
1531 _PTR(AttributeParameter) ap(ga);
1533 ap->SetBool("SUPERVISOR_MODIFIED_FLAG",1);
1534 app->updateActions();
1542 /******************************* SUPERVGUI_Thread class ****************************************/
1543 SUPERVGUI_Thread::SUPERVGUI_Thread()
1549 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1551 //it is a virtual destructor and needs to be determine here
1554 void SUPERVGUI_Thread::startThread(const char* m)
1559 myMain->getMessage()->putMessage(m);
1566 void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
1571 void SUPERVGUI_Thread::KillThread( bool theValue )
1574 myIsActive = !(theValue);
1578 template<class TObject, typename TArg, typename TArg1, typename TArg2,
1579 typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
1580 class TVoidMemFun3ArgEvent: public SALOME_Event{
1582 typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
1583 TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
1584 myObject(theObject),
1585 myAction(theAction),
1590 virtual void Execute(){
1591 (myObject->*myAction)(myArg,myArg1,myArg2);
1601 typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
1604 * main_thread_run must be executed in the qt main thread
1605 * It is activated by calling ProcessVoidEvent
1607 void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
1609 // in case node "said" something during changing state through notification mechanism - output it
1610 myMain->syncNotification();
1611 myMain->sync(); // mkr : NPAL14881
1613 // "kill" or undefined event came
1614 if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
1615 ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
1616 ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
1620 else { // a "normal" execution event came
1622 if ( aNode != NULL && !CORBA::is_nil( aNode ) )
1623 aName = aNode->Name();
1625 // What follow is not quite sure. The entire function is posted to the main qt thread.
1626 // So all executions are serialized. Is it really possible to call execute when another
1627 // execute is running. I don't think so (C Caremoli)
1628 // this function is asynchronious. The call does NOT wait when SUPERVGUI_Main::execute finishes
1629 // handling the event. So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
1630 // on the next loop iteration, BEFORE previous SUPERVGUI_Main::execute finished.
1631 myMain->execute(aName, aState );
1634 // execution is finished. just set a "finished" message(s)
1635 if ( !myIsActive ) {
1637 switch ( myMain->getDataflow()->State() ) {
1638 case SUPERV_Editing :
1639 myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()?
1640 tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
1642 case SUPERV_Suspend :
1643 myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
1646 myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
1649 myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
1651 aMess = QString(myMain->getDataflow()->Messages());
1652 if ( !aMess.isEmpty() ) {
1653 myMain->getMessage()->putMessage( tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess );
1654 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"),
1655 tr("MSG_DF_BADEXECUTE") + QString(" : ") + aMess);
1660 myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
1664 // asv 03.02.05 : fix for PAL6859, not very good, but works..
1666 } // end of if !myIsActive
1669 void SUPERVGUI_Thread::run()
1671 myMain->startTimer();
1673 // GUI cycle to handle events coming for Engine
1674 while ( myIsActive ) {
1676 SUPERV_CNode aNode = NULL;
1677 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1678 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1680 // blocking function of Engine. Return from there only after anEvent happens on node aNode
1681 myMain->getDataflow()->Event(aNode, aEvent, aState);
1683 ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
1685 } // end of while( myIsActive )
1690 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1694 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1695 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1697 Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1698 setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1699 setSizeGripEnabled( true );
1702 QGridLayout* TopLayout = new QGridLayout( this );
1703 TopLayout->setSpacing( 6 );
1704 TopLayout->setMargin( 11 );
1706 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1707 TopGroup->setColumnLayout(0, Qt::Vertical );
1708 TopGroup->layout()->setSpacing( 0 );
1709 TopGroup->layout()->setMargin( 0 );
1710 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1711 TopGroupLayout->setAlignment( Qt::AlignTop );
1712 TopGroupLayout->setSpacing( 6 );
1713 TopGroupLayout->setMargin( 11 );
1716 QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );
1717 TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1719 myDeltaTime = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
1720 myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1721 TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1724 QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup);
1725 TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1727 myTimeOut = new QLineEdit( TopGroup );
1728 myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1729 myTimeOut->setValidator( new QIntValidator(this) );
1730 myTimeOut->setMinimumSize( 100, 0 );
1731 myTimeOut->setReadOnly( isReadOnly );
1732 TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1735 QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup);
1736 TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1738 myDataStreamTrace = new QComboBox( TopGroup );
1739 myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1740 myDataStreamTrace->insertItem("WithoutTrace");
1741 myDataStreamTrace->insertItem("SummaryTrace");
1742 myDataStreamTrace->insertItem("DetailedTrace");
1743 TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1745 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1746 GroupButtons->setColumnLayout(0, Qt::Vertical );
1747 GroupButtons->layout()->setSpacing( 0 );
1748 GroupButtons->layout()->setMargin( 0 );
1749 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1750 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1751 GroupButtonsLayout->setSpacing( 6 );
1752 GroupButtonsLayout->setMargin( 11 );
1754 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
1755 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1757 GroupButtonsLayout->addWidget( okB, 0, 0 );
1758 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1759 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1761 TopLayout->addWidget( TopGroup, 0, 0 );
1762 TopLayout->addWidget( GroupButtons, 1, 0 );
1764 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
1765 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1773 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1774 Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1780 void SUPERVGUI_DSGraphParameters::setData() {
1781 CORBA::Double aDeltaTime;
1782 CORBA::Long aTimeOut;
1783 SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1785 // myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1786 if (myGraph->IsStreamGraph()) {
1787 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1788 if (!SUPERV_isNull(aSGraph))
1789 aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1792 myDeltaTime->setValue(aDeltaTime);
1793 myTimeOut->setText(QString("%1").arg(aTimeOut));
1794 myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1800 void SUPERVGUI_DSGraphParameters::accept() {
1801 // myGraph->SetStreamParams( myTimeOut->text().toLong(),
1802 // (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1803 // myDeltaTime->value());
1804 if (myGraph->IsStreamGraph()) {
1805 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1806 if (!SUPERV_isNull(aSGraph))
1807 aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1808 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1809 myDeltaTime->value());