1 // Copyright (C) 2007-2008 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
22 // File : SALOMEDSImpl_StudyManager.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDSImpl_StudyManager.hxx"
28 #include "DF_ChildIterator.hxx"
29 #include "HDFexplorer.hxx"
31 #include "SALOMEDSImpl_Attributes.hxx"
32 #include "SALOMEDSImpl_Tool.hxx"
33 #include "SALOMEDSImpl_SComponent.hxx"
34 #include "SALOMEDSImpl_GenericAttribute.hxx"
35 #include "SALOMEDSImpl_ScalarVariable.hxx"
47 //Warning undef of Ascii Winwows define
52 #define USE_CASE_LABEL_ID "0:2"
54 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
55 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
56 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
57 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
58 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
59 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
61 //============================================================================
62 /*! Function : SALOMEDSImpl_StudyManager
63 * Purpose : SALOMEDSImpl_StudyManager constructor
65 //============================================================================
66 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
69 _appli = new DF_Application();
71 _clipboard = _appli->NewDocument("SALOME_STUDY");
74 //============================================================================
75 /*! Function : ~SALOMEDSImpl_StudyManager
76 * Purpose : SALOMEDSImpl_StudyManager destructor
78 //============================================================================
79 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
81 _appli->Close(_clipboard);
82 // Destroy application
87 //============================================================================
88 /*! Function : NewStudy
89 * Purpose : Create a New Study of name study_name
91 //==================================================T==========================
92 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const std::string& study_name)
96 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
98 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
101 Study->StudyId( _IDcounter );
103 // set Study properties
104 SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
106 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
107 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
108 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
109 mn, hh, day, month, year);
110 aProp->SetCreationMode(1); //"from scratch"
115 //============================================================================
117 * Purpose : Open a Study from it's persistent reference
119 //============================================================================
120 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const std::string& aUrl)
125 HDFfile *hdf_file =0;
126 HDFgroup *hdf_group_study_structure =0;
127 HDFgroup *hdf_notebook_vars = 0;
131 bool isASCII = false;
132 if (HDFascii::isASCII(aUrl.c_str())) {
134 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
135 aC_HDFUrl = new char[strlen(aResultPath) + 19];
136 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
137 delete [] (aResultPath);
145 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
147 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
152 eStr = new char[strlen(aUrl.c_str())+17];
153 sprintf(eStr,"Can't open file %s",aUrl.c_str());
155 _errorCode = std::string(eStr);
159 // Temporary aStudyUrl in place of study name
160 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
162 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
165 Study->StudyId( _IDcounter );
167 // Assign the value of the URL in the study object
170 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
172 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
173 _errorCode = "Study is empty";
177 //Create the Structure of the Document
178 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
181 BuildTree (Study, hdf_group_study_structure);
185 char *eStr = new char [strlen(aUrl.c_str())+17];
186 sprintf(eStr,"Can't open file %s", aUrl.c_str());
187 _errorCode = std::string(eStr);
191 //Read and create notebook variables
192 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
193 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
194 ReadNoteBookVariables(Study,hdf_notebook_vars);
195 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
198 hdf_file->CloseOnDisk();
199 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
202 std::vector<std::string> aFilesToRemove;
203 aFilesToRemove.push_back("hdf_from_ascii.hdf");
204 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
207 delete hdf_file; // all related hdf objects will be deleted
214 //============================================================================
216 * Purpose : Close a study.
217 * If the study hasn't been saved, ask the user to confirm the
218 * close action without saving
221 //============================================================================
222 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
227 _errorCode = "Study is null";
232 DF_Document* doc=aStudy->GetDocument();
236 //============================================================================
238 * Purpose : Save a Study to it's persistent reference
240 //============================================================================
241 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
242 SALOMEDSImpl_DriverFactory* aFactory,
247 std::string url = aStudy->URL();
249 _errorCode = "No path specified to save the study. Nothing done";
253 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
259 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
260 SALOMEDSImpl_DriverFactory* aFactory,
265 std::string url = aStudy->URL();
267 _errorCode = "No path specified to save the study. Nothing done";
271 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
277 //=============================================================================
278 /*! Function : SaveAs
279 * Purpose : Save a study to the persistent reference aUrl
281 //============================================================================
282 bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl,
283 SALOMEDSImpl_Study* aStudy,
284 SALOMEDSImpl_DriverFactory* aFactory,
288 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
291 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl,
292 SALOMEDSImpl_Study* aStudy,
293 SALOMEDSImpl_DriverFactory* aFactory,
297 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
300 //============================================================================
301 /*! Function : GetOpenStudies
302 * Purpose : Get name list of open studies in the session
304 //============================================================================
305 std::vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
308 std::vector<SALOMEDSImpl_Study*> aList;
310 int nbDocs = _appli->NbDocuments();
313 _errorCode = "No active study in this session";
317 SALOMEDSImpl_Study* aStudy;
318 std::vector<int> ids = _appli->GetDocumentIDs();
319 for (int i = 0, len = ids.size(); i<len; i++) {
320 DF_Document* D = _appli->GetDocument(ids[i]);
321 if(D == _clipboard) continue;
322 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
323 if(!aStudy) continue;
324 aList.push_back(aStudy);
331 //============================================================================
332 /*! Function : GetStudyByName
333 * Purpose : Get a study from its name
335 //============================================================================
336 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
337 (const std::string& aStudyName)
340 int nbDocs = _appli->NbDocuments();
343 _errorCode = "No active study in this session";
347 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
348 for (int i = 0, len = studies.size(); i<len; i++) {
349 if (studies[i]->Name() == aStudyName) return studies[i];
353 _errorCode = std::string("Found no study with the name ") + aStudyName;
357 //============================================================================
358 /*! Function : GetStudyByID
359 * Purpose : Get a study from its ID
361 //============================================================================
362 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
365 int nbDocs = _appli->NbDocuments();
368 _errorCode = "No active study in this session";
372 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
373 for (int i = 0, len = studies.size(); i<len; i++) {
374 if (studies[i]->StudyId() == aStudyID) return studies[i];
378 _errorCode = "Found no study with the given ID";
382 //=============================================================================
383 /*! Function : _SaveProperties
384 * Purpose : save the study properties in HDF file
386 //============================================================================
387 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
392 HDFdataset *hdf_dataset = 0;
396 // add modifications list (user and date of save)
397 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
398 int aLocked = aProp->IsLocked();
399 if (aLocked) aProp->SetLocked(false);
401 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
402 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
403 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
404 mn, hh, day, month, year);
406 if (aLocked) aProp->SetLocked(true);
408 std::vector<std::string> aNames;
409 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
411 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
413 int aLength = 0, anIndex, i;
414 for(i=1; i<=aNames.size(); i++)
415 aLength += aNames[i-1].size() + 1;
417 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
418 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
421 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
423 aLength = aNames.size();
425 for(anIndex = 0; anIndex<aLength; anIndex++) {
426 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
427 (int)(aMinutes[anIndex]),
428 (int)(aHours[anIndex]),
429 (int)(aDays[anIndex]),
430 (int)(aMonths[anIndex]),
431 (int)(aYears[anIndex]),
432 aNames[anIndex].c_str());
433 a = strlen(aProperty);
438 name_len = (hdf_int32) a;
439 size[0] = name_len + 1 ;
440 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
441 hdf_dataset->CreateOnDisk();
442 hdf_dataset->WriteOnDisk(aProperty);
443 hdf_dataset->CloseOnDisk();
444 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
447 aProp->SetModified(0);
451 //=============================================================================
452 /*! Function : _SaveAs
453 * Purpose : save the study in HDF file
455 //============================================================================
456 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl,
457 SALOMEDSImpl_Study* aStudy,
458 SALOMEDSImpl_DriverFactory* aFactory,
462 // HDF File will be composed of differents part :
463 // * For each ComponentDataType, all data created by the component
464 // Informations in data group hdf_group_datacomponent
465 // * Study Structure -> Exactly what is contained in Document
466 // Informations in data group hdf_group_study_structure
471 HDFgroup *hdf_group_study_structure =0;
472 HDFgroup *hdf_sco_group =0;
473 HDFgroup *hdf_sco_group2 =0;
474 HDFgroup *hdf_notebook_vars =0;
475 HDFgroup *hdf_notebook_var = 0;
477 HDFgroup *hdf_group_datacomponent =0;
478 HDFdataset *hdf_dataset =0;
480 hdf_int32 name_len = 0;
481 std::string component_name;
484 _errorCode = "Study is null";
488 //Create a temporary url to which the study is saved
489 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
491 int aLocked = aStudy->GetProperties()->IsLocked();
492 if (aLocked) aStudy->GetProperties()->SetLocked(false);
494 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
495 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
499 // mpv 15.12.2003: for saving components we have to load all data from all modules
500 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
501 for (; itcomponent1.More(); itcomponent1.Next())
503 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
504 // if there is an associated Engine call its method for saving
505 std::string IOREngine;
507 if (!sco.ComponentIOR(IOREngine)) {
508 std::string aCompType = sco.GetComment();
509 if (!aCompType.empty()) {
511 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
512 aMapTypeDriver[aCompType] = aDriver;
514 if (aDriver != NULL) {
515 if(!SB->LoadWith(sco, aDriver)) {
516 _errorCode = SB->GetErrorCode();
523 _errorCode = "Can not restore information to resave it";
528 std::string anOldName = aStudy->Name();
529 aStudy->URL(aStudyUrl);
531 // To change for Save
532 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
533 hdf_file = new HDFfile((char*)aUrl.c_str());
534 hdf_file->CreateOnDisk();
536 //-----------------------------------------------------------------------
537 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
538 //-----------------------------------------------------------------------
539 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
540 hdf_group_datacomponent->CreateOnDisk();
542 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
544 for (; itcomponent.More(); itcomponent.Next())
546 SALOMEDSImpl_SComponent sco = itcomponent.Value();
548 std::string scoid = sco.GetID();
549 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
550 hdf_sco_group->CreateOnDisk();
552 std::string componentDataType = sco.ComponentDataType();
553 std::string IOREngine;
554 if (sco.ComponentIOR(IOREngine))
556 SALOMEDSImpl_Driver* Engine = NULL;
557 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
558 // we have found the associated engine to write the data
559 Engine = aMapTypeDriver[componentDataType];
562 Engine = aFactory->GetDriverByIOR(IOREngine);
567 SALOMEDSImpl_TMPFile* aStream = NULL;
570 if (theASCII) aStream = Engine->SaveASCII(sco,
571 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
574 else aStream = Engine->Save(sco,
575 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
578 HDFdataset *hdf_dataset;
579 hdf_size aHDFSize[1];
580 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
582 aHDFSize[0] = length;
584 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
585 hdf_dataset->CreateOnDisk();
586 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
587 hdf_dataset->CloseOnDisk();
590 if(aStream) delete aStream;
592 // store multifile state
594 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
595 hdf_dataset->CreateOnDisk();
596 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
597 hdf_dataset->CloseOnDisk();
598 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
601 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
602 hdf_dataset->CreateOnDisk();
603 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
604 hdf_dataset->CloseOnDisk();
605 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
606 // Creation of the persistance reference attribute
607 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
610 hdf_sco_group->CloseOnDisk();
611 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
613 hdf_group_datacomponent->CloseOnDisk();
614 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
616 //-----------------------------------------------------------------------
617 //3 - Write the Study Structure
618 //-----------------------------------------------------------------------
619 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
620 hdf_group_study_structure->CreateOnDisk();
621 // save component attributes
622 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
623 for (; itcomp.More(); itcomp.Next())
625 SALOMEDSImpl_SComponent SC = itcomp.Value();
626 std::string scid = SC.GetID();
627 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
628 hdf_sco_group2->CreateOnDisk();
629 SaveAttributes(SC, hdf_sco_group2);
630 // ComponentDataType treatment
631 component_name = SC.ComponentDataType();
632 name_len = (hdf_int32)component_name.length();
633 size[0] = name_len +1 ;
634 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
635 hdf_dataset->CreateOnDisk();
636 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
637 hdf_dataset->CloseOnDisk();
638 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
639 Impl_SaveObject(SC, hdf_sco_group2);
640 hdf_sco_group2->CloseOnDisk();
641 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
643 //-----------------------------------------------------------------------
644 //4 - Write the Study UseCases Structure
645 //-----------------------------------------------------------------------
646 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
648 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
649 hdf_soo_group->CreateOnDisk();
650 SaveAttributes(aSO, hdf_soo_group);
651 Impl_SaveObject(aSO, hdf_soo_group);
652 hdf_soo_group->CloseOnDisk();
653 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
655 //-----------------------------------------------------------------------
656 //5 - Write the NoteBook Variables
657 //-----------------------------------------------------------------------
659 //5.1 Create group to store all note book variables
660 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
661 hdf_notebook_vars->CreateOnDisk();
663 std::string varValue;
665 std::string varIndex;
667 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
668 // For each variable create HDF group
669 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
670 hdf_notebook_var->CreateOnDisk();
672 // Save Variable type
673 varType = aStudy->myNoteBookVars[i]->SaveType();
674 name_len = (hdf_int32) varType.length();
675 size[0] = name_len +1 ;
676 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
677 hdf_dataset->CreateOnDisk();
678 hdf_dataset->WriteOnDisk((char*)varType.c_str());
679 hdf_dataset->CloseOnDisk();
680 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
683 sprintf(buffer,"%d",i);
684 varIndex= std::string(buffer);
685 name_len = (hdf_int32) varIndex.length();
686 size[0] = name_len +1 ;
687 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
688 hdf_dataset->CreateOnDisk();
689 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
690 hdf_dataset->CloseOnDisk();
691 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
694 // Save Variable value
695 varValue = aStudy->myNoteBookVars[i]->Save();
696 name_len = (hdf_int32) varValue.length();
697 size[0] = name_len +1 ;
698 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
699 hdf_dataset->CreateOnDisk();
700 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
701 hdf_dataset->CloseOnDisk();
702 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
703 hdf_notebook_var->CloseOnDisk();
704 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
706 hdf_notebook_vars->CloseOnDisk();
707 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
709 if (aLocked) aStudy->GetProperties()->SetLocked(true);
710 //-----------------------------------------------------------------------
711 //6 - Write the Study Properties
712 //-----------------------------------------------------------------------
713 std::string study_name = aStudy->Name();
714 name_len = (hdf_int32) study_name.size();
715 size[0] = name_len +1 ;
716 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
717 hdf_dataset->CreateOnDisk();
718 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
719 hdf_dataset->CloseOnDisk();
720 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
722 Impl_SaveProperties(aStudy, hdf_group_study_structure);
723 hdf_group_study_structure->CloseOnDisk();
724 hdf_file->CloseOnDisk();
726 aStudy->IsSaved(true);
727 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
728 delete hdf_file; // recursively deletes all hdf objects...
732 _errorCode = "HDFexception ! ";
735 catch(std::exception& exc)
737 _errorCode = const_cast<char*>(exc.what());
742 _errorCode = "Unknown exception ! ";
745 if (theASCII) { // save file in ASCII format
746 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
749 //Now it's necessary to copy files from the temporary directory to the user defined directory.
751 // The easiest way to get a list of file in the temporary directory
753 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
754 std::string aTmpFile = aTmpFileDir +"files";
755 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
758 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
760 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
762 system(aCmd.c_str());
764 // Iterate and move files in the temporary directory
765 FILE* fp = fopen(aTmpFile.c_str(), "r");
766 if(!fp) return false;
767 char* buffer = new char[2047];
769 if((fgets(buffer, 2046, fp)) == NULL) break;
770 size_t aLen = strlen(buffer);
771 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
773 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
775 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
777 system(aCmd.c_str());
785 DeleteFileA(aTmpFile.c_str());
787 unlink(aTmpFile.c_str());
791 RemoveDirectoryA(aTmpFileDir.c_str());
792 RemoveDirectoryA(aStudyTmpDir.c_str());
794 rmdir(aTmpFileDir.c_str());
795 rmdir(aStudyTmpDir.c_str());
801 //============================================================================
802 /*! Function : Impl_SaveObject
805 //============================================================================
806 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
807 HDFgroup *hdf_group_datatype)
811 // Write in group hdf_group_datatype all informations of SObject SC
812 // Iterative function to parse all SObjects under a SComponent
814 HDFgroup *hdf_group_sobject = 0;
816 DF_ChildIterator itchild(SC.GetLabel());
817 for (; itchild.More(); itchild.Next())
820 // mpv: don't save empty labels
821 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
822 if (attr.size() == 0) { //No attributes on the label
823 DF_ChildIterator subchild(itchild.Value());
824 if (!subchild.More()) {
827 subchild.Init(itchild.Value(), true);
829 for (; subchild.More() && anEmpty; subchild.Next()) {
830 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
832 anEmpty = false; //There are attributes on the child label
836 if (anEmpty) continue;
839 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
841 std::string scoid = SO.GetID();
842 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
843 hdf_group_sobject->CreateOnDisk();
844 SaveAttributes(SO, hdf_group_sobject);
845 Impl_SaveObject(SO, hdf_group_sobject);
846 hdf_group_sobject->CloseOnDisk();
847 hdf_group_sobject =0; // will be deleted by father hdf object destructor
853 //============================================================================
854 /*! Function : Impl_SubstituteSlash
857 //============================================================================
858 std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl)
862 std::string theUrl(aUrl);
863 for(int i = 0; i<theUrl.size(); i++)
864 if(theUrl[i] == '/') theUrl[i] = ':';
868 //============================================================================
869 /*! Function : GetDocumentOfStudy
872 //============================================================================
873 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
876 return theStudy->_doc;
879 //============================================================================
880 /*! Function : CanCopy
883 //============================================================================
884 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
885 SALOMEDSImpl_Driver* theEngine)
888 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
889 if (!aComponent) return false;
890 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
891 std::string IOREngine;
892 if (!aComponent.ComponentIOR(IOREngine)) return false;
893 if (theEngine == NULL) return false;
894 return theEngine->CanCopy(theObject);
897 //============================================================================
898 /*! Function : CopyLabel
901 //============================================================================
902 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
903 SALOMEDSImpl_Driver* theEngine,
904 const int theSourceStartDepth,
905 const DF_Label& theSource,
906 const DF_Label& theDestinationMain)
911 DF_Label aTargetLabel = theDestinationMain;
912 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
913 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
914 DF_Label aSourceLabel = theSource;
915 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
916 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
917 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
919 // iterate attributes
920 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
921 for(int i = 0, len = attrList.size(); i<len; i++) {
922 DF_Attribute* anAttr = attrList[i];
923 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
924 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
925 if (type == std::string("AttributeTarget")) continue; // and target attribute
927 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
928 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
929 std::string anEntry = aReferenced.Entry();
930 // store the value of name attribute of referenced label
931 SALOMEDSImpl_AttributeName* aNameAttribute;
932 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
934 anEntry += aNameAttribute->Value();
936 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
940 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
941 std::string anEntry = theSource.Entry();
942 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
945 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
946 std::string aResStr("");
947 for(a = 0; a < aLen; a++) {
948 aResStr += (char)(aStream->Get(a));
951 if(aStream) delete aStream;
953 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
954 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
957 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
958 aTargetLabel.AddAttribute(aNewAttribute);
959 anAttr->Paste(aNewAttribute);
965 //============================================================================
969 //============================================================================
970 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
971 SALOMEDSImpl_Driver* theEngine)
975 // adoptation for alliances datamodel copy: without IOR attributes !!!
976 bool aStructureOnly; // copy only SObjects and attributes without component help
977 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
979 // get component-engine
980 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
982 // CAF document of current study usage
983 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
985 _errorCode = "Document is null";
989 //Clear the clipboard
990 _clipboard->Main().Root().ForgetAllAttributes(true);
991 _appli->Close(_clipboard);
992 _clipboard = _appli->NewDocument("SALOME_STUDY");
994 // set component data type to the name attribute of root label
995 if (!aStructureOnly) {
996 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
997 theEngine->ComponentDataType());
999 // set to the Root label integer attribute: study id
1000 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1001 // iterate all theObject's label children
1002 DF_Label aStartLabel = theObject.GetLabel();
1003 int aSourceStartDepth = aStartLabel.Depth();
1005 // copy main source label
1006 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1008 // copy all subchildren of the main source label (all levels)
1009 DF_ChildIterator anIterator(aStartLabel, true);
1010 for(; anIterator.More(); anIterator.Next()) {
1011 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1016 //============================================================================
1017 /*! Function : CanPaste
1020 //============================================================================
1021 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1022 SALOMEDSImpl_Driver* theEngine)
1027 _errorCode = "Clipboard is null";
1031 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1032 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1033 _errorCode = "Clipboard has no component type";
1036 SALOMEDSImpl_AttributeInteger* anObjID;
1037 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1038 _errorCode = "Clipboard has no object id";
1041 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1043 _errorCode = "Object doesn't belong to component";
1047 std::string IOREngine;
1048 if (!aComponent.ComponentIOR(IOREngine)) {
1049 _errorCode = "component has no IOR";
1052 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1055 //============================================================================
1056 /*! Function : PasteLabel
1059 //============================================================================
1060 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1061 SALOMEDSImpl_Driver* theEngine,
1062 const DF_Label& theSource,
1063 const DF_Label& theDestinationStart,
1064 const int theCopiedStudyID,
1065 const bool isFirstElement)
1069 // get corresponding source, target and auxiliary labels
1070 DF_Label aTargetLabel = theDestinationStart;
1072 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1074 if (!isFirstElement) {
1075 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1076 DF_Label aSourceLabel = theSource;
1077 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1078 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1079 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1083 // check auxiliary label for TMPFile => IOR
1084 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1085 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1086 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1087 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1088 std::string aCompName = aComponentName->Value();
1090 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1091 std::string aTMPStr = aNameAttribute->Value();
1092 int aLen = aTMPStr.size();
1093 unsigned char* aStream = NULL;
1095 aStream = new unsigned char[aLen+10];
1096 for(a = 0; a < aLen; a++) {
1097 aStream[a] = aTMPStr[a];
1101 std::string anEntry = aTargetLabel.Entry();
1102 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1104 if (isFirstElement) {
1105 std::string aDestEntry = theEngine->PasteInto(aStream,
1108 aPastedSO.GetFatherComponent());
1109 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1111 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1113 if(aStream != NULL) delete []aStream;
1117 // iterate attributes
1118 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1119 for(int i = 0, len = attrList.size(); i<len; i++) {
1120 DF_Attribute* anAttr = attrList[i];
1121 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1122 aTargetLabel.ForgetAttribute(anAttr->ID());
1124 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1125 aTargetLabel.AddAttribute(aNewAttribute);
1126 anAttr->Paste(aNewAttribute);
1129 // check auxiliary label for Comment => reference or name attribute of the referenced object
1130 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1131 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1132 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1133 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1134 char* aNameStart = strchr(anEntry, ' ');
1139 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1140 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1141 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1142 // target attributes structure support
1143 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1145 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1146 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1151 return aTargetLabel;
1154 //============================================================================
1155 /*! Function : Paste
1158 //============================================================================
1159 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1160 SALOMEDSImpl_Driver* theEngine)
1164 SALOMEDSImpl_SObject so;
1165 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1167 // if study is locked, then paste can't be done
1168 if (aStudy->GetProperties()->IsLocked()) {
1169 _errorCode = "LockProtection";
1170 throw LockProtection("LockProtection");
1173 // if there is no component name, then paste only SObjects and attributes: without component help
1174 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1175 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1177 // get copied study ID
1178 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1179 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1180 _errorCode = "No study ID was found";
1183 int aCStudyID = aStudyIDAttribute->Value();
1185 // CAF document of current study usage
1186 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1188 _errorCode = "Document is null";
1192 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1194 // fill root inserted SObject
1195 DF_Label aStartLabel;
1196 if (aStructureOnly) {
1197 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1198 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1200 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1201 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1204 // paste all sublebels
1205 DF_ChildIterator anIterator(_clipboard->Main(), true);
1206 for(; anIterator.More(); anIterator.Next()) {
1207 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1210 return SALOMEDSImpl_Study::SObject(aStartLabel);
1213 //#######################################################################################################
1214 //# STATIC PRIVATE FUNCTIONS
1215 //#######################################################################################################
1217 //============================================================================
1218 /*! Function : SaveAttributes
1219 * Purpose : Save attributes for object
1221 //============================================================================
1222 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1225 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1226 DF_Attribute* anAttr = NULL;
1227 for(int i = 0, len = attrList.size(); i<len; i++) {
1228 anAttr = attrList[i];
1229 //The following attributes are not supposed to be written to the file
1230 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1231 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
1232 std::string aSaveStr =anAttr->Save();
1233 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1234 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1235 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1236 hdf_dataset->CreateOnDisk();
1237 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1238 hdf_dataset->CloseOnDisk();
1239 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1243 //===========================================================================
1244 //Function : ReadAttributes
1245 //===========================================================================
1246 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1247 const SALOMEDSImpl_SObject& aSO,
1248 HDFdataset* hdf_dataset)
1250 hdf_dataset->OpenOnDisk();
1252 DF_Attribute* anAttr = NULL;
1253 char* current_string = new char[hdf_dataset->GetSize()+1];
1254 hdf_dataset->ReadFromDisk(current_string);
1255 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1256 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1257 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1258 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1259 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1260 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1261 delete [] (current_string);
1262 hdf_dataset->CloseOnDisk();
1265 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1269 anAttr->Load(current_string);
1272 delete [] (current_string);
1273 hdf_dataset->CloseOnDisk();
1276 //============================================================================
1277 //Function : BuildlTree
1278 //============================================================================
1279 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1281 hdf_current_group->OpenOnDisk();
1282 SALOMEDSImpl_SObject aSO;
1283 char* Entry = hdf_current_group->GetName();
1284 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1285 aSO = theStudy->CreateObjectID("0:1");
1288 aSO = theStudy->CreateObjectID(Entry);
1291 char name[HDF_NAME_MAX_LEN+1];
1292 int nbsons = hdf_current_group->nInternalObjects();
1293 for (int i=0; i<nbsons; i++) {
1294 hdf_current_group->InternalObjectIndentify(i,name);
1295 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1296 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1298 if (type == HDF_DATASET) {
1299 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1300 ReadAttributes(theStudy,aSO,new_dataset);
1301 new_dataset = 0; // will be deleted by father destructor
1304 else if (type == HDF_GROUP) {
1305 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1306 BuildTree (theStudy, new_group);
1307 new_group = 0; // will be deleted by father destructor
1310 hdf_current_group->CloseOnDisk();
1314 //============================================================================
1315 //Function : Translate_IOR_to_persistentID
1316 //============================================================================
1317 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1318 SALOMEDSImpl_Driver* engine,
1322 DF_ChildIterator itchild(so.GetLabel());
1323 std::string ior_string, persistent_string, curid;
1325 for (; itchild.More(); itchild.Next()) {
1326 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1327 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1328 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1329 ior_string = IOR->Value();
1331 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1332 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1334 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1338 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1343 HDFgroup* new_group =0;
1344 HDFdataset* new_dataset =0;
1346 char aVarName[HDF_NAME_MAX_LEN+1];
1347 char *currentVarType = 0;
1348 char *currentVarValue = 0;
1349 char *currentVarIndex = 0;
1351 //Open HDF group with notebook variables
1352 theGroup->OpenOnDisk();
1354 //Get Nb of variables
1355 int aNbVars = theGroup->nInternalObjects();
1357 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1359 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1360 theGroup->InternalObjectIndentify(iVar,aVarName);
1361 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1362 if(type == HDF_GROUP) {
1365 new_group = new HDFgroup(aVarName,theGroup);
1366 new_group->OpenOnDisk();
1369 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1370 new_dataset->OpenOnDisk();
1371 currentVarType = new char[new_dataset->GetSize()+1];
1372 new_dataset->ReadFromDisk(currentVarType);
1373 new_dataset->CloseOnDisk();
1374 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1377 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1378 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1379 new_dataset->OpenOnDisk();
1380 currentVarIndex = new char[new_dataset->GetSize()+1];
1381 new_dataset->ReadFromDisk(currentVarIndex);
1382 new_dataset->CloseOnDisk();
1383 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1384 order = atoi(currentVarIndex);
1385 delete [] currentVarIndex;
1391 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1392 new_dataset->OpenOnDisk();
1393 currentVarValue = new char[new_dataset->GetSize()+1];
1394 new_dataset->ReadFromDisk(currentVarValue);
1395 new_dataset->CloseOnDisk();
1396 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1398 new_group->CloseOnDisk();
1399 new_group = 0; //will be deleted by hdf_sco_group destructor
1401 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1402 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
1403 delete [] currentVarType;
1405 //Create variable and add it in the study
1406 SALOMEDSImpl_GenericVariable* aVariable =
1407 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
1408 aVariable->Load(std::string(currentVarValue));
1409 aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1410 delete [] currentVarValue;
1414 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1415 for(;it!=aVarsMap.end();it++)
1416 theStudy->AddVariable((*it).second);
1418 theGroup->CloseOnDisk();