From 1974af30b2aa06030483f030c80b55850e3cd278 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 13 Nov 2008 13:05:40 +0000 Subject: [PATCH] Dump Python extension --- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 122 ++++++++++++++---------- src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 8 ++ 2 files changed, 81 insertions(+), 49 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 4af8f7ded..e57143d20 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1728,37 +1728,93 @@ bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName) * Purpose : */ //============================================================================ -bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName) +bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder, + SALOMEDSImpl_SObject theSObject, + const std::string& theName) { + SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject ); + for( ; anIter.More(); anIter.Next() ) + if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) ) + return true; + DF_Attribute* anAttr; + if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) ) + { + if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) + { + string aString = aStringAttr->Value(); + + vector aVector = SALOMEDSImpl_Tool::splitString( aString, ':' ); + for( int i = 0, len = aVector.size(); i < len; i++ ) + { + string aStr = aVector[i]; + if( aStr.compare( theName ) == 0 ) + return true; + } + } + } + return false; +} + +//============================================================================ +/*! Function : FindVariableAttribute + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName) +{ SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder(); SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator(); for( ; aCompIter.More(); aCompIter.Next() ) { SALOMEDSImpl_SObject aComp = aCompIter.Value(); + if( FindVariableAttribute( aStudyBuilder, aComp, theName ) ) + return true; + } + return false; +} - SALOMEDSImpl_ChildIterator anIter = NewChildIterator( aComp ); - for( ; anIter.More(); anIter.Next() ) +//============================================================================ +/*! Function : ReplaceVariableAttribute + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder, + SALOMEDSImpl_SObject theSObject, + const std::string& theSource, + const std::string& theDest) +{ + SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject ); + for( ; anIter.More(); anIter.Next() ) + ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest ); + + DF_Attribute* anAttr; + if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) ) + { + if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) { - SALOMEDSImpl_SObject aSObject = anIter.Value(); - if( aStudyBuilder->FindAttribute( aSObject, anAttr, "AttributeString" ) ) + bool isChanged = false; + string aNewString, aCurrentString = aStringAttr->Value(); + + vector aVector = SALOMEDSImpl_Tool::splitString( aCurrentString, ':' ); + for( int i = 0, len = aVector.size(); i < len; i++ ) { - if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) + string aStr = aVector[i]; + if( aStr.compare( theSource ) == 0 ) { - string aString = aStringAttr->Value(); - - vector aVector = SALOMEDSImpl_Tool::splitString( aString, ':' ); - for( int i = 0, len = aVector.size(); i < len; i++ ) - { - string aStr = aVector[i]; - if( aStr.compare( theName ) == 0 ) - return true; - } + isChanged = true; + aStr = theDest; } + + aNewString.append( aStr ); + if( i != len ) + aNewString.append( ":" ); } + + if( isChanged ) + aStringAttr->SetValue( aNewString ); } } - return false; } //============================================================================ @@ -1768,44 +1824,12 @@ bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName) //============================================================================ void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest) { - DF_Attribute* anAttr; SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder(); SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator(); for( ; aCompIter.More(); aCompIter.Next() ) { SALOMEDSImpl_SObject aComp = aCompIter.Value(); - - SALOMEDSImpl_ChildIterator anIter = NewChildIterator( aComp ); - for( ; anIter.More(); anIter.Next() ) - { - SALOMEDSImpl_SObject aSObject = anIter.Value(); - if( aStudyBuilder->FindAttribute( aSObject, anAttr, "AttributeString" ) ) - { - if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr ) - { - bool isChanged = false; - string aNewString, aCurrentString = aStringAttr->Value(); - - vector aVector = SALOMEDSImpl_Tool::splitString( aCurrentString, ':' ); - for( int i = 0, len = aVector.size(); i < len; i++ ) - { - string aStr = aVector[i]; - if( aStr.compare( theSource ) == 0 ) - { - isChanged = true; - aStr = theDest; - } - - aNewString.append( aStr ); - if( i != len ) - aNewString.append( ":" ); - } - - if( isChanged ) - aStringAttr->SetValue( aNewString ); - } - } - } + ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest ); } } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index 3ba54b936..64ddce482 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -282,7 +282,15 @@ public: bool IsVariableUsed(const std::string& theVarName); + bool FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder, + SALOMEDSImpl_SObject theSObject, + const std::string& theName); bool FindVariableAttribute(const std::string& theName); + + void ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder, + SALOMEDSImpl_SObject theSObject, + const std::string& theSource, + const std::string& theDest); void ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest); //Returns a callback -- 2.39.2