From 097f9667b76db86426a194bd458a3243ce13e4b9 Mon Sep 17 00:00:00 2001 From: asv Date: Thu, 3 Feb 2005 12:52:33 +0000 Subject: [PATCH] Improvement for handling node events coming from Engine. SUPERVGUI_Thread::run(), Main::execute(), etc. methods were improved, several unsused methods were removed. --- src/SUPERVGUI/SUPERVGUI.cxx | 2 +- src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx | 6 +- src/SUPERVGUI/SUPERVGUI_Main.cxx | 175 +++++++------------------ src/SUPERVGUI/SUPERVGUI_Main.h | 1 - 4 files changed, 54 insertions(+), 130 deletions(-) diff --git a/src/SUPERVGUI/SUPERVGUI.cxx b/src/SUPERVGUI/SUPERVGUI.cxx index a294f89..8b29eec 100644 --- a/src/SUPERVGUI/SUPERVGUI.cxx +++ b/src/SUPERVGUI/SUPERVGUI.cxx @@ -454,7 +454,7 @@ bool SUPERVGUI::createDataflow( const NEW_DF_MODE mode ) { aGraph = engine->StreamGraph( MAIN_NEW ); if ( CORBA::is_nil( aGraph ) ) { - QString msg( mode == New ? QString("MSG_CANT_CREATE_DF") : QString("MSG_BAD_FILE").arg(f) ); + QString msg( mode == New ? tr("MSG_CANT_CREATE_DF") : tr("MSG_BAD_FILE").arg(f) ); QAD_MessageBox::warn1( QAD_Application::getDesktop(), tr("ERROR"), tr(msg), tr("BUT_OK") ); return false; } diff --git a/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx b/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx index 1cbe56f..a7469ff 100644 --- a/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx +++ b/src/SUPERVGUI/SUPERVGUI_CanvasNode.cxx @@ -20,6 +20,8 @@ using namespace std; #include "SALOMEGUI_NameDlg.h" #include "QAD_MessageBox.h" +#include "QAD_Message.h" + SUPERVGUI_CanvasNode::SUPERVGUI_CanvasNode(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode, bool theIsCell): QObject(theParent), @@ -406,7 +408,7 @@ void SUPERVGUI_CanvasNode::suspendResume() { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE")); } else { syncOnEvent(SUPERV::SuspendReadyState); - myMain->getMyThread()->stopThread(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2")); + myMain->getMessage()->setMessage(tr("MSG_NODE_SUSPENDED1")+myNode->Name()+tr("MSG_NODE_SUSPENDED2")); } } } @@ -418,7 +420,7 @@ void SUPERVGUI_CanvasNode::kill() { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE")); } else { syncOnEvent(SUPERV_Kill); - myMain->getMyThread()->stopThread(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2")); + myMain->getMessage()->setMessage(tr("MSG_NODE_KILLED1")+myNode->Name()+tr("MSG_NODE_KILLED2")); } } /* asv : 15.12.04 : commented out stopRestart() in Main and CanvasNode because it's not called from anywhere, diff --git a/src/SUPERVGUI/SUPERVGUI_Main.cxx b/src/SUPERVGUI/SUPERVGUI_Main.cxx index 3cd797d..4ef006a 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Main.cxx @@ -233,13 +233,13 @@ void SUPERVGUI_Main::syncAsync() { void SUPERVGUI_Main::execute( char * theNodeName, SUPERV::GraphState theNodeState ) { if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) { SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode"); - if ( aNode ) { + if ( aNode ) aNode->sync(); - } } else if (myCurrentView == CANVASTABLE) { SUPERVGUI_CanvasCellNode* aNode = (SUPERVGUI_CanvasCellNode*) myArray->child(theNodeName, "SUPERVGUI_CanvasCellNode"); - if (aNode) aNode->sync(); + if (aNode) + aNode->sync(); } // asv : 26.01.05 : Bug PAL7164 : puting out-value to study if the "put_to_Study" flag is set on a @@ -538,7 +538,7 @@ void SUPERVGUI_Main::kill() { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING")); } else if (dataflow->Kill()) { - myThread->stopThread(tr("MSG_GRAPH_KILLED")); + getMessage()->setMessage( tr("MSG_GRAPH_KILLED") ); sync(); } else { @@ -561,7 +561,7 @@ void SUPERVGUI_Main::suspendResume() { } else { if (dataflow->Suspend()) { sync(); - myThread->stopThread(tr("MSG_GRAPH_SUSPENDED")); + getMessage()->setMessage( tr("MSG_GRAPH_SUSPENDED") ); } else { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND")); } @@ -1243,24 +1243,18 @@ void SUPERVGUI_Thread::startThread(const char* m) { if (!myIsActive) { myIsActive = true; - //QThread::start(); - this->start(); + start(); myMain->getMessage()->setMessage(m); myMain->sync(); } } -void SUPERVGUI_Thread::stopThread(const char* m) -{ - myMain->getMessage()->setMessage(m); -} - -void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain) +void SUPERVGUI_Thread::setMain( SUPERVGUI_Main* theMain ) { myMain = theMain; } -void SUPERVGUI_Thread::KillThread(bool theValue) +void SUPERVGUI_Thread::KillThread( bool theValue ) { myMutex.lock(); myIsActive = !(theValue); @@ -1271,132 +1265,61 @@ typedef TVoidMemFun2ArgEvent TNodeSyn void SUPERVGUI_Thread::run() { - SUPERV_CNode aNode = NULL; - SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ; - SUPERV::GraphState aState = SUPERV::UndefinedState ; - - SUPERV_CNode aPrevNode = NULL; - SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ; - SUPERV::GraphState aPrevState = SUPERV::UndefinedState ; - - char * aName; - char * aPrevName; + myMain->startTimer(); - QPtrList< char * > anEventNodes; - QPtrList< SUPERV::GraphState > aStates; + // GUI cycle to handle events coming for Engine + while ( myIsActive ) { - myMain->startTimer(); + SUPERV_CNode aNode = NULL; + SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ; + SUPERV::GraphState aState = SUPERV::UndefinedState ; - while(myIsActive) { + // blocking function of Engine. Return from there only after anEvent happens on node aNode myMain->getDataflow()->Event(aNode, aEvent, aState); - if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState - || - aEvent == SUPERV::NoEvent && aState == SUPERV::NoState - || - aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) { - - if (myMain->getEventNodes().count()) { - myMain->removeEventNodes(); - } - if (myMain->getStates().count()) { - myMain->removeStates(); - } + // "kill" or undefined event came + if (( aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState ) || + ( aEvent == SUPERV::NoEvent && aState == SUPERV::NoState ) || + ( aEvent == SUPERV::KillEvent && aState == SUPERV::KillState )) { + myIsActive = false; } - else { - if ( aNode != NULL && !CORBA::is_nil( aNode ) ) { - aName = aNode->Name(); - } - - if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) { //first initialize aPrev... variables - anEventNodes = myMain->getEventNodes(); - anEventNodes.append( &aName ) ; - myMain->setEventNodes(anEventNodes); - - aStates = myMain->getStates(); - aStates.append( &aState ) ; - myMain->setStates(aStates); - } - else { - if ( aEvent == aPrevEvent && aState == aPrevState) { - QString aNameStr = aName; - QString aPrevNameStr = aPrevName; - if ( aNameStr != aPrevNameStr ) { - anEventNodes = myMain->getEventNodes(); - anEventNodes.append( &aName ) ; - myMain->setEventNodes(anEventNodes); - - aStates = myMain->getStates(); - aStates.append( &aState ) ; - myMain->setStates(aStates); - } - } - else { - anEventNodes = myMain->getEventNodes(); - anEventNodes.append( &aName ) ; - myMain->setEventNodes(anEventNodes); - - aStates = myMain->getStates(); - aStates.append( &aState ) ; - myMain->setStates(aStates); - } - } - } - if (!myIsActive) { - switch (myMain->getDataflow()->State()) { + else { // a "normal" execution event came + char* aName = NULL; + if ( aNode != NULL && !CORBA::is_nil( aNode ) ) + aName = aNode->Name(); + + // this function is asynchronious. The call does NOT wait when SUPERVGUI_Main::execute finishes + // handling the event. So: SUPERVGUI_Main::execute must be fast, in order we don't get here again + // on the next loop iteration, BEFORE previous SUPERVGUI_Main::execute finished. + ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aName, aState ) ); + } + + // execution is finished. just set a "finished" message(s) + if ( !myIsActive ) { + switch ( myMain->getDataflow()->State() ) { case SUPERV_Editing : - stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING")); - break; - + myMain->getMessage()->setMessage( myMain->getDataflow()->IsReadOnly()? + tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING") ); + break; case SUPERV_Suspend : - stopThread(tr("MSG_GRAPH_SUSPENDED")); - break; - + myMain->getMessage()->setMessage( tr("MSG_GRAPH_SUSPENDED") ); + break; case SUPERV_Done : - stopThread(tr("MSG_GRAPH_FINISHED")); - break; - + myMain->getMessage()->setMessage( tr("MSG_GRAPH_FINISHED") ); + break; case SUPERV_Error : - stopThread(tr("MSG_GRAPH_ABORTED")); - break; - + myMain->getMessage()->setMessage( tr("MSG_GRAPH_ABORTED") ); + break; case SUPERV_Kill: - stopThread(tr("MSG_GRAPH_KILLED")); + myMain->getMessage()->setMessage( tr("MSG_GRAPH_KILLED") ); break; - } - - break; - } - if ( myMain->getEventNodes().count() ) { - //if list not empty call execute() -> sync() - char * aNodeName = *(myMain->getEventNodes().getFirst()); - SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst()); + } // end of switch - // It is PROHIBITED to deal with widgets in a secondary thread, so event posting is used here - ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aNodeName, aNodeState ) ); - - myMain->removeFirstEN(); - myMain->removeFirstS(); - } - - aPrevNode = aNode; - aPrevEvent = aEvent; - aPrevState = aState; - - if ( aPrevNode == NULL || CORBA::is_nil( aPrevNode ) ) - aPrevName = ""; - else - aPrevName = aPrevNode->Name(); - - //usleep(10); - //msleep(5); - } - // VSR: 04/12/03 ---> update object browser ufter finishing -// qApp->lock(); -// myMain->getStudy()->updateObjBrowser(); -// qApp->unlock(); - // VSR: 04/12/03 <--- + // asv 03.02.05 : fix for PAL6859, not very good, but works.. + myMain->sync(); + } // end of if !myIsActive + } // end of while( myIsActive ) QThread::exit(); } diff --git a/src/SUPERVGUI/SUPERVGUI_Main.h b/src/SUPERVGUI/SUPERVGUI_Main.h index 131c918..ef8bd80 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.h +++ b/src/SUPERVGUI/SUPERVGUI_Main.h @@ -219,7 +219,6 @@ class SUPERVGUI_Thread : public QObject, public QThread { ~SUPERVGUI_Thread(); void startThread(const char* m); - void stopThread(const char* m); void setMain(SUPERVGUI_Main* theMain); public slots: -- 2.39.2