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());
140 aC_HDFUrl = new char[strlen(aResultPath) + 19];
141 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
142 delete [] (aResultPath);
150 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
152 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
157 eStr = new char[strlen(aUrl.c_str())+17];
158 sprintf(eStr,"Can't open file %s",aUrl.c_str());
160 _errorCode = std::string(eStr);
164 // Temporary aStudyUrl in place of study name
165 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
167 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
170 Study->StudyId( _IDcounter );
172 // Assign the value of the URL in the study object
175 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
177 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
178 _errorCode = "Study is empty";
182 //Create the Structure of the Document
183 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
186 BuildTree (Study, hdf_group_study_structure);
190 char *eStr = new char [strlen(aUrl.c_str())+17];
191 sprintf(eStr,"Can't open file %s", aUrl.c_str());
192 _errorCode = std::string(eStr);
196 //Read and create notebook variables
197 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
198 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
199 ReadNoteBookVariables(Study,hdf_notebook_vars);
200 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
203 hdf_file->CloseOnDisk();
204 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
207 std::vector<std::string> aFilesToRemove;
208 aFilesToRemove.push_back("hdf_from_ascii.hdf");
209 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
212 delete hdf_file; // all related hdf objects will be deleted
219 //============================================================================
221 * Purpose : Close a study.
222 * If the study hasn't been saved, ask the user to confirm the
223 * close action without saving
226 //============================================================================
227 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
232 _errorCode = "Study is null";
237 DF_Document* doc=aStudy->GetDocument();
241 //============================================================================
243 * Purpose : Save a Study to it's persistent reference
245 //============================================================================
246 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
247 SALOMEDSImpl_DriverFactory* aFactory,
252 std::string url = aStudy->URL();
254 _errorCode = "No path specified to save the study. Nothing done";
258 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
264 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
265 SALOMEDSImpl_DriverFactory* aFactory,
270 std::string url = aStudy->URL();
272 _errorCode = "No path specified to save the study. Nothing done";
276 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
282 //=============================================================================
283 /*! Function : SaveAs
284 * Purpose : Save a study to the persistent reference aUrl
286 //============================================================================
287 bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl,
288 SALOMEDSImpl_Study* aStudy,
289 SALOMEDSImpl_DriverFactory* aFactory,
293 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
296 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl,
297 SALOMEDSImpl_Study* aStudy,
298 SALOMEDSImpl_DriverFactory* aFactory,
302 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
305 //============================================================================
306 /*! Function : GetOpenStudies
307 * Purpose : Get name list of open studies in the session
309 //============================================================================
310 std::vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
313 std::vector<SALOMEDSImpl_Study*> aList;
315 int nbDocs = _appli->NbDocuments();
318 _errorCode = "No active study in this session";
322 SALOMEDSImpl_Study* aStudy;
323 std::vector<int> ids = _appli->GetDocumentIDs();
324 for (int i = 0, len = ids.size(); i<len; i++) {
325 DF_Document* D = _appli->GetDocument(ids[i]);
326 if(D == _clipboard) continue;
327 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
328 if(!aStudy) continue;
329 aList.push_back(aStudy);
336 //============================================================================
337 /*! Function : GetStudyByName
338 * Purpose : Get a study from its name
340 //============================================================================
341 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
342 (const std::string& aStudyName)
345 int nbDocs = _appli->NbDocuments();
348 _errorCode = "No active study in this session";
352 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
353 for (int i = 0, len = studies.size(); i<len; i++) {
354 if (studies[i]->Name() == aStudyName) return studies[i];
358 _errorCode = std::string("Found no study with the name ") + aStudyName;
362 //============================================================================
363 /*! Function : GetStudyByID
364 * Purpose : Get a study from its ID
366 //============================================================================
367 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
370 int nbDocs = _appli->NbDocuments();
373 _errorCode = "No active study in this session";
377 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
378 for (int i = 0, len = studies.size(); i<len; i++) {
379 if (studies[i]->StudyId() == aStudyID) return studies[i];
383 _errorCode = "Found no study with the given ID";
387 //=============================================================================
388 /*! Function : _SaveProperties
389 * Purpose : save the study properties in HDF file
391 //============================================================================
392 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
397 HDFdataset *hdf_dataset = 0;
401 // add modifications list (user and date of save)
402 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
403 int aLocked = aProp->IsLocked();
404 if (aLocked) aProp->SetLocked(false);
406 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
407 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
408 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
409 mn, hh, day, month, year);
411 if (aLocked) aProp->SetLocked(true);
413 std::vector<std::string> aNames;
414 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
416 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
418 int aLength = 0, anIndex, i;
419 for(i=1; i<=aNames.size(); i++)
420 aLength += aNames[i-1].size() + 1;
422 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
423 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
426 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
428 aLength = aNames.size();
430 for(anIndex = 0; anIndex<aLength; anIndex++) {
431 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
432 (int)(aMinutes[anIndex]),
433 (int)(aHours[anIndex]),
434 (int)(aDays[anIndex]),
435 (int)(aMonths[anIndex]),
436 (int)(aYears[anIndex]),
437 aNames[anIndex].c_str());
438 a = strlen(aProperty);
443 name_len = (hdf_int32) a;
444 size[0] = name_len + 1 ;
445 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
446 hdf_dataset->CreateOnDisk();
447 hdf_dataset->WriteOnDisk(aProperty);
448 hdf_dataset->CloseOnDisk();
449 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
452 aProp->SetModified(0);
456 //=============================================================================
457 /*! Function : _SaveAs
458 * Purpose : save the study in HDF file
460 //============================================================================
461 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl,
462 SALOMEDSImpl_Study* aStudy,
463 SALOMEDSImpl_DriverFactory* aFactory,
467 // Set "C" locale temporarily to avoid possible localization problems
468 Kernel_Utils::Localizer loc;
470 // HDF File will be composed of differents part :
471 // * For each ComponentDataType, all data created by the component
472 // Informations in data group hdf_group_datacomponent
473 // * Study Structure -> Exactly what is contained in Document
474 // Informations in data group hdf_group_study_structure
479 HDFgroup *hdf_group_study_structure =0;
480 HDFgroup *hdf_sco_group =0;
481 HDFgroup *hdf_sco_group2 =0;
482 HDFgroup *hdf_notebook_vars =0;
483 HDFgroup *hdf_notebook_var = 0;
485 HDFgroup *hdf_group_datacomponent =0;
486 HDFdataset *hdf_dataset =0;
488 hdf_int32 name_len = 0;
489 std::string component_name;
492 _errorCode = "Study is null";
496 //Create a temporary url to which the study is saved
497 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
499 int aLocked = aStudy->GetProperties()->IsLocked();
500 if (aLocked) aStudy->GetProperties()->SetLocked(false);
502 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
503 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
507 // mpv 15.12.2003: for saving components we have to load all data from all modules
508 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
509 for (; itcomponent1.More(); itcomponent1.Next())
511 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
512 // if there is an associated Engine call its method for saving
513 std::string IOREngine;
515 if (!sco.ComponentIOR(IOREngine)) {
516 std::string aCompType = sco.GetComment();
517 if (!aCompType.empty()) {
519 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
520 aMapTypeDriver[aCompType] = aDriver;
522 if (aDriver != NULL) {
523 if(!SB->LoadWith(sco, aDriver)) {
524 _errorCode = SB->GetErrorCode();
531 _errorCode = "Can not restore information to resave it";
536 std::string anOldName = aStudy->Name();
537 aStudy->URL(aStudyUrl);
539 // To change for Save
540 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
541 hdf_file = new HDFfile((char*)aUrl.c_str());
542 hdf_file->CreateOnDisk();
544 //-----------------------------------------------------------------------
545 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
546 //-----------------------------------------------------------------------
547 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
548 hdf_group_datacomponent->CreateOnDisk();
550 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
552 for (; itcomponent.More(); itcomponent.Next())
554 SALOMEDSImpl_SComponent sco = itcomponent.Value();
556 std::string scoid = sco.GetID();
557 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
558 hdf_sco_group->CreateOnDisk();
560 std::string componentDataType = sco.ComponentDataType();
561 std::string IOREngine;
562 if (sco.ComponentIOR(IOREngine))
564 SALOMEDSImpl_Driver* Engine = NULL;
565 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
566 // we have found the associated engine to write the data
567 Engine = aMapTypeDriver[componentDataType];
570 Engine = aFactory->GetDriverByIOR(IOREngine);
575 SALOMEDSImpl_TMPFile* aStream = NULL;
578 if (theASCII) aStream = Engine->SaveASCII(sco,
579 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
582 else aStream = Engine->Save(sco,
583 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
586 HDFdataset *hdf_dataset;
587 hdf_size aHDFSize[1];
588 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
590 aHDFSize[0] = length;
592 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
593 hdf_dataset->CreateOnDisk();
594 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
595 hdf_dataset->CloseOnDisk();
598 if(aStream) delete aStream;
600 // store multifile state
602 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
603 hdf_dataset->CreateOnDisk();
604 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
605 hdf_dataset->CloseOnDisk();
606 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
609 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
610 hdf_dataset->CreateOnDisk();
611 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
612 hdf_dataset->CloseOnDisk();
613 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
614 // Creation of the persistance reference attribute
615 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
618 hdf_sco_group->CloseOnDisk();
619 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
621 hdf_group_datacomponent->CloseOnDisk();
622 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
624 //-----------------------------------------------------------------------
625 //3 - Write the Study Structure
626 //-----------------------------------------------------------------------
627 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
628 hdf_group_study_structure->CreateOnDisk();
629 // save component attributes
630 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
631 for (; itcomp.More(); itcomp.Next())
633 SALOMEDSImpl_SComponent SC = itcomp.Value();
634 std::string scid = SC.GetID();
635 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
636 hdf_sco_group2->CreateOnDisk();
637 SaveAttributes(SC, hdf_sco_group2);
638 // ComponentDataType treatment
639 component_name = SC.ComponentDataType();
640 name_len = (hdf_int32)component_name.length();
641 size[0] = name_len +1 ;
642 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
643 hdf_dataset->CreateOnDisk();
644 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
645 hdf_dataset->CloseOnDisk();
646 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
647 Impl_SaveObject(SC, hdf_sco_group2);
648 hdf_sco_group2->CloseOnDisk();
649 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
651 //-----------------------------------------------------------------------
652 //4 - Write the Study UseCases Structure
653 //-----------------------------------------------------------------------
654 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
656 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
657 hdf_soo_group->CreateOnDisk();
658 SaveAttributes(aSO, hdf_soo_group);
659 Impl_SaveObject(aSO, hdf_soo_group);
660 hdf_soo_group->CloseOnDisk();
661 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
663 //-----------------------------------------------------------------------
664 //5 - Write the NoteBook Variables
665 //-----------------------------------------------------------------------
667 //5.1 Create group to store all note book variables
668 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
669 hdf_notebook_vars->CreateOnDisk();
671 std::string varValue;
673 std::string varIndex;
675 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
676 // For each variable create HDF group
677 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
678 hdf_notebook_var->CreateOnDisk();
680 // Save Variable type
681 varType = aStudy->myNoteBookVars[i]->SaveType();
682 name_len = (hdf_int32) varType.length();
683 size[0] = name_len +1 ;
684 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
685 hdf_dataset->CreateOnDisk();
686 hdf_dataset->WriteOnDisk((char*)varType.c_str());
687 hdf_dataset->CloseOnDisk();
688 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
691 sprintf(buffer,"%d",i);
692 varIndex= std::string(buffer);
693 name_len = (hdf_int32) varIndex.length();
694 size[0] = name_len +1 ;
695 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
696 hdf_dataset->CreateOnDisk();
697 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
698 hdf_dataset->CloseOnDisk();
699 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
702 // Save Variable value
703 varValue = aStudy->myNoteBookVars[i]->Save();
704 name_len = (hdf_int32) varValue.length();
705 size[0] = name_len +1 ;
706 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
707 hdf_dataset->CreateOnDisk();
708 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
709 hdf_dataset->CloseOnDisk();
710 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
711 hdf_notebook_var->CloseOnDisk();
712 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
714 hdf_notebook_vars->CloseOnDisk();
715 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
717 if (aLocked) aStudy->GetProperties()->SetLocked(true);
718 //-----------------------------------------------------------------------
719 //6 - Write the Study Properties
720 //-----------------------------------------------------------------------
721 std::string study_name = aStudy->Name();
722 name_len = (hdf_int32) study_name.size();
723 size[0] = name_len +1 ;
724 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
725 hdf_dataset->CreateOnDisk();
726 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
727 hdf_dataset->CloseOnDisk();
728 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
730 Impl_SaveProperties(aStudy, hdf_group_study_structure);
731 hdf_group_study_structure->CloseOnDisk();
732 hdf_file->CloseOnDisk();
734 aStudy->IsSaved(true);
735 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
736 delete hdf_file; // recursively deletes all hdf objects...
740 _errorCode = "HDFexception ! ";
743 catch(std::exception& exc)
745 _errorCode = const_cast<char*>(exc.what());
750 _errorCode = "Unknown exception ! ";
753 if (theASCII) { // save file in ASCII format
754 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
757 //Now it's necessary to copy files from the temporary directory to the user defined directory.
759 // The easiest way to get a list of file in the temporary directory
761 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
762 std::string aTmpFile = aTmpFileDir +"files";
763 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
766 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
768 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
770 system(aCmd.c_str());
772 // Iterate and move files in the temporary directory
773 FILE* fp = fopen(aTmpFile.c_str(), "r");
774 if(!fp) return false;
775 char* buffer = new char[2047];
777 if((fgets(buffer, 2046, fp)) == NULL) break;
778 size_t aLen = strlen(buffer);
779 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
781 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
783 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
785 system(aCmd.c_str());
793 DeleteFileA(aTmpFile.c_str());
795 unlink(aTmpFile.c_str());
799 RemoveDirectoryA(aTmpFileDir.c_str());
800 RemoveDirectoryA(aStudyTmpDir.c_str());
802 rmdir(aTmpFileDir.c_str());
803 rmdir(aStudyTmpDir.c_str());
809 //============================================================================
810 /*! Function : Impl_SaveObject
813 //============================================================================
814 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
815 HDFgroup *hdf_group_datatype)
819 // Write in group hdf_group_datatype all informations of SObject SC
820 // Iterative function to parse all SObjects under a SComponent
822 HDFgroup *hdf_group_sobject = 0;
824 DF_ChildIterator itchild(SC.GetLabel());
825 for (; itchild.More(); itchild.Next())
828 // mpv: don't save empty labels
829 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
830 if (attr.size() == 0) { //No attributes on the label
831 DF_ChildIterator subchild(itchild.Value());
832 if (!subchild.More()) {
835 subchild.Init(itchild.Value(), true);
837 for (; subchild.More() && anEmpty; subchild.Next()) {
838 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
840 anEmpty = false; //There are attributes on the child label
844 if (anEmpty) continue;
847 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
849 std::string scoid = SO.GetID();
850 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
851 hdf_group_sobject->CreateOnDisk();
852 SaveAttributes(SO, hdf_group_sobject);
853 Impl_SaveObject(SO, hdf_group_sobject);
854 hdf_group_sobject->CloseOnDisk();
855 hdf_group_sobject =0; // will be deleted by father hdf object destructor
861 //============================================================================
862 /*! Function : Impl_SubstituteSlash
865 //============================================================================
866 std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl)
870 std::string theUrl(aUrl);
871 for(int i = 0; i<theUrl.size(); i++)
872 if(theUrl[i] == '/') theUrl[i] = ':';
876 //============================================================================
877 /*! Function : GetDocumentOfStudy
880 //============================================================================
881 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
884 return theStudy->_doc;
887 //============================================================================
888 /*! Function : CanCopy
891 //============================================================================
892 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
893 SALOMEDSImpl_Driver* theEngine)
896 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
897 if (!aComponent) return false;
898 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
899 std::string IOREngine;
900 if (!aComponent.ComponentIOR(IOREngine)) return false;
901 if (theEngine == NULL) return false;
902 return theEngine->CanCopy(theObject);
905 //============================================================================
906 /*! Function : CopyLabel
909 //============================================================================
910 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
911 SALOMEDSImpl_Driver* theEngine,
912 const int theSourceStartDepth,
913 const DF_Label& theSource,
914 const DF_Label& theDestinationMain)
919 DF_Label aTargetLabel = theDestinationMain;
920 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
921 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
922 DF_Label aSourceLabel = theSource;
923 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
924 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
925 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
927 // iterate attributes
928 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
929 for(int i = 0, len = attrList.size(); i<len; i++) {
930 DF_Attribute* anAttr = attrList[i];
931 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
932 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
933 if (type == std::string("AttributeTarget")) continue; // and target attribute
935 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
936 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
937 std::string anEntry = aReferenced.Entry();
938 // store the value of name attribute of referenced label
939 SALOMEDSImpl_AttributeName* aNameAttribute;
940 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
942 anEntry += aNameAttribute->Value();
944 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
948 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
949 std::string anEntry = theSource.Entry();
950 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
953 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
954 std::string aResStr("");
955 for(a = 0; a < aLen; a++) {
956 aResStr += (char)(aStream->Get(a));
959 if(aStream) delete aStream;
961 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
962 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
965 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
966 aTargetLabel.AddAttribute(aNewAttribute);
967 anAttr->Paste(aNewAttribute);
973 //============================================================================
977 //============================================================================
978 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
979 SALOMEDSImpl_Driver* theEngine)
983 // adoptation for alliances datamodel copy: without IOR attributes !!!
984 bool aStructureOnly; // copy only SObjects and attributes without component help
985 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
987 // get component-engine
988 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
990 // CAF document of current study usage
991 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
993 _errorCode = "Document is null";
997 //Clear the clipboard
998 _clipboard->Main().Root().ForgetAllAttributes(true);
999 _appli->Close(_clipboard);
1000 _clipboard = _appli->NewDocument("SALOME_STUDY");
1002 // set component data type to the name attribute of root label
1003 if (!aStructureOnly) {
1004 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
1005 theEngine->ComponentDataType());
1007 // set to the Root label integer attribute: study id
1008 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1009 // iterate all theObject's label children
1010 DF_Label aStartLabel = theObject.GetLabel();
1011 int aSourceStartDepth = aStartLabel.Depth();
1013 // copy main source label
1014 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1016 // copy all subchildren of the main source label (all levels)
1017 DF_ChildIterator anIterator(aStartLabel, true);
1018 for(; anIterator.More(); anIterator.Next()) {
1019 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1024 //============================================================================
1025 /*! Function : CanPaste
1028 //============================================================================
1029 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1030 SALOMEDSImpl_Driver* theEngine)
1035 _errorCode = "Clipboard is null";
1039 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1040 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1041 _errorCode = "Clipboard has no component type";
1044 SALOMEDSImpl_AttributeInteger* anObjID;
1045 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1046 _errorCode = "Clipboard has no object id";
1049 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1051 _errorCode = "Object doesn't belong to component";
1055 std::string IOREngine;
1056 if (!aComponent.ComponentIOR(IOREngine)) {
1057 _errorCode = "component has no IOR";
1060 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1063 //============================================================================
1064 /*! Function : PasteLabel
1067 //============================================================================
1068 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1069 SALOMEDSImpl_Driver* theEngine,
1070 const DF_Label& theSource,
1071 const DF_Label& theDestinationStart,
1072 const int theCopiedStudyID,
1073 const bool isFirstElement)
1077 // get corresponding source, target and auxiliary labels
1078 DF_Label aTargetLabel = theDestinationStart;
1080 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1082 if (!isFirstElement) {
1083 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1084 DF_Label aSourceLabel = theSource;
1085 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1086 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1087 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1091 // check auxiliary label for TMPFile => IOR
1092 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1093 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1094 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1095 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1096 std::string aCompName = aComponentName->Value();
1098 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1099 std::string aTMPStr = aNameAttribute->Value();
1100 int aLen = aTMPStr.size();
1101 unsigned char* aStream = NULL;
1103 aStream = new unsigned char[aLen+10];
1104 for(a = 0; a < aLen; a++) {
1105 aStream[a] = aTMPStr[a];
1109 std::string anEntry = aTargetLabel.Entry();
1110 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1112 if (isFirstElement) {
1113 std::string aDestEntry = theEngine->PasteInto(aStream,
1116 aPastedSO.GetFatherComponent());
1117 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1119 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1121 if(aStream != NULL) delete []aStream;
1125 // iterate attributes
1126 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1127 for(int i = 0, len = attrList.size(); i<len; i++) {
1128 DF_Attribute* anAttr = attrList[i];
1129 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1130 aTargetLabel.ForgetAttribute(anAttr->ID());
1132 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1133 aTargetLabel.AddAttribute(aNewAttribute);
1134 anAttr->Paste(aNewAttribute);
1137 // check auxiliary label for Comment => reference or name attribute of the referenced object
1138 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1139 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1140 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1141 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1142 char* aNameStart = strchr(anEntry, ' ');
1147 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1148 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1149 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1150 // target attributes structure support
1151 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1153 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1154 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1159 return aTargetLabel;
1162 //============================================================================
1163 /*! Function : Paste
1166 //============================================================================
1167 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1168 SALOMEDSImpl_Driver* theEngine)
1172 SALOMEDSImpl_SObject so;
1173 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1175 // if study is locked, then paste can't be done
1176 if (aStudy->GetProperties()->IsLocked()) {
1177 _errorCode = "LockProtection";
1178 throw LockProtection("LockProtection");
1181 // if there is no component name, then paste only SObjects and attributes: without component help
1182 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1183 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1185 // get copied study ID
1186 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1187 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1188 _errorCode = "No study ID was found";
1191 int aCStudyID = aStudyIDAttribute->Value();
1193 // CAF document of current study usage
1194 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1196 _errorCode = "Document is null";
1200 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1202 // fill root inserted SObject
1203 DF_Label aStartLabel;
1204 if (aStructureOnly) {
1205 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1206 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1208 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1209 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1212 // paste all sublebels
1213 DF_ChildIterator anIterator(_clipboard->Main(), true);
1214 for(; anIterator.More(); anIterator.Next()) {
1215 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1218 return SALOMEDSImpl_Study::SObject(aStartLabel);
1221 //#######################################################################################################
1222 //# STATIC PRIVATE FUNCTIONS
1223 //#######################################################################################################
1225 //============================================================================
1226 /*! Function : SaveAttributes
1227 * Purpose : Save attributes for object
1229 //============================================================================
1230 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1233 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1234 DF_Attribute* anAttr = NULL;
1235 for(int i = 0, len = attrList.size(); i<len; i++) {
1236 anAttr = attrList[i];
1237 //The following attributes are not supposed to be written to the file
1238 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1239 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
1240 std::string aSaveStr =anAttr->Save();
1241 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1242 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1243 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1244 hdf_dataset->CreateOnDisk();
1245 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1246 hdf_dataset->CloseOnDisk();
1247 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1251 //===========================================================================
1252 //Function : ReadAttributes
1253 //===========================================================================
1254 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1255 const SALOMEDSImpl_SObject& aSO,
1256 HDFdataset* hdf_dataset)
1258 hdf_dataset->OpenOnDisk();
1260 DF_Attribute* anAttr = NULL;
1261 char* current_string = new char[hdf_dataset->GetSize()+1];
1262 hdf_dataset->ReadFromDisk(current_string);
1263 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1264 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1265 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1266 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1267 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1268 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1269 delete [] (current_string);
1270 hdf_dataset->CloseOnDisk();
1273 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1277 anAttr->Load(current_string);
1280 delete [] (current_string);
1281 hdf_dataset->CloseOnDisk();
1284 //============================================================================
1285 //Function : BuildlTree
1286 //============================================================================
1287 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1289 hdf_current_group->OpenOnDisk();
1290 SALOMEDSImpl_SObject aSO;
1291 char* Entry = hdf_current_group->GetName();
1292 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1293 aSO = theStudy->CreateObjectID("0:1");
1296 aSO = theStudy->CreateObjectID(Entry);
1299 char name[HDF_NAME_MAX_LEN+1];
1300 int nbsons = hdf_current_group->nInternalObjects();
1301 for (int i=0; i<nbsons; i++) {
1302 hdf_current_group->InternalObjectIndentify(i,name);
1303 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1304 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1306 if (type == HDF_DATASET) {
1307 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1308 ReadAttributes(theStudy,aSO,new_dataset);
1309 new_dataset = 0; // will be deleted by father destructor
1312 else if (type == HDF_GROUP) {
1313 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1314 BuildTree (theStudy, new_group);
1315 new_group = 0; // will be deleted by father destructor
1318 hdf_current_group->CloseOnDisk();
1322 //============================================================================
1323 //Function : Translate_IOR_to_persistentID
1324 //============================================================================
1325 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1326 SALOMEDSImpl_Driver* engine,
1330 DF_ChildIterator itchild(so.GetLabel());
1331 std::string ior_string, persistent_string, curid;
1333 for (; itchild.More(); itchild.Next()) {
1334 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1335 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1336 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1337 ior_string = IOR->Value();
1339 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1340 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1342 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1346 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1351 HDFgroup* new_group =0;
1352 HDFdataset* new_dataset =0;
1354 char aVarName[HDF_NAME_MAX_LEN+1];
1355 char *currentVarType = 0;
1356 char *currentVarValue = 0;
1357 char *currentVarIndex = 0;
1359 //Open HDF group with notebook variables
1360 theGroup->OpenOnDisk();
1362 //Get Nb of variables
1363 int aNbVars = theGroup->nInternalObjects();
1365 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1367 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1368 theGroup->InternalObjectIndentify(iVar,aVarName);
1369 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1370 if(type == HDF_GROUP) {
1373 new_group = new HDFgroup(aVarName,theGroup);
1374 new_group->OpenOnDisk();
1377 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1378 new_dataset->OpenOnDisk();
1379 currentVarType = new char[new_dataset->GetSize()+1];
1380 new_dataset->ReadFromDisk(currentVarType);
1381 new_dataset->CloseOnDisk();
1382 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1385 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1386 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1387 new_dataset->OpenOnDisk();
1388 currentVarIndex = new char[new_dataset->GetSize()+1];
1389 new_dataset->ReadFromDisk(currentVarIndex);
1390 new_dataset->CloseOnDisk();
1391 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1392 order = atoi(currentVarIndex);
1393 delete [] currentVarIndex;
1399 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1400 new_dataset->OpenOnDisk();
1401 currentVarValue = new char[new_dataset->GetSize()+1];
1402 new_dataset->ReadFromDisk(currentVarValue);
1403 new_dataset->CloseOnDisk();
1404 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1406 new_group->CloseOnDisk();
1407 new_group = 0; //will be deleted by hdf_sco_group destructor
1409 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1410 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
1411 delete [] currentVarType;
1413 //Create variable and add it in the study
1414 SALOMEDSImpl_GenericVariable* aVariable =
1415 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
1416 aVariable->Load(std::string(currentVarValue));
1417 aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1418 delete [] currentVarValue;
1422 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1423 for(;it!=aVarsMap.end();it++)
1424 theStudy->AddVariable((*it).second);
1426 theGroup->CloseOnDisk();