myStep( false ),
myTrace( false ),
myVerbose( false ),
- myGUIEventLoopFinished( true )
+ myExecuted( false )
{
Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
theParent->setViewWidget(this);
}
}
else {
+ myExecuted = true; // set to true on first execution. for correct publishing in Study
myThread->startThread(tr("MSG_GRAPH_STARTED"));
}
}
}
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;
}
-bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
+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;
+ if (isIn) return true;
+ else isIn = true;
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.
+ const bool aLocked = aStudy->GetProperties()->IsLocked();
+ SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
+ SALOMEDS::GenericAttribute_var anAttr;
+ SALOMEDS::AttributeName_var aName;
+ 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 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;
+ // open new command. Commit or Abort it depending on aDoneSomething variable or error
+ aBuilder->NewCommand();
- // 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);
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
-
- if (aTransaction) aBuilder->CommitCommand();
+ // Create "Run -> Time and date, etc." SObjects
+ if ( myExecuted ) { // if dataflow was executed at least once
+ 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;
+ }
- anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
- anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
- if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
- isIn = false;
- return true;
- }
- // 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;
+ 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;
}
myMain->startTimer();
- myMain->myGUIEventLoopFinished = false;
-
while(myIsActive) {
myMain->getDataflow()->Event(aNode, aEvent, aState);
// qApp->unlock();
// VSR: 04/12/03 <---
- myMain->myGUIEventLoopFinished = true;
-
QThread::exit();
}