X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study_i.cxx;h=5bbc01b31cb8a13b4c32a9fbdf347175fafc5064;hb=a63265d524e8436588a7bb82147a69812c153b1b;hp=c282ab096f431937c5ce1fade24b8f2ef130ca52;hpb=102608ce8b69dd1ea798169e30223b67742ec26d;p=modules%2Fyacs.git diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index c282ab096..5bbc01b31 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -1,70 +1,240 @@ -// SALOME SALOMEDS : data structure of SALOME and sources of Salome data server +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// 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 : Yves FRICAUD +// Author : Sergey RUIN // Module : SALOME -// $Header$ - -using namespace std; +// #include "utilities.h" #include "SALOMEDS_Study_i.hxx" - -#include "SALOMEDS_DataMapIteratorOfDataMapStringLabel.hxx" -#include -#include -#include -#include -#include -#include -#include -#include -#include "SALOMEDS_LocalIDAttribute.hxx" -#include "SALOMEDS_PersRefAttribute.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" + +#include "SALOMEDSImpl_SObject.hxx" +#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 "DF_Label.hxx" +#include "DF_Attribute.hxx" + +#include "Basics_Utils.hxx" + +#ifdef WIN32 +#include +#else +#include +#include +#endif + +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; + }; -#define DIRECTORYID 16661 -#define FILEID "FILE: " -#define FILELOCALID 26662 +} // namespace SALOMEDS + +std::map SALOMEDS_Study_i::_mapOfStudies; //============================================================================ /*! Function : SALOMEDS_Study_i * Purpose : SALOMEDS_Study_i constructor */ //============================================================================ -SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(TDocStd_Document) doc, - CORBA::ORB_ptr orb, - const char* study_name) +SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, + CORBA::ORB_ptr orb) { - _orb = CORBA::ORB::_duplicate(orb); - _doc = doc; - _name = new char[strlen(study_name) +1]; - strcpy(_name,study_name); - _isSaved = false ; - _URL = NULL; - _StudyId = -1; - _autoFill = true; + _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); + + theImpl->setNotifier(_notifier); + theImpl->setGenObjRegister( _genObjRegister ); } //============================================================================ @@ -74,8 +244,18 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(const Handle(TDocStd_Document) doc, //============================================================================ SALOMEDS_Study_i::~SALOMEDS_Study_i() { - delete [] _name ; - delete [] _URL ; + //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); } //============================================================================ @@ -85,7 +265,8 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() //============================================================================ char* SALOMEDS_Study_i::GetPersistentReference() { - return URL(); + SALOMEDS::Locker lock; + return CORBA::string_dup(_impl->GetPersistentReference().c_str()); } //============================================================================ /*! Function : GetTransientReference @@ -94,18 +275,8 @@ char* SALOMEDS_Study_i::GetPersistentReference() //============================================================================ char* SALOMEDS_Study_i::GetTransientReference() { - CORBA::String_var IOR; - - Handle(SALOMEDS_IORAttribute) Att; - TDF_Label _lab = _doc->GetData()->Root(); - if (!_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){ - - TCollection_AsciiString ch(Att->Get()); - IOR = CORBA::string_dup(ch.ToCString()); - } - else IOR = CORBA::string_dup(""); // NULL ? - - return CORBA::string_dup(IOR); + SALOMEDS::Locker lock; + return CORBA::string_dup(_impl->GetTransientReference().c_str()); } //============================================================================ @@ -115,8 +286,8 @@ char* SALOMEDS_Study_i::GetTransientReference() //============================================================================ CORBA::Boolean SALOMEDS_Study_i::IsEmpty() { - if (_doc.IsNull()) return true; - return _doc->IsEmpty(); + SALOMEDS::Locker lock; + return _impl->IsEmpty(); } //============================================================================ @@ -126,25 +297,13 @@ CORBA::Boolean SALOMEDS_Study_i::IsEmpty() //============================================================================ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponentName) { - bool _find = false; - Standard_CString name; - SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator(); - SALOMEDS::SComponent_var compo; - - for (; itcomp->More(); itcomp->Next()) { - SALOMEDS::SComponent_var SC = itcomp->Value(); - name = SC->ComponentDataType(); - //ED if ( TCollection_AsciiString(name).IsEqual(TCollection_AsciiString(strdup(aComponentName))) ) { - if(strcmp(aComponentName,name) == 0){ - _find = true; - return SALOMEDS::SComponent::_narrow(SC); - } - } - if(!_find) - { - return SALOMEDS::SComponent::_nil(); - } - return compo; + SALOMEDS::Locker lock; + + SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponent(std::string(aComponentName)); + if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil(); + + SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb); + return sco._retn(); } //============================================================================ @@ -154,28 +313,13 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponent (const char* aComponent //============================================================================ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponentID) { - // Iterate on each components defined in the study - // Get the component ID and compare with aComponentID - bool _find = false; - char *ID; - SALOMEDS::SComponent_ptr compo; - - SALOMEDS::SComponentIterator_var itcomp = NewComponentIterator(); - for (; itcomp->More(); itcomp->Next()) { - SALOMEDS::SComponent_var SC = itcomp->Value(); - ID = SC->GetID(); - if(strcmp(aComponentID,ID)==0) - { - // ComponentID found - _find = true; - compo = SALOMEDS::SComponent::_narrow(SC); - } - } - if(!_find) - { - compo = SALOMEDS::SComponent::_nil(); - } - return compo; + SALOMEDS::Locker lock; + + SALOMEDSImpl_SComponent aCompImpl = _impl->FindComponentID(std::string((char*)aComponentID)); + if(aCompImpl.IsNull()) return SALOMEDS::SComponent::_nil(); + + SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aCompImpl, _orb); + return sco._retn(); } //============================================================================ @@ -185,32 +329,20 @@ SALOMEDS::SComponent_ptr SALOMEDS_Study_i::FindComponentID(const char* aComponen //============================================================================ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName) { - // Iterate to all components defined in the study - // After testing the component name, iterate in all objects defined under - // components (function _FindObject) - bool _find = false; - SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil(); + SALOMEDS::Locker lock; - SALOMEDS::SComponentIterator_var it = NewComponentIterator(); - for (; it->More();it->Next()){ - if(!_find) - { - SALOMEDS::SComponent_var SC = it->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (SC->FindAttribute(anAttr,"AttributeName")) - { - SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr); - CORBA::String_var Val = Name->Value(); - if (strcmp(Val, anObjectName) == 0) - { - _find = true; - RefSO = SALOMEDS::SObject::_narrow(SC); - } - } - if (!_find) RefSO = _FindObject(SC,anObjectName, _find); - } + SALOMEDSImpl_SObject aSO = _impl->FindObject(std::string((char*)anObjectName)); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + + if(aSO.IsComponent()) { + SALOMEDSImpl_SComponent aSCO = aSO; + SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (aSCO, _orb); + return sco._retn(); } - return RefSO; + + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + + return so._retn(); } //============================================================================ @@ -220,15 +352,30 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObject(const char* anObjectName) //============================================================================ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID) { - // Convert aSO->GetID in TDF_Label. - TDF_Label Lab; - TDF_Tool::Label(_doc->GetData(), strdup(anObjectID), Lab); - - if (Lab.IsNull()) return SALOMEDS::SObject::_nil(); - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (Lab,_orb); - SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); - return so; + SALOMEDS::Locker lock; + + SALOMEDSImpl_SObject aSO = _impl->FindObjectID(std::string((char*)anObjectID)); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + return so._retn(); +} + +//============================================================================ +/*! Function : CreateObjectID + * Purpose : Creates an Object with ID = anObjectID + */ +//============================================================================ +SALOMEDS::SObject_ptr SALOMEDS_Study_i::CreateObjectID(const char* anObjectID) +{ + SALOMEDS::Locker lock; + + if(!anObjectID || strlen(anObjectID) == 0) return SALOMEDS::SObject::_nil(); + + SALOMEDSImpl_SObject aSO = _impl->CreateObjectID((char*)anObjectID); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + return so._retn(); } //============================================================================ @@ -238,57 +385,22 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectID(const char* anObjectID) */ //============================================================================ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindObjectByName( const char* anObjectName, - const char* aComponentName ) + const char* aComponentName ) { - SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ; - listSO->length(0); - - SALOMEDS::SComponent_ptr compo = FindComponent(aComponentName) ; - if ( compo->_is_nil() ) { - MESSAGE ("In FindObjectByName() : Component named " << aComponentName << " not found "); - return listSO._retn(); - } - - // Iterate on each object and subobject of the component - // If objectName is found add it to the list of SObjects - char *name; - char *childName ; - SALOMEDS::SObject_ptr addSO = SALOMEDS::SObject::_nil(); + SALOMEDS::Locker lock; - CORBA::String_var compoId = compo->GetID(); - SALOMEDS::ChildIterator_var it = NewChildIterator(compo); - int length = 0 ; - for ( ; it->More();it->Next() ) { - - SALOMEDS::SObject_var CSO = it->Value(); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - if ( CSO->FindAttribute(anAttr, "AttributeName") ) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - name = aName->Value(); - if ( strcmp( name, anObjectName ) == 0) { - addSO = SALOMEDS::SObject::_narrow(CSO); - /* add to list */ - length++ ; - listSO->length(length); - listSO[length-1] = addSO ; - } - - /* looks also for eventual children */ - bool found = false ; - addSO = _FindObject( CSO, anObjectName, found ) ; - if( found) { - length++ ; - listSO->length(length); - listSO[length-1] = addSO ; - } - } + std::vector aSeq = _impl->FindObjectByName(std::string((char*)anObjectName), + std::string((char*)aComponentName)); + int aLength = aSeq.size(); + SALOMEDS::Study::ListOfSObject_var listSO = new SALOMEDS::Study::ListOfSObject ; + listSO->length(aLength); + for(int i = 0; iFindAttribute(anAttr,"AttributeIOR")) { - myIORLabels.UnBind(TCollection_ExtendedString(anIOR)); - } else return aResult->_this(); - } - // Iterate to all components defined in the study - // After testing the component name, iterate in all objects defined under - // components (function _FindObject) - bool _find = false; - SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil(); - - SALOMEDS::SComponentIterator_var it = NewComponentIterator(); - for (; it->More();it->Next()){ - if(!_find) - { - SALOMEDS::SComponent_var SC = it->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (SC->FindAttribute(anAttr,"AttributeIOR")) - { - SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var Val = IOR->Value(); - if (strcmp(Val, anObjectIOR) == 0) - { - _find = true; - RefSO = SALOMEDS::SObject::_narrow(SC); - } - } - if (!_find) - RefSO = _FindObjectIOR(SC,anObjectIOR, _find); - } - } - if (!RefSO->_is_nil()) INFOS("SALOMEDS_Study_i::FindObjectIOR: found label with old methods"); + SALOMEDS::Locker lock; - return RefSO; + SALOMEDSImpl_SObject aSO = _impl->FindObjectIOR(std::string((char*)anObjectIOR)); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); + + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + return so._retn(); } //============================================================================ @@ -344,63 +424,13 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectIOR(const char* anObjectIOR) //============================================================================ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath) { - TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aToken; - SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_nil(); - int i = 1, aLength = aPath.Length(); - bool isRelative = false; - - if(aLength == 0) { //Empty path - return the current context - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (_current, _orb); - aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); - return aSO._retn(); - } - - if(aPath.Value(1) != '/') //Relative path - isRelative = true; + SALOMEDS::Locker lock; - TDF_ChildIterator anIterator; - TDF_Label aLabel; - Handle(TDataStd_Name) anAttr; + SALOMEDSImpl_SObject aSO = _impl->FindObjectByPath(std::string((char*)thePath)); + if(aSO.IsNull()) return SALOMEDS::SObject::_nil(); - if(isRelative) { - if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - anIterator.Initialize(_current, Standard_False); - } - else { - if(aPath.Length() == 1 && aPath.Value(1) == '/') { //Root - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb); - aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); - return aSO._retn(); - } - anIterator.Initialize(_doc->Main(), Standard_False); - } - - while(i <= aLength) { - - aToken = aPath.Token("/", i); - if(aToken.Length() == 0) break; - - for ( ; anIterator.More(); anIterator.Next() ) { - aLabel = anIterator.Value(); - if(aLabel.FindAttribute(TDataStd_Name::GetID(), anAttr)) { - if(anAttr->Get() == aToken) { - aToken = aPath.Token("/", i+1); //Check if it was the last part of the path - if(aToken.Length() == 0) { //The searched label is found (no part of the path is left) - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (aLabel, _orb); - aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); - return aSO._retn(); - } - - anIterator.Initialize(aLabel, Standard_False); - break; - } - } - } - - i++; - } - - return aSO._retn(); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (aSO, _orb); + return so._retn(); } //============================================================================ @@ -410,36 +440,24 @@ SALOMEDS::SObject_ptr SALOMEDS_Study_i::FindObjectByPath(const char* thePath) //============================================================================ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject) { - TCollection_AsciiString aPath(""); - if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.ToCString()); + SALOMEDS::Locker lock; - SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(theObject); - if(anObject->_is_nil()) { - anObject = FindObjectIOR(_orb->object_to_string(theObject)); - if(anObject->_is_nil()) return CORBA::string_dup(aPath.ToCString()); - } + std::string aPath(""); + if(CORBA::is_nil(theObject)) return CORBA::string_dup(aPath.c_str()); + SALOMEDSImpl_SObject aSO; + SALOMEDS::SObject_var aSObj = SALOMEDS::SObject::_narrow(theObject); - SALOMEDS::GenericAttribute_var anAttr; - if(anObject->FindAttribute(anAttr, "AttributeName")) { - SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); - if(anAttr->_is_nil()) return CORBA::string_dup(aPath.ToCString()); - TCollection_AsciiString aValue(aName->Value()); - aValue.Prepend("/"); - aValue += aPath; - aPath = aValue; - SALOMEDS::SObject_ptr aFather = anObject->GetFather(); - if(!aFather->_is_nil()) { - TDF_Label aLabel; - Handle(TDataStd_Name) aNameAttrib; - TDF_Tool::Label(_doc->GetData(), aFather->GetID(), aLabel); - if(aLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttrib)) { - aValue = GetObjectPath(aFather); - aPath = aValue + aPath; - } - } + if(!CORBA::is_nil(aSObj)) { + aSO = _impl->FindObjectID(aSObj->GetID()); } - - return CORBA::string_dup(aPath.ToCString()); + else { + aSO = _impl->FindObjectIOR(_orb->object_to_string(theObject)); + } + + if(aSO.IsNull()) return CORBA::string_dup(aPath.c_str()); + + aPath = _impl->GetObjectPath(aSO); + return CORBA::string_dup(aPath.c_str()); } @@ -450,34 +468,11 @@ char* SALOMEDS_Study_i::GetObjectPath(CORBA::Object_ptr theObject) //============================================================================ void SALOMEDS_Study_i::SetContext(const char* thePath) { - if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory(); - TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""); - bool isInvalid = false, isFound = false; - SALOMEDS::SObject_var aSO; - - if(aPath.Value(1) != '/') { //Relative path - aContext = TCollection_AsciiString(GetContext()); - aContext += '/'; - aContext += aPath; - } - else - aContext = aPath; - - try { - aSO = FindObjectByPath(aContext.ToCString()); - } - catch( ... ) { - isInvalid = true; - } + SALOMEDS::Locker lock; - if(isInvalid || aSO->_is_nil()) throw SALOMEDS::Study::StudyInvalidContext(); - - TDF_Label aLabel; - TDF_Tool::Label(_doc->GetData(), aSO->GetID(), aLabel); - if(aLabel.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - else - _current = aLabel; //Set the current context - + _impl->SetContext(std::string((char*)thePath)); + if(_impl->IsError() && _impl->GetErrorCode() == "InvalidContext") + throw SALOMEDS::Study::StudyInvalidContext(); } //============================================================================ @@ -487,10 +482,10 @@ void SALOMEDS_Study_i::SetContext(const char* thePath) //============================================================================ char* SALOMEDS_Study_i::GetContext() { - if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (_current, _orb); - SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_narrow(so_servant->_this()); - return GetObjectPath(aSO._retn()); + SALOMEDS::Locker lock; + + if(!_impl->HasCurrentContext()) throw SALOMEDS::Study::StudyInvalidContext(); + return CORBA::string_dup(_impl->GetContext().c_str()); } //============================================================================ @@ -498,35 +493,25 @@ char* SALOMEDS_Study_i::GetContext() * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty) */ //============================================================================ -SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) { - TColStd_SequenceOfExtendedString aResultSeq; +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext) +{ + SALOMEDS::Locker lock; + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; - TDF_Label aLabel; - if (strlen(theContext) == 0) { - if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - aLabel = _current; - } else { - TDF_Label aTmp = _current; - SetContext(theContext); - aLabel = _current; - _current = aTmp; - } - TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels - for(; anIter.More(); anIter.Next()) { - TDF_Label aLabel = anIter.Value(); -// Handle(TDF_Attribute) anAttribute; -// if (aLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttribute) || -// aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttribute)) { - Handle(TDataStd_Name) aName; - if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) aResultSeq.Append(aName->Get()); -// } - } - // fill the result table - int anIndex, aLength = aResultSeq.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(anIndex = 0; anIndex < aLength; anIndex++) { - aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString()); + for (int anIndex = 0; anIndex < aLength; anIndex++) { + aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str()); } + return aResult._retn(); } @@ -535,38 +520,25 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetObjectNames(const char* theContext * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty) */ //============================================================================ -SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) { - TColStd_SequenceOfExtendedString aResultSeq; +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theContext) +{ + SALOMEDS::Locker lock; + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; - TDF_Label aLabel; - if (strlen(theContext) == 0) { - if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - aLabel = _current; - } else { - TDF_Label aTmp = _current; - SetContext(theContext); - aLabel = _current; - _current = aTmp; - } - TDF_ChildIterator anIter(aLabel, Standard_False); // iterate first-level children at all sublevels - for(; anIter.More(); anIter.Next()) { - TDF_Label aLabel = anIter.Value(); - Handle(SALOMEDS_LocalIDAttribute) anID; - if (aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID)) { - if (anID->Get() == DIRECTORYID) { - Handle(TDataStd_Name) aName; - if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) { - aResultSeq.Append(aName->Get()); - } - } - } - } - // fill the result table - int anIndex, aLength = aResultSeq.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(anIndex = 0; anIndex < aLength; anIndex++) { - aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString()); + for (int anIndex = 0; anIndex < aLength; anIndex++) { + aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str()); } + return aResult._retn(); } @@ -575,64 +547,48 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetDirectoryNames(const char* theCont * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty) */ //============================================================================ -SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) { - TColStd_SequenceOfExtendedString aResultSeq; +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetFileNames(const char* theContext) +{ + SALOMEDS::Locker lock; + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; - TDF_Label aLabel; - if (strlen(theContext) == 0) { - if(_current.IsNull()) throw SALOMEDS::Study::StudyInvalidContext(); - aLabel = _current; - } else { - TDF_Label aTmp = _current; - SetContext(theContext); - aLabel = _current; - _current = aTmp; - } - TDF_ChildIterator anIter(aLabel, Standard_False); // iterate all subchildren at all sublevels - for(; anIter.More(); anIter.Next()) { - TDF_Label aLabel = anIter.Value(); - Handle(SALOMEDS_LocalIDAttribute) anID; - if (aLabel.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID)) { - if (anID->Get() == FILELOCALID) { - Handle(SALOMEDS_PersRefAttribute) aName; - if(aLabel.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), aName)) { - TCollection_ExtendedString aFileName = aName->Get(); - if(aFileName.Length() > 0) - aResultSeq.Append(aFileName.Split(strlen(FILEID))); - } - } - } -// } - } - // fill the result table - int anIndex, aLength = aResultSeq.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(anIndex = 0; anIndex < aLength; anIndex++) { - aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).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) { - TColStd_SequenceOfExtendedString aResultSeq; +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theContext) +{ + SALOMEDS::Locker lock; + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; - TDF_ChildIterator anIter(_doc->Main(), Standard_False); // iterate all subchildren at first level - for(; anIter.More(); anIter.Next()) { - TDF_Label aLabel = anIter.Value(); - Handle(TDataStd_Name) aName; - if (aLabel.FindAttribute(TDataStd_Name::GetID(), aName)) aResultSeq.Append(aName->Get()); - } - // fill the result table - int anIndex, aLength = aResultSeq.Length(); + + std::vector aSeq = _impl->GetComponentNames(std::string((char*)theContext)); + + int aLength = aSeq.size(); aResult->length(aLength); - for(anIndex = 0; anIndex < aLength; anIndex++) { - aResult[anIndex] = CORBA::string_dup(TCollection_AsciiString(aResultSeq.Value(anIndex + 1)).ToCString()); + for(int anIndex = 0; anIndex < aLength; anIndex++) { + aResult[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str()); } + return aResult._retn(); } @@ -641,17 +597,18 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetComponentNames(const char* theCont * Purpose : Create a ChildIterator from an SObject */ //============================================================================ -SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr aSO) +SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject_ptr theSO) { - //Convert aSO->GetID in TDF_Label. - TDF_Label Lab; - TDF_Tool::Label(_doc->GetData(), strdup(aSO->GetID()), Lab); + SALOMEDS::Locker lock; + + CORBA::String_var anID=theSO->GetID(); + SALOMEDSImpl_SObject aSO = _impl->GetSObject(anID.in()); + SALOMEDSImpl_ChildIterator anItr(aSO); //Create iterator - SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(Lab,_orb); - SALOMEDS::ChildIterator_var it = SALOMEDS::ChildIterator::_narrow(it_servant->_this()); + SALOMEDS_ChildIterator_i* it_servant = new SALOMEDS_ChildIterator_i(anItr, _orb); - return it; + return it_servant->_this(); } @@ -662,9 +619,10 @@ SALOMEDS::ChildIterator_ptr SALOMEDS_Study_i::NewChildIterator(SALOMEDS::SObject //============================================================================ SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator() { - SALOMEDS_SComponentIterator_i* it_servant = new SALOMEDS_SComponentIterator_i(_doc,_orb); - SALOMEDS::SComponentIterator_var it = SALOMEDS::SComponentIterator::_narrow(it_servant->_this()); - return it; + SALOMEDS::Locker lock; + SALOMEDS_SComponentIterator_i* _it = new SALOMEDS_SComponentIterator_i(_impl->NewComponentIterator(), _orb); + _it->Init(); + return _it->_this(); } @@ -675,19 +633,8 @@ SALOMEDS::SComponentIterator_ptr SALOMEDS_Study_i::NewComponentIterator() //============================================================================ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder() { - SALOMEDS_StudyBuilder_i* it_servant = new SALOMEDS_StudyBuilder_i(_doc,_orb); - SALOMEDS::StudyBuilder_var it = SALOMEDS::StudyBuilder::_narrow(it_servant->_this()); - - if(_autoFill) { - SALOMEDS_Callback_i* callback = new SALOMEDS_Callback_i(GetUseCaseBuilder(), _orb); - SALOMEDS::Callback_var cb = SALOMEDS::Callback::_narrow(callback->_this()); - - it->SetOnAddSObject(cb); - it->SetOnRemoveSObject(cb); - } - - return it; - + SALOMEDS::Locker lock; + return _builder->_this(); } //============================================================================ @@ -697,7 +644,8 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder() //============================================================================ char* SALOMEDS_Study_i::Name() { - return CORBA::string_dup(_name); + SALOMEDS::Locker lock; + return CORBA::string_dup(_impl->Name().c_str()); } //============================================================================ @@ -707,8 +655,8 @@ char* SALOMEDS_Study_i::Name() //============================================================================ void SALOMEDS_Study_i::Name(const char* name) { - _name = new char[strlen(name) +1]; - strcpy(_name,name); + SALOMEDS::Locker lock; + _impl->Name(std::string(name)); } //============================================================================ @@ -718,7 +666,8 @@ void SALOMEDS_Study_i::Name(const char* name) //============================================================================ CORBA::Boolean SALOMEDS_Study_i::IsSaved() { - return _isSaved; + SALOMEDS::Locker lock; + return _impl->IsSaved(); } //============================================================================ @@ -728,7 +677,8 @@ CORBA::Boolean SALOMEDS_Study_i::IsSaved() //============================================================================ void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save) { - _isSaved = save; + SALOMEDS::Locker lock; + _impl->IsSaved(save); } //============================================================================ @@ -738,150 +688,102 @@ void SALOMEDS_Study_i::IsSaved(CORBA::Boolean save) //============================================================================ CORBA::Boolean SALOMEDS_Study_i::IsModified() { - // True if is modified and not saved - if (_doc->IsModified()) - if (!_isSaved) return true; - else return false; - else return false; + SALOMEDS::Locker lock; + return _impl->IsModified(); } //============================================================================ -/*! Function : URL - * Purpose : get URL of the study (persistent reference of the study) +/*! Function : Modified + * Purpose : Sets a Modified flag of a Study to True */ //============================================================================ -char* SALOMEDS_Study_i::URL() +void SALOMEDS_Study_i::Modified() { - if(!_URL) { - _URL = new char[1]; - _URL[0] = (char)0; - } - return CORBA::string_dup(_URL); + SALOMEDS::Locker lock; + return _impl->Modify(); } + //============================================================================ /*! Function : URL - * Purpose : set URL of the study (persistent reference of the study) + * Purpose : get URL of the study (persistent reference of the study) */ //============================================================================ -void SALOMEDS_Study_i::URL(const char* url) +char* SALOMEDS_Study_i::URL() { - _URL = new char[strlen(url) +1]; - strcpy(_URL,url); - SCRUTE(_URL); + SALOMEDS::Locker lock; + return CORBA::string_dup(_impl->URL().c_str()); } - //============================================================================ -/*! Function : _FindObject - * Purpose : Find an Object with SALOMEDS::Name = anObjectName +/*! Function : URL + * Purpose : set URL of the study (persistent reference of the study) */ //============================================================================ -SALOMEDS::SObject_ptr SALOMEDS_Study_i::_FindObject(SALOMEDS::SObject_ptr SO, - const char* anObjectName, - bool& _find) +void SALOMEDS_Study_i::URL(const char* url) { - // Iterate on each objects and subobjects of the component - // If objectName find, stop the loop and get the object reference - SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil(); - - CORBA::String_var soid = SO->GetID(); - SALOMEDS::ChildIterator_var it = NewChildIterator(SO); - for (; it->More();it->Next()){ - if(!_find) - { - SALOMEDS::SObject_var CSO = it->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (CSO->FindAttribute(anAttr,"AttributeName")) - { - SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr); - CORBA::String_var Val = Name->Value(); - if (strcmp(Val, anObjectName) == 0) - { - RefSO = SALOMEDS::SObject::_narrow(CSO); - _find = true; - } - } - if (!_find) RefSO = _FindObject(CSO, anObjectName, _find); - } - } - return RefSO; + SALOMEDS::Locker lock; + _impl->URL(std::string((char*)url)); } -//============================================================================ -/*! Function : _FindObject - * Purpose : Find an Object with SALOMEDS::IOR = anObjectIOR - */ -//============================================================================ -SALOMEDS::SObject_ptr -SALOMEDS_Study_i::_FindObjectIOR(SALOMEDS::SObject_ptr SO, - const char* anObjectIOR, - bool& _find) -{ - // Iterate on each objects and subobjects of the component - // If objectName find, stop the loop and get the object reference - SALOMEDS::SObject_ptr RefSO = SALOMEDS::SObject::_nil(); - - SALOMEDS::ChildIterator_var it = NewChildIterator(SO); - for (; it->More();it->Next()){ - if(!_find) - { - SALOMEDS::SObject_var CSO = it->Value(); - SALOMEDS::GenericAttribute_var anAttr; - if (CSO->FindAttribute(anAttr,"AttributeIOR")) - { - SALOMEDS::AttributeIOR_var IOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var Val = IOR->Value(); - if (strcmp(Val, anObjectIOR) == 0) - { - RefSO = SALOMEDS::SObject::_narrow(CSO); - _find = true; - } - } - if (!_find) RefSO = _FindObjectIOR(CSO, anObjectIOR, _find); - } - } - return RefSO; -} CORBA::Short SALOMEDS_Study_i::StudyId() { - return _StudyId; + SALOMEDS::Locker lock; + return _impl->StudyId(); } void SALOMEDS_Study_i::StudyId(CORBA::Short id) -{ - _StudyId = id; +{ + SALOMEDS::Locker lock; + _impl->StudyId(id); } -void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) { - TDF_Label aLabel; - CORBA::String_var anEn = CORBA::string_dup(anEntry); - CORBA::String_var IOR = CORBA::string_dup(anIOR); - TDF_Tool::Label(_doc->GetData(),anEn,aLabel, Standard_True); - if (myIORLabels.IsBound(TCollection_ExtendedString(IOR))) myIORLabels.UnBind(TCollection_ExtendedString(IOR)); - myIORLabels.Bind(TCollection_ExtendedString(IOR), aLabel); +void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR,const char* anEntry) +{ + SALOMEDS::Locker lock; + _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry)); } -void SALOMEDS_Study_i::IORUpdated(const Handle(SALOMEDS_IORAttribute) theAttribute, CORBA::ORB_ptr orb) { - // get accorded study first - Handle(SALOMEDS_IORAttribute) Att; - if (theAttribute->Label().Root().FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){ - TCollection_AsciiString ch(Att->Get()); - char* IOR = CORBA::string_dup(ch.ToCString()); +SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) +{ + SALOMEDS::Locker lock; + + 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)); - TCollection_AsciiString aString; - TDF_Tool::Entry(theAttribute->Label(),aString); - aStudy->UpdateIORLabelMap(TCollection_AsciiString(theAttribute->Get()).ToCString(), aString.ToCString()); + return SALOMEDS::Study::_duplicate(aStudy); } else { - INFOS("IORUpdated: Problem to get study"); - return; + MESSAGE("GetStudy: Problem to get study"); } + return SALOMEDS::Study::_nil(); } -SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) { +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); +} + +SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObject_ptr anObject) +{ + SALOMEDS::Locker lock; + SALOMEDS::GenericAttribute_ptr aTarget; if (anObject->FindAttribute(aTarget,"AttributeTarget")) { return SALOMEDS::AttributeTarget::_narrow(aTarget)->Get(); @@ -892,40 +794,32 @@ SALOMEDS::Study::ListOfSObject* SALOMEDS_Study_i::FindDependances(SALOMEDS::SObj } -SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() { - SALOMEDS::GenericAttribute_ptr anAttr = NewBuilder()->FindOrCreateAttribute(FindObjectID("0:1"), - "AttributeStudyProperties"); - return SALOMEDS::AttributeStudyProperties::_narrow(anAttr); +SALOMEDS::AttributeStudyProperties_ptr SALOMEDS_Study_i::GetProperties() +{ + SALOMEDS::Locker lock; + + SALOMEDSImpl_AttributeStudyProperties* anAttr = _impl->GetProperties(); + SALOMEDS_AttributeStudyProperties_i* SP = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb); + return SP->AttributeStudyProperties::_this(); } -char* SALOMEDS_Study_i::GetLastModificationDate() { - SALOMEDS::AttributeStudyProperties_var aProp = GetProperties(); - SALOMEDS::StringSeq_var aNames; - SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears; - aProp->GetModificationsList(aNames , aMinutes ,aHours, aDays, aMonths, aYears, true); - int aLastIndex = aNames->length() - 1; - char aResult[20]; - sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), - (int)(aYears[aLastIndex]), (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex])); - CORBA::String_var aResStr = CORBA::string_dup(aResult); - return aResStr._retn(); +char* SALOMEDS_Study_i::GetLastModificationDate() +{ + SALOMEDS::Locker lock; + return CORBA::string_dup(_impl->GetLastModificationDate().c_str()); } -SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() { - SALOMEDS::AttributeStudyProperties_var aProp = GetProperties(); - SALOMEDS::StringSeq_var aNames; - SALOMEDS::LongSeq_var aMinutes, aHours, aDays, aMonths, aYears; - aProp->GetModificationsList(aNames , aMinutes ,aHours, aDays, aMonths, aYears, false); - - int anIndex, aLength = aNames->length(); +SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() +{ + SALOMEDS::Locker lock; + + std::vector aSeq = _impl->GetModificationsDate(); + int aLength = aSeq.size(); SALOMEDS::ListOfDates_var aDates = new SALOMEDS::ListOfDates; aDates->length(aLength); - for(anIndex = 0; anIndex < aLength; anIndex++) { - char aDate[20]; - sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d", (int)(aDays[anIndex]), (int)(aMonths[anIndex]), - (int)(aYears[anIndex]), (int)(aHours[anIndex]), (int)(aMinutes[anIndex])); - aDates[anIndex] = CORBA::string_dup(aDate); + for(int anIndex = 0; anIndex < aLength; anIndex++) { + aDates[anIndex] = CORBA::string_dup(aSeq[anIndex].c_str()); } return aDates._retn(); } @@ -939,9 +833,9 @@ SALOMEDS::ListOfDates* SALOMEDS_Study_i::GetModificationsDate() { //============================================================================ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() { - SALOMEDS_UseCaseBuilder_i* _caseBuilder = new SALOMEDS_UseCaseBuilder_i(_doc, _orb); - SALOMEDS::UseCaseBuilder_var aBuilder = SALOMEDS::UseCaseBuilder::_narrow(_caseBuilder->_this()); - return aBuilder._retn(); + SALOMEDS::Locker lock; + SALOMEDS_UseCaseBuilder_i* UCBuilder = new SALOMEDS_UseCaseBuilder_i(_impl->GetUseCaseBuilder(), _orb); + return UCBuilder->_this(); } @@ -952,31 +846,529 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() //============================================================================ void SALOMEDS_Study_i::Close() { - SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); + SALOMEDS::Locker lock; + RemovePostponed(-1); + + SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); for (; itcomponent->More(); itcomponent->Next()) { SALOMEDS::SComponent_var sco = itcomponent->Value(); - - MESSAGE ( "Look for an engine for data type :"<< sco->ComponentDataType()); + CORBA::String_var compodatatype=sco->ComponentDataType(); + MESSAGE ( "Look for an engine for data type :"<< compodatatype); // if there is an associated Engine call its method for closing CORBA::String_var IOREngine; if (sco->ComponentIOR(IOREngine)) { // we have found the associated engine to write the data - MESSAGE ( "We have found an engine for data type :"<< sco->ComponentDataType()); - CORBA::Object_var obj = _orb->string_to_object(IOREngine); - SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ; - - if (!anEngine->_is_nil()) - anEngine->Close(sco); + MESSAGE ( "We have found an engine for data type :"<< compodatatype); + //_narrow can throw a corba exception + try + { + CORBA::Object_var obj = _orb->string_to_object(IOREngine); + if (!CORBA::is_nil(obj)) + { + SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_narrow(obj) ; + if (!anEngine->_is_nil()) + { + SALOMEDS::unlock(); + anEngine->Close(sco); + SALOMEDS::lock(); + } + } + } + catch (CORBA::Exception&) + {/*pass*/ } } + sco->UnRegister(); } - Handle(TDocStd_Application) anApp = Handle(TDocStd_Application)::DownCast(_doc->Application()); -// Handle(TDocStd_Owner) anOwner; -// if (_doc->Main().Root().FindAttribute(TDocStd_Owner::GetID(), anOwner)) { -// Handle(TDocStd_Document) anEmptyDoc; -// anOwner->SetDocument(anEmptyDoc); -// } - if(!anApp.IsNull()) anApp->Close(_doc); - _doc.Nullify(); + //Does not need any more this iterator + itcomponent->UnRegister(); + + + _impl->Close(); +} + +//============================================================================ +/*! Function : AddPostponed + * Purpose : + */ + //============================================================================ +void SALOMEDS_Study_i::AddPostponed(const char* theIOR) +{ + SALOMEDS::Locker lock; + //Not implemented +} + +void SALOMEDS_Study_i::AddCreatedPostponed(const char* theIOR) +{ + SALOMEDS::Locker lock; + //Not implemented +} + +//============================================================================ +/*! Function : RemovePostponed + * Purpose : + */ +//============================================================================ +#ifndef WIN32 +void SALOMEDS_Study_i::RemovePostponed(const CORBA::Long /*theUndoLimit*/) +#else +void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) +#endif +{ + SALOMEDS::Locker lock; + + 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); + //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 +} + +//============================================================================ +/*! Function : UndoPostponed + * Purpose : + */ +//============================================================================ +#ifndef WIN32 +void SALOMEDS_Study_i::UndoPostponed(const CORBA::Long theWay) +#else +void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay) +#endif +{ + SALOMEDS::Locker lock; + //Not implemented +} + + +//============================================================================ +/*! Function : DumpStudy + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, + const char* theBaseName, + CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile) +{ + SALOMEDS::Locker lock; + + 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, 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; + + SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetCommonParameters(theID, theSavePoint); + SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb); + return SP->AttributeParameter::_this(); +} + +//============================================================================ +/*! Function : GetCommonModuleParameters + * Purpose : + */ +//============================================================================ +SALOMEDS::AttributeParameter_ptr SALOMEDS_Study_i::GetModuleParameters(const char* theID, + const char* theModuleName, + CORBA::Long theSavePoint) +{ + SALOMEDS::Locker lock; + + SALOMEDSImpl_AttributeParameter* anAttr = _impl->GetModuleParameters(theID, theModuleName, theSavePoint); + SALOMEDS_AttributeParameter_i* SP = new SALOMEDS_AttributeParameter_i(anAttr, _orb); + return SP->AttributeParameter::_this(); +} + +//============================================================================ +/*! Function : SetStudyLock + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::SetStudyLock(const char* theLockerID) +{ + SALOMEDS::Locker lock; + _impl->SetStudyLock(theLockerID); +} + +//============================================================================ +/*! Function : IsStudyLocked + * Purpose : + */ +//============================================================================ +bool SALOMEDS_Study_i::IsStudyLocked() +{ + SALOMEDS::Locker lock; + return _impl->IsStudyLocked(); +} + +//============================================================================ +/*! Function : UnLockStudy + * Purpose : + */ +//============================================================================ +void SALOMEDS_Study_i::UnLockStudy(const char* theLockerID) +{ + SALOMEDS::Locker lock; + _impl->UnLockStudy(theLockerID); +} + +//============================================================================ +/*! Function : GetLockerID + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetLockerID() +{ + SALOMEDS::Locker lock; + + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; + + 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) +{ + _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) +{ + _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) +{ + _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) +{ + _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) +{ + _impl->SetStringVariableAsDouble(std::string(theVarName), + theValue, + SALOMEDSImpl_GenericVariable::STRING_VAR); +} + +//============================================================================ +/*! Function : GetReal + * Purpose : + */ +//============================================================================ +CORBA::Double SALOMEDS_Study_i::GetReal(const char* theVarName) +{ + return _impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetInteger + * Purpose : + */ +//============================================================================ +CORBA::Long SALOMEDS_Study_i::GetInteger(const char* theVarName) +{ + return (int)_impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::GetBoolean(const char* theVarName) +{ + return (bool)_impl->GetVariableValue(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetString + * Purpose : + */ +//============================================================================ +char* SALOMEDS_Study_i::GetString(const char* theVarName) +{ + return CORBA::string_dup(_impl->GetStringVariableValue(std::string(theVarName)).c_str()); +} + +//============================================================================ +/*! Function : IsReal + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsReal(const char* theVarName) +{ + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::REAL_VAR); +} + +//============================================================================ +/*! Function : IsInteger + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsInteger(const char* theVarName) +{ + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::INTEGER_VAR); +} + +//============================================================================ +/*! Function : IsBoolean + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsBoolean(const char* theVarName) +{ + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); +} + +//============================================================================ +/*! Function : IsString + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsString(const char* theVarName) +{ + return _impl->IsTypeOf(std::string(theVarName), + SALOMEDSImpl_GenericVariable::STRING_VAR); +} + +//============================================================================ +/*! Function : IsVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsVariable(const char* theVarName) +{ + return _impl->IsVariable(std::string(theVarName)); +} + +//============================================================================ +/*! Function : GetVariableNames + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames() +{ + std::vector aVarNames = _impl->GetVariableNames(); + SALOMEDS::ListOfStrings_var aResult = new SALOMEDS::ListOfStrings; + + int aLen = aVarNames.size(); + aResult->length(aLen); + + for (int anInd = 0; anInd < aLen; anInd++) + aResult[anInd] = CORBA::string_dup(aVarNames[anInd].c_str()); + + return aResult._retn(); +} + +//============================================================================ +/*! Function : RemoveVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName) +{ + CORBA::Boolean 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) +{ + CORBA::Boolean 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) +{ + return _impl->IsVariableUsed(std::string(theVarName)); +} + + +//============================================================================ +/*! Function : ParseVariables + * Purpose : + */ +//============================================================================ +SALOMEDS::ListOfListOfStrings* SALOMEDS_Study_i::ParseVariables(const char* theVarName) +{ + std::vector< std::vector > aSections = _impl->ParseVariables(std::string(theVarName)); + + SALOMEDS::ListOfListOfStrings_var aResult = new SALOMEDS::ListOfListOfStrings; + + 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; + + 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) +{ + _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 +//=========================================================================== +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, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0; + return reinterpret_cast(_impl); }