1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_StudyManager.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_StudyManager.hxx"
29 #include "DF_ChildIterator.hxx"
30 #include "HDFexplorer.hxx"
31 #include "Basics_Utils.hxx"
33 #include "SALOMEDSImpl_Attributes.hxx"
34 #include "SALOMEDSImpl_Tool.hxx"
35 #include "SALOMEDSImpl_SComponent.hxx"
36 #include "SALOMEDSImpl_GenericAttribute.hxx"
37 #include "SALOMEDSImpl_ScalarVariable.hxx"
49 //Warning undef of Ascii Winwows define
54 #define USE_CASE_LABEL_ID "0:2"
56 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
57 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
58 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
59 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
60 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
61 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
63 //============================================================================
64 /*! Function : SALOMEDSImpl_StudyManager
65 * Purpose : SALOMEDSImpl_StudyManager constructor
67 //============================================================================
68 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
71 _appli = new DF_Application();
73 _clipboard = _appli->NewDocument("SALOME_STUDY");
76 //============================================================================
77 /*! Function : ~SALOMEDSImpl_StudyManager
78 * Purpose : SALOMEDSImpl_StudyManager destructor
80 //============================================================================
81 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
83 _appli->Close(_clipboard);
84 // Destroy application
89 //============================================================================
90 /*! Function : NewStudy
91 * Purpose : Create a New Study of name study_name
93 //==================================================T==========================
94 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const std::string& study_name)
98 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
100 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
103 Study->StudyId( _IDcounter );
105 // set Study properties
106 SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
108 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
109 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
110 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
111 mn, hh, day, month, year);
112 aProp->SetCreationMode(1); //"from scratch"
117 //============================================================================
119 * Purpose : Open a Study from it's persistent reference
121 //============================================================================
122 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const std::string& aUrl)
124 // Set "C" locale temporarily to avoid possible localization problems
125 Kernel_Utils::Localizer loc;
130 HDFfile *hdf_file =0;
131 HDFgroup *hdf_group_study_structure =0;
132 HDFgroup *hdf_notebook_vars = 0;
136 bool isASCII = false;
137 if (HDFascii::isASCII(aUrl.c_str())) {
139 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
142 aC_HDFUrl = new char[strlen(aResultPath) + 19];
143 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
144 delete [] (aResultPath);
152 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
154 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
159 eStr = new char[strlen(aUrl.c_str())+17];
160 sprintf(eStr,"Can't open file %s",aUrl.c_str());
162 _errorCode = std::string(eStr);
166 // Temporary aStudyUrl in place of study name
167 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
169 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
172 Study->StudyId( _IDcounter );
174 // Assign the value of the URL in the study object
177 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
179 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
180 _errorCode = "Study is empty";
184 //Create the Structure of the Document
185 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
188 BuildTree (Study, hdf_group_study_structure);
192 char *eStr = new char [strlen(aUrl.c_str())+17];
193 sprintf(eStr,"Can't open file %s", aUrl.c_str());
194 _errorCode = std::string(eStr);
198 //Read and create notebook variables
199 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
200 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
201 ReadNoteBookVariables(Study,hdf_notebook_vars);
202 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
205 hdf_file->CloseOnDisk();
206 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
209 std::vector<std::string> aFilesToRemove;
210 aFilesToRemove.push_back("hdf_from_ascii.hdf");
211 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
214 delete hdf_file; // all related hdf objects will be deleted
221 //============================================================================
223 * Purpose : Close a study.
224 * If the study hasn't been saved, ask the user to confirm the
225 * close action without saving
228 //============================================================================
229 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
234 _errorCode = "Study is null";
239 DF_Document* doc=aStudy->GetDocument();
243 //============================================================================
245 * Purpose : Save a Study to it's persistent reference
247 //============================================================================
248 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
249 SALOMEDSImpl_DriverFactory* aFactory,
254 std::string url = aStudy->URL();
256 _errorCode = "No path specified to save the study. Nothing done";
260 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
266 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
267 SALOMEDSImpl_DriverFactory* aFactory,
272 std::string url = aStudy->URL();
274 _errorCode = "No path specified to save the study. Nothing done";
278 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
284 //=============================================================================
285 /*! Function : SaveAs
286 * Purpose : Save a study to the persistent reference aUrl
288 //============================================================================
289 bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl,
290 SALOMEDSImpl_Study* aStudy,
291 SALOMEDSImpl_DriverFactory* aFactory,
295 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
298 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl,
299 SALOMEDSImpl_Study* aStudy,
300 SALOMEDSImpl_DriverFactory* aFactory,
304 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
307 //============================================================================
308 /*! Function : GetOpenStudies
309 * Purpose : Get name list of open studies in the session
311 //============================================================================
312 std::vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
315 std::vector<SALOMEDSImpl_Study*> aList;
317 int nbDocs = _appli->NbDocuments();
320 _errorCode = "No active study in this session";
324 SALOMEDSImpl_Study* aStudy;
325 std::vector<int> ids = _appli->GetDocumentIDs();
326 for (int i = 0, len = ids.size(); i<len; i++) {
327 DF_Document* D = _appli->GetDocument(ids[i]);
328 if(D == _clipboard) continue;
329 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
330 if(!aStudy) continue;
331 aList.push_back(aStudy);
338 //============================================================================
339 /*! Function : GetStudyByName
340 * Purpose : Get a study from its name
342 //============================================================================
343 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
344 (const std::string& aStudyName)
347 int nbDocs = _appli->NbDocuments();
350 _errorCode = "No active study in this session";
354 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
355 for (int i = 0, len = studies.size(); i<len; i++) {
356 if (studies[i]->Name() == aStudyName) return studies[i];
360 _errorCode = std::string("Found no study with the name ") + aStudyName;
364 //============================================================================
365 /*! Function : GetStudyByID
366 * Purpose : Get a study from its ID
368 //============================================================================
369 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
372 int nbDocs = _appli->NbDocuments();
375 _errorCode = "No active study in this session";
379 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
380 for (int i = 0, len = studies.size(); i<len; i++) {
381 if (studies[i]->StudyId() == aStudyID) return studies[i];
385 _errorCode = "Found no study with the given ID";
389 //=============================================================================
390 /*! Function : _SaveProperties
391 * Purpose : save the study properties in HDF file
393 //============================================================================
394 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
399 HDFdataset *hdf_dataset = 0;
403 // add modifications list (user and date of save)
404 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
405 int aLocked = aProp->IsLocked();
406 if (aLocked) aProp->SetLocked(false);
408 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
409 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
410 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
411 mn, hh, day, month, year);
413 if (aLocked) aProp->SetLocked(true);
415 std::vector<std::string> aNames;
416 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
418 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
420 int aLength = 0, anIndex, i;
421 for(i=1; i<=aNames.size(); i++)
422 aLength += aNames[i-1].size() + 1;
424 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
425 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
428 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
430 aLength = aNames.size();
432 for(anIndex = 0; anIndex<aLength; anIndex++) {
433 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
434 (int)(aMinutes[anIndex]),
435 (int)(aHours[anIndex]),
436 (int)(aDays[anIndex]),
437 (int)(aMonths[anIndex]),
438 (int)(aYears[anIndex]),
439 aNames[anIndex].c_str());
440 a = strlen(aProperty);
445 name_len = (hdf_int32) a;
446 size[0] = name_len + 1 ;
447 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
448 hdf_dataset->CreateOnDisk();
449 hdf_dataset->WriteOnDisk(aProperty);
450 hdf_dataset->CloseOnDisk();
451 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
454 aProp->SetModified(0);
458 //=============================================================================
459 /*! Function : _SaveAs
460 * Purpose : save the study in HDF file
462 //============================================================================
463 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl,
464 SALOMEDSImpl_Study* aStudy,
465 SALOMEDSImpl_DriverFactory* aFactory,
469 // Set "C" locale temporarily to avoid possible localization problems
470 Kernel_Utils::Localizer loc;
472 // HDF File will be composed of differents part :
473 // * For each ComponentDataType, all data created by the component
474 // Informations in data group hdf_group_datacomponent
475 // * Study Structure -> Exactly what is contained in Document
476 // Informations in data group hdf_group_study_structure
481 HDFgroup *hdf_group_study_structure =0;
482 HDFgroup *hdf_sco_group =0;
483 HDFgroup *hdf_sco_group2 =0;
484 HDFgroup *hdf_notebook_vars =0;
485 HDFgroup *hdf_notebook_var = 0;
487 HDFgroup *hdf_group_datacomponent =0;
488 HDFdataset *hdf_dataset =0;
490 hdf_int32 name_len = 0;
491 std::string component_name;
494 _errorCode = "Study is null";
498 //Create a temporary url to which the study is saved
499 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
501 int aLocked = aStudy->GetProperties()->IsLocked();
502 if (aLocked) aStudy->GetProperties()->SetLocked(false);
504 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
505 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
509 // mpv 15.12.2003: for saving components we have to load all data from all modules
510 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
511 for (; itcomponent1.More(); itcomponent1.Next())
513 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
514 // if there is an associated Engine call its method for saving
515 std::string IOREngine;
517 if (!sco.ComponentIOR(IOREngine)) {
518 std::string aCompType = sco.GetComment();
519 if (!aCompType.empty()) {
521 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
522 aMapTypeDriver[aCompType] = aDriver;
524 if (aDriver != NULL) {
525 if(!SB->LoadWith(sco, aDriver)) {
526 _errorCode = SB->GetErrorCode();
533 _errorCode = "Can not restore information to resave it";
538 std::string anOldName = aStudy->Name();
539 aStudy->URL(aStudyUrl);
541 // To change for Save
542 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
543 hdf_file = new HDFfile((char*)aUrl.c_str());
544 hdf_file->CreateOnDisk();
546 //-----------------------------------------------------------------------
547 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
548 //-----------------------------------------------------------------------
549 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
550 hdf_group_datacomponent->CreateOnDisk();
552 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
554 for (; itcomponent.More(); itcomponent.Next())
556 SALOMEDSImpl_SComponent sco = itcomponent.Value();
558 std::string scoid = sco.GetID();
559 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
560 hdf_sco_group->CreateOnDisk();
562 std::string componentDataType = sco.ComponentDataType();
563 std::string IOREngine;
564 if (sco.ComponentIOR(IOREngine))
566 SALOMEDSImpl_Driver* Engine = NULL;
567 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
568 // we have found the associated engine to write the data
569 Engine = aMapTypeDriver[componentDataType];
572 Engine = aFactory->GetDriverByIOR(IOREngine);
577 SALOMEDSImpl_TMPFile* aStream = NULL;
580 if (theASCII) aStream = Engine->SaveASCII(sco,
581 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
584 else aStream = Engine->Save(sco,
585 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
588 HDFdataset *hdf_dataset;
589 hdf_size aHDFSize[1];
590 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
592 aHDFSize[0] = length;
594 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
595 hdf_dataset->CreateOnDisk();
596 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
597 hdf_dataset->CloseOnDisk();
600 if(aStream) delete aStream;
602 // store multifile state
604 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
605 hdf_dataset->CreateOnDisk();
606 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
607 hdf_dataset->CloseOnDisk();
608 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
611 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
612 hdf_dataset->CreateOnDisk();
613 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
614 hdf_dataset->CloseOnDisk();
615 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
616 // Creation of the persistance reference attribute
617 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
620 hdf_sco_group->CloseOnDisk();
621 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
623 hdf_group_datacomponent->CloseOnDisk();
624 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
626 //-----------------------------------------------------------------------
627 //3 - Write the Study Structure
628 //-----------------------------------------------------------------------
629 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
630 hdf_group_study_structure->CreateOnDisk();
631 // save component attributes
632 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
633 for (; itcomp.More(); itcomp.Next())
635 SALOMEDSImpl_SComponent SC = itcomp.Value();
636 std::string scid = SC.GetID();
637 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
638 hdf_sco_group2->CreateOnDisk();
639 SaveAttributes(SC, hdf_sco_group2);
640 // ComponentDataType treatment
641 component_name = SC.ComponentDataType();
642 name_len = (hdf_int32)component_name.length();
643 size[0] = name_len +1 ;
644 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
645 hdf_dataset->CreateOnDisk();
646 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
647 hdf_dataset->CloseOnDisk();
648 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
649 Impl_SaveObject(SC, hdf_sco_group2);
650 hdf_sco_group2->CloseOnDisk();
651 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
653 //-----------------------------------------------------------------------
654 //4 - Write the Study UseCases Structure
655 //-----------------------------------------------------------------------
656 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
658 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
659 hdf_soo_group->CreateOnDisk();
660 SaveAttributes(aSO, hdf_soo_group);
661 Impl_SaveObject(aSO, hdf_soo_group);
662 hdf_soo_group->CloseOnDisk();
663 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
665 //-----------------------------------------------------------------------
666 //5 - Write the NoteBook Variables
667 //-----------------------------------------------------------------------
669 //5.1 Create group to store all note book variables
670 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
671 hdf_notebook_vars->CreateOnDisk();
673 std::string varValue;
675 std::string varIndex;
677 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
678 // For each variable create HDF group
679 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
680 hdf_notebook_var->CreateOnDisk();
682 // Save Variable type
683 varType = aStudy->myNoteBookVars[i]->SaveType();
684 name_len = (hdf_int32) varType.length();
685 size[0] = name_len +1 ;
686 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
687 hdf_dataset->CreateOnDisk();
688 hdf_dataset->WriteOnDisk((char*)varType.c_str());
689 hdf_dataset->CloseOnDisk();
690 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
693 sprintf(buffer,"%d",i);
694 varIndex= std::string(buffer);
695 name_len = (hdf_int32) varIndex.length();
696 size[0] = name_len +1 ;
697 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
698 hdf_dataset->CreateOnDisk();
699 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
700 hdf_dataset->CloseOnDisk();
701 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
704 // Save Variable value
705 varValue = aStudy->myNoteBookVars[i]->Save();
706 name_len = (hdf_int32) varValue.length();
707 size[0] = name_len +1 ;
708 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
709 hdf_dataset->CreateOnDisk();
710 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
711 hdf_dataset->CloseOnDisk();
712 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
713 hdf_notebook_var->CloseOnDisk();
714 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
716 hdf_notebook_vars->CloseOnDisk();
717 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
719 if (aLocked) aStudy->GetProperties()->SetLocked(true);
720 //-----------------------------------------------------------------------
721 //6 - Write the Study Properties
722 //-----------------------------------------------------------------------
723 std::string study_name = aStudy->Name();
724 name_len = (hdf_int32) study_name.size();
725 size[0] = name_len +1 ;
726 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
727 hdf_dataset->CreateOnDisk();
728 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
729 hdf_dataset->CloseOnDisk();
730 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
732 Impl_SaveProperties(aStudy, hdf_group_study_structure);
733 hdf_group_study_structure->CloseOnDisk();
734 hdf_file->CloseOnDisk();
736 aStudy->IsSaved(true);
737 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
738 delete hdf_file; // recursively deletes all hdf objects...
742 _errorCode = "HDFexception ! ";
745 catch(std::exception& exc)
747 _errorCode = const_cast<char*>(exc.what());
752 _errorCode = "Unknown exception ! ";
755 if (theASCII) { // save file in ASCII format
756 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
759 //Now it's necessary to copy files from the temporary directory to the user defined directory.
761 // The easiest way to get a list of file in the temporary directory
763 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
764 std::string aTmpFile = aTmpFileDir +"files";
765 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
768 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
770 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
772 system(aCmd.c_str());
774 // Iterate and move files in the temporary directory
775 FILE* fp = fopen(aTmpFile.c_str(), "rb");
776 if(!fp) return false;
777 char* buffer = new char[2047];
779 if((fgets(buffer, 2046, fp)) == NULL) break;
780 size_t aLen = strlen(buffer);
781 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
783 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
785 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
787 system(aCmd.c_str());
795 DeleteFileA(aTmpFile.c_str());
797 unlink(aTmpFile.c_str());
801 RemoveDirectoryA(aTmpFileDir.c_str());
802 RemoveDirectoryA(aStudyTmpDir.c_str());
804 rmdir(aTmpFileDir.c_str());
805 rmdir(aStudyTmpDir.c_str());
811 //============================================================================
812 /*! Function : Impl_SaveObject
815 //============================================================================
816 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
817 HDFgroup *hdf_group_datatype)
821 // Write in group hdf_group_datatype all informations of SObject SC
822 // Iterative function to parse all SObjects under a SComponent
824 HDFgroup *hdf_group_sobject = 0;
826 DF_ChildIterator itchild(SC.GetLabel());
827 for (; itchild.More(); itchild.Next())
830 // mpv: don't save empty labels
831 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
832 if (attr.size() == 0) { //No attributes on the label
833 DF_ChildIterator subchild(itchild.Value());
834 if (!subchild.More()) {
837 subchild.Init(itchild.Value(), true);
839 for (; subchild.More() && anEmpty; subchild.Next()) {
840 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
842 anEmpty = false; //There are attributes on the child label
846 if (anEmpty) continue;
849 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
851 std::string scoid = SO.GetID();
852 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
853 hdf_group_sobject->CreateOnDisk();
854 SaveAttributes(SO, hdf_group_sobject);
855 Impl_SaveObject(SO, hdf_group_sobject);
856 hdf_group_sobject->CloseOnDisk();
857 hdf_group_sobject =0; // will be deleted by father hdf object destructor
863 //============================================================================
864 /*! Function : Impl_SubstituteSlash
867 //============================================================================
868 std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl)
872 std::string theUrl(aUrl);
873 for(int i = 0; i<theUrl.size(); i++)
874 if(theUrl[i] == '/') theUrl[i] = ':';
878 //============================================================================
879 /*! Function : GetDocumentOfStudy
882 //============================================================================
883 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
886 return theStudy->_doc;
889 //============================================================================
890 /*! Function : CanCopy
893 //============================================================================
894 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
895 SALOMEDSImpl_Driver* theEngine)
898 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
899 if (!aComponent) return false;
900 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
901 std::string IOREngine;
902 if (!aComponent.ComponentIOR(IOREngine)) return false;
903 if (theEngine == NULL) return false;
904 return theEngine->CanCopy(theObject);
907 //============================================================================
908 /*! Function : CopyLabel
911 //============================================================================
912 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
913 SALOMEDSImpl_Driver* theEngine,
914 const int theSourceStartDepth,
915 const DF_Label& theSource,
916 const DF_Label& theDestinationMain)
921 DF_Label aTargetLabel = theDestinationMain;
922 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
923 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
924 DF_Label aSourceLabel = theSource;
925 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
926 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
927 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
929 // iterate attributes
930 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
931 for(int i = 0, len = attrList.size(); i<len; i++) {
932 DF_Attribute* anAttr = attrList[i];
933 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
934 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
935 if (type == std::string("AttributeTarget")) continue; // and target attribute
937 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
938 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
939 std::string anEntry = aReferenced.Entry();
940 // store the value of name attribute of referenced label
941 SALOMEDSImpl_AttributeName* aNameAttribute;
942 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
944 anEntry += aNameAttribute->Value();
946 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
950 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
951 std::string anEntry = theSource.Entry();
952 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
955 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
956 std::string aResStr("");
957 for(a = 0; a < aLen; a++) {
958 aResStr += (char)(aStream->Get(a));
961 if(aStream) delete aStream;
963 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
964 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
967 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
968 aTargetLabel.AddAttribute(aNewAttribute);
969 anAttr->Paste(aNewAttribute);
975 //============================================================================
979 //============================================================================
980 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
981 SALOMEDSImpl_Driver* theEngine)
985 // adoptation for alliances datamodel copy: without IOR attributes !!!
986 bool aStructureOnly; // copy only SObjects and attributes without component help
987 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
989 // get component-engine
990 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
992 // CAF document of current study usage
993 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
995 _errorCode = "Document is null";
999 //Clear the clipboard
1000 _clipboard->Main().Root().ForgetAllAttributes(true);
1001 _appli->Close(_clipboard);
1002 _clipboard = _appli->NewDocument("SALOME_STUDY");
1004 // set component data type to the name attribute of root label
1005 if (!aStructureOnly) {
1006 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
1007 theEngine->ComponentDataType());
1009 // set to the Root label integer attribute: study id
1010 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1011 // iterate all theObject's label children
1012 DF_Label aStartLabel = theObject.GetLabel();
1013 int aSourceStartDepth = aStartLabel.Depth();
1015 // copy main source label
1016 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1018 // copy all subchildren of the main source label (all levels)
1019 DF_ChildIterator anIterator(aStartLabel, true);
1020 for(; anIterator.More(); anIterator.Next()) {
1021 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1026 //============================================================================
1027 /*! Function : CanPaste
1030 //============================================================================
1031 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1032 SALOMEDSImpl_Driver* theEngine)
1037 _errorCode = "Clipboard is null";
1041 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1042 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1043 _errorCode = "Clipboard has no component type";
1046 SALOMEDSImpl_AttributeInteger* anObjID;
1047 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1048 _errorCode = "Clipboard has no object id";
1051 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1053 _errorCode = "Object doesn't belong to component";
1057 std::string IOREngine;
1058 if (!aComponent.ComponentIOR(IOREngine)) {
1059 _errorCode = "component has no IOR";
1062 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1065 //============================================================================
1066 /*! Function : PasteLabel
1069 //============================================================================
1070 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1071 SALOMEDSImpl_Driver* theEngine,
1072 const DF_Label& theSource,
1073 const DF_Label& theDestinationStart,
1074 const int theCopiedStudyID,
1075 const bool isFirstElement)
1079 // get corresponding source, target and auxiliary labels
1080 DF_Label aTargetLabel = theDestinationStart;
1082 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1084 if (!isFirstElement) {
1085 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1086 DF_Label aSourceLabel = theSource;
1087 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1088 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1089 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1093 // check auxiliary label for TMPFile => IOR
1094 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1095 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1096 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1097 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1098 std::string aCompName = aComponentName->Value();
1100 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1101 std::string aTMPStr = aNameAttribute->Value();
1102 int aLen = aTMPStr.size();
1103 unsigned char* aStream = NULL;
1105 aStream = new unsigned char[aLen+10];
1106 for(a = 0; a < aLen; a++) {
1107 aStream[a] = aTMPStr[a];
1111 std::string anEntry = aTargetLabel.Entry();
1112 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1114 if (isFirstElement) {
1115 std::string aDestEntry = theEngine->PasteInto(aStream,
1118 aPastedSO.GetFatherComponent());
1119 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1121 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1123 if(aStream != NULL) delete []aStream;
1127 // iterate attributes
1128 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1129 for(int i = 0, len = attrList.size(); i<len; i++) {
1130 DF_Attribute* anAttr = attrList[i];
1131 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1132 aTargetLabel.ForgetAttribute(anAttr->ID());
1134 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1135 aTargetLabel.AddAttribute(aNewAttribute);
1136 anAttr->Paste(aNewAttribute);
1139 // check auxiliary label for Comment => reference or name attribute of the referenced object
1140 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1141 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1142 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1143 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1144 char* aNameStart = strchr(anEntry, ' ');
1149 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1150 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1151 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1152 // target attributes structure support
1153 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1155 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1156 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1161 return aTargetLabel;
1164 //============================================================================
1165 /*! Function : Paste
1168 //============================================================================
1169 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1170 SALOMEDSImpl_Driver* theEngine)
1174 SALOMEDSImpl_SObject so;
1175 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1177 // if study is locked, then paste can't be done
1178 if (aStudy->GetProperties()->IsLocked()) {
1179 _errorCode = "LockProtection";
1180 throw LockProtection("LockProtection");
1183 // if there is no component name, then paste only SObjects and attributes: without component help
1184 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1185 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1187 // get copied study ID
1188 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1189 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1190 _errorCode = "No study ID was found";
1193 int aCStudyID = aStudyIDAttribute->Value();
1195 // CAF document of current study usage
1196 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1198 _errorCode = "Document is null";
1202 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1204 // fill root inserted SObject
1205 DF_Label aStartLabel;
1206 if (aStructureOnly) {
1207 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1208 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1210 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1211 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1214 // paste all sublebels
1215 DF_ChildIterator anIterator(_clipboard->Main(), true);
1216 for(; anIterator.More(); anIterator.Next()) {
1217 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1220 return SALOMEDSImpl_Study::SObject(aStartLabel);
1223 //#######################################################################################################
1224 //# STATIC PRIVATE FUNCTIONS
1225 //#######################################################################################################
1227 //============================================================================
1228 /*! Function : SaveAttributes
1229 * Purpose : Save attributes for object
1231 //============================================================================
1232 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1235 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1236 DF_Attribute* anAttr = NULL;
1237 for(int i = 0, len = attrList.size(); i<len; i++) {
1238 anAttr = attrList[i];
1239 //The following attributes are not supposed to be written to the file
1240 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1241 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
1242 std::string aSaveStr =anAttr->Save();
1243 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1244 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1245 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1246 hdf_dataset->CreateOnDisk();
1247 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1248 hdf_dataset->CloseOnDisk();
1249 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1253 //===========================================================================
1254 //Function : ReadAttributes
1255 //===========================================================================
1256 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1257 const SALOMEDSImpl_SObject& aSO,
1258 HDFdataset* hdf_dataset)
1260 hdf_dataset->OpenOnDisk();
1262 DF_Attribute* anAttr = NULL;
1263 char* current_string = new char[hdf_dataset->GetSize()+1];
1264 hdf_dataset->ReadFromDisk(current_string);
1265 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1266 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1267 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1268 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1269 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1270 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1271 delete [] (current_string);
1272 hdf_dataset->CloseOnDisk();
1275 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1279 anAttr->Load(current_string);
1282 delete [] (current_string);
1283 hdf_dataset->CloseOnDisk();
1286 //============================================================================
1287 //Function : BuildlTree
1288 //============================================================================
1289 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1291 hdf_current_group->OpenOnDisk();
1292 SALOMEDSImpl_SObject aSO;
1293 char* Entry = hdf_current_group->GetName();
1294 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1295 aSO = theStudy->CreateObjectID("0:1");
1298 aSO = theStudy->CreateObjectID(Entry);
1301 char name[HDF_NAME_MAX_LEN+1];
1302 int nbsons = hdf_current_group->nInternalObjects();
1303 for (int i=0; i<nbsons; i++) {
1304 hdf_current_group->InternalObjectIndentify(i,name);
1305 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1306 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1308 if (type == HDF_DATASET) {
1309 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1310 ReadAttributes(theStudy,aSO,new_dataset);
1311 new_dataset = 0; // will be deleted by father destructor
1314 else if (type == HDF_GROUP) {
1315 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1316 BuildTree (theStudy, new_group);
1317 new_group = 0; // will be deleted by father destructor
1320 hdf_current_group->CloseOnDisk();
1324 //============================================================================
1325 //Function : Translate_IOR_to_persistentID
1326 //============================================================================
1327 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1328 SALOMEDSImpl_Driver* engine,
1332 DF_ChildIterator itchild(so.GetLabel());
1333 std::string ior_string, persistent_string, curid;
1335 for (; itchild.More(); itchild.Next()) {
1336 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1337 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1338 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1339 ior_string = IOR->Value();
1341 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1342 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1344 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1348 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1353 HDFgroup* new_group =0;
1354 HDFdataset* new_dataset =0;
1356 char aVarName[HDF_NAME_MAX_LEN+1];
1357 char *currentVarType = 0;
1358 char *currentVarValue = 0;
1359 char *currentVarIndex = 0;
1361 //Open HDF group with notebook variables
1362 theGroup->OpenOnDisk();
1364 //Get Nb of variables
1365 int aNbVars = theGroup->nInternalObjects();
1367 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1369 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1370 theGroup->InternalObjectIndentify(iVar,aVarName);
1371 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1372 if(type == HDF_GROUP) {
1375 new_group = new HDFgroup(aVarName,theGroup);
1376 new_group->OpenOnDisk();
1379 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1380 new_dataset->OpenOnDisk();
1381 currentVarType = new char[new_dataset->GetSize()+1];
1382 new_dataset->ReadFromDisk(currentVarType);
1383 new_dataset->CloseOnDisk();
1384 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1387 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1388 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1389 new_dataset->OpenOnDisk();
1390 currentVarIndex = new char[new_dataset->GetSize()+1];
1391 new_dataset->ReadFromDisk(currentVarIndex);
1392 new_dataset->CloseOnDisk();
1393 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1394 order = atoi(currentVarIndex);
1395 delete [] currentVarIndex;
1401 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1402 new_dataset->OpenOnDisk();
1403 currentVarValue = new char[new_dataset->GetSize()+1];
1404 new_dataset->ReadFromDisk(currentVarValue);
1405 new_dataset->CloseOnDisk();
1406 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1408 new_group->CloseOnDisk();
1409 new_group = 0; //will be deleted by hdf_sco_group destructor
1411 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1412 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
1413 delete [] currentVarType;
1415 //Create variable and add it in the study
1416 SALOMEDSImpl_GenericVariable* aVariable =
1417 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
1418 aVariable->Load(std::string(currentVarValue));
1419 aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1420 delete [] currentVarValue;
1424 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1425 for(;it!=aVarsMap.end();it++)
1426 theStudy->AddVariable((*it).second);
1428 theGroup->CloseOnDisk();