Salome HOME
CCAR: add Observer CORBA object to SALOMEDS module to implement a notification
authorcaremoli <caremoli>
Mon, 3 Jan 2011 10:29:46 +0000 (10:29 +0000)
committercaremoli <caremoli>
Mon, 3 Jan 2011 10:29:46 +0000 (10:29 +0000)
mechanism for modifications in study manager (to be used mainly by GUI module)

12 files changed:
idl/SALOMEDS.idl
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_Study.hxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDSClient/Makefile.am
src/SALOMEDSClient/SALOMEDSClient_Study.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx
src/SALOMEDSImpl/SALOMEDSImpl_GenericAttribute.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx
src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx

index 955cf78373321a54d1dbb39529f82475ad1b1338..0cc5780ca4d80270e437b1ff06577910bfedfb06 100644 (file)
@@ -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<GenericAttribute> 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);   
   };
 
   //==========================================================================
index a041c040b653ae8c102457f7fc5ec62cdd29288d..08d9eb347b6f667d0c2632c5ed347704af1c1282 100644 (file)
@@ -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);
+}
index 1f373fc09790f5e303aca5fcef9df435d7fdfec9..c84261e249d779697c2e7899f958307f55d4db01 100644 (file)
@@ -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<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);     
index 94e3537e0eb5fbba75255074a8b6dd0e77bbfb38..5832eaa4c76849e3d70bd4991c1d8680193a0f74 100644 (file)
@@ -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"
 #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;
 
 //============================================================================
@@ -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
 //===========================================================================
index 55b8e2b5066b305ec998bac6464d4c6a20f7c11a..a0146ccc9b543cdad8097394d9eb7e0f457f9996 100644 (file)
@@ -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<SALOMEDSImpl_Study*, SALOMEDS_Study_i*> _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
index 98eed253db7665145ac4aed2fbf5dc2094914c74..38d9160f2318eb32503bad901d66ba0a92abf542 100644 (file)
@@ -72,6 +72,7 @@ salomeinclude_HEADERS=\
                 SALOMEDSClient_UseCaseIterator.hxx \
                SALOMEDSClient_ClientFactory.hxx \
                SALOMEDSClient_IParameters.hxx \
+               SALOMEDSClient_Observer.hxx \
                SALOMEDSClient.hxx
 
 #
index 13273ab2aa62e1b5f1a3fcdd0f71980f035fd452..2ccc8cf91277f8d34e2e9191588846ec294a9d61 100644 (file)
@@ -39,6 +39,9 @@
 #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
 {
@@ -120,7 +123,9 @@ public:
   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;
+
 };
 
 
index 91cef20ef066459ae59e9c237887a64db91672da..906403c97928ddad955eaaf31f33fd0e7ccd54d1 100644 (file)
@@ -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
index 0f7baf1eb9c9ecb9f8af7f288a77c7edc5a589d2..7f3544df177709df37fa0454c62008c7296e9ded 100644 (file)
@@ -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();
 }
 
index 9bf5348bfb8f8a8db46f2ab25d368562eddedab8..bf2b3b8582a2c13e02aa6ef7632aec89a759d9a0 100644 (file)
@@ -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<std::string> 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;
+}
index d048586aa492f77d239fb1bd2166f15e604521f5..0731d3ab3de08c4bfc7f7e55077415b376214942 100644 (file)
@@ -70,6 +70,7 @@ private:
   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;
@@ -313,6 +314,13 @@ public:
   //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;
index b42685c3f828f079f66e1526716262db8168f3b6..d42e08dfc77ac7ff553649d0e06a3ab5186536cc 100644 (file)
@@ -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;
 }