Back to index

salome-kernel  6.5.0
Defines | Functions
SALOMEDSImpl_StudyManager.cxx File Reference
#include "SALOMEDSImpl_StudyManager.hxx"
#include "DF_ChildIterator.hxx"
#include "HDFexplorer.hxx"
#include "Basics_Utils.hxx"
#include "SALOMEDSImpl_Attributes.hxx"
#include "SALOMEDSImpl_Tool.hxx"
#include "SALOMEDSImpl_SComponent.hxx"
#include "SALOMEDSImpl_GenericAttribute.hxx"
#include "SALOMEDSImpl_ScalarVariable.hxx"
#include <map>
#include "HDFOI.hxx"
#include <iostream>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define USE_CASE_LABEL_ID   "0:2"

Functions

static void SaveAttributes (const SALOMEDSImpl_SObject &aSO, HDFgroup *hdf_group_sobject)
 Function : SaveAttributes Purpose : Save attributes for object.
static void ReadAttributes (SALOMEDSImpl_Study *, const SALOMEDSImpl_SObject &, HDFdataset *)
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)

Define Documentation

#define USE_CASE_LABEL_ID   "0:2"

Definition at line 50 of file SALOMEDSImpl_StudyManager.cxx.


Function Documentation

static void BuildTree ( SALOMEDSImpl_Study *  theStudy,
HDFgroup *  hdf_current_group 
) [static]

Definition at line 1339 of file SALOMEDSImpl_StudyManager.cxx.

{
  hdf_current_group->OpenOnDisk();
  SALOMEDSImpl_SObject aSO;
  char* Entry = hdf_current_group->GetName();
  if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
    aSO = theStudy->CreateObjectID("0:1");
  }
  else {
    aSO = theStudy->CreateObjectID(Entry);
  }

  char name[HDF_NAME_MAX_LEN+1];
  int nbsons = hdf_current_group->nInternalObjects();
  for (int i=0; i<nbsons; i++) {
    hdf_current_group->InternalObjectIndentify(i,name);
    if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
    hdf_object_type type = hdf_current_group->InternalObjectType(name);

    if  (type == HDF_DATASET) {
      HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
      ReadAttributes(theStudy,aSO,new_dataset);
      new_dataset = 0; // will be deleted by father destructor

    }
    else if (type == HDF_GROUP)   {
      HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
      BuildTree (theStudy, new_group);
      new_group = 0; // will be deleted by father destructor
    }
  }
  hdf_current_group->CloseOnDisk();
}

Here is the call graph for this function:

static void ReadAttributes ( SALOMEDSImpl_Study *  theStudy,
const SALOMEDSImpl_SObject &  aSO,
HDFdataset *  hdf_dataset 
) [static]

Definition at line 1306 of file SALOMEDSImpl_StudyManager.cxx.

{
  hdf_dataset->OpenOnDisk();

  DF_Attribute* anAttr = NULL;
  char* current_string = new char[hdf_dataset->GetSize()+1];
  hdf_dataset->ReadFromDisk(current_string);
  //cout << "Reading attr type = " << hdf_dataset->GetName() << "  SO = " << aSO.GetID() << endl;
  if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
    anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
  } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
             !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
    theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
    delete [] (current_string);
    hdf_dataset->CloseOnDisk();
    return;
  } else {
    anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
  }
  
  if (anAttr) {
    anAttr->Load(current_string);
  }
  
  delete [] (current_string);
  hdf_dataset->CloseOnDisk();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ReadNoteBookVariables ( SALOMEDSImpl_Study *  theStudy,
HDFgroup *  theGroup 
) [static]

Definition at line 1398 of file SALOMEDSImpl_StudyManager.cxx.

{
  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();

  std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;

  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
      
      SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
        SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
      delete [] currentVarType;

      //Create variable and add it in the study
      SALOMEDSImpl_GenericVariable* aVariable = 
        new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
      aVariable->Load(std::string(currentVarValue));
         aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
      delete [] currentVarValue;
       }
  }
  
  std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
  for(;it!=aVarsMap.end();it++)
    theStudy->AddVariable((*it).second);
  
  theGroup->CloseOnDisk();
}
static void SaveAttributes ( const SALOMEDSImpl_SObject &  SO,
HDFgroup *  hdf_group_sobject 
) [static]

Function : SaveAttributes Purpose : Save attributes for object.

Definition at line 1282 of file SALOMEDSImpl_StudyManager.cxx.

{
  hdf_size size[1];
  std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
  DF_Attribute* anAttr = NULL;
  for(int i = 0, len = attrList.size(); i<len; i++) {
    anAttr = attrList[i];
    //The following attributes are not supposed to be written to the file
    std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
    if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
    std::string aSaveStr =anAttr->Save();
    //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
    size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
    HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
    hdf_dataset->CreateOnDisk();
    hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
    hdf_dataset->CloseOnDisk();
    hdf_dataset=0; //will be deleted by hdf_sco_group destructor
  }
}

Here is the call graph for this function:

static void Translate_IOR_to_persistentID ( const SALOMEDSImpl_SObject &  so,
SALOMEDSImpl_Driver *  engine,
bool  isMultiFile,
bool  isASCII 
) [static]

Definition at line 1377 of file SALOMEDSImpl_StudyManager.cxx.

{
  DF_ChildIterator itchild(so.GetLabel());
  std::string ior_string,  persistent_string, curid;

  for (; itchild.More(); itchild.Next()) {
    SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
    SALOMEDSImpl_AttributeIOR* IOR = NULL;
    if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
      ior_string = IOR->Value();

      persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
      SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
    }
    Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
  }
}

Here is the call graph for this function: