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 );
652 SUPERVGUI_Main::setModifiedFlag();
657 // mkr : PAL8150 : synchronize many views of the same dataflow ("Display" operation for dataflow)
658 void SUPERVGUI_Main::syncPutInStudy()
661 if ( STD_Application* app = dynamic_cast<STD_Application*>( study->application() ) ) {
662 ViewManagerList aVMList;
663 app->viewManagers( SUPERVGraph_Viewer::Type(), aVMList );
664 SUIT_ViewManager* aVM;
665 for ( aVM = aVMList.first(); aVM; aVM = aVMList.next() ) {
666 QPtrVector<SUIT_ViewWindow> aVWList = aVM->getViews();
667 for ( int i = 0; i < aVWList.count(); i++ ) {
668 SUPERVGraph_ViewFrame* aVW = dynamic_cast<SUPERVGraph_ViewFrame*>( aVWList[i] );
669 QObjectList* aMainList = aVW->queryList("SUPERVGUI_Main");
670 if ( aMainList->count() == 1 ) {
671 SUPERVGUI_Main* aMain = dynamic_cast<SUPERVGUI_Main*>( aMainList->first() );
673 if ( !CORBA::is_nil( aMain->getDataflow() )
675 !QString(aMain->getDataflow()->getIOR()).compare(getDataflow()->getIOR()) // equal dataflows
677 aMain != this ) { // not equal mains
679 // check "myInStudy" field of output ports of original main (i.e. this main)
680 // and synchronize this property for nodes' output ports of dublicate main (i.e. of aMain)
681 SUPERV_Nodes nodes = aMain->getDataflow()->Nodes();
683 SYNCPUTINSTUDY(CNodes);
684 SYNCPUTINSTUDY(FNodes);
685 SYNCPUTINSTUDY(INodes);
686 SYNCPUTINSTUDY(GNodes);
687 SYNCPUTINSTUDY(LNodes);
688 SYNCPUTINSTUDY(ELNodes);
689 SYNCPUTINSTUDY(SNodes);
690 SYNCPUTINSTUDY(ESNodes);
691 SYNCPUTINSTUDY(Graphs);
693 setRunTime( aMain->getRunTime() );
704 void SUPERVGUI_Main::run( const bool andSuspend ) {
705 Trace("SUPERVGUI_Main::run");
706 if ( SUPERV_isNull(dataflow) )
709 if ( dataflow->IsEditing() ) { // not currently Executing
711 // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here..
712 Editing(); // remove old executor, update GUI (all nodes to "No Status")
714 if ( !dataflow->IsValid() ) {
715 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTVALID") + QString(" : ") + QString(dataflow->Messages()));
717 else if (!dataflow->IsExecutable()) {
718 QString aMessage = QString(dataflow->Messages());
719 if ( aMessage.isEmpty() ) // mkr : IPAL11471
720 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
722 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE") + QString(" : ") + aMessage);
724 else if (myCanvasView->isAnyLinkCreating()) {
725 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
728 myRunTime = QDateTime::currentDateTime();
729 const bool result = andSuspend ? dataflow->Start() : dataflow->Run();
731 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
732 if ( dataflow->State() == SUPERV::ErrorState ) {
737 //myExecuted = true; // set to true on first execution. for correct publishing in Study
738 myThread->startThread(tr("MSG_GRAPH_STARTED"));
743 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
748 void SUPERVGUI_Main::kill() {
749 Trace("SUPERVGUI_Main::kill");
750 if ((SUPERV_isNull(dataflow)))
753 if (dataflow->IsEditing()) {
754 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
756 else if (dataflow->Kill()) {
757 getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
761 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
765 void SUPERVGUI_Main::suspendResume() {
766 Trace("SUPERVGUI_Main::suspendResume");
768 if ((SUPERV_isNull(dataflow))) return;
770 if (dataflow->IsEditing()) {
771 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
772 } else if (dataflow->State() == SUPERV_Suspend) {
773 if (dataflow->Resume()) {
774 myThread->startThread(tr("MSG_DF_RESUMED"));
776 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
779 if (dataflow->Suspend()) {
781 getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
783 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
787 /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere,
788 the comment from kloss below may be explaining it, but it's in French and I do not understand it..
789 It also calls deprecated method of Engine: ReStart().
790 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
791 Trace("SUPERVGUI_Main::stopRestart");
792 if ((SUPERV_isNull(dataflow))) return;
794 if (dataflow->IsEditing()) {
795 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
796 } else if (dataflow->State() == SUPERV_Stop) {
797 if (dataflow->ReStart()) {
798 message->setMessage(tr("MSG_DF_RESTARTED"));
801 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
804 if (dataflow->Stop()) {
807 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
812 void SUPERVGUI_Main::addNode() {
813 Trace("SUPERVGUI_Main::addNode");
815 if ( !ReadyToModify() ) // null dataflow or executing, ..
818 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
820 MESSAGE("NULL Supervision module!");
824 //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960
825 aSupMod->getBrowser()->choose();
829 * Add Computation node
831 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
832 switch (myCurrentView) {
840 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode( resMgr(), myCanvas, this, theNode);
841 aNode->move(theNode->X(), theNode->Y());
842 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
853 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
854 switch (myCurrentView) {
862 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode( resMgr(), myCanvas, this, theNode);
863 aNode->move(theNode->X(), theNode->Y());
864 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
875 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
876 switch (myCurrentView) {
884 SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode( resMgr(), myCanvas, this, theStartNode);
885 aStartNode->move(theStartNode->X(), theStartNode->Y());
886 if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
888 SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode( resMgr(), myCanvas, this, theEndNode, aStartNode);
889 aEndNode->move(theEndNode->X(), theEndNode->Y());
890 if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
904 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
905 switch (myCurrentView) {
913 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode( resMgr(), myCanvas, this, theNode);
914 aNode->move(theNode->X(), theNode->Y());
915 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
923 SUPERVGUI_CanvasArray* SUPERVGUI_Main::getCanvasArray() {
924 Trace("SUPERVGUI_Main::getCanvasArray");
928 SUPERVGUI_ArrayView* SUPERVGUI_Main::getArrayView() {
929 Trace("SUPERVGUI_Main::getArrayView");
933 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
934 Trace("SUPERVGUI_Main::getCanvas");
938 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
939 Trace("SUPERVGUI_Main::getCanvasView");
940 return(myCanvasView);
943 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
944 Trace("SUPERVGUI_Main::getDataflow");
948 LogWindow* SUPERVGUI_Main::getMessage() {
949 Trace("SUPERVGUI_Main::getMessage");
953 SUIT_Study* SUPERVGUI_Main::getStudy() {
954 Trace("SUPERVGUI_Main::getStudy");
958 bool SUPERVGUI_Main::isArrayShown() {
959 Trace("SUPERVGUI_Main::isArrayShown");
960 return(myCurrentView == CANVASTABLE);
963 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
964 Trace("SUPERVGUI_Main::showPopup");
965 // To check is Supervision active?
966 if (myIsLocked) return;
967 //if (dataflow->IsExecuting()) return;
969 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
970 if ( !anApp->activeModule() ) return;
971 if ( anApp->activeModule()->moduleName().compare( anApp->moduleTitle( "SUPERV" ) ) !=0 ) return;
973 if (e->button() == RightButton) {
974 p->exec(e->globalPos());
978 void SUPERVGUI_Main::changeInformation() {
979 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
985 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
986 Trace("SUPERVGUI_Main::chooseData");
988 QString id = ((OB_ListItem*)item)->text(2);// <=> get entry
990 _PTR(SObject) object ( (( SalomeApp_Study* )study)->studyDS()->FindObjectID(id.latin1()) );
991 _PTR(GenericAttribute) anAttr;
992 if (object->FindAttribute(anAttr, "AttributeIOR")) {
993 _PTR(AttributeIOR) anIOR ( anAttr );
995 // asv : 13.12.04 : commented out use of portIn field, but it seems that it
996 // should be replaced with some analogious code... selection of IOR was done -
997 // put its value into port.
998 //portIn->setValue(ior);
1000 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1002 MESSAGE("NULL Supervision module!");
1008 setCursor(aSupMod->getCursor());
1009 objectBrowser->setCursor(aSupMod->getCursor());
1010 aSupMod->putInfo("");
1016 _PTR(SObject) SearchOrCreateSOWithName( _PTR(Study) const theStudy,
1017 _PTR(StudyBuilder) const theBuilder,
1018 _PTR(SObject) const theSO,
1019 const char* theName,
1020 bool* theDoneSomething ) {
1021 _PTR(SObject) aResult;
1022 _PTR(AttributeName) aName;
1023 _PTR(GenericAttribute) anAttr;
1024 _PTR(ChildIterator) anIterator ( theStudy->NewChildIterator(theSO) );
1025 for (; anIterator->More(); anIterator->Next()) {
1026 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1027 aName = _PTR(AttributeName) ( anAttr );
1028 if (strcmp(aName->Value().c_str(), theName) == 0) {
1029 aResult = anIterator->Value();
1035 // if aResule was found then theDoneSomething=false and we return
1036 *theDoneSomething = !aResult ? 1 : 0;//->_is_nil();
1037 if ( !*theDoneSomething )
1041 aResult = theBuilder->NewObject( theSO );
1042 anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1043 aName = _PTR(AttributeName) ( anAttr );
1044 aName->SetValue(theName);
1049 * Return true if dataflow is already in the study
1051 bool SUPERVGUI_Main::isDataflowInStudy() const {
1052 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1053 _PTR(SObject) aSO ( aStudy->FindObjectIOR( dataflow->getIOR() ) );
1054 return ( aSO ? true : false );
1058 * Create a "Supervision" object in the Study and a "dataflow" object under it
1059 * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found).
1061 _PTR(SObject) createDataflowSObj( SUIT_Study* study,
1062 SUPERV::Graph_var dataflow,
1063 _PTR(StudyBuilder) aBuilder,
1064 bool& aDoneSomething ) {
1065 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1066 _PTR(GenericAttribute) anAttr;
1067 _PTR(AttributeName) aName;
1069 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1070 _PTR(SObject) aSO = aStudy->FindObjectIOR( dataflow->getIOR() );
1071 if ( !aSO ) { // dataflow SObject not found in the study
1072 aDoneSomething = true;
1073 _PTR(SComponent) aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1074 if ( !aComponent ) { // is supervision component not found, then create it
1075 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1076 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1077 aName = _PTR(AttributeName) ( anAttr );
1078 aName->SetValue( (( CAM_Application* )(study->application()))->moduleTitle( "SUPERV" ).latin1() );
1080 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1081 _PTR(AttributePixMap) aPixmap ( anAttr );
1082 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1084 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1086 aBuilder->DefineComponentInstance(aComponent, SalomeApp_Application::orb()->object_to_string(aSupMod->getEngine()));
1087 //dynamic_cast<SALOMEDS_Study*>( aStudy )->ConvertObjectToIOR(aSupMod->getEngine()));
1088 else MESSAGE("NULL Supervision module!");
1091 // create dataflow SObject ("aNewDataflow_1")
1092 aSO = aBuilder->NewObject(aComponent);
1093 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1094 aName = _PTR(AttributeName) ( anAttr );
1095 aName->SetValue(dataflow->Name());
1096 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1097 _PTR(AttributeIOR) anIORAttr ( anAttr );
1098 anIORAttr->SetValue(dataflow->getIOR());
1104 void SUPERVGUI_Main::addDataflowToStudy() {
1106 _PTR(StudyBuilder) aBuilder ( (( SalomeApp_Study* )study)->studyDS()->NewBuilder() );
1107 aBuilder->NewCommand();
1108 _PTR(SObject) aDF ( createDataflowSObj( study, dataflow, aBuilder, isCreated ) );
1110 aBuilder->CommitCommand();
1111 // what is this register/unregister?? don't know..
1112 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1114 MESSAGE("NULL Supervision module!");
1117 aSupMod->unregisterGraph(this);
1118 aSupMod->registerGraph(dataflow->getIOR(), this);
1120 if ( !myThread->running() )
1121 aSupMod->updateObjBrowser();
1124 MESSAGE( "ERROR: failed to find or create dataflow SObject" );
1125 aBuilder->AbortCommand();
1129 bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) {
1130 Trace("SUPERVGUI_Main::putDataStudy");
1132 bool PublishOtherComponent = false;
1134 // static variable to ensure that only one instance (thread) is executing this function
1135 static bool isIn = false;
1136 if (isIn) return true;
1139 _PTR(Study) aStudy = (( SalomeApp_Study* )study)->studyDS();
1140 const bool aLocked = aStudy->GetProperties()->IsLocked();
1141 _PTR(StudyBuilder) aBuilder ( aStudy->NewBuilder() );
1142 bool aDoneSomething = false;
1144 // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it.
1146 MESSAGE( "The study is locked and can not be modified!" );
1151 // check if the port and its node are good
1152 if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) {
1153 MESSAGE( "putInStudy ERROR: port or node are NULL!" );
1158 // open new command. Commit or Abort it depending on aDoneSomething variable or error
1159 aBuilder->NewCommand();
1161 // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study
1162 _PTR(SObject) aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething );
1165 MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" );
1166 aBuilder->AbortCommand();
1171 // Create "Run -> Time and date, etc." SObjects
1172 if ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value
1174 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO
1175 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO
1176 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO
1177 aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO
1179 // create IOR attribute for port SObject (usually with "return" name)
1180 _PTR(GenericAttribute) anAttr ( aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR") );
1181 _PTR(AttributeIOR) anIORAttr ( anAttr );
1183 // if we have not created anything (all SObject already existed) and we have the same IORAttribute
1184 // on the needed SObject -> then don't do anything! it's already there!
1185 if ( !aDoneSomething && strcmp(anIORAttr->Value().c_str(), p->ToString()) == 0 ) {
1186 aBuilder->AbortCommand();
1191 aDoneSomething = true; // going to set some value to anIORAttr any way from this point..
1193 // set object value to the study: if object is external, then put it with
1194 // help of the specific component - owner
1196 // get according component driver for result object
1197 SALOME_LifeCycleCORBA aLCC( myNService );
1198 SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() );
1199 if ( !aFNode->_is_nil() ) {
1200 Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() );
1201 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent );
1202 if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object
1203 CORBA::Object_ptr anObject = new CORBA::Object();
1204 CORBA::Any* anAny = p->ToAny();
1205 (*anAny) >>= anObject;
1207 if ( aDriver->CanPublishInStudy( anObject ) ) {
1208 SALOMEDS::SObject_var aTmpSO;// = aSO;
1209 SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aStudy.get() );
1210 if ( !aSStudy ) return false;
1212 aTmpSO = aDriver->PublishInStudy( aSStudy->GetStudy(), aTmpSO, anObject, "" );
1213 aBuilder->Addreference(aSO, _PTR(SObject)(new SALOMEDS_SObject( aTmpSO )) );
1214 PublishOtherComponent = true;
1216 catch ( ... ) { // mkr : PAL8150
1219 else { // can't publish object: abort transaction
1220 MESSAGE( "CanPublishInStudy() returned FALSE. ok, AbortCommand.." );
1221 aBuilder->AbortCommand();
1226 else { // component has no driver, but could store IORs (like Calculator)
1227 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1229 aBuilder->Addreference(aSO, anIORSO);
1231 PublishOtherComponent = true;
1233 else { // Hm... the object (==port value) was not found, so we don't publish it.
1234 MESSAGE( "The object (==port value) was not found, so we don't publish it" );
1235 aBuilder->AbortCommand();
1241 else { // FNode is NULL -> bad
1242 MESSAGE( "FNode is NULL." );
1243 if ( SUPERV::INode::_narrow( p->Node() ) ) { // mkr : IPAL10175
1244 _PTR(SObject) anIORSO ( aStudy->FindObjectIOR( p->ToString() ) );
1246 aBuilder->Addreference(aSO, anIORSO);
1249 MESSAGE( "FNode and INode are NULL. Not good at all. Aborting command." );
1250 aBuilder->AbortCommand();
1257 anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition
1261 if ( aDoneSomething )
1262 aBuilder->CommitCommand();
1264 aBuilder->AbortCommand();
1266 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1268 if ( PublishOtherComponent )
1269 dynamic_cast<SalomeApp_Application*>( study->application() )->updateObjectBrowser(true);
1271 aSupMod->updateObjBrowser();
1273 else MESSAGE("NULL Supervision module!");
1275 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
1276 if(app) app->updateActions();
1282 void SUPERVGUI_Main::ActivatePanning()
1284 if (myCanvasView->isVisible()) {
1285 myCanvasView->ActivatePanning();
1286 } else if (myArrayView->isVisible()) {
1287 myArrayView->ActivatePanning();
1292 void SUPERVGUI_Main::ResetView()
1294 if (myCanvasView->isVisible()) {
1295 myCanvasView->ResetView();
1296 } else if (myArrayView->isVisible()) {
1297 myArrayView->ResetView();
1301 void SUPERVGUI_Main::syncNotification() {
1311 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1312 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) { // mkr : PAL7037
1314 mess += "NOTIF: "; mess += graph;
1315 mess += " / " ; mess += node;
1316 mess += " / " ; mess += type;
1317 mess += " / " ; mess += message;
1318 getMessage()->putMessage(mess.latin1());
1323 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1324 char* sender, long counter, char* date, long stamp) {
1325 Trace("SUPERVGUI_Main::isFiltered");
1327 if (strcmp(getDataflow()->Name(), graph) == 0) {
1328 SUPERVGUI_CanvasNode* n;
1330 // mkr : PAL7037 -->
1331 if (myCurrentView == CANVASTABLE)
1332 nodes = myArray->queryList("SUPERVGUI_CanvasNode");
1334 nodes = myCanvas->queryList("SUPERVGUI_CanvasNode");
1335 // mkr : PAL7037 <--
1336 QObjectListIt i(*nodes);
1337 while ((n=(SUPERVGUI_CanvasNode*)i.current()) != 0) {
1339 if (strcmp(n->name(), node) == 0) {
1340 if (strcmp(type, NOTIF_WARNING) == 0) {
1342 } else if (strcmp(type, NOTIF_STEP) == 0) {
1344 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1346 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1353 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1354 fprintf( myLogFile, "NOTIF %ld\t%s\t%s\t%ld\t%s\t%s\t%s\t%s\n", stamp, date, sender, counter, graph, node, type, message );
1355 fflush( myLogFile );
1361 void SUPERVGUI_Main::closeEvent(QCloseEvent* e) {
1366 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1368 myCanvas->setBackgroundColor(color);
1369 myCanvasView->setPaletteBackgroundColor(color.light());
1370 myArray->setBackgroundColor(color);
1371 myArrayView->setPaletteBackgroundColor(color.light());
1373 SUPERVGraph_View::setPaletteBackgroundColor(color);
1376 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1377 return myEventNodes;
1380 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1381 myEventNodes = theEventNodes;
1384 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1388 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1389 myStates = theStates;
1392 int SUPERVGUI_Main::getNodesNumber() {
1393 //create a list of nodes of the graph
1394 SUPERV_Nodes nodes = getDataflow()->Nodes();
1395 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1396 nodes->INodes.length() + nodes->GNodes.length() +
1397 nodes->LNodes.length() + nodes->SNodes.length();
1401 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1405 void SUPERVGUI_Main::startTimer() {
1406 myTimer->start(500);
1409 void SUPERVGUI_Main::executionFinished() {
1410 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
1412 //aSupMod->updateObjBrowser();
1413 // PAL10611: update all modules data
1414 aSupMod->getApp()->updateObjectBrowser(true);
1415 else MESSAGE("NULL Supervision module!");
1421 void SUPERVGUI_Main::checkExecution() {
1422 if (myThread->finished()) {
1424 executionFinished();
1429 * Editing() is to be called by any operation in GUI before modification of a datamodel
1430 * (add/remove ports or nodes, etc.). It is used to resolve inconsistancies between 2 data models
1431 * in Engine: Editor and Executor. During and after execution, the values of ports and statuses of nodes
1432 * are taken from Executor data model. But when user starts editing the graph - these changes must
1433 * be applied to Editor data model. This function destroys Executor data model and moves to Editor.
1435 void SUPERVGUI_Main::Editing() {
1436 if ( !SUPERV_isNull( dataflow ) )
1437 dataflow->Editing();
1439 // updata GUI, Nodes' statuses and Ports' values could change.
1443 void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode)
1445 // mkr: since the deletion of the node allow only in CANVAS view,
1446 // it is necessary to remove the CanvasArray's children, which
1447 // have the same CNode engine as deleting node. This CNode is given
1450 const QObjectList* aChList = myArray->children();
1451 if ( aChList ) { // asv 27.01.05 : fix for 7817
1452 QObjectListIt aItChList(*aChList);
1453 SUPERVGUI_CanvasNode* anObjNode;
1454 while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) {
1456 if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) {
1457 myArray->removeChild(anObjNode);
1461 } // end of if ( ChList )
1466 * ReadyToModify() must be called before any modification
1467 * operation - asks to kill execution of dataflow. If returns false -
1468 * modification (==Editing() ) is not allowed.
1470 bool SUPERVGUI_Main::ReadyToModify() {
1471 if ( CORBA::is_nil( dataflow ) )
1473 if ( dataflow->IsExecuting() ) {
1474 bool quit = SUIT_MessageBox::warn2( SUIT_Session::session()->activeApplication()->desktop(), // 0=Yes, 1=No
1475 tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 );
1476 if ( quit ) // user selected NOT to kill dataflow and NOT to add new node
1478 else if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that
1479 kill(); // checking again for IsExecuting to be sure that it was not finished while MB was up
1484 void SUPERVGUI_Main::resizeView( QResizeEvent* theEvent )
1486 if ( (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) && getCanvas() )
1487 if ( getCanvas()->width() < theEvent->size().width()
1489 getCanvas()->height() < theEvent->size().height() )
1490 getCanvas()->resize( theEvent->size().width(), theEvent->size().height() );
1491 if ( myCurrentView == CANVASTABLE && getCanvasArray() )
1492 if ( getCanvasArray()->width() < theEvent->size().width()
1494 getCanvasArray()->height() < theEvent->size().height() )
1495 getCanvasArray()->resize( theEvent->size().width(), theEvent->size().height() );
1499 Sets a modified flag in an active study
1501 void SUPERVGUI_Main::setModifiedFlag()
1503 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
1505 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1507 _PTR(Study) studyDS = study->studyDS();
1508 _PTR(SComponent) sco = studyDS->FindComponent(STUDY_SUPERVISION);
1510 _PTR(StudyBuilder) builder = studyDS->NewBuilder();
1511 _PTR(GenericAttribute) ga;
1512 ga = builder->FindOrCreateAttribute(sco, "AttributeParameter");
1513 _PTR(AttributeParameter) ap(ga);
1515 ap->SetBool("SUPERVISOR_MODIFIED_FLAG",1);
1516 app->updateActions();
1524 /******************************* SUPERVGUI_Thread class ****************************************/
1525 SUPERVGUI_Thread::SUPERVGUI_Thread()
1531 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1533 //it is a virtual destructor and needs to be determine here
1536 void SUPERVGUI_Thread::startThread(const char* m)
1541 myMain->getMessage()->putMessage(m);
1548 void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain )
1553 void SUPERVGUI_Thread::KillThread( bool theValue )
1556 myIsActive = !(theValue);
1560 template<class TObject, typename TArg, typename TArg1, typename TArg2,
1561 typename TStoreArg = TArg, typename TStoreArg1 = TArg1, typename TStoreArg2 = TArg2>
1562 class TVoidMemFun3ArgEvent: public SALOME_Event{
1564 typedef void (TObject::* TAction)(TArg,TArg1,TArg2);
1565 TVoidMemFun3ArgEvent(TObject* theObject, TAction theAction, TArg theArg, TArg1 theArg1, TArg2 theArg2):
1566 myObject(theObject),
1567 myAction(theAction),
1572 virtual void Execute(){
1573 (myObject->*myAction)(myArg,myArg1,myArg2);
1583 typedef TVoidMemFun3ArgEvent<SUPERVGUI_Thread, SUPERV_CNode&, SUPERV::GraphEvent&, SUPERV::GraphState&> TMainRunEvent;
1586 * main_thread_run must be executed in the qt main thread
1587 * It is activated by calling ProcessVoidEvent
1589 void SUPERVGUI_Thread::main_thread_run(SUPERV_CNode& aNode, SUPERV::GraphEvent& aEvent, SUPERV::GraphState& aState)
1591 // in case node "said" something during changing state through notification mechanism - output it
1592 myMain->syncNotification();
1594 // "kill" or undefined event came
1595 if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) ||
1596 ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) ||
1597 ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) {
1601 else { // a "normal" execution event came
1603 if ( aNode != NULL && !CORBA::is_nil( aNode ) )
1604 aName = aNode->Name();
1606 // What follow is not quite sure. The entire function is posted to the main qt thread.
1607 // So all executions are serialized. Is it really possible to call execute when another
1608 // execute is running. I don't think so (C Caremoli)
1609 // this function is asynchronious. The call does NOT wait when SUPERVGUI_Main::execute finishes
1610 // handling the event. So: SUPERVGUI_Main::execute must be fast, in order we don't get here again
1611 // on the next loop iteration, BEFORE previous SUPERVGUI_Main::execute finished.
1612 myMain->execute(aName, aState );
1615 // execution is finished. just set a "finished" message(s)
1616 if ( !myIsActive ) {
1617 switch ( myMain->getDataflow()->State() ) {
1618 case SUPERV_Editing :
1619 myMain->getMessage()->putMessage( myMain->getDataflow()->IsReadOnly()?
1620 tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") );
1622 case SUPERV_Suspend :
1623 myMain->getMessage()->putMessage( tr("MSG_GRAPH_SUSPENDED") );
1626 myMain->getMessage()->putMessage( tr("MSG_GRAPH_FINISHED") );
1629 myMain->getMessage()->putMessage( tr("MSG_GRAPH_ABORTED") );
1632 myMain->getMessage()->putMessage( tr("MSG_GRAPH_KILLED") );
1636 // asv 03.02.05 : fix for PAL6859, not very good, but works..
1638 } // end of if !myIsActive
1641 void SUPERVGUI_Thread::run()
1643 myMain->startTimer();
1645 // GUI cycle to handle events coming for Engine
1646 while ( myIsActive ) {
1648 SUPERV_CNode aNode = NULL;
1649 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1650 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1652 // blocking function of Engine. Return from there only after anEvent happens on node aNode
1653 myMain->getDataflow()->Event(aNode, aEvent, aState);
1655 ProcessVoidEvent( new TMainRunEvent( this, &SUPERVGUI_Thread::main_thread_run,aNode, aEvent, aState ) );
1657 } // end of while( myIsActive )
1662 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1666 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1667 : QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1669 Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1670 setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1671 setSizeGripEnabled( true );
1674 QGridLayout* TopLayout = new QGridLayout( this );
1675 TopLayout->setSpacing( 6 );
1676 TopLayout->setMargin( 11 );
1678 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1679 TopGroup->setColumnLayout(0, Qt::Vertical );
1680 TopGroup->layout()->setSpacing( 0 );
1681 TopGroup->layout()->setMargin( 0 );
1682 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1683 TopGroupLayout->setAlignment( Qt::AlignTop );
1684 TopGroupLayout->setSpacing( 6 );
1685 TopGroupLayout->setMargin( 11 );
1688 QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );
1689 TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1691 myDeltaTime = new QtxDblSpinBox( 0.0, 1.0, 0.1, TopGroup );
1692 myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1693 TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1696 QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup);
1697 TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1699 myTimeOut = new QLineEdit( TopGroup );
1700 myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1701 myTimeOut->setValidator( new QIntValidator(this) );
1702 myTimeOut->setMinimumSize( 100, 0 );
1703 myTimeOut->setReadOnly( isReadOnly );
1704 TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1707 QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup);
1708 TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1710 myDataStreamTrace = new QComboBox( TopGroup );
1711 myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1712 myDataStreamTrace->insertItem("WithoutTrace");
1713 myDataStreamTrace->insertItem("SummaryTrace");
1714 myDataStreamTrace->insertItem("DetailedTrace");
1715 TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1717 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1718 GroupButtons->setColumnLayout(0, Qt::Vertical );
1719 GroupButtons->layout()->setSpacing( 0 );
1720 GroupButtons->layout()->setMargin( 0 );
1721 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1722 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1723 GroupButtonsLayout->setSpacing( 6 );
1724 GroupButtonsLayout->setMargin( 11 );
1726 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
1727 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1729 GroupButtonsLayout->addWidget( okB, 0, 0 );
1730 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1731 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1733 TopLayout->addWidget( TopGroup, 0, 0 );
1734 TopLayout->addWidget( GroupButtons, 1, 0 );
1736 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
1737 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1745 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1746 Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1752 void SUPERVGUI_DSGraphParameters::setData() {
1753 CORBA::Double aDeltaTime;
1754 CORBA::Long aTimeOut;
1755 SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1757 // myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1758 if (myGraph->IsStreamGraph()) {
1759 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1760 if (!SUPERV_isNull(aSGraph))
1761 aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1764 myDeltaTime->setValue(aDeltaTime);
1765 myTimeOut->setText(QString("%1").arg(aTimeOut));
1766 myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1772 void SUPERVGUI_DSGraphParameters::accept() {
1773 // myGraph->SetStreamParams( myTimeOut->text().toLong(),
1774 // (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1775 // myDeltaTime->value());
1776 if (myGraph->IsStreamGraph()) {
1777 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1778 if (!SUPERV_isNull(aSGraph))
1779 aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1780 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1781 myDeltaTime->value());