1 // Copyright (C) 2007-2010 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
23 // File : SALOMEDSImpl_Study.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_Study.hxx"
30 #include <KERNEL_version.h>
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"
48 #define DIRECTORYID 16661
49 #define FILELOCALID 26662
50 #define FILEID "FILE: "
51 #define VARIABLE_SEPARATOR ':'
52 #define OPERATION_SEPARATOR '|'
54 //============================================================================
55 /*! Function : SALOMEDSImpl_Study
56 * Purpose : SALOMEDSImpl_Study constructor
58 //============================================================================
59 SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
60 const std::string& study_name)
63 _doc = (DF_Document*)doc;
69 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
70 _builder = new SALOMEDSImpl_StudyBuilder(this);
71 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
73 //Put on the root label a StudyHandle attribute to store the address of this object
74 //It will be used to retrieve the study object by DF_Label that belongs to the study
75 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
79 //============================================================================
80 /*! Function : ~SALOMEDSImpl_Study
81 * Purpose : SALOMEDSImpl_Study destructor
83 //============================================================================
84 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
88 delete _useCaseBuilder;
91 //============================================================================
92 /*! Function : GetPersistentReference
93 * Purpose : Get persistent reference of study (idem URL())
95 //============================================================================
96 std::string SALOMEDSImpl_Study::GetPersistentReference()
101 //============================================================================
102 /*! Function : GetTransientReference
103 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
105 //============================================================================
106 std::string SALOMEDSImpl_Study::GetTransientReference()
109 std::string IOR = "";
111 SALOMEDSImpl_AttributeIOR* Att;
112 DF_Label _lab = _doc->Root();
113 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
117 _errorCode = "IOR is empty";
123 void SALOMEDSImpl_Study::SetTransientReference(const std::string& theIOR)
127 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
128 int aLocked = aProp->IsLocked();
129 if (aLocked) aProp->SetLocked(false);
131 // Assign the value of the IOR in the study->root
132 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
134 if (aLocked) aProp->SetLocked(true);
137 //============================================================================
138 /*! Function : IsEmpty
139 * Purpose : Detect if study is empty
141 //============================================================================
142 bool SALOMEDSImpl_Study::IsEmpty()
145 if (!_doc) return true;
146 return _doc->IsEmpty();
149 //============================================================================
150 /*! Function : FindComponent
151 * Purpose : Find a Component with ComponentDataType = aComponentName
153 //============================================================================
154 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName)
159 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
160 SALOMEDSImpl_SComponent compo;
162 for (; itcomp.More(); itcomp.Next()) {
163 SALOMEDSImpl_SComponent SC = itcomp.Value();
164 name = SC.ComponentDataType();
165 if(aComponentName == name) {
173 _errorCode = "No component was found";
179 //============================================================================
180 /*! Function : FindComponentID
181 * Purpose : Find a Component from it's ID
183 //============================================================================
184 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID)
188 // Iterate on each components defined in the study
189 // Get the component ID and compare with aComponentID
192 SALOMEDSImpl_SComponent compo;
194 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
195 for (; itcomp.More(); itcomp.Next()) {
196 SALOMEDSImpl_SComponent SC = itcomp.Value();
198 if(aComponentID == ID)
207 _errorCode = "No component was found";
214 //============================================================================
215 /*! Function : FindObject
216 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
218 //============================================================================
219 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName)
223 // Iterate to all components defined in the study
224 // After testing the component name, iterate in all objects defined under
225 // components (function _FindObject)
227 SALOMEDSImpl_SObject RefSO;
229 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
230 for (; it.More();it.Next()){
233 SALOMEDSImpl_SComponent SC = it.Value();
234 if (SC.GetName() == anObjectName)
240 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
243 if(!RefSO) _errorCode = "No object was found";
247 //============================================================================
248 /*! Function : FindObjectID
249 * Purpose : Find an Object with ID = anObjectID
251 //============================================================================
252 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID)
255 SALOMEDSImpl_SObject so;
257 // Convert aSO->GetID in DF_Label.
258 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
261 _errorCode = "No label was found by ID";
264 return GetSObject(Lab);
268 //============================================================================
269 /*! Function : CreateObjectID
270 * Purpose : Creates an Object with ID = anObjectID
272 //============================================================================
273 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID)
276 SALOMEDSImpl_SObject so;
278 // Convert aSO->GetID in DF_Label.
279 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
282 _errorCode = "Can not create a label";
285 return GetSObject(Lab);
289 //============================================================================
290 /*! Function : FindObjectByName
291 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
292 * : with ComponentDataType = aComponentName
294 //============================================================================
295 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName,
296 const std::string& aComponentName)
300 std::vector<SALOMEDSImpl_SObject> listSO;
302 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
304 _errorCode = "Can not find the component";
308 // Iterate on each object and subobject of the component
309 // If objectName is found add it to the list of SObjects
310 std::string childName ;
312 std::string compoId = compo.GetID();
313 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
314 for ( ; it.More(); it.Next() ) {
316 SALOMEDSImpl_SObject CSO = it.Value();
317 if ( CSO.GetName() == anObjectName ) {
319 listSO.push_back(CSO) ;
322 /* looks also for eventual children */
324 CSO = _FindObject( CSO, anObjectName, found ) ;
326 listSO.push_back(CSO) ;
335 //============================================================================
336 /*! Function : FindObjectIOR
337 * Purpose : Find an Object with IOR = anObjectIOR
339 //============================================================================
340 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR)
344 SALOMEDSImpl_SObject aResult ;
346 // searching in the datamap for optimization
347 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anObjectIOR);
348 if (it != myIORLabels.end()) {
349 aResult = GetSObject(it->second);
350 // 11 oct 2002: forbidden attributes must be checked here
351 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
352 myIORLabels.erase(anObjectIOR);
353 aResult = SALOMEDSImpl_SObject();
357 if(!aResult) _errorCode = "No object was found";
361 //============================================================================
362 /*! Function : FindObjectByPath
363 * Purpose : Find an Object by its path = thePath
365 //============================================================================
366 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath)
370 std::string aPath(thePath), aToken;
371 SALOMEDSImpl_SObject aSO;
372 int aLength = aPath.size();
373 bool isRelative = false;
375 if(aLength == 0) { //Empty path - return the current context
376 return GetSObject(_current);
379 if(aPath[0] != '/') //Relative path
382 DF_ChildIterator anIterator;
384 SALOMEDSImpl_AttributeName* anAttr;
387 if(_current.IsNull()) return aSO;
388 anIterator.Init(_current, false);
391 if(aPath.size() == 1 && aPath[0] == '/') { //Root
392 return GetSObject(_doc->Main());
394 anIterator.Init(_doc->Main(), false);
397 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
398 for(int i = 0, len = vs.size(); i<len; i++) {
401 if(aToken.size() == 0) break;
403 for ( ; anIterator.More(); anIterator.Next() ) {
404 aLabel = anIterator.Value();
405 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
406 if(anAttr->Value() == aToken) {
407 if(i == (len-1)) { //The searched label is found (no part of the path is left)
408 return GetSObject(aLabel);
411 anIterator.Init(aLabel, false);
419 if(!aSO) _errorCode = "No object was found";
423 //============================================================================
424 /*! Function : GetObjectPath
427 //============================================================================
428 std::string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
432 std::string aPath("");
434 _errorCode = "Null object";
438 std::string aName = theObject.GetName();
439 if(!aName.empty() && aName != "" ) {
440 std::string aValue("/");
444 SALOMEDSImpl_SObject aFather = theObject.GetFather();
446 aName = aFather.GetName();
447 if(!aName.empty() && aName != "") {
448 aValue = GetObjectPath(aFather);
449 aPath = aValue + aPath;
458 //============================================================================
459 /*! Function : GetObjectPathByIOR
462 //============================================================================
463 std::string SALOMEDSImpl_Study::GetObjectPathByIOR(const std::string& theIOR)
468 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
470 _errorCode = "No SObject was found by IOR";
474 return GetObjectPath(so);
478 //============================================================================
479 /*! Function : SetContext
480 * Purpose : Sets the current context
482 //============================================================================
483 bool SALOMEDSImpl_Study::SetContext(const std::string& thePath)
486 if(thePath.empty()) {
487 _errorCode = "InvalidPath";
491 std::string aPath(thePath), aContext("");
492 bool isInvalid = false;
493 SALOMEDSImpl_SObject aSO;
495 if(aPath[0] != '/') { //Relative path
496 aContext = GetContext();
504 aSO = FindObjectByPath(aContext);
510 if(isInvalid || !aSO) {
511 _errorCode = "InvalidContext";
515 DF_Label aLabel = aSO.GetLabel();
516 if(aLabel.IsNull()) {
517 _errorCode = "InvalidContext";
521 _current = aLabel; //Set the current context
526 //============================================================================
527 /*! Function : GetContext
528 * Purpose : Gets the current context
530 //============================================================================
531 std::string SALOMEDSImpl_Study::GetContext()
535 if(_current.IsNull()) {
536 _errorCode = "InvaidContext";
539 SALOMEDSImpl_SObject so = GetSObject(_current);
540 return GetObjectPath(so);
543 //============================================================================
544 /*! Function : GetObjectNames
545 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
547 //============================================================================
548 std::vector<std::string> SALOMEDSImpl_Study::GetObjectNames(const std::string& theContext)
552 std::vector<std::string> aResultSeq;
554 if (theContext.empty()) {
557 DF_Label aTmp = _current;
558 SetContext(theContext);
562 if (aLabel.IsNull()) {
563 _errorCode = "InvalidContext";
567 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
568 for (; anIter.More(); anIter.Next()) {
569 DF_Label aLabel = anIter.Value();
570 SALOMEDSImpl_AttributeName* aName;
571 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
572 aResultSeq.push_back(aName->Value());
578 //============================================================================
579 /*! Function : GetDirectoryNames
580 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
582 //============================================================================
583 std::vector<std::string> SALOMEDSImpl_Study::GetDirectoryNames(const std::string& theContext)
587 std::vector<std::string> aResultSeq;
589 if (theContext.empty()) {
592 DF_Label aTmp = _current;
593 SetContext(theContext);
597 if (aLabel.IsNull()) {
598 _errorCode = "InvalidContext";
602 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
603 for (; anIter.More(); anIter.Next()) {
604 DF_Label aLabel = anIter.Value();
605 SALOMEDSImpl_AttributeLocalID* anID;
606 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
607 if (anID->Value() == DIRECTORYID) {
608 SALOMEDSImpl_AttributeName* aName;
609 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
610 aResultSeq.push_back(aName->Value());
619 //============================================================================
620 /*! Function : GetFileNames
621 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
623 //============================================================================
624 std::vector<std::string> SALOMEDSImpl_Study::GetFileNames(const std::string& theContext)
628 std::vector<std::string> aResultSeq;
630 if (theContext.empty()) {
633 DF_Label aTmp = _current;
634 SetContext(theContext);
638 if (aLabel.IsNull()) {
639 _errorCode = "InvalidContext";
643 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
644 for (; anIter.More(); anIter.Next()) {
645 DF_Label aLabel = anIter.Value();
646 SALOMEDSImpl_AttributeLocalID* anID;
647 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
648 if (anID->Value() == FILELOCALID) {
649 SALOMEDSImpl_AttributePersistentRef* aName;
650 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
651 std::string aFileName = aName->Value();
652 if (aFileName.size() > 0)
653 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
662 //============================================================================
663 /*! Function : GetComponentNames
664 * Purpose : method to get all components names
666 //============================================================================
667 std::vector<std::string> SALOMEDSImpl_Study::GetComponentNames(const std::string& theContext)
671 std::vector<std::string> aResultSeq;
672 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
673 for(; anIter.More(); anIter.Next()) {
674 DF_Label aLabel = anIter.Value();
675 SALOMEDSImpl_AttributeName* aName;
676 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
677 aResultSeq.push_back(aName->Value());
683 //============================================================================
684 /*! Function : NewChildIterator
685 * Purpose : Create a ChildIterator from an SObject
687 //============================================================================
688 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
691 return SALOMEDSImpl_ChildIterator(aSO);
695 //============================================================================
696 /*! Function : NewComponentIterator
697 * Purpose : Create a SComponentIterator
699 //============================================================================
700 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
703 return SALOMEDSImpl_SComponentIterator(_doc);
707 //============================================================================
708 /*! Function : NewBuilder
709 * Purpose : Create a StudyBuilder
711 //============================================================================
712 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
716 _builder->SetOnAddSObject(_cb);
717 _builder->SetOnRemoveSObject(_cb);
723 //============================================================================
725 * Purpose : get study name
727 //============================================================================
728 std::string SALOMEDSImpl_Study::Name()
734 //============================================================================
736 * Purpose : set study name
738 //============================================================================
739 void SALOMEDSImpl_Study::Name(const std::string& name)
745 //============================================================================
746 /*! Function : IsSaved
747 * Purpose : get if study has been saved
749 //============================================================================
750 bool SALOMEDSImpl_Study::IsSaved()
756 //============================================================================
757 /*! Function : IsSaved
758 * Purpose : set if study has been saved
760 //============================================================================
761 void SALOMEDSImpl_Study::IsSaved(bool save)
765 if(save) _doc->SetModified(false);
768 //============================================================================
769 /*! Function : IsModified
770 * Purpose : Detect if a Study has been modified since it has been saved
772 //============================================================================
773 bool SALOMEDSImpl_Study::IsModified()
777 // True if is modified
778 if (_doc && _doc->IsModified()) return true;
783 //============================================================================
785 * Purpose : get URL of the study (persistent reference of the study)
787 //============================================================================
788 std::string SALOMEDSImpl_Study::URL()
794 //============================================================================
796 * Purpose : set URL of the study (persistent reference of the study)
798 //============================================================================
799 void SALOMEDSImpl_Study::URL(const std::string& url)
804 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
805 std::string tmp(_URL);
807 char *aName = (char*)tmp.ToCString();
808 char *adr = strtok(aName, "/");
812 adr = strtok(NULL, "/");
819 //============================================================================
820 /*! Function : _FindObject
821 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
823 //============================================================================
824 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
825 const std::string& theObjectName,
828 SALOMEDSImpl_SObject RefSO;
829 if(!SO) return RefSO;
831 // Iterate on each objects and subobjects of the component
832 // If objectName find, stop the loop and get the object reference
833 SALOMEDSImpl_AttributeName* anAttr;
835 std::string soid = SO.GetID();
836 DF_ChildIterator it(SO.GetLabel());
837 for (; it.More(); it.Next()){
840 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
842 std::string Val(anAttr->Value());
843 if (Val == theObjectName)
845 RefSO = GetSObject(it.Value());
849 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
855 //============================================================================
856 /*! Function : _FindObjectIOR
857 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
859 //============================================================================
861 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
862 const std::string& theObjectIOR,
865 SALOMEDSImpl_SObject RefSO, aSO;
866 if(!SO) return RefSO;
868 // Iterate on each objects and subobjects of the component
869 // If objectName find, stop the loop and get the object reference
870 SALOMEDSImpl_AttributeIOR* anAttr;
872 DF_ChildIterator it(SO.GetLabel());
873 for (; it.More();it.Next()){
876 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
878 std::string Val(anAttr->Value());
879 if (Val == theObjectIOR)
881 RefSO = GetSObject(it.Value());
885 aSO = GetSObject(it.Value());
886 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
892 //============================================================================
893 /*! Function : _GetNoteBookAccessor
894 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
896 //============================================================================
897 std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
898 return std::string("notebook");
901 //============================================================================
902 /*! Function : _GetStudyVariablesScript
905 //============================================================================
906 std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
908 std::string dump("");
910 if(myNoteBookVars.empty())
913 Kernel_Utils::Localizer loc;
915 dump += "####################################################\n";
916 dump += "## Begin of NoteBook variables section ##\n";
917 dump += "####################################################\n";
919 std::string set_method = _GetNoteBookAccessor()+".set(";
921 std::string varValue;
922 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
923 varName = myNoteBookVars[i]->Name();
924 varValue = myNoteBookVars[i]->SaveToScript();
925 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
928 dump += "####################################################\n";
929 dump += "## End of NoteBook variables section ##\n";
930 dump += "####################################################\n";
935 //============================================================================
936 /*! Function : _GetNoteBookAccess
939 //============================================================================
940 std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
942 std::string accessor = _GetNoteBookAccessor();
943 std::string notebook = "import salome_notebook\n";
944 notebook += accessor+" = salome_notebook."+accessor + "\n";
948 bool SALOMEDSImpl_Study::IsLocked()
951 return GetProperties()->IsLocked();
954 int SALOMEDSImpl_Study::StudyId()
960 void SALOMEDSImpl_Study::StudyId(int id)
966 void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry)
969 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
970 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
971 if (it != myIORLabels.end()) myIORLabels.erase(it);
972 myIORLabels[anIOR] = aLabel;
975 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
977 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
978 if (it != myIORLabels.end())
980 //remove the ior entry and decref the genericobj (if it's one)
981 myIORLabels.erase(it);
985 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
987 SALOMEDSImpl_StudyHandle* Att;
988 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
994 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
996 return GetStudy(theLabel)->GetSObject(theLabel);
999 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
1001 return GetStudy(theLabel)->GetSComponent(theLabel);
1005 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1007 std::string aString = theAttribute->Label().Entry();
1008 GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1011 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1014 std::vector<SALOMEDSImpl_SObject> aSeq;
1016 SALOMEDSImpl_AttributeTarget* aTarget;
1017 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1018 return aTarget->Get();
1025 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1028 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1031 std::string SALOMEDSImpl_Study::GetLastModificationDate()
1034 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1036 std::vector<std::string> aNames;
1037 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1038 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1040 int aLastIndex = aNames.size()-1;
1042 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1043 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1044 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1045 std::string aResStr (aResult);
1049 std::vector<std::string> SALOMEDSImpl_Study::GetModificationsDate()
1052 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1054 std::vector<std::string> aNames;
1055 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1056 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1058 int anIndex, aLength = aNames.size();
1059 std::vector<std::string> aDates;
1061 for (anIndex = 1; anIndex < aLength; anIndex++) {
1063 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1064 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1065 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1066 aDates.push_back(aDate);
1073 //============================================================================
1074 /*! Function : GetUseCaseBuilder
1075 * Purpose : Returns a UseCase builder
1077 //============================================================================
1078 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1081 return _useCaseBuilder;
1085 //============================================================================
1086 /*! Function : Close
1089 //============================================================================
1090 void SALOMEDSImpl_Study::Close()
1093 _doc->GetApplication()->Close(_doc);
1100 //============================================================================
1101 /*! Function : GetSComponent
1104 //============================================================================
1105 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry)
1107 SALOMEDSImpl_SComponent aSCO;
1108 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1109 aSCO = _mapOfSCO[theEntry];
1111 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1112 aSCO = SALOMEDSImpl_SComponent(aLabel);
1113 _mapOfSCO[theEntry] = aSCO;
1119 //============================================================================
1120 /*! Function : GetSComponent
1123 //============================================================================
1124 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1126 return SALOMEDSImpl_SComponent(theLabel);
1129 //============================================================================
1130 /*! Function : GetSObject
1133 //============================================================================
1134 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry)
1136 SALOMEDSImpl_SObject aSO;
1137 std::map<std::string, SALOMEDSImpl_SObject>::iterator it=_mapOfSO.find(theEntry);
1138 if(it != _mapOfSO.end())
1141 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1142 aSO = SALOMEDSImpl_SObject(aLabel);
1143 _mapOfSO[theEntry] = aSO;
1149 //============================================================================
1150 /*! Function : GetSObject
1153 //============================================================================
1154 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1156 return SALOMEDSImpl_SObject(theLabel);
1159 //============================================================================
1160 /*! Function : GetAttribute
1163 //============================================================================
1164 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry,
1165 const std::string& theType)
1167 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1168 DF_Attribute* anAttr;
1169 aSO.FindAttribute(anAttr, theType);
1173 //============================================================================
1174 /*! Function : DumpStudy
1177 //============================================================================
1178 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
1179 const std::string& theBaseName,
1181 SALOMEDSImpl_DriverFactory* theFactory)
1185 if(theFactory == NULL) {
1186 _errorCode = "Null factory for creation of Engines";
1190 std::vector<std::string> aSeq;
1191 std::string aCompType, aFactoryType;
1193 //Build a list of all components in the Study
1194 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1196 for (; itcomponent.More(); itcomponent.Next()) {
1197 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1198 aCompType = sco.ComponentDataType();
1199 //GEOM and MED are independent components
1200 if (aCompType == "GEOM" || aCompType == "MED")
1201 aSeq.insert(aSeq.begin(), aCompType);
1203 aSeq.push_back(aCompType);
1207 std::string aFileName =
1208 thePath + std::string("\\") + theBaseName + std::string(".py");
1210 std::string aFileName =
1211 thePath + std::string("/") + theBaseName + std::string(".py");
1214 //Create a file that will contain a main Study script
1216 fp.open(aFileName.c_str(), std::ios::out);
1219 bool isOpened = fp.is_open();
1221 bool isOpened = fp.rdbuf()->is_open();
1225 _errorCode = std::string("Can't create a file ")+aFileName;
1229 std::string aBatchModeScript = "salome";
1231 //Output to the main Study script required Python modules import,
1232 //set sys.path and add a creation of the study.
1235 fp << GetDumpStudyComment() << std::endl;
1238 fp << "import sys" << std::endl;
1239 fp << "import " << aBatchModeScript << std::endl << std::endl;
1241 // initialization function
1242 fp << aBatchModeScript << ".salome_init()" << std::endl << std::endl;
1244 // notebook initialization
1245 fp << _GetNoteBookAccess();
1247 // extend sys.path with the directory where the script is being dumped to
1248 fp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
1250 // dump NoteBook variables
1251 fp << _GetStudyVariablesScript();
1253 // dump visual parameters if necessary
1254 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1255 int lastSavePoint = -1;
1257 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1258 if(lastSavePoint > 0) {
1259 fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
1263 std::vector<std::string> aSeqOfFileNames;
1265 // dump all components and create the components specific scripts
1267 int aLength = aSeq.size();
1268 for(int i = 1; i <= aLength; i++) {
1270 aCompType = aSeq[i-1];
1271 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1272 SALOMEDSImpl_Driver* aDriver = NULL;
1273 // if there is an associated Engine call its method for saving
1274 std::string IOREngine;
1276 if (!sco.ComponentIOR(IOREngine)) {
1277 if (!aCompType.empty()) {
1279 aDriver = theFactory->GetDriverByType(aCompType);
1281 if (aDriver != NULL) {
1282 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1283 if(!SB->LoadWith(sco, aDriver)) {
1284 _errorCode = SB->GetErrorCode();
1292 aDriver = theFactory->GetDriverByIOR(IOREngine);
1295 _errorCode = "Can not restore information to dump it";
1299 if(aDriver == NULL) continue;
1302 long aStreamLength = 0;
1303 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
1304 if ( !isValidScript )
1307 //Create a file that will contain the component specific script
1310 aFileName=thePath+std::string("\\");
1312 aFileName=thePath+std::string("/");
1314 std::string aScriptName;
1315 aScriptName += theBaseName;
1317 aScriptName += aCompType;
1319 aFileName += aScriptName+ std::string(".py");
1320 aSeqOfFileNames.push_back(aFileName);
1322 fp2.open(aFileName.c_str(), std::ios::out);
1325 isOpened = fp2.is_open();
1327 isOpened = fp2.rdbuf()->is_open();
1331 _errorCode = std::string("Can't create a file ")+aFileName;
1332 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1336 //Output the Python script generated by the component in the newly created file.
1337 fp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
1338 fp2 << aStream->Data();
1341 if(aStream) delete aStream;
1343 //Add to the main script a call to RebuildData of the generated by the component the Python script
1344 fp << "import " << aScriptName << std::endl;
1345 fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
1349 fp << "if salome.sg.hasDesktop():" << std::endl;
1350 fp << "\tsalome.sg.updateObjBrowser(1)" << std::endl;
1352 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1353 fp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
1361 //=======================================================================
1362 //function : GetDumpStudyComment
1363 //purpose : return a header comment for a DumpStudy script
1364 //=======================================================================
1366 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1368 std::stringstream txt;
1369 txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl;
1370 txt << "###" << std::endl;
1371 txt << "### This file is generated automatically by SALOME v"
1372 << KERNEL_VERSION_STR
1373 << " with dump python functionality";
1374 if ( theComponentName )
1375 txt << " (" << theComponentName << " component)";
1377 txt << "###" << std::endl;
1381 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1383 const std::string& Tab,
1384 SALOMEDSImpl_Study* theStudy);
1386 //============================================================================
1390 //============================================================================
1391 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
1393 //Create a file that will contain a main Study script
1395 fp.open(theFileName.c_str(), std::ios::out);
1398 bool isOpened = fp.is_open();
1400 bool isOpened = fp.rdbuf()->is_open();
1404 _errorCode = std::string("Can't create a file ")+theFileName;
1405 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
1409 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1410 fp << "0:1" << std::endl;
1411 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1412 std::string aTab(" ");
1413 for(; Itr.More(); Itr.Next()) {
1414 dumpSO(Itr.Value(), fp, aTab, this);
1421 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1423 const std::string& Tab,
1424 SALOMEDSImpl_Study* theStudy)
1426 std::string aTab(Tab), anID(theSO.GetID());
1427 fp << aTab << anID << std::endl;
1428 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1429 for(int i = 0; i<attribs.size(); i++) {
1430 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1436 std::string aType = anAttr->GetClassType();
1437 fp << Tab << " -- " << aType;
1439 if(aType == std::string("AttributeReal")) {
1440 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1442 else if(aType == std::string("AttributeInteger")) {
1443 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1445 else if(aType == std::string("AttributeName")) {
1446 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1448 else if(aType == std::string("AttributeComment")) {
1449 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1451 else if(aType == std::string("AttributeReference")) {
1452 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1457 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1458 std::string aNewTab(" ");
1460 for(; Itr.More(); Itr.Next()) {
1461 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1467 void SALOMEDSImpl_Study::Modify()
1470 _doc->SetModified(true);
1473 //============================================================================
1477 //============================================================================
1478 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1480 if (theSavePoint < 0) return NULL;
1481 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1482 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1483 if (!so) so = builder->NewComponent((char*)theID);
1484 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1486 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1487 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1488 if ( !savePointLabel.IsNull() )
1489 so = GetSObject( savePointLabel );
1490 else // ... if it does not exist - create a new one
1491 so = builder->NewObjectToTag( so, theSavePoint );
1496 builder->FindAttribute(so, A, "AttributeParameter");
1497 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1498 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1500 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1505 //============================================================================
1509 //============================================================================
1510 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1511 const char* theModuleName,
1514 if(theSavePoint <= 0) return NULL;
1515 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1516 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1517 SALOMEDSImpl_AttributeParameter* par = NULL;
1519 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1520 std::string moduleName(theModuleName);
1521 for(; it.More(); it.Next()) {
1522 SALOMEDSImpl_SObject so(it.Value());
1523 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1524 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1525 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1529 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1530 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1531 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1532 par->SetString("AP_MODULE_NAME", moduleName);
1536 //============================================================================
1537 /*! Function : SetStudyLock
1540 //============================================================================
1541 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1543 _lockers.push_back(theLockerID);
1546 //============================================================================
1547 /*! Function : IsStudyLocked
1550 //============================================================================
1551 bool SALOMEDSImpl_Study::IsStudyLocked()
1553 return (_lockers.size() > 0);
1556 //============================================================================
1557 /*! Function : UnLockStudy
1560 //============================================================================
1561 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1563 std::vector<std::string>::iterator vsI = _lockers.begin();
1564 int length = _lockers.size();
1565 bool isFound = false;
1566 std::string id(theLockerID);
1567 for(int i = 0; i<length; i++, vsI++) {
1568 if(id == _lockers[i]) {
1573 if(isFound) _lockers.erase(vsI);
1576 //============================================================================
1577 /*! Function : GetLockerID
1580 //============================================================================
1581 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
1586 //============================================================================
1587 /*! Function : SetVariable
1590 //============================================================================
1591 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
1592 const double theValue,
1593 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1595 bool modified = false;
1596 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1598 if( aGVar == NULL ) {
1600 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1602 aSVar->setValue(theValue);
1603 myNoteBookVars.push_back(aSVar);
1607 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1608 modified = aSVar->setValue(theValue) || modified;
1609 modified = aSVar->setType(theType) || modified;
1616 //============================================================================
1617 /*! Function : SetStringVariable
1620 //============================================================================
1621 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
1622 const std::string& theValue,
1623 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1625 bool modified = false;
1626 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1628 if( aGVar == NULL ) {
1630 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1632 aSVar->setStringValue(theValue);
1633 myNoteBookVars.push_back(aSVar);
1637 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1638 modified = aSVar->setStringValue(theValue) || modified;
1639 modified = aSVar->setType(theType) || modified;
1646 //============================================================================
1647 /*! Function : SetStringVariableAsDouble
1650 //============================================================================
1651 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
1652 const double theValue,
1653 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1655 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1656 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1657 aSVar->setValue(theValue);
1660 //============================================================================
1661 /*! Function : GetReal
1664 //============================================================================
1665 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
1667 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1670 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1671 return aSVar->getValue();
1676 //============================================================================
1677 /*! Function : GetString
1680 //============================================================================
1681 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
1683 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1686 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1687 return aSVar->getStringValue();
1692 //============================================================================
1693 /*! Function : IsTypeOf
1696 //============================================================================
1697 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
1698 SALOMEDSImpl_GenericVariable::
1699 VariableTypes theType) const
1701 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1704 return aGVar->Type() == theType;
1709 //============================================================================
1710 /*! Function : IsVariable
1713 //============================================================================
1714 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
1716 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1717 return (aGVar != NULL);
1720 //============================================================================
1721 /*! Function : GetVariableNames
1724 //============================================================================
1725 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
1727 std::vector<std::string> aResult;
1729 for(int i = 0; i < myNoteBookVars.size(); i++)
1730 aResult.push_back(myNoteBookVars[i]->Name());
1735 //============================================================================
1736 /*! Function : AddVariable
1739 //============================================================================
1740 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1742 myNoteBookVars.push_back(theVariable);
1745 //============================================================================
1746 /*! Function : AddVariable
1749 //============================================================================
1750 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1752 SALOMEDSImpl_GenericVariable* aResult = NULL;
1753 for(int i = 0; i < myNoteBookVars.size();i++) {
1754 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1755 aResult = myNoteBookVars[i];
1762 //============================================================================
1763 /*! Function : RemoveVariable
1766 //============================================================================
1767 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
1769 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1773 std::string aValue = aVariable->SaveToScript();
1774 ReplaceVariableAttribute( theVarName, aValue );
1776 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1777 for( ; it != itEnd; it++ )
1779 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1780 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1782 myNoteBookVars.erase( it );
1791 //============================================================================
1792 /*! Function : RenameVariable
1795 //============================================================================
1796 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
1798 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1802 ReplaceVariableAttribute( theVarName, theNewVarName );
1804 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1805 for( ; it != itEnd; it++ )
1807 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1808 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1810 aVariableRef->setName( theNewVarName );
1819 //============================================================================
1820 /*! Function : IsVariableUsed
1823 //============================================================================
1824 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
1826 return FindVariableAttribute( theVarName );
1829 //============================================================================
1830 /*! Function : FindVariableAttribute
1833 //============================================================================
1834 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1835 SALOMEDSImpl_SObject theSObject,
1836 const std::string& theName)
1838 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1839 for( ; anIter.More(); anIter.Next() )
1840 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1843 DF_Attribute* anAttr;
1844 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1846 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1848 std::string aString = aStringAttr->Value();
1850 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
1851 for( int i = 0, n = aSections.size(); i < n; i++ )
1853 std::vector<std::string> aVector = aSections[i];
1854 for( int j = 0, m = aVector.size(); j < m; j++ )
1856 std::string aStr = aVector[j];
1857 if( aStr.compare( theName ) == 0 )
1866 //============================================================================
1867 /*! Function : FindVariableAttribute
1870 //============================================================================
1871 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1873 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1874 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1875 for( ; aCompIter.More(); aCompIter.Next() )
1877 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1878 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1884 //============================================================================
1885 /*! Function : ReplaceVariableAttribute
1888 //============================================================================
1889 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1890 SALOMEDSImpl_SObject theSObject,
1891 const std::string& theSource,
1892 const std::string& theDest)
1894 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1895 for( ; anIter.More(); anIter.Next() )
1896 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1898 DF_Attribute* anAttr;
1899 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1901 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1903 bool isChanged = false;
1904 std::string aNewString, aCurrentString = aStringAttr->Value();
1906 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
1907 for( int i = 0, n = aSections.size(); i < n; i++ )
1909 std::vector<std::string> aVector = aSections[i];
1910 for( int j = 0, m = aVector.size(); j < m; j++ )
1912 std::string aStr = aVector[j];
1913 if( aStr.compare( theSource ) == 0 )
1919 aNewString.append( aStr );
1921 aNewString.append( ":" );
1924 aNewString.append( "|" );
1928 aStringAttr->SetValue( aNewString );
1933 //============================================================================
1934 /*! Function : ReplaceVariableAttribute
1937 //============================================================================
1938 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
1940 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1941 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1942 for( ; aCompIter.More(); aCompIter.Next() )
1944 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1945 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
1949 //============================================================================
1950 /*! Function : ParseVariables
1953 //============================================================================
1954 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
1956 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
1959 //============================================================================
1960 /*! Function : EnableUseCaseAutoFilling
1963 //============================================================================
1964 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
1966 _errorCode = ""; _autoFill = isEnabled;
1968 _builder->SetOnAddSObject(_cb);
1969 _builder->SetOnRemoveSObject(_cb);
1972 _builder->SetOnAddSObject(NULL);
1973 _builder->SetOnRemoveSObject(NULL);
1977 //============================================================================
1978 /*! Function : GetIORs
1981 //============================================================================
1982 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
1984 std::vector<std::string> anIORs;
1985 std::map<std::string, DF_Label>::const_iterator MI;
1986 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
1987 anIORs.push_back(MI->first);
1992 //============================================================================
1993 /*! Function : addSO_Notification
1994 * Purpose : This function tells all the observers that a SO has been added
1996 //============================================================================
1997 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2000 return _notifier->addSO_Notification(theSObject);
2005 //============================================================================
2006 /*! Function : removeSO_Notification
2007 * Purpose : This function tells all the observers that a SO has been removed
2009 //============================================================================
2010 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2013 return _notifier->removeSO_Notification(theSObject);
2018 //============================================================================
2019 /*! Function : modifySO_Notification
2020 * Purpose : This function tells all the observers that a SO has been modified and
2021 pass the mofification reason
2023 //============================================================================
2024 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
2027 return _notifier->modifySO_Notification(theSObject, reason);
2032 //============================================================================
2033 /*! Function : setNotifier
2034 * Purpose : register a notifier
2036 //============================================================================
2037 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)