X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study_i.cxx;h=d0b936acc08a635d67697e4f9b2a857f180ef0fc;hb=e98f5c9609cbe485a448f2f345650f595f1a172a;hp=32e0cfc9b37b9114af671bb3687cea2351ab25c6;hpb=1bd1d38e86c39b13e265f8ff534fc1463c25fef3;p=modules%2Fkernel.git diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 32e0cfc9b..d0b936acc 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -1,13 +1,37 @@ +// 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, 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 +// 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 #include "SALOMEDS_Study_i.hxx" +#include "SALOMEDS_StudyManager_i.hxx" #include "SALOMEDS_UseCaseIterator_i.hxx" #include "SALOMEDS_GenericAttribute_i.hxx" #include "SALOMEDS_AttributeStudyProperties_i.hxx" +#include "SALOMEDS_AttributeParameter_i.hxx" #include "SALOMEDS_ChildIterator_i.hxx" #include "SALOMEDS_Driver_i.hxx" #include "SALOMEDS.hxx" @@ -16,16 +40,16 @@ #include "SALOMEDSImpl_SComponent.hxx" #include "SALOMEDSImpl_UseCaseBuilder.hxx" #include "SALOMEDSImpl_AttributeStudyProperties.hxx" +#include "SALOMEDSImpl_AttributeParameter.hxx" #include "SALOMEDSImpl_ChildIterator.hxx" +#include "SALOMEDSImpl_IParameters.hxx" +#include "SALOMEDSImpl_Callback.hxx" -#include -#include -#include -#include -#include +#include "DF_Label.hxx" +#include "DF_Attribute.hxx" -#include -#include +#include "Basics_Utils.hxx" +#include "SALOME_KernelServices.hxx" #ifdef WIN32 #include @@ -34,22 +58,199 @@ #include #endif -#include "OpUtil.hxx" +namespace SALOMEDS +{ + class Notifier: public SALOMEDSImpl_AbstractCallback + { + public: + Notifier(CORBA::ORB_ptr orb) + { + _orb = CORBA::ORB::_duplicate(orb); + } + + //============================================================================ + /*! Function : addSO_Notification + * Purpose : This function tells all the observers that a SO has been added + */ + //============================================================================ + + virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject) + { + std::string anID=theSObject.GetID(); + const char* cID=anID.c_str(); + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + it->first->notifyObserverID(cID,1); + } + return true; // NGE return always true but can be modified if needed + } + + //============================================================================ + /*! Function : removeSO_Notification + * Purpose : This function tells all the observers that a SO has been removed + */ + //============================================================================ + + virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject) + { + std::string anID=theSObject.GetID(); + const char* cID=anID.c_str(); + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + it->first->notifyObserverID(cID,2); + } + return true; // NGE return always true but can be modified if needed + } + + //============================================================================ + /*! Function : modifySO_Notification + * Purpose : This function tells all the observers that a SO has been modified + */ + //============================================================================ + + virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason) + { + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + if(it->second) + { + std::string anID=theSObject.GetID(); + const char* cID=anID.c_str(); + it->first->notifyObserverID(cID,reason); + } + } + return true; // NGE return always true but can be modified if needed + } + + //============================================================================ + /*! Function : modifyNB_Notification + * Purpose : This function tells all the observers that + * a NoteBook variable has been added/modified/removed. + */ + //============================================================================ + + virtual bool modifyNB_Notification(const char* theVarName) + { + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + it->first->notifyObserverID(theVarName,6); + } + return true; // NGE return always true but can be modified if needed + } + + //============================================================================ + /*! Function : attach + * Purpose : register an Observer + */ + //============================================================================ + + virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify) + { + myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify)); + } + + //============================================================================ + /*! Function : detach + * Purpose : unregister an Observer + */ + //============================================================================ + + virtual void detach(SALOMEDS::Observer_ptr theObs) + { + for (ObsListIter it (myObservers.begin()); it != myObservers.end(); ++it) + { + if ( it->first->_is_equivalent(theObs) ) { + myObservers.erase( it ); + break; + } + } + } + + private: + typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList; + typedef ObsList::iterator ObsListIter; + ObsList myObservers; + CORBA::ORB_var _orb; + }; + + class GenObjRegister: public SALOMEDSImpl_AbstractCallback + { + public: + GenObjRegister(CORBA::ORB_ptr orb) + { + _orb = CORBA::ORB::_duplicate(orb); + } + virtual void RegisterGenObj (const std::string& theIOR) + { + try + { + CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str()); + if ( obj->_non_existent() ) return; + SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->Register(); + } + } + catch(const CORBA::Exception& e) + { + } + } + virtual void UnRegisterGenObj(const std::string& theIOR) + { + try + { + CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str()); + if ( obj->_non_existent() ) return; + SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->UnRegister(); + } + } + catch(const CORBA::Exception& e) + { + } + } + + private: + CORBA::ORB_var _orb; + }; + +} // namespace SALOMEDS -using namespace std; +std::map SALOMEDS_Study_i::_mapOfStudies; //============================================================================ /*! Function : SALOMEDS_Study_i * Purpose : SALOMEDS_Study_i constructor */ //============================================================================ -SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(SALOMEDSImpl_Study) theImpl, - CORBA::ORB_ptr orb) +SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, + CORBA::ORB_ptr orb) { - _orb = CORBA::ORB::_duplicate(orb); - _impl = theImpl; - - _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); + _orb = CORBA::ORB::_duplicate(orb); + _impl = theImpl; + _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); + _notifier = new SALOMEDS::Notifier(_orb); + _genObjRegister = new SALOMEDS::GenObjRegister(_orb); + _closed = false; + + theImpl->setNotifier(_notifier); + theImpl->setGenObjRegister( _genObjRegister ); + + // Notify GUI that study was created + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + if ( !CORBA::is_nil(aSession) ) { + std::stringstream ss; + ss << "studyCreated:" << theImpl->StudyId(); + std::string str = ss.str(); + SALOMEDS::unlock(); + aSession->emitMessageOneWay(str.c_str()); + SALOMEDS::lock(); + } } //============================================================================ @@ -59,6 +260,18 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(SALOMEDSImpl_Study) theImpl, //============================================================================ SALOMEDS_Study_i::~SALOMEDS_Study_i() { + //delete the builder servant + PortableServer::POA_var poa=_builder->_default_POA(); + PortableServer::ObjectId_var anObjectId = poa->servant_to_id(_builder); + poa->deactivate_object(anObjectId.in()); + _builder->_remove_ref(); + + _impl->setNotifier(0); + delete _notifier; + delete _genObjRegister; + //delete implementation + delete _impl; + _mapOfStudies.erase(_impl); } //============================================================================ @@ -69,17 +282,21 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() char* SALOMEDS_Study_i::GetPersistentReference() { SALOMEDS::Locker lock; - return CORBA::string_dup(_impl->GetPersistentReference().ToCString()); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + return CORBA::string_dup(_impl->GetPersistentReference().c_str()); } //============================================================================ /*! Function : GetTransientReference - * Purpose : Get IOR of the Study (registred in OCAF document in doc->Root) + * Purpose : Get IOR of the Study (registered in OCAF document in doc->Root) */ //============================================================================ char* SALOMEDS_Study_i::GetTransientReference() { SALOMEDS::Locker lock; - return CORBA::string_dup(_impl->GetTransientReference().ToCString()); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + return CORBA::string_dup(_impl->GetTransientReference().c_str()); } //============================================================================ @@ -90,6 +307,8 @@ char* SALOMEDS_Study_i::GetTransientReference() CORBA::Boolean SALOMEDS_Study_i::IsEmpty() { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); return _impl->IsEmpty(); } @@ -102,10 +321,15 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponent { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponent(TCollection_AsciiString((char*)aComponentName)); - if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SComponent_var sco; + + SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName)); + if (!aCompImpl.IsNull()) + sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb); - SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb); return sco._retn(); } @@ -118,10 +342,15 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SComponent) aCompImpl = _impl->FindComponentID(TCollection_AsciiString((char*)aComponentID)); - if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SComponent_var sco; + + SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID)); + if (!aCompImpl.IsNull()) + sco = SALOMEDS_SComponent_i::New(aCompImpl, _orb); - SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb); return sco._retn(); } @@ -134,18 +363,23 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName) { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObject(TCollection_AsciiString((char*)anObjectName)); - if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SObject_var so; - if(aSO->DynamicType() == STANDARD_TYPE(SALOMEDSImpl_SComponent)) { - Handle(SALOMEDSImpl_SComponent) aSCO = Handle(SALOMEDSImpl_SComponent)::DownCast(aSO); - SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb); - return sco._retn(); + SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName)); + if (!aSO.IsNull()) { + if (aSO.IsComponent()) { + SALOMEDSImpl_SComponent aSCO = aSO; + so = SALOMEDS_SComponent_i::New(aSCO, _orb); + } + else { + so = SALOMEDS_SObject_i::New(aSO, _orb); + } } - - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); - - return so._retn(); + + return so._retn(); } //============================================================================ @@ -157,9 +391,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID) { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectID(TCollection_AsciiString((char*)anObjectID)); - if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SObject_var so; + + SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID)); + if (!aSO.IsNull()) + so = SALOMEDS_SObject_i::New(aSO, _orb); + return so._retn(); } @@ -172,10 +412,17 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID) { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SObject) aSO = _impl->CreateObjectID((char*)anObjectID); - if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SObject_var so; + + if (anObjectID && strlen(anObjectID) > 0) { + SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID); + if (!aSO.IsNull()) + so = SALOMEDS_SObject_i::New(aSO, _orb); + } - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); return so._retn(); } @@ -186,21 +433,25 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID) */ //============================================================================ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName, - const char* aComponentName ) + const char* aComponentName ) { SALOMEDS::Locker lock; - Handle(TColStd_HSequenceOfTransient) aSeq = _impl->FindObjectByName(TCollection_AsciiString((char*)anObjectName), - TCollection_AsciiString((char*)aComponentName)); - int aLength = aSeq->Length(); - SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + std::vector aSeq = _impl->FindObjectByName(std::string((char*)anObjectName), + std::string((char*)aComponentName)); + + SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject; + int aLength = aSeq.size(); 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() ; + + return listSO._retn(); } //============================================================================ @@ -212,10 +463,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR) { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectIOR(TCollection_AsciiString((char*)anObjectIOR)); - if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SObject_var so; + + SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR)); + if (!aSO.IsNull()) + so = SALOMEDS_SObject_i::New(aSO, _orb); - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); return so._retn(); } @@ -228,10 +484,15 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath) { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_SObject) aSO = _impl->FindObjectByPath(TCollection_AsciiString((char*)thePath)); - if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::SObject_var so; + + SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath)); + if (!aSO.IsNull()) + so = SALOMEDS_SObject_i::New (aSO, _orb); - SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); return so._retn(); } @@ -244,22 +505,28 @@ 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; - SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); - if(!CORBA::is_nil(aSObj)) { - aSO = _impl->FindObjectID(aSObj->GetID()); - } - else { - aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject)); + std::string aPath = ""; + + if (!CORBA::is_nil(theObject)) { + SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject); + SALOMEDSImpl_SObject aSO; + + if (!CORBA::is_nil(aSObj)) { + aSO = _impl->FindObjectID(aSObj->GetID()); + } + else { + aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject)); + } + + if (!aSO.IsNull()) { + aPath = _impl->GetObjectPath(aSO); + } } - - if(aSO.IsNull()) return CORBA::string_dup(aPath.ToCString()); - - aPath = _impl->GetObjectPath(aSO); - return CORBA::string_dup(aPath.ToCString()); + + return CORBA::string_dup(aPath.c_str()); } @@ -272,8 +539,11 @@ void SALOMEDS_Study_i::SetContext(const char* thePath) { SALOMEDS::Locker lock; - _impl->SetContext(TCollection_AsciiString((char*)thePath)); - if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetContext(std::string((char*)thePath)); + if (_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") throw SALOMEDS::Study::StudyInvalidContext(); } @@ -285,9 +555,13 @@ void SALOMEDS_Study_i::SetContext(const char* thePath) char* SALOMEDS_Study_i::GetContext() { SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + if (!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext(); - if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext(); - return CORBA::string_dup(_impl->GetContext().ToCString()); + return CORBA::string_dup(_impl->GetContext().c_str()); } //============================================================================ @@ -299,14 +573,24 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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(); + + std::vector aSeq = _impl->GetObjectNames(std::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(); } @@ -319,14 +603,24 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theCont { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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(); + + std::vector aSeq = _impl->GetDirectoryNames(std::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(); } @@ -339,34 +633,50 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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(); + + std::vector aSeq = _impl->GetFileNames(std::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) { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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(); + + std::vector aSeq = _impl->GetComponentNames(std::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(); } @@ -379,14 +689,16 @@ 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); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); - //Create iterator + CORBA::String_var anID = theSO->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in()); + SALOMEDSImpl_ChildIterator anItr(aSO); SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb); - SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); + SALOMEDS::ChildIterator_var it = it_servant->_this(); - return it; + return it._retn(); } @@ -398,9 +710,15 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator() { SALOMEDS::Locker lock; - SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb); - _it->Init(); - return _it->_this(); + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb); + it_servant->Init(); + SALOMEDS::SComponentIterator_var it = it_servant->_this(); + + return it._retn(); } @@ -412,7 +730,13 @@ SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator() SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder() { SALOMEDS::Locker lock; - return _builder->_this(); + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::StudyBuilder_var sb = SALOMEDS::StudyBuilder::_duplicate(_builder->_this()); + + return sb._retn(); } //============================================================================ @@ -423,7 +747,8 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder() char* SALOMEDS_Study_i::Name() { SALOMEDS::Locker lock; - return CORBA::string_dup(_impl->Name().ToCString()); + // Name is specified as IDL attribute: user exception cannot be raised + return CORBA::string_dup(_impl->Name().c_str()); } //============================================================================ @@ -434,7 +759,8 @@ char* SALOMEDS_Study_i::Name() void SALOMEDS_Study_i::Name(const char* name) { SALOMEDS::Locker lock; - _impl->Name(TCollection_AsciiString((char*)name)); + // Name is specified as IDL attribute: user exception cannot be raised + _impl->Name(std::string(name)); } //============================================================================ @@ -442,10 +768,11 @@ void SALOMEDS_Study_i::Name(const char* name) * Purpose : get if study has been saved */ //============================================================================ -CORBA::Boolean SALOMEDS_Study_i::IsSaved() +CORBA::Boolean SALOMEDS_Study_i::IsSaved() { SALOMEDS::Locker lock; - return _impl->IsSaved(); + // IsSaved is specified as IDL attribute: user exception cannot be raised + return (!_closed) ? _impl->IsSaved() : false; } //============================================================================ @@ -456,7 +783,9 @@ CORBA::Boolean SALOMEDS_Study_i::IsSaved() void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save) { SALOMEDS::Locker lock; - _impl->IsSaved(save); + // IsSaved is specified as IDL attribute: user exception cannot be raised + if (!_closed) + _impl->IsSaved(save); } //============================================================================ @@ -464,12 +793,31 @@ void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save) * Purpose : Detect if a Study has been modified since it has been saved */ //============================================================================ -CORBA::Boolean SALOMEDS_Study_i::IsModified() +CORBA::Boolean SALOMEDS_Study_i::IsModified() { SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + return _impl->IsModified(); } +//============================================================================ +/*! Function : Modified + * Purpose : Sets a Modified flag of a Study to True + */ +//============================================================================ +void SALOMEDS_Study_i::Modified() +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->Modify(); +} + //============================================================================ /*! Function : URL * Purpose : get URL of the study (persistent reference of the study) @@ -478,7 +826,8 @@ CORBA::Boolean SALOMEDS_Study_i::IsModified() char* SALOMEDS_Study_i::URL() { SALOMEDS::Locker lock; - return CORBA::string_dup(_impl->URL().ToCString()); + // URL is specified as IDL attribute: user exception cannot be raised + return CORBA::string_dup(_impl->URL().c_str()); } //============================================================================ @@ -489,35 +838,41 @@ char* SALOMEDS_Study_i::URL() void SALOMEDS_Study_i::URL(const char* url) { SALOMEDS::Locker lock; - _impl->URL(TCollection_AsciiString((char*)url)); + // URL is specified as IDL attribute: user exception cannot be raised + _impl->URL(std::string((char*)url)); } - CORBA::Short SALOMEDS_Study_i::StudyId() { SALOMEDS::Locker lock; + // StudyId is specified as IDL attribute: user exception cannot be raised return _impl->StudyId(); } void SALOMEDS_Study_i::StudyId(CORBA::Short id) { SALOMEDS::Locker lock; + // StudyId is specified as IDL attribute: user exception cannot be raised _impl->StudyId(id); } -void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) +void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) { SALOMEDS::Locker lock; - _impl->UpdateIORLabelMap(TCollection_AsciiString((char*)anIOR), TCollection_AsciiString((char*)anEntry)); + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::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)); @@ -528,7 +883,19 @@ 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) +SALOMEDS_Study_i* SALOMEDS_Study_i::GetStudyServant(SALOMEDSImpl_Study* aStudyImpl, CORBA::ORB_ptr orb) +{ + if (_mapOfStudies.find(aStudyImpl) != _mapOfStudies.end()) + return _mapOfStudies[aStudyImpl]; + else + { + SALOMEDS_Study_i *Study_servant = new SALOMEDS_Study_i(aStudyImpl, orb); + _mapOfStudies[aStudyImpl]=Study_servant; + return Study_servant; + } +} + +void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) { SALOMEDS::Locker lock; SALOMEDSImpl_Study::IORUpdated(theAttribute); @@ -538,6 +905,9 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObj { SALOMEDS::Locker lock; + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + SALOMEDS::GenericAttribute_ptr aTarget; if (anObject->FindAttribute(aTarget,"AttributeTarget")) { return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get(); @@ -552,34 +922,45 @@ SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() { SALOMEDS::Locker lock; - Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr = _impl->GetProperties(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties(); SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb); - return SP->AttributeStudyProperties::_this(); + SALOMEDS::AttributeStudyProperties_var aProp = SP->_this(); + return aProp._retn(); } char* SALOMEDS_Study_i::GetLastModificationDate() { SALOMEDS::Locker lock; - return CORBA::string_dup(_impl->GetLastModificationDate().ToCString()); + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + 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(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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()); + std::vector aSeq = _impl->GetModificationsDate(); + + int aLength = aSeq.size(); + aDates->length(aLength); + for (int anIndex = 0; anIndex < aLength; anIndex++) { + aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str()); } + return aDates._retn(); } - - //============================================================================ /*! Function : GetUseCaseBuilder * Purpose : Returns a UseCase builder @@ -588,8 +969,13 @@ SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() { SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb); - return UCBuilder->_this(); + SALOMEDS::UseCaseBuilder_var uc = UCBuilder->_this(); + return uc._retn(); } @@ -601,33 +987,58 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() void SALOMEDS_Study_i::Close() { SALOMEDS::Locker lock; - - RemovePostponed(-1); - SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + 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&) { } } + sco->UnRegister(); } + + //Does not need any more this iterator + itcomponent->UnRegister(); + + // Notify GUI that study is closed + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + if ( !CORBA::is_nil(aSession) ) { + std::stringstream ss; + ss << "studyClosed:" << _impl->StudyId(); + std::string str = ss.str(); + SALOMEDS::unlock(); + aSession->emitMessageOneWay(str.c_str()); + SALOMEDS::lock(); + } + _impl->Close(); + _closed = true; } //============================================================================ @@ -638,23 +1049,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 } //============================================================================ @@ -662,38 +1063,28 @@ void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) * Purpose : */ //============================================================================ -#ifndef WNT -void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long theUndoLimit) -#else -void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit) -#endif +void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) { 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()); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + std::vector 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 (...) {} - } + //rnv: To avoid double deletion of the Salome Generic Objects: + //rnv: 1. First decrement of the reference count in the SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR(); + //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister(); + //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister(); + } catch (...) {} } + + //Not implemented } //============================================================================ @@ -701,15 +1092,10 @@ void SALOMEDS_Study_i::RemovePostponed(CORBA::Long theUndoLimit) * Purpose : */ //============================================================================ -#ifndef WNT -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 } @@ -718,28 +1104,515 @@ void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) * Purpose : */ //============================================================================ -CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished) +CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, + const char* theBaseName, + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile) { SALOMEDS::Locker lock; - TCollection_AsciiString aPath((char*)thePath), aBaseName((char*)theBaseName); + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + std::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); + bool ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory); delete factory; + return ret; } +//============================================================================ +/*! Function : GetCommonParameters + * Purpose : + */ +//============================================================================ +SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetCommonParameters(const char* theID, CORBA::Long theSavePoint) +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint); + SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb); + SALOMEDS::AttributeParameter_var aParam = SP->_this(); + + return aParam._retn(); +} + +//============================================================================ +/*! Function : GetCommonModuleParameters + * Purpose : + */ +//============================================================================ +SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, + const char* theModuleName, + CORBA::Long theSavePoint) +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint); + SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb); + SALOMEDS::AttributeParameter_var aParam = SP->_this(); + + return aParam._retn(); +} + +//============================================================================ +/*! Function : SetStudyLock + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID) +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetStudyLock(theLockerID); +} + +//============================================================================ +/*! Function : IsStudyLocked + * Purpose : + */ +//============================================================================ +bool SALOMEDS_Study_i::IsStudyLocked() +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsStudyLocked(); +} + +//============================================================================ +/*! Function : UnLockStudy + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID) +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->UnLockStudy(theLockerID); +} + +//============================================================================ +/*! Function : GetLockerID + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID() +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; + + std::vector 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) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + + _impl->SetVariable(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::REAL_VAR); + if (_notifier) + _notifier->modifyNB_Notification(theVarName); +} + +//============================================================================ +/*! Function : SetInteger + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetInteger(const char* theVarName, CORBA::Long theValue) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetVariable(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::INTEGER_VAR); + if (_notifier) + _notifier->modifyNB_Notification(theVarName); +} + +//============================================================================ +/*! Function : SetBoolean + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValue) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetVariable(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); + if (_notifier) + _notifier->modifyNB_Notification(theVarName); +} + +//============================================================================ +/*! Function : SetString + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetString(const char* theVarName, const char* theValue) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetStringVariable(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::STRING_VAR); + if (_notifier) + _notifier->modifyNB_Notification(theVarName); +} + +//============================================================================ +/*! Function : SetStringAsDouble + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetStringAsDouble(const char* theVarName, CORBA::Double theValue) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _impl->SetStringVariableAsDouble(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::STRING_VAR); +} + +//============================================================================ +/*! Function : GetReal + * Purpose : + */ +//============================================================================ +CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetInteger + * Purpose : + */ +//============================================================================ +CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return (long)_impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return (bool)_impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetString + * Purpose : + */ +//============================================================================ +char* SALOMEDS_Study_i::GetString(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str()); +} + +//============================================================================ +/*! Function : IsReal + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::REAL_VAR); +} + +//============================================================================ +/*! Function : IsInteger + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::INTEGER_VAR); +} + +//============================================================================ +/*! Function : IsBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); +} + +//============================================================================ +/*! Function : IsString + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::STRING_VAR); +} + +//============================================================================ +/*! Function : IsVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsVariable(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetVariableNames + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames() +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; + + std::vector aVarNames = _impl->GetVariableNames(); + + 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) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + bool res = _impl->RemoveVariable(std::string(theVarName)); + if (res && _notifier) + _notifier->modifyNB_Notification(theVarName); + + return res; +} + +//============================================================================ +/*! Function : RenameVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + bool res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName)); + if (res && _notifier) + _notifier->modifyNB_Notification(theVarName); + + return res; +} + +//============================================================================ +/*! Function : IsVariableUsed + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + return _impl->IsVariableUsed(std::string(theVarName)); +} + + +//============================================================================ +/*! Function : ParseVariables + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings; + + std::vector< std::vector > aSections = _impl->ParseVariables(std::string(theVarName)); + + int aSectionsLen = aSections.size(); + aResult->length(aSectionsLen); + + for (int aSectionInd = 0; aSectionInd < aSectionsLen; aSectionInd++) { + std::vector 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 : + */ +//============================================================================ +char* SALOMEDS_Study_i::GetDefaultScript(const char* theModuleName, const char* theShift) +{ + SALOMEDS::Locker lock; + + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + std::string script = SALOMEDSImpl_IParameters::getDefaultScript(_impl, theModuleName, theShift); + return CORBA::string_dup(script.c_str()); +} + +//============================================================================ +/*! Function : EnableUseCaseAutoFilling + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) +{ + if (_closed) + throw SALOMEDS::Study::StudyInvalidReference(); + + _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); + } + } +} + +//============================================================================ +/*! Function : attach + * Purpose : This function attach an observer to the study + */ +//============================================================================ +void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify) +{ + if (_notifier) + static_cast(_notifier)->attach(theObs, modify); +} + + +//============================================================================ +/*! Function : detach + * Purpose : This function detaches an observer from the study + */ +//============================================================================ +void SALOMEDS_Study_i::detach(SALOMEDS::Observer_ptr theObs) +{ + if (_notifier) + static_cast(_notifier)->detach(theObs); +} + //=========================================================================== // PRIVATE FUNCTIONS //=========================================================================== -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(_impl); }