From: rnv Date: Fri, 29 Apr 2011 12:19:45 +0000 (+0000) Subject: Fix for the bug "IPAL22425 TC6.3.0: Wrong Dump of Study". X-Git-Tag: V6_3_0b1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8215f3bed448287082ff89fb5a8ff7edf88553b1;p=modules%2Fkernel.git Fix for the bug "IPAL22425 TC6.3.0: Wrong Dump of Study". --- diff --git a/src/SALOMEDS/SALOMEDS_IParameters.cxx b/src/SALOMEDS/SALOMEDS_IParameters.cxx index 54000374e..37f11d8d8 100644 --- a/src/SALOMEDS/SALOMEDS_IParameters.cxx +++ b/src/SALOMEDS/SALOMEDS_IParameters.cxx @@ -36,6 +36,9 @@ #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST" #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON" +#define _PT_ID_ "_PT_OBJECT_ID_" + + /*! Constructor */ @@ -144,6 +147,33 @@ std::vector SALOMEDS_IParameters::getAllParameterNames(const std::s return names; } + +std::string SALOMEDS_IParameters::getIdParameter(const std::string& entry) +{ + if(!_ap) return ""; + if(!_ap->IsSet(entry, PT_STRARRAY)) return ""; + std::vector v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i v; + if(!_ap->IsSet(entry, PT_STRARRAY)) { + append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries + _ap->SetStrArray(entry, v); + } + v = _ap->GetStrArray(entry); + v.push_back(_PT_ID_); + v.push_back(value); + _ap->SetStrArray(entry, v); +} + std::vector SALOMEDS_IParameters::getAllParameterValues(const std::string& entry) { std::vector v, values; diff --git a/src/SALOMEDS/SALOMEDS_IParameters.hxx b/src/SALOMEDS/SALOMEDS_IParameters.hxx index fe5860b62..30c10bd1f 100644 --- a/src/SALOMEDS/SALOMEDS_IParameters.hxx +++ b/src/SALOMEDS/SALOMEDS_IParameters.hxx @@ -77,6 +77,16 @@ public: */ virtual std::string getParameter(const std::string& entry, const std::string& parameterName); + /*! + Sets an id parameter value for the given entry. + */ + virtual void setIdParameter(const std::string& entry, const std::string& value); + + /*! + Gets an id parameter value for the given entry + */ + virtual std::string getIdParameter(const std::string& entry); + /*! Returns all parameter names of the given entry */ diff --git a/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx b/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx index 54eaf507f..6e6124fda 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx @@ -76,6 +76,16 @@ public: */ virtual std::string getParameter(const std::string& entry, const std::string& parameterName) = 0; + /*! + Sets an id parameter value for the given entry. + */ + virtual void setIdParameter(const std::string& entry, const std::string& value) = 0; + + /*! + Gets an id parameter value for the given entry + */ + virtual std::string getIdParameter(const std::string& entry) = 0; + /*! Returns all parameter names of the given entry */ diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx index f113c55a5..c99153962 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx @@ -31,6 +31,8 @@ #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST" #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON" +#define _PT_ID_ "_PT_OBJECT_ID_" + /*! Constructor */ @@ -126,6 +128,33 @@ std::string SALOMEDSImpl_IParameters::getParameter(const std::string& entry, con } +void SALOMEDSImpl_IParameters::setIdParameter(const std::string& entry, const std::string& value) +{ + if(!_ap) return; + std::vector v; + if(!_ap->IsSet(entry, PT_STRARRAY)) { + append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries + _ap->SetStrArray(entry, v); + } + v = _ap->GetStrArray(entry); + v.push_back(_PT_ID_); + v.push_back(value); + _ap->SetStrArray(entry, v); +} + + +std::string SALOMEDSImpl_IParameters::getIdParameter(const std::string& entry) +{ + if(!_ap) return ""; + if(!_ap->IsSet(entry, PT_STRARRAY)) return ""; + std::vector v = _ap->GetStrArray(entry); + int length = v.size(); + for(int i = 0; i SALOMEDSImpl_IParameters::getAllParameterNames(const std::string& entry) { std::vector v, names; @@ -347,9 +376,27 @@ std::string SALOMEDSImpl_IParameters::getDefaultScript(SALOMEDSImpl_Study* study SALOMEDSImpl_SObject so = study->FindObjectID(decodedEntry); std::string so_name(""); if(so) so_name = so.GetName(); - dump += shift + "# set up entry " + v[i] +" ("+so_name+")" + " parameters" + "\n"; - for(int j = 0; j < names.size() && j < values.size(); j++) - dump += shift + "ipar.setParameter(\"" + v[i] + "\", \"" + names[j] + "\", \"" + values[j] + "\")\n"; + + //Try to find id parameter + std::vector::iterator it = std::find(names.begin(), names.end(), _PT_ID_ ); + bool hasId = it != names.end(); + bool onlyId = hasId && names.size() == 1; + + if(!onlyId) { + dump += shift + "# set up entry " + v[i] +" ("+so_name+")" + " parameters" + "\n"; + if(hasId) { + int idIndex = std::distance(names.begin(), it); + dump += shift + "objId = " + values[idIndex] + "\n"; + } + + for(int j = 0; j < names.size() && j < values.size(); j++) { + if(names[j] == _PT_ID_) continue; + if(hasId) + dump += shift + "ipar.setParameter(" + "objId" + ", \"" + names[j] + "\", \"" + values[j] + "\")\n"; + else + dump += shift + "ipar.setParameter(\"" + v[i] + "\", \"" + names[j] + "\", \"" + values[j] + "\")\n"; + } + } } } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx index 712a676fc..9ed72eb9b 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx @@ -78,6 +78,16 @@ public: */ virtual std::string getParameter(const std::string& entry, const std::string& parameterName); + /*! + Sets an id parameter value for the given entry. + */ + virtual void setIdParameter(const std::string& entry, const std::string& value); + + /*! + Gets an id parameter value for the given entry + */ + virtual std::string getIdParameter(const std::string& entry); + /*! Returns all parameter names of the given entry */ diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 67c8ce04e..3ee056114 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1524,12 +1524,24 @@ void SALOMEDSImpl_Study::Modify() //============================================================================ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint) { - if (theSavePoint < 0) return NULL; + if (theSavePoint < -1) return NULL; SALOMEDSImpl_StudyBuilder* builder = NewBuilder(); SALOMEDSImpl_SObject so = FindComponent((char*)theID); if (!so) so = builder->NewComponent((char*)theID); SALOMEDSImpl_AttributeParameter* attParam = NULL; + if (theSavePoint == -1) { + int ctag = 1; + DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 ); + DF_Label prevPointLabel; + while ( !savePointLabel.IsNull() ) { + ctag++; + prevPointLabel = savePointLabel; + savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 ); + } + if ( !prevPointLabel.IsNull() ) + so = GetSObject( prevPointLabel ); + } if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ... DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 ); if ( !savePointLabel.IsNull() ) @@ -1558,7 +1570,7 @@ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const c const char* theModuleName, int theSavePoint) { - if(theSavePoint <= 0) return NULL; + if(theSavePoint < -1) return NULL; SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint); SALOMEDSImpl_SObject main_so = main_ap->GetSObject(); SALOMEDSImpl_AttributeParameter* par = NULL;