Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_BrowseNodeDlg.cxx
index a50fe23ce2ccaa3568f0d2040d6df841eb5005a4..5969c3923b921e34d07ed94b90a48f5ceaa9bc18 100644 (file)
@@ -302,7 +302,88 @@ void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
   myActiveField = (aField->isEditable())? aField : 0;
 }
 
+namespace {
+
+  QString getIORfromIO (const Handle(SALOME_InteractiveObject)& theIO,
+                        SUPERVGUI * theModule)
+  {
+    QString ior ("");
+    if (!theIO->hasEntry()) return ior;
+
+    SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(theModule->getActiveStudy());
+    _PTR(SObject) aSObj (anAppStudy->studyDS()->FindObjectID(theIO->getEntry()));
+
+    _PTR(GenericAttribute) anAttr;
+    if (aSObj->FindAttribute(anAttr, "AttributeIOR")) {
+      _PTR(AttributeIOR) anIOR (anAttr);
+      ior = anIOR->Value().c_str();
+      return ior;
+    }
 
+    // old code, it is useless, because <aSSObj->GetObject()> here will be NULL
+    // (because it is retrieved from <aSSObj> by stored IOR)
+    /*
+      SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aSObj->GetStudy().get() );
+      SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aSObj.get() );
+      if ( aSStudy && aSSObj )
+      ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
+    //*/
+
+    // new code
+
+    // default value: null IOR (IOR:01000000010000000000...)
+    SalomeApp_Application* anApp = theModule->getApp();
+    CORBA::Object_var aNullObj;
+    ior = anApp->orb()->object_to_string(aNullObj);
+
+    // try to load a component data from an opened (presumably) study
+    _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
+    std::string aCompIOR;
+    if (!aSComp->ComponentIOR(aCompIOR)) {
+      std::string aCompDataType = aSComp->ComponentDataType();
+
+      // obtain a driver by a component data type
+      // like it is done in SALOMEDS_DriverFactory_i::GetDriverByType
+      SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_nil();
+      SALOME_LifeCycleCORBA * LCC = anApp->lcc();
+      try {
+        CORBA::Object_var
+          anEngineObj = LCC->FindOrLoad_Component("FactoryServer", aCompDataType.c_str());
+        if (CORBA::is_nil(anEngineObj))
+          anEngineObj = LCC->FindOrLoad_Component("FactoryServerPy", aCompDataType.c_str());
+
+        if (!CORBA::is_nil(anEngineObj))
+          anEngine = SALOMEDS::Driver::_narrow(anEngineObj);
+      }
+      catch (...) {
+      }
+
+      if (!CORBA::is_nil(anEngine)) {
+        // try to load
+        _PTR(StudyBuilder) aStudyBuilder = aSObj->GetStudy()->NewBuilder();
+        bool isOk = true;
+        try {
+          CORBA::String_var aDriverIOR = anApp->orb()->object_to_string(anEngine);
+          aStudyBuilder->LoadWith(aSComp, aDriverIOR.in());
+        }
+        catch (...) {
+          isOk = false;
+        }
+
+        if (isOk) {
+          // now try to obtain the IOR once again (after successfull component data loading)
+          if (aSObj->FindAttribute( anAttr, "AttributeIOR" )) {
+            _PTR(AttributeIOR) anIOR ( anAttr );
+            ior = anIOR->Value().c_str();
+          }
+        }
+      } // if (!CORBA::is_nil(anEngine))
+    } // if (!aSComp->ComponentIOR(aCompIOR))
+
+    return ior;
+  }
+
+} // no name namespace
 
 /**
  * Slot, called when selection is changed
@@ -310,7 +391,7 @@ void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
 {
   if ( myActiveField ) {
-    
+
     SALOME_ListIO aList;
     aList.Clear();
 
@@ -320,28 +401,13 @@ void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
       return;
     }
 
-    (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))
-      ->selectionMgr()->selectedObjects( aList );
-    
-    if( aList.Extent() == 1 ) {
+    SalomeApp_Application* anApp = aSupMod->getApp();
+    anApp->selectionMgr()->selectedObjects( aList );
+
+    if ( aList.Extent() == 1 ) {
       Handle( SALOME_InteractiveObject ) anIO = aList.First();
       if ( anIO->hasEntry() ) {
-       _PTR(SObject) aObj ( dynamic_cast<SalomeApp_Study*>( aSupMod->getActiveStudy() )->
-                            studyDS()->FindObjectID( anIO->getEntry() ) );
-         
-       _PTR(GenericAttribute) anAttr;
-       QString ior("");
-         
-       if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
-         _PTR(AttributeIOR) anIOR ( anAttr );
-         ior = anIOR->Value().c_str();
-       }
-       else {
-         SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aObj->GetStudy().get() );
-         SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aObj.get() );
-         if ( aSStudy && aSSObj )
-           ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
-       }
+        QString ior = ::getIORfromIO(anIO, aSupMod);
        myActiveField->setData( ior );
       }
     }
@@ -476,35 +542,20 @@ void SUPERVGUI_GetValueDlg::onSelectionChanged()
 {
   SALOME_ListIO aList;
   aList.Clear();
-  
+
   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
   if ( !aSupMod ) {
     MESSAGE("NULL Supervision module!");
     return;
   }
-  
-  (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))
-    ->selectionMgr()->selectedObjects( aList );
-  
-  if( aList.Extent() == 1 ) {
+
+  SalomeApp_Application* anApp = aSupMod->getApp();
+  anApp->selectionMgr()->selectedObjects( aList );
+
+  if ( aList.Extent() == 1 ) {
     Handle( SALOME_InteractiveObject ) anIO = aList.First();
     if ( anIO->hasEntry() ) {
-      _PTR(SObject) aObj ( dynamic_cast<SalomeApp_Study*>( aSupMod->getActiveStudy() )->
-                          studyDS()->FindObjectID( anIO->getEntry() ) );
-       
-      _PTR(GenericAttribute) anAttr;
-      QString ior("");
-       
-      if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
-       _PTR(AttributeIOR) anIOR ( anAttr );
-       ior = anIOR->Value().c_str();
-      }
-      else {
-       SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aObj->GetStudy().get() );
-       SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aObj.get() );
-       if ( aSStudy && aSSObj )
-         ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
-      }
+      QString ior = ::getIORfromIO(anIO, aSupMod);
       myField->setData( ior );
     }
   }