From ffc0cd0a83dfd5f286bc3d4636e7a4c5afb72f06 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 24 Nov 2009 14:02:12 +0000 Subject: [PATCH] debug of rename/remove --- src/Notebook/SALOME_Notebook.cxx | 43 +++++++++++++++++++------------ src/Notebook/SALOME_Notebook.hxx | 2 +- src/Notebook/SALOME_Parameter.cxx | 17 +++++++++--- src/Notebook/SALOME_Parameter.hxx | 5 ++-- 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index 72aa738b3..cd46feac2 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -193,19 +193,35 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution ) if( CORBA::is_nil( aParam ) ) { //it is real object + SALOME::StringArray_var aParams = anObj->GetParameters(); + int n = aParams->length(); + //printf( "get params: %i\n", n ); + for( int i=0; iSetParameters( _this(), aParams ); } else { std::string - aName = aParam->GetEntry(), + aName = aParam->GetEntry(), anOldKey = GetKey( aName ), - aNewKey = GetKey( aNewName ); + aNewKey = GetKey( aNewName ); + SALOME_Parameter* aParamPtr = myParameters[aName]; + + aParamPtr->Substitute( anOldName, aNewName ); if( aName == anOldName ) { //it is renamed parameter //1. update parameters map - SALOME_Parameter* aParam = myParameters[anOldName]; if( isRename ) { std::list aDeps = myDependencies[anOldKey]; @@ -213,12 +229,12 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution ) myDependencies[aNewKey] = aDeps; myParameters.erase( anOldName ); - myParameters[aNewName] = aParam; + myParameters[aNewName] = aParamPtr; } else { ClearDependencies( anOldKey, SALOME::All ); - myParameters.erase( anOldName ); + myParameters.erase( aName ); } //2. update dependencies map @@ -227,7 +243,7 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution ) { std::list::iterator dit = it->second.begin(), dlast = it->second.end(), dremove; for( ; dit!=dlast; ) - if( *dit == anOldName ) + if( *dit == anOldKey ) { if( isRename ) { @@ -245,11 +261,6 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution ) dit++; } } - else - { - SALOME_Parameter* aParamPtr = GetParameterPtr( aName.c_str() ); - aParamPtr->Substitute( anOldName, anExpr ); - } } } theSubstitution.myObjects = aPostponedUpdate; @@ -291,7 +302,7 @@ SALOME_Notebook::SubstitutionInfo SALOME_Notebook::CreateSubstitution( const std SubstitutionInfo anInfo; anInfo.myName = theName; anInfo.myExpr = theExpr; - anInfo.myIsRename = true; + anInfo.myIsRename = theIsRename; std::list aDeps = GetAllDependingOn( GetKey( theName ) ); anInfo.myObjects.clear(); std::list::const_iterator dit = aDeps.begin(), dlast = aDeps.end(); @@ -331,9 +342,9 @@ CORBA::Boolean SALOME_Notebook::Remove( const char* theParamName ) return ok; } -void SALOME_Notebook::UpdateAnonymous( const char* theOldName, SALOME_Parameter* theParam ) +void SALOME_Notebook::UpdateAnonymous( const std::string& theOldName, const std::string& theNewName ) { - SubstitutionInfo anInfo = CreateSubstitution( theOldName, theParam->GetEntry(), true ); + SubstitutionInfo anInfo = CreateSubstitution( theOldName, theNewName, true ); Substitute( anInfo ); } @@ -786,7 +797,7 @@ char* SALOME_Notebook::Dump() aStr += " -> "; std::list::const_iterator it = dit->second.begin(), last = dit->second.end(); for( ; it!=last; it++ ) - aStr += *it; + aStr += *it + " "; aStr += "\n"; } aStr += "\n"; @@ -796,7 +807,7 @@ char* SALOME_Notebook::Dump() std::map< std::string, SALOME_Parameter* >::const_iterator pit = myParameters.begin(), plast = myParameters.end(); for( ; pit!=plast; pit++ ) { - aStr += pit->first + ": "; + aStr += pit->first + " (" + pit->second->GetEntry() + "): "; if( pit->second->IsAnonymous() ) aStr += "[A] "; if( pit->second->IsCalculable() ) diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index 0a95d1c54..e094f59ab 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -67,7 +67,7 @@ public: virtual char* Dump(); SALOME_Parameter* GetParameterPtr( const char* theParamName ) const; - void UpdateAnonymous( const char* theOldName, SALOME_Parameter* theParam ); + void UpdateAnonymous( const std::string& theOldName, const std::string& theNewName ); static std::vector Split( const std::string& theData, const std::string& theSeparator, bool theIsKeepEmpty ); diff --git a/src/Notebook/SALOME_Parameter.cxx b/src/Notebook/SALOME_Parameter.cxx index 72f844f5e..e516de222 100644 --- a/src/Notebook/SALOME_Parameter.cxx +++ b/src/Notebook/SALOME_Parameter.cxx @@ -86,6 +86,11 @@ void SALOME_Parameter::SetParameters( SALOME::Notebook_ptr /*theNotebook*/, cons { } +SALOME::StringArray* SALOME_Parameter::GetParameters() +{ + return 0; +} + void SALOME_Parameter::Update( SALOME::Notebook_ptr /*theNotebook*/ ) { //printf( "Update of %s\n", GetEntry() ); @@ -280,11 +285,17 @@ void SALOME_Parameter::Substitute( const std::string& theName, const SALOME_Eval if( !IsCalculable() ) return; + if( myName == theName ) + { + myName = theExpr.expression(); + return; + } + myExpr.substitute( theName, theExpr ); if( IsAnonymous() ) { - std::string anOldName = myName; - myName = myExpr.expression(); - myNotebook->UpdateAnonymous( anOldName.c_str(), this ); + std::string aNewName = myExpr.expression(); + myNotebook->UpdateAnonymous( myName, aNewName ); + myName = aNewName; } } diff --git a/src/Notebook/SALOME_Parameter.hxx b/src/Notebook/SALOME_Parameter.hxx index dd24e0db0..4c04ff97e 100644 --- a/src/Notebook/SALOME_Parameter.hxx +++ b/src/Notebook/SALOME_Parameter.hxx @@ -53,8 +53,9 @@ public: virtual char* GetComponent(); virtual CORBA::Boolean IsValid(); - virtual void Update( SALOME::Notebook_ptr theNotebook ); - virtual void SetParameters ( SALOME::Notebook_ptr theNotebook, const SALOME::StringArray& theParameters ); + virtual void Update( SALOME::Notebook_ptr theNotebook ); + virtual void SetParameters( SALOME::Notebook_ptr theNotebook, const SALOME::StringArray& theParameters ); + virtual SALOME::StringArray* GetParameters(); virtual void SetExpression( const char* theExpr ); virtual void SetBoolean( CORBA::Boolean theValue ); -- 2.39.2