]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
add method createStudy()
authormpa <mpa@opencascade.com>
Wed, 19 Oct 2016 09:46:44 +0000 (12:46 +0300)
committermpa <mpa@opencascade.com>
Wed, 19 Oct 2016 09:46:44 +0000 (12:46 +0300)
src/SALOMEDS/SALOMEDS.cxx
src/SALOMEDSClient/SALOMEDSClient_ClientFactory.cxx
src/SALOMEDSClient/SALOMEDSClient_ClientFactory.hxx

index 42ba79c59b5d5ce8f2b9333fe1b3a65ef1a962cf..86cfc79968bac50eba25b12b68bfe0ea294f5575 100644 (file)
@@ -28,6 +28,7 @@
 //
 #include "SALOMEDS.hxx"
 #include "SALOMEDS_Study.hxx"
+#include "SALOMEDS_Study_i.hxx"
 #include "SALOMEDS_StudyBuilder.hxx"
 #include "SALOMEDS_SObject.hxx"
 #include "SALOMEDS_SComponent.hxx"
@@ -102,6 +103,31 @@ extern "C"
     return new SALOMEDS_StudyBuilder(theBuilder);
   }
 
+  SALOMEDS_EXPORT
+  SALOMEDSClient_Study* CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
+  {
+    SALOME_NamingService namingService(orb);
+    CORBA::Object_var obj = namingService.Resolve( "/Study" );
+    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( obj );
+    SALOMEDS_Study_i* aStudy_i;
+    if( CORBA::is_nil(aStudy) ) {
+      aStudy_i = new SALOMEDS_Study_i(orb);
+
+      // Activate the objects.  This tells the POA that the objects are ready to accept requests.
+      PortableServer::ObjectId_var aStudy_iid =  root_poa->activate_object(aStudy_i);
+      aStudy = aStudy_i->_this();
+
+      //give ownership to the poa : the object will be deleted by the poa
+      aStudy_i->_remove_ref();
+      namingService.Register(aStudy.in(), "/Study");
+
+      // Assign the value of the IOR in the study->root
+      CORBA::String_var IORStudy = orb->object_to_string(aStudy);
+      aStudy_i->GetImpl()->SetTransientReference((char*)IORStudy.in());
+    }
+    return new SALOMEDS_Study(aStudy_i->GetImpl());
+  }
+
   SALOMEDS_EXPORT
   SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
   {
index b42b4b12ebfe97057b19e8a2c802932fcb280e7a..76f5221fffeb6fe94e7ab37306577ce27a50e5de 100644 (file)
@@ -35,6 +35,7 @@ static void* _libHandle = NULL;
 #define SOBJECT_FACTORY      "SObjectFactory"
 #define SCOMPONENT_FACTORY   "SComponentFactory"
 #define STUDY_FACTORY        "StudyFactory"
+#define STUDY_CREATE         "CreateStudy"
 #define BUILDER_FACTORY      "BuilderFactory"
 #define GET_PARAMETERS       "GetIParameters"
 #define CONVERT_SOBJECT      "ConvertSObject"
@@ -44,6 +45,7 @@ static void* _libHandle = NULL;
 typedef SALOMEDSClient_SObject* (*SOBJECT_FACTORY_FUNCTION) (SALOMEDS::SObject_ptr);
 typedef SALOMEDSClient_SComponent* (*SCOMPONENT_FACTORY_FUNCTION) (SALOMEDS::SComponent_ptr);
 typedef SALOMEDSClient_Study* (*STUDY_FACTORY_FUNCTION) (SALOMEDS::Study_ptr);
+typedef SALOMEDSClient_Study* (*STUDY_CREATE_FUNCTION) (CORBA::ORB_ptr, PortableServer::POA_ptr);
 typedef SALOMEDSClient_StudyBuilder* (*BUILDER_FACTORY_FUNCTION) (SALOMEDS::StudyBuilder_ptr);
 typedef SALOMEDSClient_IParameters* (*GET_PARAMETERS_FACTORY) (const _PTR(AttributeParameter)&);
 typedef SALOMEDS::SObject_ptr (*CONVERT_SOBJECT_FUNCTION) (const _PTR(SObject)&);
@@ -54,6 +56,7 @@ typedef SALOMEDS::StudyBuilder_ptr (*CONVERT_BUILDER_FUNCTION) (const _PTR(Study
 static SOBJECT_FACTORY_FUNCTION aSObjectFactory = NULL;
 static SCOMPONENT_FACTORY_FUNCTION aSComponentFactory = NULL;
 static STUDY_FACTORY_FUNCTION aStudyFactory = NULL;
+static STUDY_CREATE_FUNCTION aCreateFactory = NULL;
 static BUILDER_FACTORY_FUNCTION aBuilderFactory = NULL;
 static GET_PARAMETERS_FACTORY aGetIParameters = NULL;
 static CONVERT_SOBJECT_FUNCTION aConvertSObject = NULL;
@@ -108,6 +111,21 @@ _PTR(Study) ClientFactory::Study(SALOMEDS::Study_ptr theStudy)
   return _PTR(Study)(study);
 }
 
+_PTR(Study) ClientFactory::createStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa)
+{
+  SALOMEDSClient_Study* study = NULL;
+#ifdef WIN32
+  if(!_libHandle) _libHandle = ::LoadLibrary(SALOMEDS_LIB_NAME);
+  if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION)::GetProcAddress(_libHandle, STUDY_CREATE);
+#else
+  if(!_libHandle) _libHandle = dlopen(SALOMEDS_LIB_NAME, RTLD_LAZY | RTLD_GLOBAL);
+  if(!aCreateFactory) aCreateFactory = (STUDY_CREATE_FUNCTION) dlsym(_libHandle, STUDY_CREATE);
+#endif
+
+  if(aCreateFactory) study = aCreateFactory(orb, poa);
+  return _PTR(Study)(study);
+}
+
 _PTR(StudyBuilder) ClientFactory::StudyBuilder(SALOMEDS::StudyBuilder_ptr theStudyBuilder)
 {
   SALOMEDSClient_StudyBuilder* studyBuilder = NULL;
index a3d5ca4fabcd8de543ba00aab2d253bb2b86a38f..7c407f89856d9581f66d1d97fb7b45b27da085fb 100644 (file)
@@ -58,6 +58,11 @@ public:
    */
   static _PTR(Study) Study(SALOMEDS::Study_ptr theStudy);
 
+  /*!
+   *  Creates and returns a client Study wrapper
+   */
+  static _PTR(Study) createStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa);
+
   /*!
    *  Returns a client StudyBuilder wrapper that corresponds %theStudy
    */