]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Added methods to get a CORBA wrappers of the SALOMEDSClient objects
authorsrn <srn@opencascade.com>
Tue, 12 Apr 2005 08:38:58 +0000 (08:38 +0000)
committersrn <srn@opencascade.com>
Tue, 12 Apr 2005 08:38:58 +0000 (08:38 +0000)
src/SALOMEDS/SALOMEDS_SComponent.cxx
src/SALOMEDS/SALOMEDS_SComponent.hxx
src/SALOMEDS/SALOMEDS_SObject.cxx
src/SALOMEDS/SALOMEDS_SObject.hxx
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_StudyBuilder.cxx
src/SALOMEDS/SALOMEDS_StudyManager.cxx

index 6d51a3ba52ee92b0d38c2481d29cfa135308e0a4..7501232508ca01aa879bda1e1fcd9f587ed228c4 100644 (file)
@@ -5,6 +5,7 @@
 using namespace std; 
 
 #include "SALOMEDS_SComponent.hxx"
+#include "SALOMEDS_SComponent_i.hxx"
 #include <string> 
 #include <TCollection_AsciiString.hxx> 
 
@@ -47,3 +48,17 @@ bool SALOMEDS_SComponent::ComponentIOR(std::string& theID)
 
   return ret;
 }
+
+SALOMEDS::SComponent_ptr SALOMEDS_SComponent::GetSComponent()
+{
+  if(_isLocal) {
+    if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SComponent::_narrow(GetCORBAImpl());
+    return SALOMEDS_SComponent_i::New(Handle(SALOMEDSImpl_SComponent)::DownCast(GetLocalImpl()), _orb);
+  }
+  else {
+    return SALOMEDS::SComponent::_narrow(GetCORBAImpl());
+  }
+
+  return SALOMEDS::SComponent::_nil();
+}
+
index cfd57e2b038907dafa7a2ce26ab5509eb9785623..7f0d338780e1b087dc8e5fb150da69eebfda528d 100644 (file)
@@ -23,5 +23,7 @@ public:
 
   virtual std::string ComponentDataType();
   virtual bool ComponentIOR(std::string& theID);    
+
+  SALOMEDS::SComponent_ptr GetSComponent();
 };
 #endif
index 5ad2e9b1b49647ea56c1bb3461d9b5ef5f98478d..9958da4ce2b2340dafe226f8d71a6ead8e8697ae 100644 (file)
@@ -16,6 +16,9 @@ using namespace std;
 #include "SALOMEDS_Study.hxx"
 #include "SALOMEDSImpl_Study.hxx"
 
+#include "Utils_ORB_INIT.hxx" 
+#include "Utils_SINGLETON.hxx" 
+
 #ifdef WIN32
 #include <process.h>
 #else
@@ -36,12 +39,14 @@ SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
   long addr = theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
     _local_impl = ((SALOMEDSImpl_SObject*)(addr));
-    _corba_impl = SALOMEDS::SObject::_nil();
+    _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
   }
   else {
     _local_impl = NULL;
     _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
   }
+
+  init_orb();
 }
 
 SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObject)
@@ -49,6 +54,8 @@ SALOMEDS_SObject::SALOMEDS_SObject(const Handle(SALOMEDSImpl_SObject)& theSObjec
 {
   _corba_impl = SALOMEDS::SObject::_nil();
   _local_impl = theSObject;
+
+  init_orb();
 }
 
 SALOMEDS_SObject::~SALOMEDS_SObject()
@@ -217,13 +224,31 @@ int SALOMEDS_SObject::Depth()
 
 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
 {
-  CORBA::Object_var obj;
   if(_isLocal) {
     std::string anIOR = GetIOR();
-    SALOMEDS_Study* aStudy = dynamic_cast<SALOMEDS_Study*>(GetStudy());
-    obj = CORBA::Object::_duplicate(aStudy->ConvertIORToObject(anIOR));
-    delete aStudy;
+    return _orb->string_to_object(anIOR.c_str());
+  }
+  else return _corba_impl->GetObject();
+
+  return CORBA::Object::_nil();
+}
+
+SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
+{
+  if(_isLocal) {
+    if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
+    return SALOMEDS_SObject_i::New(_local_impl, _orb);
+  }
+  else {
+    return _corba_impl;
   }
-  else obj = CORBA::Object::_duplicate(_corba_impl->GetObject());
-  return obj._retn();
+  return SALOMEDS::SObject::_nil();
+}
+
+
+void SALOMEDS_SObject::init_orb()
+{
+  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
+  _orb = init(0 , 0 ) ;     
 }
index 5cfb7497c7c3df2a1b2e4fd556a26d10a57c7909..d6cf5687ca41bac3c4f8a4ed3711fec33b0d042c 100644 (file)
@@ -23,9 +23,10 @@ class SALOMEDS_SObject: public virtual SALOMEDSClient_SObject
 {
 protected:
 
-bool                         _isLocal;
-Handle(SALOMEDSImpl_SObject) _local_impl;
-SALOMEDS::SObject_var        _corba_impl;
+  bool                         _isLocal;
+  Handle(SALOMEDSImpl_SObject) _local_impl;
+  SALOMEDS::SObject_var        _corba_impl;
+  CORBA::ORB_var               _orb;
 
 public:
   
@@ -50,8 +51,13 @@ public:
   virtual int   Depth();
 
   CORBA::Object_ptr GetObject();
+  SALOMEDS::SObject_ptr GetSObject();
+
   SALOMEDS::SObject_ptr        GetCORBAImpl() { return SALOMEDS::SObject::_duplicate(_corba_impl); }
-  Handle(SALOMEDSImpl_SObject) GetLocalImpl() { return _local_impl; }
+  Handle(SALOMEDSImpl_SObject) GetLocalImpl() { return _local_impl; } 
+
+private:
+  void init_orb();
 };
 
 #endif
index ac5b4c0639232c80460aec1d6ef54a071dbfb00e..7f1fac0a3cb6b6940f66959ed53b29cf16acfbc3 100644 (file)
@@ -60,7 +60,7 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
   long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
     _local_impl = ((SALOMEDSImpl_Study*)(addr));
-    _corba_impl = SALOMEDS::Study::_nil();
+    _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
   }
   else {
     _local_impl = NULL;
@@ -133,18 +133,21 @@ SALOMEDSClient_SComponent* SALOMEDS_Study::FindComponentID(const std::string& aC
  
 SALOMEDSClient_SObject* SALOMEDS_Study::FindObject(const std::string& anObjectName)
 {
-  SALOMEDS_SObject* aSO = NULL;
   if(_isLocal) {
     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObject((char*)anObjectName.c_str());
     if(aSO_impl.IsNull()) return NULL;
-    aSO = new SALOMEDS_SObject(aSO_impl);
+    Handle(SALOMEDSImpl_SComponent) aSCO_impl = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO_impl);
+    if(!aSCO_impl.IsNull()) return new SALOMEDS_SComponent(aSCO_impl);
+    return new SALOMEDS_SObject(aSO_impl);
   }
   else { 
     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str());
     if(CORBA::is_nil(aSO_impl)) return NULL;
-    aSO = new SALOMEDS_SObject(aSO_impl);
+    SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl);
+    if(!CORBA::is_nil(aSCO_impl)) return new SALOMEDS_SComponent(aSCO_impl);
+    return new SALOMEDS_SObject(aSO_impl);
   }
-  return aSO;
+  return NULL;
 }
  
 std::vector<SALOMEDSClient_SObject*> SALOMEDS_Study::FindObjectByName(const std::string& anObjectName, 
@@ -170,18 +173,17 @@ std::vector<SALOMEDSClient_SObject*> SALOMEDS_Study::FindObjectByName(const std:
  
 SALOMEDSClient_SObject* SALOMEDS_Study::FindObjectID(const std::string& anObjectID)
 {
-  SALOMEDS_SObject* aSO = NULL;
   if(_isLocal) {
     Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str());
     if(aSO_impl.IsNull()) return NULL;
-    aSO = new SALOMEDS_SObject(aSO_impl);
+    return new SALOMEDS_SObject(aSO_impl);
   }
   else { 
     SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectID((char*)anObjectID.c_str());
     if(CORBA::is_nil(aSO_impl)) return NULL;
-    aSO = new SALOMEDS_SObject(aSO_impl);
+    return new SALOMEDS_SObject(aSO_impl);
   }
-  return aSO;
+  return NULL;
 }
  
 SALOMEDSClient_SObject* SALOMEDS_Study::CreateObjectID(const std::string& anObjectID)
@@ -530,13 +532,14 @@ CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR)
 void SALOMEDS_Study::init_orb()
 {
   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting())
   _orb = init(0 , 0 ) ;     
 }
 
 SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
 {
    if(_isLocal) {
+     if(!CORBA::is_nil(_corba_impl)) return _corba_impl;
      SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(_local_impl, _orb);
      SALOMEDS::Study_var Study = Study_servant->_this();
      return Study;
index a84717d52774f7a024494054ad9a755d32b0cc99..8e76a248e53b1055a50cf3000818b5cb6b0850c8 100644 (file)
@@ -415,6 +415,6 @@ void SALOMEDS_StudyBuilder::SetIOR(SALOMEDSClient_SObject* theSO, const std::str
 void SALOMEDS_StudyBuilder::init_orb()
 {
   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting())
   _orb = init(0 , 0 ) ;     
 }
index f0f189e444f9e853956bbbbc89aa0b8287111739..181fa4c93498a98c2503bf1023fe998a85573f4b 100644 (file)
@@ -257,7 +257,7 @@ SALOMEDSClient_SObject* SALOMEDS_StudyManager::Paste(SALOMEDSClient_SObject* the
 void SALOMEDS_StudyManager::init_orb()
 {
   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting())
   _orb = init(0 , 0 ) ;     
 }