From 0b28b481121d045603d54df066efb923114eeb67 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 15 Dec 2009 13:17:31 +0000 Subject: [PATCH] Implementation of object remove on deactivation --- src/Notebook/Makefile.am | 6 ++- src/Notebook/SALOME_Notebook.cxx | 30 +++++++++++++- src/Notebook/SALOME_Notebook.hxx | 1 + src/Notebook/SALOME_ParameterizedObject.cxx | 37 +++++++++++++++++ src/Notebook/SALOME_ParameterizedObject.hxx | 44 +++++++++++++++++++++ 5 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 src/Notebook/SALOME_ParameterizedObject.cxx create mode 100644 src/Notebook/SALOME_ParameterizedObject.hxx diff --git a/src/Notebook/Makefile.am b/src/Notebook/Makefile.am index 5db33dd75..8eeba1cae 100644 --- a/src/Notebook/Makefile.am +++ b/src/Notebook/Makefile.am @@ -39,7 +39,8 @@ salomeinclude_HEADERS = \ SALOME_EvalExpr.hxx \ SALOME_EvalParser.hxx \ SALOME_EvalSet.hxx \ - SALOME_EvalVariant.hxx + SALOME_EvalVariant.hxx \ + SALOME_ParameterizedObject.hxx # Scripts to be installed dist_salomescript_PYTHON= @@ -79,7 +80,8 @@ libSalomeNotebook_la_SOURCES = \ SALOME_EvalExpr.cxx \ SALOME_EvalParser.cxx \ SALOME_EvalSet.cxx \ - SALOME_EvalVariant.cxx + SALOME_EvalVariant.cxx \ + SALOME_ParameterizedObject.cxx libSalomeNotebook_la_CPPFLAGS = $(COMMON_CPPFLAGS) libSalomeNotebook_la_LDFLAGS = -Wl,-E -no-undefined -version-info=0:0:0 @LDEXPDYNFLAGS@ diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index ac661163e..23fffd52b 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -264,7 +264,7 @@ void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) bool SALOME_Notebook::CanUpdate( SALOME::ParameterizedObject_ptr theObj ) const { - if( CORBA::is_nil( theObj ) ) + if( CORBA::is_nil( theObj ) || theObj->_non_existent() ) return false; SALOME::Parameter_var aParam = SALOME::Parameter::_narrow( theObj ); @@ -282,7 +282,7 @@ void SALOME_Notebook::Update( bool theOnlyParameters ) //Utils_Locker lock( &myMutex ); //1. Simple recompute - std::list< KeyHelper > aPostponedUpdate; + std::list aPostponedUpdate; std::list::const_iterator it = myToUpdate.begin(), last = myToUpdate.end(); for( ; it!=last; it++ ) { @@ -482,6 +482,32 @@ void SALOME_Notebook::Rename( const char* theOldName, const char* theNewName ) ThrowError( aMsg ); } +void SALOME_Notebook::RemoveObject( SALOME::ParameterizedObject_ptr theObject ) +{ + if( theObject->GetComponent()==PARAM_COMPONENT ) + Remove( theObject->GetEntry() ); + + std::list anObjToRemove; + std::string aKey = GetKey( theObject ); + + std::map< std::string, std::list >::iterator it = myDependencies.begin(), last = myDependencies.end(); + for( ; it!=last; it++ ) + { + it->second.remove( aKey ); + if( it->second.size()==0 ) + anObjToRemove.push_back( it->first ); + } + + std::list::const_iterator rit = anObjToRemove.begin(), rlast = anObjToRemove.end(); + for( ; rit!=rlast; rit++ ) + myDependencies.erase( *rit ); + + std::list::iterator uit = myToUpdate.begin(), ulast = myToUpdate.end(); + for( ; uit!=ulast; uit++ ) + if( uit->key()==aKey ) + myToUpdate.erase( uit ); +} + void SALOME_Notebook::Remove( const char* theParamName ) { SALOME_Parameter* aParam = GetParameterPtr( theParamName ); diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index b69b5c0fa..fc8ec47bf 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -64,6 +64,7 @@ public: virtual void AddInteger( const char* theName, CORBA::Long theValue ); virtual void AddReal( const char* theName, CORBA::Double theValue ); virtual void AddString( const char* theName, const char* theValue ); + virtual void RemoveObject( SALOME::ParameterizedObject_ptr theObject ); virtual void Remove( const char* theParamName ); virtual void Rename( const char* theOldName, const char* theNewName ); virtual SALOME::Parameter_ptr GetParameter( const char* theParamName ); diff --git a/src/Notebook/SALOME_ParameterizedObject.cxx b/src/Notebook/SALOME_ParameterizedObject.cxx new file mode 100644 index 000000000..1754271af --- /dev/null +++ b/src/Notebook/SALOME_ParameterizedObject.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2008 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 +// +// 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. +// +// 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 +// +// File : SALOME_ParameterizedObject.cxx +// Author : Alexandre SOLOVYOV +// Module : SALOME + +#include + +SALOME_ParameterizedObject::SALOME_ParameterizedObject( SALOME::Notebook_ptr theNotebook ) +{ + myNotebook = theNotebook; +} + +void SALOME_ParameterizedObject::BeforeDeactivate() +{ + if( !CORBA::is_nil( myNotebook ) ) + myNotebook->RemoveObject( _this() ); +} diff --git a/src/Notebook/SALOME_ParameterizedObject.hxx b/src/Notebook/SALOME_ParameterizedObject.hxx new file mode 100644 index 000000000..6a1c90469 --- /dev/null +++ b/src/Notebook/SALOME_ParameterizedObject.hxx @@ -0,0 +1,44 @@ +// Copyright (C) 2007-2008 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 +// +// 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. +// +// 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 +// +// File : SALOME_ParameterizedObject.hxx +// Author : Alexandre SOLOVYOV +// Module : SALOME +// +#ifndef __SALOME_PARAMETERIZED_OBJECT_H__ +#define __SALOME_PARAMETERIZED_OBJECT_H__ + +#include +#include CORBA_SERVER_HEADER(SALOME_Notebook) +#include + +class SALOME_ParameterizedObject : public virtual POA_SALOME::ParameterizedObject, public virtual SALOME::GenericObj_i +{ +public: + SALOME_ParameterizedObject( SALOME::Notebook_ptr theNotebook ); + + virtual void BeforeDeactivate(); + +private: + SALOME::Notebook_var myNotebook; +}; + +#endif -- 2.39.2