Salome HOME
Merge branch 'rbe/evol-job-newparams'
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Driver_i.cxx
index 15c7dd880c70074cbdb4d584f4de8abf57b41494..8dcb46a44fa1e38f1c9ecf7e0d623765562dfa93 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 #include "SALOMEDS_SComponent_i.hxx"
 #include "SALOMEDS_Study_i.hxx"
 #include "SALOMEDS.hxx"
+#include <SALOMEDSImpl_IParameters.hxx>
 #include <stdlib.h>
 
+#include CORBA_CLIENT_HEADER(SALOME_Session)
+
 SALOMEDS_Driver_i::SALOMEDS_Driver_i(Engines::EngineComponent_ptr theEngine, CORBA::ORB_ptr theORB)
 {
   // engine should not be null - component is supposed to be inherited from Engines::EngineComponent
@@ -200,7 +203,8 @@ std::string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject
   if ( !CORBA::is_nil(_driver) ) {
     CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), IORString.c_str(),
                                                                    isMultiFile, isASCII);
-    pstr = pers_string;
+    if ( pers_string.in() )
+      pstr = pers_string;
   }
 
   so->UnRegister();
@@ -355,26 +359,32 @@ SALOMEDS_DriverFactory_i::~SALOMEDS_DriverFactory_i()
 
 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const std::string& theComponentType)
 {
-  CORBA::Object_var obj;
 
-  std::string aFactoryType;
-  if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
-  else aFactoryType = "FactoryServer";
+  if ( theComponentType == SALOMEDSImpl_IParameters::getDefaultVisualComponent() )
+    return NULL; // skip the "Interface Applicative" component
 
-  SALOMEDS::unlock();
-  obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
-  SALOMEDS::lock();
+  SALOMEDSImpl_Driver* driver = 0;
 
-  if (CORBA::is_nil(obj)) {
-    obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServer", theComponentType.c_str());
-  }
+  CORBA::Object_var obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServer", theComponentType.c_str());
 
   if (!CORBA::is_nil(obj)) {
     Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
-    return new SALOMEDS_Driver_i(anEngine, _orb);
+    driver = new SALOMEDS_Driver_i(anEngine, _orb);
+  }
+  else {
+    // It can be "light" module
+    obj = _name_service->Resolve("/Kernel/Session");
+    if (!CORBA::is_nil(obj)) {
+      SALOME::Session_var session = SALOME::Session::_narrow(obj);
+      if (!CORBA::is_nil(session)) {
+       Engines::EngineComponent_var anEngine = session->GetComponent(theComponentType.c_str());
+       if (!CORBA::is_nil(anEngine))
+         driver = new SALOMEDS_Driver_i(anEngine, _orb);
+      }
+    }
   }
 
-  return NULL;
+  return driver;
 }
 
 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const std::string& theIOR)