Salome HOME
Fix bug of the observer: detach an observer when study is unloaded from GUI
authorvsr <vsr@opencascade.com>
Mon, 17 Mar 2014 07:30:36 +0000 (11:30 +0400)
committervsr <vsr@opencascade.com>
Mon, 17 Mar 2014 07:30:36 +0000 (11:30 +0400)
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/SALOMEDSClient_Study.hxx

index 1e73daad5161897249a828de0a9b0f2010cb11e0..d911ea1ad4516ef3c2324c738025ec2131d866d7 100644 (file)
@@ -552,9 +552,17 @@ during each working session.
 /*!
      Attach an observer to the Study
 
-    \param theObserver
+    \param theObserver observer being attached
+    \param modify when \c true, observer receives any object's modification events;
+           otherwise observer receives object's creation events only
 */
      void attach(in SALOMEDS::Observer theObserver, in boolean modify);   
+/*!
+     Detach an observer from the Study
+
+    \param theObserver observer to be detached
+*/
+     void detach(in SALOMEDS::Observer theObserver);   
   };
 
   //===========================================================================
index 4dc66de3f9c4fba818b63f0afcf870d4e074058d..1834ca349f178fc73e051613566abd04fb867000 100644 (file)
@@ -1008,3 +1008,9 @@ 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);
 }
+
+void SALOMEDS_Study::detach(SALOMEDS::Observer_ptr theObserver)
+{
+  if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
+  _corba_impl->detach(theObserver);
+}
index deae52fe4d76f008fca55621d55bd201a132a8e0..5732761f5e5bc9d3074e89fd681214cf895275bd 100644 (file)
@@ -123,6 +123,7 @@ public:
   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);
+  virtual void detach(SALOMEDS::Observer_ptr theObserver);
 
   std::string ConvertObjectToIOR(CORBA::Object_ptr theObject);
   CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR);     
index 3dec698bc06ab9aa388be5ea2c96f4460bd9807f..5bbc01b31cb8a13b4c32a9fbdf347175fafc5064 100644 (file)
@@ -147,6 +147,23 @@ namespace SALOMEDS
       myObservers.push_back(std::make_pair(SALOMEDS::Observer::_duplicate(theObs),modify));
     }
 
+    //============================================================================
+    /*! 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;
@@ -1330,6 +1347,18 @@ void SALOMEDS_Study_i::attach(SALOMEDS::Observer_ptr theObs,CORBA::Boolean modif
     static_cast<SALOMEDS::Notifier*>(_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<SALOMEDS::Notifier*>(_notifier)->detach(theObs);
+}
+
 //===========================================================================
 //   PRIVATE FUNCTIONS
 //===========================================================================
index fc10f36f22dc5b2c27ec0cb248f789237ff129de..d988daa48980d470f9422a733010db99cb807ab7 100644 (file)
@@ -351,6 +351,6 @@ public:
   virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal);
 
   virtual void attach(SALOMEDS::Observer_ptr theObs, CORBA::Boolean modify);
-
+  virtual void detach(SALOMEDS::Observer_ptr theObs);
 };
 #endif
index 92d681b083c7e2cd58d9725ce1d1b984228ab545..5492ffd4ae670c84e458feb3e34f129bac137f72 100644 (file)
@@ -126,7 +126,7 @@ public:
   virtual std::vector< std::vector<std::string> > ParseVariables(const std::string& theVars) = 0;
 
   virtual void attach(SALOMEDS::Observer_ptr theObserver,bool modify) = 0;
-
+  virtual void detach(SALOMEDS::Observer_ptr theObserver) = 0;
 };