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
54 #define USE_CASE_LABEL_ID "0:2"
56 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
57 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
58 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
59 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
60 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
61 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
63 //============================================================================
64 /*! Function : SALOMEDSImpl_StudyManager
65 * Purpose : SALOMEDSImpl_StudyManager constructor
67 //============================================================================
68 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
71 _appli = new DF_Application();
73 _clipboard = _appli->NewDocument("SALOME_STUDY");
76 //============================================================================
77 /*! Function : ~SALOMEDSImpl_StudyManager
78 * Purpose : SALOMEDSImpl_StudyManager destructor
80 //============================================================================
81 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
83 _appli->Close(_clipboard);
84 // Destroy application
89 //============================================================================
90 /*! Function : NewStudy
91 * Purpose : Create a New Study of name study_name
93 //==================================================T==========================
94 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const string& study_name)
98 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
100 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
103 Study->StudyId( _IDcounter );
105 // set Study properties
106 SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
108 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
109 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
110 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
111 mn, hh, day, month, year);
112 aProp->SetCreationMode(1); //"from scratch"
117 //============================================================================
119 * Purpose : Open a Study from it's persistent reference
121 //============================================================================
122 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl)
127 HDFfile *hdf_file =0;
128 HDFgroup *hdf_group_study_structure =0;
129 HDFgroup *hdf_notebook_vars = 0;
133 bool isASCII = false;
134 if (HDFascii::isASCII(aUrl.c_str())) {
136 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
137 aC_HDFUrl = new char[strlen(aResultPath) + 19];
138 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
139 delete [] (aResultPath);
147 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
149 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
154 eStr = new char[strlen(aUrl.c_str())+17];
155 sprintf(eStr,"Can't open file %s",aUrl.c_str());
157 _errorCode = string(eStr);
161 // Temporary aStudyUrl in place of study name
162 DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
164 SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
167 Study->StudyId( _IDcounter );
169 // Assign the value of the URL in the study object
172 SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
174 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
175 _errorCode = "Study is empty";
179 //Create the Structure of the Document
180 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
183 BuildTree (Study, hdf_group_study_structure);
187 char *eStr = new char [strlen(aUrl.c_str())+17];
188 sprintf(eStr,"Can't open file %s", aUrl.c_str());
189 _errorCode = string(eStr);
193 //Read and create notebook variables
194 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
195 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
196 ReadNoteBookVariables(Study,hdf_notebook_vars);
197 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
200 hdf_file->CloseOnDisk();
201 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
204 vector<string> aFilesToRemove;
205 aFilesToRemove.push_back("hdf_from_ascii.hdf");
206 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
209 delete hdf_file; // all related hdf objects will be deleted
216 //============================================================================
218 * Purpose : Close a study.
219 * If the study hasn't been saved, ask the user to confirm the
220 * close action without saving
223 //============================================================================
224 void SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
229 _errorCode = "Study is null";
234 DF_Document* doc=aStudy->GetDocument();
238 //============================================================================
240 * Purpose : Save a Study to it's persistent reference
242 //============================================================================
243 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
244 SALOMEDSImpl_DriverFactory* aFactory,
249 string url = aStudy->URL();
251 _errorCode = "No path specified to save the study. Nothing done";
255 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
261 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
262 SALOMEDSImpl_DriverFactory* aFactory,
267 string url = aStudy->URL();
269 _errorCode = "No path specified to save the study. Nothing done";
273 return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
279 //=============================================================================
280 /*! Function : SaveAs
281 * Purpose : Save a study to the persistent reference aUrl
283 //============================================================================
284 bool SALOMEDSImpl_StudyManager::SaveAs(const string& aUrl,
285 SALOMEDSImpl_Study* aStudy,
286 SALOMEDSImpl_DriverFactory* aFactory,
290 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
293 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const string& aUrl,
294 SALOMEDSImpl_Study* aStudy,
295 SALOMEDSImpl_DriverFactory* aFactory,
299 return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
302 //============================================================================
303 /*! Function : GetOpenStudies
304 * Purpose : Get name list of open studies in the session
306 //============================================================================
307 vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
310 vector<SALOMEDSImpl_Study*> aList;
312 int nbDocs = _appli->NbDocuments();
315 _errorCode = "No active study in this session";
319 SALOMEDSImpl_Study* aStudy;
320 vector<int> ids = _appli->GetDocumentIDs();
321 for (int i = 0, len = ids.size(); i<len; i++) {
322 DF_Document* D = _appli->GetDocument(ids[i]);
323 if(D == _clipboard) continue;
324 aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
325 if(!aStudy) continue;
326 aList.push_back(aStudy);
333 //============================================================================
334 /*! Function : GetStudyByName
335 * Purpose : Get a study from its name
337 //============================================================================
338 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
339 (const string& aStudyName)
342 int nbDocs = _appli->NbDocuments();
345 _errorCode = "No active study in this session";
349 vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
350 for (int i = 0, len = studies.size(); i<len; i++) {
351 if (studies[i]->Name() == aStudyName) return studies[i];
355 _errorCode = string("Found no study with the name ") + aStudyName;
359 //============================================================================
360 /*! Function : GetStudyByID
361 * Purpose : Get a study from its ID
363 //============================================================================
364 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
367 int nbDocs = _appli->NbDocuments();
370 _errorCode = "No active study in this session";
374 vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
375 for (int i = 0, len = studies.size(); i<len; i++) {
376 if (studies[i]->StudyId() == aStudyID) return studies[i];
380 _errorCode = "Found no study with the given ID";
384 //=============================================================================
385 /*! Function : _SaveProperties
386 * Purpose : save the study properties in HDF file
388 //============================================================================
389 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
394 HDFdataset *hdf_dataset = 0;
398 // add modifications list (user and date of save)
399 SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
400 int aLocked = aProp->IsLocked();
401 if (aLocked) aProp->SetLocked(false);
403 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
404 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
405 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
406 mn, hh, day, month, year);
408 if (aLocked) aProp->SetLocked(true);
410 vector<string> aNames;
411 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
413 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
415 int aLength = 0, anIndex, i;
416 for(i=1; i<=aNames.size(); i++)
417 aLength += aNames[i-1].size() + 1;
419 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
420 char* aProperty = new char[3 + aLength + 12 * aNames.size()];
423 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
425 aLength = aNames.size();
427 for(anIndex = 0; anIndex<aLength; anIndex++) {
428 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
429 (int)(aMinutes[anIndex]),
430 (int)(aHours[anIndex]),
431 (int)(aDays[anIndex]),
432 (int)(aMonths[anIndex]),
433 (int)(aYears[anIndex]),
434 aNames[anIndex].c_str());
435 a = strlen(aProperty);
440 name_len = (hdf_int32) a;
441 size[0] = name_len + 1 ;
442 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
443 hdf_dataset->CreateOnDisk();
444 hdf_dataset->WriteOnDisk(aProperty);
445 hdf_dataset->CloseOnDisk();
446 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
449 aProp->SetModified(0);
453 //=============================================================================
454 /*! Function : _SaveAs
455 * Purpose : save the study in HDF file
457 //============================================================================
458 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aStudyUrl,
459 SALOMEDSImpl_Study* aStudy,
460 SALOMEDSImpl_DriverFactory* aFactory,
464 // HDF File will be composed of differents part :
465 // * For each ComponentDataType, all data created by the component
466 // Informations in data group hdf_group_datacomponent
467 // * Study Structure -> Exactly what is contained in Document
468 // Informations in data group hdf_group_study_structure
473 HDFgroup *hdf_group_study_structure =0;
474 HDFgroup *hdf_sco_group =0;
475 HDFgroup *hdf_sco_group2 =0;
476 HDFgroup *hdf_notebook_vars =0;
477 HDFgroup *hdf_notebook_var = 0;
479 HDFgroup *hdf_group_datacomponent =0;
480 HDFdataset *hdf_dataset =0;
482 hdf_int32 name_len = 0;
483 string component_name;
486 _errorCode = "Study is null";
490 //Create a temporary url to which the study is saved
491 string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
493 int aLocked = aStudy->GetProperties()->IsLocked();
494 if (aLocked) aStudy->GetProperties()->SetLocked(false);
496 SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
497 map<string, SALOMEDSImpl_Driver*> aMapTypeDriver;
501 // mpv 15.12.2003: for saving components we have to load all data from all modules
502 SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
503 for (; itcomponent1.More(); itcomponent1.Next())
505 SALOMEDSImpl_SComponent sco = itcomponent1.Value();
506 // if there is an associated Engine call its method for saving
509 if (!sco.ComponentIOR(IOREngine)) {
510 string aCompType = sco.GetComment();
511 if (!aCompType.empty()) {
513 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
514 aMapTypeDriver[aCompType] = aDriver;
516 if (aDriver != NULL) {
517 if(!SB->LoadWith(sco, aDriver)) {
518 _errorCode = SB->GetErrorCode();
525 _errorCode = "Can not restore information to resave it";
530 string anOldName = aStudy->Name();
531 aStudy->URL(aStudyUrl);
533 // To change for Save
534 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
535 hdf_file = new HDFfile((char*)aUrl.c_str());
536 hdf_file->CreateOnDisk();
538 //-----------------------------------------------------------------------
539 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
540 //-----------------------------------------------------------------------
541 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
542 hdf_group_datacomponent->CreateOnDisk();
544 SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
546 for (; itcomponent.More(); itcomponent.Next())
548 SALOMEDSImpl_SComponent sco = itcomponent.Value();
550 string scoid = sco.GetID();
551 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
552 hdf_sco_group->CreateOnDisk();
554 string componentDataType = sco.ComponentDataType();
556 if (sco.ComponentIOR(IOREngine))
558 SALOMEDSImpl_Driver* Engine = NULL;
559 if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
560 // we have found the associated engine to write the data
561 Engine = aMapTypeDriver[componentDataType];
564 Engine = aFactory->GetDriverByIOR(IOREngine);
569 SALOMEDSImpl_TMPFile* aStream = NULL;
572 if (theASCII) aStream = Engine->SaveASCII(sco,
573 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
576 else aStream = Engine->Save(sco,
577 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
580 HDFdataset *hdf_dataset;
581 hdf_size aHDFSize[1];
582 if(length > 0) { //The component saved some auxiliary files, then put them into HDF file
584 aHDFSize[0] = length;
586 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
587 hdf_dataset->CreateOnDisk();
588 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
589 hdf_dataset->CloseOnDisk();
592 if(aStream) delete aStream;
594 // store multifile state
596 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
597 hdf_dataset->CreateOnDisk();
598 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
599 hdf_dataset->CloseOnDisk();
600 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
603 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
604 hdf_dataset->CreateOnDisk();
605 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
606 hdf_dataset->CloseOnDisk();
607 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
608 // Creation of the persistance reference attribute
609 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
612 hdf_sco_group->CloseOnDisk();
613 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
615 hdf_group_datacomponent->CloseOnDisk();
616 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
618 //-----------------------------------------------------------------------
619 //3 - Write the Study Structure
620 //-----------------------------------------------------------------------
621 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
622 hdf_group_study_structure->CreateOnDisk();
623 // save component attributes
624 SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
625 for (; itcomp.More(); itcomp.Next())
627 SALOMEDSImpl_SComponent SC = itcomp.Value();
628 string scid = SC.GetID();
629 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
630 hdf_sco_group2->CreateOnDisk();
631 SaveAttributes(SC, hdf_sco_group2);
632 // ComponentDataType treatment
633 component_name = SC.ComponentDataType();
634 name_len = (hdf_int32)component_name.length();
635 size[0] = name_len +1 ;
636 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
637 hdf_dataset->CreateOnDisk();
638 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
639 hdf_dataset->CloseOnDisk();
640 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
641 Impl_SaveObject(SC, hdf_sco_group2);
642 hdf_sco_group2->CloseOnDisk();
643 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
645 //-----------------------------------------------------------------------
646 //4 - Write the Study UseCases Structure
647 //-----------------------------------------------------------------------
648 SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
650 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
651 hdf_soo_group->CreateOnDisk();
652 SaveAttributes(aSO, hdf_soo_group);
653 Impl_SaveObject(aSO, hdf_soo_group);
654 hdf_soo_group->CloseOnDisk();
655 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
657 //-----------------------------------------------------------------------
658 //5 - Write the NoteBook Variables
659 //-----------------------------------------------------------------------
661 //5.1 Create group to store all note book variables
662 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
663 hdf_notebook_vars->CreateOnDisk();
669 for(int i=0 ;i < aStudy->myNoteBookVars.size(); i++ ){
670 // For each variable create HDF group
671 hdf_notebook_var = new HDFgroup((char*)aStudy->myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
672 hdf_notebook_var->CreateOnDisk();
674 // Save Variable type
675 varType = aStudy->myNoteBookVars[i]->SaveType();
676 name_len = (hdf_int32) varType.length();
677 size[0] = name_len +1 ;
678 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
679 hdf_dataset->CreateOnDisk();
680 hdf_dataset->WriteOnDisk((char*)varType.c_str());
681 hdf_dataset->CloseOnDisk();
682 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
685 sprintf(buffer,"%d",i);
686 varIndex= string(buffer);
687 name_len = (hdf_int32) varIndex.length();
688 size[0] = name_len +1 ;
689 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
690 hdf_dataset->CreateOnDisk();
691 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
692 hdf_dataset->CloseOnDisk();
693 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
696 // Save Variable value
697 varValue = aStudy->myNoteBookVars[i]->Save();
698 name_len = (hdf_int32) varValue.length();
699 size[0] = name_len +1 ;
700 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
701 hdf_dataset->CreateOnDisk();
702 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
703 hdf_dataset->CloseOnDisk();
704 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
705 hdf_notebook_var->CloseOnDisk();
706 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
708 hdf_notebook_vars->CloseOnDisk();
709 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
711 if (aLocked) aStudy->GetProperties()->SetLocked(true);
712 //-----------------------------------------------------------------------
713 //6 - Write the Study Properties
714 //-----------------------------------------------------------------------
715 string study_name = aStudy->Name();
716 name_len = (hdf_int32) study_name.size();
717 size[0] = name_len +1 ;
718 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
719 hdf_dataset->CreateOnDisk();
720 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
721 hdf_dataset->CloseOnDisk();
722 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
724 Impl_SaveProperties(aStudy, hdf_group_study_structure);
725 hdf_group_study_structure->CloseOnDisk();
726 hdf_file->CloseOnDisk();
728 aStudy->IsSaved(true);
729 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
730 delete hdf_file; // recursively deletes all hdf objects...
734 _errorCode = "HDFexception ! ";
737 catch(std::exception& exc)
739 _errorCode = const_cast<char*>(exc.what());
744 _errorCode = "Unknown exception ! ";
747 if (theASCII) { // save file in ASCII format
748 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
751 //Now it's necessary to copy files from the temporary directory to the user defined directory.
753 // The easiest way to get a list of file in the temporary directory
755 string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
756 string aTmpFile = aTmpFileDir +"files";
757 string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
760 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
762 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
764 system(aCmd.c_str());
766 // Iterate and move files in the temporary directory
767 FILE* fp = fopen(aTmpFile.c_str(), "r");
768 if(!fp) return false;
769 char* buffer = new char[2047];
771 if((fgets(buffer, 2046, fp)) == NULL) break;
772 size_t aLen = strlen(buffer);
773 if(buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
775 aCmd = "move /Y \"" + aStudyTmpDir + string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
777 aCmd = "mv -f \"" + aStudyTmpDir + string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
779 system(aCmd.c_str());
787 DeleteFileA(aTmpFile.c_str());
789 unlink(aTmpFile.c_str());
793 RemoveDirectoryA(aTmpFileDir.c_str());
794 RemoveDirectoryA(aStudyTmpDir.c_str());
796 rmdir(aTmpFileDir.c_str());
797 rmdir(aStudyTmpDir.c_str());
803 //============================================================================
804 /*! Function : Impl_SaveObject
807 //============================================================================
808 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
809 HDFgroup *hdf_group_datatype)
813 // Write in group hdf_group_datatype all informations of SObject SC
814 // Iterative function to parse all SObjects under a SComponent
816 HDFgroup *hdf_group_sobject = 0;
818 DF_ChildIterator itchild(SC.GetLabel());
819 for (; itchild.More(); itchild.Next())
822 // mpv: don't save empty labels
823 vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
824 if (attr.size() == 0) { //No attributes on the label
825 DF_ChildIterator subchild(itchild.Value());
826 if (!subchild.More()) {
829 subchild.Init(itchild.Value(), true);
831 for (; subchild.More() && anEmpty; subchild.Next()) {
832 vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
834 anEmpty = false; //There are attributes on the child label
838 if (anEmpty) continue;
841 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
843 string scoid = SO.GetID();
844 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
845 hdf_group_sobject->CreateOnDisk();
846 SaveAttributes(SO, hdf_group_sobject);
847 Impl_SaveObject(SO, hdf_group_sobject);
848 hdf_group_sobject->CloseOnDisk();
849 hdf_group_sobject =0; // will be deleted by father hdf object destructor
855 //============================================================================
856 /*! Function : Impl_SubstituteSlash
859 //============================================================================
860 string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const string& aUrl)
864 std::string theUrl(aUrl);
865 for(int i = 0; i<theUrl.size(); i++)
866 if(theUrl[i] == '/') theUrl[i] = ':';
870 //============================================================================
871 /*! Function : GetDocumentOfStudy
874 //============================================================================
875 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
878 return theStudy->_doc;
881 //============================================================================
882 /*! Function : CanCopy
885 //============================================================================
886 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
887 SALOMEDSImpl_Driver* theEngine)
890 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
891 if (!aComponent) return false;
892 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
894 if (!aComponent.ComponentIOR(IOREngine)) return false;
895 if (theEngine == NULL) return false;
896 return theEngine->CanCopy(theObject);
899 //============================================================================
900 /*! Function : CopyLabel
903 //============================================================================
904 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
905 SALOMEDSImpl_Driver* theEngine,
906 const int theSourceStartDepth,
907 const DF_Label& theSource,
908 const DF_Label& theDestinationMain)
913 DF_Label aTargetLabel = theDestinationMain;
914 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
915 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
916 DF_Label aSourceLabel = theSource;
917 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
918 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
919 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
921 // iterate attributes
922 vector<DF_Attribute*> attrList = theSource.GetAttributes();
923 for(int i = 0, len = attrList.size(); i<len; i++) {
924 DF_Attribute* anAttr = attrList[i];
925 string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
926 if (type.substr(0, 17) == string("AttributeTreeNode")) continue; // never copy tree node attribute
927 if (type == string("AttributeTarget")) continue; // and target attribute
929 if (type == string("AttributeReference")) { // reference copied as Comment in aux tree
930 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
931 string anEntry = aReferenced.Entry();
932 // store the value of name attribute of referenced label
933 SALOMEDSImpl_AttributeName* aNameAttribute;
934 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
936 anEntry += aNameAttribute->Value();
938 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
942 if (type == string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
943 string anEntry = theSource.Entry();
944 SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
947 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
949 for(a = 0; a < aLen; a++) {
950 aResStr += (char)(aStream->Get(a));
953 if(aStream) delete aStream;
955 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
956 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
959 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
960 aTargetLabel.AddAttribute(aNewAttribute);
961 anAttr->Paste(aNewAttribute);
967 //============================================================================
971 //============================================================================
972 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
973 SALOMEDSImpl_Driver* theEngine)
977 // adoptation for alliances datamodel copy: without IOR attributes !!!
978 bool aStructureOnly; // copy only SObjects and attributes without component help
979 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
981 // get component-engine
982 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
984 // CAF document of current study usage
985 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
987 _errorCode = "Document is null";
991 //Clear the clipboard
992 _clipboard->Main().Root().ForgetAllAttributes(true);
993 _appli->Close(_clipboard);
994 _clipboard = _appli->NewDocument("SALOME_STUDY");
996 // set component data type to the name attribute of root label
997 if (!aStructureOnly) {
998 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
999 theEngine->ComponentDataType());
1001 // set to the Root label integer attribute: study id
1002 SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
1003 // iterate all theObject's label children
1004 DF_Label aStartLabel = theObject.GetLabel();
1005 int aSourceStartDepth = aStartLabel.Depth();
1007 // copy main source label
1008 CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
1010 // copy all subchildren of the main source label (all levels)
1011 DF_ChildIterator anIterator(aStartLabel, true);
1012 for(; anIterator.More(); anIterator.Next()) {
1013 CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1018 //============================================================================
1019 /*! Function : CanPaste
1022 //============================================================================
1023 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
1024 SALOMEDSImpl_Driver* theEngine)
1029 _errorCode = "Clipboard is null";
1033 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1034 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1035 _errorCode = "Clipboard has no component type";
1038 SALOMEDSImpl_AttributeInteger* anObjID;
1039 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1040 _errorCode = "Clipboard has no object id";
1043 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1045 _errorCode = "Object doesn't belong to component";
1050 if (!aComponent.ComponentIOR(IOREngine)) {
1051 _errorCode = "component has no IOR";
1054 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1057 //============================================================================
1058 /*! Function : PasteLabel
1061 //============================================================================
1062 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
1063 SALOMEDSImpl_Driver* theEngine,
1064 const DF_Label& theSource,
1065 const DF_Label& theDestinationStart,
1066 const int theCopiedStudyID,
1067 const bool isFirstElement)
1071 // get corresponding source, target and auxiliary labels
1072 DF_Label aTargetLabel = theDestinationStart;
1074 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1076 if (!isFirstElement) {
1077 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1078 DF_Label aSourceLabel = theSource;
1079 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1080 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1081 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1085 // check auxiliary label for TMPFile => IOR
1086 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1087 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1088 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1089 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1090 string aCompName = aComponentName->Value();
1092 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1093 std::string aTMPStr = aNameAttribute->Value();
1094 int aLen = aTMPStr.size();
1095 unsigned char* aStream = NULL;
1097 aStream = new unsigned char[aLen+10];
1098 for(a = 0; a < aLen; a++) {
1099 aStream[a] = aTMPStr[a];
1103 string anEntry = aTargetLabel.Entry();
1104 SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
1106 if (isFirstElement) {
1107 string aDestEntry = theEngine->PasteInto(aStream,
1110 aPastedSO.GetFatherComponent());
1111 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1113 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1115 if(aStream != NULL) delete []aStream;
1119 // iterate attributes
1120 vector<DF_Attribute*> attrList = theSource.GetAttributes();
1121 for(int i = 0, len = attrList.size(); i<len; i++) {
1122 DF_Attribute* anAttr = attrList[i];
1123 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1124 aTargetLabel.ForgetAttribute(anAttr->ID());
1126 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1127 aTargetLabel.AddAttribute(aNewAttribute);
1128 anAttr->Paste(aNewAttribute);
1131 // check auxiliary label for Comment => reference or name attribute of the referenced object
1132 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1133 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1134 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1135 strcpy(anEntry, string(aCommentAttribute->Value()).c_str());
1136 char* aNameStart = strchr(anEntry, ' ');
1141 if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1142 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1143 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1144 // target attributes structure support
1145 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1147 if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1148 else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1153 return aTargetLabel;
1156 //============================================================================
1157 /*! Function : Paste
1160 //============================================================================
1161 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1162 SALOMEDSImpl_Driver* theEngine)
1166 SALOMEDSImpl_SObject so;
1167 SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1169 // if study is locked, then paste can't be done
1170 if (aStudy->GetProperties()->IsLocked()) {
1171 _errorCode = "LockProtection";
1172 throw LockProtection("LockProtection");
1175 // if there is no component name, then paste only SObjects and attributes: without component help
1176 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1177 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1179 // get copied study ID
1180 SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1181 if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1182 _errorCode = "No study ID was found";
1185 int aCStudyID = aStudyIDAttribute->Value();
1187 // CAF document of current study usage
1188 DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1190 _errorCode = "Document is null";
1194 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1196 // fill root inserted SObject
1197 DF_Label aStartLabel;
1198 if (aStructureOnly) {
1199 DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1200 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1202 DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1203 aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1206 // paste all sublebels
1207 DF_ChildIterator anIterator(_clipboard->Main(), true);
1208 for(; anIterator.More(); anIterator.Next()) {
1209 PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1212 return SALOMEDSImpl_Study::SObject(aStartLabel);
1215 //#######################################################################################################
1216 //# STATIC PRIVATE FUNCTIONS
1217 //#######################################################################################################
1219 //============================================================================
1220 /*! Function : SaveAttributes
1221 * Purpose : Save attributes for object
1223 //============================================================================
1224 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1227 vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1228 DF_Attribute* anAttr = NULL;
1229 for(int i = 0, len = attrList.size(); i<len; i++) {
1230 anAttr = attrList[i];
1231 //The following attributes are not supposed to be written to the file
1232 string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1233 if(type == string("AttributeIOR")) continue; //IOR attribute is not saved
1234 string aSaveStr =anAttr->Save();
1235 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1236 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1237 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1238 hdf_dataset->CreateOnDisk();
1239 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1240 hdf_dataset->CloseOnDisk();
1241 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1245 //===========================================================================
1246 //Function : ReadAttributes
1247 //===========================================================================
1248 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1249 const SALOMEDSImpl_SObject& aSO,
1250 HDFdataset* hdf_dataset)
1252 hdf_dataset->OpenOnDisk();
1254 DF_Attribute* anAttr = NULL;
1255 char* current_string = new char[hdf_dataset->GetSize()+1];
1256 hdf_dataset->ReadFromDisk(current_string);
1257 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
1258 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1259 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1260 } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1261 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1262 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1263 delete [] (current_string);
1264 hdf_dataset->CloseOnDisk();
1267 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1271 anAttr->Load(current_string);
1274 delete [] (current_string);
1275 hdf_dataset->CloseOnDisk();
1278 //============================================================================
1279 //Function : BuildlTree
1280 //============================================================================
1281 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1283 hdf_current_group->OpenOnDisk();
1284 SALOMEDSImpl_SObject aSO;
1285 char* Entry = hdf_current_group->GetName();
1286 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1287 aSO = theStudy->CreateObjectID("0:1");
1290 aSO = theStudy->CreateObjectID(Entry);
1293 char name[HDF_NAME_MAX_LEN+1];
1294 int nbsons = hdf_current_group->nInternalObjects();
1295 for (int i=0; i<nbsons; i++) {
1296 hdf_current_group->InternalObjectIndentify(i,name);
1297 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1298 hdf_object_type type = hdf_current_group->InternalObjectType(name);
1300 if (type == HDF_DATASET) {
1301 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1302 ReadAttributes(theStudy,aSO,new_dataset);
1303 new_dataset = 0; // will be deleted by father destructor
1306 else if (type == HDF_GROUP) {
1307 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1308 BuildTree (theStudy, new_group);
1309 new_group = 0; // will be deleted by father destructor
1312 hdf_current_group->CloseOnDisk();
1316 //============================================================================
1317 //Function : Translate_IOR_to_persistentID
1318 //============================================================================
1319 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1320 SALOMEDSImpl_Driver* engine,
1324 DF_ChildIterator itchild(so.GetLabel());
1325 string ior_string, persistent_string, curid;
1327 for (; itchild.More(); itchild.Next()) {
1328 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1329 SALOMEDSImpl_AttributeIOR* IOR = NULL;
1330 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1331 ior_string = IOR->Value();
1333 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1334 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1336 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1340 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
1345 HDFgroup* new_group =0;
1346 HDFdataset* new_dataset =0;
1348 char aVarName[HDF_NAME_MAX_LEN+1];
1349 char *currentVarType = 0;
1350 char *currentVarValue = 0;
1351 char *currentVarIndex = 0;
1353 //Open HDF group with notebook variables
1354 theGroup->OpenOnDisk();
1356 //Get Nb of variables
1357 int aNbVars = theGroup->nInternalObjects();
1359 map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
1361 for( int iVar=0;iVar < aNbVars;iVar++ ) {
1362 theGroup->InternalObjectIndentify(iVar,aVarName);
1363 hdf_object_type type = theGroup->InternalObjectType(aVarName);
1364 if(type == HDF_GROUP) {
1367 new_group = new HDFgroup(aVarName,theGroup);
1368 new_group->OpenOnDisk();
1371 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
1372 new_dataset->OpenOnDisk();
1373 currentVarType = new char[new_dataset->GetSize()+1];
1374 new_dataset->ReadFromDisk(currentVarType);
1375 new_dataset->CloseOnDisk();
1376 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1379 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
1380 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
1381 new_dataset->OpenOnDisk();
1382 currentVarIndex = new char[new_dataset->GetSize()+1];
1383 new_dataset->ReadFromDisk(currentVarIndex);
1384 new_dataset->CloseOnDisk();
1385 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1386 order = atoi(currentVarIndex);
1387 delete [] currentVarIndex;
1393 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
1394 new_dataset->OpenOnDisk();
1395 currentVarValue = new char[new_dataset->GetSize()+1];
1396 new_dataset->ReadFromDisk(currentVarValue);
1397 new_dataset->CloseOnDisk();
1398 new_dataset = 0; //will be deleted by hdf_sco_group destructor
1400 new_group->CloseOnDisk();
1401 new_group = 0; //will be deleted by hdf_sco_group destructor
1403 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
1404 SALOMEDSImpl_GenericVariable::String2VariableType(string(currentVarType));
1405 delete [] currentVarType;
1407 //Create variable and add it in the study
1408 SALOMEDSImpl_GenericVariable* aVariable =
1409 new SALOMEDSImpl_ScalarVariable(aVarType,string(aVarName));
1410 aVariable->Load(string(currentVarValue));
1411 aVarsMap.insert(make_pair<int,SALOMEDSImpl_GenericVariable*>(order,aVariable));
1412 delete [] currentVarValue;
1416 map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
1417 for(;it!=aVarsMap.end();it++)
1418 theStudy->AddVariable((*it).second);
1420 theGroup->CloseOnDisk();