Salome HOME
[EDF29093] : Quick fix resorbed
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study.cxx
index 67220592ea50bd39eb33faacca6a697daf9deeca..8f438d9f4ea55151182b1b355dce427dcfeb514a 100644 (file)
@@ -1,28 +1,29 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
+//
 // 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.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  File   : SALOMEDS_Study.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
-
+//
 #include "utilities.h" 
 
 #include "SALOMEDS_Study.hxx"
 #include "SALOMEDSImpl_SComponentIterator.hxx"
 #include "SALOMEDSImpl_AttributeStudyProperties.hxx"
 #include "SALOMEDSImpl_AttributeParameter.hxx"
+#include "SALOMEDSImpl_GenericVariable.hxx"
 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
 
+#include <SALOME_KernelServices.hxx>
+
 #include "SALOMEDS_Driver_i.hxx"
 #include "SALOMEDS_Study_i.hxx"
 
-#include <TCollection_AsciiString.hxx> 
-#include <TColStd_HSequenceOfAsciiString.hxx>
-#include <TColStd_HSequenceOfTransient.hxx>
+#include "OpUtil.hxx"
 
-#include "Utils_ORB_INIT.hxx" 
-#include "Utils_SINGLETON.hxx" 
+#include "Basics_Utils.hxx"
 
 #ifdef WIN32
 #include <process.h>
 #include <unistd.h>
 #endif
 
-#include "OpUtil.hxx"
-
-using namespace std; 
-
-SALOMEDS_Study::SALOMEDS_Study(const Handle(SALOMEDSImpl_Study)& theStudy)
+SALOMEDS_Study::SALOMEDS_Study(SALOMEDSImpl_Study* theStudy)
 {
   _isLocal = true;
   _local_impl = theStudy;
   _corba_impl = SALOMEDS::Study::_nil();
-  init_orb();
+
+  pthread_mutex_init( &SALOMEDS_StudyBuilder::_remoteBuilderMutex, 0 );
+
+  InitORB();
 }
 
 SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
@@ -83,9 +83,11 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
   long pid =  (long)getpid();
 #endif  
 
-  long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
+  pthread_mutex_init( &SALOMEDS_StudyBuilder::_remoteBuilderMutex, 0 );
+
+  CORBA::LongLong addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
   if(_isLocal) {
-    _local_impl = ((SALOMEDSImpl_Study*)(addr));
+    _local_impl = reinterpret_cast<SALOMEDSImpl_Study*>(addr);
     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
   }
   else {
@@ -93,32 +95,175 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy)
     _corba_impl = SALOMEDS::Study::_duplicate(theStudy);
   }
 
-  init_orb();
+  InitORB();
 }
 
 SALOMEDS_Study::~SALOMEDS_Study()
 {
 }
 
-std::string SALOMEDS_Study::GetPersistentReference()
+void SALOMEDS_Study::InitORB()
 {
-  std::string aRef;
+  _orb = KERNEL::GetRefToORB();
+}
+
+void SALOMEDS_Study::Init()
+{
+  if(CORBA::is_nil(_corba_impl))
+    return;
+
+  _corba_impl->Init();
+}
+
+void SALOMEDS_Study::Clear()
+{
+  if(CORBA::is_nil(_corba_impl))
+    return;
+
+  _corba_impl->Clear();
+}
+
+bool SALOMEDS_Study::Open(const std::string& theStudyUrl)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return false;
+  std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
+  
+  return _corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() );
+}
+
+bool SALOMEDS_Study::CanOpen(const std::string& theStudyUrl)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return false;
+  std::wstring wtheStudyUrl = Kernel_Utils::decode_s( theStudyUrl );
+  
+  return _corba_impl->CanOpen( (wchar_t*)wtheStudyUrl.c_str() );
+}
+
+bool SALOMEDS_Study::Save(bool theMultiFile, bool theASCII)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return false;
+
+  return _corba_impl->Save(theMultiFile, theASCII);
+}
+
+bool SALOMEDS_Study::SaveAs(const std::string& theUrl, bool theMultiFile, bool theASCII)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return false;
+
+  return _corba_impl->SaveAs(Kernel_Utils::decode_s(theUrl), theMultiFile, theASCII);
+}
+
+SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
+{
+  SALOMEDS_Driver_i* driver = NULL;
+
+  SALOMEDSImpl_SComponent aSCO = theObject.GetFatherComponent();
+  if(!aSCO.IsNull()) {
+    std::string IOREngine = aSCO.GetIOR();
+    if(!IOREngine.empty()) {
+      CORBA::Object_var obj = orb->string_to_object(IOREngine.c_str());
+      Engines::EngineComponent_var Engine = Engines::EngineComponent::_narrow(obj) ;
+      driver = new SALOMEDS_Driver_i(Engine, orb);
+    }
+  }
+
+  return driver;
+}
+
+bool SALOMEDS_Study::CanCopy(const _PTR(SObject)& theSO)
+{
+  SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
+  bool ret;
+
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aRef = _local_impl->GetPersistentReference().ToCString();
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
+    SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
+    ret = _local_impl->CanCopy(aSO_impl, aDriver);
+    delete aDriver;
   }
-  else aRef = _corba_impl->GetPersistentReference();
-  return aRef;
+  else {
+    ret = _corba_impl->CanCopy(aSO->GetCORBAImpl());
+  }
+
+  return ret;
+}
+
+bool SALOMEDS_Study::Copy(const _PTR(SObject)& theSO)
+{
+  SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
+  bool ret;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
+    SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
+    ret = _local_impl->Copy(aSO_impl, aDriver);
+    delete aDriver;
+  }
+  else {
+    ret = _corba_impl->Copy(aSO->GetCORBAImpl());
+  }
+  return ret;
+}
+
+bool SALOMEDS_Study::CanPaste(const _PTR(SObject)& theSO)
+{
+  SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
+  bool ret;
+
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
+    SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
+    ret = _local_impl->CanPaste(aSO_impl, aDriver);
+    delete aDriver;
+  }
+  else {
+    ret = _corba_impl->CanPaste(aSO->GetCORBAImpl());
+  }
+
+  return ret;
+}
+
+_PTR(SObject) SALOMEDS_Study::Paste(const _PTR(SObject)& theSO)
+{
+  SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
+  SALOMEDSClient_SObject* aResult = NULL;
+
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+
+    SALOMEDSImpl_SObject aSO_impl = *(aSO->GetLocalImpl());
+    SALOMEDS_Driver_i* aDriver = GetDriver(aSO_impl, _orb);
+    SALOMEDSImpl_SObject aNewSO = _local_impl->Paste(aSO_impl, aDriver);
+    delete aDriver;
+    if(aNewSO.IsNull()) return _PTR(SObject)(aResult);
+    aResult = new SALOMEDS_SObject(aNewSO);
+  }
+  else {
+    SALOMEDS::SObject_ptr aNewSO = _corba_impl->Paste(aSO->GetCORBAImpl());
+    if(CORBA::is_nil(aNewSO)) return _PTR(SObject)(aResult);
+    aResult = new SALOMEDS_SObject(aNewSO);
+  }
+
+  return _PTR(SObject)(aResult);
 }
 
-std::string SALOMEDS_Study::GetTransientReference()
+std::string SALOMEDS_Study::GetPersistentReference()
 {
   std::string aRef;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aRef = _local_impl->GetTransientReference().ToCString();
+    aRef = _local_impl->GetPersistentReference();
   }
-  else aRef = _corba_impl->GetTransientReference();
+  else aRef = (CORBA::String_var)_corba_impl->GetPersistentReference();
   return aRef;
 }
  
@@ -139,9 +284,8 @@ _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentNam
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SComponent) aSCO_impl =
-      _local_impl->FindComponent((char*)aComponentName.c_str());
-    if (aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
+    SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponent(aComponentName);
+    if (!aSCO_impl) return _PTR(SComponent)(aSCO);
     aSCO = new SALOMEDS_SComponent(aSCO_impl);
   }
   else {
@@ -158,9 +302,8 @@ _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SComponent) aSCO_impl =
-      _local_impl->FindComponentID((char*)aComponentID.c_str());
-    if (aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO);
+    SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponentID(aComponentID);
+    if (!aSCO_impl) return _PTR(SComponent)(aSCO);
     aSCO = new SALOMEDS_SComponent(aSCO_impl);
   }
   else {
@@ -178,10 +321,12 @@ _PTR(SObject) SALOMEDS_Study::FindObject(const std::string& anObjectName)
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObject((char*)anObjectName.c_str());
-    if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
-    Handle(SALOMEDSImpl_SComponent) aSCO_impl = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO_impl);
-    if (!aSCO_impl.IsNull()) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
+    SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObject(anObjectName);
+    if (!aSO_impl) return _PTR(SObject)(aSO);
+    if(aSO_impl.IsComponent()) {
+        SALOMEDSImpl_SComponent aSCO_impl = aSO_impl;
+        return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl));
+    }   
     aSO = new SALOMEDS_SObject(aSO_impl);
   }
   else { 
@@ -204,16 +349,14 @@ std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& a
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(TColStd_HSequenceOfTransient) aSeq =
-      _local_impl->FindObjectByName((char*)anObjectName.c_str(), (char*)aComponentName.c_str());
-    aLength = aSeq->Length();
-    for (i = 1; i<= aLength; i++) 
-      aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject
-                                      (Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
+    std::vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindObjectByName(anObjectName, aComponentName);
+    aLength = (int)aSeq.size(); //!< TODO: conversion from size_t to int
+    for (i = 0; i< aLength; i++) 
+      aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
   }
   else {
     SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindObjectByName((char*)anObjectName.c_str(), 
-                                                                           (char*)aComponentName.c_str());
+                                                                            (char*)aComponentName.c_str());
     aLength = aSeq->length();
     for (i = 0; i< aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
   }
@@ -227,8 +370,8 @@ _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID)
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str());
-    if(aSO_impl.IsNull()) return _PTR(SObject)(aSO);
+    SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectID(anObjectID);
+    if(!aSO_impl) return _PTR(SObject)(aSO);
     return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl));
   }
   else { 
@@ -244,9 +387,15 @@ _PTR(SObject) SALOMEDS_Study::CreateObjectID(const std::string& anObjectID)
   SALOMEDSClient_SObject* aSO = NULL;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aSO = new SALOMEDS_SObject(_local_impl->CreateObjectID((char*)anObjectID.c_str()));
+    SALOMEDSImpl_SObject aSO_impl = _local_impl->CreateObjectID(anObjectID);
+    if(!aSO_impl) return _PTR(SObject)(aSO);
+    aSO = new SALOMEDS_SObject(aSO_impl);
+  }
+  else { 
+    SALOMEDS::SObject_var aSO_impl = _corba_impl->CreateObjectID((char*)anObjectID.c_str());
+    if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO);
+    aSO = new SALOMEDS_SObject(aSO_impl);
   }
-  else aSO = new SALOMEDS_SObject(_corba_impl->CreateObjectID((char*)anObjectID.c_str())); 
   return _PTR(SObject)(aSO);
 }
 
@@ -256,8 +405,8 @@ _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR)
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectIOR((char*)anObjectIOR.c_str());
-    if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
+    SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectIOR(anObjectIOR);
+    if (!aSO_impl) return _PTR(SObject)(aSO);
     aSO = new SALOMEDS_SObject(aSO_impl);
   }
   else { 
@@ -274,8 +423,8 @@ _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath)
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectByPath((char*)thePath.c_str());
-    if (aSO_impl.IsNull()) return _PTR(SObject)(aSO);
+    SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectByPath(thePath);
+    if (!aSO_impl) return _PTR(SObject)(aSO);
     aSO = new SALOMEDS_SObject(aSO_impl);
   }
   else {
@@ -288,122 +437,24 @@ _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath)
 
 std::string SALOMEDS_Study::GetObjectPath(const _PTR(SObject)& theSO)
 {
+  if(!theSO) return "";
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   std::string aPath;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aPath = _local_impl->GetObjectPath(aSO->GetLocalImpl()).ToCString();
+    aPath = _local_impl->GetObjectPath(*(aSO->GetLocalImpl()));
   }
   else aPath = _corba_impl->GetObjectPath(aSO->GetCORBAImpl());
   return aPath;
 }
 
-void SALOMEDS_Study::SetContext(const std::string& thePath)
-{
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-    _local_impl->SetContext((char*)thePath.c_str());
-  }
-  else _corba_impl->SetContext((char*)thePath.c_str());
-}
-
-std::string SALOMEDS_Study::GetContext()  
-{
-  std::string aPath;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-    aPath = _local_impl->GetContext().ToCString();
-  }
-  else aPath = _corba_impl->GetContext();
-  return aPath;
-}
-
-std::vector<std::string> SALOMEDS_Study::GetObjectNames(const std::string& theContext)
-{
-  std::vector<std::string> aVector;
-  int aLength, i;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-
-    Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetObjectNames((char*)theContext.c_str());
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
-  }
-  else {
-    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str());
-    aLength = aSeq->length();
-    for (i = 0; i < aLength; i++) aVector.push_back(std::string((std::string)aSeq[i].in()));
-  }
-  return aVector;
-}
-std::vector<std::string> SALOMEDS_Study::GetDirectoryNames(const std::string& theContext)
-{
-  std::vector<std::string> aVector;
-  int aLength, i;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-
-    Handle(TColStd_HSequenceOfAsciiString) aSeq =
-      _local_impl->GetDirectoryNames((char*)theContext.c_str());
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
-  }
-  else {
-    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str());
-    aLength = aSeq->length();
-    for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
-  }
-  return aVector;
-}
-std::vector<std::string> SALOMEDS_Study::GetFileNames(const std::string& theContext)
-{
-  std::vector<std::string> aVector;
-  int aLength, i;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-
-    Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetFileNames((char*)theContext.c_str());
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
-  }
-  else {
-    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str());
-    aLength = aSeq->length();
-
-    for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
-  }
-  return aVector;
-}
-std::vector<std::string> SALOMEDS_Study::GetComponentNames(const std::string& theContext)
-{
-  std::vector<std::string> aVector;
-  int aLength, i;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-
-    Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetComponentNames((char*)theContext.c_str());
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
-  }
-  else {
-    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str());
-    aLength = aSeq->length();
-    for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
-  }
-  return aVector;
-}
-
 _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO)
 {
   SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(theSO.get());
   SALOMEDSClient_ChildIterator* aCI = NULL; 
   if (_isLocal) {
     SALOMEDS::Locker lock;
-
-    Handle(SALOMEDSImpl_ChildIterator) aCIimpl = _local_impl->NewChildIterator(aSO->GetLocalImpl());
+    SALOMEDSImpl_ChildIterator aCIimpl = _local_impl->NewChildIterator(*(aSO->GetLocalImpl()));
     aCI = new SALOMEDS_ChildIterator(aCIimpl);
   }
   else {
@@ -437,7 +488,7 @@ _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder()
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_StudyBuilder) aSBimpl = _local_impl->NewBuilder();
+    SALOMEDSImpl_StudyBuilder* aSBimpl = _local_impl->NewBuilder();
     aSB = new SALOMEDS_StudyBuilder(aSBimpl);
   }
   else {
@@ -453,9 +504,9 @@ std::string SALOMEDS_Study::Name()
   std::string aName;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aName = _local_impl->Name().ToCString();
+    aName = _local_impl->Name();
   }
-  else aName = _corba_impl->Name();
+  else aName = Kernel_Utils::encode_s(_corba_impl->Name());
   return aName;
 }
 
@@ -463,9 +514,9 @@ void SALOMEDS_Study::Name(const std::string& theName)
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    _local_impl->Name((char*)theName.c_str());
+    _local_impl->Name(theName);
   }
-  else _corba_impl->Name((char*)theName.c_str());
+  else _corba_impl->Name(Kernel_Utils::decode_s(theName));
 }
 
 bool SALOMEDS_Study::IsSaved()
@@ -498,45 +549,36 @@ bool SALOMEDS_Study::IsModified()
   else isModified = _corba_impl->IsModified();
   return isModified;
 }
-std::string SALOMEDS_Study::URL()
-{
-  std::string aURL;
-  if (_isLocal) {
-    SALOMEDS::Locker lock;
-    aURL = _local_impl->URL().ToCString();
-  }
-  else aURL = _corba_impl->URL();
-  return aURL;
-}
 
-void SALOMEDS_Study::URL(const std::string& url)
+void SALOMEDS_Study::Modified()
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    _local_impl->URL((char*)url.c_str());
+    _local_impl->Modify();
   }
-  else _corba_impl->URL((char*)url.c_str());
+  else _corba_impl->Modified();
 }
 
-int SALOMEDS_Study::StudyId()
+std::string SALOMEDS_Study::URL()
 {
-  int anID;
+  std::string aURL;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    anID = _local_impl->StudyId();
+    aURL = _local_impl->URL();
   }
-  else anID = _corba_impl->StudyId();
-  return anID;
+  else 
+      aURL = Kernel_Utils::encode_s(_corba_impl->URL());
+  return aURL;
 }
-void SALOMEDS_Study::StudyId(int id) 
+
+void SALOMEDS_Study::URL(const std::string& url)
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    _local_impl->StudyId(id);
+    _local_impl->URL(url);
   }
-  else _corba_impl->StudyId(id);  
+  else _corba_impl->URL(Kernel_Utils::decode_s(url));
 }
 
 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
@@ -547,12 +589,11 @@ std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)&
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(TColStd_HSequenceOfTransient) aSeq = _local_impl->FindDependances(aSO->GetLocalImpl());
-    if (!aSeq.IsNull()) {
-      aLength = aSeq->Length();
-      for (i = 1; i <= aLength; i++) 
-        aVector.push_back(_PTR(SObject)(
-          new SALOMEDS_SObject(Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i)))));
+    std::vector<SALOMEDSImpl_SObject> aSeq = _local_impl->FindDependances(*(aSO->GetLocalImpl()));
+    if (aSeq.size()) {
+      aLength = (int)aSeq.size(); //!< TODO: conversion from size_t to int
+      for (i = 0; i < aLength; i++) 
+        aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i])));
     }
   }
   else {
@@ -570,7 +611,7 @@ _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties()
     SALOMEDS::Locker lock;
     aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties());
   }
-  else aProp = new SALOMEDS_AttributeStudyProperties(_corba_impl->GetProperties());
+  else aProp = new SALOMEDS_AttributeStudyProperties((SALOMEDS::AttributeStudyProperties_var)_corba_impl->GetProperties());
   return _PTR(AttributeStudyProperties)(aProp);
 }
  
@@ -579,7 +620,7 @@ std::string SALOMEDS_Study::GetLastModificationDate()
   std::string aDate;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    aDate = _local_impl->GetLastModificationDate().ToCString();
+    aDate = _local_impl->GetLastModificationDate();
   }
   else aDate = _corba_impl->GetLastModificationDate();
   return aDate;
@@ -591,10 +632,7 @@ std::vector<std::string> SALOMEDS_Study::GetModificationsDate()
   int aLength, i;
   if (_isLocal) {
     SALOMEDS::Locker lock;
-
-    Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetModificationsDate();
-    aLength = aSeq->Length();
-    for (i = 1; i <= aLength; i++) aVector.push_back(aSeq->Value(i).ToCString());
+    aVector = _local_impl->GetModificationsDate();
   }
   else {
     SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate();
@@ -610,7 +648,7 @@ _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
   if (_isLocal) {
     SALOMEDS::Locker lock;
 
-    Handle(SALOMEDSImpl_UseCaseBuilder) aUBimpl = _local_impl->GetUseCaseBuilder();
+    SALOMEDSImpl_UseCaseBuilder* aUBimpl = _local_impl->GetUseCaseBuilder();
     aUB = new SALOMEDS_UseCaseBuilder(aUBimpl);
   }
   else {
@@ -621,71 +659,322 @@ _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder()
   return _PTR(UseCaseBuilder)(aUB);
 }
 
-void SALOMEDS_Study::Close()
+void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
+{
+  if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
+  else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
+}
+
+bool SALOMEDS_Study::DumpStudy(const std::string& thePath,
+                               const std::string& theBaseName,
+                               bool isPublished,
+                               bool isMultiFile)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return false;
+
+  return _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished, isMultiFile);
+}     
+
+void SALOMEDS_Study::SetStudyLock(const std::string& theLockerID)
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
-    _local_impl->Close();
+    _local_impl->SetStudyLock(theLockerID.c_str());
   }
-  else _corba_impl->Close();
+  else _corba_impl->SetStudyLock((char*)theLockerID.c_str());
+}
+bool SALOMEDS_Study::IsStudyLocked()
+{
+  bool isLocked;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    isLocked = _local_impl->IsStudyLocked();
+  }
+  else isLocked = _corba_impl->IsStudyLocked();
+  return isLocked;
+}
+void SALOMEDS_Study::UnLockStudy(const std::string& theLockerID)
+{
+  if(_isLocal) _local_impl->UnLockStudy(theLockerID.c_str());
+  else _corba_impl->UnLockStudy((char*)theLockerID.c_str());
 }
 
-void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
+std::vector<std::string> SALOMEDS_Study::GetLockerID()
 {
-  if(_isLocal) _local_impl->EnableUseCaseAutoFilling(isEnabled);
-  else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
+  std::vector<std::string> aVector;
+  int aLength, i;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aVector = _local_impl->GetLockerID();
+  }
+  else {
+    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetLockerID();
+    aLength = aSeq->length();
+    for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
+  }
+  return aVector;
 }
 
-bool SALOMEDS_Study::DumpStudy(const string& thePath, const string& theBaseName, bool isPublished)
+
+void SALOMEDS_Study::SetReal(const std::string& theVarName, const double theValue)
 {
-  //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one
-  bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished);
-  return ret;
-}     
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::REAL_VAR);
+  }
+  else 
+    _corba_impl->SetReal((char*)theVarName.c_str(),theValue);
+}
 
-std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
+void SALOMEDS_Study::SetInteger(const std::string& theVarName, const int theValue)
 {
-  return _orb->object_to_string(theObject); 
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  }
+  else 
+    _corba_impl->SetInteger((char*)theVarName.c_str(),theValue);
 }
 
-CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) 
-{ 
-  return _orb->string_to_object(theIOR.c_str()); 
-} 
+void SALOMEDS_Study::SetBoolean(const std::string& theVarName, const bool theValue)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetVariable(theVarName,
+                             theValue,
+                             SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  }
+  else 
+    _corba_impl->SetBoolean((char*)theVarName.c_str(),theValue);
+}
 
-void SALOMEDS_Study::init_orb()
+void SALOMEDS_Study::SetString(const std::string& theVarName, const std::string& theValue)
 {
-  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
-  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()); 
-  _orb = init(0 , 0 ) ;     
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->SetStringVariable(theVarName,
+                                   theValue,
+                                   SALOMEDSImpl_GenericVariable::STRING_VAR);
+  }
+  else 
+    _corba_impl->SetString((char*)theVarName.c_str(),(char*)theValue.c_str());
 }
 
-SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy()
+void SALOMEDS_Study::SetStringAsDouble(const std::string& theVarName, const double theValue)
 {
   if (_isLocal) {
     SALOMEDS::Locker lock;
+    _local_impl->SetStringVariableAsDouble(theVarName,
+                                           theValue,
+                                           SALOMEDSImpl_GenericVariable::STRING_VAR);
+  }
+  else 
+    _corba_impl->SetStringAsDouble((char*)theVarName.c_str(),theValue);
+}
 
-    if (!CORBA::is_nil(_corba_impl)) return _corba_impl;
-    std::string anIOR = _local_impl->GetTransientReference().ToCString();
-    SALOMEDS::Study_var aStudy;
-    if (!_local_impl->IsError() && anIOR != "") {
-      aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str()));
-    }
-    else {
-      SALOMEDS_Study_i *aStudy_servant = new SALOMEDS_Study_i(_local_impl, _orb);
-      aStudy = aStudy_servant->_this();
-      _local_impl->SetTransientReference(_orb->object_to_string(aStudy));
-    }
-    return aStudy._retn();
+double SALOMEDS_Study::GetReal(const std::string& theVarName)
+{
+  double aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetReal((char*)theVarName.c_str());
+  return aResult;
+}
+
+int SALOMEDS_Study::GetInteger(const std::string& theVarName)
+{
+  int aResult;  
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = (int) _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetInteger((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::GetBoolean(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = (bool) _local_impl->GetVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetBoolean((char*)theVarName.c_str());
+  return aResult;
+}
+
+std::string SALOMEDS_Study::GetString(const std::string& theVarName)
+{
+  std::string aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->GetStringVariableValue(theVarName);
+  }
+  else 
+    aResult = _corba_impl->GetString((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsReal(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::REAL_VAR);
+  }
+  else
+    aResult = _corba_impl->IsReal((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsInteger(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+  }
+  else
+    aResult = _corba_impl->IsInteger((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsBoolean(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                   SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+  }
+  else
+    aResult = _corba_impl->IsBoolean((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsString(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsTypeOf(theVarName, 
+                                    SALOMEDSImpl_GenericVariable::STRING_VAR);
+  }
+  else
+    aResult = _corba_impl->IsString((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsVariable(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsVariable(theVarName);
+  }
+  else
+    aResult = _corba_impl->IsVariable((char*)theVarName.c_str());
+  return aResult;
+}
+
+std::vector<std::string> SALOMEDS_Study::GetVariableNames()
+{
+  std::vector<std::string> aVector;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aVector = _local_impl->GetVariableNames();
   }
   else {
-    return _corba_impl;
+    SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetVariableNames();
+    int aLength = aSeq->length();
+    for (int i = 0; i < aLength; i++) 
+      aVector.push_back( std::string(aSeq[i].in()) );
   }
+  return aVector;
+}
+
+bool SALOMEDS_Study::RemoveVariable(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->RemoveVariable(theVarName);
+  }
+  else
+    aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->RenameVariable(theVarName, theNewVarName);
+  }
+  else
+    aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str());
+  return aResult;
+}
+
+bool SALOMEDS_Study::IsVariableUsed(const std::string& theVarName)
+{
+  bool aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->IsVariableUsed(theVarName);
+  }
+  else
+    aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str());
+  return aResult;
+}
+
+std::vector< std::vector<std::string> > SALOMEDS_Study::ParseVariables(const std::string& theVars)
+{
+  std::vector< std::vector<std::string> > aResult;
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    aResult = _local_impl->ParseVariables(theVars);
+  }
+  else {
+    SALOMEDS::ListOfListOfStrings_var aSeq = _corba_impl->ParseVariables(theVars.c_str());
+    for (int i = 0, n = aSeq->length(); i < n; i++) {
+      std::vector<std::string> aVector;
+      SALOMEDS::ListOfStrings aSection = aSeq[i];
+      for (int j = 0, m = aSection.length(); j < m; j++) {
+        aVector.push_back( std::string(aSection[j].in()) );
+      }
+      aResult.push_back( aVector );
+    }
+  }
+  return aResult;
+}
 
-  return SALOMEDS::Study::_nil();
+std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) 
+{
+  return _orb->object_to_string(theObject); 
 }
 
-_PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const string& theID, int theSavePoint)
+CORBA::Object_ptr SALOMEDS_Study::ConvertIORToObject(const std::string& theIOR) 
+{ 
+  return _orb->string_to_object(theIOR.c_str()); 
+} 
+
+_PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const std::string& theID, int theSavePoint)
 {
   SALOMEDSClient_AttributeParameter* AP = NULL;
   if(theSavePoint >= 0) {
@@ -700,8 +989,8 @@ _PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const string& theID
   return _PTR(AttributeParameter)(AP);
 }
 
-_PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const string& theID, 
-                                                            const string& theModuleName, int theSavePoint)
+_PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const std::string& theID, 
+                                                             const std::string& theModuleName, int theSavePoint)
 {
   SALOMEDSClient_AttributeParameter* AP = NULL;
   if(theSavePoint > 0) {
@@ -715,3 +1004,19 @@ _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const string& theID
   }
   return _PTR(AttributeParameter)(AP);
 }
+
+void SALOMEDS_Study::attach(SALOMEDS::Observer_ptr theObserver,bool modify)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return;
+
+  _corba_impl->attach(theObserver,modify);
+}
+
+void SALOMEDS_Study::detach(SALOMEDS::Observer_ptr theObserver)
+{
+  if(CORBA::is_nil(_corba_impl))
+    return;
+
+  _corba_impl->detach(theObserver);
+}