From: asl Date: Tue, 8 Dec 2009 12:55:08 +0000 (+0000) Subject: Loading of old-style Notebook data X-Git-Tag: PHASE_17_Part1_V3~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f939a2e6d037c34d3bde81805d6c9e76e837ca28;p=modules%2Fkernel.git Loading of old-style Notebook data --- diff --git a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx index 7ffd82dd7..8af0a4a27 100644 --- a/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyBuilder_i.cxx @@ -204,6 +204,12 @@ void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO, if(!isDone && _impl->IsError()) { THROW_SALOME_CORBA_EXCEPTION(_impl->GetErrorCode().c_str(),SALOME::BAD_PARAM); } + + SALOMEDS::Study_var aStudy = anSCO->GetStudy(); + SALOME::Notebook_var aNotebookVar = aStudy->GetNotebook(); + SALOME_Notebook* aNotebook = dynamic_cast( _default_POA()->reference_to_servant( aNotebookVar ) ); + if( aNotebook ) + aNotebook->RebuildLinks(); } diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx index ce1259c5b..b0a7f2234 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.cxx @@ -183,9 +183,52 @@ SALOMEDS::Study_ptr SALOMEDS_StudyManager_i::Open(const char* aUrl) if(!_name_service->Change_Directory("/Study")) MESSAGE( "Unable to access the study directory" ) else _name_service->Register(Study, CORBA::string_dup(aStudyImpl->Name().c_str())); - SALOMEDS::SComponent_ptr aNotebookComponent = Study->FindComponent( "NOTEBOOK" ); - SALOMEDS::StudyBuilder_var aBuilder = Study->NewBuilder(); - aBuilder->LoadWith( aNotebookComponent, SALOME_NotebookDriver::getInstance() ); + // Notebook creation + SALOME::Notebook_var aNotebookVar = Study->GetNotebook(); + SALOME_Notebook* aNotebook = dynamic_cast(_poa->reference_to_servant( aNotebookVar._retn() ) ); + + // Parsing of old style notebook data + list keys; + std::map > vars = _impl->GetOldStyleNotebookData(); + std::map >::const_iterator it = vars.begin(), last = vars.end(); + for( ; it!=last; it++ ) + keys.push_back( it->first ); + keys.sort(); + + list::const_iterator kit = keys.begin(), klast = keys.end(); + for( ; kit!=klast; kit++ ) + { + std::list::const_iterator lit = vars[*kit].begin(); + std::string aName = *lit; lit++; + std::string aType = *lit; lit++; + std::string aVal = *lit; + + aNotebook->ParseOldStyleParam( aName, aType, aVal ); + } + + //Old style object parsing: creation of dependencies in the notebook + SALOMEDS::SComponentIterator_var aCompIt = Study->NewComponentIterator(); + for( ; aCompIt->More(); aCompIt->Next() ) + { + SALOMEDS::SComponent_var aComp = aCompIt->Value(); + CORBA::String_var aCompDataType = aComp->ComponentDataType(); + std::string aCompName = aCompDataType.in(); + + SALOMEDS::ChildIterator_var anObjIt = Study->NewChildIterator( aComp._retn() ); + for( ; anObjIt->More(); anObjIt->Next() ) + { + SALOMEDS::SObject_var anObj = anObjIt->Value(); + std::string anEntry = anObj->GetID(); + + SALOMEDS::GenericAttribute_var anAttr; + if( anObj->FindAttribute( anAttr, "AttributeString" ) ) + { + SALOMEDS::AttributeString_var aStrAttr = SALOMEDS::AttributeString::_narrow( anAttr ); + std::string aData = aStrAttr->Value(); + aNotebook->ParseOldStyleObject( aCompName, anEntry, aData ); + } + } + } return Study._retn(); } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx index 3741a3cce..7799372ce 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.cxx @@ -32,7 +32,6 @@ #include "SALOMEDSImpl_Tool.hxx" #include "SALOMEDSImpl_SComponent.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" -#include #include "HDFOI.hxx" #include @@ -57,6 +56,7 @@ static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDF static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*); static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&, SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII); +static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup, std::map >& theVarsMap ); //============================================================================ /*! Function : SALOMEDSImpl_StudyManager @@ -124,6 +124,7 @@ SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl) // open the HDFFile HDFfile *hdf_file =0; HDFgroup *hdf_group_study_structure =0; + HDFgroup *hdf_notebook_vars = 0; char* aC_HDFUrl; string aHDFUrl; @@ -187,6 +188,14 @@ SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl) return NULL; } + //Read and create notebook variables + if( hdf_file->ExistInternalObject( "NOTEBOOK_VARIABLES" ) ) + { + hdf_notebook_vars = new HDFgroup( "NOTEBOOK_VARIABLES", hdf_file ); + ReadNoteBookVariables( Study, hdf_notebook_vars, myVariables ); + hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor + } + hdf_file->CloseOnDisk(); hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file); @@ -643,64 +652,6 @@ bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aStudyUrl, hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor } - /*ASL - //----------------------------------------------------------------------- - //5 - Write the NoteBook Variables - //----------------------------------------------------------------------- - - //5.1 Create group to store all note book variables - hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file); - hdf_notebook_vars->CreateOnDisk(); - - string varValue; - string varType; - string varIndex; - - for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){ - // For each variable create HDF group - hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars); - hdf_notebook_var->CreateOnDisk(); - - // Save Variable type - varType = aStudy->myNoteBookVars[i]->SaveType(); - name_len = (hdf_int32) varType.length(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)varType.c_str()); - 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(); - size[0] = name_len +1 ; - hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1); - hdf_dataset->CreateOnDisk(); - hdf_dataset->WriteOnDisk((char*)varValue.c_str()); - hdf_dataset->CloseOnDisk(); - hdf_dataset=0; //will be deleted by hdf_sco_group destructor - hdf_notebook_var->CloseOnDisk(); - hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor - } - hdf_notebook_vars->CloseOnDisk(); - hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor - - if (aLocked) aStudy->GetProperties()->SetLocked(true); - */ - //----------------------------------------------------------------------- //6 - Write the Study Properties //----------------------------------------------------------------------- @@ -1204,6 +1155,16 @@ SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject return SALOMEDSImpl_Study::SObject(aStartLabel); } +//============================================================================ +/*! Function : GetOldStyleNotebookData + * Purpose : + */ +//============================================================================ +std::map > SALOMEDSImpl_StudyManager::GetOldStyleNotebookData() const +{ + return myVariables; +} + //####################################################################################################### //# STATIC PRIVATE FUNCTIONS //####################################################################################################### @@ -1328,3 +1289,78 @@ static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so, Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII); } } + +void ReadNoteBookVariables( SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup, std::map >& theVarsMap ) +{ + theVarsMap.clear(); + if(!theGroup) + return; + + HDFgroup* new_group =0; + HDFdataset* new_dataset =0; + + 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(); + + for( int iVar = 0; iVar < aNbVars; iVar++ ) + { + theGroup->InternalObjectIndentify(iVar, aVarName); + hdf_object_type type = theGroup->InternalObjectType(aVarName); + if(type == HDF_GROUP) { + + //Read Variable + new_group = new HDFgroup(aVarName,theGroup); + new_group->OpenOnDisk(); + + //Read Type + new_dataset = new HDFdataset("VARIABLE_TYPE",new_group); + new_dataset->OpenOnDisk(); + currentVarType = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarType); + 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(); + currentVarValue = new char[new_dataset->GetSize()+1]; + new_dataset->ReadFromDisk(currentVarValue); + new_dataset->CloseOnDisk(); + new_dataset = 0; //will be deleted by hdf_sco_group destructor + + new_group->CloseOnDisk(); + new_group = 0; //will be deleted by hdf_sco_group destructor + + std::list var_data; + var_data.push_back( aVarName ); + var_data.push_back( currentVarType ); + var_data.push_back( currentVarValue ); + theVarsMap[order] = var_data; + } + } + + theGroup->CloseOnDisk(); +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx index b98a47364..44c3c0ed5 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyManager.hxx @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "DF_Application.hxx" #include "SALOMEDSImpl_Study.hxx" @@ -138,6 +140,11 @@ public: std::string GetErrorCode() { return _errorCode; } virtual bool IsError() { return _errorCode != ""; } + + std::map > GetOldStyleNotebookData() const; + +private: + std::map > myVariables; }; #endif