X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study_i.cxx;h=5bbc01b31cb8a13b4c32a9fbdf347175fafc5064;hb=a63265d524e8436588a7bb82147a69812c153b1b;hp=ef483d08687009c2493470f7f5d976d6d5ba59d3;hpb=288dc1c84630e521220d796b7c88c518f34856d5;p=modules%2Fyacs.git diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index ef483d086..5bbc01b31 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 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 @@ -6,7 +6,7 @@ // 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. +// 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 @@ -56,86 +56,166 @@ #include #endif -class Notifier: public SALOMEDSImpl_AbstractCallback +namespace SALOMEDS { -public: -Notifier(CORBA::ORB_ptr orb) -{ - _orb = CORBA::ORB::_duplicate(orb); -} + 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 - */ -//============================================================================ + //============================================================================ + /*! Function : addSO_Notification + * Purpose : This function tells all the observers that a SO has been added + */ + //============================================================================ - virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject) + 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); - } + { + 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 - */ -//============================================================================ + //============================================================================ + /*! Function : removeSO_Notification + * Purpose : This function tells all the observers that a SO has been removed + */ + //============================================================================ - virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject) + 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) { - it->first->notifyObserverID(cID,2); + 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 : 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) + //============================================================================ + /*! 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) { - if(it->second) - { - std::string anID=theSObject.GetID(); - const char* cID=anID.c_str(); - it->first->notifyObserverID(cID,reason); - } + it->first->notifyObserverID(theVarName,6); } return true; // NGE return always true but can be modified if needed } -//============================================================================ -/*! Function : attach - * Purpose : register an Observer - */ -//============================================================================ + //============================================================================ + /*! Function : attach + * Purpose : register an Observer + */ + //============================================================================ - virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify) + virtual void attach(SALOMEDS::Observer_ptr theObs, bool modify) { - myObservers.push_back(std::pair< SALOMEDS::Observer_var, bool > (SALOMEDS::Observer::_duplicate(theObs),modify)); + myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify)); } -private: + //============================================================================ + /*! 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 std::map SALOMEDS_Study_i::_mapOfStudies; @@ -145,14 +225,16 @@ std::map SALOMEDS_Study_i::_mapOfStudie */ //============================================================================ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, - CORBA::ORB_ptr orb) + CORBA::ORB_ptr orb) { - _orb = CORBA::ORB::_duplicate(orb); - _impl = theImpl; - _notifier = new Notifier(_orb); - theImpl->setNotifier(_notifier); + _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); - _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); + theImpl->setNotifier(_notifier); + theImpl->setGenObjRegister( _genObjRegister ); } //============================================================================ @@ -168,6 +250,9 @@ SALOMEDS_Study_i::~SALOMEDS_Study_i() poa->deactivate_object(anObjectId.in()); _builder->_remove_ref(); + _impl->setNotifier(0); + delete _notifier; + delete _genObjRegister; //delete implementation delete _impl; _mapOfStudies.erase(_impl); @@ -571,7 +656,7 @@ char* SALOMEDS_Study_i::Name() void SALOMEDS_Study_i::Name(const char* name) { SALOMEDS::Locker lock; - _impl->Name(std::string((char*)name)); + _impl->Name(std::string(name)); } //============================================================================ @@ -840,9 +925,9 @@ void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/) 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(); + //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 (...) {} } @@ -978,6 +1063,8 @@ 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); } //============================================================================ @@ -990,6 +1077,8 @@ 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); } //============================================================================ @@ -1002,6 +1091,8 @@ void SALOMEDS_Study_i::SetBoolean(const char* theVarName, CORBA::Boolean theValu _impl->SetVariable(std::string(theVarName), theValue, SALOMEDSImpl_GenericVariable::BOOLEAN_VAR); + if(_notifier) + _notifier->modifyNB_Notification(theVarName); } //============================================================================ @@ -1014,6 +1105,8 @@ 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); } //============================================================================ @@ -1148,7 +1241,10 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames() //============================================================================ CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName) { - return _impl->RemoveVariable(std::string(theVarName)); + CORBA::Boolean res = _impl->RemoveVariable(std::string(theVarName)); + if(res && _notifier) + _notifier->modifyNB_Notification(theVarName); + return res; } //============================================================================ @@ -1158,7 +1254,10 @@ CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName) //============================================================================ CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName) { - return _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName)); + CORBA::Boolean res = _impl->RenameVariable(std::string(theVarName), std::string(theNewVarName)); + if(res && _notifier) + _notifier->modifyNB_Notification(theVarName); + return res; } //============================================================================ @@ -1245,7 +1344,19 @@ void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modify) { if(_notifier) - _notifier->attach(theObs,modify); + 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); } //===========================================================================