1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_StudyManager.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_StudyManager.hxx"
29 #include "DF_ChildIterator.hxx"
30 #include "HDFexplorer.hxx"
32 #include "SALOMEDSImpl_Attributes.hxx"
33 #include "SALOMEDSImpl_Tool.hxx"
34 #include "SALOMEDSImpl_SComponent.hxx"
35 #include "SALOMEDSImpl_GenericAttribute.hxx"
36 #include "SALOMEDSImpl_ScalarVariable.hxx"
48 //Warning undef of Ascii Winwows define
53 #define USE_CASE_LABEL_ID "0:2"
55 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
56 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
57 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
58 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
59 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
60 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
62 //============================================================================
63 /*! Function : SALOMEDSImpl_StudyManager
64 * Purpose : SALOMEDSImpl_StudyManager constructor
66 //============================================================================
67 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
70 _appli = new DF_Application();
72 _clipboard = _appli->NewDocument("SALOME_STUDY");
75 //============================================================================
76 /*! Function : ~SALOMEDSImpl_StudyManager
77 * Purpose : SALOMEDSImpl_StudyManager destructor
79 //============================================================================
80 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
82 _appli->Close(_clipboard);
83 // Destroy application
88 //============================================================================
89 /*! Function : NewStudy
90 * Purpose : Create a New Study of name study_name
92 //==================================================T==========================
93 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const std::string& study_name)
97 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
99 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
102 Study->StudyId( _IDcounter );
104 // set Study properties
105 SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
107 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
108 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
109 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
110 mn, hh, day, month, year);
111 aProp->SetCreationMode(1); //"from scratch"
116 //============================================================================
118 * Purpose : Open a Study from it's persistent reference
120 //============================================================================
121 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const std::string& aUrl)
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());
136 aC_HDFUrl = new char[strlen(aResultPath) + 19];
137 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
138 delete [] (aResultPath);
146 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
148 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
153 eStr = new char[strlen(aUrl.c_str())+17];
154 sprintf(eStr,"Can't open file %s",aUrl.c_str());
156 _errorCode = std::string(eStr);
160 // Temporary aStudyUrl in place of study name
161 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
163 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
166 Study->StudyId( _IDcounter );
168 // Assign the value of the URL in the study object
171 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
173 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
174 _errorCode = "Study is empty";
178 //Create the Structure of the Document
179 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
182 BuildTree (Study, hdf_group_study_structure);
186 char *eStr = new char [strlen(aUrl.c_str())+17];
187 sprintf(eStr,"Can't open file %s", aUrl.c_str());
188 _errorCode = std::string(eStr);
192 //Read and create notebook variables
193 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
194 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
195 ReadNoteBookVariables(Study,hdf_notebook_vars);
196 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
199 hdf_file->CloseOnDisk();
200 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
203 std::vector<std::string> aFilesToRemove;
204 aFilesToRemove.push_back("hdf_from_ascii.hdf");
205 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
208 delete hdf_file; // all related hdf objects will be deleted
215 //============================================================================
217 * Purpose : Close a study.
218 * If the study hasn't been saved, ask the user to confirm the
219 * close action without saving
222 //============================================================================
223 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
228 _errorCode = "Study is null";
233 DF_Document* doc=aStudy->GetDocument();
237 //============================================================================
239 * Purpose : Save a Study to it's persistent reference
241 //============================================================================
242 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
243 SALOMEDSImpl_DriverFactory* aFactory,
248 std::string url = aStudy->URL();
250 _errorCode = "No path specified to save the study. Nothing done";
254 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
260 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
261 SALOMEDSImpl_DriverFactory* aFactory,
266 std::string url = aStudy->URL();
268 _errorCode = "No path specified to save the study. Nothing done";
272 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
278 //=============================================================================
279 /*! Function : SaveAs
280 * Purpose : Save a study to the persistent reference aUrl
282 //============================================================================
283 bool SALOMEDSImpl_StudyManager::SaveAs(const std::string& aUrl,
284 SALOMEDSImpl_Study* aStudy,
285 SALOMEDSImpl_DriverFactory* aFactory,
289 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
292 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const std::string& aUrl,
293 SALOMEDSImpl_Study* aStudy,
294 SALOMEDSImpl_DriverFactory* aFactory,
298 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
301 //============================================================================
302 /*! Function : GetOpenStudies
303 * Purpose : Get name list of open studies in the session
305 //============================================================================
306 std::vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
309 std::vector<SALOMEDSImpl_Study*> aList;
311 int nbDocs = _appli->NbDocuments();
314 _errorCode = "No active study in this session";
318 SALOMEDSImpl_Study* aStudy;
319 std::vector<int> ids = _appli->GetDocumentIDs();
320 for (int i = 0, len = ids.size(); i<len; i++) {
321 DF_Document* D = _appli->GetDocument(ids[i]);
322 if(D == _clipboard) continue;
323 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
324 if(!aStudy) continue;
325 aList.push_back(aStudy);
332 //============================================================================
333 /*! Function : GetStudyByName
334 * Purpose : Get a study from its name
336 //============================================================================
337 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
338 (const std::string& aStudyName)
341 int nbDocs = _appli->NbDocuments();
344 _errorCode = "No active study in this session";
348 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
349 for (int i = 0, len = studies.size(); i<len; i++) {
350 if (studies[i]->Name() == aStudyName) return studies[i];
354 _errorCode = std::string("Found no study with the name ") + aStudyName;
358 //============================================================================
359 /*! Function : GetStudyByID
360 * Purpose : Get a study from its ID
362 //============================================================================
363 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
366 int nbDocs = _appli->NbDocuments();
369 _errorCode = "No active study in this session";
373 std::vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
374 for (int i = 0, len = studies.size(); i<len; i++) {
375 if (studies[i]->StudyId() == aStudyID) return studies[i];
379 _errorCode = "Found no study with the given ID";
383 //=============================================================================
384 /*! Function : _SaveProperties
385 * Purpose : save the study properties in HDF file
387 //============================================================================
388 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
393 HDFdataset *hdf_dataset = 0;
397 // add modifications list (user and date of save)
398 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
399 int aLocked = aProp->IsLocked();
400 if (aLocked) aProp->SetLocked(false);
402 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
403 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
404 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
405 mn, hh, day, month, year);
407 if (aLocked) aProp->SetLocked(true);
409 std::vector<std::string> aNames;
410 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
412 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
414 int aLength = 0, anIndex, i;
415 for(i=1; i<=aNames.size(); i++)
416 aLength += aNames[i-1].size() + 1;
418 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
419 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
422 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
424 aLength = aNames.size();
426 for(anIndex = 0; anIndex<aLength; anIndex++) {
427 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
428 (int)(aMinutes[anIndex]),
429 (int)(aHours[anIndex]),
430 (int)(aDays[anIndex]),
431 (int)(aMonths[anIndex]),
432 (int)(aYears[anIndex]),
433 aNames[anIndex].c_str());
434 a = strlen(aProperty);
439 name_len = (hdf_int32) a;
440 size[0] = name_len + 1 ;
441 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
442 hdf_dataset->CreateOnDisk();
443 hdf_dataset->WriteOnDisk(aProperty);
444 hdf_dataset->CloseOnDisk();
445 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
448 aProp->SetModified(0);
452 //=============================================================================
453 /*! Function : _SaveAs
454 * Purpose : save the study in HDF file
456 //============================================================================
457 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const std::string& aStudyUrl,
458 SALOMEDSImpl_Study* aStudy,
459 SALOMEDSImpl_DriverFactory* aFactory,
463 // HDF File will be composed of differents part :
464 // * For each ComponentDataType, all data created by the component
465 // Informations in data group hdf_group_datacomponent
466 // * Study Structure -> Exactly what is contained in Document
467 // Informations in data group hdf_group_study_structure
472 HDFgroup *hdf_group_study_structure =0;
473 HDFgroup *hdf_sco_group =0;
474 HDFgroup *hdf_sco_group2 =0;
475 HDFgroup *hdf_notebook_vars =0;
476 HDFgroup *hdf_notebook_var = 0;
478 HDFgroup *hdf_group_datacomponent =0;
479 HDFdataset *hdf_dataset =0;
481 hdf_int32 name_len = 0;
482 std::string component_name;
485 _errorCode = "Study is null";
489 //Create a temporary url to which the study is saved
490 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
492 int aLocked = aStudy->GetProperties()->IsLocked();
493 if (aLocked) aStudy->GetProperties()->SetLocked(false);
495 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
496 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
500 // mpv 15.12.2003: for saving components we have to load all data from all modules
501 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
502 for (; itcomponent1.More(); itcomponent1.Next())
504 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
505 // if there is an associated Engine call its method for saving
506 std::string IOREngine;
508 if (!sco.ComponentIOR(IOREngine)) {
509 std::string aCompType = sco.GetComment();
510 if (!aCompType.empty()) {
512 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
513 aMapTypeDriver[aCompType] = aDriver;
515 if (aDriver != NULL) {
516 if(!SB->LoadWith(sco, aDriver)) {
517 _errorCode = SB->GetErrorCode();
524 _errorCode = "Can not restore information to resave it";
529 std::string anOldName = aStudy->Name();
530 aStudy->URL(aStudyUrl);
532 // To change for Save
533 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
534 hdf_file = new HDFfile((char*)aUrl.c_str());
535 hdf_file->CreateOnDisk();
537 //-----------------------------------------------------------------------
538 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
539 //-----------------------------------------------------------------------
540 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
541 hdf_group_datacomponent->CreateOnDisk();
543 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
545 for (; itcomponent.More(); itcomponent.Next())
547 SALOMEDSImpl_SComponent sco = itcomponent.Value();
549 std::string scoid = sco.GetID();
550 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
551 hdf_sco_group->CreateOnDisk();
553 std::string componentDataType = sco.ComponentDataType();
554 std::string IOREngine;
555 if (sco.ComponentIOR(IOREngine))
557 SALOMEDSImpl_Driver* Engine = NULL;
558 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
559 // we have found the associated engine to write the data
560 Engine = aMapTypeDriver[componentDataType];
563 Engine = aFactory->GetDriverByIOR(IOREngine);
568 SALOMEDSImpl_TMPFile* aStream = NULL;
571 if (theASCII) aStream = Engine->SaveASCII(sco,
572 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
575 else aStream = Engine->Save(sco,
576 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
579 HDFdataset *hdf_dataset;
580 hdf_size aHDFSize[1];
581 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
583 aHDFSize[0] = length;
585 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
586 hdf_dataset->CreateOnDisk();
587 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
588 hdf_dataset->CloseOnDisk();
591 if(aStream) delete aStream;
593 // store multifile state
595 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
596 hdf_dataset->CreateOnDisk();
597 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
598 hdf_dataset->CloseOnDisk();
599 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
602 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
603 hdf_dataset->CreateOnDisk();
604 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
605 hdf_dataset->CloseOnDisk();
606 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
607 // Creation of the persistance reference attribute
608 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
611 hdf_sco_group->CloseOnDisk();
612 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
614 hdf_group_datacomponent->CloseOnDisk();
615 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
617 //-----------------------------------------------------------------------
618 //3 - Write the Study Structure
619 //-----------------------------------------------------------------------
620 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
621 hdf_group_study_structure->CreateOnDisk();
622 // save component attributes
623 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
624 for (; itcomp.More(); itcomp.Next())
626 SALOMEDSImpl_SComponent SC = itcomp.Value();
627 std::string scid = SC.GetID();
628 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
629 hdf_sco_group2->CreateOnDisk();
630 SaveAttributes(SC, hdf_sco_group2);
631 // ComponentDataType treatment
632 component_name = SC.ComponentDataType();
633 name_len = (hdf_int32)component_name.length();
634 size[0] = name_len +1 ;
635 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
636 hdf_dataset->CreateOnDisk();
637 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
638 hdf_dataset->CloseOnDisk();
639 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
640 Impl_SaveObject(SC, hdf_sco_group2);
641 hdf_sco_group2->CloseOnDisk();
642 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
644 //-----------------------------------------------------------------------
645 //4 - Write the Study UseCases Structure
646 //-----------------------------------------------------------------------
647 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
649 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
650 hdf_soo_group->CreateOnDisk();
651 SaveAttributes(aSO, hdf_soo_group);
652 Impl_SaveObject(aSO, hdf_soo_group);
653 hdf_soo_group->CloseOnDisk();
654 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
656 //-----------------------------------------------------------------------
657 //5 - Write the NoteBook Variables
658 //-----------------------------------------------------------------------
660 //5.1 Create group to store all note book variables
661 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
662 hdf_notebook_vars->CreateOnDisk();
664 std::string varValue;
666 std::string varIndex;
668 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
669 // For each variable create HDF group
670 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
671 hdf_notebook_var->CreateOnDisk();
673 // Save Variable type
674 varType = aStudy->myNoteBookVars[i]->SaveType();
675 name_len = (hdf_int32) varType.length();
676 size[0] = name_len +1 ;
677 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
678 hdf_dataset->CreateOnDisk();
679 hdf_dataset->WriteOnDisk((char*)varType.c_str());
680 hdf_dataset->CloseOnDisk();
681 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
684 sprintf(buffer,"%d",i);
685 varIndex= std::string(buffer);
686 name_len = (hdf_int32) varIndex.length();
687 size[0] = name_len +1 ;
688 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
689 hdf_dataset->CreateOnDisk();
690 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
691 hdf_dataset->CloseOnDisk();
692 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
695 // Save Variable value
696 varValue = aStudy->myNoteBookVars[i]->Save();
697 name_len = (hdf_int32) varValue.length();
698 size[0] = name_len +1 ;
699 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
700 hdf_dataset->CreateOnDisk();
701 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
702 hdf_dataset->CloseOnDisk();
703 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
704 hdf_notebook_var->CloseOnDisk();
705 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
707 hdf_notebook_vars->CloseOnDisk();
708 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
710 if (aLocked) aStudy->GetProperties()->SetLocked(true);
711 //-----------------------------------------------------------------------
712 //6 - Write the Study Properties
713 //-----------------------------------------------------------------------
714 std::string study_name = aStudy->Name();
715 name_len = (hdf_int32) study_name.size();
716 size[0] = name_len +1 ;
717 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
718 hdf_dataset->CreateOnDisk();
719 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
720 hdf_dataset->CloseOnDisk();
721 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
723 Impl_SaveProperties(aStudy, hdf_group_study_structure);
724 hdf_group_study_structure->CloseOnDisk();
725 hdf_file->CloseOnDisk();
727 aStudy->IsSaved(true);
728 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
729 delete hdf_file; // recursively deletes all hdf objects...
733 _errorCode = "HDFexception ! ";
736 catch(std::exception& exc)
738 _errorCode = const_cast<char*>(exc.what());
743 _errorCode = "Unknown exception ! ";
746 if (theASCII) { // save file in ASCII format
747 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
750 //Now it's necessary to copy files from the temporary directory to the user defined directory.
752 // The easiest way to get a list of file in the temporary directory
754 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
755 std::string aTmpFile = aTmpFileDir +"files";
756 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
759 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
761 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
763 system(aCmd.c_str());
765 // Iterate and move files in the temporary directory
766 FILE* fp = fopen(aTmpFile.c_str(), "r");
767 if(!fp) return false;
768 char* buffer = new char[2047];
770 if((fgets(buffer, 2046, fp)) == NULL) break;
771 size_t aLen = strlen(buffer);
772 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
774 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
776 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
778 system(aCmd.c_str());
786 DeleteFileA(aTmpFile.c_str());
788 unlink(aTmpFile.c_str());
792 RemoveDirectoryA(aTmpFileDir.c_str());
793 RemoveDirectoryA(aStudyTmpDir.c_str());
795 rmdir(aTmpFileDir.c_str());
796 rmdir(aStudyTmpDir.c_str());
802 //============================================================================
803 /*! Function : Impl_SaveObject
806 //============================================================================
807 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
808 HDFgroup *hdf_group_datatype)
812 // Write in group hdf_group_datatype all informations of SObject SC
813 // Iterative function to parse all SObjects under a SComponent
815 HDFgroup *hdf_group_sobject = 0;
817 DF_ChildIterator itchild(SC.GetLabel());
818 for (; itchild.More(); itchild.Next())
821 // mpv: don't save empty labels
822 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
823 if (attr.size() == 0) { //No attributes on the label
824 DF_ChildIterator subchild(itchild.Value());
825 if (!subchild.More()) {
828 subchild.Init(itchild.Value(), true);
830 for (; subchild.More() && anEmpty; subchild.Next()) {
831 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
833 anEmpty = false; //There are attributes on the child label
837 if (anEmpty) continue;
840 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
842 std::string scoid = SO.GetID();
843 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
844 hdf_group_sobject->CreateOnDisk();
845 SaveAttributes(SO, hdf_group_sobject);
846 Impl_SaveObject(SO, hdf_group_sobject);
847 hdf_group_sobject->CloseOnDisk();
848 hdf_group_sobject =0; // will be deleted by father hdf object destructor
854 //============================================================================
855 /*! Function : Impl_SubstituteSlash
858 //============================================================================
859 std::string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const std::string& aUrl)
863 std::string theUrl(aUrl);
864 for(int i = 0; i<theUrl.size(); i++)
865 if(theUrl[i] == '/') theUrl[i] = ':';
869 //============================================================================
870 /*! Function : GetDocumentOfStudy
873 //============================================================================
874 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
877 return theStudy->_doc;
880 //============================================================================
881 /*! Function : CanCopy
884 //============================================================================
885 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
886 SALOMEDSImpl_Driver* theEngine)
889 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
890 if (!aComponent) return false;
891 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
892 std::string IOREngine;
893 if (!aComponent.ComponentIOR(IOREngine)) return false;
894 if (theEngine == NULL) return false;
895 return theEngine->CanCopy(theObject);
898 //============================================================================
899 /*! Function : CopyLabel
902 //============================================================================
903 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
904 SALOMEDSImpl_Driver* theEngine,
905 const int theSourceStartDepth,
906 const DF_Label& theSource,
907 const DF_Label& theDestinationMain)
912 DF_Label aTargetLabel = theDestinationMain;
913 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
914 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
915 DF_Label aSourceLabel = theSource;
916 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
917 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
918 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
920 // iterate attributes
921 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
922 for(int i = 0, len = attrList.size(); i<len; i++) {
923 DF_Attribute* anAttr = attrList[i];
924 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
925 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
926 if (type == std::string("AttributeTarget")) continue; // and target attribute
928 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
929 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
930 std::string anEntry = aReferenced.Entry();
931 // store the value of name attribute of referenced label
932 SALOMEDSImpl_AttributeName* aNameAttribute;
933 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
935 anEntry += aNameAttribute->Value();
937 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
941 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
942 std::string anEntry = theSource.Entry();
943 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
946 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
947 std::string aResStr("");
948 for(a = 0; a < aLen; a++) {
949 aResStr += (char)(aStream->Get(a));
952 if(aStream) delete aStream;
954 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
955 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
958 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
959 aTargetLabel.AddAttribute(aNewAttribute);
960 anAttr->Paste(aNewAttribute);
966 //============================================================================
970 //============================================================================
971 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
972 SALOMEDSImpl_Driver* theEngine)
976 // adoptation for alliances datamodel copy: without IOR attributes !!!
977 bool aStructureOnly; // copy only SObjects and attributes without component help
978 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
980 // get component-engine
981 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
983 // CAF document of current study usage
984 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
986 _errorCode = "Document is null";
990 //Clear the clipboard
991 _clipboard->Main().Root().ForgetAllAttributes(true);
992 _appli->Close(_clipboard);
993 _clipboard = _appli->NewDocument("SALOME_STUDY");
995 // set component data type to the name attribute of root label
996 if (!aStructureOnly) {
997 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
998 theEngine->ComponentDataType());
1000 // set to the Root label integer attribute: study id
1001 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1002 // iterate all theObject's label children
1003 DF_Label aStartLabel = theObject.GetLabel();
1004 int aSourceStartDepth = aStartLabel.Depth();
1006 // copy main source label
1007 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1009 // copy all subchildren of the main source label (all levels)
1010 DF_ChildIterator anIterator(aStartLabel, true);
1011 for(; anIterator.More(); anIterator.Next()) {
1012 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1017 //============================================================================
1018 /*! Function : CanPaste
1021 //============================================================================
1022 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1023 SALOMEDSImpl_Driver* theEngine)
1028 _errorCode = "Clipboard is null";
1032 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1033 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1034 _errorCode = "Clipboard has no component type";
1037 SALOMEDSImpl_AttributeInteger* anObjID;
1038 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1039 _errorCode = "Clipboard has no object id";
1042 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1044 _errorCode = "Object doesn't belong to component";
1048 std::string IOREngine;
1049 if (!aComponent.ComponentIOR(IOREngine)) {
1050 _errorCode = "component has no IOR";
1053 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1056 //============================================================================
1057 /*! Function : PasteLabel
1060 //============================================================================
1061 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1062 SALOMEDSImpl_Driver* theEngine,
1063 const DF_Label& theSource,
1064 const DF_Label& theDestinationStart,
1065 const int theCopiedStudyID,
1066 const bool isFirstElement)
1070 // get corresponding source, target and auxiliary labels
1071 DF_Label aTargetLabel = theDestinationStart;
1073 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1075 if (!isFirstElement) {
1076 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1077 DF_Label aSourceLabel = theSource;
1078 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1079 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1080 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1084 // check auxiliary label for TMPFile => IOR
1085 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1086 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1087 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1088 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1089 std::string aCompName = aComponentName->Value();
1091 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1092 std::string aTMPStr = aNameAttribute->Value();
1093 int aLen = aTMPStr.size();
1094 unsigned char* aStream = NULL;
1096 aStream = new unsigned char[aLen+10];
1097 for(a = 0; a < aLen; a++) {
1098 aStream[a] = aTMPStr[a];
1102 std::string anEntry = aTargetLabel.Entry();
1103 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1105 if (isFirstElement) {
1106 std::string aDestEntry = theEngine->PasteInto(aStream,
1109 aPastedSO.GetFatherComponent());
1110 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1112 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1114 if(aStream != NULL) delete []aStream;
1118 // iterate attributes
1119 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1120 for(int i = 0, len = attrList.size(); i<len; i++) {
1121 DF_Attribute* anAttr = attrList[i];
1122 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1123 aTargetLabel.ForgetAttribute(anAttr->ID());
1125 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1126 aTargetLabel.AddAttribute(aNewAttribute);
1127 anAttr->Paste(aNewAttribute);
1130 // check auxiliary label for Comment => reference or name attribute of the referenced object
1131 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1132 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1133 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1134 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1135 char* aNameStart = strchr(anEntry, ' ');
1140 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1141 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1142 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1143 // target attributes structure support
1144 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1146 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1147 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1152 return aTargetLabel;
1155 //============================================================================
1156 /*! Function : Paste
1159 //============================================================================
1160 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1161 SALOMEDSImpl_Driver* theEngine)
1165 SALOMEDSImpl_SObject so;
1166 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1168 // if study is locked, then paste can't be done
1169 if (aStudy->GetProperties()->IsLocked()) {
1170 _errorCode = "LockProtection";
1171 throw LockProtection("LockProtection");
1174 // if there is no component name, then paste only SObjects and attributes: without component help
1175 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1176 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1178 // get copied study ID
1179 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1180 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1181 _errorCode = "No study ID was found";
1184 int aCStudyID = aStudyIDAttribute->Value();
1186 // CAF document of current study usage
1187 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1189 _errorCode = "Document is null";
1193 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1195 // fill root inserted SObject
1196 DF_Label aStartLabel;
1197 if (aStructureOnly) {
1198 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1199 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1201 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1202 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1205 // paste all sublebels
1206 DF_ChildIterator anIterator(_clipboard->Main(), true);
1207 for(; anIterator.More(); anIterator.Next()) {
1208 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1211 return SALOMEDSImpl_Study::SObject(aStartLabel);
1214 //#######################################################################################################
1215 //# STATIC PRIVATE FUNCTIONS
1216 //#######################################################################################################
1218 //============================================================================
1219 /*! Function : SaveAttributes
1220 * Purpose : Save attributes for object
1222 //============================================================================
1223 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1226 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1227 DF_Attribute* anAttr = NULL;
1228 for(int i = 0, len = attrList.size(); i<len; i++) {
1229 anAttr = attrList[i];
1230 //The following attributes are not supposed to be written to the file
1231 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1232 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
1233 std::string aSaveStr =anAttr->Save();
1234 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1235 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1236 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1237 hdf_dataset->CreateOnDisk();
1238 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1239 hdf_dataset->CloseOnDisk();
1240 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1244 //===========================================================================
1245 //Function : ReadAttributes
1246 //===========================================================================
1247 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1248 const SALOMEDSImpl_SObject& aSO,
1249 HDFdataset* hdf_dataset)
1251 hdf_dataset->OpenOnDisk();
1253 DF_Attribute* anAttr = NULL;
1254 char* current_string = new char[hdf_dataset->GetSize()+1];
1255 hdf_dataset->ReadFromDisk(current_string);
1256 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1257 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1258 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1259 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1260 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1261 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1262 delete [] (current_string);
1263 hdf_dataset->CloseOnDisk();
1266 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1270 anAttr->Load(current_string);
1273 delete [] (current_string);
1274 hdf_dataset->CloseOnDisk();
1277 //============================================================================
1278 //Function : BuildlTree
1279 //============================================================================
1280 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1282 hdf_current_group->OpenOnDisk();
1283 SALOMEDSImpl_SObject aSO;
1284 char* Entry = hdf_current_group->GetName();
1285 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1286 aSO = theStudy->CreateObjectID("0:1");
1289 aSO = theStudy->CreateObjectID(Entry);
1292 char name[HDF_NAME_MAX_LEN+1];
1293 int nbsons = hdf_current_group->nInternalObjects();
1294 for (int i=0; i<nbsons; i++) {
1295 hdf_current_group->InternalObjectIndentify(i,name);
1296 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1297 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1299 if (type == HDF_DATASET) {
1300 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1301 ReadAttributes(theStudy,aSO,new_dataset);
1302 new_dataset = 0; // will be deleted by father destructor
1305 else if (type == HDF_GROUP) {
1306 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1307 BuildTree (theStudy, new_group);
1308 new_group = 0; // will be deleted by father destructor
1311 hdf_current_group->CloseOnDisk();
1315 //============================================================================
1316 //Function : Translate_IOR_to_persistentID
1317 //============================================================================
1318 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1319 SALOMEDSImpl_Driver* engine,
1323 DF_ChildIterator itchild(so.GetLabel());
1324 std::string ior_string, persistent_string, curid;
1326 for (; itchild.More(); itchild.Next()) {
1327 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1328 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1329 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1330 ior_string = IOR->Value();
1332 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1333 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1335 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1339 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1344 HDFgroup* new_group =0;
1345 HDFdataset* new_dataset =0;
1347 char aVarName[HDF_NAME_MAX_LEN+1];
1348 char *currentVarType = 0;
1349 char *currentVarValue = 0;
1350 char *currentVarIndex = 0;
1352 //Open HDF group with notebook variables
1353 theGroup->OpenOnDisk();
1355 //Get Nb of variables
1356 int aNbVars = theGroup->nInternalObjects();
1358 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1360 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1361 theGroup->InternalObjectIndentify(iVar,aVarName);
1362 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1363 if(type == HDF_GROUP) {
1366 new_group = new HDFgroup(aVarName,theGroup);
1367 new_group->OpenOnDisk();
1370 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1371 new_dataset->OpenOnDisk();
1372 currentVarType = new char[new_dataset->GetSize()+1];
1373 new_dataset->ReadFromDisk(currentVarType);
1374 new_dataset->CloseOnDisk();
1375 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1378 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1379 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1380 new_dataset->OpenOnDisk();
1381 currentVarIndex = new char[new_dataset->GetSize()+1];
1382 new_dataset->ReadFromDisk(currentVarIndex);
1383 new_dataset->CloseOnDisk();
1384 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1385 order = atoi(currentVarIndex);
1386 delete [] currentVarIndex;
1392 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1393 new_dataset->OpenOnDisk();
1394 currentVarValue = new char[new_dataset->GetSize()+1];
1395 new_dataset->ReadFromDisk(currentVarValue);
1396 new_dataset->CloseOnDisk();
1397 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1399 new_group->CloseOnDisk();
1400 new_group = 0; //will be deleted by hdf_sco_group destructor
1402 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1403 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
1404 delete [] currentVarType;
1406 //Create variable and add it in the study
1407 SALOMEDSImpl_GenericVariable* aVariable =
1408 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
1409 aVariable->Load(std::string(currentVarValue));
1410 aVarsMap.insert(std::make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1411 delete [] currentVarValue;
1415 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1416 for(;it!=aVarsMap.end();it++)
1417 theStudy->AddVariable((*it).second);
1419 theGroup->CloseOnDisk();