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 "DF_Application.hxx"
32 #include "DF_ChildIterator.hxx"
34 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
35 #include "SALOMEDSImpl_Attributes.hxx"
36 #include "SALOMEDSImpl_UseCaseIterator.hxx"
37 #include "SALOMEDSImpl_AttributeReference.hxx"
38 #include "SALOMEDSImpl_StudyHandle.hxx"
39 #include "SALOMEDSImpl_Tool.hxx"
40 #include "SALOMEDSImpl_IParameters.hxx"
41 #include "SALOMEDSImpl_ScalarVariable.hxx"
45 #define DIRECTORYID 16661
46 #define FILELOCALID 26662
47 #define FILEID "FILE: "
48 #define VARIABLE_SEPARATOR ':'
49 #define OPERATION_SEPARATOR '|'
51 //to disable automatic genericobj management comment the following line
52 #define WITHGENERICOBJ
55 #include "SALOME_GenericObj_i.hh"
56 static CORBA::ORB_var getORB()
59 return CORBA::ORB_init(argc,0);
63 //============================================================================
64 /*! Function : SALOMEDSImpl_Study
65 * Purpose : SALOMEDSImpl_Study constructor
67 //============================================================================
68 SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
69 const string& study_name)
72 _doc = (DF_Document*)doc;
78 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
79 _builder = new SALOMEDSImpl_StudyBuilder(this);
80 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
81 //Put on the root label a StudyHandle attribute to store the address of this object
82 //It will be used to retrieve the study object by DF_Label that belongs to the study
83 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
87 //============================================================================
88 /*! Function : ~SALOMEDSImpl_Study
89 * Purpose : SALOMEDSImpl_Study destructor
91 //============================================================================
92 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
96 delete _useCaseBuilder;
99 //============================================================================
100 /*! Function : GetPersistentReference
101 * Purpose : Get persistent reference of study (idem URL())
103 //============================================================================
104 string SALOMEDSImpl_Study::GetPersistentReference()
109 //============================================================================
110 /*! Function : GetTransientReference
111 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
113 //============================================================================
114 string SALOMEDSImpl_Study::GetTransientReference()
119 SALOMEDSImpl_AttributeIOR* Att;
120 DF_Label _lab = _doc->Root();
121 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
125 _errorCode = "IOR is empty";
131 void SALOMEDSImpl_Study::SetTransientReference(const string& theIOR)
135 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
136 int aLocked = aProp->IsLocked();
137 if (aLocked) aProp->SetLocked(false);
139 // Assign the value of the IOR in the study->root
140 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
142 if (aLocked) aProp->SetLocked(true);
145 //============================================================================
146 /*! Function : IsEmpty
147 * Purpose : Detect if study is empty
149 //============================================================================
150 bool SALOMEDSImpl_Study::IsEmpty()
153 if (!_doc) return true;
154 return _doc->IsEmpty();
157 //============================================================================
158 /*! Function : FindComponent
159 * Purpose : Find a Component with ComponentDataType = aComponentName
161 //============================================================================
162 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const string& aComponentName)
167 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
168 SALOMEDSImpl_SComponent compo;
170 for (; itcomp.More(); itcomp.Next()) {
171 SALOMEDSImpl_SComponent SC = itcomp.Value();
172 name = SC.ComponentDataType();
173 if(aComponentName == name) {
181 _errorCode = "No component was found";
187 //============================================================================
188 /*! Function : FindComponentID
189 * Purpose : Find a Component from it's ID
191 //============================================================================
192 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const string& aComponentID)
196 // Iterate on each components defined in the study
197 // Get the component ID and compare with aComponentID
200 SALOMEDSImpl_SComponent compo;
202 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
203 for (; itcomp.More(); itcomp.Next()) {
204 SALOMEDSImpl_SComponent SC = itcomp.Value();
206 if(aComponentID == ID)
215 _errorCode = "No component was found";
222 //============================================================================
223 /*! Function : FindObject
224 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
226 //============================================================================
227 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const string& anObjectName)
231 // Iterate to all components defined in the study
232 // After testing the component name, iterate in all objects defined under
233 // components (function _FindObject)
235 SALOMEDSImpl_SObject RefSO;
237 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
238 for (; it.More();it.Next()){
241 SALOMEDSImpl_SComponent SC = it.Value();
242 if (SC.GetName() == anObjectName)
248 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
251 if(!RefSO) _errorCode = "No object was found";
255 //============================================================================
256 /*! Function : FindObjectID
257 * Purpose : Find an Object with ID = anObjectID
259 //============================================================================
260 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const string& anObjectID)
263 SALOMEDSImpl_SObject so;
265 // Convert aSO->GetID in DF_Label.
266 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
269 _errorCode = "No label was found by ID";
272 return GetSObject(Lab);
276 //============================================================================
277 /*! Function : CreateObjectID
278 * Purpose : Creates an Object with ID = anObjectID
280 //============================================================================
281 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const string& anObjectID)
284 SALOMEDSImpl_SObject so;
286 // Convert aSO->GetID in DF_Label.
287 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
290 _errorCode = "Can not create a label";
293 return GetSObject(Lab);
297 //============================================================================
298 /*! Function : FindObjectByName
299 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
300 * : with ComponentDataType = aComponentName
302 //============================================================================
303 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const string& anObjectName,
304 const string& aComponentName)
308 vector<SALOMEDSImpl_SObject> listSO;
310 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
312 _errorCode = "Can not find the component";
316 // Iterate on each object and subobject of the component
317 // If objectName is found add it to the list of SObjects
320 string compoId = compo.GetID();
321 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
322 for ( ; it.More(); it.Next() ) {
324 SALOMEDSImpl_SObject CSO = it.Value();
325 if ( CSO.GetName() == anObjectName ) {
327 listSO.push_back(CSO) ;
330 /* looks also for eventual children */
332 CSO = _FindObject( CSO, anObjectName, found ) ;
334 listSO.push_back(CSO) ;
343 //============================================================================
344 /*! Function : FindObjectIOR
345 * Purpose : Find an Object with IOR = anObjectIOR
347 //============================================================================
348 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const string& anObjectIOR)
352 SALOMEDSImpl_SObject aResult ;
354 // searching in the datamap for optimization
355 if (myIORLabels.find(anObjectIOR) != myIORLabels.end()) {
356 aResult = GetSObject(myIORLabels[anObjectIOR]);
357 // 11 oct 2002: forbidden attributes must be checked here
358 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
359 myIORLabels.erase(anObjectIOR);
360 aResult = SALOMEDSImpl_SObject();
364 if(!aResult) _errorCode = "No object was found";
368 //============================================================================
369 /*! Function : FindObjectByPath
370 * Purpose : Find an Object by its path = thePath
372 //============================================================================
373 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const string& thePath)
377 string aPath(thePath), aToken;
378 SALOMEDSImpl_SObject aSO;
379 int aLength = aPath.size();
380 bool isRelative = false;
382 if(aLength == 0) { //Empty path - return the current context
383 return GetSObject(_current);
386 if(aPath[0] != '/') //Relative path
389 DF_ChildIterator anIterator;
391 SALOMEDSImpl_AttributeName* anAttr;
394 if(_current.IsNull()) return aSO;
395 anIterator.Init(_current, false);
398 if(aPath.size() == 1 && aPath[0] == '/') { //Root
399 return GetSObject(_doc->Main());
401 anIterator.Init(_doc->Main(), false);
404 vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
405 for(int i = 0, len = vs.size(); i<len; i++) {
408 if(aToken.size() == 0) break;
410 for ( ; anIterator.More(); anIterator.Next() ) {
411 aLabel = anIterator.Value();
412 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
413 if(anAttr->Value() == aToken) {
414 if(i == (len-1)) { //The searched label is found (no part of the path is left)
415 return GetSObject(aLabel);
418 anIterator.Init(aLabel, false);
426 if(!aSO) _errorCode = "No object was found";
430 //============================================================================
431 /*! Function : GetObjectPath
434 //============================================================================
435 string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
441 _errorCode = "Null object";
445 string aName = theObject.GetName();
446 if(!aName.empty() && aName != "" ) {
451 SALOMEDSImpl_SObject aFather = theObject.GetFather();
453 aName = aFather.GetName();
454 if(!aName.empty() && aName != "") {
455 aValue = GetObjectPath(aFather);
456 aPath = aValue + aPath;
465 //============================================================================
466 /*! Function : GetObjectPathByIOR
469 //============================================================================
470 string SALOMEDSImpl_Study::GetObjectPathByIOR(const string& theIOR)
475 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
477 _errorCode = "No SObject was found by IOR";
481 return GetObjectPath(so);
485 //============================================================================
486 /*! Function : SetContext
487 * Purpose : Sets the current context
489 //============================================================================
490 bool SALOMEDSImpl_Study::SetContext(const string& thePath)
493 if(thePath.empty()) {
494 _errorCode = "InvalidPath";
498 string aPath(thePath), aContext("");
499 bool isInvalid = false;
500 SALOMEDSImpl_SObject aSO;
502 if(aPath[0] != '/') { //Relative path
503 aContext = GetContext();
511 aSO = FindObjectByPath(aContext);
517 if(isInvalid || !aSO) {
518 _errorCode = "InvalidContext";
522 DF_Label aLabel = aSO.GetLabel();
523 if(aLabel.IsNull()) {
524 _errorCode = "InvalidContext";
528 _current = aLabel; //Set the current context
533 //============================================================================
534 /*! Function : GetContext
535 * Purpose : Gets the current context
537 //============================================================================
538 string SALOMEDSImpl_Study::GetContext()
542 if(_current.IsNull()) {
543 _errorCode = "InvaidContext";
546 SALOMEDSImpl_SObject so = GetSObject(_current);
547 return GetObjectPath(so);
550 //============================================================================
551 /*! Function : GetObjectNames
552 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
554 //============================================================================
555 vector<string> SALOMEDSImpl_Study::GetObjectNames(const string& theContext)
559 vector<string> aResultSeq;
561 if (theContext.empty()) {
564 DF_Label aTmp = _current;
565 SetContext(theContext);
569 if (aLabel.IsNull()) {
570 _errorCode = "InvalidContext";
574 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
575 for (; anIter.More(); anIter.Next()) {
576 DF_Label aLabel = anIter.Value();
577 SALOMEDSImpl_AttributeName* aName;
578 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
579 aResultSeq.push_back(aName->Value());
585 //============================================================================
586 /*! Function : GetDirectoryNames
587 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
589 //============================================================================
590 vector<string> SALOMEDSImpl_Study::GetDirectoryNames(const string& theContext)
594 vector<string> aResultSeq;
596 if (theContext.empty()) {
599 DF_Label aTmp = _current;
600 SetContext(theContext);
604 if (aLabel.IsNull()) {
605 _errorCode = "InvalidContext";
609 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
610 for (; anIter.More(); anIter.Next()) {
611 DF_Label aLabel = anIter.Value();
612 SALOMEDSImpl_AttributeLocalID* anID;
613 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
614 if (anID->Value() == DIRECTORYID) {
615 SALOMEDSImpl_AttributeName* aName;
616 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
617 aResultSeq.push_back(aName->Value());
626 //============================================================================
627 /*! Function : GetFileNames
628 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
630 //============================================================================
631 vector<string> SALOMEDSImpl_Study::GetFileNames(const string& theContext)
635 vector<string> aResultSeq;
637 if (theContext.empty()) {
640 DF_Label aTmp = _current;
641 SetContext(theContext);
645 if (aLabel.IsNull()) {
646 _errorCode = "InvalidContext";
650 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
651 for (; anIter.More(); anIter.Next()) {
652 DF_Label aLabel = anIter.Value();
653 SALOMEDSImpl_AttributeLocalID* anID;
654 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
655 if (anID->Value() == FILELOCALID) {
656 SALOMEDSImpl_AttributePersistentRef* aName;
657 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
658 std::string aFileName = aName->Value();
659 if (aFileName.size() > 0)
660 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
669 //============================================================================
670 /*! Function : GetComponentNames
671 * Purpose : method to get all components names
673 //============================================================================
674 vector<string> SALOMEDSImpl_Study::GetComponentNames(const string& theContext)
678 vector<string> aResultSeq;
679 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
680 for(; anIter.More(); anIter.Next()) {
681 DF_Label aLabel = anIter.Value();
682 SALOMEDSImpl_AttributeName* aName;
683 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
684 aResultSeq.push_back(aName->Value());
690 //============================================================================
691 /*! Function : NewChildIterator
692 * Purpose : Create a ChildIterator from an SObject
694 //============================================================================
695 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
698 return SALOMEDSImpl_ChildIterator(aSO);
702 //============================================================================
703 /*! Function : NewComponentIterator
704 * Purpose : Create a SComponentIterator
706 //============================================================================
707 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
710 return SALOMEDSImpl_SComponentIterator(_doc);
714 //============================================================================
715 /*! Function : NewBuilder
716 * Purpose : Create a StudyBuilder
718 //============================================================================
719 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
723 _builder->SetOnAddSObject(_cb);
724 _builder->SetOnRemoveSObject(_cb);
730 //============================================================================
732 * Purpose : get study name
734 //============================================================================
735 string SALOMEDSImpl_Study::Name()
741 //============================================================================
743 * Purpose : set study name
745 //============================================================================
746 void SALOMEDSImpl_Study::Name(const string& name)
752 //============================================================================
753 /*! Function : IsSaved
754 * Purpose : get if study has been saved
756 //============================================================================
757 bool SALOMEDSImpl_Study::IsSaved()
763 //============================================================================
764 /*! Function : IsSaved
765 * Purpose : set if study has been saved
767 //============================================================================
768 void SALOMEDSImpl_Study::IsSaved(bool save)
772 if(save) _doc->SetModified(false);
775 //============================================================================
776 /*! Function : IsModified
777 * Purpose : Detect if a Study has been modified since it has been saved
779 //============================================================================
780 bool SALOMEDSImpl_Study::IsModified()
784 // True if is modified
785 if (_doc && _doc->IsModified()) return true;
790 //============================================================================
792 * Purpose : get URL of the study (persistent reference of the study)
794 //============================================================================
795 string SALOMEDSImpl_Study::URL()
801 //============================================================================
803 * Purpose : set URL of the study (persistent reference of the study)
805 //============================================================================
806 void SALOMEDSImpl_Study::URL(const string& url)
811 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
814 char *aName = (char*)tmp.ToCString();
815 char *adr = strtok(aName, "/");
819 adr = strtok(NULL, "/");
826 //============================================================================
827 /*! Function : _FindObject
828 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
830 //============================================================================
831 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
832 const string& theObjectName,
835 SALOMEDSImpl_SObject RefSO;
836 if(!SO) return RefSO;
838 // Iterate on each objects and subobjects of the component
839 // If objectName find, stop the loop and get the object reference
840 SALOMEDSImpl_AttributeName* anAttr;
842 string soid = SO.GetID();
843 DF_ChildIterator it(SO.GetLabel());
844 for (; it.More(); it.Next()){
847 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
849 string Val(anAttr->Value());
850 if (Val == theObjectName)
852 RefSO = GetSObject(it.Value());
856 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
862 //============================================================================
863 /*! Function : _FindObjectIOR
864 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
866 //============================================================================
868 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
869 const string& theObjectIOR,
872 SALOMEDSImpl_SObject RefSO, aSO;
873 if(!SO) return RefSO;
875 // Iterate on each objects and subobjects of the component
876 // If objectName find, stop the loop and get the object reference
877 SALOMEDSImpl_AttributeIOR* anAttr;
879 DF_ChildIterator it(SO.GetLabel());
880 for (; it.More();it.Next()){
883 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
885 string Val(anAttr->Value());
886 if (Val == theObjectIOR)
888 RefSO = GetSObject(it.Value());
892 aSO = GetSObject(it.Value());
893 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
899 //============================================================================
900 /*! Function : _GetNoteBookAccessor
901 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
903 //============================================================================
904 string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
905 return string("notebook");
908 //============================================================================
909 /*! Function : _GetStudyVariablesScript
912 //============================================================================
913 string SALOMEDSImpl_Study::_GetStudyVariablesScript()
917 if(myNoteBookVars.empty())
920 dump += "####################################################\n";
921 dump += "## Begin of NoteBook variables section ##\n";
922 dump += "####################################################\n";
924 string set_method = _GetNoteBookAccessor()+".set(";
927 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
928 varName = myNoteBookVars[i]->Name();
929 varValue = myNoteBookVars[i]->SaveToScript();
930 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
933 dump += "####################################################\n";
934 dump += "## End of NoteBook variables section ##\n";
935 dump += "####################################################\n";
940 //============================================================================
941 /*! Function : _GetNoteBookAccess
944 //============================================================================
945 string SALOMEDSImpl_Study::_GetNoteBookAccess()
947 string accessor = _GetNoteBookAccessor();
948 string notebook = "import salome_notebook\n";
949 notebook += accessor+" = salome_notebook."+accessor + "\n";
953 bool SALOMEDSImpl_Study::IsLocked()
956 return GetProperties()->IsLocked();
959 int SALOMEDSImpl_Study::StudyId()
965 void SALOMEDSImpl_Study::StudyId(int id)
971 void SALOMEDSImpl_Study::UpdateIORLabelMap(const string& anIOR,const string& anEntry)
974 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
975 if (myIORLabels.find(anIOR) != myIORLabels.end()) myIORLabels.erase(anIOR);
976 #ifdef WITHGENERICOBJ
979 // if the ior was not already registered, incref the genericobj (if it's one)
980 CORBA::Object_var obj;
981 SALOME::GenericObj_var gobj;
984 obj = getORB()->string_to_object(anIOR.c_str());
985 gobj = SALOME::GenericObj::_narrow(obj);
986 if(! CORBA::is_nil(gobj) )
991 catch(const CORBA::Exception& e)
996 myIORLabels[anIOR] = aLabel;
999 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
1001 if (myIORLabels.find(anIOR) != myIORLabels.end())
1003 //remove the ior entry and decref the genericobj (if it's one)
1004 myIORLabels.erase(anIOR);
1005 #ifdef WITHGENERICOBJ
1006 CORBA::Object_var obj;
1007 SALOME::GenericObj_var gobj;
1010 obj = getORB()->string_to_object(anIOR.c_str());
1011 gobj = SALOME::GenericObj::_narrow(obj);
1012 if(! CORBA::is_nil(gobj) )
1017 catch(const CORBA::Exception& e)
1024 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
1026 SALOMEDSImpl_StudyHandle* Att;
1027 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
1033 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
1035 return GetStudy(theLabel)->GetSObject(theLabel);
1038 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
1040 return GetStudy(theLabel)->GetSComponent(theLabel);
1044 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1046 string aString = theAttribute->Label().Entry();
1047 GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1050 vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1053 vector<SALOMEDSImpl_SObject> aSeq;
1055 SALOMEDSImpl_AttributeTarget* aTarget;
1056 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1057 return aTarget->Get();
1064 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1067 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1070 string SALOMEDSImpl_Study::GetLastModificationDate()
1073 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1075 vector<string> aNames;
1076 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1077 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1079 int aLastIndex = aNames.size()-1;
1081 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1082 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1083 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1084 string aResStr (aResult);
1088 vector<string> SALOMEDSImpl_Study::GetModificationsDate()
1091 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1093 vector<string> aNames;
1094 vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1095 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1097 int anIndex, aLength = aNames.size();
1098 vector<string> aDates;
1100 for (anIndex = 1; anIndex < aLength; anIndex++) {
1102 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1103 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1104 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1105 aDates.push_back(aDate);
1112 //============================================================================
1113 /*! Function : GetUseCaseBuilder
1114 * Purpose : Returns a UseCase builder
1116 //============================================================================
1117 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1120 return _useCaseBuilder;
1124 //============================================================================
1125 /*! Function : Close
1128 //============================================================================
1129 void SALOMEDSImpl_Study::Close()
1132 _doc->GetApplication()->Close(_doc);
1139 //============================================================================
1140 /*! Function : GetSComponent
1143 //============================================================================
1144 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const string& theEntry)
1146 SALOMEDSImpl_SComponent aSCO;
1147 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1148 aSCO = _mapOfSCO[theEntry];
1150 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1151 aSCO = SALOMEDSImpl_SComponent(aLabel);
1152 _mapOfSCO[theEntry] = aSCO;
1158 //============================================================================
1159 /*! Function : GetSComponent
1162 //============================================================================
1163 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1165 return SALOMEDSImpl_SComponent(theLabel);
1168 //============================================================================
1169 /*! Function : GetSObject
1172 //============================================================================
1173 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const string& theEntry)
1175 SALOMEDSImpl_SObject aSO;
1176 if(_mapOfSO.find(theEntry) != _mapOfSO.end())
1177 aSO = _mapOfSO[theEntry];
1179 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1180 aSO = SALOMEDSImpl_SObject(aLabel);
1181 _mapOfSO[theEntry] = aSO;
1187 //============================================================================
1188 /*! Function : GetSObject
1191 //============================================================================
1192 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1194 return SALOMEDSImpl_SObject(theLabel);
1197 //============================================================================
1198 /*! Function : GetAttribute
1201 //============================================================================
1202 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const string& theEntry,
1203 const string& theType)
1205 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1206 DF_Attribute* anAttr;
1207 aSO.FindAttribute(anAttr, theType);
1211 //============================================================================
1212 /*! Function : DumpStudy
1215 //============================================================================
1216 bool SALOMEDSImpl_Study::DumpStudy(const string& thePath,
1217 const string& theBaseName,
1219 SALOMEDSImpl_DriverFactory* theFactory)
1223 if(theFactory == NULL) {
1224 _errorCode = "Null factory for creation of Engines";
1228 vector<string> aSeq;
1229 string aCompType, aFactoryType;
1231 //Build a list of all components in the Study
1232 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1234 for (; itcomponent.More(); itcomponent.Next()) {
1235 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1236 aCompType = sco.ComponentDataType();
1237 //GEOM and MED are independent components
1238 if (aCompType == "GEOM" || aCompType == "MED")
1239 aSeq.insert(aSeq.begin(), aCompType);
1241 aSeq.push_back(aCompType);
1246 thePath + string("\\") + theBaseName + string(".py");
1249 thePath + string("/") + theBaseName + string(".py");
1252 //Create a file that will contain a main Study script
1254 fp.open(aFileName.c_str(), ios::out);
1257 bool isOpened = fp.is_open();
1259 bool isOpened = fp.rdbuf()->is_open();
1263 _errorCode = string("Can't create a file ")+aFileName;
1267 string aBatchModeScript = "salome";
1269 //Output to the main Study script required Python modules import,
1270 //set sys.path and add a creation of the study.
1271 fp << GetDumpStudyComment() << endl << endl;
1272 fp << "import sys" << endl;
1273 fp << "import " << aBatchModeScript << endl << endl;
1275 fp << aBatchModeScript << ".salome_init()" << endl << endl;
1277 fp << _GetNoteBookAccess();
1279 fp << "sys.path.insert( 0, r\'" << thePath << "\')" << endl << endl;
1281 //Dump NoteBook Variables
1282 fp << _GetStudyVariablesScript();
1284 //Check if it's necessary to dump visual parameters
1285 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1286 int lastSavePoint = -1;
1288 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1289 if(lastSavePoint > 0) {
1290 fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << endl << endl;
1295 vector<string> aSeqOfFileNames;
1297 //Iterate all components and create the componponents specific scripts.
1299 int aLength = aSeq.size();
1300 for(int i = 1; i <= aLength; i++) {
1302 aCompType = aSeq[i-1];
1303 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1304 SALOMEDSImpl_Driver* aDriver = NULL;
1305 // if there is an associated Engine call its method for saving
1308 if (!sco.ComponentIOR(IOREngine)) {
1309 if (!aCompType.empty()) {
1311 aDriver = theFactory->GetDriverByType(aCompType);
1313 if (aDriver != NULL) {
1314 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1315 if(!SB->LoadWith(sco, aDriver)) {
1316 _errorCode = SB->GetErrorCode();
1324 aDriver = theFactory->GetDriverByIOR(IOREngine);
1327 _errorCode = "Can not restore information to dump it";
1331 if(aDriver == NULL) continue;
1334 long aStreamLength = 0;
1335 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
1336 if ( !isValidScript )
1339 //Create a file that will contain the component specific script
1342 aFileName=thePath+string("\\");
1344 aFileName=thePath+string("/");
1347 aScriptName += theBaseName;
1349 aScriptName += aCompType;
1351 aFileName += aScriptName+ string(".py");
1352 aSeqOfFileNames.push_back(aFileName);
1354 fp2.open(aFileName.c_str(), ios::out);
1357 isOpened = fp2.is_open();
1359 isOpened = fp2.rdbuf()->is_open();
1363 _errorCode = string("Can't create a file ")+aFileName;
1364 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1368 //Output the Python script generated by the component in the newly created file.
1369 fp2 << aStream->Data();
1372 if(aStream) delete aStream;
1374 //Add to the main script a call to RebuildData of the generated by the component the Python script
1375 fp << "import " << aScriptName << endl;
1376 fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << endl;
1380 fp << "if salome.sg.hasDesktop():" << endl;
1381 fp << "\tsalome.sg.updateObjBrowser(1)" << endl;
1383 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1384 fp << "\tiparameters.getSession().restoreVisualState(1)" << endl;
1392 //=======================================================================
1393 //function : GetDumpStudyComment
1394 //purpose : return a header comment for a DumpStudy script
1395 //=======================================================================
1397 string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1400 ("### This file is generated by SALOME automatically by dump python functionality");
1401 if ( theComponentName )
1402 txt += string(" of ") + (char*) theComponentName + " component";
1406 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1409 SALOMEDSImpl_Study* theStudy);
1411 //============================================================================
1415 //============================================================================
1416 void SALOMEDSImpl_Study::dump(const string& theFileName)
1418 //Create a file that will contain a main Study script
1420 fp.open(theFileName.c_str(), ios::out);
1423 bool isOpened = fp.is_open();
1425 bool isOpened = fp.rdbuf()->is_open();
1429 _errorCode = string("Can't create a file ")+theFileName;
1430 cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << endl;
1434 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1435 fp << "0:1" << endl;
1436 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1438 for(; Itr.More(); Itr.Next()) {
1439 dumpSO(Itr.Value(), fp, aTab, this);
1446 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1449 SALOMEDSImpl_Study* theStudy)
1451 string aTab(Tab), anID(theSO.GetID());
1452 fp << aTab << anID << endl;
1453 vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1454 for(int i = 0; i<attribs.size(); i++) {
1455 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1461 string aType = anAttr->GetClassType();
1462 fp << Tab << " -- " << aType;
1464 if(aType == string("AttributeReal")) {
1465 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1467 else if(aType == string("AttributeInteger")) {
1468 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1470 else if(aType == string("AttributeName")) {
1471 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1473 else if(aType == string("AttributeComment")) {
1474 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1476 else if(aType == string("AttributeReference")) {
1477 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1482 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1483 string aNewTab(" ");
1485 for(; Itr.More(); Itr.Next()) {
1486 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1492 void SALOMEDSImpl_Study::Modify()
1495 _doc->SetModified(true);
1498 //============================================================================
1502 //============================================================================
1503 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1505 if (theSavePoint < 0) return NULL;
1506 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1507 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1508 if (!so) so = builder->NewComponent((char*)theID);
1509 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1511 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1512 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1513 if ( !savePointLabel.IsNull() )
1514 so = GetSObject( savePointLabel );
1515 else // ... if it does not exist - create a new one
1516 so = builder->NewObjectToTag( so, theSavePoint );
1521 builder->FindAttribute(so, A, "AttributeParameter");
1522 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1523 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1525 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1530 //============================================================================
1534 //============================================================================
1535 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1536 const char* theModuleName,
1539 if(theSavePoint <= 0) return NULL;
1540 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1541 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1542 SALOMEDSImpl_AttributeParameter* par = NULL;
1544 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1545 string moduleName(theModuleName);
1546 for(; it.More(); it.Next()) {
1547 SALOMEDSImpl_SObject so(it.Value());
1548 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1549 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1550 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1554 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1555 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1556 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1557 par->SetString("AP_MODULE_NAME", moduleName);
1561 //============================================================================
1562 /*! Function : SetStudyLock
1565 //============================================================================
1566 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1568 _lockers.push_back(theLockerID);
1571 //============================================================================
1572 /*! Function : IsStudyLocked
1575 //============================================================================
1576 bool SALOMEDSImpl_Study::IsStudyLocked()
1578 return (_lockers.size() > 0);
1581 //============================================================================
1582 /*! Function : UnLockStudy
1585 //============================================================================
1586 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1588 vector<string>::iterator vsI = _lockers.begin();
1589 int length = _lockers.size();
1590 bool isFound = false;
1591 string id(theLockerID);
1592 for(int i = 0; i<length; i++, vsI++) {
1593 if(id == _lockers[i]) {
1598 if(isFound) _lockers.erase(vsI);
1601 //============================================================================
1602 /*! Function : GetLockerID
1605 //============================================================================
1606 vector<string> SALOMEDSImpl_Study::GetLockerID()
1611 //============================================================================
1612 /*! Function : SetVariable
1615 //============================================================================
1616 void SALOMEDSImpl_Study::SetVariable(const string& theVarName,
1617 const double theValue,
1618 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1620 bool modified = false;
1621 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1623 if( aGVar == NULL ) {
1625 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1627 aSVar->setValue(theValue);
1628 myNoteBookVars.push_back(aSVar);
1632 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1633 modified = aSVar->setValue(theValue) || modified;
1634 modified = aSVar->setType(theType) || modified;
1641 //============================================================================
1642 /*! Function : GetReal
1645 //============================================================================
1646 double SALOMEDSImpl_Study::GetVariableValue(const string& theVarName)
1648 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1651 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1652 return aSVar->getValue();
1657 //============================================================================
1658 /*! Function : IsTypeOf
1661 //============================================================================
1662 bool SALOMEDSImpl_Study::IsTypeOf(const string& theVarName,
1663 SALOMEDSImpl_GenericVariable::
1664 VariableTypes theType) const
1666 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1669 return aGVar->Type() == theType;
1674 //============================================================================
1675 /*! Function : IsVariable
1678 //============================================================================
1679 bool SALOMEDSImpl_Study::IsVariable(const string& theVarName) const
1681 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1682 return (aGVar != NULL);
1685 //============================================================================
1686 /*! Function : GetVariableNames
1689 //============================================================================
1690 vector<string> SALOMEDSImpl_Study::GetVariableNames() const
1692 vector<string> aResult;
1694 for(int i = 0; i < myNoteBookVars.size(); i++)
1695 aResult.push_back(myNoteBookVars[i]->Name());
1700 //============================================================================
1701 /*! Function : AddVariable
1704 //============================================================================
1705 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1707 myNoteBookVars.push_back(theVariable);
1710 //============================================================================
1711 /*! Function : AddVariable
1714 //============================================================================
1715 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1717 SALOMEDSImpl_GenericVariable* aResult = NULL;
1718 for(int i = 0; i < myNoteBookVars.size();i++) {
1719 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1720 aResult = myNoteBookVars[i];
1727 //============================================================================
1728 /*! Function : RemoveVariable
1731 //============================================================================
1732 bool SALOMEDSImpl_Study::RemoveVariable(const string& theVarName)
1734 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1738 string aValue = aVariable->SaveToScript();
1739 ReplaceVariableAttribute( theVarName, aValue );
1741 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1742 for( ; it != itEnd; it++ )
1744 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1745 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1747 myNoteBookVars.erase( it );
1756 //============================================================================
1757 /*! Function : RenameVariable
1760 //============================================================================
1761 bool SALOMEDSImpl_Study::RenameVariable(const string& theVarName, const string& theNewVarName)
1763 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1767 ReplaceVariableAttribute( theVarName, theNewVarName );
1769 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1770 for( ; it != itEnd; it++ )
1772 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1773 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1775 aVariableRef->setName( theNewVarName );
1784 //============================================================================
1785 /*! Function : IsVariableUsed
1788 //============================================================================
1789 bool SALOMEDSImpl_Study::IsVariableUsed(const string& theVarName)
1791 return FindVariableAttribute( theVarName );
1794 //============================================================================
1795 /*! Function : FindVariableAttribute
1798 //============================================================================
1799 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1800 SALOMEDSImpl_SObject theSObject,
1801 const std::string& theName)
1803 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1804 for( ; anIter.More(); anIter.Next() )
1805 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1808 DF_Attribute* anAttr;
1809 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1811 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1813 string aString = aStringAttr->Value();
1815 vector< vector<string> > aSections = ParseVariables( aString );
1816 for( int i = 0, n = aSections.size(); i < n; i++ )
1818 vector<string> aVector = aSections[i];
1819 for( int j = 0, m = aVector.size(); j < m; j++ )
1821 string aStr = aVector[j];
1822 if( aStr.compare( theName ) == 0 )
1831 //============================================================================
1832 /*! Function : FindVariableAttribute
1835 //============================================================================
1836 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1838 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1839 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1840 for( ; aCompIter.More(); aCompIter.Next() )
1842 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1843 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1849 //============================================================================
1850 /*! Function : ReplaceVariableAttribute
1853 //============================================================================
1854 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1855 SALOMEDSImpl_SObject theSObject,
1856 const std::string& theSource,
1857 const std::string& theDest)
1859 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1860 for( ; anIter.More(); anIter.Next() )
1861 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1863 DF_Attribute* anAttr;
1864 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1866 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1868 bool isChanged = false;
1869 string aNewString, aCurrentString = aStringAttr->Value();
1871 vector< vector<string> > aSections = ParseVariables( aCurrentString );
1872 for( int i = 0, n = aSections.size(); i < n; i++ )
1874 vector<string> aVector = aSections[i];
1875 for( int j = 0, m = aVector.size(); j < m; j++ )
1877 string aStr = aVector[j];
1878 if( aStr.compare( theSource ) == 0 )
1884 aNewString.append( aStr );
1886 aNewString.append( ":" );
1889 aNewString.append( "|" );
1893 aStringAttr->SetValue( aNewString );
1898 //============================================================================
1899 /*! Function : ReplaceVariableAttribute
1902 //============================================================================
1903 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
1905 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1906 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1907 for( ; aCompIter.More(); aCompIter.Next() )
1909 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1910 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
1914 //============================================================================
1915 /*! Function : ParseVariables
1918 //============================================================================
1919 vector< vector< string > > SALOMEDSImpl_Study::ParseVariables(const string& theVariables) const
1921 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
1924 //============================================================================
1925 /*! Function : EnableUseCaseAutoFilling
1928 //============================================================================
1929 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
1931 _errorCode = ""; _autoFill = isEnabled;
1933 _builder->SetOnAddSObject(_cb);
1934 _builder->SetOnRemoveSObject(_cb);
1937 _builder->SetOnAddSObject(NULL);
1938 _builder->SetOnRemoveSObject(NULL);
1942 //============================================================================
1943 /*! Function : GetIORs
1946 //============================================================================
1947 vector<string> SALOMEDSImpl_Study::GetIORs()
1949 vector<string> anIORs;
1950 map<string, DF_Label>::const_iterator MI;
1951 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
1952 anIORs.push_back(MI->first);