]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
Fix for 7950. myExecuted boolean field added to the class. set to true on first...
authorasv <asv@opencascade.com>
Wed, 2 Feb 2005 13:33:29 +0000 (13:33 +0000)
committerasv <asv@opencascade.com>
Wed, 2 Feb 2005 13:33:29 +0000 (13:33 +0000)
src/SUPERVGUI/SUPERVGUI_Main.cxx
src/SUPERVGUI/SUPERVGUI_Main.h

index af9d7054fd7e68d9d6fb3a23781758758255aa0b..3cd797d4520242ee32261c2ed5c3c80ffa39aff8 100644 (file)
@@ -69,7 +69,7 @@ SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* th
        myStep( false ),
        myTrace( false ),
        myVerbose( false ),
-       myGUIEventLoopFinished( true )
+       myExecuted( false )
 {
   Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
   theParent->setViewWidget(this);  
@@ -518,6 +518,7 @@ void SUPERVGUI_Main::run( const bool andSuspend ) {
        }
       } 
       else {
+       myExecuted = true; // set to true on first execution. for correct publishing in Study
        myThread->startThread(tr("MSG_GRAPH_STARTED"));
       }
     }
@@ -859,88 +860,81 @@ 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;
 }
 
-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);
@@ -950,66 +944,85 @@ 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
-
-  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;
 }
@@ -1274,8 +1287,6 @@ void SUPERVGUI_Thread::run()
 
   myMain->startTimer();
 
-  myMain->myGUIEventLoopFinished = false;
-
   while(myIsActive) {
     myMain->getDataflow()->Event(aNode, aEvent, aState);
     
@@ -1387,8 +1398,6 @@ void SUPERVGUI_Thread::run()
 //   qApp->unlock();
   // VSR: 04/12/03 <---    
 
-  myMain->myGUIEventLoopFinished = true;
-
   QThread::exit();
 }
 
index db76c9cd220d3ac3969598b66bb15193d7fe9970..131c918ae5348bab145aebab435fc79a9db36741 100644 (file)
@@ -125,8 +125,6 @@ class SUPERVGUI_Main: public SUPERVGraph_View {
 
     bool eventFilter( QObject* o, QEvent* e);
 
-    bool IsGUIEventLoopFinished() const { return myGUIEventLoopFinished; }
-
     void Editing(); // any Editing operation is to be performed ->
                    // activate Editors data model in Engine
 
@@ -182,39 +180,36 @@ class SUPERVGUI_Main: public SUPERVGraph_View {
     SUPERVGUI_Canvas*       myCanvas;
     SUPERVGUI_CanvasView*   myCanvasView;
 
-    bool               choosing;
+    bool                    choosing;
 
-    QString            myHashCode;
+    QString                 myHashCode;
     
-    bool               myIsFromStudy;
-    int                myCopyNum;
+    bool                    myIsFromStudy;
+    int                     myCopyNum;
 
-    SALOME_NamingService* myNService;
-    QDateTime             myRunTime; // mpv 23.12.2002: we need time of running of dataflow
-                                     // for right Study document modification
+    SALOME_NamingService*   myNService;
+    QDateTime               myRunTime; // mpv 23.12.2002: we need time of running of dataflow
+                                       // for correct Study document modification
     /* notification data */                           
-    NOTIFICATION_Consumer* notification;
-    bool                   myFiltered;
-    bool                   myLogged;
-    QString                myLogFileName;
-    FILE*                  myLogFile;
-    bool                   myWarning;
-    bool                   myStep;
-    bool                   myTrace;
-    bool                   myVerbose;
-    bool                   myIsLocked;
-
-    SUPERVGUI_Thread*      myThread; 
+    NOTIFICATION_Consumer*  notification;
+    bool                    myFiltered;
+    bool                    myLogged;
+    QString                 myLogFileName;
+    FILE*                   myLogFile;
+    bool                    myWarning;
+    bool                    myStep;
+    bool                    myTrace;
+    bool                    myVerbose;
+    bool                    myIsLocked;
+
+    SUPERVGUI_Thread*       myThread; 
 
     QPtrList< char * >                myEventNodes ;
     QPtrList< SUPERV::GraphState >    myStates ;
-    QTimer*                myTimer;
-    
-    // asv : 18.11.04 : fix for bug 6170 : this field is FALSE when SUPERVGUI_Thread
-    // is inside event loop during graph execution.  dataflow->IsDone() returns true
-    // BEFORE all events are handled (a few of them are still being processed in GUI thread), 
-    // and for bug 6170 it is neccessary to know exactly when GUI events processing stops..
-    bool                   myGUIEventLoopFinished;
+    QTimer*                 myTimer;
+
+    bool                    myExecuted; // asv 02.02.05 : set to true on first dataflow execution
+                                        // is needed for correct publishing objects in Study
 };
 
 class SUPERVGUI_Thread : public QObject, public QThread {