From 745723800f69c3df03ede6a4a41e8fe24e57418c Mon Sep 17 00:00:00 2001 From: caremoli Date: Mon, 3 Jan 2011 10:29:46 +0000 Subject: [PATCH] CCAR: add Observer CORBA object to SALOMEDS module to implement a notification mechanism for modifications in study manager (to be used mainly by GUI module) --- idl/SALOMEDS.idl | 14 ++- src/SALOMEDS/SALOMEDS_Study.cxx | 6 ++ src/SALOMEDS/SALOMEDS_Study.hxx | 1 + src/SALOMEDS/SALOMEDS_Study_i.cxx | 97 ++++++++++++++++++- src/SALOMEDS/SALOMEDS_Study_i.hxx | 6 ++ src/SALOMEDSClient/Makefile.am | 1 + src/SALOMEDSClient/SALOMEDSClient_Study.hxx | 7 +- src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx | 7 ++ .../SALOMEDSImpl_GenericAttribute.cxx | 1 + src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 50 ++++++++++ src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 8 ++ .../SALOMEDSImpl_StudyBuilder.cxx | 6 ++ 12 files changed, 201 insertions(+), 3 deletions(-) diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 955cf7837..0cc5780ca 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -94,6 +94,12 @@ during each working session. interface UseCaseIterator; interface UseCaseBuilder; + interface Observer + { + void notifyObserverID(in string theID, in long event); + }; + + //! List of attributes of %SObjects typedef sequence ListOfAttributes; @@ -539,7 +545,13 @@ during each working session. \return Variables list. */ ListOfListOfStrings ParseVariables( in string theVars ); - + +/*! + Attach an observer to the Study + + \param theObserver +*/ + void attach(in SALOMEDS::Observer theObserver, in boolean modify); }; //========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index a041c040b..08d9eb347 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -999,3 +999,9 @@ _PTR(AttributeParameter) SALOMEDS_Study::GetModuleParameters(const std::string& } return _PTR(AttributeParameter)(AP); } + +void SALOMEDS_Study::attach(SALOMEDS::Observer_ptr theObserver,bool modify) +{ + if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it + _corba_impl->attach(theObserver,modify); +} diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index 1f373fc09..c84261e24 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -122,6 +122,7 @@ public: virtual bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName); virtual bool IsVariableUsed(const std::string& theVarName); virtual std::vector< std::vector > ParseVariables(const std::string& theVars); + virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify); std::string ConvertObjectToIOR(CORBA::Object_ptr theObject); CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 94e3537e0..5832eaa4c 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -42,6 +42,7 @@ #include "SALOMEDSImpl_AttributeParameter.hxx" #include "SALOMEDSImpl_ChildIterator.hxx" #include "SALOMEDSImpl_IParameters.hxx" +#include "SALOMEDSImpl_Callback.hxx" #include "DF_Label.hxx" #include "DF_Attribute.hxx" @@ -55,6 +56,87 @@ #include #endif +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) + { + 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,0); + } + } + 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::pair< SALOMEDS::Observer_var, bool > (SALOMEDS::Observer::_duplicate(theObs),modify)); + } + +private: + typedef std::list< std::pair< SALOMEDS::Observer_var, bool > > ObsList; + typedef ObsList::iterator ObsListIter; + ObsList myObservers; + CORBA::ORB_var _orb; +}; + + std::map SALOMEDS_Study_i::_mapOfStudies; //============================================================================ @@ -67,6 +149,8 @@ SALOMEDS_Study_i::SALOMEDS_Study_i(SALOMEDSImpl_Study* theImpl, { _orb = CORBA::ORB::_duplicate(orb); _impl = theImpl; + _notifier = new Notifier(_orb); + theImpl->setNotifier(_notifier); _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); } @@ -678,7 +762,7 @@ SALOMEDS::UseCaseBuilder_ptr SALOMEDS_Study_i::GetUseCaseBuilder() void SALOMEDS_Study_i::Close() { SALOMEDS::Locker lock; - + RemovePostponed(-1); SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator(); @@ -1152,6 +1236,17 @@ void SALOMEDS_Study_i::EnableUseCaseAutoFilling(CORBA::Boolean isEnabled) } } +//============================================================================ +/*! 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) + _notifier->attach(theObs,modify); +} + //=========================================================================== // PRIVATE FUNCTIONS //=========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 55b8e2b50..a0146ccc9 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -46,6 +46,8 @@ #include "SALOMEDSImpl_Study.hxx" #include "SALOMEDSImpl_AttributeIOR.hxx" +class Notifier; + class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study { private: @@ -53,6 +55,7 @@ private: SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder; static std::map _mapOfStudies; + Notifier* _notifier; public: @@ -344,5 +347,8 @@ public: virtual SALOMEDSImpl_Study* GetImpl() { return _impl; } virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal); + + virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify); + }; #endif diff --git a/src/SALOMEDSClient/Makefile.am b/src/SALOMEDSClient/Makefile.am index 98eed253d..38d9160f2 100644 --- a/src/SALOMEDSClient/Makefile.am +++ b/src/SALOMEDSClient/Makefile.am @@ -72,6 +72,7 @@ salomeinclude_HEADERS=\ SALOMEDSClient_UseCaseIterator.hxx \ SALOMEDSClient_ClientFactory.hxx \ SALOMEDSClient_IParameters.hxx \ + SALOMEDSClient_Observer.hxx \ SALOMEDSClient.hxx # diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index 13273ab2a..2ccc8cf91 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -39,6 +39,9 @@ #include "SALOMEDSClient_UseCaseBuilder.hxx" #include "SALOMEDSClient_AttributeStudyProperties.hxx" #include "SALOMEDSClient_ChildIterator.hxx" +#include "SALOMEDSClient_Observer.hxx" +#include +#include CORBA_CLIENT_HEADER(SALOMEDS) class SALOMEDSClient_Study { @@ -120,7 +123,9 @@ public: virtual bool IsVariableUsed(const std::string& theVarName) = 0; virtual std::vector< std::vector > ParseVariables(const std::string& theVars) = 0; - + + virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify) = 0; + }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx index 91cef20ef..906403c97 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx @@ -54,4 +54,11 @@ public: }; +class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AbstractCallback +{ +public: + virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; + virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; + virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; +}; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx index 0f7baf1eb..7f3544df1 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx @@ -85,6 +85,7 @@ void SALOMEDSImpl_GenericAttribute::SetModifyFlag() if(aLabel.IsNull()) return; SALOMEDSImpl_Study* aStudy = SALOMEDSImpl_Study::GetStudy(aLabel); + if(aStudy) aStudy->modifySO_Notification(GetSObject()); if(aStudy) aStudy->Modify(); } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 9bf5348bf..bf2b3b858 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -69,6 +69,7 @@ SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc, _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc); _builder = new SALOMEDSImpl_StudyBuilder(this); _cb = new SALOMEDSImpl_Callback(_useCaseBuilder); + _notifier=0; //Put on the root label a StudyHandle attribute to store the address of this object //It will be used to retrieve the study object by DF_Label that belongs to the study SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this); @@ -1983,3 +1984,52 @@ std::vector SALOMEDSImpl_Study::GetIORs() return anIORs; } + +//============================================================================ +/*! Function : addSO_Notification + * Purpose : This function tells all the observers that a SO has been added + */ +//============================================================================ +bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + if(_notifier) + return _notifier->addSO_Notification(theSObject); + else + return false; +} + +//============================================================================ +/*! Function : removeSO_Notification + * Purpose : This function tells all the observers that a SO has been removed + */ +//============================================================================ +bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + if(_notifier) + return _notifier->removeSO_Notification(theSObject); + else + return false; +} + +//============================================================================ +/*! Function : modifySO_Notification + * Purpose : This function tells all the observers that a SO has been modified + */ +//============================================================================ +bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject) +{ + if(_notifier) + return _notifier->modifySO_Notification(theSObject); + else + return false; +} + +//============================================================================ +/*! Function : setNotifier + * Purpose : register a notifier + */ +//============================================================================ +void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier) +{ + _notifier=notifier; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index d048586aa..0731d3ab3 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -70,6 +70,7 @@ private: SALOMEDSImpl_Callback* _cb; SALOMEDSImpl_StudyBuilder* _builder; SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder; + SALOMEDSImpl_AbstractCallback* _notifier; std::map _mapOfSO; std::map _mapOfSCO; @@ -313,6 +314,13 @@ public: //Returns a list of IOR's stored in the study std::vector GetIORs(); + // Notification mechanism + virtual bool addSO_Notification(const SALOMEDSImpl_SObject& theSObject); + virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject); + virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject); + virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier); + + friend class SALOMEDSImpl_StudyManager; friend class SALOMEDSImpl_GenericAttribute; friend class SALOMEDSImpl_GenericVariable; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx index b42685c3f..d42e08dfc 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -91,6 +91,7 @@ SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const std::strin SALOMEDSImpl_SComponent so = _study->GetSComponent (NL); if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so); + _study->addSO_Notification(so); _doc->SetModified(true); @@ -148,6 +149,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SOb SALOMEDSImpl_SObject so = _study->GetSObject(NewLab); if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so); + _study->addSO_Notification(so); _doc->SetModified(true); return so; @@ -172,6 +174,7 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImp SALOMEDSImpl_SObject so = _study->GetSObject(NewLab); if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so); + _study->addSO_Notification(so); _doc->SetModified(true); return so; @@ -210,6 +213,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObjec Lab.ForgetAllAttributes(); _doc->SetModified(true); + _study->removeSO_Notification(anObject); return true; } @@ -260,6 +264,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObj Lab.ForgetAllAttributes(true); _doc->SetModified(true); + _study->removeSO_Notification(anObject); return true; } @@ -548,6 +553,7 @@ bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anOb Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)); _doc->SetModified(true); + _study->modifySO_Notification(anObject); return true; } -- 2.39.2