interface UseCaseIterator;
interface UseCaseBuilder;
+ interface Observer
+ {
+ void notifyObserverID(in string theID, in long event);
+ };
+
+
//! List of attributes of %SObjects
typedef sequence<GenericAttribute> ListOfAttributes;
\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);
};
//==========================================================================
}
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);
+}
virtual bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName);
virtual bool IsVariableUsed(const std::string& theVarName);
virtual std::vector< std::vector<std::string> > 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);
#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 <unistd.h>
#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<SALOMEDSImpl_Study* , SALOMEDS_Study_i*> SALOMEDS_Study_i::_mapOfStudies;
//============================================================================
{
_orb = CORBA::ORB::_duplicate(orb);
_impl = theImpl;
+ _notifier = new Notifier(_orb);
+ theImpl->setNotifier(_notifier);
_builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb);
}
void SALOMEDS_Study_i::Close()
{
SALOMEDS::Locker lock;
-
+
RemovePostponed(-1);
SALOMEDS::SComponentIterator_var itcomponent = NewComponentIterator();
}
}
+//============================================================================
+/*! 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
//===========================================================================
#include "SALOMEDSImpl_Study.hxx"
#include "SALOMEDSImpl_AttributeIOR.hxx"
+class Notifier;
+
class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study
{
private:
SALOMEDSImpl_Study* _impl;
SALOMEDS_StudyBuilder_i* _builder;
static std::map<SALOMEDSImpl_Study*, SALOMEDS_Study_i*> _mapOfStudies;
+ Notifier* _notifier;
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
SALOMEDSClient_UseCaseIterator.hxx \
SALOMEDSClient_ClientFactory.hxx \
SALOMEDSClient_IParameters.hxx \
+ SALOMEDSClient_Observer.hxx \
SALOMEDSClient.hxx
#
#include "SALOMEDSClient_UseCaseBuilder.hxx"
#include "SALOMEDSClient_AttributeStudyProperties.hxx"
#include "SALOMEDSClient_ChildIterator.hxx"
+#include "SALOMEDSClient_Observer.hxx"
+#include <SALOMEconfig.h>
+#include CORBA_CLIENT_HEADER(SALOMEDS)
class SALOMEDSClient_Study
{
virtual bool IsVariableUsed(const std::string& theVarName) = 0;
virtual std::vector< std::vector<std::string> > ParseVariables(const std::string& theVars) = 0;
-
+
+ virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify) = 0;
+
};
};
+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
if(aLabel.IsNull()) return;
SALOMEDSImpl_Study* aStudy = SALOMEDSImpl_Study::GetStudy(aLabel);
+ if(aStudy) aStudy->modifySO_Notification(GetSObject());
if(aStudy) aStudy->Modify();
}
_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);
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;
+}
SALOMEDSImpl_Callback* _cb;
SALOMEDSImpl_StudyBuilder* _builder;
SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
+ SALOMEDSImpl_AbstractCallback* _notifier;
std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
std::map<std::string, SALOMEDSImpl_SComponent> _mapOfSCO;
//Returns a list of IOR's stored in the study
std::vector<std::string> 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;
SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
return so;
SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
+ _study->addSO_Notification(so);
_doc->SetModified(true);
return so;
Lab.ForgetAllAttributes();
_doc->SetModified(true);
+ _study->removeSO_Notification(anObject);
return true;
}
Lab.ForgetAllAttributes(true);
_doc->SetModified(true);
+ _study->removeSO_Notification(anObject);
return true;
}
Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
_doc->SetModified(true);
+ _study->modifySO_Notification(anObject);
return true;
}