X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_Study_i.cxx;h=ccad82686ac98079983e13a4781ef9f3b4e01ed6;hb=5a898fa18674049bd3e02014ece2036709bd251a;hp=ef483d08687009c2493470f7f5d976d6d5ba59d3;hpb=4bf1713ced3d1eb46f9188cf6e84ef72fb76fa88;p=modules%2Fkernel.git diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index ef483d086..ccad82686 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -56,86 +56,149 @@ #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: + 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 +208,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 +233,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 +639,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 +908,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 +1046,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 +1060,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 +1074,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 +1088,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 +1224,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 +1237,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 +1327,7 @@ 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); } //===========================================================================