1 // Copyright (C) 2007-2012 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 //Warning undef of Ascii Winwows define
38 #include "SALOMEDSImpl_Attributes.hxx"
39 #include "SALOMEDSImpl_Tool.hxx"
40 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "SALOMEDSImpl_GenericAttribute.hxx"
42 #include "SALOMEDSImpl_ScalarVariable.hxx"
50 #define USE_CASE_LABEL_ID "0:2"
52 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
53 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
54 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
55 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
56 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
57 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
59 //============================================================================
60 /*! Function : SALOMEDSImpl_StudyManager
61 * Purpose : SALOMEDSImpl_StudyManager constructor
63 //============================================================================
64 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
67 _appli = new DF_Application();
69 _clipboard = _appli->NewDocument("SALOME_STUDY");
72 //============================================================================
73 /*! Function : ~SALOMEDSImpl_StudyManager
74 * Purpose : SALOMEDSImpl_StudyManager destructor
76 //============================================================================
77 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
79 _appli->Close(_clipboard);
80 // Destroy application
85 //============================================================================
86 /*! Function : NewStudy
87 * Purpose : Create a New Study of name study_name
89 //==================================================T==========================
90 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const std::string& study_name)
94 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
96 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
99 Study->StudyId( _IDcounter );
101 // set Study properties
102 SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
104 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
105 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
106 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
107 mn, hh, day, month, year);
108 aProp->SetCreationMode(1); //"from scratch"
113 //============================================================================
115 * Purpose : Open a Study from it's persistent reference
117 //============================================================================
118 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const std::string& aUrl)
120 // Set "C" locale temporarily to avoid possible localization problems
121 Kernel_Utils::Localizer loc;
126 HDFfile *hdf_file =0;
127 HDFgroup *hdf_group_study_structure =0;
128 HDFgroup *hdf_notebook_vars = 0;
132 bool isASCII = false;
133 if (HDFascii::isASCII(aUrl.c_str())) {
135 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
138 aC_HDFUrl = new char[strlen(aResultPath) + 19];
139 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
140 delete [] (aResultPath);
148 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
150 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
155 eStr = new char[strlen(aUrl.c_str())+17];
156 sprintf(eStr,"Can't open file %s",aUrl.c_str());
158 _errorCode = std::string(eStr);
162 // Temporary aStudyUrl in place of study name
163 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
165 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
168 Study->StudyId( _IDcounter );
170 // Assign the value of the URL in the study object
173 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
175 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
176 _errorCode = "Study is empty";
180 //Create the Structure of the Document
181 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
184 BuildTree (Study, hdf_group_study_structure);
188 char *eStr = new char [strlen(aUrl.c_str())+17];
189 sprintf(eStr,"Can't open file %s", aUrl.c_str());
190 _errorCode = std::string(eStr);
194 //Read and create notebook variables
195 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
196 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
197 ReadNoteBookVariables(Study,hdf_notebook_vars);
198 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
201 hdf_file->CloseOnDisk();
202 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
205 std::vector<std::string> aFilesToRemove;
206 aFilesToRemove.push_back("hdf_from_ascii.hdf");
207 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
210 delete hdf_file; // all related hdf objects will be deleted
217 //============================================================================
219 * Purpose : Close a study.
220 * If the study hasn't been saved, ask the user to confirm the
221 * close action without saving
224 //============================================================================
225 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
230 _errorCode = "Study is null";
235 DF_Document* doc=aStudy->GetDocument();
239 //============================================================================
241 * Purpose : Save a Study to it's persistent reference
243 //============================================================================
244 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
245 SALOMEDSImpl_DriverFactory* aFactory,
250 std::string url = aStudy->URL();
252 _errorCode = "No path specified to save the study. Nothing done";
256 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
262 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
263 SALOMEDSImpl_DriverFactory* aFactory,
268 std::string url = aStudy->URL();
270 _errorCode = "No path specified to save the study. Nothing done";
274 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
280 //=============================================================================
281 /*! Function : SaveAs
282 * Purpose : Save a study to the persistent reference aUrl
284 //============================================================================
285 bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl,
286 SALOMEDSImpl_Study* aStudy,
287 SALOMEDSImpl_DriverFactory* aFactory,
291 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
294 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl,
295 SALOMEDSImpl_Study* aStudy,
296 SALOMEDSImpl_DriverFactory* aFactory,
300 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
303 //============================================================================
304 /*! Function : GetOpenStudies
305 * Purpose : Get name list of open studies in the session
307 //============================================================================
308 std::vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
311 std::vector<SALOMEDSImpl_Study*> aList;
313 int nbDocs = _appli->NbDocuments();
316 _errorCode = "No active study in this session";
320 SALOMEDSImpl_Study* aStudy;
321 std::vector<int> ids = _appli->GetDocumentIDs();
322 for (int i = 0, len = ids.size(); i<len; i++) {
323 DF_Document* D = _appli->GetDocument(ids[i]);
324 if(D == _clipboard) continue;
325 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
326 if(!aStudy) continue;
327 aList.push_back(aStudy);
334 //============================================================================
335 /*! Function : GetStudyByName
336 * Purpose : Get a study from its name
338 //============================================================================
339 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
340 (const std::string& aStudyName)
343 int nbDocs = _appli->NbDocuments();
346 _errorCode = "No active study in this session";
350 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
351 for (int i = 0, len = studies.size(); i<len; i++) {
352 if (studies[i]->Name() == aStudyName) return studies[i];
356 _errorCode = std::string("Found no study with the name ") + aStudyName;
360 //============================================================================
361 /*! Function : GetStudyByID
362 * Purpose : Get a study from its ID
364 //============================================================================
365 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
368 int nbDocs = _appli->NbDocuments();
371 _errorCode = "No active study in this session";
375 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
376 for (int i = 0, len = studies.size(); i<len; i++) {
377 if (studies[i]->StudyId() == aStudyID) return studies[i];
381 _errorCode = "Found no study with the given ID";
385 //=============================================================================
386 /*! Function : _SaveProperties
387 * Purpose : save the study properties in HDF file
389 //============================================================================
390 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
395 HDFdataset *hdf_dataset = 0;
399 // add modifications list (user and date of save)
400 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
401 int aLocked = aProp->IsLocked();
402 if (aLocked) aProp->SetLocked(false);
404 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
405 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
406 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
407 mn, hh, day, month, year);
409 if (aLocked) aProp->SetLocked(true);
411 std::vector<std::string> aNames;
412 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
414 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
416 std::string units = aProp->GetUnits();
417 std::string comment = aProp->GetComment();
419 int aLength = 0, anIndex, i, unitsSize = 0, commentSize = 0;
420 for(i=1; i<=aNames.size(); i++)
421 aLength += aNames[i-1].size() + 1;
423 unitsSize = units.size();
424 commentSize = comment.size();
427 //locked flag, modified flag,
428 //minutes, hours, day, months, year, user name, char(1),
429 //minutes, hours, day, months, year, user name, char(1),
430 //.....................................................,
431 //.....................................................,
432 //.....................................................,
433 //minutes, hours, day, months, year, user name, char(1), char(30) <- !!!! used to define end of section with modifications !!!!
434 //units, char(1), comment, char(0)
436 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, 1 byte (char(30) section delimeter)
437 // unit length + 1, comment length, "zero" byte
439 char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize ];
442 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
444 aLength = aNames.size();
446 for(anIndex = 0; anIndex<aLength; anIndex++) {
447 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
448 (int)(aMinutes[anIndex]),
449 (int)(aHours[anIndex]),
450 (int)(aDays[anIndex]),
451 (int)(aMonths[anIndex]),
452 (int)(aYears[anIndex]),
453 aNames[anIndex].c_str());
454 a = strlen(aProperty);
458 //Write delimeter of the section to define end of the modifications section
461 //Write units if need
462 if(units.size() > 0) {
463 sprintf(&(aProperty[a]),"%s",units.c_str());
464 a = strlen(aProperty);
469 //Write comments if need
470 if(comment.size() > 0) {
471 sprintf(&(aProperty[a]),"%s",comment.c_str());
472 a = strlen(aProperty);
478 name_len = (hdf_int32) a;
479 size[0] = name_len + 1 ;
480 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
481 hdf_dataset->CreateOnDisk();
482 hdf_dataset->WriteOnDisk(aProperty);
483 hdf_dataset->CloseOnDisk();
484 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
487 aProp->SetModified(0);
491 //=============================================================================
492 /*! Function : _SaveAs
493 * Purpose : save the study in HDF file
495 //============================================================================
496 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl,
497 SALOMEDSImpl_Study* aStudy,
498 SALOMEDSImpl_DriverFactory* aFactory,
502 // Set "C" locale temporarily to avoid possible localization problems
503 Kernel_Utils::Localizer loc;
505 // HDF File will be composed of differents part :
506 // * For each ComponentDataType, all data created by the component
507 // Informations in data group hdf_group_datacomponent
508 // * Study Structure -> Exactly what is contained in Document
509 // Informations in data group hdf_group_study_structure
514 HDFgroup *hdf_group_study_structure =0;
515 HDFgroup *hdf_sco_group =0;
516 HDFgroup *hdf_sco_group2 =0;
517 HDFgroup *hdf_notebook_vars =0;
518 HDFgroup *hdf_notebook_var = 0;
520 HDFgroup *hdf_group_datacomponent =0;
521 HDFdataset *hdf_dataset =0;
523 hdf_int32 name_len = 0;
524 std::string component_name;
527 _errorCode = "Study is null";
531 // Store previous URL
532 std::string anOldName = aStudy->Name();
534 //Create a temporary url to which the study is saved
535 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
537 int aLocked = aStudy->GetProperties()->IsLocked();
538 if (aLocked) aStudy->GetProperties()->SetLocked(false);
540 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
541 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
545 // mpv 15.12.2003: for saving components we have to load all data from all modules
546 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
547 for (; itcomponent1.More(); itcomponent1.Next())
549 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
550 // if there is an associated Engine call its method for saving
551 std::string IOREngine;
553 if (!sco.ComponentIOR(IOREngine)) {
554 std::string aCompType = sco.GetComment();
555 if (!aCompType.empty()) {
557 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
558 aMapTypeDriver[aCompType] = aDriver;
560 if (aDriver != NULL) {
561 if(!SB->LoadWith(sco, aDriver)) {
562 _errorCode = SB->GetErrorCode();
569 _errorCode = "Can not restore information to resave it";
574 // VSR: set URL to new file name
575 // VSR: remember to set previous name if save operation fails
576 aStudy->URL(aStudyUrl);
578 // To change for Save
579 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
580 hdf_file = new HDFfile((char*)aUrl.c_str());
581 hdf_file->CreateOnDisk();
583 //-----------------------------------------------------------------------
584 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
585 //-----------------------------------------------------------------------
586 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
587 hdf_group_datacomponent->CreateOnDisk();
589 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
591 for (; itcomponent.More(); itcomponent.Next())
593 SALOMEDSImpl_SComponent sco = itcomponent.Value();
595 std::string scoid = sco.GetID();
596 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
597 hdf_sco_group->CreateOnDisk();
599 std::string componentDataType = sco.ComponentDataType();
600 std::string IOREngine;
601 if (sco.ComponentIOR(IOREngine))
603 SALOMEDSImpl_Driver* Engine = NULL;
604 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
605 // we have found the associated engine to write the data
606 Engine = aMapTypeDriver[componentDataType];
609 Engine = aFactory->GetDriverByIOR(IOREngine);
614 SALOMEDSImpl_TMPFile* aStream = NULL;
617 if (theASCII) aStream = Engine->SaveASCII(sco,
618 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
621 else aStream = Engine->Save(sco,
622 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
625 HDFdataset *hdf_dataset;
626 hdf_size aHDFSize[1];
627 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
629 aHDFSize[0] = length;
631 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
632 hdf_dataset->CreateOnDisk();
633 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
634 hdf_dataset->CloseOnDisk();
637 if(aStream) delete aStream;
639 // store multifile state
641 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
642 hdf_dataset->CreateOnDisk();
643 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
644 hdf_dataset->CloseOnDisk();
645 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
648 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
649 hdf_dataset->CreateOnDisk();
650 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
651 hdf_dataset->CloseOnDisk();
652 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
653 // Creation of the persistance reference attribute
654 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
657 hdf_sco_group->CloseOnDisk();
658 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
660 hdf_group_datacomponent->CloseOnDisk();
661 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
663 //-----------------------------------------------------------------------
664 //3 - Write the Study Structure
665 //-----------------------------------------------------------------------
666 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
667 hdf_group_study_structure->CreateOnDisk();
668 // save component attributes
669 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
670 for (; itcomp.More(); itcomp.Next())
672 SALOMEDSImpl_SComponent SC = itcomp.Value();
673 std::string scid = SC.GetID();
674 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
675 hdf_sco_group2->CreateOnDisk();
676 SaveAttributes(SC, hdf_sco_group2);
677 // ComponentDataType treatment
678 component_name = SC.ComponentDataType();
679 name_len = (hdf_int32)component_name.length();
680 size[0] = name_len +1 ;
681 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
682 hdf_dataset->CreateOnDisk();
683 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
684 hdf_dataset->CloseOnDisk();
685 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
686 Impl_SaveObject(SC, hdf_sco_group2);
687 hdf_sco_group2->CloseOnDisk();
688 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
690 //-----------------------------------------------------------------------
691 //4 - Write the Study UseCases Structure
692 //-----------------------------------------------------------------------
693 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
695 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
696 hdf_soo_group->CreateOnDisk();
697 SaveAttributes(aSO, hdf_soo_group);
698 Impl_SaveObject(aSO, hdf_soo_group);
699 hdf_soo_group->CloseOnDisk();
700 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
702 //-----------------------------------------------------------------------
703 //5 - Write the NoteBook Variables
704 //-----------------------------------------------------------------------
706 //5.1 Create group to store all note book variables
707 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
708 hdf_notebook_vars->CreateOnDisk();
710 std::string varValue;
712 std::string varIndex;
714 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
715 // For each variable create HDF group
716 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
717 hdf_notebook_var->CreateOnDisk();
719 // Save Variable type
720 varType = aStudy->myNoteBookVars[i]->SaveType();
721 name_len = (hdf_int32) varType.length();
722 size[0] = name_len +1 ;
723 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
724 hdf_dataset->CreateOnDisk();
725 hdf_dataset->WriteOnDisk((char*)varType.c_str());
726 hdf_dataset->CloseOnDisk();
727 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
730 sprintf(buffer,"%d",i);
731 varIndex= std::string(buffer);
732 name_len = (hdf_int32) varIndex.length();
733 size[0] = name_len +1 ;
734 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
735 hdf_dataset->CreateOnDisk();
736 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
737 hdf_dataset->CloseOnDisk();
738 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
741 // Save Variable value
742 varValue = aStudy->myNoteBookVars[i]->Save();
743 name_len = (hdf_int32) varValue.length();
744 size[0] = name_len +1 ;
745 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
746 hdf_dataset->CreateOnDisk();
747 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
748 hdf_dataset->CloseOnDisk();
749 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
750 hdf_notebook_var->CloseOnDisk();
751 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
753 hdf_notebook_vars->CloseOnDisk();
754 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
756 if (aLocked) aStudy->GetProperties()->SetLocked(true);
757 //-----------------------------------------------------------------------
758 //6 - Write the Study Properties
759 //-----------------------------------------------------------------------
760 std::string study_name = aStudy->Name();
761 name_len = (hdf_int32) study_name.size();
762 size[0] = name_len +1 ;
763 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
764 hdf_dataset->CreateOnDisk();
765 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
766 hdf_dataset->CloseOnDisk();
767 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
769 Impl_SaveProperties(aStudy, hdf_group_study_structure);
770 hdf_group_study_structure->CloseOnDisk();
771 hdf_file->CloseOnDisk();
773 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
774 delete hdf_file; // recursively deletes all hdf objects...
778 _errorCode = "HDFexception ! ";
779 aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed
782 catch(std::exception& exc)
784 _errorCode = const_cast<char*>(exc.what());
785 aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed
790 _errorCode = "Unknown exception ! ";
791 aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed
794 if (theASCII) { // save file in ASCII format
795 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
798 //Now it's necessary to copy files from the temporary directory to the user defined directory.
800 // The easiest way to get a list of file in the temporary directory
802 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
803 std::string aTmpFile = aTmpFileDir +"files";
804 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
807 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
809 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
811 system(aCmd.c_str());
813 // Iterate and move files in the temporary directory
814 FILE* fp = fopen(aTmpFile.c_str(), "rb");
816 aStudy->URL( anOldName ); // VSR: restore previous url if operation is failed
819 char* buffer = new char[2047];
821 while(!feof(fp) && !errors) {
822 if((fgets(buffer, 2046, fp)) == NULL) break;
823 size_t aLen = strlen(buffer);
824 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
826 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
828 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
830 errors = system(aCmd.c_str());
838 DeleteFileA(aTmpFile.c_str());
840 unlink(aTmpFile.c_str());
844 RemoveDirectoryA(aTmpFileDir.c_str());
845 RemoveDirectoryA(aStudyTmpDir.c_str());
847 rmdir(aTmpFileDir.c_str());
848 rmdir(aStudyTmpDir.c_str());
852 // VSR: finally, if all is done without errors, mark study as Saved
853 aStudy->IsSaved(true);
859 //============================================================================
860 /*! Function : Impl_SaveObject
863 //============================================================================
864 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
865 HDFgroup *hdf_group_datatype)
869 // Write in group hdf_group_datatype all informations of SObject SC
870 // Iterative function to parse all SObjects under a SComponent
872 HDFgroup *hdf_group_sobject = 0;
874 DF_ChildIterator itchild(SC.GetLabel());
875 for (; itchild.More(); itchild.Next())
878 // mpv: don't save empty labels
879 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
880 if (attr.size() == 0) { //No attributes on the label
881 DF_ChildIterator subchild(itchild.Value());
882 if (!subchild.More()) {
885 subchild.Init(itchild.Value(), true);
887 for (; subchild.More() && anEmpty; subchild.Next()) {
888 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
890 anEmpty = false; //There are attributes on the child label
894 if (anEmpty) continue;
897 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
899 std::string scoid = SO.GetID();
900 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
901 hdf_group_sobject->CreateOnDisk();
902 SaveAttributes(SO, hdf_group_sobject);
903 Impl_SaveObject(SO, hdf_group_sobject);
904 hdf_group_sobject->CloseOnDisk();
905 hdf_group_sobject =0; // will be deleted by father hdf object destructor
911 //============================================================================
912 /*! Function : Impl_SubstituteSlash
915 //============================================================================
916 std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl)
920 std::string theUrl(aUrl);
921 for(int i = 0; i<theUrl.size(); i++)
922 if(theUrl[i] == '/') theUrl[i] = ':';
926 //============================================================================
927 /*! Function : GetDocumentOfStudy
930 //============================================================================
931 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
934 return theStudy->_doc;
937 //============================================================================
938 /*! Function : CanCopy
941 //============================================================================
942 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
943 SALOMEDSImpl_Driver* theEngine)
946 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
947 if (!aComponent) return false;
948 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
949 std::string IOREngine;
950 if (!aComponent.ComponentIOR(IOREngine)) return false;
951 if (theEngine == NULL) return false;
952 return theEngine->CanCopy(theObject);
955 //============================================================================
956 /*! Function : CopyLabel
959 //============================================================================
960 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
961 SALOMEDSImpl_Driver* theEngine,
962 const int theSourceStartDepth,
963 const DF_Label& theSource,
964 const DF_Label& theDestinationMain)
969 DF_Label aTargetLabel = theDestinationMain;
970 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
971 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
972 DF_Label aSourceLabel = theSource;
973 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
974 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
975 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
977 // iterate attributes
978 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
979 for(int i = 0, len = attrList.size(); i<len; i++) {
980 DF_Attribute* anAttr = attrList[i];
981 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
982 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
983 if (type == std::string("AttributeTarget")) continue; // and target attribute
985 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
986 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
987 std::string anEntry = aReferenced.Entry();
988 // store the value of name attribute of referenced label
989 SALOMEDSImpl_AttributeName* aNameAttribute;
990 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
992 anEntry += aNameAttribute->Value();
994 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
998 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
999 std::string anEntry = theSource.Entry();
1000 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
1003 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
1004 std::string aResStr("");
1005 for(a = 0; a < aLen; a++) {
1006 aResStr += (char)(aStream->Get(a));
1009 if(aStream) delete aStream;
1011 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
1012 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
1015 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1016 aTargetLabel.AddAttribute(aNewAttribute);
1017 anAttr->Paste(aNewAttribute);
1023 //============================================================================
1027 //============================================================================
1028 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
1029 SALOMEDSImpl_Driver* theEngine)
1033 // adoptation for alliances datamodel copy: without IOR attributes !!!
1034 bool aStructureOnly; // copy only SObjects and attributes without component help
1035 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
1037 // get component-engine
1038 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1040 // CAF document of current study usage
1041 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1043 _errorCode = "Document is null";
1047 //Clear the clipboard
1048 _clipboard->Main().Root().ForgetAllAttributes(true);
1049 _appli->Close(_clipboard);
1050 _clipboard = _appli->NewDocument("SALOME_STUDY");
1052 // set component data type to the name attribute of root label
1053 if (!aStructureOnly) {
1054 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
1055 theEngine->ComponentDataType());
1057 // set to the Root label integer attribute: study id
1058 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1059 // iterate all theObject's label children
1060 DF_Label aStartLabel = theObject.GetLabel();
1061 int aSourceStartDepth = aStartLabel.Depth();
1063 // copy main source label
1064 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1066 // copy all subchildren of the main source label (all levels)
1067 DF_ChildIterator anIterator(aStartLabel, true);
1068 for(; anIterator.More(); anIterator.Next()) {
1069 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1074 //============================================================================
1075 /*! Function : CanPaste
1078 //============================================================================
1079 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1080 SALOMEDSImpl_Driver* theEngine)
1085 _errorCode = "Clipboard is null";
1089 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1090 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1091 _errorCode = "Clipboard has no component type";
1094 SALOMEDSImpl_AttributeInteger* anObjID;
1095 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1096 _errorCode = "Clipboard has no object id";
1099 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1101 _errorCode = "Object doesn't belong to component";
1105 std::string IOREngine;
1106 if (!aComponent.ComponentIOR(IOREngine)) {
1107 _errorCode = "component has no IOR";
1110 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1113 //============================================================================
1114 /*! Function : PasteLabel
1117 //============================================================================
1118 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1119 SALOMEDSImpl_Driver* theEngine,
1120 const DF_Label& theSource,
1121 const DF_Label& theDestinationStart,
1122 const int theCopiedStudyID,
1123 const bool isFirstElement)
1127 // get corresponding source, target and auxiliary labels
1128 DF_Label aTargetLabel = theDestinationStart;
1130 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1132 if (!isFirstElement) {
1133 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1134 DF_Label aSourceLabel = theSource;
1135 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1136 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1137 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1139 SALOMEDSImpl_SObject so = theDestinationStudy->GetSObject(aTargetLabel);
1140 theDestinationStudy->addSO_Notification(so);
1143 // check auxiliary label for TMPFile => IOR
1144 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1145 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1146 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1147 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1148 std::string aCompName = aComponentName->Value();
1150 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1151 std::string aTMPStr = aNameAttribute->Value();
1152 int aLen = aTMPStr.size();
1153 unsigned char* aStream = NULL;
1155 aStream = new unsigned char[aLen+10];
1156 for(a = 0; a < aLen; a++) {
1157 aStream[a] = aTMPStr[a];
1161 std::string anEntry = aTargetLabel.Entry();
1162 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1164 if (isFirstElement) {
1165 std::string aDestEntry = theEngine->PasteInto(aStream,
1168 aPastedSO.GetFatherComponent());
1169 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1171 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1173 if(aStream != NULL) delete []aStream;
1177 // iterate attributes
1178 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1179 for(int i = 0, len = attrList.size(); i<len; i++) {
1180 DF_Attribute* anAttr = attrList[i];
1181 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1182 aTargetLabel.ForgetAttribute(anAttr->ID());
1184 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1185 aTargetLabel.AddAttribute(aNewAttribute);
1186 anAttr->Paste(aNewAttribute);
1189 // check auxiliary label for Comment => reference or name attribute of the referenced object
1190 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1191 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1192 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1193 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1194 char* aNameStart = strchr(anEntry, ' ');
1199 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1200 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1201 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1202 // target attributes structure support
1203 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1205 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1206 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1211 return aTargetLabel;
1214 //============================================================================
1215 /*! Function : Paste
1218 //============================================================================
1219 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1220 SALOMEDSImpl_Driver* theEngine)
1224 SALOMEDSImpl_SObject so;
1225 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1227 // if study is locked, then paste can't be done
1228 if (aStudy->GetProperties()->IsLocked()) {
1229 _errorCode = "LockProtection";
1230 throw LockProtection("LockProtection");
1233 // if there is no component name, then paste only SObjects and attributes: without component help
1234 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1235 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1237 // get copied study ID
1238 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1239 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1240 _errorCode = "No study ID was found";
1243 int aCStudyID = aStudyIDAttribute->Value();
1245 // CAF document of current study usage
1246 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1248 _errorCode = "Document is null";
1252 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1254 // fill root inserted SObject
1255 DF_Label aStartLabel;
1256 if (aStructureOnly) {
1257 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1258 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1260 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1261 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1264 // paste all sublebels
1265 DF_ChildIterator anIterator(_clipboard->Main(), true);
1266 for(; anIterator.More(); anIterator.Next()) {
1267 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1270 return SALOMEDSImpl_Study::SObject(aStartLabel);
1273 //#######################################################################################################
1274 //# STATIC PRIVATE FUNCTIONS
1275 //#######################################################################################################
1277 //============================================================================
1278 /*! Function : SaveAttributes
1279 * Purpose : Save attributes for object
1281 //============================================================================
1282 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1285 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1286 DF_Attribute* anAttr = NULL;
1287 for(int i = 0, len = attrList.size(); i<len; i++) {
1288 anAttr = attrList[i];
1289 //The following attributes are not supposed to be written to the file
1290 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1291 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
1292 std::string aSaveStr =anAttr->Save();
1293 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1294 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1295 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1296 hdf_dataset->CreateOnDisk();
1297 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1298 hdf_dataset->CloseOnDisk();
1299 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1303 //===========================================================================
1304 //Function : ReadAttributes
1305 //===========================================================================
1306 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1307 const SALOMEDSImpl_SObject& aSO,
1308 HDFdataset* hdf_dataset)
1310 hdf_dataset->OpenOnDisk();
1312 DF_Attribute* anAttr = NULL;
1313 char* current_string = new char[hdf_dataset->GetSize()+1];
1314 hdf_dataset->ReadFromDisk(current_string);
1315 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1316 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1317 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1318 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1319 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1320 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1321 delete [] (current_string);
1322 hdf_dataset->CloseOnDisk();
1325 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1329 anAttr->Load(current_string);
1332 delete [] (current_string);
1333 hdf_dataset->CloseOnDisk();
1336 //============================================================================
1337 //Function : BuildlTree
1338 //============================================================================
1339 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1341 hdf_current_group->OpenOnDisk();
1342 SALOMEDSImpl_SObject aSO;
1343 char* Entry = hdf_current_group->GetName();
1344 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1345 aSO = theStudy->CreateObjectID("0:1");
1348 aSO = theStudy->CreateObjectID(Entry);
1351 char name[HDF_NAME_MAX_LEN+1];
1352 int nbsons = hdf_current_group->nInternalObjects();
1353 for (int i=0; i<nbsons; i++) {
1354 hdf_current_group->InternalObjectIndentify(i,name);
1355 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1356 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1358 if (type == HDF_DATASET) {
1359 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1360 ReadAttributes(theStudy,aSO,new_dataset);
1361 new_dataset = 0; // will be deleted by father destructor
1364 else if (type == HDF_GROUP) {
1365 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1366 BuildTree (theStudy, new_group);
1367 new_group = 0; // will be deleted by father destructor
1370 hdf_current_group->CloseOnDisk();
1374 //============================================================================
1375 //Function : Translate_IOR_to_persistentID
1376 //============================================================================
1377 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1378 SALOMEDSImpl_Driver* engine,
1382 DF_ChildIterator itchild(so.GetLabel());
1383 std::string ior_string, persistent_string, curid;
1385 for (; itchild.More(); itchild.Next()) {
1386 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1387 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1388 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1389 ior_string = IOR->Value();
1391 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1392 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1394 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1398 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1403 HDFgroup* new_group =0;
1404 HDFdataset* new_dataset =0;
1406 char aVarName[HDF_NAME_MAX_LEN+1];
1407 char *currentVarType = 0;
1408 char *currentVarValue = 0;
1409 char *currentVarIndex = 0;
1411 //Open HDF group with notebook variables
1412 theGroup->OpenOnDisk();
1414 //Get Nb of variables
1415 int aNbVars = theGroup->nInternalObjects();
1417 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1419 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1420 theGroup->InternalObjectIndentify(iVar,aVarName);
1421 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1422 if(type == HDF_GROUP) {
1425 new_group = new HDFgroup(aVarName,theGroup);
1426 new_group->OpenOnDisk();
1429 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1430 new_dataset->OpenOnDisk();
1431 currentVarType = new char[new_dataset->GetSize()+1];
1432 new_dataset->ReadFromDisk(currentVarType);
1433 new_dataset->CloseOnDisk();
1434 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1437 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1438 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1439 new_dataset->OpenOnDisk();
1440 currentVarIndex = new char[new_dataset->GetSize()+1];
1441 new_dataset->ReadFromDisk(currentVarIndex);
1442 new_dataset->CloseOnDisk();
1443 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1444 order = atoi(currentVarIndex);
1445 delete [] currentVarIndex;
1451 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1452 new_dataset->OpenOnDisk();
1453 currentVarValue = new char[new_dataset->GetSize()+1];
1454 new_dataset->ReadFromDisk(currentVarValue);
1455 new_dataset->CloseOnDisk();
1456 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1458 new_group->CloseOnDisk();
1459 new_group = 0; //will be deleted by hdf_sco_group destructor
1461 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1462 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
1463 delete [] currentVarType;
1465 //Create variable and add it in the study
1466 SALOMEDSImpl_GenericVariable* aVariable =
1467 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
1468 aVariable->Load(std::string(currentVarValue));
1469 aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1470 delete [] currentVarValue;
1474 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1475 for(;it!=aVarsMap.end();it++)
1476 theStudy->AddVariable((*it).second);
1478 theGroup->CloseOnDisk();