- TDF_Label Lab;
- CORBA::String_var aString = theSComponent->GetID();
- TDF_Tool::Label(_doc->GetData(),const_cast<char*>(aString.in()),Lab);
-
- //Find the current Url of the study
- Handle(TDF_Attribute) Att;
- if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
- if(CORBA::is_nil(theDriver))
- return;
-
- int aLocked = theSComponent->GetStudy()->GetProperties()->IsLocked();
- if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(false);
-
- // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
- if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
- if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
- return;
- }
- DefineComponentInstance (theSComponent,theDriver);
-
- TCollection_AsciiString aHDFPath(Handle(TDataStd_Comment)::DownCast(Att)->Get());
-
- bool isASCII = false;
- std::ostringstream anURLStream;
- if(HDFascii::isASCII(aHDFPath.ToCString())){
- isASCII = true;
- auto_ptr<char> aResultPath(HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString()));
- anURLStream<<aResultPath.get()<<"hdf_from_ascii.hdf";
- } else {
- anURLStream<<aHDFPath.ToCString();
- }
- std::string aHDFUrl = anURLStream.str();
-
- //Open the Study HDF file
- auto_ptr<HDFfile> hdf_file(new HDFfile(const_cast<char*>(aHDFUrl.c_str())));
-
- char aMultifileState[2];
- char ASCIIfileState[2];
- try {
- CORBA::String_var scoid = theSComponent->GetID();
- hdf_file->OpenOnDisk(HDF_RDONLY);
- HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file.get());
- hdf_group->OpenOnDisk();
- HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
- hdf_sco_group->OpenOnDisk();
-
- SALOMEDS::TMPFile_var aStreamFile;
- if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
- HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
- hdf_dataset->OpenOnDisk();
- int aStreamSize = hdf_dataset->GetSize();
- unsigned char* aBuffer = new unsigned char[aStreamSize];
- if(aBuffer == NULL)
- throw HDFexception("Unable to open dataset FILE_STREAM");
- hdf_dataset->ReadFromDisk(aBuffer);
- aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
- hdf_dataset->CloseOnDisk();
- hdf_dataset = 0;
- } else
- aStreamFile = new SALOMEDS::TMPFile(0);
-
- HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
- multifile_hdf_dataset->OpenOnDisk();
- multifile_hdf_dataset->ReadFromDisk(aMultifileState);
-
- HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
- ascii_hdf_dataset->OpenOnDisk();
- ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
-
- // set path without file name from URL
- std::string aDir(aHDFPath.ToCString());
- aDir.substr(0,aDir.find('/'));
-
- CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
- theDriver->LoadASCII(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M'):
- theDriver->Load(theSComponent, aStreamFile.in(), aDir.c_str(), aMultifileState[0]=='M');
- if(!aResult) {
- RemoveAttribute( theSComponent, "AttributeIOR" );
- if (isASCII) {
- SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
- aFilesToRemove->length(1);
- std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
- aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
- SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
- }
- MESSAGE("Can't load component");
- THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
- }
-
- multifile_hdf_dataset->CloseOnDisk();
- multifile_hdf_dataset = 0;
- ascii_hdf_dataset->CloseOnDisk();
- ascii_hdf_dataset = 0;
- hdf_sco_group->CloseOnDisk();
- hdf_sco_group = 0;
- hdf_group->CloseOnDisk();
- hdf_group = 0;
- hdf_file->CloseOnDisk();
-
- if (isASCII) {
- SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
- aFilesToRemove->length(1);
- std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
- aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
- SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
- }
- }
- catch (HDFexception) {
- INFOS("No persistent file Name");
- if (isASCII) {
- SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
- aFilesToRemove->length(1);
- std::string aDir = SALOMEDS_Tool::GetDirFromPath(aHDFUrl);
- aFilesToRemove[0] = CORBA::string_dup(&aHDFUrl[strlen(aDir.c_str())]);
- SALOMEDS_Tool::RemoveTemporaryFiles(aDir,aFilesToRemove,true);
- }
- if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
- THROW_SALOME_CORBA_EXCEPTION("No persistent file Name found",SALOME::BAD_PARAM);
- }
-
- try {
- Translate_persistentID_to_IOR(Lab,theDriver,GetORB(),_study, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
- } catch (SALOME::SALOME_Exception) {
- INFOS("Can't translate PersRef to IOR");
- if (aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
- THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
- // throw HDFexception("Unable to load component data");
- }
- if(aLocked)
- theSComponent->GetStudy()->GetProperties()->SetLocked(true);
- } else
- MESSAGE("No persistent file Name");