From: rnv Date: Wed, 10 Dec 2008 14:44:01 +0000 (+0000) Subject: Fix for IPAL20762 DPE: notebook sortes variables after restoring from the study. X-Git-Tag: TG_DumpPython_Extension_4~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=63ad236877052c367f5d8a30ca128aa9f5d1dea6;p=modules%2Fkernel.git Fix for IPAL20762 DPE: notebook sortes variables after restoring from the study. --- diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index b81519815..d662e03c7 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -654,6 +654,7 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, string varValue; string varType; + string varIndex; for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){ // For each variable create HDF group @@ -670,6 +671,18 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl, hdf_dataset->CloseOnDisk(); hdf_dataset=0; //will be deleted by hdf_sco_group destructor + char buffer[256]; + sprintf(buffer,"%d",i); + varIndex= string(buffer); + name_len = (hdf_int32) varIndex.length(); + size[0] = name_len +1 ; + hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1); + hdf_dataset->CreateOnDisk(); + hdf_dataset->WriteOnDisk((char*)varIndex.c_str()); + hdf_dataset->CloseOnDisk(); + hdf_dataset=0; //will be deleted by hdf_sco_group destructor + + // Save Variable value varValue = aStudy->myNoteBookVars[i]->Save(); name_len = (hdf_int32) varValue.length(); @@ -1276,12 +1289,16 @@ void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) char aVarName[HDF_NAME_MAX_LEN+1]; char *currentVarType = 0; char *currentVarValue = 0; + char *currentVarIndex = 0; + int order = 0; //Open HDF group with notebook variables theGroup->OpenOnDisk(); //Get Nb of variables int aNbVars = theGroup->nInternalObjects(); + map aVarsMap; + for( int iVar=0;iVar < aNbVars;iVar++ ) { theGroup->InternalObjectIndentify(iVar,aVarName); hdf_object_type type = theGroup->InternalObjectType(aVarName); @@ -1299,6 +1316,20 @@ void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) new_dataset->CloseOnDisk(); new_dataset = 0; //will be deleted by hdf_sco_group destructor + //Read Order + if(new_group->ExistInternalObject("VARIABLE_INDEX")) { + new_dataset = new HDFdataset("VARIABLE_INDEX",new_group); + new_dataset->OpenOnDisk(); + currentVarIndex = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarIndex); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + order = atoi(currentVarIndex); + delete currentVarIndex; + } + else + order = iVar; + //Read Value new_dataset = new HDFdataset("VARIABLE_VALUE",new_group); new_dataset->OpenOnDisk(); @@ -1318,10 +1349,14 @@ void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup) SALOMEDSImpl_GenericVariable* aVariable = new SALOMEDSImpl_ScalarVariable(aVarType,string(aVarName)); aVariable->Load(string(currentVarValue)); + aVarsMap.insert(make_pair(order,aVariable)); delete currentVarValue; - - theStudy->AddVariable(aVariable); } } + + map::const_iterator it= aVarsMap.begin(); + for(;it!=aVarsMap.end();it++) + theStudy->AddVariable((*it).second); + theGroup->CloseOnDisk(); }