From: asl Date: Sat, 21 Nov 2009 12:12:02 +0000 (+0000) Subject: Debug X-Git-Tag: PHASE_17_Part1_V1~33 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=928af2340b2439472073da3ed88a9000c0f17847;p=modules%2Fkernel.git Debug --- diff --git a/src/Notebook/SALOME_Notebook.cxx b/src/Notebook/SALOME_Notebook.cxx index 592eee847..6960c82c1 100644 --- a/src/Notebook/SALOME_Notebook.cxx +++ b/src/Notebook/SALOME_Notebook.cxx @@ -38,15 +38,19 @@ CORBA::Boolean SALOME_Notebook::AddDependency( SALOME::ParameterizedObject_ptr t return AddDependency( GetKey( theObj ), GetKey( theRef ) ); } -void SALOME_Notebook::RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ) +CORBA::Boolean SALOME_Notebook::RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ) { std::string anObjKey = GetKey( theObj ), aRefKey = GetKey( theRef ); - myDeps[anObjKey].remove( aRefKey ); + std::map< std::string, std::list >::iterator it = myDeps.find( anObjKey ); + bool ok = it != myDeps.end(); + if( ok ) + it->second.remove( aRefKey ); + return ok; } -void SALOME_Notebook::ClearDependencies( SALOME::ParameterizedObject_ptr theObj ) +void SALOME_Notebook::ClearDependencies( SALOME::ParameterizedObject_ptr theObj, SALOME::DependenciesType theType ) { - ClearDependencies( GetKey( theObj ) ); + ClearDependencies( GetKey( theObj ), theType ); } void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) @@ -59,7 +63,7 @@ void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) std::string anEntry = aParam->GetEntry(); SALOME_Parameter* aParamPtr = myParams[anEntry]; std::string aKey = GetKey( anEntry ); - ClearDependencies( aKey ); + ClearDependencies( aKey, SALOME::All ); AddDependencies( aParamPtr ); } @@ -83,16 +87,7 @@ void SALOME_Notebook::SetToUpdate( SALOME::ParameterizedObject_ptr theObj ) if( find( myToUpdate.begin(), myToUpdate.end(), *it ) == myToUpdate.end() ) myToUpdate.push_back( KeyHelper( *it, this ) ); - //myToUpdate.sort(); - std::list::iterator uit = myToUpdate.begin(), uit1, ulast = myToUpdate.end(); - for( ; uit!=ulast; uit++ ) - for( uit1=uit, uit1++; uit1!=ulast; uit1++ ) - if( *uit1 < *uit ) - { - KeyHelper tmp = *uit1; - *uit1 = *uit; - *uit = tmp; - } + Sort( myToUpdate ); /* uit = myToUpdate.begin(); ulast = myToUpdate.end(); @@ -119,38 +114,96 @@ void SALOME_Notebook::Update() myToUpdate = aPostponedUpdate; } -CORBA::Boolean SALOME_Notebook::AddExpr( const char* theExpr ) +CORBA::Boolean SALOME_Notebook::AddExpression( const char* theExpr ) { return AddParam( new SALOME_Parameter( this, theExpr ) ); } -CORBA::Boolean SALOME_Notebook::AddNameExpr( const char* theName, const char* theExpr ) +CORBA::Boolean SALOME_Notebook::AddNamedExpression( const char* theName, const char* theExpr ) +{ + return AddParam( new SALOME_Parameter( this, theName, theExpr, true ) ); +} + +CORBA::Boolean SALOME_Notebook::AddBoolean( const char* theName, CORBA::Boolean theValue ) +{ + return AddParam( new SALOME_Parameter( this, theName, theValue ) ); +} + +CORBA::Boolean SALOME_Notebook::AddInteger( const char* theName, CORBA::Long theValue ) { - return AddParam( new SALOME_Parameter( this, theName, theExpr ) ); + return AddParam( new SALOME_Parameter( this, theName, (int)theValue ) ); } -CORBA::Boolean SALOME_Notebook::AddValue( const char* theName, CORBA::Double theValue ) +CORBA::Boolean SALOME_Notebook::AddReal( const char* theName, CORBA::Double theValue ) { return AddParam( new SALOME_Parameter( this, theName, theValue ) ); } -void SALOME_Notebook::Remove( const char* theParamName ) +CORBA::Boolean SALOME_Notebook::AddString( const char* theName, const char* theValue ) +{ + return AddParam( new SALOME_Parameter( this, theName, theValue, false ) ); +} + +CORBA::Boolean SALOME_Notebook::Remove( const char* theParamName ) { std::string aKey = GetKey( theParamName ); - ClearDependencies( aKey ); + ClearDependencies( aKey, SALOME::All ); + bool ok = myDeps.find( aKey ) != myDeps.end() && myParams.find( aKey ) != myParams.end(); myDeps.erase( aKey ); myParams.erase( theParamName ); + return ok; +} + +SALOME::StringArray* SALOME_Notebook::GenerateList( const std::list& theList ) const +{ + SALOME::StringArray_var aRes = new SALOME::StringArray(); + aRes->length( theList.size() ); + std::list::const_iterator nit = theList.begin(), nlast = theList.end(); + for( int i=0; nit!=nlast; nit++, i++ ) + aRes[i] = CORBA::string_dup( nit->c_str() ); + + return aRes._retn(); } -SALOME::StringList* SALOME_Notebook::Params() +SALOME::StringArray* SALOME_Notebook::Parameters() { - return 0; + std::list aNames; + std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.begin(), last = myParams.end(); + for( ; it!=last; it++ ) + { + std::string anEntry = it->second->GetEntry(); + if( !it->second->IsAnonimous() && find( aNames.begin(), aNames.end(), anEntry ) == aNames.end() ) + aNames.push_back( anEntry ); + } + + aNames.sort(); + return GenerateList( aNames ); +} + +SALOME::StringArray* SALOME_Notebook::AbsentParameters() +{ + std::list anAbsents; + std::map< std::string, std::list >::const_iterator it = myDeps.begin(), last = myDeps.end(); + for( ; it!=last; it++ ) + { + std::list::const_iterator pit = it->second.begin(), plast = it->second.end(); + for( ; pit!=plast; pit++ ) + { + std::string anEntry, aComponent = GetComponent( *pit, anEntry ); + if( aComponent == PARAM_COMPONENT && !GetParameterPtr( anEntry.c_str() ) && + find( anAbsents.begin(), anAbsents.end(), anEntry ) == anAbsents.end() ) + anAbsents.push_back( anEntry ); + } + } + + anAbsents.sort(); + return GenerateList( anAbsents ); } -SALOME::Parameter_ptr SALOME_Notebook::Param( const char* theParamName ) +SALOME::Parameter_ptr SALOME_Notebook::GetParameter( const char* theParamName ) { //printf( "Param, name = %s\n", theParamName ); - SALOME_Parameter* aParam = ParamPtr( theParamName ); + SALOME_Parameter* aParam = GetParameterPtr( theParamName ); //printf( "Result = %i\n", (int)aParam ); SALOME::Parameter_var aRes; if( aParam ) @@ -158,7 +211,7 @@ SALOME::Parameter_ptr SALOME_Notebook::Param( const char* theParamName ) return aRes._retn(); } -SALOME_Parameter* SALOME_Notebook::ParamPtr( const char* theParamName ) const +SALOME_Parameter* SALOME_Notebook::GetParameterPtr( const char* theParamName ) const { std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.find( theParamName ); return it==myParams.end() ? 0 : it->second; @@ -167,7 +220,7 @@ SALOME_Parameter* SALOME_Notebook::ParamPtr( const char* theParamName ) const bool SALOME_Notebook::AddParam( SALOME_Parameter* theParam ) { std::string anEntry = theParam->GetEntry(); - if( !CheckParamName( anEntry ) ) + if( !theParam->IsAnonimous() && !CheckParamName( anEntry ) ) return false; //printf( "Add param: %s\n", anEntry.c_str() ); @@ -176,7 +229,7 @@ bool SALOME_Notebook::AddParam( SALOME_Parameter* theParam ) if( it!=myParams.end() ) { delete it->second; - ClearDependencies( GetKey( anEntry ) ); + ClearDependencies( GetKey( anEntry ), SALOME::All ); } bool ok = AddDependencies( theParam ); @@ -223,10 +276,30 @@ bool SALOME_Notebook::AddDependency( const std::string& theObjKey, const std::st return ok; } -void SALOME_Notebook::ClearDependencies( const std::string& theObjKey ) +void SALOME_Notebook::ClearDependencies( const std::string& theObjKey, SALOME::DependenciesType theType ) { //printf( "Clear dependencies: %s\n", theObjKey.c_str() ); - myDeps.erase( theObjKey ); + + std::map< std::string, std::list >::iterator it = myDeps.find( theObjKey ); + if( it == myDeps.end() ) + return; + + std::list aNewDeps; + if( theType != SALOME::All ) + { + std::list::const_iterator dit = it->second.begin(), dlast = it->second.end(); + for( ; dit!=dlast; dit++ ) + { + SALOME::Parameter_ptr aParam = SALOME::Parameter::_narrow( FindObject( *dit ) ); + if( ( !CORBA::is_nil( aParam ) && theType == SALOME::Objects ) || theType == SALOME::Parameters ) + aNewDeps.push_back( *dit ); + } + } + + if( aNewDeps.size() == 0 ) + myDeps.erase( theObjKey ); + else + it->second = aNewDeps; } std::string SALOME_Notebook::GetKey( SALOME::ParameterizedObject_ptr theObj ) @@ -271,12 +344,18 @@ std::list SALOME_Notebook::GetAllDependingOn( const std::string& th return aDeps; } -SALOME::ParameterizedObject_ptr SALOME_Notebook::FindObject( const std::string& theKey ) +std::string SALOME_Notebook::GetComponent( const std::string& theKey, std::string& theEntry ) const { int aPos = theKey.find( "#" ); - std::string aComponent = theKey.substr( 0, aPos ), anEntry = theKey.substr( aPos+1, theKey.length()-aPos-1 ); + theEntry = theKey.substr( aPos+1, theKey.length()-aPos-1 ); + return theKey.substr( 0, aPos ); +} + +SALOME::ParameterizedObject_ptr SALOME_Notebook::FindObject( const std::string& theKey ) +{ + std::string anEntry, aComponent = GetComponent( theKey, anEntry ); if( aComponent == PARAM_COMPONENT ) - return Param( anEntry.c_str() ); + return GetParameter( anEntry.c_str() ); else return SALOME::ParameterizedObject::_narrow( myStudy->FindObjectByInternalEntry( aComponent.c_str(), anEntry.c_str() ) ); } @@ -311,11 +390,13 @@ bool SALOME_Notebook::KeyHelper::operator == ( const std::string& theKey ) const return myKey == theKey; } -void SALOME_Notebook::Save( const char* theFileName ) +CORBA::Boolean SALOME_Notebook::Save( const char* theFileName ) { //printf( "SALOME_Notebook::Save into %s\n", theFileName ); FILE* aFile = fopen( theFileName, "w" ); + if( !aFile ) + return false; fprintf( aFile, "\n\nnotebook\n" ); @@ -350,11 +431,67 @@ void SALOME_Notebook::Save( const char* theFileName ) } fclose( aFile ); + return true; } +typedef enum { Start, Title, Dependencies, Parameters, Update } LoadState; + CORBA::Boolean SALOME_Notebook::Load( const char* theFileName ) { - return false; + //printf( "SALOME_Notebook::Load\n" ); + //LoadState state = Start; + FILE* aFile = fopen( theFileName, "r" ); + if( !aFile ) + return false; + + char buf[256]; + while( !feof( aFile ) ) + { + fscanf( aFile, "%s", buf ); + printf( "loaded line = %s\n", buf ); + } + + fclose( aFile ); + return true; +} + +CORBA::Boolean SALOME_Notebook::DumpPython( const char* theFileName ) +{ + FILE* aFile = fopen( theFileName, "w" ); + if( !aFile ) + return false; + + fprintf( aFile, "from salome_notebook import *\n" ); + std::list< KeyHelper > aParams; + std::map< std::string, SALOME_Parameter* >::const_iterator it = myParams.begin(), last = myParams.end(); + for( ; it!=last; it++ ) + aParams.push_back( KeyHelper( it->first, this ) ); + + Sort( aParams ); + std::list< KeyHelper >::const_iterator pit = aParams.begin(), plast = aParams.end(); + std::string anEntry; + for( ; pit!=plast; pit++ ) + { + GetComponent( pit->key(), anEntry ); + fprintf( aFile, "notebook.set( " ); + + SALOME_Parameter* aParam = GetParameterPtr( anEntry.c_str() ); + if( aParam->IsAnonimous() ) + fprintf( aFile, "\"%s\"", aParam->Expression().c_str() ); + else + { + fprintf( aFile, "\"%s\", ", anEntry.c_str() ); + if( aParam->IsCalculable() ) + fprintf( aFile, "\"%s\"", aParam->Expression().c_str() ); + else + fprintf( aFile, "%s", aParam->AsString() ); + } + + fprintf( aFile, " )\n" ); + } + + fclose( aFile ); + return true; } bool SALOME_Notebook::CheckParamName( const std::string& theParamName ) const @@ -366,3 +503,16 @@ bool SALOME_Notebook::CheckParamName( const std::string& theParamName ) const SALOME_EvalExpr anExpr( theParamName ); return anExpr.parser()->isMonoParam(); } + +void SALOME_Notebook::Sort( std::list< KeyHelper >& theList ) const +{ + std::list::iterator uit = theList.begin(), uit1, ulast = theList.end(); + for( ; uit!=ulast; uit++ ) + for( uit1=uit, uit1++; uit1!=ulast; uit1++ ) + if( *uit1 < *uit ) + { + KeyHelper tmp = *uit1; + *uit1 = *uit; + *uit = tmp; + } +} diff --git a/src/Notebook/SALOME_Notebook.hxx b/src/Notebook/SALOME_Notebook.hxx index 6a2c36124..803f3163b 100644 --- a/src/Notebook/SALOME_Notebook.hxx +++ b/src/Notebook/SALOME_Notebook.hxx @@ -42,42 +42,44 @@ public: SALOME_Notebook( PortableServer::POA_ptr thePOA, SALOMEDS::Study_ptr theStudy ); virtual CORBA::Boolean AddDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ); - virtual void RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ); - virtual void ClearDependencies( SALOME::ParameterizedObject_ptr theObj ); + virtual CORBA::Boolean RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef ); + virtual void ClearDependencies( SALOME::ParameterizedObject_ptr theObj, SALOME::DependenciesType theType ); virtual void SetToUpdate( SALOME::ParameterizedObject_ptr theObj ); virtual void Update(); - virtual CORBA::Boolean AddExpr( const char* theExpr ); - virtual CORBA::Boolean AddNameExpr( const char* theName, const char* theExpr ); - virtual CORBA::Boolean AddValue( const char* theName, CORBA::Double theValue ); - virtual void Remove( const char* theParamName ); - virtual SALOME::Parameter_ptr Param( const char* theParamName ); - virtual SALOME::StringList* Params(); + virtual CORBA::Boolean AddExpression( const char* theExpr ); + virtual CORBA::Boolean AddNamedExpression( const char* theName, const char* theExpr ); + virtual CORBA::Boolean AddBoolean( const char* theName, CORBA::Boolean theValue ); + virtual CORBA::Boolean AddInteger( const char* theName, CORBA::Long theValue ); + virtual CORBA::Boolean AddReal( const char* theName, CORBA::Double theValue ); + virtual CORBA::Boolean AddString( const char* theName, const char* theValue ); + virtual CORBA::Boolean Remove( const char* theParamName ); + virtual SALOME::Parameter_ptr GetParameter( const char* theParamName ); + virtual SALOME::StringArray* Parameters(); + virtual SALOME::StringArray* AbsentParameters(); - virtual void Save( const char* theFileName ); + virtual CORBA::Boolean Save( const char* theFileName ); virtual CORBA::Boolean Load( const char* theFileName ); + virtual CORBA::Boolean DumpPython( const char* theFileName ); - SALOME_Parameter* ParamPtr( const char* theParamName ) const; + SALOME_Parameter* GetParameterPtr( const char* theParamName ) const; protected: bool AddParam( SALOME_Parameter* theParam ); bool AddDependencies( SALOME_Parameter* theParam ); bool AddDependency( const std::string& theObjKey, const std::string& theRefKey ); - void ClearDependencies( const std::string& theObjKey ); + void ClearDependencies( const std::string& theObjKey, SALOME::DependenciesType theType ); bool CheckParamName( const std::string& theParamName ) const; + SALOME::StringArray* GenerateList( const std::list& theList ) const; + std::string GetComponent( const std::string& theKey, std::string& theEntry ) const; private: std::string GetKey( SALOME::ParameterizedObject_ptr theObj ); std::string GetKey( const std::string& theParamName ); - - //! return list of objects that depend on object with given key std::list GetAllDependingOn( const std::string& theKey ); SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ); private: - std::map< std::string, std::list > myDeps; - std::map< std::string, SALOME_Parameter* > myParams; - friend class KeyHelper; class KeyHelper { @@ -91,8 +93,13 @@ private: std::string myKey; SALOME_Notebook* myNotebook; }; - std::list< KeyHelper > myToUpdate; + void Sort( std::list< KeyHelper >& theList ) const; + +private: + std::map< std::string, std::list > myDeps; + std::map< std::string, SALOME_Parameter* > myParams; + std::list< KeyHelper > myToUpdate; SALOMEDS::Study_var myStudy; };