From: ouv Date: Wed, 12 Nov 2008 16:20:28 +0000 (+0000) Subject: Dump Python extension X-Git-Tag: TG_DumpPython_Extension_2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=51aa257abf6b7547080c4edd10aad08fc49deb9a;p=modules%2Fkernel.git Dump Python extension --- diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 80c75954b..32eb2463e 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -476,6 +476,34 @@ during each working session. boolean IsVariable( in string theVarName ); ListOfStrings GetVariableNames(); + +/*! \brief Removing variable + + Remove variable with the specified name from the study with substitution of its value. + + \param theVarName Name of the variable. + \return Status of operation. +*/ + boolean RemoveVariable( in string theVarName ); + +/*! \brief Renaming variable + + Rename variable with the specified name within the study. + + \param theVarName Name of the variable. + \param theNewVarName New name for the variable. + \return Status of operation. +*/ + boolean RenameVariable( in string theVarName, in string theNewVarName ); + +/*! \brief Checking variable usage + + Check that variable is used in the study. + + \param theVarName Name of the variable. + \return Variable usage. +*/ + boolean IsVariableUsed( in string theVarName ); }; //========================================================================== diff --git a/src/SALOMEDS/SALOMEDS_Study.cxx b/src/SALOMEDS/SALOMEDS_Study.cxx index ade49db95..fce5d225a 100644 --- a/src/SALOMEDS/SALOMEDS_Study.cxx +++ b/src/SALOMEDS/SALOMEDS_Study.cxx @@ -820,6 +820,42 @@ vector SALOMEDS_Study::GetVariableNames() return aVector; } +bool SALOMEDS_Study::RemoveVariable(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->RemoveVariable(theVarName); + } + else + aResult = _corba_impl->RemoveVariable((char*)theVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::RenameVariable(const string& theVarName, const string& theNewVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->RenameVariable(theVarName, theNewVarName); + } + else + aResult = _corba_impl->RenameVariable((char*)theVarName.c_str(), (char*)theNewVarName.c_str()); + return aResult; +} + +bool SALOMEDS_Study::IsVariableUsed(const string& theVarName) +{ + bool aResult; + if (_isLocal) { + SALOMEDS::Locker lock; + aResult = _local_impl->IsVariableUsed(theVarName); + } + else + aResult = _corba_impl->IsVariableUsed((char*)theVarName.c_str()); + return aResult; +} + std::string SALOMEDS_Study::ConvertObjectToIOR(CORBA::Object_ptr theObject) { return _orb->object_to_string(theObject); diff --git a/src/SALOMEDS/SALOMEDS_Study.hxx b/src/SALOMEDS/SALOMEDS_Study.hxx index 2a0775ee4..3c885b64b 100644 --- a/src/SALOMEDS/SALOMEDS_Study.hxx +++ b/src/SALOMEDS/SALOMEDS_Study.hxx @@ -111,6 +111,10 @@ public: virtual bool IsVariable(const std::string& theVarName); virtual std::vector GetVariableNames(); + virtual bool RemoveVariable(const std::string& theVarName); + virtual bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName); + virtual bool IsVariableUsed(const std::string& theVarName); + std::string ConvertObjectToIOR(CORBA::Object_ptr theObject); CORBA::Object_ptr ConvertIORToObject(const std::string& theIOR); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 6d8ef34e5..22abc8a03 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -971,6 +971,36 @@ SALOMEDS::ListOfStrings* SALOMEDS_Study_i::GetVariableNames() return aResult._retn(); } +//============================================================================ +/*! Function : RemoveVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::RemoveVariable(const char* theVarName) +{ + return _impl->RemoveVariable(string(theVarName)); +} + +//============================================================================ +/*! Function : RenameVariable + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::RenameVariable(const char* theVarName, const char* theNewVarName) +{ + return _impl->RenameVariable(string(theVarName), string(theNewVarName)); +} + +//============================================================================ +/*! Function : IsVariableUsed + * Purpose : + */ +//============================================================================ +CORBA::Boolean SALOMEDS_Study_i::IsVariableUsed(const char* theVarName) +{ + return _impl->IsVariableUsed(string(theVarName)); +} + //============================================================================ /*! Function : GetDefaultScript * Purpose : diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index fa59532c6..8466582ee 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -316,6 +316,12 @@ public: virtual SALOMEDS::ListOfStrings* GetVariableNames(); + virtual CORBA::Boolean RemoveVariable(const char* theVarName); + + virtual CORBA::Boolean RenameVariable(const char* theVarName, const char* theNewVarName); + + virtual CORBA::Boolean IsVariableUsed(const char* theVarName); + virtual char* GetDefaultScript(const char* theModuleName, const char* theShift); virtual CORBA::Boolean DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished); diff --git a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx index d2f48e16e..2cb48ed4b 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_Study.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_Study.hxx @@ -107,6 +107,11 @@ public: virtual bool IsVariable(const std::string& theVarName) = 0; virtual std::vector GetVariableNames() = 0; + virtual bool RemoveVariable(const std::string& theVarName) = 0; + virtual bool RenameVariable(const std::string& theVarName, + const std::string& theNewVarName) = 0; + virtual bool IsVariableUsed(const std::string& theVarName) = 0; + }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx index 529620ef0..e266329c4 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.cxx @@ -80,6 +80,16 @@ void SALOMEDSImpl_GenericVariable::setType(const SALOMEDSImpl_GenericVariable::V _type = theType; } +//============================================================================ +/*! Function : setName + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_GenericVariable::setName(const std::string& theName) +{ + _name = theName; +} + //============================================================================ /*! Function : CheckLocked * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx index 5e4d6c669..c5166f217 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_GenericVariable.hxx @@ -48,6 +48,8 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_GenericVariable void setType(const VariableTypes theType); + void setName(const std::string& theName); + virtual void CheckLocked(); virtual void SetModifyFlag(); diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index c74298441..4af8f7ded 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1584,6 +1584,8 @@ double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName) if(aGVar != NULL ) if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast(aGVar)) return aSVar->getValue(); + + return 0; } //============================================================================ @@ -1656,6 +1658,157 @@ SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& return aResult; } +//============================================================================ +/*! Function : RemoveVariable + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName) +{ + SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName ); + if( !aVariable ) + return false; + + string aValue = aVariable->SaveToScript(); + ReplaceVariableAttribute( theVarName, aValue ); + + std::vector::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end(); + for( ; it != itEnd; it++ ) + { + SALOMEDSImpl_GenericVariable* aVariableRef = *it; + if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 ) + { + myNoteBookVars.erase( it ); + break; + } + } + + return true; +} + +//============================================================================ +/*! Function : RenameVariable + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& theNewVarName) +{ + SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName ); + if( !aVariable ) + return false; + + ReplaceVariableAttribute( theVarName, theNewVarName ); + + std::vector::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end(); + for( ; it != itEnd; it++ ) + { + SALOMEDSImpl_GenericVariable* aVariableRef = *it; + if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 ) + { + aVariableRef->setName( theNewVarName ); + break; + } + } + + return true; +} + +//============================================================================ +/*! Function : IsVariableUsed + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName) +{ + return FindVariableAttribute( theVarName ); +} + +//============================================================================ +/*! Function : FindVariableAttribute + * Purpose : + */ +//============================================================================ +bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName) +{ + 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 ) + { + 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 : ReplaceVariableAttribute + * Purpose : + */ +//============================================================================ +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 ); + } + } + } + } +} + //============================================================================ /*! Function : EnableUseCaseAutoFilling * Purpose : diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index 98bb6c52a..3ba54b936 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -276,6 +276,15 @@ public: SALOMEDSImpl_GenericVariable* GetVariable(const std::string& theName) const; + bool RemoveVariable(const std::string& theVarName); + + bool RenameVariable(const std::string& theVarName, const std::string& theNewVarName); + + bool IsVariableUsed(const std::string& theVarName); + + bool FindVariableAttribute(const std::string& theName); + void ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest); + //Returns a callback SALOMEDSImpl_Callback* GetCallback() { return _cb; }