Salome HOME
CCAR: remove some memory leaks in SALOMEDS CORBA interface
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.cxx
index d5f80fb03286edd0b5fa298a781ad32bd682105b..fb0e28abdf407df09442b4e09ede8351b8ca64f5 100644 (file)
@@ -1,27 +1,28 @@
-// Copyright (C) 2005  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 
-// Lesser General Public License for more details.
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// 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
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/
+//  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
+//  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
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : SALOMEDS_Study_i.cxx
 //  Author : Sergey RUIN
 //  Module : SALOME
-
-
+//
 #include "utilities.h"
 #include "SALOMEDS_Study_i.hxx"
 #include "SALOMEDS_UseCaseIterator_i.hxx"
 #include "SALOMEDSImpl_ChildIterator.hxx"
 #include "SALOMEDSImpl_IParameters.hxx"
 
-#include <TColStd_SequenceOfExtendedString.hxx>
-#include <TColStd_HSequenceOfAsciiString.hxx>
-#include <TColStd_HSequenceOfTransient.hxx>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
+#include "DF_Label.hxx"
+#include "DF_Attribute.hxx"
 
-#include <TDF_Label.hxx>
-#include <TDF_Attribute.hxx>
+#include "Basics_Utils.hxx"
 
 #ifdef WIN32
 #include <process.h>
@@ -56,8 +53,6 @@
 #include <unistd.h>
 #endif
 
-#include "OpUtil.hxx"
-
 using namespace std;
 
 //============================================================================
@@ -65,7 +60,7 @@ using namespace std;
  *  Purpose  : SALOMEDS_Study_i constructor
  */
 //============================================================================
-SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(SALOMEDSImpl_Study) theImpl,
+SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl,
                                   CORBA::ORB_ptr orb)
 {
   _orb = CORBA::ORB::_duplicate(orb);
@@ -91,7 +86,7 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i()
 char* SALOMEDS_Study_i::GetPersistentReference()
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->GetPersistentReference().ToCString());
+  return CORBA::string_dup(_impl->GetPersistentReference().c_str());
 }
 //============================================================================
 /*! Function : GetTransientReference
@@ -101,7 +96,7 @@ char* SALOMEDS_Study_i::GetPersistentReference()
 char* SALOMEDS_Study_i::GetTransientReference()
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->GetTransientReference().ToCString()); 
+  return CORBA::string_dup(_impl->GetTransientReference().c_str()); 
 }
 
 //============================================================================
@@ -124,7 +119,7 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponent
 {
   SALOMEDS::Locker lock; 
   
-  Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponent(TCollection_AsciiString((char*)aComponentName));
+  SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(string(aComponentName));
   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
 
   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
@@ -140,7 +135,7 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen
 {
   SALOMEDS::Locker lock; 
   
-  Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponentID(TCollection_AsciiString((char*)aComponentID));
+  SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(string((char*)aComponentID));
   if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil();
 
   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb);
@@ -156,11 +151,11 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName)
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObject(TCollection_AsciiString((char*)anObjectName));
+  SALOMEDSImpl_SObject aSO = _impl->FindObject(string((char*)anObjectName));
   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
 
-  if(aSO->DynamicType() == STANDARD_TYPE(SALOMEDSImpl_SComponent)) {
-    Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO);
+  if(aSO.IsComponent()) {
+    SALOMEDSImpl_SComponent aSCO = aSO;
     SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb);
     return sco._retn();
   }
@@ -179,7 +174,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID)
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectID(TCollection_AsciiString((char*)anObjectID));
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectID(string((char*)anObjectID));
   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
   return so._retn();
@@ -194,7 +189,9 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID)
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->CreateObjectID((char*)anObjectID);
+  if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil();
+
+  SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID);
   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
 
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
@@ -212,15 +209,14 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char*
 {
   SALOMEDS::Locker lock; 
 
-  Handle(TColStd_HSequenceOfTransient) aSeq = _impl->FindObjectByName(TCollection_AsciiString((char*)anObjectName),
-                                                                     TCollection_AsciiString((char*)aComponentName));
-  int aLength = aSeq->Length();
+  vector<SALOMEDSImpl_SObject> aSeq = _impl->FindObjectByName(string((char*)anObjectName),
+                                                              string((char*)aComponentName));
+  int aLength = aSeq.size();
   SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ;
   listSO->length(aLength);
-  for(int i = 1; i<=aLength; i++) {
-    Handle(SALOMEDSImpl_SObject) aSO = Handle(SALOMEDSImpl_SObject)::DownCast(aSeq->Value(i));
-    SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
-    listSO[i-1] = so ;
+  for(int i = 0; i<aLength; i++) {
+    SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSeq[i], _orb);
+    listSO[i] = so ;
   }
   return listSO._retn() ;
 }
@@ -234,7 +230,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR)
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectIOR(TCollection_AsciiString((char*)anObjectIOR));
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(string((char*)anObjectIOR));
   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
 
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
@@ -250,7 +246,7 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath)
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectByPath(TCollection_AsciiString((char*)thePath));
+  SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(string((char*)thePath));
   if(aSO.IsNull()) return SALOMEDS::SObject::_nil();
 
   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb);
@@ -266,9 +262,9 @@ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
 {
   SALOMEDS::Locker lock; 
 
-  TCollection_AsciiString aPath("");
-  if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.ToCString());
-  Handle(SALOMEDSImpl_SObject) aSO;
+  string aPath("");
+  if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str());
+  SALOMEDSImpl_SObject aSO;
   SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject);
 
   if(!CORBA::is_nil(aSObj)) {
@@ -278,10 +274,10 @@ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject)
     aSO  = _impl->FindObjectIOR(_orb->object_to_string(theObject));
   }
    
-  if(aSO.IsNull()) return CORBA::string_dup(aPath.ToCString());
+  if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str());
   
   aPath = _impl->GetObjectPath(aSO);
-  return  CORBA::string_dup(aPath.ToCString());
+  return  CORBA::string_dup(aPath.c_str());
 }
 
 
@@ -294,7 +290,7 @@ void SALOMEDS_Study_i::SetContext(const char* thePath)
 {
   SALOMEDS::Locker lock; 
 
-  _impl->SetContext(TCollection_AsciiString((char*)thePath));
+  _impl->SetContext(string((char*)thePath));
   if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") 
     throw SALOMEDS::Study::StudyInvalidContext();  
 }
@@ -307,9 +303,9 @@ void SALOMEDS_Study_i::SetContext(const char* thePath)
 char* SALOMEDS_Study_i::GetContext() 
 {
   SALOMEDS::Locker lock; 
-
+  
   if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
-  return CORBA::string_dup(_impl->GetContext().ToCString());
+  return CORBA::string_dup(_impl->GetContext().c_str());
 }
 
 //============================================================================
@@ -322,13 +318,20 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext
   SALOMEDS::Locker lock; 
 
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetObjectNames(TCollection_AsciiString((char*)theContext));
-  int aLength = aSeq->Length();
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  vector<string> aSeq = _impl->GetObjectNames(string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
   aResult->length(aLength);
-  for(int anIndex = 1; anIndex <= aLength; anIndex++) {
-    aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
 
@@ -342,13 +345,20 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theCont
   SALOMEDS::Locker lock; 
 
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetDirectoryNames(TCollection_AsciiString((char*)theContext));
-  int aLength = aSeq->Length();
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  vector<string> aSeq = _impl->GetDirectoryNames(string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
   aResult->length(aLength);
-  for(int anIndex = 1; anIndex <= aLength; anIndex++) {
-    aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
 
@@ -362,19 +372,27 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext)
   SALOMEDS::Locker lock; 
 
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetFileNames(TCollection_AsciiString((char*)theContext));
-  int aLength = aSeq->Length();
+
+  if (strlen(theContext) == 0 && !_impl->HasCurrentContext())
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  vector<string> aSeq = _impl->GetFileNames(string((char*)theContext));
+  if (_impl->GetErrorCode() == "InvalidContext")
+    throw SALOMEDS::Study::StudyInvalidContext();
+
+  int aLength = aSeq.size();
   aResult->length(aLength);
-  for(int anIndex = 1; anIndex <= aLength; anIndex++) {
-    aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
+  for (int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
 
 //============================================================================
 /*! Function : GetComponentNames
  *  Purpose  : method to get all components names
+ *  SRN:       Note, theContext can be any, it doesn't matter
  */
 //============================================================================
 SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) 
@@ -382,13 +400,15 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theCont
   SALOMEDS::Locker lock; 
 
   SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
-  if (strlen(theContext) == 0 && !_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext();   
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetComponentNames(TCollection_AsciiString((char*)theContext));
-  int aLength = aSeq->Length();
+
+  vector<string> aSeq = _impl->GetComponentNames(string((char*)theContext));
+
+  int aLength = aSeq.size();
   aResult->length(aLength);
-  for(int anIndex = 1; anIndex <= aLength; anIndex++) {
-    aResult[anIndex-1] = CORBA::string_dup(TCollection_AsciiString(aSeq->Value(anIndex)).ToCString());
+  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
+
   return aResult._retn();
 }
 
@@ -401,14 +421,13 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_SObject) aSO = _impl->GetSObject(theSO->GetID());
-  Handle(SALOMEDSImpl_ChildIterator) anItr = new SALOMEDSImpl_ChildIterator(aSO);
+  SALOMEDSImpl_SObject aSO = _impl->GetSObject(theSO->GetID());
+  SALOMEDSImpl_ChildIterator anItr(aSO);
 
   //Create iterator
   SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb);
-  SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); 
 
-  return it;
+  return it_servant->_this();
 }
 
 
@@ -445,7 +464,7 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
 char* SALOMEDS_Study_i::Name()
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->Name().ToCString());
+  return CORBA::string_dup(_impl->Name().c_str());
 }
 
 //============================================================================
@@ -456,7 +475,7 @@ char* SALOMEDS_Study_i::Name()
 void SALOMEDS_Study_i::Name(const char* name)
 {
   SALOMEDS::Locker lock;  
-  _impl->Name(TCollection_AsciiString((char*)name));
+  _impl->Name(string((char*)name));
 }
 
 //============================================================================
@@ -492,6 +511,18 @@ CORBA::Boolean  SALOMEDS_Study_i::IsModified()
   return _impl->IsModified();
 }
 
+//============================================================================
+/*! Function : Modified
+ *  Purpose  : Sets a Modified flag of a Study to True
+ */
+//============================================================================
+void  SALOMEDS_Study_i::Modified()
+{
+  SALOMEDS::Locker lock; 
+  return _impl->Modify();
+}
+
+
 //============================================================================
 /*! Function : URL
  *  Purpose  : get URL of the study (persistent reference of the study)
@@ -500,7 +531,7 @@ CORBA::Boolean  SALOMEDS_Study_i::IsModified()
 char* SALOMEDS_Study_i::URL()
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->URL().ToCString());
+  return CORBA::string_dup(_impl->URL().c_str());
 }
 
 //============================================================================
@@ -511,7 +542,7 @@ char* SALOMEDS_Study_i::URL()
 void SALOMEDS_Study_i::URL(const char* url)
 {
   SALOMEDS::Locker lock; 
-  _impl->URL(TCollection_AsciiString((char*)url));
+  _impl->URL(string((char*)url));
 }
 
 
@@ -530,16 +561,16 @@ void SALOMEDS_Study_i::StudyId(CORBA::Short id)
 void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) 
 {
   SALOMEDS::Locker lock; 
-  _impl->UpdateIORLabelMap(TCollection_AsciiString((char*)anIOR), TCollection_AsciiString((char*)anEntry));
+  _impl->UpdateIORLabelMap(string((char*)anIOR), string((char*)anEntry));
 }
 
-SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::ORB_ptr orb) 
+SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) 
 {
   SALOMEDS::Locker lock; 
 
-  Handle(SALOMEDSImpl_AttributeIOR) Att;
-  if (theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(),Att)){
-    char* IOR = CORBA::string_dup(TCollection_AsciiString(Att->Value()).ToCString());
+  SALOMEDSImpl_AttributeIOR* Att = NULL;
+  if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){
+    char* IOR = CORBA::string_dup(Att->Value().c_str());
     CORBA::Object_var obj = orb->string_to_object(IOR);
     SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ;
     ASSERT(!CORBA::is_nil(aStudy));
@@ -550,7 +581,7 @@ SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const TDF_Label theLabel, CORBA::
   return SALOMEDS::Study::_nil();
 }
 
-void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDSImpl_AttributeIOR) theAttribute) 
+void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) 
 {
   SALOMEDS::Locker lock; 
   SALOMEDSImpl_Study::IORUpdated(theAttribute);
@@ -574,7 +605,7 @@ SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
 {
   SALOMEDS::Locker lock; 
   
-  Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr = _impl->GetProperties();
+  SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties();
   SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
   return SP->AttributeStudyProperties::_this();
 }
@@ -582,20 +613,20 @@ SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties()
 char* SALOMEDS_Study_i::GetLastModificationDate() 
 {
   SALOMEDS::Locker lock; 
-  return CORBA::string_dup(_impl->GetLastModificationDate().ToCString());
+  return CORBA::string_dup(_impl->GetLastModificationDate().c_str());
 }
 
 SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() 
 {
   SALOMEDS::Locker lock; 
   
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->GetModificationsDate();
-  int aLength = aSeq->Length();
+  vector<string> aSeq = _impl->GetModificationsDate();
+  int aLength = aSeq.size();
   SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates;
   aDates->length(aLength);
 
-  for(int anIndex = 1; anIndex <= aLength; anIndex++) {
-    aDates[anIndex-1] = CORBA::string_dup(aSeq->Value(anIndex).ToCString());
+  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+    aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
   }
   return aDates._retn();
 }
@@ -623,32 +654,39 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder()
 void SALOMEDS_Study_i::Close()
 {
   SALOMEDS::Locker lock; 
-  
+
   RemovePostponed(-1);
 
   SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
-
   for (; itcomponent->More(); itcomponent->Next()) {
     SALOMEDS::SComponent_var sco = itcomponent->Value();
-         
-    MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType());
+    CORBA::String_var compodatatype=sco->ComponentDataType();
+    MESSAGE ( "Look for an engine for data type :"<< compodatatype);
     // if there is an associated Engine call its method for closing
     CORBA::String_var IOREngine;
     if (sco->ComponentIOR(IOREngine)) {
       // we have found the associated engine to write the data 
-      MESSAGE ( "We have found an engine for data type :"<< sco->ComponentDataType());
-      CORBA::Object_var obj = _orb->string_to_object(IOREngine);
-      if (!CORBA::is_nil(obj)) {
-       SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
-
-       if (!anEngine->_is_nil()) { 
-         SALOMEDS::unlock();
-         anEngine->Close(sco);
-         SALOMEDS::lock();
-       }
-      }
+      MESSAGE ( "We have found an engine for data type :"<< compodatatype);
+      //_narrow can throw a corba exception
+      try
+        {
+          CORBA::Object_var obj = _orb->string_to_object(IOREngine);
+          if (!CORBA::is_nil(obj)) 
+            {
+              SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ;
+              if (!anEngine->_is_nil()) 
+                { 
+                  SALOMEDS::unlock();
+                  anEngine->Close(sco);
+                  SALOMEDS::lock();
+                }
+            }
+        } 
+      catch (CORBA::Exception&) 
+        {/*pass*/ }
     }
   }
+
   _impl->Close();
 }
 
@@ -660,23 +698,13 @@ void SALOMEDS_Study_i::Close()
 void SALOMEDS_Study_i::AddPostponed(const char* theIOR) 
 {
   SALOMEDS::Locker lock; 
-  CORBA::Object_var obj = _orb->string_to_object(theIOR);
-  if (!CORBA::is_nil(obj)) {
-    SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
-    if (!CORBA::is_nil(aGeneric)) _impl->AddPostponed((char*)theIOR);     
-  }
+  //Not implemented
 }
 
 void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) 
 {
   SALOMEDS::Locker lock; 
-
-  CORBA::Object_var obj = _orb->string_to_object(theIOR);
-  if (!CORBA::is_nil(obj)) {
-    SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj) ;
-    if (!CORBA::is_nil(aGeneric)) _impl->AddCreatedPostponed((char*)theIOR);
-  }
+  //Not implemented
 }
 
 //============================================================================
@@ -684,38 +712,26 @@ void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR)
  *  Purpose  : 
  */
 //============================================================================
-#ifndef WNT
-void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit
+#ifndef WIN32
+void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/
 #else
-void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit
+void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/
 #endif
 {  
   SALOMEDS::Locker lock; 
 
-  Handle(TColStd_HSequenceOfAsciiString) aSeq = _impl->RemovePostponed(theUndoLimit);
-  int aLegth = aSeq->Length();
-  for(int i = 1; i <= aLegth; i++) {
-    TCollection_AsciiString anIOR = aSeq->Value(i);
-    //mkr : fix for bug IPAL9408 : check the length of anIOR
-    //                             before take value from it
-    if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'c') {
-      CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
-      SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-      if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-    }
-    else if ( !anIOR.IsEmpty() && anIOR.Value(1) == 'd') {
-      CORBA::Object_var obj = _orb->string_to_object(anIOR.Split(1).ToCString());
+  vector<string> anIORs = _impl->GetIORs();
+  int i, aSize = (int)anIORs.size();
+
+  for(i = 0; i < aSize; i++) {
+    try {
+      CORBA::Object_var obj = _orb->string_to_object(anIORs[i].c_str());
       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-    }
-    else {
-      try {
-       CORBA::Object_var obj = _orb->string_to_object(anIOR.ToCString());
-       SALOME::GenericObj_var aGeneric = SALOME::GenericObj::_narrow(obj);
-       if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
-      } catch (...) {}
-    }
+    } catch (...) {}
   }
+
+  //Not implemented
 }
 
 //============================================================================
@@ -723,15 +739,14 @@ void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit)
  *  Purpose  : 
  */
 //============================================================================
-#ifndef WNT
+#ifndef WIN32
 void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) 
 #else
 void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) 
 #endif
 {
   SALOMEDS::Locker lock; 
-
-  _impl->UndoPostponed(theWay);
+  //Not implemented
 }
 
 
@@ -746,7 +761,7 @@ CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath,
 {
   SALOMEDS::Locker lock; 
 
-  TCollection_AsciiString aPath((char*)thePath), aBaseName((char*)theBaseName);
+  string aPath((char*)thePath), aBaseName((char*)theBaseName);
   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
   CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
   delete factory;
@@ -762,7 +777,7 @@ SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const cha
 {
   SALOMEDS::Locker lock; 
   
-  Handle(SALOMEDSImpl_AttributeParameter) anAttr = _impl->GetCommonParameters(theID, theSavePoint);
+  SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint);
   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
   return SP->AttributeParameter::_this();
 }
@@ -778,11 +793,254 @@ SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const cha
 {
   SALOMEDS::Locker lock; 
   
-  Handle(SALOMEDSImpl_AttributeParameter) anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
+  SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint);
   SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb);
   return SP->AttributeParameter::_this();
 }
 
+//============================================================================
+/*! Function : SetStudyLock
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID)
+{
+  SALOMEDS::Locker lock; 
+  _impl->SetStudyLock(theLockerID);
+}
+
+//============================================================================
+/*! Function : IsStudyLocked
+ *  Purpose  : 
+ */
+//============================================================================
+bool SALOMEDS_Study_i::IsStudyLocked()
+{
+  SALOMEDS::Locker lock; 
+  return _impl->IsStudyLocked();
+}
+
+//============================================================================
+/*! Function : UnLockStudy
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID)
+{
+  SALOMEDS::Locker lock; 
+  _impl->UnLockStudy(theLockerID);
+}
+
+//============================================================================
+/*! Function : GetLockerID
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID()
+{
+  SALOMEDS::Locker lock; 
+
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+
+  vector<string> aSeq = _impl->GetLockerID();
+
+  int aLength = aSeq.size();
+  aResult->length(aLength);
+  for(int anIndex = 0; anIndex < aLength; anIndex++) {
+    aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str());
+  }
+  return aResult._retn();
+}
+//============================================================================
+/*! Function : SetReal
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetReal(const char* theVarName, CORBA::Double theValue)
+{
+  _impl->SetVariable(string(theVarName), 
+                     theValue,
+                     SALOMEDSImpl_GenericVariable::REAL_VAR);
+}
+
+//============================================================================
+/*! Function : SetInteger
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue)
+{
+  _impl->SetVariable(string(theVarName), 
+                     theValue,
+                     SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+}
+
+//============================================================================
+/*! Function : SetBoolean
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue)
+{
+  _impl->SetVariable(string(theVarName), 
+                     theValue,
+                     SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+}
+
+//============================================================================
+/*! Function : GetReal
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName)
+{
+  return _impl->GetVariableValue(string(theVarName));
+}
+
+//============================================================================
+/*! Function : GetInteger
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName)
+{
+  return (int)_impl->GetVariableValue(string(theVarName));
+}
+
+//============================================================================
+/*! Function : GetBoolean
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName)
+{
+  return (bool)_impl->GetVariableValue(string(theVarName));
+}
+
+//============================================================================
+/*! Function : IsReal
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName)
+{
+  return _impl->IsTypeOf(string(theVarName),
+                         SALOMEDSImpl_GenericVariable::REAL_VAR);
+}
+
+//============================================================================
+/*! Function : IsInteger
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName)
+{
+  return _impl->IsTypeOf(string(theVarName),
+                         SALOMEDSImpl_GenericVariable::INTEGER_VAR);
+}
+
+//============================================================================
+/*! Function : IsBoolean
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName)
+{
+  return _impl->IsTypeOf(string(theVarName),
+                         SALOMEDSImpl_GenericVariable::BOOLEAN_VAR);
+}
+
+//============================================================================
+/*! Function : IsVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName)
+{
+  return _impl->IsVariable(string(theVarName));
+}
+
+//============================================================================
+/*! Function : GetVariableNames
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames()
+{
+  vector<string> aVarNames = _impl->GetVariableNames();
+  SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings;
+  
+  int aLen = aVarNames.size();
+  aResult->length(aLen);
+  
+  for (int anInd = 0; anInd < aLen; anInd++)
+    aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
+  
+  return aResult._retn();
+}
+
+//============================================================================
+/*! Function : RemoveVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName)
+{
+  return _impl->RemoveVariable(string(theVarName));
+}
+
+//============================================================================
+/*! Function : RenameVariable
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName)
+{
+  return _impl->RenameVariable(string(theVarName), string(theNewVarName));
+}
+
+//============================================================================
+/*! Function : IsVariableUsed
+ *  Purpose  : 
+ */
+//============================================================================
+CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName)
+{
+  return _impl->IsVariableUsed(string(theVarName));
+}
+
+
+//============================================================================
+/*! Function : ParseVariables
+ *  Purpose  : 
+ */
+//============================================================================
+SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName)
+{
+  vector< vector<string> > aSections = _impl->ParseVariables(string(theVarName));
+
+  SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings;
+
+  int aSectionsLen = aSections.size();
+  aResult->length(aSectionsLen);
+
+  for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) {
+    vector<string> aVarNames = aSections[aSectionInd];
+
+    SALOMEDS::ListOfStrings_var aList = new SALOMEDS::ListOfStrings;
+
+    int aLen = aVarNames.size();
+    aList->length(aLen);
+
+    for (int anInd = 0; anInd < aLen; anInd++)
+      aList[anInd] = CORBA::string_dup(aVarNames[anInd].c_str());
+
+    aResult[aSectionInd] = aList;
+  }
+
+  return aResult._retn();
+}
+
 //============================================================================
 /*! Function : GetDefaultScript
  *  Purpose  : 
@@ -796,17 +1054,37 @@ char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char*
   return CORBA::string_dup(script.c_str());
 }
 
+//============================================================================
+/*! Function : EnableUseCaseAutoFilling
+ *  Purpose  : 
+ */
+//============================================================================
+void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) 
+{ 
+  _impl->EnableUseCaseAutoFilling(isEnabled); 
+  SALOMEDSImpl_StudyBuilder* builder = _builder->GetImpl();
+  if(builder) {
+    if(isEnabled) {
+      builder->SetOnAddSObject(_impl->GetCallback());
+      builder->SetOnRemoveSObject(_impl->GetCallback());
+    }
+    else {
+      builder->SetOnAddSObject(NULL);
+      builder->SetOnRemoveSObject(NULL);
+    }
+  }
+}
+
 //===========================================================================
 //   PRIVATE FUNCTIONS
 //===========================================================================
-CORBA::Long SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
+CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
 {
 #ifdef WIN32
   long pid = (long)_getpid();
 #else
   long pid = (long)getpid();
 #endif  
-  isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
-  SALOMEDSImpl_Study* local_impl = _impl.operator->();
-  return ((long)local_impl);
+  isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
+  return reinterpret_cast<CORBA::LongLong>(_impl);
 }