1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDSImpl_Study.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDSImpl_Study.hxx"
31 #include <Basics_Utils.hxx>
33 #include "DF_Application.hxx"
34 #include "DF_ChildIterator.hxx"
36 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
37 #include "SALOMEDSImpl_Attributes.hxx"
38 #include "SALOMEDSImpl_UseCaseIterator.hxx"
39 #include "SALOMEDSImpl_AttributeReference.hxx"
40 #include "SALOMEDSImpl_StudyHandle.hxx"
41 #include "SALOMEDSImpl_Tool.hxx"
42 #include "SALOMEDSImpl_IParameters.hxx"
43 #include "SALOMEDSImpl_ScalarVariable.hxx"
47 #define DIRECTORYID 16661
48 #define FILELOCALID 26662
49 #define FILEID "FILE: "
50 #define VARIABLE_SEPARATOR ':'
51 #define OPERATION_SEPARATOR '|'
53 //============================================================================
54 /*! Function : SALOMEDSImpl_Study
55 * Purpose : SALOMEDSImpl_Study constructor
57 //============================================================================
58 SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
59 const string& study_name)
62 _doc = (DF_Document*)doc;
68 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
69 _builder = new SALOMEDSImpl_StudyBuilder(this);
70 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
71 //Put on the root label a StudyHandle attribute to store the address of this object
72 //It will be used to retrieve the study object by DF_Label that belongs to the study
73 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
77 //============================================================================
78 /*! Function : ~SALOMEDSImpl_Study
79 * Purpose : SALOMEDSImpl_Study destructor
81 //============================================================================
82 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
86 delete _useCaseBuilder;
89 //============================================================================
90 /*! Function : GetPersistentReference
91 * Purpose : Get persistent reference of study (idem URL())
93 //============================================================================
94 string SALOMEDSImpl_Study::GetPersistentReference()
99 //============================================================================
100 /*! Function : GetTransientReference
101 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
103 //============================================================================
104 string SALOMEDSImpl_Study::GetTransientReference()
109 SALOMEDSImpl_AttributeIOR* Att;
110 DF_Label _lab = _doc->Root();
111 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
115 _errorCode = "IOR is empty";
121 void SALOMEDSImpl_Study::SetTransientReference(const string& theIOR)
125 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
126 int aLocked = aProp->IsLocked();
127 if (aLocked) aProp->SetLocked(false);
129 // Assign the value of the IOR in the study->root
130 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
132 if (aLocked) aProp->SetLocked(true);
135 //============================================================================
136 /*! Function : IsEmpty
137 * Purpose : Detect if study is empty
139 //============================================================================
140 bool SALOMEDSImpl_Study::IsEmpty()
143 if (!_doc) return true;
144 return _doc->IsEmpty();
147 //============================================================================
148 /*! Function : FindComponent
149 * Purpose : Find a Component with ComponentDataType = aComponentName
151 //============================================================================
152 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const string& aComponentName)
157 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
158 SALOMEDSImpl_SComponent compo;
160 for (; itcomp.More(); itcomp.Next()) {
161 SALOMEDSImpl_SComponent SC = itcomp.Value();
162 name = SC.ComponentDataType();
163 if(aComponentName == name) {
171 _errorCode = "No component was found";
177 //============================================================================
178 /*! Function : FindComponentID
179 * Purpose : Find a Component from it's ID
181 //============================================================================
182 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const string& aComponentID)
186 // Iterate on each components defined in the study
187 // Get the component ID and compare with aComponentID
190 SALOMEDSImpl_SComponent compo;
192 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
193 for (; itcomp.More(); itcomp.Next()) {
194 SALOMEDSImpl_SComponent SC = itcomp.Value();
196 if(aComponentID == ID)
205 _errorCode = "No component was found";
212 //============================================================================
213 /*! Function : FindObject
214 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
216 //============================================================================
217 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const string& anObjectName)
221 // Iterate to all components defined in the study
222 // After testing the component name, iterate in all objects defined under
223 // components (function _FindObject)
225 SALOMEDSImpl_SObject RefSO;
227 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
228 for (; it.More();it.Next()){
231 SALOMEDSImpl_SComponent SC = it.Value();
232 if (SC.GetName() == anObjectName)
238 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
241 if(!RefSO) _errorCode = "No object was found";
245 //============================================================================
246 /*! Function : FindObjectID
247 * Purpose : Find an Object with ID = anObjectID
249 //============================================================================
250 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const string& anObjectID)
253 SALOMEDSImpl_SObject so;
255 // Convert aSO->GetID in DF_Label.
256 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
259 _errorCode = "No label was found by ID";
262 return GetSObject(Lab);
266 //============================================================================
267 /*! Function : CreateObjectID
268 * Purpose : Creates an Object with ID = anObjectID
270 //============================================================================
271 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const string& anObjectID)
274 SALOMEDSImpl_SObject so;
276 // Convert aSO->GetID in DF_Label.
277 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
280 _errorCode = "Can not create a label";
283 return GetSObject(Lab);
287 //============================================================================
288 /*! Function : FindObjectByName
289 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
290 * : with ComponentDataType = aComponentName
292 //============================================================================
293 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const string& anObjectName,
294 const string& aComponentName)
298 vector<SALOMEDSImpl_SObject> listSO;
300 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
302 _errorCode = "Can not find the component";
306 // Iterate on each object and subobject of the component
307 // If objectName is found add it to the list of SObjects
310 string compoId = compo.GetID();
311 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
312 for ( ; it.More(); it.Next() ) {
314 SALOMEDSImpl_SObject CSO = it.Value();
315 if ( CSO.GetName() == anObjectName ) {
317 listSO.push_back(CSO) ;
320 /* looks also for eventual children */
322 CSO = _FindObject( CSO, anObjectName, found ) ;
324 listSO.push_back(CSO) ;
333 //============================================================================
334 /*! Function : FindObjectIOR
335 * Purpose : Find an Object with IOR = anObjectIOR
337 //============================================================================
338 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const string& anObjectIOR)
342 SALOMEDSImpl_SObject aResult ;
344 // searching in the datamap for optimization
345 if (myIORLabels.find(anObjectIOR) != myIORLabels.end()) {
346 aResult = GetSObject(myIORLabels[anObjectIOR]);
347 // 11 oct 2002: forbidden attributes must be checked here
348 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
349 myIORLabels.erase(anObjectIOR);
350 aResult = SALOMEDSImpl_SObject();
354 if(!aResult) _errorCode = "No object was found";
358 //============================================================================
359 /*! Function : FindObjectByPath
360 * Purpose : Find an Object by its path = thePath
362 //============================================================================
363 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const string& thePath)
367 string aPath(thePath), aToken;
368 SALOMEDSImpl_SObject aSO;
369 int aLength = aPath.size();
370 bool isRelative = false;
372 if(aLength == 0) { //Empty path - return the current context
373 return GetSObject(_current);
376 if(aPath[0] != '/') //Relative path
379 DF_ChildIterator anIterator;
381 SALOMEDSImpl_AttributeName* anAttr;
384 if(_current.IsNull()) return aSO;
385 anIterator.Init(_current, false);
388 if(aPath.size() == 1 && aPath[0] == '/') { //Root
389 return GetSObject(_doc->Main());
391 anIterator.Init(_doc->Main(), false);
394 vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
395 for(int i = 0, len = vs.size(); i<len; i++) {
398 if(aToken.size() == 0) break;
400 for ( ; anIterator.More(); anIterator.Next() ) {
401 aLabel = anIterator.Value();
402 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
403 if(anAttr->Value() == aToken) {
404 if(i == (len-1)) { //The searched label is found (no part of the path is left)
405 return GetSObject(aLabel);
408 anIterator.Init(aLabel, false);
416 if(!aSO) _errorCode = "No object was found";
420 //============================================================================
421 /*! Function : GetObjectPath
424 //============================================================================
425 string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
431 _errorCode = "Null object";
435 string aName = theObject.GetName();
436 if(!aName.empty() && aName != "" ) {
441 SALOMEDSImpl_SObject aFather = theObject.GetFather();
443 aName = aFather.GetName();
444 if(!aName.empty() && aName != "") {
445 aValue = GetObjectPath(aFather);
446 aPath = aValue + aPath;
455 //============================================================================
456 /*! Function : GetObjectPathByIOR
459 //============================================================================
460 string SALOMEDSImpl_Study::GetObjectPathByIOR(const string& theIOR)
465 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
467 _errorCode = "No SObject was found by IOR";
471 return GetObjectPath(so);
475 //============================================================================
476 /*! Function : SetContext
477 * Purpose : Sets the current context
479 //============================================================================
480 bool SALOMEDSImpl_Study::SetContext(const string& thePath)
483 if(thePath.empty()) {
484 _errorCode = "InvalidPath";
488 string aPath(thePath), aContext("");
489 bool isInvalid = false;
490 SALOMEDSImpl_SObject aSO;
492 if(aPath[0] != '/') { //Relative path
493 aContext = GetContext();
501 aSO = FindObjectByPath(aContext);
507 if(isInvalid || !aSO) {
508 _errorCode = "InvalidContext";
512 DF_Label aLabel = aSO.GetLabel();
513 if(aLabel.IsNull()) {
514 _errorCode = "InvalidContext";
518 _current = aLabel; //Set the current context
523 //============================================================================
524 /*! Function : GetContext
525 * Purpose : Gets the current context
527 //============================================================================
528 string SALOMEDSImpl_Study::GetContext()
532 if(_current.IsNull()) {
533 _errorCode = "InvaidContext";
536 SALOMEDSImpl_SObject so = GetSObject(_current);
537 return GetObjectPath(so);
540 //============================================================================
541 /*! Function : GetObjectNames
542 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
544 //============================================================================
545 vector<string> SALOMEDSImpl_Study::GetObjectNames(const string& theContext)
549 vector<string> aResultSeq;
551 if (theContext.empty()) {
554 DF_Label aTmp = _current;
555 SetContext(theContext);
559 if (aLabel.IsNull()) {
560 _errorCode = "InvalidContext";
564 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
565 for (; anIter.More(); anIter.Next()) {
566 DF_Label aLabel = anIter.Value();
567 SALOMEDSImpl_AttributeName* aName;
568 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
569 aResultSeq.push_back(aName->Value());
575 //============================================================================
576 /*! Function : GetDirectoryNames
577 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
579 //============================================================================
580 vector<string> SALOMEDSImpl_Study::GetDirectoryNames(const string& theContext)
584 vector<string> aResultSeq;
586 if (theContext.empty()) {
589 DF_Label aTmp = _current;
590 SetContext(theContext);
594 if (aLabel.IsNull()) {
595 _errorCode = "InvalidContext";
599 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
600 for (; anIter.More(); anIter.Next()) {
601 DF_Label aLabel = anIter.Value();
602 SALOMEDSImpl_AttributeLocalID* anID;
603 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
604 if (anID->Value() == DIRECTORYID) {
605 SALOMEDSImpl_AttributeName* aName;
606 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
607 aResultSeq.push_back(aName->Value());
616 //============================================================================
617 /*! Function : GetFileNames
618 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
620 //============================================================================
621 vector<string> SALOMEDSImpl_Study::GetFileNames(const string& theContext)
625 vector<string> aResultSeq;
627 if (theContext.empty()) {
630 DF_Label aTmp = _current;
631 SetContext(theContext);
635 if (aLabel.IsNull()) {
636 _errorCode = "InvalidContext";
640 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
641 for (; anIter.More(); anIter.Next()) {
642 DF_Label aLabel = anIter.Value();
643 SALOMEDSImpl_AttributeLocalID* anID;
644 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
645 if (anID->Value() == FILELOCALID) {
646 SALOMEDSImpl_AttributePersistentRef* aName;
647 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
648 std::string aFileName = aName->Value();
649 if (aFileName.size() > 0)
650 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
659 //============================================================================
660 /*! Function : GetComponentNames
661 * Purpose : method to get all components names
663 //============================================================================
664 vector<string> SALOMEDSImpl_Study::GetComponentNames(const string& theContext)
668 vector<string> aResultSeq;
669 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
670 for(; anIter.More(); anIter.Next()) {
671 DF_Label aLabel = anIter.Value();
672 SALOMEDSImpl_AttributeName* aName;
673 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
674 aResultSeq.push_back(aName->Value());
680 //============================================================================
681 /*! Function : NewChildIterator
682 * Purpose : Create a ChildIterator from an SObject
684 //============================================================================
685 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
688 return SALOMEDSImpl_ChildIterator(aSO);
692 //============================================================================
693 /*! Function : NewComponentIterator
694 * Purpose : Create a SComponentIterator
696 //============================================================================
697 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
700 return SALOMEDSImpl_SComponentIterator(_doc);
704 //============================================================================
705 /*! Function : NewBuilder
706 * Purpose : Create a StudyBuilder
708 //============================================================================
709 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
713 _builder->SetOnAddSObject(_cb);
714 _builder->SetOnRemoveSObject(_cb);
720 //============================================================================
722 * Purpose : get study name
724 //============================================================================
725 string SALOMEDSImpl_Study::Name()
731 //============================================================================
733 * Purpose : set study name
735 //============================================================================
736 void SALOMEDSImpl_Study::Name(const string& name)
742 //============================================================================
743 /*! Function : IsSaved
744 * Purpose : get if study has been saved
746 //============================================================================
747 bool SALOMEDSImpl_Study::IsSaved()
753 //============================================================================
754 /*! Function : IsSaved
755 * Purpose : set if study has been saved
757 //============================================================================
758 void SALOMEDSImpl_Study::IsSaved(bool save)
762 if(save) _doc->SetModified(false);
765 //============================================================================
766 /*! Function : IsModified
767 * Purpose : Detect if a Study has been modified since it has been saved
769 //============================================================================
770 bool SALOMEDSImpl_Study::IsModified()
774 // True if is modified
775 if (_doc && _doc->IsModified()) return true;
780 //============================================================================
782 * Purpose : get URL of the study (persistent reference of the study)
784 //============================================================================
785 string SALOMEDSImpl_Study::URL()
791 //============================================================================
793 * Purpose : set URL of the study (persistent reference of the study)
795 //============================================================================
796 void SALOMEDSImpl_Study::URL(const string& url)
801 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
804 char *aName = (char*)tmp.ToCString();
805 char *adr = strtok(aName, "/");
809 adr = strtok(NULL, "/");
816 //============================================================================
817 /*! Function : _FindObject
818 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
820 //============================================================================
821 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
822 const string& theObjectName,
825 SALOMEDSImpl_SObject RefSO;
826 if(!SO) return RefSO;
828 // Iterate on each objects and subobjects of the component
829 // If objectName find, stop the loop and get the object reference
830 SALOMEDSImpl_AttributeName* anAttr;
832 string soid = SO.GetID();
833 DF_ChildIterator it(SO.GetLabel());
834 for (; it.More(); it.Next()){
837 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
839 string Val(anAttr->Value());
840 if (Val == theObjectName)
842 RefSO = GetSObject(it.Value());
846 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
852 //============================================================================
853 /*! Function : _FindObjectIOR
854 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
856 //============================================================================
858 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
859 const string& theObjectIOR,
862 SALOMEDSImpl_SObject RefSO, aSO;
863 if(!SO) return RefSO;
865 // Iterate on each objects and subobjects of the component
866 // If objectName find, stop the loop and get the object reference
867 SALOMEDSImpl_AttributeIOR* anAttr;
869 DF_ChildIterator it(SO.GetLabel());
870 for (; it.More();it.Next()){
873 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
875 string Val(anAttr->Value());
876 if (Val == theObjectIOR)
878 RefSO = GetSObject(it.Value());
882 aSO = GetSObject(it.Value());
883 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
889 //============================================================================
890 /*! Function : _GetNoteBookAccessor
891 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
893 //============================================================================
894 string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
895 return string("notebook");
898 //============================================================================
899 /*! Function : _GetStudyVariablesScript
902 //============================================================================
903 string SALOMEDSImpl_Study::_GetStudyVariablesScript()
907 if(myNoteBookVars.empty())
910 Kernel_Utils::Localizer loc;
912 dump += "####################################################\n";
913 dump += "## Begin of NoteBook variables section ##\n";
914 dump += "####################################################\n";
916 string set_method = _GetNoteBookAccessor()+".set(";
919 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
920 varName = myNoteBookVars[i]->Name();
921 varValue = myNoteBookVars[i]->SaveToScript();
922 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
925 dump += "####################################################\n";
926 dump += "## End of NoteBook variables section ##\n";
927 dump += "####################################################\n";
932 //============================================================================
933 /*! Function : _GetNoteBookAccess
936 //============================================================================
937 string SALOMEDSImpl_Study::_GetNoteBookAccess()
939 string accessor = _GetNoteBookAccessor();
940 string notebook = "import salome_notebook\n";
941 notebook += accessor+" = salome_notebook."+accessor + "\n";
945 bool SALOMEDSImpl_Study::IsLocked()
948 return GetProperties()->IsLocked();
951 int SALOMEDSImpl_Study::StudyId()
957 void SALOMEDSImpl_Study::StudyId(int id)
963 void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anEntry)
966 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
967 if (myIORLabels.find(anIOR) != myIORLabels.end()) myIORLabels.erase(anIOR);
968 myIORLabels[anIOR] = aLabel;
971 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
973 if (myIORLabels.find(anIOR) != myIORLabels.end())
975 //remove the ior entry and decref the genericobj (if it's one)
976 myIORLabels.erase(anIOR);
980 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
982 SALOMEDSImpl_StudyHandle* Att;
983 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
989 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
991 return GetStudy(theLabel)->GetSObject(theLabel);
994 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
996 return GetStudy(theLabel)->GetSComponent(theLabel);
1000 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1002 string aString = theAttribute->Label().Entry();
1003 GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1006 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1009 vector<SALOMEDSImpl_SObject> aSeq;
1011 SALOMEDSImpl_AttributeTarget* aTarget;
1012 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1013 return aTarget->Get();
1020 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1023 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1026 string SALOMEDSImpl_Study::GetLastModificationDate()
1029 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1031 vector<string> aNames;
1032 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1033 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1035 int aLastIndex = aNames.size()-1;
1037 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1038 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1039 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1040 string aResStr (aResult);
1044 vector<string> SALOMEDSImpl_Study::GetModificationsDate()
1047 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1049 vector<string> aNames;
1050 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1051 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1053 int anIndex, aLength = aNames.size();
1054 vector<string> aDates;
1056 for (anIndex = 1; anIndex < aLength; anIndex++) {
1058 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1059 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1060 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1061 aDates.push_back(aDate);
1068 //============================================================================
1069 /*! Function : GetUseCaseBuilder
1070 * Purpose : Returns a UseCase builder
1072 //============================================================================
1073 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1076 return _useCaseBuilder;
1080 //============================================================================
1081 /*! Function : Close
1084 //============================================================================
1085 void SALOMEDSImpl_Study::Close()
1088 _doc->GetApplication()->Close(_doc);
1095 //============================================================================
1096 /*! Function : GetSComponent
1099 //============================================================================
1100 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const string& theEntry)
1102 SALOMEDSImpl_SComponent aSCO;
1103 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1104 aSCO = _mapOfSCO[theEntry];
1106 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1107 aSCO = SALOMEDSImpl_SComponent(aLabel);
1108 _mapOfSCO[theEntry] = aSCO;
1114 //============================================================================
1115 /*! Function : GetSComponent
1118 //============================================================================
1119 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1121 return SALOMEDSImpl_SComponent(theLabel);
1124 //============================================================================
1125 /*! Function : GetSObject
1128 //============================================================================
1129 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const string& theEntry)
1131 SALOMEDSImpl_SObject aSO;
1132 if(_mapOfSO.find(theEntry) != _mapOfSO.end())
1133 aSO = _mapOfSO[theEntry];
1135 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1136 aSO = SALOMEDSImpl_SObject(aLabel);
1137 _mapOfSO[theEntry] = aSO;
1143 //============================================================================
1144 /*! Function : GetSObject
1147 //============================================================================
1148 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1150 return SALOMEDSImpl_SObject(theLabel);
1153 //============================================================================
1154 /*! Function : GetAttribute
1157 //============================================================================
1158 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const string& theEntry,
1159 const string& theType)
1161 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1162 DF_Attribute* anAttr;
1163 aSO.FindAttribute(anAttr, theType);
1167 //============================================================================
1168 /*! Function : DumpStudy
1171 //============================================================================
1172 bool SALOMEDSImpl_Study::DumpStudy(const string& thePath,
1173 const string& theBaseName,
1175 SALOMEDSImpl_DriverFactory* theFactory)
1179 if(theFactory == NULL) {
1180 _errorCode = "Null factory for creation of Engines";
1184 vector<string> aSeq;
1185 string aCompType, aFactoryType;
1187 //Build a list of all components in the Study
1188 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1190 for (; itcomponent.More(); itcomponent.Next()) {
1191 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1192 aCompType = sco.ComponentDataType();
1193 //GEOM and MED are independent components
1194 if (aCompType == "GEOM" || aCompType == "MED")
1195 aSeq.insert(aSeq.begin(), aCompType);
1197 aSeq.push_back(aCompType);
1202 thePath + string("\\") + theBaseName + string(".py");
1205 thePath + string("/") + theBaseName + string(".py");
1208 //Create a file that will contain a main Study script
1210 fp.open(aFileName.c_str(), ios::out);
1213 bool isOpened = fp.is_open();
1215 bool isOpened = fp.rdbuf()->is_open();
1219 _errorCode = string("Can't create a file ")+aFileName;
1223 string aBatchModeScript = "salome";
1225 //Output to the main Study script required Python modules import,
1226 //set sys.path and add a creation of the study.
1227 fp << "# -*- coding: iso-8859-1 -*-\n" << endl;
1229 fp << GetDumpStudyComment() << endl << endl;
1230 fp << "import sys" << endl;
1231 fp << "import " << aBatchModeScript << endl << endl;
1233 fp << aBatchModeScript << ".salome_init()" << endl << endl;
1235 fp << _GetNoteBookAccess();
1237 fp << "sys.path.insert( 0, r\'" << thePath << "\')" << endl << endl;
1239 //Dump NoteBook Variables
1240 fp << _GetStudyVariablesScript();
1242 //Check if it's necessary to dump visual parameters
1243 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1244 int lastSavePoint = -1;
1246 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1247 if(lastSavePoint > 0) {
1248 fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << endl << endl;
1253 vector<string> aSeqOfFileNames;
1255 //Iterate all components and create the componponents specific scripts.
1257 int aLength = aSeq.size();
1258 for(int i = 1; i <= aLength; i++) {
1260 aCompType = aSeq[i-1];
1261 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1262 SALOMEDSImpl_Driver* aDriver = NULL;
1263 // if there is an associated Engine call its method for saving
1266 if (!sco.ComponentIOR(IOREngine)) {
1267 if (!aCompType.empty()) {
1269 aDriver = theFactory->GetDriverByType(aCompType);
1271 if (aDriver != NULL) {
1272 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1273 if(!SB->LoadWith(sco, aDriver)) {
1274 _errorCode = SB->GetErrorCode();
1282 aDriver = theFactory->GetDriverByIOR(IOREngine);
1285 _errorCode = "Can not restore information to dump it";
1289 if(aDriver == NULL) continue;
1292 long aStreamLength = 0;
1293 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
1294 if ( !isValidScript )
1297 //Create a file that will contain the component specific script
1300 aFileName=thePath+string("\\");
1302 aFileName=thePath+string("/");
1305 aScriptName += theBaseName;
1307 aScriptName += aCompType;
1309 aFileName += aScriptName+ string(".py");
1310 aSeqOfFileNames.push_back(aFileName);
1312 fp2.open(aFileName.c_str(), ios::out);
1315 isOpened = fp2.is_open();
1317 isOpened = fp2.rdbuf()->is_open();
1321 _errorCode = string("Can't create a file ")+aFileName;
1322 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1326 //Output the Python script generated by the component in the newly created file.
1327 fp2 << aStream->Data();
1330 if(aStream) delete aStream;
1332 //Add to the main script a call to RebuildData of the generated by the component the Python script
1333 fp << "import " << aScriptName << endl;
1334 fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl;
1338 fp << "if salome.sg.hasDesktop():" << endl;
1339 fp << "\tsalome.sg.updateObjBrowser(1)" << endl;
1341 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1342 fp << "\tiparameters.getSession().restoreVisualState(1)" << endl;
1350 //=======================================================================
1351 //function : GetDumpStudyComment
1352 //purpose : return a header comment for a DumpStudy script
1353 //=======================================================================
1355 string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1358 ("### This file is generated by SALOME automatically by dump python functionality");
1359 if ( theComponentName )
1360 txt += string(" of ") + (char*) theComponentName + " component";
1364 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1367 SALOMEDSImpl_Study* theStudy);
1369 //============================================================================
1373 //============================================================================
1374 void SALOMEDSImpl_Study::dump(const string& theFileName)
1376 //Create a file that will contain a main Study script
1378 fp.open(theFileName.c_str(), ios::out);
1381 bool isOpened = fp.is_open();
1383 bool isOpened = fp.rdbuf()->is_open();
1387 _errorCode = string("Can't create a file ")+theFileName;
1388 cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << endl;
1392 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1393 fp << "0:1" << endl;
1394 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1396 for(; Itr.More(); Itr.Next()) {
1397 dumpSO(Itr.Value(), fp, aTab, this);
1404 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1407 SALOMEDSImpl_Study* theStudy)
1409 string aTab(Tab), anID(theSO.GetID());
1410 fp << aTab << anID << endl;
1411 vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1412 for(int i = 0; i<attribs.size(); i++) {
1413 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1419 string aType = anAttr->GetClassType();
1420 fp << Tab << " -- " << aType;
1422 if(aType == string("AttributeReal")) {
1423 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1425 else if(aType == string("AttributeInteger")) {
1426 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1428 else if(aType == string("AttributeName")) {
1429 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1431 else if(aType == string("AttributeComment")) {
1432 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1434 else if(aType == string("AttributeReference")) {
1435 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1440 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1441 string aNewTab(" ");
1443 for(; Itr.More(); Itr.Next()) {
1444 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1450 void SALOMEDSImpl_Study::Modify()
1453 _doc->SetModified(true);
1456 //============================================================================
1460 //============================================================================
1461 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1463 if (theSavePoint < 0) return NULL;
1464 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1465 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1466 if (!so) so = builder->NewComponent((char*)theID);
1467 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1469 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1470 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1471 if ( !savePointLabel.IsNull() )
1472 so = GetSObject( savePointLabel );
1473 else // ... if it does not exist - create a new one
1474 so = builder->NewObjectToTag( so, theSavePoint );
1479 builder->FindAttribute(so, A, "AttributeParameter");
1480 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1481 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1483 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1488 //============================================================================
1492 //============================================================================
1493 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1494 const char* theModuleName,
1497 if(theSavePoint <= 0) return NULL;
1498 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1499 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1500 SALOMEDSImpl_AttributeParameter* par = NULL;
1502 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1503 string moduleName(theModuleName);
1504 for(; it.More(); it.Next()) {
1505 SALOMEDSImpl_SObject so(it.Value());
1506 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1507 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1508 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1512 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1513 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1514 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1515 par->SetString("AP_MODULE_NAME", moduleName);
1519 //============================================================================
1520 /*! Function : SetStudyLock
1523 //============================================================================
1524 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1526 _lockers.push_back(theLockerID);
1529 //============================================================================
1530 /*! Function : IsStudyLocked
1533 //============================================================================
1534 bool SALOMEDSImpl_Study::IsStudyLocked()
1536 return (_lockers.size() > 0);
1539 //============================================================================
1540 /*! Function : UnLockStudy
1543 //============================================================================
1544 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1546 vector<string>::iterator vsI = _lockers.begin();
1547 int length = _lockers.size();
1548 bool isFound = false;
1549 string id(theLockerID);
1550 for(int i = 0; i<length; i++, vsI++) {
1551 if(id == _lockers[i]) {
1556 if(isFound) _lockers.erase(vsI);
1559 //============================================================================
1560 /*! Function : GetLockerID
1563 //============================================================================
1564 vector<string> SALOMEDSImpl_Study::GetLockerID()
1569 //============================================================================
1570 /*! Function : SetVariable
1573 //============================================================================
1574 void SALOMEDSImpl_Study::SetVariable(const string& theVarName,
1575 const double theValue,
1576 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1578 bool modified = false;
1579 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1581 if( aGVar == NULL ) {
1583 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1585 aSVar->setValue(theValue);
1586 myNoteBookVars.push_back(aSVar);
1590 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1591 modified = aSVar->setValue(theValue) || modified;
1592 modified = aSVar->setType(theType) || modified;
1599 //============================================================================
1600 /*! Function : SetStringVariable
1603 //============================================================================
1604 void SALOMEDSImpl_Study::SetStringVariable(const string& theVarName,
1605 const string& theValue,
1606 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1608 bool modified = false;
1609 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1611 if( aGVar == NULL ) {
1613 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1615 aSVar->setStringValue(theValue);
1616 myNoteBookVars.push_back(aSVar);
1620 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1621 modified = aSVar->setStringValue(theValue) || modified;
1622 modified = aSVar->setType(theType) || modified;
1629 //============================================================================
1630 /*! Function : SetStringVariableAsDouble
1633 //============================================================================
1634 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const string& theVarName,
1635 const double theValue,
1636 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1638 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1639 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1640 aSVar->setValue(theValue);
1643 //============================================================================
1644 /*! Function : GetReal
1647 //============================================================================
1648 double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName)
1650 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1653 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1654 return aSVar->getValue();
1659 //============================================================================
1660 /*! Function : GetString
1663 //============================================================================
1664 string SALOMEDSImpl_Study::GetStringVariableValue(const string& theVarName)
1666 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1669 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1670 return aSVar->getStringValue();
1675 //============================================================================
1676 /*! Function : IsTypeOf
1679 //============================================================================
1680 bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName,
1681 SALOMEDSImpl_GenericVariable::
1682 VariableTypes theType) const
1684 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1687 return aGVar->Type() == theType;
1692 //============================================================================
1693 /*! Function : IsVariable
1696 //============================================================================
1697 bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const
1699 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1700 return (aGVar != NULL);
1703 //============================================================================
1704 /*! Function : GetVariableNames
1707 //============================================================================
1708 vector<string> SALOMEDSImpl_Study::GetVariableNames() const
1710 vector<string> aResult;
1712 for(int i = 0; i < myNoteBookVars.size(); i++)
1713 aResult.push_back(myNoteBookVars[i]->Name());
1718 //============================================================================
1719 /*! Function : AddVariable
1722 //============================================================================
1723 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1725 myNoteBookVars.push_back(theVariable);
1728 //============================================================================
1729 /*! Function : AddVariable
1732 //============================================================================
1733 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1735 SALOMEDSImpl_GenericVariable* aResult = NULL;
1736 for(int i = 0; i < myNoteBookVars.size();i++) {
1737 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1738 aResult = myNoteBookVars[i];
1745 //============================================================================
1746 /*! Function : RemoveVariable
1749 //============================================================================
1750 bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName)
1752 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1756 string aValue = aVariable->SaveToScript();
1757 ReplaceVariableAttribute( theVarName, aValue );
1759 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1760 for( ; it != itEnd; it++ )
1762 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1763 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1765 myNoteBookVars.erase( it );
1774 //============================================================================
1775 /*! Function : RenameVariable
1778 //============================================================================
1779 bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
1781 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1785 ReplaceVariableAttribute( theVarName, theNewVarName );
1787 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1788 for( ; it != itEnd; it++ )
1790 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1791 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1793 aVariableRef->setName( theNewVarName );
1802 //============================================================================
1803 /*! Function : IsVariableUsed
1806 //============================================================================
1807 bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName)
1809 return FindVariableAttribute( theVarName );
1812 //============================================================================
1813 /*! Function : FindVariableAttribute
1816 //============================================================================
1817 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1818 SALOMEDSImpl_SObject theSObject,
1819 const std::string& theName)
1821 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1822 for( ; anIter.More(); anIter.Next() )
1823 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1826 DF_Attribute* anAttr;
1827 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1829 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1831 string aString = aStringAttr->Value();
1833 vector< vector<string> > aSections = ParseVariables( aString );
1834 for( int i = 0, n = aSections.size(); i < n; i++ )
1836 vector<string> aVector = aSections[i];
1837 for( int j = 0, m = aVector.size(); j < m; j++ )
1839 string aStr = aVector[j];
1840 if( aStr.compare( theName ) == 0 )
1849 //============================================================================
1850 /*! Function : FindVariableAttribute
1853 //============================================================================
1854 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1856 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1857 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1858 for( ; aCompIter.More(); aCompIter.Next() )
1860 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1861 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1867 //============================================================================
1868 /*! Function : ReplaceVariableAttribute
1871 //============================================================================
1872 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1873 SALOMEDSImpl_SObject theSObject,
1874 const std::string& theSource,
1875 const std::string& theDest)
1877 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1878 for( ; anIter.More(); anIter.Next() )
1879 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1881 DF_Attribute* anAttr;
1882 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1884 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1886 bool isChanged = false;
1887 string aNewString, aCurrentString = aStringAttr->Value();
1889 vector< vector<string> > aSections = ParseVariables( aCurrentString );
1890 for( int i = 0, n = aSections.size(); i < n; i++ )
1892 vector<string> aVector = aSections[i];
1893 for( int j = 0, m = aVector.size(); j < m; j++ )
1895 string aStr = aVector[j];
1896 if( aStr.compare( theSource ) == 0 )
1902 aNewString.append( aStr );
1904 aNewString.append( ":" );
1907 aNewString.append( "|" );
1911 aStringAttr->SetValue( aNewString );
1916 //============================================================================
1917 /*! Function : ReplaceVariableAttribute
1920 //============================================================================
1921 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
1923 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1924 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1925 for( ; aCompIter.More(); aCompIter.Next() )
1927 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1928 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
1932 //============================================================================
1933 /*! Function : ParseVariables
1936 //============================================================================
1937 vector< vector< string > > SALOMEDSImpl_Study::ParseVariables(const string& theVariables) const
1939 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
1942 //============================================================================
1943 /*! Function : EnableUseCaseAutoFilling
1946 //============================================================================
1947 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
1949 _errorCode = ""; _autoFill = isEnabled;
1951 _builder->SetOnAddSObject(_cb);
1952 _builder->SetOnRemoveSObject(_cb);
1955 _builder->SetOnAddSObject(NULL);
1956 _builder->SetOnRemoveSObject(NULL);
1960 //============================================================================
1961 /*! Function : GetIORs
1964 //============================================================================
1965 vector<string> SALOMEDSImpl_Study::GetIORs()
1967 vector<string> anIORs;
1968 map<string, DF_Label>::const_iterator MI;
1969 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
1970 anIORs.push_back(MI->first);