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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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())->Port(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 if (myCurrentView == CANVASTABLE) {
362 void SUPERVGUI_Main::showCanvasTable() {
363 if (myCurrentView == CANVASTABLE)
366 if (myArray->create()) {
367 myCanvasView->hide();
369 myCurrentView = CANVASTABLE;
374 void SUPERVGUI_Main::showContolFlow() {
376 if (myCurrentView == CANVASTABLE) {
381 myCurrentView = CONTROLFLOW;
382 myCanvas->setControlView();
385 myCanvasView->show();
389 void SUPERVGUI_Main::showCanvas() {
390 if (myCurrentView == CANVAS)
394 if (myCurrentView == CANVASTABLE) {
399 myCurrentView = CANVAS;
400 myCanvas->setFullView();
403 myCanvasView->show();
407 void SUPERVGUI_Main::insertFile() {
408 Trace("SUPERVGUI_Main::insertFile");
410 if ( !ReadyToModify() ) // null dataflow or executing, ..
413 QString f = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
416 tr("MSG_GRAPH_INSERT"),
418 if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name
420 Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960
422 if (dataflow->Import(f.latin1())) {
423 if (myCurrentView == CANVASTABLE) {
427 else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
432 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
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"));
444 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
446 MESSAGE("NULL Supervision module!");
450 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aSupMod->createGraph() );
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"));
459 aNewGraph = aSGraph->StreamCopy();
462 aNewGraph = dataflow->Copy();
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(),
474 void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
476 if (theNode->IsMacro()) {
477 // get SubGraph from MacroNode
478 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(theNode);
480 if (aMacro->IsStreamMacro())
481 aGraph = aMacro->StreamObjRef();
483 aGraph = aMacro->FlowObjRef();
486 if (SUPERV_isNull(aGraph)) {
487 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NOACCESS"));
491 QString aGraphName = aGraph->Name();
492 SUIT_ViewWindow* aStudyFrame;
493 if (mySubGraphs.contains(aGraphName)) {
494 aStudyFrame = mySubGraphs[aGraphName];
495 aStudyFrame->setActiveWindow();
496 aStudyFrame->setFocus();
499 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
501 MESSAGE("NULL Supervision module!");
505 aStudyFrame = aSupMod->createGraph();
507 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( aStudyFrame );
509 new SUPERVGUI_Main(aViewFrame,
510 aSupMod->application()->desktop(),//getDesktop(),
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);
518 mySubGraphs.insert(aGraphName, aStudyFrame);
519 mySubGraphMap.insert(aGraphName, theNode->Name());
525 if (!correct) myLastGraph = aStudyFrame;
531 void SUPERVGUI_Main::destroySubGraph(QString theSubGraphName)
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);
542 bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
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);
549 return SUPERVGraph_View::eventFilter(o, e);
552 // workaround to fix PAL6255 -> opened SubGraph is not on top
553 void SUPERVGUI_Main::onSubGraphActivated(SUIT_ViewWindow* theStudyFrame)
556 SUIT_ViewWindow* aFrame = myLastGraph;
558 aFrame->setActiveWindow();
563 void SUPERVGUI_Main::onSubGraphClosed(SUIT_ViewWindow* theStudyFrame)
565 if ( SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>( theStudyFrame ) ) {
566 theStudyFrame->removeEventFilter(this);
567 disconnect(theStudyFrame, 0, this, 0);
569 SUPERVGraph_View* view = supervFrame->getViewWidget();
570 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
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");
582 mySubGraphMap.remove(it);
584 mySubGraphs.remove(aGraphName);
589 void SUPERVGUI_Main::onShowToolbar()
591 SUPERVGraph_ViewFrame* aVF = (SUPERVGraph_ViewFrame*)this->parent();
593 aVF->getToolBar()->show();
596 // mkr : PAL8237 : synchronize many views of the same dataflow (objects creation/deletion)
597 void SUPERVGUI_Main::onObjectCreatedDeleted()
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() );
612 if ( !CORBA::is_nil( aMain->getDataflow() )
614 !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
616 aMain != this ) // not equal mains
617 aMain->getCanvas()->merge();
625 // mkr : PAL8150 : synchronize many views of the same dataflow ("Put In Study"/"Not In Study" operation)
626 void SUPERVGUI_Main::onPutInStudy( QString* theNodePortName )
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() );
641 if ( !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
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 );
656 // mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
657 void SUPERVGUI_Main::syncPutInStudy()
660 if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
661 ViewManagerList aVMList;
662 app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
663 SUIT_ViewManager* aVM;
664 for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
665 QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
666 for ( int i = 0; i < aVWList.count(); i++ ) {
667 SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
668 QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
669 if ( aMainList->count() == 1 ) {
670 SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
672 if ( !CORBA::is_nil( aMain->getDataflow() )
674 !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
676 aMain != this ) { // not equal mains
678 // check "myInStudy" field of output ports of original main (i.e. this main)
679 // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
680 SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
682 SYNCPUTINSTUDY(CNodes);
683 SYNCPUTINSTUDY(FNodes);
684 SYNCPUTINSTUDY(INodes);
685 SYNCPUTINSTUDY(GNodes);
686 SYNCPUTINSTUDY(LNodes);
687 SYNCPUTINSTUDY(ELNodes);
688 SYNCPUTINSTUDY(SNodes);
689 SYNCPUTINSTUDY(ESNodes);
690 SYNCPUTINSTUDY(Graphs);
692 setRunTime( aMain->getRunTime() );
703 void SUPERVGUI_Main::run( const bool andSuspend ) {
704 Trace("SUPERVGUI_Main::run");
705 if ( SUPERV_isNull(dataflow) )
708 if ( dataflow->IsEditing() ) { // not currently Executing
710 // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
711 Editing(); // remove old executor, update GUI (all nodes to "No Status")
713 if ( !dataflow->IsValid() ) {
714 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
716 else if (!dataflow->IsExecutable()) {
717 QString aMessage = QString(dataflow->Messages());
718 if ( aMessage.isEmpty() ) // mkr : IPAL11471
719 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
721 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
723 else if (myCanvasView->isAnyLinkCreating()) {
724 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
727 myRunTime = QDateTime::currentDateTime();
728 const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
730 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
731 if ( dataflow->State() == SUPERV::ErrorState ) {
736 //myExecuted = true; // set to true on first execution. for correct publishing in Study
737 myThread->startThread(tr("MSG_GRAPH_STARTED"));
742 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
747 void SUPERVGUI_Main::kill() {
748 Trace("SUPERVGUI_Main::kill");
749 if ((SUPERV_isNull(dataflow)))
752 if (dataflow->IsEditing()) {
753 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
755 else if (dataflow->Kill()) {
756 getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
760 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
764 void SUPERVGUI_Main::suspendResume() {
765 Trace("SUPERVGUI_Main::suspendResume");
767 if ((SUPERV_isNull(dataflow))) return;
769 if (dataflow->IsEditing()) {
770 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
771 } else if (dataflow->State() == SUPERV_Suspend) {
772 if (dataflow->Resume()) {
773 myThread->startThread(tr("MSG_DF_RESUMED"));
775 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
778 if (dataflow->Suspend()) {
780 getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
782 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
786 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
787 the comment from kloss below may be explaining it, but it's in French and I do not understand it..
788 It also calls deprecated method of Engine: ReStart().
789 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
790 Trace("SUPERVGUI_Main::stopRestart");
791 if ((SUPERV_isNull(dataflow))) return;
793 if (dataflow->IsEditing()) {
794 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
795 } else if (dataflow->State() == SUPERV_Stop) {
796 if (dataflow->ReStart()) {
797 message->setMessage(tr("MSG_DF_RESTARTED"));
800 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
803 if (dataflow->Stop()) {
806 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
811 void SUPERVGUI_Main::addNode() {
812 Trace("SUPERVGUI_Main::addNode");
814 if ( !ReadyToModify() ) // null dataflow or executing, ..
817 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
819 MESSAGE("NULL Supervision module!");
823 //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
824 aSupMod->getBrowser()->choose();
828 * Add Computation node
830 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
831 switch (myCurrentView) {
839 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode( resMgr(), myCanvas, this, theNode);
840 aNode->move(theNode->X(), theNode->Y());
841 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
852 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
853 switch (myCurrentView) {
861 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode( resMgr(), myCanvas, this, theNode);
862 aNode->move(theNode->X(), theNode->Y());
863 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
874 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
875 switch (myCurrentView) {
883 SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode( resMgr(), myCanvas, this, theStartNode);
884 aStartNode->move(theStartNode->X(), theStartNode->Y());
885 if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
887 SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode( resMgr(), myCanvas, this, theEndNode, aStartNode);
888 aEndNode->move(theEndNode->X(), theEndNode->Y());
889 if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
903 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
904 switch (myCurrentView) {
912 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode( resMgr(), myCanvas, this, theNode);
913 aNode->move(theNode->X(), theNode->Y());
914 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
922 SUPERVGUI_CanvasArray* SUPERVGUI_Main::getCanvasArray() {
923 Trace("SUPERVGUI_Main::getCanvasArray");
927 SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
928 Trace("SUPERVGUI_Main::getArrayView");
932 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
933 Trace("SUPERVGUI_Main::getCanvas");
937 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
938 Trace("SUPERVGUI_Main::getCanvasView");
939 return(myCanvasView);
942 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
943 Trace("SUPERVGUI_Main::getDataflow");
947 LogWindow* SUPERVGUI_Main::getMessage() {
948 Trace("SUPERVGUI_Main::getMessage");
952 SUIT_Study* SUPERVGUI_Main::getStudy() {
953 Trace("SUPERVGUI_Main::getStudy");
957 bool SUPERVGUI_Main::isArrayShown() {
958 Trace("SUPERVGUI_Main::isArrayShown");
959 return(myCurrentView == CANVASTABLE);
962 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
963 Trace("SUPERVGUI_Main::showPopup");
964 // To check is Supervision active?
965 if (myIsLocked) return;
966 //if (dataflow->IsExecuting()) return;
968 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
969 if ( !anApp->activeModule() ) return;
970 if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
972 if (e->button() == RightButton) {
973 p->exec(e->globalPos());
977 void SUPERVGUI_Main::changeInformation() {
978 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
984 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
985 Trace("SUPERVGUI_Main::chooseData");
987 QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
989 _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
990 _PTR(GenericAttribute) anAttr;
991 if (object->FindAttribute(anAttr, "AttributeIOR")) {
992 _PTR(AttributeIOR) anIOR ( anAttr );
994 // asv : 13.12.04 : commented out use of portIn field, but it seems that it
995 // should be replaced with some analogious code... selection of IOR was done -
996 // put its value into port.
997 //portIn->setValue(ior);
999 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1001 MESSAGE("NULL Supervision module!");
1007 setCursor(aSupMod->getCursor());
1008 objectBrowser->setCursor(aSupMod->getCursor());
1009 aSupMod->putInfo("");
1015 _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
1016 _PTR(StudyBuilder) const theBuilder,
1017 _PTR(SObject) const theSO,
1018 const char* theName,
1019 bool* theDoneSomething ) {
1020 _PTR(SObject) aResult;
1021 _PTR(AttributeName) aName;
1022 _PTR(GenericAttribute) anAttr;
1023 _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
1024 for (; anIterator->More(); anIterator->Next()) {
1025 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1026 aName = _PTR(AttributeName) ( anAttr );
1027 if (strcmp(aName->Value().c_str(), theName) == 0) {
1028 aResult = anIterator->Value();
1034 // if aResule was found then theDoneSomething=false and we return
1035 *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
1036 if ( !*theDoneSomething )
1040 aResult = theBuilder->NewObject( theSO );
1041 anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1042 aName = _PTR(AttributeName) ( anAttr );
1043 aName->SetValue(theName);
1048 * Return true if dataflow is already in the study
1050 bool SUPERVGUI_Main::isDataflowInStudy() const {
1051 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1052 _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
1053 return ( aSO ? true : false );
1057 * Create a "Supervision" object in the Study and a "dataflow" object under it
1058 * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
1060 _PTR(SObject) createDataflowSObj( SUIT_Study* study,
1061 SUPERV::Graph_var dataflow,
1062 _PTR(StudyBuilder) aBuilder,
1063 bool& aDoneSomething ) {
1064 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1065 _PTR(GenericAttribute) anAttr;
1066 _PTR(AttributeName) aName;
1068 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1069 _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
1070 if ( !aSO ) { // dataflow SObject not found in the study
1071 aDoneSomething = true;
1072 _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1073 if ( !aComponent ) { // is supervision component not found, then create it
1074 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1075 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1076 aName = _PTR(AttributeName) ( anAttr );
1077 aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
1079 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1080 _PTR(AttributePixMap) aPixmap ( anAttr );
1081 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1083 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1085 aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
1086 //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
1087 else MESSAGE("NULL Supervision module!");
1090 // create dataflow SObject ("aNewDataflow_1")
1091 aSO = aBuilder->NewObject(aComponent);
1092 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1093 aName = _PTR(AttributeName) ( anAttr );
1094 aName->SetValue(dataflow->Name());
1095 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1096 _PTR(AttributeIOR) anIORAttr ( anAttr );
1097 anIORAttr->SetValue(dataflow->getIOR());
1103 void SUPERVGUI_Main::addDataflowToStudy() {
1105 _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
1106 aBuilder->NewCommand();
1107 _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
1109 aBuilder->CommitCommand();
1110 // what is this register/unregister?? don't know..
1111 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1113 MESSAGE("NULL Supervision module!");
1116 aSupMod->unregisterGraph(this);
1117 aSupMod->registerGraph(dataflow->getIOR(), this);
1119 if ( !myThread->running() )
1120 aSupMod->updateObjBrowser();
1123 MESSAGE( "ERROR: failed to find or create dataflow SObject" );
1124 aBuilder->AbortCommand();
1128 bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
1129 Trace("SUPERVGUI_Main::putDataStudy");
1131 bool PublishOtherComponent = false;
1133 // static variable to ensure that only one instance (thread) is executing this function
1134 static bool isIn = false;
1135 if (isIn) return true;
1138 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1139 const bool aLocked = aStudy->GetProperties()->IsLocked();
1140 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
1141 bool aDoneSomething = false;
1143 // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
1145 MESSAGE( "The study is locked and can not be modified!" );
1150 // check if the port and its node are good
1151 if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
1152 MESSAGE( "putInStudy ERROR: port or node are NULL!" );
1157 // open new command. Commit or Abort it depending on aDoneSomething variable or error
1158 aBuilder->NewCommand();
1160 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1161 _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
1164 MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" );
1165 aBuilder->AbortCommand();
1170 // Create "Run -> Time and date, etc." SObjects
1171 if ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
1173 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
1174 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
1175 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
1176 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
1178 // create IOR attribute for port SObject (usually with "return" name)
1179 _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
1180 _PTR(AttributeIOR) anIORAttr ( anAttr );
1182 // if we have not created anything (all SObject already existed) and we have the same IORAttribute
1183 // on the needed SObject -> then don't do anything! it's already there!
1184 if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
1185 aBuilder->AbortCommand();
1190 aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
1192 // set object value to the study: if object is external, then put it with
1193 // help of the specific component - owner
1195 // get according component driver for result object
1196 SALOME_LifeCycleCORBA aLCC( myNService );
1197 SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
1198 if ( !aFNode->_is_nil() ) {
1199 Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
1200 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
1201 if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
1202 CORBA::Object_ptr anObject = new CORBA::Object();
1203 CORBA::Any* anAny = p->ToAny();
1204 (*anAny) >>= anObject;
1206 if ( aDriver->CanPublishInStudy( anObject ) ) {
1207 SALOMEDS::SObject_var aTmpSO;// = aSO;
1208 SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
1209 if ( !aSStudy ) return false;
1211 aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
1212 aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
1213 PublishOtherComponent = true;
1215 catch ( ... ) { // mkr : PAL8150
1218 else { // can't publish object: abort transaction
1219 MESSAGE( "CanPublishInStudy() returned FALSE. ok, AbortCommand.." );
1220 aBuilder->AbortCommand();
1225 else { // component has no driver, but could store IORs (like Calculator)
1226 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1228 aBuilder->Addreference(aSO, anIORSO);
1230 PublishOtherComponent = true;
1232 else { // Hm... the object (==port value) was not found, so we don't publish it.
1233 MESSAGE( "The object (==port value) was not found, so we don't publish it" );
1234 aBuilder->AbortCommand();
1240 else { // FNode is NULL -> bad
1241 MESSAGE( "FNode is NULL." );
1242 if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
1243 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1245 aBuilder->Addreference(aSO, anIORSO);
1248 MESSAGE( "FNode and INode are NULL. Not good at all. Aborting command." );
1249 aBuilder->AbortCommand();
1256 anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
1260 if ( aDoneSomething )
1261 aBuilder->CommitCommand();
1263 aBuilder->AbortCommand();
1265 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1267 if ( PublishOtherComponent )
1268 dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
1270 aSupMod->updateObjBrowser();
1272 else MESSAGE("NULL Supervision module!");
1279 void SUPERVGUI_Main::ActivatePanning()
1281 if (myCanvasView->isVisible()) {
1282 myCanvasView->ActivatePanning();
1283 } else if (myArrayView->isVisible()) {
1284 myArrayView->ActivatePanning();
1289 void SUPERVGUI_Main::ResetView()
1291 if (myCanvasView->isVisible()) {
1292 myCanvasView->ResetView();
1293 } else if (myArrayView->isVisible()) {
1294 myArrayView->ResetView();
1298 void SUPERVGUI_Main::syncNotification() {
1308 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1309 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) { // mkr : PAL7037
1311 mess += "NOTIF: "; mess += graph;
1312 mess += " / " ; mess += node;
1313 mess += " / " ; mess += type;
1314 mess += " / " ; mess += message;
1315 getMessage()->putMessage(mess.latin1());
1320 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1321 char* sender, long counter, char* date, long stamp) {
1322 Trace("SUPERVGUI_Main::isFiltered");
1324 if (strcmp(getDataflow()->Name(), graph) == 0) {
1325 SUPERVGUI_CanvasNode* n;
1327 // mkr : PAL7037 -->
1328 if (myCurrentView == CANVASTABLE)
1329 nodes = myArray->queryList("SUPERVGUI_CanvasNode");
1331 nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
1332 // mkr : PAL7037 <--
1333 QObjectListIt i(*nodes);
1334 while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
1336 if (strcmp(n->name(), node) == 0) {
1337 if (strcmp(type, NOTIF_WARNING) == 0) {
1339 } else if (strcmp(type, NOTIF_STEP) == 0) {
1341 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1343 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1350 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1351 fprintf( myLogFile, "NOTIF %ld\t%s\t%s\t%ld\t%s\t%s\t%s\t%s\n", stamp, date, sender, counter, graph, node, type, message );
1352 fflush( myLogFile );
1358 void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
1363 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1365 myCanvas->setBackgroundColor(color);
1366 myCanvasView->setPaletteBackgroundColor(color.light());
1367 myArray->setBackgroundColor(color);
1368 myArrayView->setPaletteBackgroundColor(color.light());
1370 SUPERVGraph_View::setPaletteBackgroundColor(color);
1373 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1374 return myEventNodes;
1377 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1378 myEventNodes = theEventNodes;
1381 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1385 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1386 myStates = theStates;
1389 int SUPERVGUI_Main::getNodesNumber() {
1390 //create a list of nodes of the graph
1391 SUPERV_Nodes nodes = getDataflow()->Nodes();
1392 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1393 nodes->INodes.length() + nodes->GNodes.length() +
1394 nodes->LNodes.length() + nodes->SNodes.length();
1398 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1402 void SUPERVGUI_Main::startTimer() {
1403 myTimer->start(500);
1406 void SUPERVGUI_Main::executionFinished() {
1407 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1409 //aSupMod->updateObjBrowser();
1410 // PAL10611: update all modules data
1411 aSupMod->getApp()->updateObjectBrowser(true);
1412 else MESSAGE("NULL Supervision module!");
1418 void SUPERVGUI_Main::checkExecution() {
1419 if (myThread->finished()) {
1421 executionFinished();
1426 * Editing() is to be called by any operation in GUI before modification of a datamodel
1427 * (add/remove ports or nodes, etc.). It is used to resolve inconsistancies between 2 data models
1428 * in Engine: Editor and Executor. During and after execution, the values of ports and statuses of nodes
1429 * are taken from Executor data model. But when user starts editing the graph - these changes must
1430 * be applied to Editor data model. This function destroys Executor data model and moves to Editor.
1432 void SUPERVGUI_Main::Editing() {
1433 if ( !SUPERV_isNull( dataflow ) )
1434 dataflow->Editing();
1436 // updata GUI, Nodes' statuses and Ports' values could change.
1440 void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
1442 // mkr: since the deletion of the node allow only in CANVAS view,
1443 // it is necessary to remove the CanvasArray's children, which
1444 // have the same CNode engine as deleting node. This CNode is given
1447 const QObjectList* aChList = myArray->children();
1448 if ( aChList ) { // asv 27.01.05 : fix for 7817
1449 QObjectListIt aItChList(*aChList);
1450 SUPERVGUI_CanvasNode* anObjNode;
1451 while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
1453 if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
1454 myArray->removeChild(anObjNode);
1458 } // end of if ( ChList )
1463 * ReadyToModify() must be called before any modification
1464 * operation - asks to kill execution of dataflow. If returns false -
1465 * modification (==Editing() ) is not allowed.
1467 bool SUPERVGUI_Main::ReadyToModify() {
1468 if ( CORBA::is_nil( dataflow ) )
1470 if ( dataflow->IsExecuting() ) {
1471 bool quit = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 0=Yes, 1=No
1472 tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
1473 if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
1475 else if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
1476 kill(); // checking again for IsExecuting to be sure that it was not finished while MB was up
1481 void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
1483 if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
1484 if ( getCanvas()->width() < theEvent->size().width()
1486 getCanvas()->height() < theEvent->size().height() )
1487 getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
1488 if ( myCurrentView == CANVASTABLE && getCanvasArray() )
1489 if ( getCanvasArray()->width() < theEvent->size().width()
1491 getCanvasArray()->height() < theEvent->size().height() )
1492 getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
1495 /******************************* SUPERVGUI_Thread class ****************************************/
1496 SUPERVGUI_Thread::SUPERVGUI_Thread()
1502 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1504 //it is a virtual destructor and needs to be determine here
1507 void SUPERVGUI_Thread::startThread(const char* m)
1512 myMain->getMessage()->putMessage(m);
1519 void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
1524 void SUPERVGUI_Thread::KillThread( bool theValue )
1527 myIsActive = !(theValue);
1531 template<class TObject, typename TArg, typename TArg1, typename TArg2,
1532 typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
1533 class TVoidMemFun3ArgEvent: public SALOME_Event{
1535 typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
1536 TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
1537 myObject(theObject),
1538 myAction(theAction),
1543 virtual void Execute(){
1544 (myObject->*myAction)(myArg,myArg1,myArg2);
1554 typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
1557 * main_thread_run must be executed in the qt main thread
1558 * It is activated by calling ProcessVoidEvent
1560 void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
1562 // in case node "said" something during changing state through notification mechanism - output it
1563 myMain->syncNotification();
1565 // "kill" or undefined event came
1566 if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
1567 ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
1568 ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
1572 else { // a "normal" execution event came
1574 if ( aNode != NULL && !CORBA::is_nil( aNode ) )
1575 aName = aNode->Name();
1577 // What follow is not quite sure. The entire function is posted to the main qt thread.
1578 // So all executions are serialized. Is it really possible to call execute when another
1579 // execute is running. I don't think so (C Caremoli)
1580 // this function is asynchronious. The call does NOT wait when SUPERVGUI_Main::execute finishes
1581 // handling the event. So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
1582 // on the next loop iteration, BEFORE previous SUPERVGUI_Main::execute finished.
1583 myMain->execute(aName, aState );
1586 // execution is finished. just set a "finished" message(s)
1587 if ( !myIsActive ) {
1588 switch ( myMain->getDataflow()->State() ) {
1589 case SUPERV_Editing :
1590 myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()?
1591 tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
1593 case SUPERV_Suspend :
1594 myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
1597 myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
1600 myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
1603 myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
1607 // asv 03.02.05 : fix for PAL6859, not very good, but works..
1609 } // end of if !myIsActive
1612 void SUPERVGUI_Thread::run()
1614 myMain->startTimer();
1616 // GUI cycle to handle events coming for Engine
1617 while ( myIsActive ) {
1619 SUPERV_CNode aNode = NULL;
1620 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1621 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1623 // blocking function of Engine. Return from there only after anEvent happens on node aNode
1624 myMain->getDataflow()->Event(aNode, aEvent, aState);
1626 ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
1628 } // end of while( myIsActive )
1633 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1637 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1638 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1640 Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1641 setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1642 setSizeGripEnabled( true );
1645 QGridLayout* TopLayout = new QGridLayout( this );
1646 TopLayout->setSpacing( 6 );
1647 TopLayout->setMargin( 11 );
1649 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1650 TopGroup->setColumnLayout(0, Qt::Vertical );
1651 TopGroup->layout()->setSpacing( 0 );
1652 TopGroup->layout()->setMargin( 0 );
1653 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1654 TopGroupLayout->setAlignment( Qt::AlignTop );
1655 TopGroupLayout->setSpacing( 6 );
1656 TopGroupLayout->setMargin( 11 );
1659 QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );
1660 TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1662 myDeltaTime = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
1663 myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1664 TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1667 QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup);
1668 TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1670 myTimeOut = new QLineEdit( TopGroup );
1671 myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1672 myTimeOut->setValidator( new QIntValidator(this) );
1673 myTimeOut->setMinimumSize( 100, 0 );
1674 myTimeOut->setReadOnly( isReadOnly );
1675 TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1678 QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup);
1679 TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1681 myDataStreamTrace = new QComboBox( TopGroup );
1682 myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1683 myDataStreamTrace->insertItem("WithoutTrace");
1684 myDataStreamTrace->insertItem("SummaryTrace");
1685 myDataStreamTrace->insertItem("DetailedTrace");
1686 TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1688 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1689 GroupButtons->setColumnLayout(0, Qt::Vertical );
1690 GroupButtons->layout()->setSpacing( 0 );
1691 GroupButtons->layout()->setMargin( 0 );
1692 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1693 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1694 GroupButtonsLayout->setSpacing( 6 );
1695 GroupButtonsLayout->setMargin( 11 );
1697 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
1698 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1700 GroupButtonsLayout->addWidget( okB, 0, 0 );
1701 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1702 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1704 TopLayout->addWidget( TopGroup, 0, 0 );
1705 TopLayout->addWidget( GroupButtons, 1, 0 );
1707 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
1708 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1716 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1717 Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1723 void SUPERVGUI_DSGraphParameters::setData() {
1726 SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1728 // myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1729 if (myGraph->IsStreamGraph()) {
1730 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1731 if (!SUPERV_isNull(aSGraph))
1732 aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1735 myDeltaTime->setValue(aDeltaTime);
1736 myTimeOut->setText(QString("%1").arg(aTimeOut));
1737 myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1743 void SUPERVGUI_DSGraphParameters::accept() {
1744 // myGraph->SetStreamParams( myTimeOut->text().toLong(),
1745 // (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1746 // myDeltaTime->value());
1747 if (myGraph->IsStreamGraph()) {
1748 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1749 if (!SUPERV_isNull(aSGraph))
1750 aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1751 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1752 myDeltaTime->value());