1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_Study.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_Study.hxx"
30 #include <KERNEL_version.h>
31 #include <Basics_Utils.hxx>
32 #include <Basics_DirUtils.hxx>
34 #include "HDFexplorer.hxx"
36 #include "DF_Application.hxx"
37 #include "DF_ChildIterator.hxx"
39 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
40 #include "SALOMEDSImpl_Attributes.hxx"
41 #include "SALOMEDSImpl_UseCaseIterator.hxx"
42 #include "SALOMEDSImpl_AttributeReference.hxx"
43 #include "SALOMEDSImpl_StudyHandle.hxx"
44 #include "SALOMEDSImpl_Tool.hxx"
45 #include "SALOMEDSImpl_IParameters.hxx"
46 #include "SALOMEDSImpl_ScalarVariable.hxx"
47 #include "SALOMEDSImpl_SComponent.hxx"
54 // comment out the following define to enable \t symbols in in the python dump files
57 #define DIRECTORYID 16661
58 #define FILELOCALID 26662
59 #define FILEID "FILE: "
60 #define VARIABLE_SEPARATOR ':'
61 #define OPERATION_SEPARATOR '|'
62 #define USE_CASE_LABEL_ID "0:2"
64 static void SaveAttributes(const SALOMEDSImpl_SObject& SO, HDFgroup *hdf_group_sobject);
65 static void ReadAttributes(SALOMEDSImpl_Study*, const SALOMEDSImpl_SObject&, HDFdataset* );
66 static void BuildTree (SALOMEDSImpl_Study*, HDFgroup*);
67 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject&,
68 SALOMEDSImpl_Driver*, bool isMultiFile, bool isASCII);
69 static void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup);
75 StudyUnlocker( SALOMEDSImpl_Study* study ): myStudy( study ), myLocked( false )
77 myPrevLocked = myStudy->GetProperties()->IsLocked();
87 myStudy->GetProperties()->SetLocked(true);
88 myPrevLocked = myLocked;
95 myStudy->GetProperties()->SetLocked(false);
96 myLocked = myPrevLocked;
101 SALOMEDSImpl_Study* myStudy;
107 //============================================================================
108 /*! Function : SALOMEDSImpl_Study
109 * Purpose : SALOMEDSImpl_Study constructor
111 //============================================================================
112 SALOMEDSImpl_Study::SALOMEDSImpl_Study()
114 _appli = new DF_Application();
115 _clipboard = _appli->NewDocument("SALOME_STUDY");
120 //============================================================================
121 /*! Function : ~SALOMEDSImpl_Study
122 * Purpose : SALOMEDSImpl_Study destructor
124 //============================================================================
125 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
128 _appli->Close(_clipboard);
129 // Destroy application
133 //============================================================================
135 * Purpose : Initialize study components
137 //============================================================================
138 void SALOMEDSImpl_Study::Init()
141 std::stringstream sstrm;
143 _name = "Study" + std::string(sstrm.str());
144 _doc = _appli->NewDocument("SALOME_STUDY");
149 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
150 _builder = new SALOMEDSImpl_StudyBuilder(this);
151 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
154 //Put on the root label a StudyHandle attribute to store the address of this object
155 //It will be used to retrieve the study object by DF_Label that belongs to the study
156 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
158 // set Study properties
159 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
161 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
162 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
163 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
164 mn, hh, day, month, year);
165 aProp->SetCreationMode(1); //"from scratch"
168 //============================================================================
170 * Purpose : Clear study components
172 //============================================================================
173 void SALOMEDSImpl_Study::Clear()
177 delete _useCaseBuilder;
185 //============================================================================
187 * Purpose : Open a Study from it's persistent reference
189 //============================================================================
190 bool SALOMEDSImpl_Study::Open(const std::string& aUrl)
192 // Set "C" locale temporarily to avoid possible localization problems
193 Kernel_Utils::Localizer loc;
198 HDFfile *hdf_file =0;
199 HDFgroup *hdf_group_study_structure =0;
200 HDFgroup *hdf_notebook_vars = 0;
204 bool isASCII = false;
205 if (HDFascii::isASCII(aUrl.c_str())) {
207 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aUrl.c_str());
210 aC_HDFUrl = new char[strlen(aResultPath) + 19];
211 sprintf(aC_HDFUrl, "%shdf_from_ascii.hdf", aResultPath);
212 delete [] (aResultPath);
220 hdf_file = new HDFfile((char*)aHDFUrl.c_str());
222 hdf_file->OpenOnDisk(HDF_RDONLY);// mpv: was RDWR, but opened file can be write-protected too
227 eStr = new char[strlen(aUrl.c_str())+17];
228 sprintf(eStr,"Can't open file %s",aUrl.c_str());
230 _errorCode = std::string(eStr);
234 // Assign the value of the URL in the study object
237 SALOMEDSImpl_AttributePersistentRef::Set(_doc->Main(), aUrl);
239 if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
240 _errorCode = "Study is empty";
244 //Create the Structure of the Document
245 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
248 BuildTree (this, hdf_group_study_structure);
252 char *eStr = new char [strlen(aUrl.c_str())+17];
253 sprintf(eStr,"Can't open file %s", aUrl.c_str());
254 _errorCode = std::string(eStr);
258 //Read and create notebook variables
259 if(hdf_file->ExistInternalObject("NOTEBOOK_VARIABLES")) {
260 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
261 ReadNoteBookVariables(this, hdf_notebook_vars);
262 hdf_notebook_vars =0; //will be deleted by hdf_sco_group destructor
265 hdf_file->CloseOnDisk();
266 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
269 std::vector<std::string> aFilesToRemove;
270 aFilesToRemove.push_back("hdf_from_ascii.hdf");
271 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
274 delete hdf_file; // all related hdf objects will be deleted
276 // unlock study if it is locked, to set components versions
277 StudyUnlocker unlock(this);
279 //For old studies we have to add "unknown" version tag for all stored components
280 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
281 for (; itcomponent.More(); itcomponent.Next())
283 SALOMEDSImpl_SComponent sco = itcomponent.Value();
284 std::string aCompType = sco.GetComment();
285 if ( aCompType == SALOMEDSImpl_IParameters::getDefaultVisualComponent() ) continue;
286 if ( GetProperties()->GetComponentVersions( aCompType ).empty() )
287 GetProperties()->SetComponentVersion( aCompType, "" ); // empty version means "unknown"
293 //============================================================================
295 * Purpose : Save a Study to it's persistent reference
297 //============================================================================
298 bool SALOMEDSImpl_Study::Save(SALOMEDSImpl_DriverFactory* aFactory,
304 std::string url = URL();
306 _errorCode = "No path specified to save the study. Nothing done";
310 return Impl_SaveAs(url, aFactory, theMultiFile, theASCII);
316 //=============================================================================
317 /*! Function : SaveAs
318 * Purpose : Save a study to the persistent reference aUrl
320 //============================================================================
321 bool SALOMEDSImpl_Study::SaveAs(const std::string& aUrl,
322 SALOMEDSImpl_DriverFactory* aFactory,
327 return Impl_SaveAs(aUrl, aFactory, theMultiFile, theASCII);
330 //=============================================================================
331 /*! Function : _SaveProperties
332 * Purpose : save the study properties in HDF file
334 //============================================================================
335 bool SALOMEDSImpl_Study::Impl_SaveProperties(HDFgroup *hdf_group)
339 HDFdataset *hdf_dataset = 0;
343 // add modifications list (user and date of save)
344 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
346 // unlock study if it is locked, to set modification date
347 StudyUnlocker unlock(this);
349 int month=0,day=0,year=0,hh=0,mn=0,ss=0;
350 SALOMEDSImpl_Tool::GetSystemDate(year, month, day, hh, mn, ss);
351 aProp->SetModification(SALOMEDSImpl_Tool::GetUserName(),
352 mn, hh, day, month, year);
354 // lock study back if it was locked initially, to write correct value of Locked flag
357 std::vector<std::string> aNames;
358 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
360 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
362 std::string units = aProp->GetUnits();
363 std::string comment = aProp->GetComment();
365 std::map< std::string, std::vector<std::string> > allVersions = aProp->GetComponentsVersions();
366 std::map<std::string, std::string> versions;
368 int aLength = 0, aLength1 = 0, anIndex, i, unitsSize = 0, commentSize = 0;
370 for(i=1; i<=aNames.size(); i++)
371 aLength += aNames[i-1].size() + 1;
373 std::map< std::string, std::vector<std::string> >::const_iterator it;
374 for (it = allVersions.begin(); it != allVersions.end(); ++it ) {
375 std::string vlist = "";
376 std::vector<std::string> vl = it->second;
377 std::vector<std::string>::const_iterator vlit;
378 for ( vlit = vl.begin(); vlit != vl.end(); ++vlit ) {
379 if ( vlist != "" ) vlist += ";";
382 versions[ it->first ] = vlist;
383 aLength1 += it->first.size() + vlist.size() + 2;
386 unitsSize = units.size();
387 commentSize = comment.size();
390 //locked flag, modified flag,
391 //minutes, hours, day, months, year, user name, char(1),
392 //minutes, hours, day, months, year, user name, char(1),
393 //.....................................................,
394 //.....................................................,
395 //.....................................................,
396 //minutes, hours, day, months, year, user name, char(1), char(30) <- !!!! used to define end of section with modifications !!!!
397 //units, char(1), comment, char(30) <- !!!! used to define start of section with components' versions !!!!
398 //component=versions, char(1),
399 //component=versions, char(1),
400 //...........................,
401 //component=versions, char(1), char(0)
403 //string length: 1 byte = locked flag, 1 byte = modified flag, (12 + name length + 1) for each name and date, 1 byte (char(30) section delimeter)
404 // unit length + 1, comment length, "zero" byte
406 char* aProperty = new char[3 + aLength + 12 * aNames.size() + 1 + unitsSize + 1 + commentSize + 1 + aLength1 ];
408 sprintf(aProperty,"%c%c", (char)aProp->GetCreationMode(), (aProp->IsLocked())?'l':'u');
410 aLength = aNames.size();
412 for(anIndex = 0; anIndex<aLength; anIndex++) {
413 sprintf(&(aProperty[a]),"%2d%2d%2d%2d%4d%s",
414 (int)(aMinutes[anIndex]),
415 (int)(aHours[anIndex]),
416 (int)(aDays[anIndex]),
417 (int)(aMonths[anIndex]),
418 (int)(aYears[anIndex]),
419 aNames[anIndex].c_str());
420 a = strlen(aProperty);
424 //Write delimeter of the section to define end of the modifications section
427 //Write units if need
428 if(units.size() > 0) {
429 sprintf(&(aProperty[a]),"%s",units.c_str());
430 a = strlen(aProperty);
435 //Write comments if need
436 if(comment.size() > 0) {
437 sprintf(&(aProperty[a]),"%s",comment.c_str());
438 a = strlen(aProperty);
441 aProperty[a++] = 30; //delimeter of the component versions
443 std::map<std::string, std::string>::const_iterator versionsIt;
444 for ( versionsIt = versions.begin(); versionsIt != versions.end(); ++versionsIt ) {
445 sprintf(&(aProperty[a]),"%s=%s",
446 (char*)(versionsIt->first.c_str()),
447 (char*)(versionsIt->second.c_str()));
448 a = a + versionsIt->first.size() + versionsIt->second.size() + 1;
454 name_len = (hdf_int32) a;
455 size[0] = name_len + 1 ;
456 hdf_dataset = new HDFdataset("AttributeStudyProperties",hdf_group,HDF_STRING,size,1);
457 hdf_dataset->CreateOnDisk();
458 hdf_dataset->WriteOnDisk(aProperty);
459 hdf_dataset->CloseOnDisk();
460 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
463 aProp->SetModified(0);
467 //=============================================================================
468 /*! Function : _SaveAs
469 * Purpose : save the study in HDF file
471 //============================================================================
472 bool SALOMEDSImpl_Study::Impl_SaveAs(const std::string& aStudyUrl,
473 SALOMEDSImpl_DriverFactory* aFactory,
477 // Set "C" locale temporarily to avoid possible localization problems
478 Kernel_Utils::Localizer loc;
480 // HDF File will be composed of differents part :
481 // * For each ComponentDataType, all data created by the component
482 // Informations in data group hdf_group_datacomponent
483 // * Study Structure -> Exactly what is contained in Document
484 // Informations in data group hdf_group_study_structure
489 HDFgroup *hdf_group_study_structure =0;
490 HDFgroup *hdf_sco_group =0;
491 HDFgroup *hdf_sco_group2 =0;
492 HDFgroup *hdf_notebook_vars =0;
493 HDFgroup *hdf_notebook_var = 0;
495 HDFgroup *hdf_group_datacomponent =0;
496 HDFdataset *hdf_dataset =0;
498 hdf_int32 name_len = 0;
499 std::string component_name;
501 // Store previous URL
502 std::string anOldName = URL();
504 // Map to store components' versions
505 std::map<std::string, std::string> componentVersions;
507 //Create a temporary url to which the study is saved
508 std::string aUrl = SALOMEDSImpl_Tool::GetTmpDir() + SALOMEDSImpl_Tool::GetNameFromPath(aStudyUrl);
510 // unlock study if it is locked, as some attributes need to be modified
511 StudyUnlocker unlock(this);
513 SALOMEDSImpl_StudyBuilder* SB= NewBuilder();
514 std::map<std::string, SALOMEDSImpl_Driver*> aMapTypeDriver;
517 // mpv 15.12.2003: for saving components we have to load all data from all modules
518 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
519 for (; itcomponent.More(); itcomponent.Next()) {
520 SALOMEDSImpl_SComponent sco = itcomponent.Value();
521 // if there is an associated Engine call its method for saving
522 std::string IOREngine;
524 SALOMEDSImpl_Driver* aDriver = NULL;
525 std::string aCompType = sco.GetComment();
526 if (!sco.ComponentIOR(IOREngine)) {
527 if (!aCompType.empty()) {
528 aDriver = aFactory->GetDriverByType(aCompType);
529 if (aDriver != NULL) {
530 if (!SB->LoadWith(sco, aDriver)) {
531 _errorCode = SB->GetErrorCode();
538 aDriver = aFactory->GetDriverByIOR(IOREngine);
540 aMapTypeDriver[aCompType] = aDriver;
543 _errorCode = "Can not restore information to resave it";
548 // VSR: set URL to new file name
549 // VSR: remember to set previous name if save operation fails
552 // To change for Save
553 // Do not have to do a new file but just a Open??? Rewrite all informations after erasing evrything??
554 hdf_file = new HDFfile((char*)aUrl.c_str());
555 hdf_file->CreateOnDisk();
557 //-----------------------------------------------------------------------
558 // 1 - Create a groupe for each SComponent and Update the PersistanceRef
559 //-----------------------------------------------------------------------
560 hdf_group_datacomponent = new HDFgroup("DATACOMPONENT",hdf_file);
561 hdf_group_datacomponent->CreateOnDisk();
563 for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) {
564 SALOMEDSImpl_SComponent sco = itcomponent.Value();
566 std::string scoid = sco.GetID();
567 hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group_datacomponent);
568 hdf_sco_group->CreateOnDisk();
570 std::string componentDataType = sco.ComponentDataType();
571 std::string IOREngine;
572 if (sco.ComponentIOR(IOREngine)) {
573 // Engine should be already in the map as it was to added before
574 SALOMEDSImpl_Driver* Engine = aMapTypeDriver[componentDataType];
575 if (Engine != NULL) {
576 SALOMEDSImpl_TMPFile* aStream = NULL;
579 componentVersions[ componentDataType ] = Engine->Version();
581 if (theASCII) aStream = Engine->SaveASCII(sco,
582 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
585 else aStream = Engine->Save(sco,
586 SALOMEDSImpl_Tool::GetDirFromPath(aUrl),
589 HDFdataset *hdf_dataset;
590 hdf_size aHDFSize[1];
591 if (length > 0) { //The component saved some auxiliary files, then put them into HDF file
592 aHDFSize[0] = length;
594 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
595 hdf_dataset->CreateOnDisk();
596 hdf_dataset->WriteOnDisk(aStream->Data()); //Save the stream in the HDF file
597 hdf_dataset->CloseOnDisk();
600 if (aStream) delete aStream;
602 // store multifile state
604 hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
605 hdf_dataset->CreateOnDisk();
606 hdf_dataset->WriteOnDisk((void*)(theMultiFile?"M":"S")); // save: multi or single
607 hdf_dataset->CloseOnDisk();
608 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
611 hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
612 hdf_dataset->CreateOnDisk();
613 hdf_dataset->WriteOnDisk((void*)(theASCII?"A":"B")); // save: ASCII or BINARY
614 hdf_dataset->CloseOnDisk();
615 hdf_dataset=0; //will be deleted by hdf_sco_AuxFiles destructor
616 // Creation of the persistance reference attribute
617 Translate_IOR_to_persistentID (sco, Engine, theMultiFile, theASCII);
620 hdf_sco_group->CloseOnDisk();
621 hdf_sco_group=0; // will be deleted by hdf_group_datacomponent destructor
623 hdf_group_datacomponent->CloseOnDisk();
624 hdf_group_datacomponent =0; // will be deleted by hdf_file destructor
626 //-----------------------------------------------------------------------
627 //3 - Write the Study Structure
628 //-----------------------------------------------------------------------
629 hdf_group_study_structure = new HDFgroup("STUDY_STRUCTURE",hdf_file);
630 hdf_group_study_structure->CreateOnDisk();
631 // save component attributes
632 for (itcomponent.Init(); itcomponent.More(); itcomponent.Next()) {
633 SALOMEDSImpl_SComponent SC = itcomponent.Value();
634 std::string scid = SC.GetID();
635 hdf_sco_group2 = new HDFgroup((char*)scid.c_str(), hdf_group_study_structure);
636 hdf_sco_group2->CreateOnDisk();
637 SaveAttributes(SC, hdf_sco_group2);
638 // ComponentDataType treatment
639 component_name = SC.ComponentDataType();
640 name_len = (hdf_int32)component_name.length();
641 size[0] = name_len +1 ;
642 hdf_dataset = new HDFdataset("COMPONENTDATATYPE",hdf_sco_group2,HDF_STRING,size,1);
643 hdf_dataset->CreateOnDisk();
644 hdf_dataset->WriteOnDisk((char*)component_name.c_str());
645 hdf_dataset->CloseOnDisk();
646 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
647 Impl_SaveObject(SC, hdf_sco_group2);
648 hdf_sco_group2->CloseOnDisk();
649 hdf_sco_group2=0; // will be deleted by hdf_group_study_structure destructor
651 //-----------------------------------------------------------------------
652 //4 - Write the Study UseCases Structure
653 //-----------------------------------------------------------------------
654 SALOMEDSImpl_SObject aSO = FindObjectID(USE_CASE_LABEL_ID);
656 HDFgroup *hdf_soo_group = new HDFgroup(USE_CASE_LABEL_ID,hdf_group_study_structure);
657 hdf_soo_group->CreateOnDisk();
658 SaveAttributes(aSO, hdf_soo_group);
659 Impl_SaveObject(aSO, hdf_soo_group);
660 hdf_soo_group->CloseOnDisk();
661 hdf_soo_group=0; // will be deleted by hdf_group_study_structure destructor
663 //-----------------------------------------------------------------------
664 //5 - Write the NoteBook Variables
665 //-----------------------------------------------------------------------
667 //5.1 Create group to store all note book variables
668 hdf_notebook_vars = new HDFgroup("NOTEBOOK_VARIABLES",hdf_file);
669 hdf_notebook_vars->CreateOnDisk();
671 std::string varValue;
673 std::string varIndex;
675 for (int i=0 ;i < myNoteBookVars.size(); i++ ) {
676 // For each variable create HDF group
677 hdf_notebook_var = new HDFgroup((char*)myNoteBookVars[i]->Name().c_str(),hdf_notebook_vars);
678 hdf_notebook_var->CreateOnDisk();
680 // Save Variable type
681 varType = myNoteBookVars[i]->SaveType();
682 name_len = (hdf_int32) varType.length();
683 size[0] = name_len +1 ;
684 hdf_dataset = new HDFdataset("VARIABLE_TYPE",hdf_notebook_var,HDF_STRING,size,1);
685 hdf_dataset->CreateOnDisk();
686 hdf_dataset->WriteOnDisk((char*)varType.c_str());
687 hdf_dataset->CloseOnDisk();
688 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
691 sprintf(buffer,"%d",i);
692 varIndex= std::string(buffer);
693 name_len = (hdf_int32) varIndex.length();
694 size[0] = name_len +1 ;
695 hdf_dataset = new HDFdataset("VARIABLE_INDEX",hdf_notebook_var,HDF_STRING,size,1);
696 hdf_dataset->CreateOnDisk();
697 hdf_dataset->WriteOnDisk((char*)varIndex.c_str());
698 hdf_dataset->CloseOnDisk();
699 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
701 // Save Variable value
702 varValue = myNoteBookVars[i]->Save();
703 name_len = (hdf_int32) varValue.length();
704 size[0] = name_len +1 ;
705 hdf_dataset = new HDFdataset("VARIABLE_VALUE",hdf_notebook_var,HDF_STRING,size,1);
706 hdf_dataset->CreateOnDisk();
707 hdf_dataset->WriteOnDisk((char*)varValue.c_str());
708 hdf_dataset->CloseOnDisk();
709 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
710 hdf_notebook_var->CloseOnDisk();
711 hdf_notebook_var = 0; //will be deleted by hdf_sco_group destructor
713 hdf_notebook_vars->CloseOnDisk();
714 hdf_notebook_vars = 0; //will be deleted by hdf_sco_group destructor
716 // record component versions
717 std::map<std::string, std::string>::const_iterator itVersions;
718 for ( itVersions = componentVersions.begin(); itVersions != componentVersions.end(); ++itVersions )
719 GetProperties()->SetComponentVersion( itVersions->first, itVersions->second );
721 // lock study back if it was locked initially, to write correct value of Locked flag
724 //-----------------------------------------------------------------------
725 //6 - Write the Study Properties
726 //-----------------------------------------------------------------------
727 std::string study_name = Name();
728 name_len = (hdf_int32) study_name.size();
729 size[0] = name_len +1 ;
730 hdf_dataset = new HDFdataset("STUDY_NAME",hdf_group_study_structure,HDF_STRING,size,1);
731 hdf_dataset->CreateOnDisk();
732 hdf_dataset->WriteOnDisk((char*)study_name.c_str());
733 hdf_dataset->CloseOnDisk();
734 hdf_dataset=0; // will be deleted by hdf_group_study_structure destructor
736 Impl_SaveProperties(hdf_group_study_structure);
737 hdf_group_study_structure->CloseOnDisk();
738 hdf_file->CloseOnDisk();
740 hdf_group_study_structure =0; // will be deleted by hdf_file destructor
741 delete hdf_file; // recursively deletes all hdf objects...
743 catch (HDFexception) {
744 _errorCode = "HDFexception ! ";
745 URL( anOldName ); // VSR: restore previous url if operation is failed
748 catch (std::exception& exc) {
749 _errorCode = const_cast<char*>(exc.what());
750 URL( anOldName ); // VSR: restore previous url if operation is failed
754 _errorCode = "Unknown exception ! ";
755 URL( anOldName ); // VSR: restore previous url if operation is failed
758 if (theASCII) { // save file in ASCII format
759 HDFascii::ConvertFromHDFToASCII(aUrl.c_str(), true);
762 // Now it's necessary to copy files from the temporary directory to the user defined directory.
763 // The easiest way to get a list of file in the temporary directory
765 std::string aCmd, aTmpFileDir = SALOMEDSImpl_Tool::GetTmpDir();
766 std::string aTmpFile = aTmpFileDir +"files";
767 std::string aStudyTmpDir = SALOMEDSImpl_Tool::GetDirFromPath(aUrl);
770 aCmd = "dir /B \"" + aStudyTmpDir +"\" > " + aTmpFile;
772 aCmd ="ls -1 \"" + aStudyTmpDir +"\" > " + aTmpFile;
774 system(aCmd.c_str());
776 // Iterate and move files in the temporary directory
777 FILE* fp = fopen(aTmpFile.c_str(), "rb");
779 URL( anOldName ); // VSR: restore previous url if operation is failed
782 char* buffer = new char[2047];
784 while (!feof(fp) && !errors) {
785 if ((fgets(buffer, 2046, fp)) == NULL) break;
786 size_t aLen = strlen(buffer);
787 if (buffer[aLen-1] == '\n') buffer[aLen-1] = char(0);
789 aCmd = "move /Y \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl) +"\"";
791 aCmd = "mv -f \"" + aStudyTmpDir + std::string(buffer) + "\" \"" + SALOMEDSImpl_Tool::GetDirFromPath(aStudyUrl)+"\"";
793 errors = system(aCmd.c_str());
801 DeleteFileA(aTmpFile.c_str());
803 unlink(aTmpFile.c_str());
807 RemoveDirectoryA(aTmpFileDir.c_str());
808 RemoveDirectoryA(aStudyTmpDir.c_str());
810 rmdir(aTmpFileDir.c_str());
811 rmdir(aStudyTmpDir.c_str());
815 // VSR: finally, if all is done without errors, mark study as Saved
822 //============================================================================
823 /*! Function : Impl_SaveObject
826 //============================================================================
827 bool SALOMEDSImpl_Study::Impl_SaveObject(const SALOMEDSImpl_SObject& SC,
828 HDFgroup *hdf_group_datatype)
832 // Write in group hdf_group_datatype all informations of SObject SC
833 // Iterative function to parse all SObjects under a SComponent
835 HDFgroup *hdf_group_sobject = 0;
837 DF_ChildIterator itchild(SC.GetLabel());
838 for (; itchild.More(); itchild.Next()) {
839 // mpv: don't save empty labels
840 std::vector<DF_Attribute*> attr = itchild.Value().GetAttributes();
841 if (attr.size() == 0) { //No attributes on the label
842 DF_ChildIterator subchild(itchild.Value());
843 if (!subchild.More()) {
846 subchild.Init(itchild.Value(), true);
848 for (; subchild.More() && anEmpty; subchild.Next()) {
849 std::vector<DF_Attribute*> attr2 = subchild.Value().GetAttributes();
851 anEmpty = false; //There are attributes on the child label
855 if (anEmpty) continue;
858 SALOMEDSImpl_SObject SO = SALOMEDSImpl_Study::SObject(itchild.Value());
860 std::string scoid = SO.GetID();
861 hdf_group_sobject = new HDFgroup(scoid.c_str(), hdf_group_datatype);
862 hdf_group_sobject->CreateOnDisk();
863 SaveAttributes(SO, hdf_group_sobject);
864 Impl_SaveObject(SO, hdf_group_sobject);
865 hdf_group_sobject->CloseOnDisk();
866 hdf_group_sobject =0; // will be deleted by father hdf object destructor
871 //============================================================================
872 /*! Function : CanCopy
875 //============================================================================
876 bool SALOMEDSImpl_Study::CanCopy(const SALOMEDSImpl_SObject& theObject,
877 SALOMEDSImpl_Driver* theEngine)
880 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
881 if (!aComponent) return false;
882 if (aComponent.GetLabel() == theObject.GetLabel()) return false;
883 std::string IOREngine;
884 if (!aComponent.ComponentIOR(IOREngine)) return false;
885 if (theEngine == NULL) return false;
886 return theEngine->CanCopy(theObject);
889 //============================================================================
890 /*! Function : CopyLabel
893 //============================================================================
894 bool SALOMEDSImpl_Study::CopyLabel(SALOMEDSImpl_Driver* theEngine,
895 const int theSourceStartDepth,
896 const DF_Label& theSource,
897 const DF_Label& theDestinationMain)
902 DF_Label aTargetLabel = theDestinationMain;
903 DF_Label aAuxTargetLabel = theDestinationMain.Father().FindChild(2);
904 for(a = theSource.Depth() - theSourceStartDepth; a > 0 ; a--) {
905 DF_Label aSourceLabel = theSource;
906 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
907 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
908 aAuxTargetLabel = aAuxTargetLabel.FindChild(aSourceLabel.Tag());
910 // iterate attributes
911 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
912 for(int i = 0, len = attrList.size(); i<len; i++) {
913 DF_Attribute* anAttr = attrList[i];
914 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
915 if (type.substr(0, 17) == std::string("AttributeTreeNode")) continue; // never copy tree node attribute
916 if (type == std::string("AttributeTarget")) continue; // and target attribute
918 if (type == std::string("AttributeReference")) { // reference copied as Comment in aux tree
919 DF_Label aReferenced = dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Get();
920 std::string anEntry = aReferenced.Entry();
921 // store the value of name attribute of referenced label
922 SALOMEDSImpl_AttributeName* aNameAttribute;
923 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aReferenced.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
925 anEntry += aNameAttribute->Value();
927 SALOMEDSImpl_AttributeComment::Set(aAuxTargetLabel, anEntry);
931 if (type == std::string("AttributeIOR")) { // IOR => ID and TMPFile of Engine
932 std::string anEntry = theSource.Entry();
933 SALOMEDSImpl_SObject aSO = FindObjectID(anEntry);
936 SALOMEDSImpl_TMPFile* aStream = theEngine->CopyFrom(aSO, anObjID, aLen);
937 std::string aResStr("");
938 for(a = 0; a < aLen; a++) {
939 aResStr += (char)(aStream->Get(a));
942 if(aStream) delete aStream;
944 SALOMEDSImpl_AttributeInteger::Set(aAuxTargetLabel, anObjID);
945 SALOMEDSImpl_AttributeName::Set(aAuxTargetLabel, aResStr);
948 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
949 aTargetLabel.AddAttribute(aNewAttribute);
950 anAttr->Paste(aNewAttribute);
956 //============================================================================
960 //============================================================================
961 bool SALOMEDSImpl_Study::Copy(const SALOMEDSImpl_SObject& theObject,
962 SALOMEDSImpl_Driver* theEngine)
966 // adoptation for alliances datamodel copy: without IOR attributes !!!
967 bool aStructureOnly; // copy only SObjects and attributes without component help
968 aStructureOnly = !theObject.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID());
971 _errorCode = "Document is null";
975 //Clear the clipboard
976 _clipboard->Main().Root().ForgetAllAttributes(true);
977 _appli->Close(_clipboard);
978 _clipboard = _appli->NewDocument("SALOME_STUDY");
980 // set component data type to the name attribute of root label
981 if (!aStructureOnly) {
982 SALOMEDSImpl_AttributeComment::Set(_clipboard->Main().Root(),
983 theEngine->ComponentDataType());
985 // iterate all theObject's label children
986 DF_Label aStartLabel = theObject.GetLabel();
987 int aSourceStartDepth = aStartLabel.Depth();
989 // copy main source label
990 CopyLabel(theEngine, aSourceStartDepth, aStartLabel, _clipboard->Main());
992 // copy all subchildren of the main source label (all levels)
993 DF_ChildIterator anIterator(aStartLabel, true);
994 for(; anIterator.More(); anIterator.Next()) {
995 CopyLabel(theEngine, aSourceStartDepth, anIterator.Value(), _clipboard->Main());
1001 //============================================================================
1002 /*! Function : CanPaste
1005 //============================================================================
1006 bool SALOMEDSImpl_Study::CanPaste(const SALOMEDSImpl_SObject& theObject,
1007 SALOMEDSImpl_Driver* theEngine)
1012 _errorCode = "Clipboard is null";
1016 SALOMEDSImpl_AttributeComment* aCompName = NULL;
1017 if (!(aCompName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1018 _errorCode = "Clipboard has no component type";
1021 SALOMEDSImpl_AttributeInteger* anObjID;
1022 if (!(anObjID=(SALOMEDSImpl_AttributeInteger*)_clipboard->Main().Father().FindChild(2).FindAttribute(SALOMEDSImpl_AttributeInteger::GetID()))) {
1023 _errorCode = "Clipboard has no object id";
1026 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1028 _errorCode = "Object doesn't belong to component";
1032 std::string IOREngine;
1033 if (!aComponent.ComponentIOR(IOREngine)) {
1034 _errorCode = "component has no IOR";
1037 return theEngine->CanPaste(aCompName->Value(), anObjID->Value());
1040 //============================================================================
1041 /*! Function : PasteLabel
1044 //============================================================================
1045 DF_Label SALOMEDSImpl_Study::PasteLabel(SALOMEDSImpl_Driver* theEngine,
1046 const DF_Label& theSource,
1047 const DF_Label& theDestinationStart,
1048 const bool isFirstElement)
1052 // get corresponding source, target and auxiliary labels
1053 DF_Label aTargetLabel = theDestinationStart;
1055 DF_Label aAuxSourceLabel = theSource.Root().FindChild(2);
1057 if (!isFirstElement) {
1058 for(a = theSource.Depth() - 1; a > 0 ; a--) {
1059 DF_Label aSourceLabel = theSource;
1060 for(int aNbFather = 1; aNbFather < a; aNbFather++) aSourceLabel = aSourceLabel.Father();
1061 aTargetLabel = aTargetLabel.FindChild(aSourceLabel.Tag());
1062 aAuxSourceLabel = aAuxSourceLabel.FindChild(aSourceLabel.Tag());
1064 SALOMEDSImpl_SObject so = GetSObject(aTargetLabel);
1065 addSO_Notification(so);
1068 // check auxiliary label for TMPFile => IOR
1069 SALOMEDSImpl_AttributeName* aNameAttribute = NULL;
1070 if ((aNameAttribute=(SALOMEDSImpl_AttributeName*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1071 SALOMEDSImpl_AttributeInteger* anObjID = (SALOMEDSImpl_AttributeInteger*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeInteger::GetID());
1072 SALOMEDSImpl_AttributeComment* aComponentName = (SALOMEDSImpl_AttributeComment*)theSource.Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID());
1073 std::string aCompName = aComponentName->Value();
1075 if (theEngine->CanPaste(aCompName, anObjID->Value())) {
1076 std::string aTMPStr = aNameAttribute->Value();
1077 int aLen = aTMPStr.size();
1078 unsigned char* aStream = NULL;
1080 aStream = new unsigned char[aLen+10];
1081 for(a = 0; a < aLen; a++) {
1082 aStream[a] = aTMPStr[a];
1086 std::string anEntry = aTargetLabel.Entry();
1087 SALOMEDSImpl_SObject aPastedSO = FindObjectID(anEntry);
1089 if (isFirstElement) {
1090 std::string aDestEntry = theEngine->PasteInto(aStream,
1093 aPastedSO.GetFatherComponent());
1094 aTargetLabel = DF_Label::Label(theDestinationStart, aDestEntry);
1096 theEngine->PasteInto(aStream, aLen, anObjID->Value(), aPastedSO);
1098 if(aStream != NULL) delete []aStream;
1102 // iterate attributes
1103 std::vector<DF_Attribute*> attrList = theSource.GetAttributes();
1104 for(int i = 0, len = attrList.size(); i<len; i++) {
1105 DF_Attribute* anAttr = attrList[i];
1106 if (aTargetLabel.FindAttribute(anAttr->ID())) {
1107 aTargetLabel.ForgetAttribute(anAttr->ID());
1109 DF_Attribute* aNewAttribute = anAttr->NewEmpty();
1110 aTargetLabel.AddAttribute(aNewAttribute);
1111 anAttr->Paste(aNewAttribute);
1114 // check auxiliary label for Comment => reference or name attribute of the referenced object
1115 SALOMEDSImpl_AttributeComment* aCommentAttribute = NULL;
1116 if ((aCommentAttribute=(SALOMEDSImpl_AttributeComment*)aAuxSourceLabel.FindAttribute(SALOMEDSImpl_AttributeComment::GetID()))) {
1117 char * anEntry = new char[aCommentAttribute->Value().size() + 1];
1118 strcpy(anEntry, std::string(aCommentAttribute->Value()).c_str());
1119 char* aNameStart = strchr(anEntry, ' ');
1124 // copy to the same study, reanimate reference
1125 DF_Label aRefLabel = DF_Label::Label(aTargetLabel, anEntry);
1126 SALOMEDSImpl_AttributeReference::Set(aTargetLabel, aRefLabel);
1127 // target attributes structure support
1128 SALOMEDSImpl_AttributeTarget::Set(aRefLabel)->Add(SALOMEDSImpl_Study::SObject(aTargetLabel));
1133 return aTargetLabel;
1136 //============================================================================
1137 /*! Function : Paste
1140 //============================================================================
1141 SALOMEDSImpl_SObject SALOMEDSImpl_Study::Paste(const SALOMEDSImpl_SObject& theObject,
1142 SALOMEDSImpl_Driver* theEngine)
1146 SALOMEDSImpl_SObject so;
1148 // if study is locked, then paste can't be done
1149 if (GetProperties()->IsLocked()) {
1150 _errorCode = "LockProtection";
1151 throw LockProtection("LockProtection");
1154 // if there is no component name, then paste only SObjects and attributes: without component help
1155 SALOMEDSImpl_AttributeComment* aComponentName = NULL;
1156 bool aStructureOnly = !(aComponentName=(SALOMEDSImpl_AttributeComment*)_clipboard->Main().Root().FindAttribute(SALOMEDSImpl_AttributeComment::GetID()));
1158 // CAF document of current study usage
1160 _errorCode = "Document is null";
1164 SALOMEDSImpl_SComponent aComponent = theObject.GetFatherComponent();
1166 // fill root inserted SObject
1167 DF_Label aStartLabel;
1168 if (aStructureOnly) {
1169 DF_Label anObjectLabel = DF_Label::Label(_doc->Main(), theObject.GetID());
1170 aStartLabel = PasteLabel(theEngine, _clipboard->Main(), anObjectLabel, false);
1172 DF_Label aComponentLabel = DF_Label::Label(_doc->Main(), aComponent.GetID());
1173 aStartLabel = PasteLabel(theEngine, _clipboard->Main(), aComponentLabel, true);
1176 // paste all sublebels
1177 DF_ChildIterator anIterator(_clipboard->Main(), true);
1178 for(; anIterator.More(); anIterator.Next()) {
1179 PasteLabel(theEngine, anIterator.Value(), aStartLabel, false);
1182 return SALOMEDSImpl_Study::SObject(aStartLabel);
1185 //============================================================================
1186 /*! Function : GetPersistentReference
1187 * Purpose : Get persistent reference of study (idem URL())
1189 //============================================================================
1190 std::string SALOMEDSImpl_Study::GetPersistentReference()
1196 //============================================================================
1197 /*! Function : IsEmpty
1198 * Purpose : Detect if study is empty
1200 //============================================================================
1201 bool SALOMEDSImpl_Study::IsEmpty()
1204 if (!_doc) return true;
1205 return _doc->IsEmpty();
1208 //============================================================================
1209 /*! Function : FindComponent
1210 * Purpose : Find a Component with ComponentDataType = aComponentName
1212 //============================================================================
1213 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName)
1218 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
1219 SALOMEDSImpl_SComponent compo;
1221 for (; itcomp.More(); itcomp.Next()) {
1222 SALOMEDSImpl_SComponent SC = itcomp.Value();
1223 name = SC.ComponentDataType();
1224 if(aComponentName == name) {
1232 _errorCode = "No component was found";
1238 //============================================================================
1239 /*! Function : FindComponentID
1240 * Purpose : Find a Component from it's ID
1242 //============================================================================
1243 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID)
1247 // Iterate on each components defined in the study
1248 // Get the component ID and compare with aComponentID
1251 SALOMEDSImpl_SComponent compo;
1253 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
1254 for (; itcomp.More(); itcomp.Next()) {
1255 SALOMEDSImpl_SComponent SC = itcomp.Value();
1257 if(aComponentID == ID)
1259 // ComponentID found
1266 _errorCode = "No component was found";
1273 //============================================================================
1274 /*! Function : FindObject
1275 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
1277 //============================================================================
1278 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName)
1282 // Iterate to all components defined in the study
1283 // After testing the component name, iterate in all objects defined under
1284 // components (function _FindObject)
1286 SALOMEDSImpl_SObject RefSO;
1288 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
1289 for (; it.More();it.Next()){
1292 SALOMEDSImpl_SComponent SC = it.Value();
1293 if (SC.GetName() == anObjectName)
1299 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
1302 if(!RefSO) _errorCode = "No object was found";
1306 //============================================================================
1307 /*! Function : FindObjectID
1308 * Purpose : Find an Object with ID = anObjectID
1310 //============================================================================
1311 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID)
1314 SALOMEDSImpl_SObject so;
1316 // Convert aSO->GetID in DF_Label.
1317 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
1320 _errorCode = "No label was found by ID";
1323 return GetSObject(Lab);
1327 //============================================================================
1328 /*! Function : CreateObjectID
1329 * Purpose : Creates an Object with ID = anObjectID
1331 //============================================================================
1332 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID)
1335 SALOMEDSImpl_SObject so;
1337 // Convert aSO->GetID in DF_Label.
1338 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
1341 _errorCode = "Can not create a label";
1344 return GetSObject(Lab);
1348 //============================================================================
1349 /*! Function : FindObjectByName
1350 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
1351 * : with ComponentDataType = aComponentName
1353 //============================================================================
1354 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName,
1355 const std::string& aComponentName)
1359 std::vector<SALOMEDSImpl_SObject> listSO;
1361 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
1363 _errorCode = "Can not find the component";
1367 // Iterate on each object and subobject of the component
1368 // If objectName is found add it to the list of SObjects
1369 std::string childName ;
1371 std::string compoId = compo.GetID();
1372 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
1373 for ( ; it.More(); it.Next() ) {
1375 SALOMEDSImpl_SObject CSO = it.Value();
1376 if ( CSO.GetName() == anObjectName ) {
1378 listSO.push_back(CSO) ;
1381 /* looks also for eventual children */
1382 bool found = false ;
1383 CSO = _FindObject( CSO, anObjectName, found ) ;
1385 listSO.push_back(CSO) ;
1394 //============================================================================
1395 /*! Function : FindObjectIOR
1396 * Purpose : Find an Object with IOR = anObjectIOR
1398 //============================================================================
1399 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR)
1403 SALOMEDSImpl_SObject aResult ;
1405 // searching in the datamap for optimization
1406 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anObjectIOR);
1407 if (it != myIORLabels.end()) {
1408 aResult = GetSObject(it->second);
1409 // 11 oct 2002: forbidden attributes must be checked here
1410 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
1411 myIORLabels.erase(anObjectIOR);
1412 aResult = SALOMEDSImpl_SObject();
1416 if(!aResult) _errorCode = "No object was found";
1420 //============================================================================
1421 /*! Function : FindObjectByPath
1422 * Purpose : Find an Object by its path = thePath
1424 //============================================================================
1425 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath)
1429 std::string aPath(thePath), aToken;
1430 SALOMEDSImpl_SObject aSO;
1431 int aLength = aPath.size();
1432 bool isRelative = false;
1434 if(aLength == 0) { //Empty path - return the current context
1438 if(aPath[0] != '/') //Relative path
1441 DF_ChildIterator anIterator;
1443 SALOMEDSImpl_AttributeName* anAttr;
1449 if(aPath.size() == 1 && aPath[0] == '/') { //Root
1450 return GetSObject(_doc->Main());
1452 anIterator.Init(_doc->Main(), false);
1455 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
1456 for(int i = 0, len = vs.size(); i<len; i++) {
1459 if(aToken.size() == 0) break;
1461 for ( ; anIterator.More(); anIterator.Next() ) {
1462 aLabel = anIterator.Value();
1463 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
1464 if(anAttr->Value() == aToken) {
1465 if(i == (len-1)) { //The searched label is found (no part of the path is left)
1466 return GetSObject(aLabel);
1469 anIterator.Init(aLabel, false);
1477 if(!aSO) _errorCode = "No object was found";
1481 //============================================================================
1482 /*! Function : GetObjectPath
1485 //============================================================================
1486 std::string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
1490 std::string aPath("");
1492 _errorCode = "Null object";
1496 std::string aName = theObject.GetName();
1497 if(!aName.empty() && aName != "" ) {
1498 std::string aValue("/");
1502 SALOMEDSImpl_SObject aFather = theObject.GetFather();
1504 aName = aFather.GetName();
1505 if(!aName.empty() && aName != "") {
1506 aValue = GetObjectPath(aFather);
1507 aPath = aValue + aPath;
1516 //============================================================================
1517 /*! Function : GetObjectPathByIOR
1520 //============================================================================
1521 std::string SALOMEDSImpl_Study::GetObjectPathByIOR(const std::string& theIOR)
1526 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
1528 _errorCode = "No SObject was found by IOR";
1532 return GetObjectPath(so);
1535 //============================================================================
1536 /*! Function : NewChildIterator
1537 * Purpose : Create a ChildIterator from an SObject
1539 //============================================================================
1540 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
1543 return SALOMEDSImpl_ChildIterator(aSO);
1547 //============================================================================
1548 /*! Function : NewComponentIterator
1549 * Purpose : Create a SComponentIterator
1551 //============================================================================
1552 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
1555 return SALOMEDSImpl_SComponentIterator(_doc);
1559 //============================================================================
1560 /*! Function : NewBuilder
1561 * Purpose : Create a StudyBuilder
1563 //============================================================================
1564 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
1568 _builder->SetOnAddSObject(_cb);
1569 _builder->SetOnRemoveSObject(_cb);
1575 //============================================================================
1577 * Purpose : get study name
1579 //============================================================================
1580 std::string SALOMEDSImpl_Study::Name()
1583 return Kernel_Utils::GetBaseName( _name, false );
1586 //============================================================================
1588 * Purpose : set study name
1590 //============================================================================
1591 void SALOMEDSImpl_Study::Name(const std::string& name)
1597 //============================================================================
1598 /*! Function : IsSaved
1599 * Purpose : get if study has been saved
1601 //============================================================================
1602 bool SALOMEDSImpl_Study::IsSaved()
1608 //============================================================================
1609 /*! Function : IsSaved
1610 * Purpose : set if study has been saved
1612 //============================================================================
1613 void SALOMEDSImpl_Study::IsSaved(bool save)
1617 if(save) _doc->SetModified(false);
1620 //============================================================================
1621 /*! Function : IsModified
1622 * Purpose : Detect if a Study has been modified since it has been saved
1624 //============================================================================
1625 bool SALOMEDSImpl_Study::IsModified()
1629 // True if is modified
1630 if (_doc && _doc->IsModified()) return true;
1635 //============================================================================
1637 * Purpose : get URL of the study (persistent reference of the study)
1639 //============================================================================
1640 std::string SALOMEDSImpl_Study::URL()
1646 //============================================================================
1648 * Purpose : set URL of the study (persistent reference of the study)
1650 //============================================================================
1651 void SALOMEDSImpl_Study::URL(const std::string& url)
1657 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
1658 std::string tmp(_URL);
1660 char *aName = (char*)tmp.ToCString();
1661 char *adr = strtok(aName, "/");
1665 adr = strtok(NULL, "/");
1671 //============================================================================
1672 /*! Function : _FindObject
1673 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
1675 //============================================================================
1676 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
1677 const std::string& theObjectName,
1680 SALOMEDSImpl_SObject RefSO;
1681 if(!SO) return RefSO;
1683 // Iterate on each objects and subobjects of the component
1684 // If objectName find, stop the loop and get the object reference
1685 SALOMEDSImpl_AttributeName* anAttr;
1687 std::string soid = SO.GetID();
1688 DF_ChildIterator it(SO.GetLabel());
1689 for (; it.More(); it.Next()){
1692 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
1694 std::string Val(anAttr->Value());
1695 if (Val == theObjectName)
1697 RefSO = GetSObject(it.Value());
1701 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
1707 //============================================================================
1708 /*! Function : _FindObjectIOR
1709 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
1711 //============================================================================
1712 SALOMEDSImpl_SObject
1713 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
1714 const std::string& theObjectIOR,
1717 SALOMEDSImpl_SObject RefSO, aSO;
1718 if(!SO) return RefSO;
1720 // Iterate on each objects and subobjects of the component
1721 // If objectName find, stop the loop and get the object reference
1722 SALOMEDSImpl_AttributeIOR* anAttr;
1724 DF_ChildIterator it(SO.GetLabel());
1725 for (; it.More();it.Next()){
1728 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
1730 std::string Val(anAttr->Value());
1731 if (Val == theObjectIOR)
1733 RefSO = GetSObject(it.Value());
1737 aSO = GetSObject(it.Value());
1738 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
1744 //============================================================================
1745 /*! Function : _GetNoteBookAccessor
1746 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
1748 //============================================================================
1749 std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
1750 return std::string("notebook");
1753 //============================================================================
1754 /*! Function : _GetStudyVariablesScript
1757 //============================================================================
1758 std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
1760 std::string dump("");
1762 if(myNoteBookVars.empty())
1765 Kernel_Utils::Localizer loc;
1767 dump += "####################################################\n";
1768 dump += "## Begin of NoteBook variables section ##\n";
1769 dump += "####################################################\n";
1771 std::string set_method = _GetNoteBookAccessor()+".set(";
1772 std::string varName;
1773 std::string varValue;
1774 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
1775 varName = myNoteBookVars[i]->Name();
1776 varValue = myNoteBookVars[i]->SaveToScript();
1777 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
1780 dump += "####################################################\n";
1781 dump += "## End of NoteBook variables section ##\n";
1782 dump += "####################################################\n";
1787 //============================================================================
1788 /*! Function : _GetNoteBookAccess
1791 //============================================================================
1792 std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
1794 std::string notebook = "import salome_notebook\n";
1795 notebook += _GetNoteBookAccessor() + " = salome_notebook.NoteBook()" ;
1799 bool SALOMEDSImpl_Study::IsLocked()
1802 return GetProperties()->IsLocked();
1805 void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry)
1808 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
1809 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
1810 if (it != myIORLabels.end()) myIORLabels.erase(it);
1811 myIORLabels[anIOR] = aLabel;
1814 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
1816 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
1817 if (it != myIORLabels.end())
1819 //remove the ior entry and decref the genericobj (if it's one)
1820 myIORLabels.erase(it);
1824 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudyImpl(const DF_Label& theLabel)
1826 SALOMEDSImpl_StudyHandle* Att;
1827 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
1833 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
1835 return GetStudyImpl(theLabel)->GetSObject(theLabel);
1838 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
1840 return GetStudyImpl(theLabel)->GetSComponent(theLabel);
1844 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1846 std::string aString = theAttribute->Label().Entry();
1847 GetStudyImpl(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1850 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1853 std::vector<SALOMEDSImpl_SObject> aSeq;
1855 SALOMEDSImpl_AttributeTarget* aTarget;
1856 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1857 return aTarget->Get();
1864 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1867 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1870 std::string SALOMEDSImpl_Study::GetLastModificationDate()
1873 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1875 std::vector<std::string> aNames;
1876 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1877 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1879 int aLastIndex = aNames.size()-1;
1881 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1882 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1883 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1884 std::string aResStr (aResult);
1888 std::vector<std::string> SALOMEDSImpl_Study::GetModificationsDate()
1891 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1893 std::vector<std::string> aNames;
1894 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1895 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1897 int anIndex, aLength = aNames.size();
1898 std::vector<std::string> aDates;
1900 for (anIndex = 1; anIndex < aLength; anIndex++) {
1902 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1903 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1904 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1905 aDates.push_back(aDate);
1912 //============================================================================
1913 /*! Function : GetUseCaseBuilder
1914 * Purpose : Returns a UseCase builder
1916 //============================================================================
1917 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1920 return _useCaseBuilder;
1923 //============================================================================
1924 /*! Function : GetSComponent
1927 //============================================================================
1928 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry)
1930 SALOMEDSImpl_SComponent aSCO;
1931 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1932 aSCO = _mapOfSCO[theEntry];
1934 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1935 aSCO = SALOMEDSImpl_SComponent(aLabel);
1936 _mapOfSCO[theEntry] = aSCO;
1942 //============================================================================
1943 /*! Function : GetSComponent
1946 //============================================================================
1947 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1949 return SALOMEDSImpl_SComponent(theLabel);
1952 //============================================================================
1953 /*! Function : GetSObject
1956 //============================================================================
1957 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry)
1959 SALOMEDSImpl_SObject aSO;
1960 std::map<std::string, SALOMEDSImpl_SObject>::iterator it=_mapOfSO.find(theEntry);
1961 if(it != _mapOfSO.end())
1964 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1965 aSO = SALOMEDSImpl_SObject(aLabel);
1966 _mapOfSO[theEntry] = aSO;
1972 //============================================================================
1973 /*! Function : GetSObject
1976 //============================================================================
1977 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1979 return SALOMEDSImpl_SObject(theLabel);
1982 //============================================================================
1983 /*! Function : GetAttribute
1986 //============================================================================
1987 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry,
1988 const std::string& theType)
1990 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1991 DF_Attribute* anAttr;
1992 aSO.FindAttribute(anAttr, theType);
1996 //! number of spaces for indentation in Python dump files (to replace \t symbols)
1997 static const int indent_size = 2;
1999 static std::string replace_tabs( const std::string& in )
2001 std::string out = in;
2003 size_t pos = out.find( '\t' );
2004 while ( pos != std::string::npos ) {
2005 out.replace( pos, 1, indent_size, ' ' );
2006 pos = out.find( '\t' );
2012 static std::string GetComponentHeader(const char* theComponentName)
2014 std::stringstream txt;
2015 txt << "###" << std::endl;
2016 txt << "### " << theComponentName << " component" << std::endl;
2017 txt << "###" << std::endl;
2021 //============================================================================
2022 /*! Function : DumpStudy
2025 //============================================================================
2026 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
2027 const std::string& theBaseName,
2030 SALOMEDSImpl_DriverFactory* theFactory)
2034 if(theFactory == NULL) {
2035 _errorCode = "Null factory for creation of Engines";
2039 std::vector<std::string> aSeq;
2040 std::string aCompType, aFactoryType;
2042 //Build a list of all components in the Study
2043 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
2045 for (; itcomponent.More(); itcomponent.Next()) {
2046 SALOMEDSImpl_SComponent sco = itcomponent.Value();
2047 aCompType = sco.ComponentDataType();
2048 if (aCompType == "GEOM")
2049 aSeq.insert(aSeq.begin(), aCompType);
2051 aSeq.push_back(aCompType);
2053 // re-arrange modules in the sequence, if specific order is given via SALOME_MODULES_ORDER environment variable.
2054 if ( getenv("SALOME_MODULES_ORDER") != 0 ) {
2055 std::string order = getenv("SALOME_MODULES_ORDER");
2056 std::vector<std::string> mlist;
2057 while ( !order.empty() ) {
2058 size_t idx = order.find( "," );
2059 std::string m = order.substr(0, idx);
2060 order = order.substr( ( idx == std::string::npos ) ? order.size() : idx+1 );
2061 if ( m.empty() || std::find( mlist.begin(), mlist.end(), m ) != mlist.end() ) continue;
2062 mlist.push_back( m );
2065 for ( std::vector<std::string>::reverse_iterator mit = mlist.rbegin(); mit != mlist.rend(); ++mit ) {
2066 std::vector<std::string>::iterator it = std::find( aSeq.begin(), aSeq.end(), *mit );
2067 if ( it != aSeq.end() ) {
2069 aSeq.insert( aSeq.begin(), *mit );
2075 std::string aFileName =
2076 thePath + std::string("\\") + theBaseName + std::string(".py");
2078 std::string aFileName =
2079 thePath + std::string("/") + theBaseName + std::string(".py");
2082 //Create a file that will contain a main Study script
2084 fp.open(aFileName.c_str(), std::ios::out);
2087 bool isOpened = fp.is_open();
2089 bool isOpened = fp.rdbuf()->is_open();
2093 _errorCode = std::string("Can't create a file ")+aFileName;
2097 std::stringstream sfp;
2099 std::string aBatchModeScript = "salome";
2101 //Output to the main Study script required Python modules import,
2102 //set sys.path and add a creation of the study.
2105 sfp << GetDumpStudyComment() << std::endl;
2108 sfp << "import sys" << std::endl;
2109 sfp << "import " << aBatchModeScript << std::endl << std::endl;
2111 // initialization function
2112 sfp << aBatchModeScript << ".salome_init()" << std::endl;
2114 // notebook initialization
2115 sfp << _GetNoteBookAccess() << std::endl;
2117 // extend sys.path with the directory where the script is being dumped to
2118 sfp << "sys.path.insert(0, r\'" << thePath << "\')" << std::endl << std::endl;
2120 // dump NoteBook variables
2121 sfp << _GetStudyVariablesScript();
2123 // dump visual parameters if necessary
2124 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
2125 int lastSavePoint = -1;
2127 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
2128 if(lastSavePoint > 0) {
2129 sfp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
2133 std::vector<std::string> aSeqOfFileNames;
2135 // dump all components and create the components specific scripts
2137 int aLength = aSeq.size();
2138 for(int i = 1; i <= aLength; i++) {
2140 aCompType = aSeq[i-1];
2141 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
2142 SALOMEDSImpl_Driver* aDriver = NULL;
2143 // if there is an associated Engine call its method for saving
2144 std::string IOREngine;
2146 if (!sco.ComponentIOR(IOREngine)) {
2147 if (!aCompType.empty()) {
2149 aDriver = theFactory->GetDriverByType(aCompType);
2151 if (aDriver != NULL) {
2152 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
2153 if(!SB->LoadWith(sco, aDriver)) {
2154 _errorCode = SB->GetErrorCode();
2162 aDriver = theFactory->GetDriverByIOR(IOREngine);
2165 _errorCode = "Can not restore information to dump it";
2169 if(aDriver == NULL) continue;
2172 long aStreamLength = 0;
2173 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(isPublished, isMultiFile, isValidScript, aStreamLength);
2174 if ( !isValidScript )
2177 std::stringstream sfp2;
2179 //Output the Python script generated by the component in the newly created file.
2181 sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
2183 sfp2 << GetComponentHeader( aCompType.c_str() ) << std::endl;
2184 sfp2 << aStream->Data();
2186 if ( isMultiFile ) {
2187 //Create a file that will contain the component specific script
2190 aFileName=thePath+std::string("\\");
2192 aFileName=thePath+std::string("/");
2194 std::string aScriptName;
2195 aScriptName += theBaseName;
2197 aScriptName += aCompType;
2199 aFileName += aScriptName+ std::string(".py");
2200 aSeqOfFileNames.push_back(aFileName);
2202 fp2.open(aFileName.c_str(), std::ios::out);
2205 isOpened = fp2.is_open();
2207 isOpened = fp2.rdbuf()->is_open();
2211 _errorCode = std::string("Can't create a file ")+aFileName;
2212 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
2216 // replace '\t' symbols
2217 fp2 << replace_tabs( sfp2.str() );
2221 //Add to the main script a call to RebuildData of the generated by the component the Python script
2222 sfp << "import " << aScriptName << std::endl;
2223 sfp << aScriptName << ".RebuildData()" << std::endl;
2228 if(aStream) delete aStream;
2232 sfp << "if salome.sg.hasDesktop():" << std::endl;
2233 sfp << "\tsalome.sg.updateObjBrowser()" << std::endl;
2235 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
2236 sfp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
2239 // replace '\t' symbols
2240 fp << replace_tabs( sfp.str() );
2247 //=======================================================================
2248 //function : GetDumpStudyComment
2249 //purpose : return a header comment for a DumpStudy script
2250 //=======================================================================
2252 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
2254 std::stringstream txt;
2255 txt << "#!/usr/bin/env python" << std::endl << std::endl;
2256 txt << "###" << std::endl;
2257 txt << "### This file is generated automatically by SALOME v"
2258 << KERNEL_VERSION_STR
2259 << " with dump python functionality";
2260 if ( theComponentName )
2261 txt << " (" << theComponentName << " component)";
2263 txt << "###" << std::endl;
2267 void dumpSO(const SALOMEDSImpl_SObject& theSO,
2269 const std::string& Tab,
2270 SALOMEDSImpl_Study* theStudy);
2272 //============================================================================
2276 //============================================================================
2277 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
2279 //Create a file that will contain a main Study script
2281 fp.open(theFileName.c_str(), std::ios::out);
2284 bool isOpened = fp.is_open();
2286 bool isOpened = fp.rdbuf()->is_open();
2290 _errorCode = std::string("Can't create a file ")+theFileName;
2291 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
2295 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
2296 fp << "0:1" << std::endl;
2297 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
2298 std::string aTab(" ");
2299 for(; Itr.More(); Itr.Next()) {
2300 dumpSO(Itr.Value(), fp, aTab, this);
2307 void dumpSO(const SALOMEDSImpl_SObject& theSO,
2309 const std::string& Tab,
2310 SALOMEDSImpl_Study* theStudy)
2312 std::string aTab(Tab), anID(theSO.GetID());
2313 fp << aTab << anID << std::endl;
2314 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
2315 for(int i = 0; i<attribs.size(); i++) {
2316 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
2322 std::string aType = anAttr->GetClassType();
2323 fp << Tab << " -- " << aType;
2325 if(aType == std::string("AttributeReal")) {
2326 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
2328 else if(aType == std::string("AttributeInteger")) {
2329 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
2331 else if(aType == std::string("AttributeName")) {
2332 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
2334 else if(aType == std::string("AttributeComment")) {
2335 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
2337 else if(aType == std::string("AttributeReference")) {
2338 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
2343 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
2344 std::string aNewTab(" ");
2346 for(; Itr.More(); Itr.Next()) {
2347 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
2353 void SALOMEDSImpl_Study::Modify()
2356 _doc->SetModified(true);
2359 //============================================================================
2363 //============================================================================
2364 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
2366 if (theSavePoint < -1) return NULL;
2367 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
2368 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
2369 if (!so) so = builder->NewComponent((char*)theID);
2370 SALOMEDSImpl_AttributeParameter* attParam = NULL;
2372 if (theSavePoint == -1) {
2374 DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
2375 DF_Label prevPointLabel;
2376 while ( !savePointLabel.IsNull() ) {
2378 prevPointLabel = savePointLabel;
2379 savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
2381 if ( !prevPointLabel.IsNull() )
2382 so = GetSObject( prevPointLabel );
2384 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
2385 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
2386 if ( !savePointLabel.IsNull() )
2387 so = GetSObject( savePointLabel );
2388 else // ... if it does not exist - create a new one
2389 so = builder->NewObjectToTag( so, theSavePoint );
2394 builder->FindAttribute(so, A, "AttributeParameter");
2395 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
2396 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
2398 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
2403 //============================================================================
2407 //============================================================================
2408 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
2409 const char* theModuleName,
2412 if(theSavePoint < -1) return NULL;
2413 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
2414 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
2415 SALOMEDSImpl_AttributeParameter* par = NULL;
2417 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
2418 std::string moduleName(theModuleName);
2419 for(; it.More(); it.Next()) {
2420 SALOMEDSImpl_SObject so(it.Value());
2421 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
2422 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
2423 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
2427 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
2428 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
2429 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
2430 par->SetString("AP_MODULE_NAME", moduleName);
2434 //============================================================================
2435 /*! Function : SetStudyLock
2438 //============================================================================
2439 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
2441 _lockers.push_back(theLockerID);
2444 //============================================================================
2445 /*! Function : IsStudyLocked
2448 //============================================================================
2449 bool SALOMEDSImpl_Study::IsStudyLocked()
2451 return (_lockers.size() > 0);
2454 //============================================================================
2455 /*! Function : UnLockStudy
2458 //============================================================================
2459 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
2461 std::vector<std::string>::iterator vsI = _lockers.begin();
2462 int length = _lockers.size();
2463 bool isFound = false;
2464 std::string id(theLockerID);
2465 for(int i = 0; i<length; i++, vsI++) {
2466 if(id == _lockers[i]) {
2471 if(isFound) _lockers.erase(vsI);
2474 //============================================================================
2475 /*! Function : GetLockerID
2478 //============================================================================
2479 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
2484 //============================================================================
2485 /*! Function : SetVariable
2488 //============================================================================
2489 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
2490 const double theValue,
2491 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
2493 bool modified = false;
2494 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2496 if( aGVar == NULL ) {
2498 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
2500 aSVar->setValue(theValue);
2501 myNoteBookVars.push_back(aSVar);
2505 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
2506 modified = aSVar->setValue(theValue) || modified;
2507 modified = aSVar->setType(theType) || modified;
2514 //============================================================================
2515 /*! Function : SetStringVariable
2518 //============================================================================
2519 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
2520 const std::string& theValue,
2521 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
2523 bool modified = false;
2524 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2526 if( aGVar == NULL ) {
2528 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
2530 aSVar->setStringValue(theValue);
2531 myNoteBookVars.push_back(aSVar);
2535 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
2536 modified = aSVar->setStringValue(theValue) || modified;
2537 modified = aSVar->setType(theType) || modified;
2544 //============================================================================
2545 /*! Function : SetStringVariableAsDouble
2548 //============================================================================
2549 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
2550 const double theValue,
2551 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
2553 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2554 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
2555 aSVar->setValue(theValue);
2558 //============================================================================
2559 /*! Function : GetReal
2562 //============================================================================
2563 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
2565 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2568 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
2569 return aSVar->getValue();
2574 //============================================================================
2575 /*! Function : GetString
2578 //============================================================================
2579 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
2581 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2584 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
2585 return aSVar->getStringValue();
2590 //============================================================================
2591 /*! Function : IsTypeOf
2594 //============================================================================
2595 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
2596 SALOMEDSImpl_GenericVariable::
2597 VariableTypes theType) const
2599 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2602 return aGVar->Type() == theType;
2607 //============================================================================
2608 /*! Function : IsVariable
2611 //============================================================================
2612 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
2614 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
2615 return (aGVar != NULL);
2618 //============================================================================
2619 /*! Function : GetVariableNames
2622 //============================================================================
2623 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
2625 std::vector<std::string> aResult;
2627 for(int i = 0; i < myNoteBookVars.size(); i++)
2628 aResult.push_back(myNoteBookVars[i]->Name());
2633 //============================================================================
2634 /*! Function : AddVariable
2637 //============================================================================
2638 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
2640 myNoteBookVars.push_back(theVariable);
2643 //============================================================================
2644 /*! Function : AddVariable
2647 //============================================================================
2648 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
2650 SALOMEDSImpl_GenericVariable* aResult = NULL;
2651 for(int i = 0; i < myNoteBookVars.size();i++) {
2652 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
2653 aResult = myNoteBookVars[i];
2660 //============================================================================
2661 /*! Function : RemoveVariable
2664 //============================================================================
2665 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
2667 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
2671 std::string aValue = aVariable->SaveToScript();
2672 ReplaceVariableAttribute( theVarName, aValue );
2674 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
2675 for( ; it != itEnd; it++ )
2677 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
2678 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
2680 myNoteBookVars.erase( it );
2689 //============================================================================
2690 /*! Function : RenameVariable
2693 //============================================================================
2694 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
2696 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
2700 ReplaceVariableAttribute( theVarName, theNewVarName );
2702 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
2703 for( ; it != itEnd; it++ )
2705 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
2706 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
2708 aVariableRef->setName( theNewVarName );
2717 //============================================================================
2718 /*! Function : IsVariableUsed
2721 //============================================================================
2722 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
2724 return FindVariableAttribute( theVarName );
2727 //============================================================================
2728 /*! Function : FindVariableAttribute
2731 //============================================================================
2732 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
2733 SALOMEDSImpl_SObject theSObject,
2734 const std::string& theName)
2736 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
2737 for( ; anIter.More(); anIter.Next() )
2738 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
2741 DF_Attribute* anAttr;
2742 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
2744 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
2746 std::string aString = aStringAttr->Value();
2748 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
2749 for( int i = 0, n = aSections.size(); i < n; i++ )
2751 std::vector<std::string> aVector = aSections[i];
2752 for( int j = 0, m = aVector.size(); j < m; j++ )
2754 std::string aStr = aVector[j];
2755 if( aStr.compare( theName ) == 0 )
2764 //============================================================================
2765 /*! Function : FindVariableAttribute
2768 //============================================================================
2769 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
2771 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
2772 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
2773 for( ; aCompIter.More(); aCompIter.Next() )
2775 SALOMEDSImpl_SObject aComp = aCompIter.Value();
2776 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
2782 //============================================================================
2783 /*! Function : ReplaceVariableAttribute
2786 //============================================================================
2787 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
2788 SALOMEDSImpl_SObject theSObject,
2789 const std::string& theSource,
2790 const std::string& theDest)
2792 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
2793 for( ; anIter.More(); anIter.Next() )
2794 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
2796 DF_Attribute* anAttr;
2797 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
2799 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
2801 bool isChanged = false;
2802 std::string aNewString, aCurrentString = aStringAttr->Value();
2804 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
2805 for( int i = 0, n = aSections.size(); i < n; i++ )
2807 std::vector<std::string> aVector = aSections[i];
2808 for( int j = 0, m = aVector.size(); j < m; j++ )
2810 std::string aStr = aVector[j];
2811 if( aStr.compare( theSource ) == 0 )
2817 aNewString.append( aStr );
2819 aNewString.append( ":" );
2822 aNewString.append( "|" );
2826 aStringAttr->SetValue( aNewString );
2831 //============================================================================
2832 /*! Function : ReplaceVariableAttribute
2835 //============================================================================
2836 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
2838 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
2839 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
2840 for( ; aCompIter.More(); aCompIter.Next() )
2842 SALOMEDSImpl_SObject aComp = aCompIter.Value();
2843 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
2847 //============================================================================
2848 /*! Function : ParseVariables
2851 //============================================================================
2852 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
2854 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
2857 //============================================================================
2858 /*! Function : EnableUseCaseAutoFilling
2861 //============================================================================
2862 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
2864 _errorCode = ""; _autoFill = isEnabled;
2866 _builder->SetOnAddSObject(_cb);
2867 _builder->SetOnRemoveSObject(_cb);
2870 _builder->SetOnAddSObject(NULL);
2871 _builder->SetOnRemoveSObject(NULL);
2875 //============================================================================
2876 /*! Function : GetIORs
2879 //============================================================================
2880 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
2882 std::vector<std::string> anIORs;
2883 std::map<std::string, DF_Label>::const_iterator MI;
2884 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
2885 anIORs.push_back(MI->first);
2890 //============================================================================
2891 /*! Function : addSO_Notification
2892 * Purpose : This function tells all the observers that a SO has been added
2894 //============================================================================
2895 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2898 return _notifier->addSO_Notification(theSObject);
2903 //============================================================================
2904 /*! Function : removeSO_Notification
2905 * Purpose : This function tells all the observers that a SO has been removed
2907 //============================================================================
2908 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2911 return _notifier->removeSO_Notification(theSObject);
2916 //============================================================================
2917 /*! Function : modifySO_Notification
2918 * Purpose : This function tells all the observers that a SO has been modified and
2919 pass the mofification reason
2921 //============================================================================
2922 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
2925 return _notifier->modifySO_Notification(theSObject, reason);
2930 //============================================================================
2931 /*! Function : setNotifier
2932 * Purpose : register a notifier
2934 //============================================================================
2935 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)
2940 static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc )
2942 static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec;
2943 if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() )
2944 _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 );
2945 return _genObjRegVec[ doc->GetDocumentID() ];
2948 //================================================================================
2950 * \brief Stores theRegister
2952 //================================================================================
2954 void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister)
2956 getGenObjRegister( _doc ) = theRegister;
2959 //================================================================================
2961 * \brief Indirectly invokes GenericObj_i::Register()
2963 //================================================================================
2965 void SALOMEDSImpl_Study::RegisterGenObj (const std::string& theIOR, DF_Label label)
2967 if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
2968 goRegister->RegisterGenObj( theIOR );
2971 //================================================================================
2973 * \brief Indirectly invokes GenericObj_i::UnRegister()
2975 //================================================================================
2977 void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label)
2979 if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
2980 goRegister->UnRegisterGenObj( theIOR );
2983 //#######################################################################################################
2984 //# STATIC PRIVATE FUNCTIONS
2985 //#######################################################################################################
2987 //============================================================================
2988 /*! Function : SaveAttributes
2989 * Purpose : Save attributes for object
2991 //============================================================================
2992 static void SaveAttributes(const SALOMEDSImpl_SObject& aSO, HDFgroup *hdf_group_sobject)
2995 std::vector<DF_Attribute*> attrList = aSO.GetLabel().GetAttributes();
2996 DF_Attribute* anAttr = NULL;
2997 for(int i = 0, len = attrList.size(); i<len; i++) {
2998 anAttr = attrList[i];
2999 //The following attributes are not supposed to be written to the file
3000 std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(anAttr);
3001 if(type == std::string("AttributeIOR")) continue; //IOR attribute is not saved
3002 std::string aSaveStr =anAttr->Save();
3003 //cout << "Saving: " << aSO.GetID() << " type: "<< type<<"|" << endl;
3004 size[0] = (hdf_int32) strlen(aSaveStr.c_str()) + 1;
3005 HDFdataset *hdf_dataset = new HDFdataset((char*)type.c_str(), hdf_group_sobject, HDF_STRING,size, 1);
3006 hdf_dataset->CreateOnDisk();
3007 hdf_dataset->WriteOnDisk((char*)aSaveStr.c_str());
3008 hdf_dataset->CloseOnDisk();
3009 hdf_dataset=0; //will be deleted by hdf_sco_group destructor
3013 //===========================================================================
3014 //Function : ReadAttributes
3015 //===========================================================================
3016 static void ReadAttributes(SALOMEDSImpl_Study* theStudy,
3017 const SALOMEDSImpl_SObject& aSO,
3018 HDFdataset* hdf_dataset)
3020 hdf_dataset->OpenOnDisk();
3022 DF_Attribute* anAttr = NULL;
3023 char* current_string = new char[hdf_dataset->GetSize()+1];
3024 hdf_dataset->ReadFromDisk(current_string);
3025 //cout << "Reading attr type = " << hdf_dataset->GetName() << " SO = " << aSO.GetID() << endl;
3026 if (!strcmp(hdf_dataset->GetName(),"COMPONENTDATATYPE")) {
3027 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, "AttributeComment");
3029 else if (!strcmp(hdf_dataset->GetName(),"AttributeReference") ||
3030 !strcmp(hdf_dataset->GetName(),"Reference")) { // Old format maintainance
3031 theStudy->NewBuilder()->Addreference(aSO, theStudy->CreateObjectID(current_string));
3032 delete [] (current_string);
3033 hdf_dataset->CloseOnDisk();
3037 anAttr = theStudy->NewBuilder()->FindOrCreateAttribute(aSO, hdf_dataset->GetName());
3041 anAttr->Load(current_string);
3044 delete [] (current_string);
3045 hdf_dataset->CloseOnDisk();
3048 //============================================================================
3049 //Function : BuildlTree
3050 //============================================================================
3051 static void BuildTree (SALOMEDSImpl_Study* theStudy, HDFgroup* hdf_current_group)
3053 hdf_current_group->OpenOnDisk();
3054 SALOMEDSImpl_SObject aSO;
3055 char* Entry = hdf_current_group->GetName();
3056 if (strcmp(Entry,"STUDY_STRUCTURE") == 0) {
3057 aSO = theStudy->CreateObjectID("0:1");
3060 aSO = theStudy->CreateObjectID(Entry);
3063 char name[HDF_NAME_MAX_LEN+1];
3064 int nbsons = hdf_current_group->nInternalObjects();
3065 for (int i=0; i<nbsons; i++) {
3066 hdf_current_group->InternalObjectIndentify(i,name);
3067 if (strncmp(name, "INTERNAL_COMPLEX",16) == 0) continue;
3068 hdf_object_type type = hdf_current_group->InternalObjectType(name);
3070 if (type == HDF_DATASET) {
3071 HDFdataset* new_dataset = new HDFdataset(name,hdf_current_group);
3072 ReadAttributes(theStudy,aSO,new_dataset);
3073 new_dataset = 0; // will be deleted by father destructor
3075 else if (type == HDF_GROUP) {
3076 HDFgroup* new_group = new HDFgroup(name,hdf_current_group);
3077 BuildTree (theStudy, new_group);
3078 new_group = 0; // will be deleted by father destructor
3081 hdf_current_group->CloseOnDisk();
3085 //============================================================================
3086 //Function : Translate_IOR_to_persistentID
3087 //============================================================================
3088 static void Translate_IOR_to_persistentID (const SALOMEDSImpl_SObject& so,
3089 SALOMEDSImpl_Driver* engine,
3093 DF_ChildIterator itchild(so.GetLabel());
3094 std::string ior_string, persistent_string, curid;
3096 for (; itchild.More(); itchild.Next()) {
3097 SALOMEDSImpl_SObject current = SALOMEDSImpl_Study::SObject(itchild.Value());
3098 SALOMEDSImpl_AttributeIOR* IOR = NULL;
3099 if ((IOR=(SALOMEDSImpl_AttributeIOR*)current.GetLabel().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
3100 ior_string = IOR->Value();
3102 persistent_string = engine->IORToLocalPersistentID (current, ior_string, isMultiFile, isASCII);
3103 SALOMEDSImpl_AttributePersistentRef::Set(current.GetLabel(), persistent_string);
3105 Translate_IOR_to_persistentID (current, engine, isMultiFile, isASCII);
3109 void ReadNoteBookVariables(SALOMEDSImpl_Study* theStudy, HDFgroup* theGroup)
3114 HDFgroup* new_group =0;
3115 HDFdataset* new_dataset =0;
3117 char aVarName[HDF_NAME_MAX_LEN+1];
3118 char *currentVarType = 0;
3119 char *currentVarValue = 0;
3120 char *currentVarIndex = 0;
3122 //Open HDF group with notebook variables
3123 theGroup->OpenOnDisk();
3125 //Get Nb of variables
3126 int aNbVars = theGroup->nInternalObjects();
3128 std::map<int,SALOMEDSImpl_GenericVariable*> aVarsMap;
3130 for( int iVar=0;iVar < aNbVars;iVar++ ) {
3131 theGroup->InternalObjectIndentify(iVar,aVarName);
3132 hdf_object_type type = theGroup->InternalObjectType(aVarName);
3133 if(type == HDF_GROUP) {
3136 new_group = new HDFgroup(aVarName,theGroup);
3137 new_group->OpenOnDisk();
3140 new_dataset = new HDFdataset("VARIABLE_TYPE",new_group);
3141 new_dataset->OpenOnDisk();
3142 currentVarType = new char[new_dataset->GetSize()+1];
3143 new_dataset->ReadFromDisk(currentVarType);
3144 new_dataset->CloseOnDisk();
3145 new_dataset = 0; //will be deleted by hdf_sco_group destructor
3148 if(new_group->ExistInternalObject("VARIABLE_INDEX")) {
3149 new_dataset = new HDFdataset("VARIABLE_INDEX",new_group);
3150 new_dataset->OpenOnDisk();
3151 currentVarIndex = new char[new_dataset->GetSize()+1];
3152 new_dataset->ReadFromDisk(currentVarIndex);
3153 new_dataset->CloseOnDisk();
3154 new_dataset = 0; //will be deleted by hdf_sco_group destructor
3155 order = atoi(currentVarIndex);
3156 delete [] currentVarIndex;
3162 new_dataset = new HDFdataset("VARIABLE_VALUE",new_group);
3163 new_dataset->OpenOnDisk();
3164 currentVarValue = new char[new_dataset->GetSize()+1];
3165 new_dataset->ReadFromDisk(currentVarValue);
3166 new_dataset->CloseOnDisk();
3167 new_dataset = 0; //will be deleted by hdf_sco_group destructor
3169 new_group->CloseOnDisk();
3170 new_group = 0; //will be deleted by hdf_sco_group destructor
3172 SALOMEDSImpl_GenericVariable::VariableTypes aVarType =
3173 SALOMEDSImpl_GenericVariable::String2VariableType(std::string(currentVarType));
3174 delete [] currentVarType;
3176 //Create variable and add it in the study
3177 SALOMEDSImpl_GenericVariable* aVariable =
3178 new SALOMEDSImpl_ScalarVariable(aVarType,std::string(aVarName));
3179 aVariable->Load(std::string(currentVarValue));
3180 aVarsMap.insert(std::make_pair(order,aVariable));
3181 delete [] currentVarValue;
3185 std::map<int,SALOMEDSImpl_GenericVariable*>::const_iterator it= aVarsMap.begin();
3186 for(;it!=aVarsMap.end();it++)
3187 theStudy->AddVariable((*it).second);
3189 theGroup->CloseOnDisk();