Salome HOME
Optimized method GetSObject
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_StudyManager.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDSImpl_StudyManager.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDSImpl_StudyManager.hxx"
25
26 #include "DF_ChildIterator.hxx"
27 #include "HDFexplorer.hxx"
28
29 #include "SALOMEDSImpl_Attributes.hxx"
30 #include "SALOMEDSImpl_Tool.hxx"
31 #include "SALOMEDSImpl_SComponent.hxx"
32 #include "SALOMEDSImpl_GenericAttribute.hxx"
33 #include <map>
34
35 #include "HDFOI.hxx"
36 #include <iostream>
37 #include <stdlib.h>
38
39 using namespace std;
40
41 #define USE_CASE_LABEL_ID                       "0:2"
42
43 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
44 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
45 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
46 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
47                                            SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
48
49 //============================================================================
50 /*! Function : SALOMEDSImpl_StudyManager
51  *  Purpose  : SALOMEDSImpl_StudyManager constructor
52  */
53 //============================================================================
54 SALOMEDSImpl_StudyManager::SALOMEDSImpl_StudyManager()
55 {
56   _errorCode = "";
57   _appli = new DF_Application();
58   _IDcounter = 0;
59   _clipboard = _appli->NewDocument("SALOME_STUDY");
60 }
61
62 //============================================================================
63 /*! Function : ~SALOMEDSImpl_StudyManager
64  *  Purpose  : SALOMEDSImpl_StudyManager destructor
65  */
66 //============================================================================
67 SALOMEDSImpl_StudyManager::~SALOMEDSImpl_StudyManager()
68 {
69   // Destroy application
70   delete _appli;    
71 }
72
73
74 //============================================================================
75 /*! Function : NewStudy
76  *  Purpose  : Create a New Study of name study_name
77  */
78 //==================================================T==========================
79 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::NewStudy(const string& study_name)
80 {
81   _errorCode = "";
82
83   DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
84
85   SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, study_name);
86
87   _IDcounter++;
88   Study->StudyId( _IDcounter );
89
90   // set Study properties
91   SALOMEDSImpl_AttributeStudyProperties* aProp = Study->GetProperties();
92   
93   int month=0,day=0,year=0,hh=0,mn=0,ss=0;
94   SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
95   aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
96                          mn, hh, day, month, year);
97   aProp->SetCreationMode(1);  //"from scratch"
98
99   return Study;
100 }
101
102 //============================================================================
103 /*! Function : Open
104  *  Purpose  : Open a Study from it's persistent reference
105  */
106 //============================================================================
107 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::Open(const string& aUrl)
108 {
109   _errorCode = "";
110
111   // open the HDFFile
112   HDFfile *hdf_file =0;
113   HDFgroup *hdf_group_study_structure =0;
114
115   char* aC_HDFUrl;
116   string aHDFUrl;
117   bool isASCII = false;
118   if (HDFascii::isASCII(aUrl.c_str())) {
119     isASCII = true;
120     char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
121     aC_HDFUrl = new char[strlen(aResultPath) + 19];
122     sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
123     delete(aResultPath);
124     aHDFUrl = aC_HDFUrl;
125     delete aC_HDFUrl;
126   } else {
127     aHDFUrl = aUrl;
128   }
129
130   
131   hdf_file = new HDFfile((char*)aHDFUrl.c_str());
132   try {
133     hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
134   }
135   catch (HDFexception)
136     {
137 //#ifndef WNT
138 //      char eStr[strlen(aUrl.ToCString())+17];
139 //#else
140           char *eStr;
141           eStr = new char[strlen(aUrl.c_str())+17];
142 //#endif
143       sprintf(eStr,"Can't open file %s",aUrl.c_str());
144 //#ifdef WNT
145           delete [] eStr;
146 //#endif
147       _errorCode = string(eStr);
148       return NULL;
149     }
150
151   // Temporary aStudyUrl in place of study name
152   DF_Document* Doc = _appli->NewDocument("SALOME_STUDY");
153
154   SALOMEDSImpl_Study* Study = new SALOMEDSImpl_Study(Doc, aUrl);
155
156   _IDcounter++;
157   Study->StudyId( _IDcounter );
158
159   // Assign the value of the URL in the study object
160   Study->URL (aUrl);
161
162   SALOMEDSImpl_AttributePersistentRef::Set(Doc->Main(), aUrl);
163
164   if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
165      _errorCode = "Study is empty";
166     return Study;
167   }
168
169   //Create  the Structure of the Document
170   hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
171
172   try {
173     BuildTree (Study, hdf_group_study_structure);
174   }
175   catch (HDFexception)
176     {
177 //#ifndef WNT
178 //      char eStr[strlen(aUrl.ToCString())+17];
179 //#else
180           char *eStr = new char [strlen(aUrl.c_str())+17];
181 //#endif
182       sprintf(eStr,"Can't open file %s", aUrl.c_str());
183       _errorCode = string(eStr);
184       return NULL;
185     }
186
187   hdf_file->CloseOnDisk();
188
189   if (isASCII) {
190     vector<string> aFilesToRemove;
191     aFilesToRemove.push_back("hdf_from_ascii.hdf");
192     SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
193   }
194
195   delete hdf_file; // all related hdf objects will be deleted
196
197   return Study;
198 }
199
200
201
202 //============================================================================
203 /*! Function : Close
204  *  Purpose  : Close a study.
205  *             If the study hasn't been saved, ask the user to confirm the
206  *             close action without saving
207  */
208
209 //============================================================================
210 void  SALOMEDSImpl_StudyManager::Close(SALOMEDSImpl_Study* aStudy)
211 {
212   _errorCode = "";
213
214   if(!aStudy) {
215     _errorCode = "Study is null";
216     return;
217   }
218
219   aStudy->Close();
220 }
221
222 //============================================================================
223 /*! Function : Save
224  *  Purpose  : Save a Study to it's persistent reference
225  */
226 //============================================================================
227 bool SALOMEDSImpl_StudyManager::Save(SALOMEDSImpl_Study* aStudy,
228                                      SALOMEDSImpl_DriverFactory* aFactory,
229                                      bool theMultiFile)
230 {
231   _errorCode = "";
232
233   string url = aStudy->URL();
234   if (url.empty()) {
235     _errorCode = "No path specified to save the study. Nothing done";
236     return false;
237   }
238   else {
239     return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, false);
240   }
241
242   return false;
243 }
244
245 bool SALOMEDSImpl_StudyManager::SaveASCII(SALOMEDSImpl_Study* aStudy,
246                                           SALOMEDSImpl_DriverFactory* aFactory,
247                                           bool theMultiFile)
248 {
249   _errorCode = "";
250
251   string url = aStudy->URL();
252   if (url.empty()) {
253     _errorCode = "No path specified to save the study. Nothing done";
254     return false;
255   }
256   else {
257     return Impl_SaveAs(url,aStudy, aFactory, theMultiFile, true);
258   }
259
260   return false;
261 }
262
263 //=============================================================================
264 /*! Function : SaveAs
265  *  Purpose  : Save a study to the persistent reference aUrl
266  */
267 //============================================================================
268 bool SALOMEDSImpl_StudyManager::SaveAs(const string& aUrl,
269                                        SALOMEDSImpl_Study* aStudy,
270                                        SALOMEDSImpl_DriverFactory* aFactory,
271                                        bool theMultiFile)
272 {
273   _errorCode = "";
274   return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, false);
275 }
276
277 bool SALOMEDSImpl_StudyManager::SaveAsASCII(const string& aUrl,
278                                             SALOMEDSImpl_Study* aStudy,
279                                             SALOMEDSImpl_DriverFactory* aFactory,
280                                             bool theMultiFile)
281 {
282   _errorCode = "";
283   return Impl_SaveAs(aUrl,aStudy, aFactory, theMultiFile, true);
284 }
285
286 //============================================================================
287 /*! Function : GetOpenStudies
288  *  Purpose  : Get name list of open studies in the session
289  */
290 //============================================================================
291 vector<SALOMEDSImpl_Study*> SALOMEDSImpl_StudyManager::GetOpenStudies()
292 {
293   _errorCode = "";
294   vector<SALOMEDSImpl_Study*> aList;
295
296   int nbDocs = _appli->NbDocuments();
297
298   if(nbDocs == 0) {
299     _errorCode = "No active study in this session";
300     return aList;
301   }
302   else {
303     SALOMEDSImpl_Study* aStudy;
304     vector<int> ids = _appli->GetDocumentIDs();
305     for (int i = 0, len = ids.size(); i<len; i++) {
306       DF_Document* D = _appli->GetDocument(ids[i]);
307       if(D == _clipboard) continue;
308       aStudy = SALOMEDSImpl_Study::GetStudy(D->Main());
309       if(!aStudy) continue;
310       aList.push_back(aStudy);
311     }
312   }
313
314   return aList;
315 }
316
317 //============================================================================
318 /*! Function : GetStudyByName
319  *  Purpose  : Get a study from its name
320  */
321 //============================================================================
322 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByName
323                                    (const string& aStudyName)
324 {
325   _errorCode = "";
326   int nbDocs = _appli->NbDocuments();
327
328   if (nbDocs == 0) {
329     _errorCode = "No active study in this session";
330     return NULL;
331   }
332   else {
333     vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
334     for (int i = 0, len = studies.size(); i<len; i++) {
335       if (studies[i]->Name() == aStudyName) return studies[i];
336     }
337   }
338
339   _errorCode = string("Found no study with the name ") + aStudyName;
340   return NULL;
341 }
342
343 //============================================================================
344 /*! Function : GetStudyByID
345  *  Purpose  : Get a study from its ID
346  */
347 //============================================================================
348 SALOMEDSImpl_Study* SALOMEDSImpl_StudyManager::GetStudyByID(int aStudyID)
349 {
350   _errorCode = "";
351   int nbDocs = _appli->NbDocuments();
352
353   if (nbDocs == 0) {
354     _errorCode = "No active study in this session";
355     return NULL;
356   }
357   else {
358     vector<SALOMEDSImpl_Study*> studies = GetOpenStudies();
359     for (int i = 0, len = studies.size(); i<len; i++) {
360       if (studies[i]->StudyId() == aStudyID) return studies[i];
361     }
362   }
363
364   _errorCode = "Found no study with the given ID";
365   return NULL;
366 }
367
368 //=============================================================================
369 /*! Function : _SaveProperties
370  *  Purpose  : save the study properties in HDF file
371  */
372 //============================================================================
373 bool SALOMEDSImpl_StudyManager::Impl_SaveProperties(SALOMEDSImpl_Study* aStudy,
374                                                     HDFgroup *hdf_group)
375 {
376   _errorCode = "";
377
378   HDFdataset *hdf_dataset = 0;
379   hdf_size size[1];
380   hdf_int32 name_len;
381
382   // add modifications list (user and date of save)
383   SALOMEDSImpl_AttributeStudyProperties* aProp = aStudy->GetProperties();
384   int aLocked = aProp->IsLocked();
385   if (aLocked) aProp->SetLocked(false);
386
387   int month=0,day=0,year=0,hh=0,mn=0,ss=0;
388   SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
389   aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
390                          mn, hh, day, month, year);
391
392   if (aLocked) aProp->SetLocked(true);
393
394   vector<string> aNames;
395   vector<int> aMinutes, aHours, aDays, aMonths, aYears;
396
397   aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
398
399   int aLength = 0, anIndex, i;
400   for(i=1; i<=aNames.size(); i++)
401     aLength += aNames[i-1].size() + 1;
402
403   //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, "zero" byte
404   char* aProperty = new char[3 + aLength + 12 * aNames.size()];
405
406
407   sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(),  (aProp->IsLocked())?'l':'u');
408
409   aLength = aNames.size();
410   int a = 2;
411   for(anIndex = 0; anIndex<aLength; anIndex++) {
412     sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
413             (int)(aMinutes[anIndex]),
414             (int)(aHours[anIndex]),
415             (int)(aDays[anIndex]),
416             (int)(aMonths[anIndex]),
417             (int)(aYears[anIndex]),
418             aNames[anIndex].c_str());
419     a = strlen(aProperty);
420     aProperty[a++] = 1;
421   }
422   aProperty[a] = 0;
423
424   name_len = (hdf_int32) a;
425   size[0] = name_len + 1 ;
426   hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
427   hdf_dataset->CreateOnDisk();
428   hdf_dataset->WriteOnDisk(aProperty);
429   hdf_dataset->CloseOnDisk();
430   hdf_dataset=0; //will be deleted by hdf_sco_group destructor
431   delete [] aProperty;
432
433   aProp->SetModified(0);
434   return true;
435 }
436
437 //=============================================================================
438 /*! Function : _SaveAs
439  *  Purpose  : save the study in HDF file
440  */
441 //============================================================================
442 bool SALOMEDSImpl_StudyManager::Impl_SaveAs(const string& aUrl,
443                                             SALOMEDSImpl_Study* aStudy,
444                                             SALOMEDSImpl_DriverFactory* aFactory,
445                                             bool theMultiFile,
446                                             bool theASCII)
447 {
448   // HDF File will be composed of differents part :
449   // * For each ComponentDataType, all data created by the component
450   //   Informations in data group hdf_group_datacomponent
451   // * Study Structure -> Exactly what is contained in Document
452   //   Informations in data group hdf_group_study_structure
453
454   _errorCode = "";
455
456   HDFfile *hdf_file=0;
457   HDFgroup *hdf_group_study_structure =0;
458   HDFgroup *hdf_sco_group =0;
459   HDFgroup *hdf_sco_group2 =0;
460
461   HDFgroup *hdf_group_datacomponent =0;
462   HDFdataset *hdf_dataset =0;
463   hdf_size size[1];
464   hdf_int32 name_len = 0;
465   char *component_name = 0;
466
467   if(!aStudy) {
468     _errorCode = "Study is null";
469     return false;
470   }
471
472   int aLocked = aStudy->GetProperties()->IsLocked();
473   if (aLocked) aStudy->GetProperties()->SetLocked(false);
474
475   SALOMEDSImpl_StudyBuilder* SB= aStudy->NewBuilder();
476   map<string, SALOMEDSImpl_Driver*> aMapTypeDriver;
477
478   try
479     {
480       // mpv 15.12.2003: for saving components we have to load all data from all modules
481       SALOMEDSImpl_SComponentIterator itcomponent1 = aStudy->NewComponentIterator();
482       for (; itcomponent1.More(); itcomponent1.Next())
483         {
484           SALOMEDSImpl_SComponent sco = itcomponent1.Value();
485           // if there is an associated Engine call its method for saving
486           string IOREngine;
487           try {
488             if (!sco.ComponentIOR(IOREngine)) {
489               string aCompType = sco.GetComment();
490               if (!aCompType.empty()) {
491
492                 SALOMEDSImpl_Driver* aDriver = aFactory->GetDriverByType(aCompType);
493                 aMapTypeDriver[aCompType] = aDriver;
494
495                 if (aDriver != NULL) {
496                   if(!SB->LoadWith(sco, aDriver)) {
497                     _errorCode = SB->GetErrorCode();
498                     return false;
499                   }
500                 }
501               }
502             }
503           } catch(...) {
504             _errorCode = "Can not restore information to resave it";
505             return false;
506           }
507         }
508
509       string anOldName = aStudy->Name();
510       aStudy->URL(aUrl);
511
512       // To change for Save
513       // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
514       hdf_file = new HDFfile((char*)aUrl.c_str());
515       hdf_file->CreateOnDisk();
516
517       //-----------------------------------------------------------------------
518       // 1 - Create a groupe for each SComponent and Update the PersistanceRef
519       //-----------------------------------------------------------------------
520       hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
521       hdf_group_datacomponent->CreateOnDisk();
522
523       SALOMEDSImpl_SComponentIterator itcomponent = aStudy->NewComponentIterator();
524
525       for (; itcomponent.More(); itcomponent.Next())
526         {
527           SALOMEDSImpl_SComponent sco = itcomponent.Value();
528
529           string scoid = sco.GetID();
530           hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
531           hdf_sco_group->CreateOnDisk();
532
533           string componentDataType = sco.ComponentDataType();
534           string IOREngine;
535           if (sco.ComponentIOR(IOREngine))
536             {
537               SALOMEDSImpl_Driver* Engine = NULL;
538               if(aMapTypeDriver.find(componentDataType) != aMapTypeDriver.end()) {
539                 // we have found the associated engine to write the data
540                 Engine = aMapTypeDriver[componentDataType];
541               }
542               else {
543                 Engine = aFactory->GetDriverByIOR(IOREngine);
544               }
545
546               if (Engine != NULL)
547                 {
548                   SALOMEDSImpl_TMPFile* aStream = NULL;
549                   long length = 0;
550
551                   if (theASCII) aStream = Engine->SaveASCII(sco,
552                                                             SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
553                                                             length,
554                                                             theMultiFile);
555                   else aStream = Engine->Save(sco,
556                                               SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
557                                               length,
558                                               theMultiFile);
559                   HDFdataset *hdf_dataset;
560                   hdf_size aHDFSize[1]; 
561                   if(length > 0) {  //The component saved some auxiliary files, then put them into HDF file
562
563                     aHDFSize[0] = length;
564
565                     HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
566                     hdf_dataset->CreateOnDisk();
567                     hdf_dataset->WriteOnDisk(aStream->Data());  //Save the stream in the HDF file
568                     hdf_dataset->CloseOnDisk();
569                   }
570
571                   if(aStream) delete aStream;
572
573                   // store multifile state
574                   aHDFSize[0] = 2;
575                   hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
576                   hdf_dataset->CreateOnDisk();
577                   hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
578                   hdf_dataset->CloseOnDisk();
579                   hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
580                   // store ASCII state
581                   aHDFSize[0] = 2;
582                   hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
583                   hdf_dataset->CreateOnDisk();
584                   hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
585                   hdf_dataset->CloseOnDisk();
586                   hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
587                   // Creation of the persistance reference  attribute
588                   Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
589                 }
590             }
591           hdf_sco_group->CloseOnDisk();
592           hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
593         }
594       hdf_group_datacomponent->CloseOnDisk();
595       hdf_group_datacomponent =0;  // will be deleted by hdf_file destructor
596
597       //-----------------------------------------------------------------------
598       //3 - Write the Study Structure
599       //-----------------------------------------------------------------------
600       hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
601       hdf_group_study_structure->CreateOnDisk();
602       // save component attributes
603       SALOMEDSImpl_SComponentIterator itcomp = aStudy->NewComponentIterator();
604       for (; itcomp.More(); itcomp.Next())
605         {
606           SALOMEDSImpl_SComponent SC = itcomp.Value();
607           string scid = SC.GetID();
608           hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
609           hdf_sco_group2->CreateOnDisk();
610           SaveAttributes(SC, hdf_sco_group2);
611           // ComponentDataType treatment
612           component_name = (char*)SC.ComponentDataType().c_str();
613           name_len = (hdf_int32)strlen(component_name);
614           size[0] = name_len +1 ;
615           hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
616           hdf_dataset->CreateOnDisk();
617           hdf_dataset->WriteOnDisk(component_name);
618           hdf_dataset->CloseOnDisk();
619           hdf_dataset=0; //will be deleted by hdf_sco_group destructor
620           Impl_SaveObject(SC, hdf_sco_group2);
621           hdf_sco_group2->CloseOnDisk();
622           hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
623         }
624       //-----------------------------------------------------------------------
625       //4 - Write the Study UseCases Structure
626       //-----------------------------------------------------------------------
627       SALOMEDSImpl_SObject aSO = aStudy->FindObjectID(USE_CASE_LABEL_ID);
628       if (aSO) {
629         HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
630         hdf_soo_group->CreateOnDisk();
631         SaveAttributes(aSO, hdf_soo_group);
632         Impl_SaveObject(aSO, hdf_soo_group);
633         hdf_soo_group->CloseOnDisk();
634         hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
635       }
636
637       if (aLocked) aStudy->GetProperties()->SetLocked(true);
638       //-----------------------------------------------------------------------
639       //5 - Write the Study Properties
640       //-----------------------------------------------------------------------
641       name_len = (hdf_int32) aStudy->Name().size();
642       size[0] = name_len +1 ;
643       hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
644       hdf_dataset->CreateOnDisk();
645       char* studid = (char*)aStudy->Name().c_str();
646       hdf_dataset->WriteOnDisk(studid);
647       hdf_dataset->CloseOnDisk();
648       hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
649
650       Impl_SaveProperties(aStudy, hdf_group_study_structure);
651       hdf_group_study_structure->CloseOnDisk();
652       hdf_file->CloseOnDisk();
653
654       aStudy->IsSaved(true);
655       hdf_group_study_structure =0; // will be deleted by hdf_file destructor
656       delete hdf_file; // recursively deletes all hdf objects...
657     }
658   catch (HDFexception)
659     {
660       _errorCode = "HDFexception ! ";
661       return false;
662     }
663   catch(std::exception& exc)
664     {
665       _errorCode = const_cast<char*>(exc.what());
666       return false;
667     }
668   catch(...)
669     {
670       _errorCode = "Unknown exception ! ";
671       return false;
672     }
673   if (theASCII) { // save file in ASCII format
674     HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
675   }
676
677   return true;
678 }
679
680 //============================================================================
681 /*! Function : Impl_SaveObject
682  *  Purpose  :
683  */
684 //============================================================================
685 bool SALOMEDSImpl_StudyManager::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
686                                                 HDFgroup *hdf_group_datatype)
687 {
688   _errorCode = "";
689
690   // Write in group hdf_group_datatype all informations of SObject SC
691   // Iterative function to parse all SObjects under a SComponent
692
693   HDFgroup *hdf_group_sobject = 0;
694
695   DF_ChildIterator itchild(SC.GetLabel());
696   for (; itchild.More(); itchild.Next())
697     {
698
699       // mpv: don't save empty labels
700       vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
701       if (attr.size() == 0) {  //No attributes on the label
702         DF_ChildIterator subchild(itchild.Value());
703         if (!subchild.More()) {
704           continue;
705         }
706         subchild.Init(itchild.Value(), true);
707         bool anEmpty = true;
708         for (; subchild.More() && anEmpty; subchild.Next()) {
709           vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
710           if (attr2.size()) {
711             anEmpty = false;  //There are attributes on the child label
712             break;
713           }
714         }
715         if (anEmpty) continue;
716       }
717
718       SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
719
720       char* scoid = (char*) SO.GetID().c_str();
721       hdf_group_sobject = new HDFgroup(scoid, hdf_group_datatype);
722       hdf_group_sobject->CreateOnDisk();
723       SaveAttributes(SO, hdf_group_sobject);
724       Impl_SaveObject(SO, hdf_group_sobject);
725       hdf_group_sobject->CloseOnDisk();
726       hdf_group_sobject =0; // will be deleted by father hdf object destructor
727     }
728
729   return true;
730 }
731
732 //============================================================================
733 /*! Function : Impl_SubstituteSlash
734  *  Purpose  :
735  */
736 //============================================================================
737 string SALOMEDSImpl_StudyManager::Impl_SubstituteSlash(const string& aUrl)
738 {
739   _errorCode = "";
740
741   std::string theUrl(aUrl);
742   for(int i = 0; i<theUrl.size(); i++)
743     if(theUrl[i] == '/') theUrl[i] = ':';
744   return theUrl;
745 }
746
747 //============================================================================
748 /*! Function : GetDocumentOfStudy
749  *  Purpose  :
750  */
751 //============================================================================
752 DF_Document* SALOMEDSImpl_StudyManager::GetDocumentOfStudy(SALOMEDSImpl_Study* theStudy)
753 {
754   _errorCode = "";
755   return theStudy->_doc;
756 }
757
758 //============================================================================
759 /*! Function : CanCopy
760  *  Purpose  :
761  */
762 //============================================================================
763 bool SALOMEDSImpl_StudyManager::CanCopy(const SALOMEDSImpl_SObject& theObject,
764                                         SALOMEDSImpl_Driver* theEngine)
765 {
766   _errorCode = "";
767   SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
768   if (!aComponent) return false;
769   if (aComponent.GetLabel() == theObject.GetLabel()) return false;
770   string IOREngine;
771   if (!aComponent.ComponentIOR(IOREngine)) return false;
772   if (theEngine == NULL) return false;
773   return theEngine->CanCopy(theObject);
774 }
775
776 //============================================================================
777 /*! Function : CopyLabel
778  *  Purpose  :
779  */
780 //============================================================================
781 bool SALOMEDSImpl_StudyManager::CopyLabel(SALOMEDSImpl_Study* theSourceStudy,
782                                           SALOMEDSImpl_Driver* theEngine,
783                                           const int theSourceStartDepth,
784                                           const DF_Label& theSource,
785                                           const DF_Label& theDestinationMain)
786 {
787   _errorCode = "";
788
789   int a;
790   DF_Label aTargetLabel = theDestinationMain;
791   DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
792   for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
793     DF_Label aSourceLabel = theSource;
794     for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
795     aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
796     aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
797   }
798   // iterate attributes
799   vector<DF_Attribute*> attrList = theSource.GetAttributes();
800   for(int i = 0, len = attrList.size(); i<len; i++) {
801     DF_Attribute* anAttr = attrList[i];
802     string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
803     if (type.substr(0, 17) == string("AttributeTreeNode")) continue; // never copy tree node attribute
804     if (type == string("AttributeTarget")) continue; // and target attribute
805
806     if (type == string("AttributeReference")) { // reference copied as Comment in aux tree
807       DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
808       string anEntry = aReferenced.Entry();
809       // store the value of name attribute of referenced label
810       SALOMEDSImpl_AttributeName* aNameAttribute;
811       if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
812         anEntry += " ";
813         anEntry += aNameAttribute->Value();
814       }
815       SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
816       continue;
817     }
818
819     if (type == string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
820       string anEntry = theSource.Entry();
821       SALOMEDSImpl_SObject aSO = theSourceStudy->FindObjectID(anEntry);
822       int anObjID;
823       long aLen;
824       SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
825       string aResStr("");
826       for(a = 0; a < aLen; a++) {
827         aResStr += (char)(aStream->Get(a));
828       }
829
830       if(aStream) delete aStream;
831
832       SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
833       SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
834       continue;
835     }
836     DF_Attribute* aNewAttribute = anAttr->NewEmpty();
837     aTargetLabel.AddAttribute(aNewAttribute);
838     anAttr->Paste(aNewAttribute);
839   }
840
841   return true;
842 }
843
844 //============================================================================
845 /*! Function : Copy
846  *  Purpose  :
847  */
848 //============================================================================
849 bool SALOMEDSImpl_StudyManager::Copy(const SALOMEDSImpl_SObject& theObject,
850                                      SALOMEDSImpl_Driver* theEngine)
851 {
852   _errorCode = "";
853
854   // adoptation for alliances datamodel copy: without IOR attributes !!!
855   bool aStructureOnly; // copy only SObjects and attributes without component help
856   aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
857
858   // get component-engine
859   SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
860
861   // CAF document of current study usage
862   DF_Document* aDocument = GetDocumentOfStudy(aStudy);
863   if (!aDocument) {
864     _errorCode = "Document is null";
865     return false;
866   }
867
868   //Clear the clipboard
869   _clipboard->Main().Root().ForgetAllAttributes(true);
870   _appli->Close(_clipboard);
871   _clipboard = _appli->NewDocument("SALOME_STUDY");
872
873   // set component data type to the name attribute of root label
874   if (!aStructureOnly) {
875     SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
876                                        theEngine->ComponentDataType());
877   }
878   // set to the Root label integer attribute: study id
879   SALOMEDSImpl_AttributeInteger::Set(_clipboard->Main().Root(), aStudy->StudyId());
880   // iterate all theObject's label children
881   DF_Label aStartLabel = theObject.GetLabel();
882   int aSourceStartDepth = aStartLabel.Depth();
883
884   // copy main source label
885   CopyLabel(aStudy, theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
886
887   // copy all subchildren of the main source label (all levels)
888   DF_ChildIterator anIterator(aStartLabel, true);
889   for(; anIterator.More(); anIterator.Next()) {
890     CopyLabel(aStudy, theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
891   }
892
893   return true;
894 }
895 //============================================================================
896 /*! Function : CanPaste
897  *  Purpose  :
898  */
899 //============================================================================
900 bool SALOMEDSImpl_StudyManager::CanPaste(const SALOMEDSImpl_SObject& theObject,
901                                          SALOMEDSImpl_Driver* theEngine)
902 {
903   _errorCode = "";
904
905   if (!_clipboard) {
906     _errorCode = "Clipboard is null";
907     return false;
908   }
909
910   SALOMEDSImpl_AttributeComment* aCompName = NULL;
911   if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
912     _errorCode = "Clipboard has no component type";
913     return false;
914   }
915   SALOMEDSImpl_AttributeInteger* anObjID;
916   if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
917     _errorCode = "Clipboard has no object id";
918     return false;
919   }
920   SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
921   if (!aComponent) {
922     _errorCode = "Object doesn't belong to component";
923     return false;
924   }
925
926   string IOREngine;
927   if (!aComponent.ComponentIOR(IOREngine)) {
928     _errorCode = "component has no IOR";
929     return false;
930   }
931   return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
932 }
933
934 //============================================================================
935 /*! Function : PasteLabel
936  *  Purpose  :
937  */
938 //============================================================================
939 DF_Label SALOMEDSImpl_StudyManager::PasteLabel(SALOMEDSImpl_Study* theDestinationStudy,
940                                                SALOMEDSImpl_Driver* theEngine,
941                                                const DF_Label& theSource,
942                                                const DF_Label& theDestinationStart,
943                                                const int theCopiedStudyID,
944                                                const bool isFirstElement)
945 {
946   _errorCode = "";
947
948   // get corresponding source, target and auxiliary labels
949   DF_Label aTargetLabel = theDestinationStart;
950
951   DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
952   int a;
953   if (!isFirstElement) {
954     for(a = theSource.Depth() - 1; a > 0 ; a--) {
955       DF_Label aSourceLabel = theSource;
956       for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
957       aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
958       aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
959     }
960   }
961
962   // check auxiliary label for TMPFile => IOR
963   SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
964   if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
965     SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
966     SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
967     string aCompName = aComponentName->Value();
968
969     if (theEngine->CanPaste(aCompName, anObjID->Value())) {
970       std::string aTMPStr = aNameAttribute->Value();
971       int aLen = aTMPStr.size();
972       unsigned char* aStream = NULL;
973       if(aLen > 0) {
974         aStream = new unsigned char[aLen+10];
975         for(a = 0; a < aLen; a++) {
976           aStream[a] = aTMPStr[a];
977         }
978       }
979
980       string anEntry = aTargetLabel.Entry();
981       SALOMEDSImpl_SObject aPastedSO = theDestinationStudy->FindObjectID(anEntry);
982
983       if (isFirstElement) {
984         string aDestEntry = theEngine->PasteInto(aStream,
985                                                  aLen,
986                                                  anObjID->Value(),
987                                                  aPastedSO.GetFatherComponent());
988         aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
989       } else
990         theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
991
992       if(aStream != NULL) delete []aStream;
993     }
994   }
995
996   // iterate attributes
997   vector<DF_Attribute*> attrList = theSource.GetAttributes();
998   for(int i = 0, len = attrList.size(); i<len; i++) {
999     DF_Attribute* anAttr = attrList[i];
1000     if (aTargetLabel.FindAttribute(anAttr->ID())) {
1001       aTargetLabel.ForgetAttribute(anAttr->ID());
1002     }
1003     DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1004     aTargetLabel.AddAttribute(aNewAttribute);
1005     anAttr->Paste(aNewAttribute);
1006   }
1007
1008   // check auxiliary label for Comment => reference or name attribute of the referenced object
1009   SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1010   if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1011     char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1012     strcpy(anEntry, string(aCommentAttribute->Value()).c_str());
1013     char* aNameStart = strchr(anEntry, ' ');
1014     if (aNameStart) {
1015       *aNameStart = '\0';
1016       aNameStart++;
1017     }
1018     if (theCopiedStudyID == theDestinationStudy->StudyId()) { // if copy to the same study, reanimate reference
1019       DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1020       SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1021       // target attributes structure support
1022       SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1023     } else {
1024       if (aNameStart) SALOMEDSImpl_AttributeName::Set(aTargetLabel, aNameStart);
1025       else SALOMEDSImpl_AttributeName::Set(aTargetLabel, std::string("Reference to:")+anEntry);
1026     }
1027     delete [] anEntry;
1028   }
1029
1030   return aTargetLabel;
1031 }
1032
1033 //============================================================================
1034 /*! Function : Paste
1035  *  Purpose  :
1036  */
1037 //============================================================================
1038 SALOMEDSImpl_SObject SALOMEDSImpl_StudyManager::Paste(const SALOMEDSImpl_SObject& theObject,
1039                                                SALOMEDSImpl_Driver* theEngine)
1040 {
1041   _errorCode = "";
1042
1043   SALOMEDSImpl_SObject so;
1044   SALOMEDSImpl_Study* aStudy = theObject.GetStudy();
1045
1046   // if study is locked, then paste can't be done
1047   if (aStudy->GetProperties()->IsLocked()) {
1048     _errorCode = "LockProtection";
1049     throw LockProtection("LockProtection");
1050   }
1051
1052   // if there is no component name, then paste only SObjects and attributes: without component help
1053   SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1054   bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1055
1056   // get copied study ID
1057   SALOMEDSImpl_AttributeInteger* aStudyIDAttribute = NULL;
1058   if (!(aStudyIDAttribute=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1059     _errorCode = "No study ID was found";
1060     return so;
1061   }
1062   int aCStudyID = aStudyIDAttribute->Value();
1063
1064   // CAF document of current study usage
1065   DF_Document* aDocument = GetDocumentOfStudy(aStudy);
1066   if (!aDocument) {
1067     _errorCode = "Document is null";
1068     return so;
1069   }
1070
1071   SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1072
1073   // fill root inserted SObject
1074   DF_Label aStartLabel;
1075   if (aStructureOnly) {
1076     DF_Label anObjectLabel = DF_Label::Label(aDocument->Main(), theObject.GetID());
1077     aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), anObjectLabel, aCStudyID, false);
1078   } else {
1079     DF_Label aComponentLabel = DF_Label::Label(aDocument->Main(), aComponent.GetID());
1080     aStartLabel = PasteLabel(aStudy, theEngine, _clipboard->Main(), aComponentLabel, aCStudyID, true);
1081   }
1082
1083   // paste all sublebels
1084   DF_ChildIterator anIterator(_clipboard->Main(), true);
1085   for(; anIterator.More(); anIterator.Next()) {
1086     PasteLabel(aStudy, theEngine, anIterator.Value(), aStartLabel, aCStudyID, false);
1087   }
1088
1089   return SALOMEDSImpl_Study::SObject(aStartLabel);
1090 }
1091
1092 //#######################################################################################################
1093 //#                                     STATIC PRIVATE FUNCTIONS
1094 //#######################################################################################################
1095
1096 //============================================================================
1097 /*! Function : SaveAttributes
1098  *  Purpose  : Save attributes for object
1099  */
1100 //============================================================================
1101 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
1102 {
1103   hdf_size size[1];
1104   vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
1105   DF_Attribute* anAttr = NULL;
1106   for(int i = 0, len = attrList.size(); i<len; i++) {
1107     anAttr = attrList[i];
1108     //The following attributes are not supposed to be written to the file
1109     string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
1110     if(type == string("AttributeIOR")) continue; //IOR attribute is not saved
1111     string aSaveStr =anAttr->Save();
1112     //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
1113     size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
1114     HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
1115     hdf_dataset->CreateOnDisk();
1116     hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
1117     hdf_dataset->CloseOnDisk();
1118     hdf_dataset=0; //will be deleted by hdf_sco_group destructor
1119   }
1120 }
1121
1122 //===========================================================================
1123 //Function : ReadAttributes
1124 //===========================================================================
1125 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
1126                            const SALOMEDSImpl_SObject& aSO,
1127                            HDFdataset* hdf_dataset)
1128 {
1129   hdf_dataset->OpenOnDisk();
1130
1131   DF_Attribute* anAttr = NULL;
1132   char* current_string = new char[hdf_dataset->GetSize()+1];
1133   hdf_dataset->ReadFromDisk(current_string);
1134   //cout << "Reading attr type = " << hdf_dataset->GetName() << "  SO = " << aSO.GetID() << endl;
1135   if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
1136     anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
1137   } else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
1138              !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
1139     theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
1140     delete(current_string);
1141     hdf_dataset->CloseOnDisk();
1142     return;
1143   } else {
1144     anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
1145   }
1146   
1147   if (anAttr) {
1148     anAttr->Load(current_string);
1149   }
1150   
1151   delete(current_string);
1152   hdf_dataset->CloseOnDisk();
1153 }
1154
1155 //============================================================================
1156 //Function : BuildlTree
1157 //============================================================================
1158 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
1159 {
1160   hdf_current_group->OpenOnDisk();
1161   SALOMEDSImpl_SObject aSO;
1162   char* Entry = hdf_current_group->GetName();
1163   if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
1164     aSO = theStudy->CreateObjectID("0:1");
1165   }
1166   else {
1167     aSO = theStudy->CreateObjectID(Entry);
1168   }
1169
1170   char name[HDF_NAME_MAX_LEN+1];
1171   int nbsons = hdf_current_group->nInternalObjects();
1172   for (int i=0; i<nbsons; i++) {
1173     hdf_current_group->InternalObjectIndentify(i,name);
1174     if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
1175     hdf_object_type type = hdf_current_group->InternalObjectType(name);
1176
1177     if  (type == HDF_DATASET) {
1178       HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
1179       ReadAttributes(theStudy,aSO,new_dataset);
1180       new_dataset = 0; // will be deleted by father destructor
1181
1182     }
1183     else if (type == HDF_GROUP)   {
1184       HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
1185       BuildTree (theStudy, new_group);
1186       new_group = 0; // will be deleted by father destructor
1187     }
1188   }
1189   hdf_current_group->CloseOnDisk();
1190 }
1191
1192
1193 //============================================================================
1194 //Function : Translate_IOR_to_persistentID
1195 //============================================================================
1196 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
1197                                            SALOMEDSImpl_Driver*                engine,
1198                                            bool                                isMultiFile,
1199                                            bool                                isASCII)
1200 {
1201   DF_ChildIterator itchild(so.GetLabel());
1202   string ior_string,  persistent_string, curid;
1203
1204   for (; itchild.More(); itchild.Next()) {
1205     SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
1206     SALOMEDSImpl_AttributeIOR* IOR = NULL;
1207     if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
1208       ior_string = IOR->Value();
1209
1210       persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
1211       SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
1212     }
1213     Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
1214   }
1215 }
1216