From 116a3046e4dc4aed65500ec07e1ad1f5caddb506 Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 8 Dec 2009 11:10:44 +0000 Subject: [PATCH] 1. New method GetParametersDependingOn() 2. Loading of old studies containing notebook data --- src/Notebook/SALOME_Notebook.cxx | 91 +++++++++++++++++++++++++++++++- src/Notebook/SALOME_Notebook.hxx | 17 +++--- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index dccd3e9aa..fb4e59aae 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -66,11 +66,11 @@ std::vector split( const std::string& theData, const std::string& t { std::vector aParts; int aPrev = 0, anInd = 0; - while( true ) + while( anInd 0 || theIsKeepEmpty ) @@ -1117,3 +1117,90 @@ SALOME::Parameter_ptr SALOME_Notebook::Calculate( const char* theExpr ) myTmpParam->Update( _this() ); return myTmpParam.in(); } + +void SALOME_Notebook::ParseOldStyleParam( const std::string& theName, const std::string& theType, const std::string& theValue ) +{ + int aType; + if( sscanf( theType.c_str(), "%i", &aType ) != 1 ) + return; + + switch( aType ) + { + case 0: + { + double aValue; + if( sscanf( theValue.c_str(), "%lf", &aValue ) != 1 ) + return; + + AddReal( theName.c_str(), aValue ); + break; + } + case 1: + { + int aValue; + if( sscanf( theValue.c_str(), "%i", &aValue ) != 1 ) + return; + + AddInteger( theName.c_str(), aValue ); + break; + } + case 2: + { + int aValue; + if( sscanf( theValue.c_str(), "%i", &aValue ) != 1 ) + return; + + AddBoolean( theName.c_str(), aValue ); + break; + } + case 3: + { + std::string aValue = theValue; + for( int i = 0, n = aValue.length(); i < n; i++ ) + if( aValue[i]=='"' ) + aValue[i] = ' '; + + AddNamedExpression( theName.c_str(), aValue.c_str() ); + break; + } + } +} + +void SALOME_Notebook::ParseOldStyleObject( const std::string& theComponent, const std::string& theEntry, const std::string& theData ) +{ + //printf( "ParseOldStyleObject: %s\n", theData.c_str() ); + std::string anObjKey = GetKey( theComponent, theEntry ); + std::vector aParts = split( theData, "|", false ), anItems; + for( int i=0, n=aParts.size(); i aParamsDeps; + std::list aDeps = GetAllDependingOn( GetKey( theParamName ) ); + std::list::const_iterator it = aDeps.begin(), last = aDeps.end(); + std::string aName; + for( ; it!=last; it++ ) + if( GetComponent( *it, aName ) == PARAM_COMPONENT ) + aParamsDeps.push_back( aName ); + + return GenerateList( aParamsDeps ); +} diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index b26df1750..203117b62 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -72,16 +72,20 @@ public: virtual SALOME::Parameter_ptr Calculate( const char* theExpr ); - virtual CORBA::Boolean Save( const char* theFileName ); - virtual CORBA::Boolean Load( const char* theFileName ); - virtual char* DumpPython(); - virtual char* Dump(); - virtual char* GetParameters( const char* theComponent, const char* theEntry ); + virtual CORBA::Boolean Save( const char* theFileName ); + virtual CORBA::Boolean Load( const char* theFileName ); + virtual char* DumpPython(); + virtual char* Dump(); + virtual char* GetParameters( const char* theComponent, const char* theEntry ); + virtual SALOME::StringArray* GetParametersDependingOn( const char* theParamName ); SALOME_Parameter* GetParameterPtr( const char* theParamName ) const; void UpdateAnonymous( const std::string& theOldName, const std::string& theNewName ); int GetNewId(); bool HasDependency( const std::string& theObjKey, const std::string& theRefKey ) const; + void ParseOldStyleParam( const std::string& theName, const std::string& theType, const std::string& theValue ); + void ParseOldStyleObject( const std::string& theComponent, const std::string& theEntry, const std::string& theData ); + void RebuildLinks(); private: void Update( bool theOnlyParameters ); @@ -94,7 +98,7 @@ private: std::string GetComponent( const std::string& theKey, std::string& theEntry ) const; void ParseDependencies( FILE* theFile, const std::string& theFirstLine ); std::string GetKey( SALOME::ParameterizedObject_ptr theObj ) const; - std::string GetKey( const std::string& theComponent, const std::string& theParamName ) const; + std::string GetKey( const std::string& theComponent, const std::string& theEntry ) const; std::string GetKey( const std::string& theParamName ) const; std::list GetAllDependingOn( const std::string& theKey ) const; SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ) const; @@ -136,6 +140,7 @@ private: std::map< std::string, SALOME_Parameter* > myParameters; std::list< KeyHelper > myToUpdate; std::list mySubstitutions; + std::list< std::string > myEntriesToRebuild; SALOMEDS::Study_var myStudy; SALOME::Parameter_var myTmpParam; Utils_Mutex myMutex; -- 2.39.2