X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study.cxx;h=1947f674c18d0afff288b74109dfd2e6947675be;hb=9749fc1db72bd80e278405114b05ffc69b5031da;hp=1f6c1ee8719408dccad0baa76082c86b606cf111;hpb=35960e77d7f9f2a5cac7d6550c23f12943bc4378;p=modules%2Fyacs.git diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index 1f6c1ee87..1947f674c 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -1,56 +1,61 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// Copyright (C) 2007-2013 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 +// 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 +// +// 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 "SALOMEDS.hxx" #include "SALOMEDS_SComponent.hxx" -#include "SALOMEDSImpl_SComponent.hxx" #include "SALOMEDS_SObject.hxx" -#include "SALOMEDSImpl_SObject.hxx" #include "SALOMEDS_StudyBuilder.hxx" -#include "SALOMEDSImpl_StudyBuilder.hxx" #include "SALOMEDS_ChildIterator.hxx" -#include "SALOMEDSImpl_ChildIterator.hxx" #include "SALOMEDS_SComponentIterator.hxx" -#include "SALOMEDSImpl_SComponentIterator.hxx" #include "SALOMEDS_AttributeStudyProperties.hxx" -#include "SALOMEDSImpl_AttributeStudyProperties.hxx" +#include "SALOMEDS_AttributeParameter.hxx" #include "SALOMEDS_UseCaseBuilder.hxx" + +#include "SALOMEDSImpl_SComponent.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_StudyBuilder.hxx" +#include "SALOMEDSImpl_ChildIterator.hxx" +#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 @@ -58,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; @@ -78,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 { @@ -98,15 +99,21 @@ SALOMEDS_Study::~SALOMEDS_Study() std::string SALOMEDS_Study::GetPersistentReference() { std::string aRef; - if(_isLocal) aRef = _local_impl->GetPersistentReference().ToCString(); - else aRef = _corba_impl->GetPersistentReference(); + if (_isLocal) { + SALOMEDS::Locker lock; + aRef = _local_impl->GetPersistentReference(); + } + else aRef = (CORBA::String_var)_corba_impl->GetPersistentReference(); return aRef; } std::string SALOMEDS_Study::GetTransientReference() { std::string aRef; - if(_isLocal) aRef = _local_impl->GetTransientReference().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + aRef = _local_impl->GetTransientReference(); + } else aRef = _corba_impl->GetTransientReference(); return aRef; } @@ -114,7 +121,10 @@ std::string SALOMEDS_Study::GetTransientReference() bool SALOMEDS_Study::IsEmpty() { bool ret; - if(_isLocal) ret = _local_impl->IsEmpty(); + if (_isLocal) { + SALOMEDS::Locker lock; + ret = _local_impl->IsEmpty(); + } else ret = _corba_impl->IsEmpty(); return ret; } @@ -122,14 +132,16 @@ bool SALOMEDS_Study::IsEmpty() _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentName) { SALOMEDSClient_SComponent* aSCO = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_SComponent) aSCO_impl =_local_impl->FindComponent((char*)aComponentName.c_str()); - if(aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponent(aComponentName); + if (!aSCO_impl) return _PTR(SComponent)(aSCO); aSCO = new SALOMEDS_SComponent(aSCO_impl); } else { SALOMEDS::SComponent_var aSCO_impl = _corba_impl->FindComponent((char*)aComponentName.c_str()); - if(CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO); + if (CORBA::is_nil(aSCO_impl)) return _PTR(SComponent)(aSCO); aSCO = new SALOMEDS_SComponent(aSCO_impl); } return _PTR(SComponent)(aSCO); @@ -138,9 +150,11 @@ _PTR(SComponent) SALOMEDS_Study::FindComponent (const std::string& aComponentNam _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID) { SALOMEDSClient_SComponent* aSCO = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_SComponent) aSCO_impl =_local_impl->FindComponentID((char*)aComponentID.c_str()); - if(aSCO_impl.IsNull()) return _PTR(SComponent)(aSCO); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SComponent aSCO_impl = _local_impl->FindComponentID(aComponentID); + if (!aSCO_impl) return _PTR(SComponent)(aSCO); aSCO = new SALOMEDS_SComponent(aSCO_impl); } else { @@ -149,59 +163,66 @@ _PTR(SComponent) SALOMEDS_Study::FindComponentID(const std::string& aComponentID aSCO = new SALOMEDS_SComponent(aSCO_impl); } return _PTR(SComponent)(aSCO); - } _PTR(SObject) SALOMEDS_Study::FindObject(const std::string& anObjectName) { SALOMEDSClient_SObject* aSO = NULL; - if(_isLocal) { - 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)); + if (_isLocal) { + SALOMEDS::Locker lock; + + 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 { SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObject((char*)anObjectName.c_str()); - if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); + if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); SALOMEDS::SComponent_var aSCO_impl = SALOMEDS::SComponent::_narrow(aSO_impl); - if(!CORBA::is_nil(aSCO_impl)) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl)); + if (!CORBA::is_nil(aSCO_impl)) return _PTR(SObject)(new SALOMEDS_SComponent(aSCO_impl)); aSO = new SALOMEDS_SObject(aSO_impl); } return _PTR(SObject)(aSO); } - + std::vector<_PTR(SObject)> SALOMEDS_Study::FindObjectByName(const std::string& anObjectName, - const std::string& aComponentName) + const std::string& aComponentName) { std::vector<_PTR(SObject)> aVector; int i, aLength = 0; - - if(_isLocal) { - 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))))); + + if (_isLocal) { + SALOMEDS::Locker lock; + + 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]))); + for (i = 0; i< aLength; i++) aVector.push_back(_PTR(SObject)(new SALOMEDS_SObject(aSeq[i]))); } return aVector; } - + _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID) { SALOMEDSClient_SObject* aSO = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectID((char*)anObjectID.c_str()); - if(aSO_impl.IsNull()) return _PTR(SObject)(aSO); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectID(anObjectID); + if(!aSO_impl) return _PTR(SObject)(aSO); return _PTR(SObject)(new SALOMEDS_SObject(aSO_impl)); } else { @@ -215,22 +236,33 @@ _PTR(SObject) SALOMEDS_Study::FindObjectID(const std::string& anObjectID) _PTR(SObject) SALOMEDS_Study::CreateObjectID(const std::string& anObjectID) { SALOMEDSClient_SObject* aSO = NULL; - if(_isLocal) aSO = new SALOMEDS_SObject(_local_impl->CreateObjectID((char*)anObjectID.c_str())); - else aSO = new SALOMEDS_SObject(_corba_impl->CreateObjectID((char*)anObjectID.c_str())); + if (_isLocal) { + SALOMEDS::Locker lock; + 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); + } return _PTR(SObject)(aSO); } - + _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR) { SALOMEDSClient_SObject* aSO = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectIOR((char*)anObjectIOR.c_str()); - if(aSO_impl.IsNull()) return _PTR(SObject)(aSO); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectIOR(anObjectIOR); + if (!aSO_impl) return _PTR(SObject)(aSO); aSO = new SALOMEDS_SObject(aSO_impl); } else { SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectIOR((char*)anObjectIOR.c_str()); - if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); + if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); aSO = new SALOMEDS_SObject(aSO_impl); } return _PTR(SObject)(aSO); @@ -239,14 +271,16 @@ _PTR(SObject) SALOMEDS_Study::FindObjectIOR(const std::string& anObjectIOR) _PTR(SObject) SALOMEDS_Study::FindObjectByPath(const std::string& thePath) { SALOMEDSClient_SObject* aSO = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_SObject) aSO_impl = _local_impl->FindObjectByPath((char*)thePath.c_str()); - if(aSO_impl.IsNull()) return _PTR(SObject)(aSO); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO_impl = _local_impl->FindObjectByPath(thePath); + if (!aSO_impl) return _PTR(SObject)(aSO); aSO = new SALOMEDS_SObject(aSO_impl); } else { SALOMEDS::SObject_var aSO_impl = _corba_impl->FindObjectByPath((char*)thePath.c_str()); - if(CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); + if (CORBA::is_nil(aSO_impl)) return _PTR(SObject)(aSO); aSO = new SALOMEDS_SObject(aSO_impl); } return _PTR(SObject)(aSO); @@ -254,23 +288,33 @@ _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) aPath = _local_impl->GetObjectPath(aSO->GetLocalImpl()).ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + 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) _local_impl->SetContext((char*)thePath.c_str()); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->SetContext(thePath); + } else _corba_impl->SetContext((char*)thePath.c_str()); } std::string SALOMEDS_Study::GetContext() { std::string aPath; - if(_isLocal) aPath = _local_impl->GetContext().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + aPath = _local_impl->GetContext(); + } else aPath = _corba_impl->GetContext(); return aPath; } @@ -279,15 +323,14 @@ std::vector SALOMEDS_Study::GetObjectNames(const std::string& theCo { std::vector aVector; int aLength, i; - if(_isLocal) { - 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()); + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetObjectNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetObjectNames((char*)theContext.c_str()); aLength = aSeq->length(); - for(i = 0; i SALOMEDS_Study::GetDirectoryNames(const std::string& th { std::vector aVector; int aLength, i; - if(_isLocal) { - 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()); + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetDirectoryNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetDirectoryNames((char*)theContext.c_str()); aLength = aSeq->length(); - for(i = 0; i SALOMEDS_Study::GetFileNames(const std::string& theCont { std::vector aVector; int aLength, i; - if(_isLocal) { - 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()); + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetFileNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetFileNames((char*)theContext.c_str()); aLength = aSeq->length(); - for(i = 0; i SALOMEDS_Study::GetComponentNames(const std::string& th { std::vector aVector; int aLength, i; - if(_isLocal) { - 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()); + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetComponentNames(theContext); } else { SALOMEDS::ListOfStrings_var aSeq = _corba_impl->GetComponentNames((char*)theContext.c_str()); aLength = aSeq->length(); - for(i = 0; i(theSO.get()); SALOMEDSClient_ChildIterator* aCI = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_ChildIterator) aCIimpl = _local_impl->NewChildIterator(aSO->GetLocalImpl()); + if (_isLocal) { + SALOMEDS::Locker lock; + SALOMEDSImpl_ChildIterator aCIimpl = _local_impl->NewChildIterator(*(aSO->GetLocalImpl())); aCI = new SALOMEDS_ChildIterator(aCIimpl); } else { @@ -363,7 +404,9 @@ _PTR(ChildIterator) SALOMEDS_Study::NewChildIterator(const _PTR(SObject)& theSO) _PTR(SComponentIterator) SALOMEDS_Study::NewComponentIterator() { SALOMEDSClient_SComponentIterator* aCI = NULL; - if(_isLocal) { + if (_isLocal) { + SALOMEDS::Locker lock; + SALOMEDSImpl_SComponentIterator aCIimpl = _local_impl->NewComponentIterator(); aCI = new SALOMEDS_SComponentIterator(aCIimpl); } @@ -374,12 +417,14 @@ _PTR(SComponentIterator) SALOMEDS_Study::NewComponentIterator() return _PTR(SComponentIterator)(aCI); } - + _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder() { SALOMEDSClient_StudyBuilder* aSB = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_StudyBuilder) aSBimpl = _local_impl->NewBuilder(); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_StudyBuilder* aSBimpl = _local_impl->NewBuilder(); aSB = new SALOMEDS_StudyBuilder(aSBimpl); } else { @@ -393,64 +438,101 @@ _PTR(StudyBuilder) SALOMEDS_Study::NewBuilder() std::string SALOMEDS_Study::Name() { std::string aName; - if(_isLocal) aName = _local_impl->Name().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + aName = _local_impl->Name(); + } else aName = _corba_impl->Name(); return aName; } - + void SALOMEDS_Study::Name(const std::string& theName) { - if(_isLocal) _local_impl->Name((char*)theName.c_str()); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->Name(theName); + } else _corba_impl->Name((char*)theName.c_str()); } bool SALOMEDS_Study::IsSaved() { bool isSaved; - if(_isLocal) isSaved = _local_impl->IsSaved(); + if (_isLocal) { + SALOMEDS::Locker lock; + isSaved = _local_impl->IsSaved(); + } else isSaved = _corba_impl->IsSaved(); return isSaved; } void SALOMEDS_Study::IsSaved(bool save) { - if(_isLocal) _local_impl->IsSaved(save); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->IsSaved(save); + } else _corba_impl->IsSaved(save); } bool SALOMEDS_Study::IsModified() { bool isModified; - if(_isLocal) isModified = _local_impl->IsModified(); + if (_isLocal) { + SALOMEDS::Locker lock; + isModified = _local_impl->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) aURL = _local_impl->URL().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + aURL = _local_impl->URL(); + } else aURL = _corba_impl->URL(); return aURL; } void SALOMEDS_Study::URL(const std::string& url) { - if(_isLocal) _local_impl->URL((char*)url.c_str()); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->URL(url); + } else _corba_impl->URL((char*)url.c_str()); } int SALOMEDS_Study::StudyId() { int anID; - if(_isLocal) anID = _local_impl->StudyId(); + if (_isLocal) { + SALOMEDS::Locker lock; + anID = _local_impl->StudyId(); + } else anID = _corba_impl->StudyId(); return anID; } void SALOMEDS_Study::StudyId(int id) { - if(_isLocal) _local_impl->StudyId(id); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->StudyId(id); + } else _corba_impl->StudyId(id); } @@ -459,20 +541,20 @@ std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& std::vector<_PTR(SObject)> aVector; SALOMEDS_SObject* aSO = dynamic_cast(theSO.get()); int aLength, i; - if(_isLocal) { - 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))))); + if (_isLocal) { + SALOMEDS::Locker lock; + + 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 { SALOMEDS::Study::ListOfSObject_var aSeq = _corba_impl->FindDependances(aSO->GetCORBAImpl()); aLength = aSeq->length(); - for(i=0; i SALOMEDS_Study::FindDependances(const _PTR(SObject)& _PTR(AttributeStudyProperties) SALOMEDS_Study::GetProperties() { SALOMEDSClient_AttributeStudyProperties* aProp; - if(_isLocal) aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties()); - else aProp = new SALOMEDS_AttributeStudyProperties(_corba_impl->GetProperties()); + if (_isLocal) { + SALOMEDS::Locker lock; + aProp = new SALOMEDS_AttributeStudyProperties(_local_impl->GetProperties()); + } + else aProp = new SALOMEDS_AttributeStudyProperties((SALOMEDS::AttributeStudyProperties_var)_corba_impl->GetProperties()); return _PTR(AttributeStudyProperties)(aProp); } std::string SALOMEDS_Study::GetLastModificationDate() { std::string aDate; - if(_isLocal) aDate = _local_impl->GetLastModificationDate().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + aDate = _local_impl->GetLastModificationDate(); + } else aDate = _corba_impl->GetLastModificationDate(); return aDate; } @@ -497,15 +585,14 @@ std::vector SALOMEDS_Study::GetModificationsDate() { std::vector aVector; int aLength, i; - if(_isLocal) { - Handle(TColStd_HSequenceOfAsciiString) aSeq = _local_impl->GetModificationsDate(); - aLength = aSeq->Length(); - for(i=1; i<=aLength; i++) aVector.push_back(aSeq->Value(i).ToCString()); + if (_isLocal) { + SALOMEDS::Locker lock; + aVector = _local_impl->GetModificationsDate(); } else { SALOMEDS::ListOfDates_var aSeq = _corba_impl->GetModificationsDate(); aLength = aSeq->length(); - for(i=0; i SALOMEDS_Study::GetModificationsDate() _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder() { SALOMEDSClient_UseCaseBuilder* aUB = NULL; - if(_isLocal) { - Handle(SALOMEDSImpl_UseCaseBuilder) aUBimpl = _local_impl->GetUseCaseBuilder(); + if (_isLocal) { + SALOMEDS::Locker lock; + + SALOMEDSImpl_UseCaseBuilder* aUBimpl = _local_impl->GetUseCaseBuilder(); aUB = new SALOMEDS_UseCaseBuilder(aUBimpl); } else { @@ -527,7 +616,10 @@ _PTR(UseCaseBuilder) SALOMEDS_Study::GetUseCaseBuilder() void SALOMEDS_Study::Close() { - if(_isLocal) _local_impl->Close(); + if (_isLocal) { + SALOMEDS::Locker lock; + _local_impl->Close(); + } else _corba_impl->Close(); } @@ -537,18 +629,305 @@ void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled) else _corba_impl->EnableUseCaseAutoFilling(isEnabled); } -bool SALOMEDS_Study::DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished) +bool SALOMEDS_Study::DumpStudy(const std::string& thePath, + const std::string& theBaseName, + bool isPublished, + bool isMultiFile) { - bool ret; - if(_isLocal) { - SALOMEDS_DriverFactory_i* aFactory = new SALOMEDS_DriverFactory_i(_orb); - ret = _local_impl->DumpStudy((char*)thePath.c_str(), (char*)theBaseName.c_str(), isPublished, aFactory); - delete aFactory; - } - else ret = _corba_impl->DumpStudy((char*)thePath.c_str(), (char*)theBaseName.c_str(), isPublished); + //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one + 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); @@ -568,11 +947,13 @@ void SALOMEDS_Study::init_orb() SALOMEDS::Study_ptr SALOMEDS_Study::GetStudy() { - if(_isLocal) { - if(!CORBA::is_nil(_corba_impl)) return _corba_impl; - std::string anIOR = _local_impl->GetTransientReference().ToCString(); + if (_isLocal) { + SALOMEDS::Locker lock; + + 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 != "") { + if (!_local_impl->IsError() && anIOR != "") { aStudy = SALOMEDS::Study::_narrow(_orb->string_to_object(anIOR.c_str())); } else { @@ -580,11 +961,50 @@ 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 std::string& theID, int theSavePoint) +{ + SALOMEDSClient_AttributeParameter* AP = NULL; + if(theSavePoint >= 0) { + if (_isLocal) { + SALOMEDS::Locker lock; + AP = new SALOMEDS_AttributeParameter(_local_impl->GetCommonParameters(theID.c_str(), theSavePoint)); + } + else { + AP = new SALOMEDS_AttributeParameter(_corba_impl->GetCommonParameters(theID.c_str(), theSavePoint)); + } + } + return _PTR(AttributeParameter)(AP); +} + +_PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const std::string& theID, + const std::string& theModuleName, int theSavePoint) +{ + SALOMEDSClient_AttributeParameter* AP = NULL; + if(theSavePoint > 0) { + if (_isLocal) { + SALOMEDS::Locker lock; + AP = new SALOMEDS_AttributeParameter(_local_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint)); + } + else { + AP = new SALOMEDS_AttributeParameter(_corba_impl->GetModuleParameters(theID.c_str(), theModuleName.c_str(), theSavePoint)); + } + } + 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); +}