X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study.cxx;h=63d44b5ac2acb37fbfc6279e84fbeeea2295e5b9;hb=718e0abe0126e5e53b3ba41fff1028efcf5bc887;hp=67220592ea50bd39eb33faacca6a697daf9deeca;hpb=836c34a4e2dd99f1f302a2c3ae93a51cd182368f;p=modules%2Fyacs.git diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 67220592e..63d44b5ac 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -1,28 +1,29 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2007-2016 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 -// +// // 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" @@ -44,18 +45,17 @@ #include "SALOMEDSImpl_SComponentIterator.hxx" #include "SALOMEDSImpl_AttributeStudyProperties.hxx" #include "SALOMEDSImpl_AttributeParameter.hxx" +#include "SALOMEDSImpl_GenericVariable.hxx" #include "SALOMEDSImpl_UseCaseBuilder.hxx" #include "SALOMEDS_Driver_i.hxx" #include "SALOMEDS_Study_i.hxx" -#include -#include -#include - #include "Utils_ORB_INIT.hxx" #include "Utils_SINGLETON.hxx" +#include "Basics_Utils.hxx" + #ifdef WIN32 #include #else @@ -63,11 +63,7 @@ #include #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; @@ -83,9 +79,9 @@ SALOMEDS_Study::SALOMEDS_Study(SALOMEDS::Study_ptr theStudy) long pid = (long)getpid(); #endif - long addr = theStudy->GetLocalImpl(GetHostname().c_str(), pid, _isLocal); + long addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal); if(_isLocal) { - _local_impl = ((SALOMEDSImpl_Study*)(addr)); + _local_impl = reinterpret_cast(addr); _corba_impl = SALOMEDS::Study::_duplicate(theStudy); } else { @@ -105,9 +101,9 @@ std::string SALOMEDS_Study::GetPersistentReference() std::string aRef; if (_isLocal) { SALOMEDS::Locker lock; - aRef = _local_impl->GetPersistentReference().ToCString(); + aRef = _local_impl->GetPersistentReference(); } - else aRef = _corba_impl->GetPersistentReference(); + else aRef = (CORBA::String_var)_corba_impl->GetPersistentReference(); return aRef; } @@ -116,7 +112,7 @@ std::string SALOMEDS_Study::GetTransientReference() std::string aRef; if (_isLocal) { SALOMEDS::Locker lock; - aRef = _local_impl->GetTransientReference().ToCString(); + aRef = _local_impl->GetTransientReference(); } else aRef = _corba_impl->GetTransientReference(); return aRef; @@ -139,9 +135,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 +153,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 +172,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 +200,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 aSeq = _local_impl->FindObjectByName(anObjectName, aComponentName); + aLength = aSeq.size(); + 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 +221,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 +238,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 +256,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 +274,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,11 +288,12 @@ _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(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; @@ -302,7 +303,7 @@ void SALOMEDS_Study::SetContext(const std::string& thePath) { if (_isLocal) { SALOMEDS::Locker lock; - _local_impl->SetContext((char*)thePath.c_str()); + _local_impl->SetContext(thePath); } else _corba_impl->SetContext((char*)thePath.c_str()); } @@ -312,7 +313,7 @@ std::string SALOMEDS_Study::GetContext() std::string aPath; if (_isLocal) { SALOMEDS::Locker lock; - aPath = _local_impl->GetContext().ToCString(); + aPath = _local_impl->GetContext(); } else aPath = _corba_impl->GetContext(); return aPath; @@ -324,10 +325,7 @@ std::vector SALOMEDS_Study::GetObjectNames(const std::string& theCo 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()); + aVector = _local_impl->GetObjectNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str()); @@ -343,11 +341,7 @@ std::vector SALOMEDS_Study::GetDirectoryNames(const std::string& th 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()); + aVector = _local_impl->GetDirectoryNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str()); @@ -363,10 +357,7 @@ std::vector SALOMEDS_Study::GetFileNames(const std::string& theCont 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()); + aVector = _local_impl->GetFileNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str()); @@ -383,10 +374,7 @@ std::vector SALOMEDS_Study::GetComponentNames(const std::string& th 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()); + aVector = _local_impl->GetComponentNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str()); @@ -402,8 +390,7 @@ _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO) 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 +424,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,7 +440,7 @@ 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(); return aName; @@ -463,7 +450,7 @@ 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()); } @@ -498,13 +485,23 @@ bool SALOMEDS_Study::IsModified() else isModified = _corba_impl->IsModified(); return isModified; } + +void SALOMEDS_Study::Modified() +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->Modify(); + } + else _corba_impl->Modified(); +} + std::string SALOMEDS_Study::URL() { std::string aURL; if (_isLocal) { SALOMEDS::Locker lock; - aURL = _local_impl->URL().ToCString(); + aURL = _local_impl->URL(); } else aURL = _corba_impl->URL(); return aURL; @@ -514,7 +511,7 @@ void SALOMEDS_Study::URL(const std::string& url) { if (_isLocal) { SALOMEDS::Locker lock; - _local_impl->URL((char*)url.c_str()); + _local_impl->URL(url); } else _corba_impl->URL((char*)url.c_str()); } @@ -547,12 +544,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 aSeq = _local_impl->FindDependances(*(aSO->GetLocalImpl())); + if (aSeq.size()) { + aLength = aSeq.size(); + for (i = 0; i < aLength; i++) + aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i]))); } } else { @@ -570,7 +566,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 +575,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 +587,7 @@ std::vector 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 +603,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 { @@ -636,13 +629,305 @@ void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled) else _corba_impl->EnableUseCaseAutoFilling(isEnabled); } -bool SALOMEDS_Study::DumpStudy(const string& thePath, const string& theBaseName, bool isPublished) +bool SALOMEDS_Study::DumpStudy(const std::string& thePath, + const std::string& theBaseName, + bool isPublished, + bool isMultiFile) { //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); + if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it + bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished, isMultiFile); return ret; } +void SALOMEDS_Study::SetStudyLock(const std::string& theLockerID) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetStudyLock(theLockerID.c_str()); + } + 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()); +} + +std::vector SALOMEDS_Study::GetLockerID() +{ + std::vector 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; +} + + +void SALOMEDS_Study::SetReal(const std::string& theVarName, const double theValue) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetVariable(theVarName, + theValue, + SALOMEDSImpl_GenericVariable::REAL_VAR); + } + else + _corba_impl->SetReal((char*)theVarName.c_str(),theValue); +} + +void SALOMEDS_Study::SetInteger(const std::string& theVarName, const int theValue) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetVariable(theVarName, + theValue, + SALOMEDSImpl_GenericVariable::INTEGER_VAR); + } + else + _corba_impl->SetInteger((char*)theVarName.c_str(),theValue); +} + +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::SetString(const std::string& theVarName, const std::string& theValue) +{ + 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()); +} + +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); +} + +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 SALOMEDS_Study::GetVariableNames() +{ + std::vector aVector; + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetVariableNames(); + } + else { + 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 > SALOMEDS_Study::ParseVariables(const std::string& theVars) +{ + std::vector< std::vector > 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 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; +} + std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) { return _orb->object_to_string(theObject); @@ -665,8 +950,8 @@ SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() if (_isLocal) { SALOMEDS::Locker lock; - if (!CORBA::is_nil(_corba_impl)) return _corba_impl; - std::string anIOR = _local_impl->GetTransientReference().ToCString(); + if (!CORBA::is_nil(_corba_impl)) return SALOMEDS::Study::_duplicate(_corba_impl); + std::string anIOR = _local_impl->GetTransientReference(); SALOMEDS::Study_var aStudy; if (!_local_impl->IsError() && anIOR != "") { aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str())); @@ -676,16 +961,18 @@ SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() aStudy = aStudy_servant->_this(); _local_impl->SetTransientReference(_orb->object_to_string(aStudy)); } + _corba_impl = SALOMEDS::Study::_duplicate(aStudy); return aStudy._retn(); } else { - return _corba_impl; + return SALOMEDS::Study::_duplicate(_corba_impl); } return SALOMEDS::Study::_nil(); } -_PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const string& theID, int theSavePoint) + +_PTR(AttributeParameter) SALOMEDS_Study::GetCommonParameters(const std::string& theID, int theSavePoint) { SALOMEDSClient_AttributeParameter* AP = NULL; if(theSavePoint >= 0) { @@ -700,8 +987,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 +1002,15 @@ _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)) GetStudy(); //If CORBA implementation is null then retrieve it + _corba_impl->attach(theObserver,modify); +} + +void SALOMEDS_Study::detach(SALOMEDS::Observer_ptr theObserver) +{ + if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it + _corba_impl->detach(theObserver); +}