Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Study_i.cxx
index 94e3537e0eb5fbba75255074a8b6dd0e77bbfb38..0c74680da1d4b28e67b69e2f128f477d68372a12 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  File   : 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"
 #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, int reason)
+    {
+      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);
+            }
+        }
+      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();
@@ -709,11 +793,11 @@ void SALOMEDS_Study_i::Close()
       catch (CORBA::Exception&) 
         {/*pass*/ }
     }
-    sco->Destroy();
+    sco->UnRegister();
   }
 
   //Does not need any more this iterator
-  itcomponent->Destroy();
+  itcomponent->UnRegister();
 
 
   _impl->Close();
@@ -758,8 +842,8 @@ void SALOMEDS_Study_i::RemovePostponed(CORBA::Long /*theUndoLimit*/)
       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->Destroy();
-      //if (!CORBA::is_nil(aGeneric)) aGeneric->Destroy();
+         //rnv: 2. Second decrement of the reference count in the next string : aGeneric->UnRegister();
+      //if (!CORBA::is_nil(aGeneric)) aGeneric->UnRegister();
     } catch (...) {}
   }
 
@@ -789,13 +873,14 @@ void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
                                            const char* theBaseName, 
-                                           CORBA::Boolean isPublished)
+                                           CORBA::Boolean isPublished,
+                                           CORBA::Boolean isMultiFile)
 {
   SALOMEDS::Locker lock; 
 
   std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
-  CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
+  CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
   delete factory;
   return ret;
 }
@@ -1152,6 +1237,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
 //===========================================================================