X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUPERVGUI%2FSUPERVGUI_Main.cxx;h=33e2a18d3523673749bc6813774d8b599052e14b;hb=ea7f29f75031ca13b9454f5e9ac73730f1f584eb;hp=667670f50c7d8459b3235889f7a5556724f19e17;hpb=3f6f0841df1a2c7c868c947bb373a14ab654a2ef;p=modules%2Fsuperv.git diff --git a/src/SUPERVGUI/SUPERVGUI_Main.cxx b/src/SUPERVGUI/SUPERVGUI_Main.cxx index 667670f..33e2a18 100644 --- a/src/SUPERVGUI/SUPERVGUI_Main.cxx +++ b/src/SUPERVGUI/SUPERVGUI_Main.cxx @@ -37,6 +37,7 @@ using namespace std; #include "QAD_Application.h" #include "QAD_RightFrame.h" #include "QAD_SpinBoxDbl.h" +#include "QAD_MessageBox.h" #include "NOTIFICATION.hxx" #include "SALOME_Event.hxx" @@ -67,8 +68,8 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th myWarning( false ), myStep( false ), myTrace( false ), - myVerbose( false ), - myGUIEventLoopFinished( true ) + myVerbose( false ) + //myExecuted( false ) { Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)"); theParent->setViewWidget(this); @@ -221,8 +222,8 @@ void SUPERVGUI_Main::filterNotification() { } void SUPERVGUI_Main::syncAsync() { - Trace("SUPERVGUI_Main::syncAsync"); - QTimer::singleShot(1, this, SLOT(sync())); + Trace("SUPERVGUI_Main::syncAsync"); + QTimer::singleShot(1, this, SLOT(sync())); } @@ -232,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 @@ -331,30 +332,33 @@ void SUPERVGUI_Main::showCanvas() { } void SUPERVGUI_Main::insertFile() { - Trace("SUPERVGUI_Main::insertFile"); - if ((SUPERV_isNull(dataflow))) return; + Trace("SUPERVGUI_Main::insertFile"); - Editing(); // PAL6170: GUI->Engine: setting "Editing" flag - - QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), - "", - "*.xml", - tr("MSG_GRAPH_INSERT"), - true); - if (!f.isEmpty()) { - if (dataflow->Import(f.latin1())) { - if (myCurrentView == CANVASTABLE) { - myArray->destroy(); - myArray->create(); - } - else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) { - myCanvas->merge(); - } - sync(); - } else { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f)); + if ( !ReadyToModify() ) // null dataflow or executing, .. + return; + + QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), + "", + "*.xml", + tr("MSG_GRAPH_INSERT"), + true); + if ( !f.isEmpty() ) { // not Cancel, but "OK" was pressed with valid file name + + Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> see 7960 + + if (dataflow->Import(f.latin1())) { + if (myCurrentView == CANVASTABLE) { + myArray->destroy(); + myArray->create(); + } + else { // (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) { + myCanvas->merge(); } + sync(); + } else { + QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f)); } + } } void SUPERVGUI_Main::copy() { @@ -488,12 +492,17 @@ void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame) } } -void SUPERVGUI_Main::run() { +void SUPERVGUI_Main::run( const bool andSuspend ) { Trace("SUPERVGUI_Main::run"); - if ((SUPERV_isNull(dataflow))) return; + if ( SUPERV_isNull(dataflow) ) + return; - if (dataflow->IsEditing()) { - if (!dataflow->IsValid()) { + if ( dataflow->IsEditing() ) { // not currently Executing + + // asv 31.01.05 : fix for PAL7854, Editing moved from SUPERVGUI.cxx runDataflow(), stepByStep() to here.. + Editing(); // remove old executor, update GUI (all nodes to "No Status") + + if ( !dataflow->IsValid() ) { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID")); } else if (!dataflow->IsExecutable()) { @@ -504,44 +513,15 @@ void SUPERVGUI_Main::run() { } else { myRunTime = QDateTime::currentDateTime(); - if ( !dataflow->Run() ) { + const bool result = andSuspend ? dataflow->Start() : dataflow->Run(); + if ( !result ) { QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE")); if ( dataflow->State() == SUPERV::ErrorState ) { kill(); } } else { - myThread->startThread(tr("MSG_GRAPH_STARTED")); - } - } - } - else { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING")); - } -} - - - -void SUPERVGUI_Main::startExecute() { - Trace("SUPERVGUI_Main::startExecute"); - if ((SUPERV_isNull(dataflow))) return; - - if (dataflow->IsEditing()) { - if (!dataflow->IsValid()) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID")); - } - else if (!dataflow->IsExecutable()) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE")); - } - else if (myCanvasView->isAnyLinkCreating()) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE")); - } - else { - myRunTime = QDateTime::currentDateTime(); - if (!dataflow->Start()) { - QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE")); - } - else { + //myExecuted = true; // set to true on first execution. for correct publishing in Study myThread->startThread(tr("MSG_GRAPH_STARTED")); } } @@ -561,7 +541,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 { @@ -584,7 +564,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")); } @@ -617,20 +597,11 @@ void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le */ void SUPERVGUI_Main::addNode() { Trace("SUPERVGUI_Main::addNode"); - if (SUPERV_isNull(dataflow)) return; - - if (dataflow->IsExecuting()) { - if (QMessageBox::warning(QAD_Application::getDesktop(), - tr("WARNING"), tr("MSG_GRAPH_ISRUN"), - QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) { - return; - } else { - kill(); - } - } - Editing(); // PAL6170: GUI->Engine: setting "Editing" flag - + if ( !ReadyToModify() ) // null dataflow or executing, .. + return; + + //Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, commented: PAL7960 Supervision.getBrowser()->choose(); } @@ -778,14 +749,11 @@ void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) { //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return; if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return; - checkIsInStudy(); if (e->button() == RightButton) { p->exec(e->globalPos()); } } - - void SUPERVGUI_Main::changeInformation() { SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly()); if (aDlg->exec() ) @@ -793,66 +761,6 @@ void SUPERVGUI_Main::changeInformation() { delete aDlg; } -// returns false, if can't add dataflow into the study -bool SUPERVGUI_Main::addStudy() { - Trace("SUPERVGUI_Main::addStudy"); - if (myIsFromStudy) return false; - if ((SUPERV_isNull(dataflow))) return false; - - SALOMEDS::Study_var aStudy = study->getStudyDocument(); - bool aLocked = aStudy->GetProperties()->IsLocked(); - // asv : 23.11.04 : if the study is locked -- then we can't put anything in it. - // fix for PAL6852. - if ( aLocked ) - return false; - - SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIORAttr; - SALOMEDS::AttributePixMap_var aPixmap; - QAD_Operation* op = new SALOMEGUI_ImportOperation( study ); - - // searching dataflow - SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR()); - if (aSO->_is_nil()) { // create new dataflow SObject - SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION); - if (aComponent->_is_nil()) { // is supervision component not found, then create it - QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study ); - anOperation->start(); - //if (aLocked) aStudy->GetProperties()->SetLocked(false); - aComponent = aBuilder->NewComponent(STUDY_SUPERVISION); - anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - //aName->SetValue(STUDY_SUPERVISION); - aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ); - anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap"); - aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); - aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" ); - aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine()); - //if (aLocked) aStudy->GetProperties()->SetLocked(true); - anOperation->finish(); - } - op->start(); - aSO = aBuilder->NewObject(aComponent); - anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - aName->SetValue(dataflow->Name()); - anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR"); - anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIORAttr->SetValue(dataflow->getIOR()); - op->finish(); - //if (aLocked) return false; - } - - sync(); - Supervision.unregisterGraph(this); - Supervision.registerGraph(dataflow->getIOR(), this); - myIsFromStudy = true; - return true; -} - - void SUPERVGUI_Main::chooseData(QListViewItem* item) { Trace("SUPERVGUI_Main::chooseData"); if (choosing) { @@ -882,88 +790,77 @@ void SUPERVGUI_Main::chooseData(QListViewItem* item) { } SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy, + const SALOMEDS::StudyBuilder_var theBuilder, const SALOMEDS::SObject_var theSO, const char* theName, - //QAD_Operation* theOperation, - bool* theStarted) { + bool* theDoneSomething ) { SALOMEDS::SObject_var aResult; SALOMEDS::AttributeName_var aName; SALOMEDS::GenericAttribute_var anAttr; - if (!*theStarted) { // optimisation - SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO); - for (; anIterator->More(); anIterator->Next()) { - if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - if (strcmp(aName->Value(), theName) == 0) { - aResult = anIterator->Value(); - break; - } + SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO); + for (; anIterator->More(); anIterator->Next()) { + if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) { + aName = SALOMEDS::AttributeName::_narrow(anAttr); + if (strcmp(aName->Value(), theName) == 0) { + aResult = anIterator->Value(); + break; } } } - if (!aResult->_is_nil()) return aResult; + + // if aResule was found then theDoneSomething=false and we return + *theDoneSomething = aResult->_is_nil(); + if ( !*theDoneSomething ) + return aResult; + // add new SObject - SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder(); - if (!*theStarted) { - *theStarted = true; - //theOperation->start(); - aBuilder->NewCommand(); - } - aResult = aBuilder->NewObject(theSO); - anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName"); + aResult = theBuilder->NewObject( theSO ); + anAttr = theBuilder->FindOrCreateAttribute(aResult, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theName); return aResult; } + +/** + * Return true if dataflow is already in the study + */ +bool SUPERVGUI_Main::isDataflowInStudy() const { + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR( dataflow->getIOR() ); + return ( !CORBA::is_nil( aSO ) ); +} -bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) { - Trace("SUPERVGUI_Main::putDataStudy"); - - // static variable to ensure that only one instance (thread) is executing this function - static bool isIn = false; - if (isIn) - return true; - else - isIn = true; - +/** + * Create a "Supervision" object in the Study and a "dataflow" object under it + * aDoneSomething will be true if "Supervision" or "dataflow" object were created (not found). + */ +SALOMEDS::SObject_var createDataflowSObj( QAD_Study* study, + SUPERV::Graph_var dataflow, + SALOMEDS::StudyBuilder_var aBuilder, + bool& aDoneSomething ) { SALOMEDS::Study_var aStudy = study->getStudyDocument(); - bool aLocked = aStudy->GetProperties()->IsLocked(); - // asv : 23.11.04 : if the study is locked -- then we can't put anything in it. - // fix for PAL6852. - if ( aLocked ) { - isIn = false; - return false; - } - - SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::AttributeName_var aName; SALOMEDS::AttributeIOR_var anIORAttr; SALOMEDS::AttributePixMap_var aPixmap; - bool aTransaction = false; - - // searching dataflow - SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR()); - if (aSO->_is_nil()) { // create new dataflow SObject + + // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study + SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR( dataflow->getIOR() ); + if ( aSO->_is_nil() ) { // dataflow SObject not found in the study + aDoneSomething = true; SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION); - if (aComponent->_is_nil()) { // is supervision component not found, then create it - aBuilder->NewCommand(); - //if (aLocked) aStudy->GetProperties()->SetLocked(false); + if ( aComponent->_is_nil() ) { // is supervision component not found, then create it aComponent = aBuilder->NewComponent(STUDY_SUPERVISION); anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); - //aName->SetValue(STUDY_SUPERVISION); aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ); anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap"); aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" ); aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine()); - //if (aLocked) aStudy->GetProperties()->SetLocked(true); - aBuilder->CommitCommand(); } - aTransaction = true; - aBuilder->NewCommand(); + // create dataflow SObject ("aNewDataflow_1") aSO = aBuilder->NewObject(aComponent); anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); @@ -973,66 +870,152 @@ bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) { anIORAttr->SetValue(dataflow->getIOR()); } - aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO - QString("Run ") + myRunTime.toString(), &aTransaction); - aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name(), &aTransaction); // get node SO - aSO = SearchOrCreateSOWithName(aStudy, aSO, inout, &aTransaction); // get in/out SO - aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name(), &aTransaction); // get port SO + return aSO; +} + +void SUPERVGUI_Main::addDataflowToStudy() { + bool isCreated; + SALOMEDS::StudyBuilder_var aBuilder = study->getStudyDocument()->NewBuilder(); + aBuilder->NewCommand(); + SALOMEDS::SObject_var aDF = createDataflowSObj( study, dataflow, aBuilder, isCreated ); + if ( !CORBA::is_nil( aDF ) ) { + aBuilder->CommitCommand(); + // what is this register/unregister?? don't know.. + Supervision.unregisterGraph(this); + Supervision.registerGraph(dataflow->getIOR(), this); - if (aTransaction) aBuilder->CommitCommand(); + if ( !myThread->running() ) + study->updateObjBrowser(); + } + else { + MESSAGE( "ERROR: failed to find or create dataflow SObject" ); + aBuilder->AbortCommand(); + } +} + +bool SUPERVGUI_Main::putDataStudy( SUPERV_Port p, const char* inout ) { + Trace("SUPERVGUI_Main::putDataStudy"); - anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR"); - anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); - if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) { + // static variable to ensure that only one instance (thread) is executing this function + static bool isIn = false; + if (isIn) return true; + else isIn = true; + + SALOMEDS::Study_var aStudy = study->getStudyDocument(); + const bool aLocked = aStudy->GetProperties()->IsLocked(); + SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr; + SALOMEDS::AttributeIOR_var anIORAttr; + SALOMEDS::AttributePixMap_var aPixmap; + bool aDoneSomething = false; + + // asv 23.11.04 : fix for PAL6852 if the study is locked -- then we can't put anything in it. + if ( aLocked ) { + MESSAGE( "The study is locked and can not be modified!" ); isIn = false; - return true; + return false; } - // set object value to the study: if object is external, then put it with - // help of the specific component - owner - if (p->IsIOR()) { - // get according component driver for result object - SALOME_LifeCycleCORBA aLCC(myNService); - SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node()); - if (!aFNode->_is_nil()) { - Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(), - aFNode->GetComponentName()); - SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent); - if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object - CORBA::Object_ptr anObject = new CORBA::Object(); - CORBA::Any* anAny = p->ToAny(); - (*anAny) >>= anObject; + + // check if the port and its node are good + if ( CORBA::is_nil( p ) || CORBA::is_nil( p->Node() ) ) { + MESSAGE( "putInStudy ERROR: port or node are NULL!" ); + isIn = false; + return false; + } + + // open new command. Commit or Abort it depending on aDoneSomething variable or error + aBuilder->NewCommand(); + + // Find or create "Supervisor -> aNewDataflow_1" SObjects in the study + SALOMEDS::SObject_var aSO = createDataflowSObj( study, dataflow, aBuilder, aDoneSomething ); + + if ( CORBA::is_nil( aSO ) ) { + MESSAGE( "ERROR: putDataStudy() could not find or create dataflow SObject" ); + aBuilder->AbortCommand(); + isIn = false; + return false; + } + + // Create "Run -> Time and date, etc." SObjects + if ( p->State() == SUPERV::ReadyState ) { // if port contains valid computed value + + aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, QString("Run ") + myRunTime.toString(), &aDoneSomething ); // get run time SO + aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Node()->Name(), &aDoneSomething ); // get node SO + aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, inout, &aDoneSomething ); // get in/out SO + aSO = SearchOrCreateSOWithName( aStudy, aBuilder, aSO, p->Name(), &aDoneSomething ); // get port SO + + // create IOR attribute for port SObject (usually with "return" name) + anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR"); + anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr); + + // if we have not created anything (all SObject already existed) and we have the same IORAttribute + // on the needed SObject -> then don't do anything! it's already there! + if ( !aDoneSomething && strcmp(anIORAttr->Value(), p->ToString()) == 0 ) { + aBuilder->AbortCommand(); + isIn = false; + return true; + } + + aDoneSomething = true; // going to set some value to anIORAttr any way from this point.. + + // set object value to the study: if object is external, then put it with + // help of the specific component - owner + if ( p->IsIOR() ) { + // get according component driver for result object + SALOME_LifeCycleCORBA aLCC( myNService ); + SUPERV_FNode aFNode = SUPERV::FNode::_narrow( p->Node() ); + if ( !aFNode->_is_nil() ) { + Engines::Component_var aComponent = aLCC.FindOrLoad_Component( aFNode->GetContainer(), aFNode->GetComponentName() ); + SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow( aComponent ); + if ( !CORBA::is_nil( aDriver ) ) { // if driver was found, publish object + CORBA::Object_ptr anObject = new CORBA::Object(); + CORBA::Any* anAny = p->ToAny(); + (*anAny) >>= anObject; - if (aDriver->CanPublishInStudy(anObject)) { - SALOMEDS::SObject_var aTmpSO; - if (!aTransaction) { - aTmpSO = aSO; - aTransaction = true; - aBuilder->NewCommand(); + if ( aDriver->CanPublishInStudy( anObject ) ) { + SALOMEDS::SObject_var aTmpSO;// = aSO; + aTmpSO = aDriver->PublishInStudy( aStudy, aTmpSO, anObject, "" ); + aBuilder->Addreference(aSO, aTmpSO); + } + else { // can't publish object: abort transaction + MESSAGE( "CanPublishInStudy() returned FALSE. ok, AbortCommand.." ); + aBuilder->AbortCommand(); + isIn = false; + return false; + } + } + else { // component has no driver, but could store IORs (like Calculator) + SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR( p->ToString() ); + if ( !CORBA::is_nil( anIORSO ) ) + aBuilder->Addreference(aSO, anIORSO); + else { // Hm... the object (==port value) was not found, so we don't publish it. + MESSAGE( "The object (==port value) was not found, so we don't publish it" ); + aBuilder->AbortCommand(); + isIn = false; + return false; } - aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, /*anObject->Name()*/""); - aBuilder->Addreference(aSO, aTmpSO); - } else { // can't publish object: abort transaction - if (aTransaction) aBuilder->AbortCommand(); - isIn = false; - return false; } - } else { // component has no drivel, but could store IORs (like Calculator) - SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString()); - if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO); } + else { // FNode is NULL -> bad + MESSAGE( "FNode is NULL. Not good at all. Aborting command." ); + aBuilder->AbortCommand(); + isIn = false; + return false; + } + } + else { + anIORAttr->SetValue( p->ToString() ); // ior attribute already set for the prevoius condition } - } else { - if (!aTransaction) { - aTransaction = true; - aBuilder->NewCommand(); - } - anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition } - - if (aTransaction) + + if ( aDoneSomething ) aBuilder->CommitCommand(); - if (!myThread->running()) + else + aBuilder->AbortCommand(); + + if ( !myThread->running() ) study->updateObjBrowser(); + isIn = false; return true; } @@ -1057,34 +1040,6 @@ void SUPERVGUI_Main::ResetView() } } - -void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) { - myIsFromStudy = theToStudy; - myCanvas->setAsFromStudy(theToStudy); -} - -void SUPERVGUI_Main::checkIsInStudy() { - if (!myIsFromStudy) return; - - SALOMEDS::Study_var aStudyDoc = study->getStudyDocument(); - SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION); - SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl); - SALOMEDS::SObject_var aDataflowLbl; - SALOMEDS::GenericAttribute_var anAttr; - - for (; aChildIterator->More(); aChildIterator->Next()) { - aDataflowLbl = aChildIterator->Value(); - if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR")) - continue; - - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return; - } - // This Graph considered as in study but in study it is not exists - Supervision.unregisterGraph(this); - setAsFromStudy(false); -} - void SUPERVGUI_Main::syncNotification() { char* graph; char* node; @@ -1223,18 +1178,39 @@ void SUPERVGUI_Main::removeArrayChild(SUPERV::CNode_ptr theNode) // as argument if (myArray) { const QObjectList* aChList = myArray->children(); - QObjectListIt aItChList(*aChList); - SUPERVGUI_CanvasNode* anObjNode; - while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) { - ++aItChList; - if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) { - myArray->removeChild(anObjNode); - delete anObjNode; + if ( aChList ) { // asv 27.01.05 : fix for 7817 + QObjectListIt aItChList(*aChList); + SUPERVGUI_CanvasNode* anObjNode; + while ((anObjNode = (SUPERVGUI_CanvasNode*)aItChList.current()) != 0) { + ++aItChList; + if ((QString(anObjNode->getEngine()->Name())).compare(QString(theNode->Name())) == 0) { + myArray->removeChild(anObjNode); + delete anObjNode; + } } - } + } // end of if ( ChList ) } } +/** + * ReadyToModify() must be called before any modification + * operation - asks to kill execution of dataflow. If returns false - + * modification (==Editing() ) is not allowed. + */ +bool SUPERVGUI_Main::ReadyToModify() { + if ( CORBA::is_nil( dataflow ) ) + return false; + if ( dataflow->IsExecuting() ) { + bool quit = QAD_MessageBox::warn2( QAD_Application::getDesktop(), // 0=Yes, 1=No + tr("WARNING"), tr("MSG_GRAPH_ISRUN"), tr( "BUT_YES" ), tr( "BUT_CANCEL" ), 0, 1, 0 ); + if ( quit ) // user selected NOT to kill dataflow and NOT to add new node + return false; + else if ( dataflow->IsExecuting() ) // user selected to kill the dataflow and add new node after that + kill(); // checking again for IsExecuting to be sure that it was not finished while MB was up + } + return true; +} + /******************************* SUPERVGUI_Thread class ****************************************/ SUPERVGUI_Thread::SUPERVGUI_Thread() :QThread() @@ -1251,24 +1227,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); @@ -1279,136 +1249,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; - - QPtrList< char * > anEventNodes; - QPtrList< SUPERV::GraphState > aStates; - myMain->startTimer(); - myMain->myGUIEventLoopFinished = false; + // GUI cycle to handle events coming for Engine + while ( myIsActive ) { - while(myIsActive) { + SUPERV_CNode aNode = NULL; + SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ; + SUPERV::GraphState aState = SUPERV::UndefinedState ; + + // 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()); - - // 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 <--- + } // end of switch - myMain->myGUIEventLoopFinished = true; + // asv 03.02.05 : fix for PAL6859, not very good, but works.. + myMain->sync(); + } // end of if !myIsActive + } // end of while( myIsActive ) QThread::exit(); }