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 // comment out the following define to enable \t symbols in in the python dump files
51 #define DIRECTORYID 16661
52 #define FILELOCALID 26662
53 #define FILEID "FILE: "
54 #define VARIABLE_SEPARATOR ':'
55 #define OPERATION_SEPARATOR '|'
57 //============================================================================
58 /*! Function : SALOMEDSImpl_Study
59 * Purpose : SALOMEDSImpl_Study constructor
61 //============================================================================
62 SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
63 const std::string& study_name)
66 _doc = (DF_Document*)doc;
72 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
73 _builder = new SALOMEDSImpl_StudyBuilder(this);
74 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
76 //Put on the root label a StudyHandle attribute to store the address of this object
77 //It will be used to retrieve the study object by DF_Label that belongs to the study
78 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
82 //============================================================================
83 /*! Function : ~SALOMEDSImpl_Study
84 * Purpose : SALOMEDSImpl_Study destructor
86 //============================================================================
87 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
91 delete _useCaseBuilder;
94 //============================================================================
95 /*! Function : GetPersistentReference
96 * Purpose : Get persistent reference of study (idem URL())
98 //============================================================================
99 std::string SALOMEDSImpl_Study::GetPersistentReference()
104 //============================================================================
105 /*! Function : GetTransientReference
106 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
108 //============================================================================
109 std::string SALOMEDSImpl_Study::GetTransientReference()
112 std::string IOR = "";
114 SALOMEDSImpl_AttributeIOR* Att;
115 DF_Label _lab = _doc->Root();
116 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
120 _errorCode = "IOR is empty";
126 void SALOMEDSImpl_Study::SetTransientReference(const std::string& theIOR)
130 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
131 int aLocked = aProp->IsLocked();
132 if (aLocked) aProp->SetLocked(false);
134 // Assign the value of the IOR in the study->root
135 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
137 if (aLocked) aProp->SetLocked(true);
140 //============================================================================
141 /*! Function : IsEmpty
142 * Purpose : Detect if study is empty
144 //============================================================================
145 bool SALOMEDSImpl_Study::IsEmpty()
148 if (!_doc) return true;
149 return _doc->IsEmpty();
152 //============================================================================
153 /*! Function : FindComponent
154 * Purpose : Find a Component with ComponentDataType = aComponentName
156 //============================================================================
157 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName)
162 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
163 SALOMEDSImpl_SComponent compo;
165 for (; itcomp.More(); itcomp.Next()) {
166 SALOMEDSImpl_SComponent SC = itcomp.Value();
167 name = SC.ComponentDataType();
168 if(aComponentName == name) {
176 _errorCode = "No component was found";
182 //============================================================================
183 /*! Function : FindComponentID
184 * Purpose : Find a Component from it's ID
186 //============================================================================
187 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID)
191 // Iterate on each components defined in the study
192 // Get the component ID and compare with aComponentID
195 SALOMEDSImpl_SComponent compo;
197 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
198 for (; itcomp.More(); itcomp.Next()) {
199 SALOMEDSImpl_SComponent SC = itcomp.Value();
201 if(aComponentID == ID)
210 _errorCode = "No component was found";
217 //============================================================================
218 /*! Function : FindObject
219 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
221 //============================================================================
222 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName)
226 // Iterate to all components defined in the study
227 // After testing the component name, iterate in all objects defined under
228 // components (function _FindObject)
230 SALOMEDSImpl_SObject RefSO;
232 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
233 for (; it.More();it.Next()){
236 SALOMEDSImpl_SComponent SC = it.Value();
237 if (SC.GetName() == anObjectName)
243 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
246 if(!RefSO) _errorCode = "No object was found";
250 //============================================================================
251 /*! Function : FindObjectID
252 * Purpose : Find an Object with ID = anObjectID
254 //============================================================================
255 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID)
258 SALOMEDSImpl_SObject so;
260 // Convert aSO->GetID in DF_Label.
261 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
264 _errorCode = "No label was found by ID";
267 return GetSObject(Lab);
271 //============================================================================
272 /*! Function : CreateObjectID
273 * Purpose : Creates an Object with ID = anObjectID
275 //============================================================================
276 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID)
279 SALOMEDSImpl_SObject so;
281 // Convert aSO->GetID in DF_Label.
282 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
285 _errorCode = "Can not create a label";
288 return GetSObject(Lab);
292 //============================================================================
293 /*! Function : FindObjectByName
294 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
295 * : with ComponentDataType = aComponentName
297 //============================================================================
298 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName,
299 const std::string& aComponentName)
303 std::vector<SALOMEDSImpl_SObject> listSO;
305 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
307 _errorCode = "Can not find the component";
311 // Iterate on each object and subobject of the component
312 // If objectName is found add it to the list of SObjects
313 std::string childName ;
315 std::string compoId = compo.GetID();
316 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
317 for ( ; it.More(); it.Next() ) {
319 SALOMEDSImpl_SObject CSO = it.Value();
320 if ( CSO.GetName() == anObjectName ) {
322 listSO.push_back(CSO) ;
325 /* looks also for eventual children */
327 CSO = _FindObject( CSO, anObjectName, found ) ;
329 listSO.push_back(CSO) ;
338 //============================================================================
339 /*! Function : FindObjectIOR
340 * Purpose : Find an Object with IOR = anObjectIOR
342 //============================================================================
343 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR)
347 SALOMEDSImpl_SObject aResult ;
349 // searching in the datamap for optimization
350 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anObjectIOR);
351 if (it != myIORLabels.end()) {
352 aResult = GetSObject(it->second);
353 // 11 oct 2002: forbidden attributes must be checked here
354 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
355 myIORLabels.erase(anObjectIOR);
356 aResult = SALOMEDSImpl_SObject();
360 if(!aResult) _errorCode = "No object was found";
364 //============================================================================
365 /*! Function : FindObjectByPath
366 * Purpose : Find an Object by its path = thePath
368 //============================================================================
369 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath)
373 std::string aPath(thePath), aToken;
374 SALOMEDSImpl_SObject aSO;
375 int aLength = aPath.size();
376 bool isRelative = false;
378 if(aLength == 0) { //Empty path - return the current context
379 return GetSObject(_current);
382 if(aPath[0] != '/') //Relative path
385 DF_ChildIterator anIterator;
387 SALOMEDSImpl_AttributeName* anAttr;
390 if(_current.IsNull()) return aSO;
391 anIterator.Init(_current, false);
394 if(aPath.size() == 1 && aPath[0] == '/') { //Root
395 return GetSObject(_doc->Main());
397 anIterator.Init(_doc->Main(), false);
400 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
401 for(int i = 0, len = vs.size(); i<len; i++) {
404 if(aToken.size() == 0) break;
406 for ( ; anIterator.More(); anIterator.Next() ) {
407 aLabel = anIterator.Value();
408 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
409 if(anAttr->Value() == aToken) {
410 if(i == (len-1)) { //The searched label is found (no part of the path is left)
411 return GetSObject(aLabel);
414 anIterator.Init(aLabel, false);
422 if(!aSO) _errorCode = "No object was found";
426 //============================================================================
427 /*! Function : GetObjectPath
430 //============================================================================
431 std::string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
435 std::string aPath("");
437 _errorCode = "Null object";
441 std::string aName = theObject.GetName();
442 if(!aName.empty() && aName != "" ) {
443 std::string aValue("/");
447 SALOMEDSImpl_SObject aFather = theObject.GetFather();
449 aName = aFather.GetName();
450 if(!aName.empty() && aName != "") {
451 aValue = GetObjectPath(aFather);
452 aPath = aValue + aPath;
461 //============================================================================
462 /*! Function : GetObjectPathByIOR
465 //============================================================================
466 std::string SALOMEDSImpl_Study::GetObjectPathByIOR(const std::string& theIOR)
471 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
473 _errorCode = "No SObject was found by IOR";
477 return GetObjectPath(so);
481 //============================================================================
482 /*! Function : SetContext
483 * Purpose : Sets the current context
485 //============================================================================
486 bool SALOMEDSImpl_Study::SetContext(const std::string& thePath)
489 if(thePath.empty()) {
490 _errorCode = "InvalidPath";
494 std::string aPath(thePath), aContext("");
495 bool isInvalid = false;
496 SALOMEDSImpl_SObject aSO;
498 if(aPath[0] != '/') { //Relative path
499 aContext = GetContext();
507 aSO = FindObjectByPath(aContext);
513 if(isInvalid || !aSO) {
514 _errorCode = "InvalidContext";
518 DF_Label aLabel = aSO.GetLabel();
519 if(aLabel.IsNull()) {
520 _errorCode = "InvalidContext";
524 _current = aLabel; //Set the current context
529 //============================================================================
530 /*! Function : GetContext
531 * Purpose : Gets the current context
533 //============================================================================
534 std::string SALOMEDSImpl_Study::GetContext()
538 if(_current.IsNull()) {
539 _errorCode = "InvaidContext";
542 SALOMEDSImpl_SObject so = GetSObject(_current);
543 return GetObjectPath(so);
546 //============================================================================
547 /*! Function : GetObjectNames
548 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
550 //============================================================================
551 std::vector<std::string> SALOMEDSImpl_Study::GetObjectNames(const std::string& theContext)
555 std::vector<std::string> aResultSeq;
557 if (theContext.empty()) {
560 DF_Label aTmp = _current;
561 SetContext(theContext);
565 if (aLabel.IsNull()) {
566 _errorCode = "InvalidContext";
570 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
571 for (; anIter.More(); anIter.Next()) {
572 DF_Label aLabel = anIter.Value();
573 SALOMEDSImpl_AttributeName* aName;
574 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
575 aResultSeq.push_back(aName->Value());
581 //============================================================================
582 /*! Function : GetDirectoryNames
583 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
585 //============================================================================
586 std::vector<std::string> SALOMEDSImpl_Study::GetDirectoryNames(const std::string& theContext)
590 std::vector<std::string> aResultSeq;
592 if (theContext.empty()) {
595 DF_Label aTmp = _current;
596 SetContext(theContext);
600 if (aLabel.IsNull()) {
601 _errorCode = "InvalidContext";
605 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
606 for (; anIter.More(); anIter.Next()) {
607 DF_Label aLabel = anIter.Value();
608 SALOMEDSImpl_AttributeLocalID* anID;
609 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
610 if (anID->Value() == DIRECTORYID) {
611 SALOMEDSImpl_AttributeName* aName;
612 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
613 aResultSeq.push_back(aName->Value());
622 //============================================================================
623 /*! Function : GetFileNames
624 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
626 //============================================================================
627 std::vector<std::string> SALOMEDSImpl_Study::GetFileNames(const std::string& theContext)
631 std::vector<std::string> aResultSeq;
633 if (theContext.empty()) {
636 DF_Label aTmp = _current;
637 SetContext(theContext);
641 if (aLabel.IsNull()) {
642 _errorCode = "InvalidContext";
646 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
647 for (; anIter.More(); anIter.Next()) {
648 DF_Label aLabel = anIter.Value();
649 SALOMEDSImpl_AttributeLocalID* anID;
650 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
651 if (anID->Value() == FILELOCALID) {
652 SALOMEDSImpl_AttributePersistentRef* aName;
653 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
654 std::string aFileName = aName->Value();
655 if (aFileName.size() > 0)
656 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
665 //============================================================================
666 /*! Function : GetComponentNames
667 * Purpose : method to get all components names
669 //============================================================================
670 std::vector<std::string> SALOMEDSImpl_Study::GetComponentNames(const std::string& theContext)
674 std::vector<std::string> aResultSeq;
675 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
676 for(; anIter.More(); anIter.Next()) {
677 DF_Label aLabel = anIter.Value();
678 SALOMEDSImpl_AttributeName* aName;
679 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
680 aResultSeq.push_back(aName->Value());
686 //============================================================================
687 /*! Function : NewChildIterator
688 * Purpose : Create a ChildIterator from an SObject
690 //============================================================================
691 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
694 return SALOMEDSImpl_ChildIterator(aSO);
698 //============================================================================
699 /*! Function : NewComponentIterator
700 * Purpose : Create a SComponentIterator
702 //============================================================================
703 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
706 return SALOMEDSImpl_SComponentIterator(_doc);
710 //============================================================================
711 /*! Function : NewBuilder
712 * Purpose : Create a StudyBuilder
714 //============================================================================
715 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
719 _builder->SetOnAddSObject(_cb);
720 _builder->SetOnRemoveSObject(_cb);
726 //============================================================================
728 * Purpose : get study name
730 //============================================================================
731 std::string SALOMEDSImpl_Study::Name()
737 //============================================================================
739 * Purpose : set study name
741 //============================================================================
742 void SALOMEDSImpl_Study::Name(const std::string& name)
748 //============================================================================
749 /*! Function : IsSaved
750 * Purpose : get if study has been saved
752 //============================================================================
753 bool SALOMEDSImpl_Study::IsSaved()
759 //============================================================================
760 /*! Function : IsSaved
761 * Purpose : set if study has been saved
763 //============================================================================
764 void SALOMEDSImpl_Study::IsSaved(bool save)
768 if(save) _doc->SetModified(false);
771 //============================================================================
772 /*! Function : IsModified
773 * Purpose : Detect if a Study has been modified since it has been saved
775 //============================================================================
776 bool SALOMEDSImpl_Study::IsModified()
780 // True if is modified
781 if (_doc && _doc->IsModified()) return true;
786 //============================================================================
788 * Purpose : get URL of the study (persistent reference of the study)
790 //============================================================================
791 std::string SALOMEDSImpl_Study::URL()
797 //============================================================================
799 * Purpose : set URL of the study (persistent reference of the study)
801 //============================================================================
802 void SALOMEDSImpl_Study::URL(const std::string& url)
807 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
808 std::string tmp(_URL);
810 char *aName = (char*)tmp.ToCString();
811 char *adr = strtok(aName, "/");
815 adr = strtok(NULL, "/");
822 //============================================================================
823 /*! Function : _FindObject
824 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
826 //============================================================================
827 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
828 const std::string& theObjectName,
831 SALOMEDSImpl_SObject RefSO;
832 if(!SO) return RefSO;
834 // Iterate on each objects and subobjects of the component
835 // If objectName find, stop the loop and get the object reference
836 SALOMEDSImpl_AttributeName* anAttr;
838 std::string soid = SO.GetID();
839 DF_ChildIterator it(SO.GetLabel());
840 for (; it.More(); it.Next()){
843 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
845 std::string Val(anAttr->Value());
846 if (Val == theObjectName)
848 RefSO = GetSObject(it.Value());
852 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
858 //============================================================================
859 /*! Function : _FindObjectIOR
860 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
862 //============================================================================
864 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
865 const std::string& theObjectIOR,
868 SALOMEDSImpl_SObject RefSO, aSO;
869 if(!SO) return RefSO;
871 // Iterate on each objects and subobjects of the component
872 // If objectName find, stop the loop and get the object reference
873 SALOMEDSImpl_AttributeIOR* anAttr;
875 DF_ChildIterator it(SO.GetLabel());
876 for (; it.More();it.Next()){
879 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
881 std::string Val(anAttr->Value());
882 if (Val == theObjectIOR)
884 RefSO = GetSObject(it.Value());
888 aSO = GetSObject(it.Value());
889 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
895 //============================================================================
896 /*! Function : _GetNoteBookAccessor
897 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
899 //============================================================================
900 std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
901 return std::string("notebook");
904 //============================================================================
905 /*! Function : _GetStudyVariablesScript
908 //============================================================================
909 std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
911 std::string dump("");
913 if(myNoteBookVars.empty())
916 Kernel_Utils::Localizer loc;
918 dump += "####################################################\n";
919 dump += "## Begin of NoteBook variables section ##\n";
920 dump += "####################################################\n";
922 std::string set_method = _GetNoteBookAccessor()+".set(";
924 std::string varValue;
925 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
926 varName = myNoteBookVars[i]->Name();
927 varValue = myNoteBookVars[i]->SaveToScript();
928 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
931 dump += "####################################################\n";
932 dump += "## End of NoteBook variables section ##\n";
933 dump += "####################################################\n";
938 //============================================================================
939 /*! Function : _GetNoteBookAccess
942 //============================================================================
943 std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
945 std::string accessor = _GetNoteBookAccessor();
946 std::string notebook = "import salome_notebook\n";
947 notebook += accessor+" = salome_notebook."+accessor + "\n";
951 bool SALOMEDSImpl_Study::IsLocked()
954 return GetProperties()->IsLocked();
957 int SALOMEDSImpl_Study::StudyId()
963 void SALOMEDSImpl_Study::StudyId(int id)
969 void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry)
972 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
973 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
974 if (it != myIORLabels.end()) myIORLabels.erase(it);
975 myIORLabels[anIOR] = aLabel;
978 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
980 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anIOR);
981 if (it != myIORLabels.end())
983 //remove the ior entry and decref the genericobj (if it's one)
984 myIORLabels.erase(it);
988 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
990 SALOMEDSImpl_StudyHandle* Att;
991 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
997 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
999 return GetStudy(theLabel)->GetSObject(theLabel);
1002 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
1004 return GetStudy(theLabel)->GetSComponent(theLabel);
1008 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1010 std::string aString = theAttribute->Label().Entry();
1011 GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1014 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1017 std::vector<SALOMEDSImpl_SObject> aSeq;
1019 SALOMEDSImpl_AttributeTarget* aTarget;
1020 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1021 return aTarget->Get();
1028 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1031 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1034 std::string SALOMEDSImpl_Study::GetLastModificationDate()
1037 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1039 std::vector<std::string> aNames;
1040 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1041 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1043 int aLastIndex = aNames.size()-1;
1045 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1046 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1047 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1048 std::string aResStr (aResult);
1052 std::vector<std::string> SALOMEDSImpl_Study::GetModificationsDate()
1055 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1057 std::vector<std::string> aNames;
1058 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1059 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1061 int anIndex, aLength = aNames.size();
1062 std::vector<std::string> aDates;
1064 for (anIndex = 1; anIndex < aLength; anIndex++) {
1066 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1067 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1068 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1069 aDates.push_back(aDate);
1076 //============================================================================
1077 /*! Function : GetUseCaseBuilder
1078 * Purpose : Returns a UseCase builder
1080 //============================================================================
1081 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1084 return _useCaseBuilder;
1088 //============================================================================
1089 /*! Function : Close
1092 //============================================================================
1093 void SALOMEDSImpl_Study::Close()
1096 _doc->GetApplication()->Close(_doc);
1103 //============================================================================
1104 /*! Function : GetSComponent
1107 //============================================================================
1108 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry)
1110 SALOMEDSImpl_SComponent aSCO;
1111 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1112 aSCO = _mapOfSCO[theEntry];
1114 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1115 aSCO = SALOMEDSImpl_SComponent(aLabel);
1116 _mapOfSCO[theEntry] = aSCO;
1122 //============================================================================
1123 /*! Function : GetSComponent
1126 //============================================================================
1127 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1129 return SALOMEDSImpl_SComponent(theLabel);
1132 //============================================================================
1133 /*! Function : GetSObject
1136 //============================================================================
1137 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry)
1139 SALOMEDSImpl_SObject aSO;
1140 std::map<std::string, SALOMEDSImpl_SObject>::iterator it=_mapOfSO.find(theEntry);
1141 if(it != _mapOfSO.end())
1144 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1145 aSO = SALOMEDSImpl_SObject(aLabel);
1146 _mapOfSO[theEntry] = aSO;
1152 //============================================================================
1153 /*! Function : GetSObject
1156 //============================================================================
1157 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1159 return SALOMEDSImpl_SObject(theLabel);
1162 //============================================================================
1163 /*! Function : GetAttribute
1166 //============================================================================
1167 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry,
1168 const std::string& theType)
1170 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1171 DF_Attribute* anAttr;
1172 aSO.FindAttribute(anAttr, theType);
1176 //! number of spaces for indentation in Python dump files (to replace \t symbols)
1177 static const int indent_size = 2;
1179 static std::string replace_tabs( const std::string& in )
1181 std::string out = in;
1183 size_t pos = out.find( '\t' );
1184 while ( pos != std::string::npos ) {
1185 out.replace( pos, 1, indent_size, ' ' );
1186 pos = out.find( '\t' );
1192 //============================================================================
1193 /*! Function : DumpStudy
1196 //============================================================================
1197 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
1198 const std::string& theBaseName,
1200 SALOMEDSImpl_DriverFactory* theFactory)
1204 if(theFactory == NULL) {
1205 _errorCode = "Null factory for creation of Engines";
1209 std::vector<std::string> aSeq;
1210 std::string aCompType, aFactoryType;
1212 //Build a list of all components in the Study
1213 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1215 for (; itcomponent.More(); itcomponent.Next()) {
1216 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1217 aCompType = sco.ComponentDataType();
1218 //GEOM and MED are independent components
1219 if (aCompType == "GEOM" || aCompType == "MED")
1220 aSeq.insert(aSeq.begin(), aCompType);
1222 aSeq.push_back(aCompType);
1226 std::string aFileName =
1227 thePath + std::string("\\") + theBaseName + std::string(".py");
1229 std::string aFileName =
1230 thePath + std::string("/") + theBaseName + std::string(".py");
1233 //Create a file that will contain a main Study script
1235 fp.open(aFileName.c_str(), std::ios::out);
1238 bool isOpened = fp.is_open();
1240 bool isOpened = fp.rdbuf()->is_open();
1244 _errorCode = std::string("Can't create a file ")+aFileName;
1248 std::stringstream sfp;
1250 std::string aBatchModeScript = "salome";
1252 //Output to the main Study script required Python modules import,
1253 //set sys.path and add a creation of the study.
1256 sfp << GetDumpStudyComment() << std::endl;
1259 sfp << "import sys" << std::endl;
1260 sfp << "import " << aBatchModeScript << std::endl << std::endl;
1262 // initialization function
1263 sfp << aBatchModeScript << ".salome_init()" << std::endl << std::endl;
1265 // notebook initialization
1266 sfp << _GetNoteBookAccess();
1268 // extend sys.path with the directory where the script is being dumped to
1269 sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
1271 // dump NoteBook variables
1272 sfp << _GetStudyVariablesScript();
1274 // dump visual parameters if necessary
1275 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1276 int lastSavePoint = -1;
1278 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1279 if(lastSavePoint > 0) {
1280 sfp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
1284 std::vector<std::string> aSeqOfFileNames;
1286 // dump all components and create the components specific scripts
1288 int aLength = aSeq.size();
1289 for(int i = 1; i <= aLength; i++) {
1291 aCompType = aSeq[i-1];
1292 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1293 SALOMEDSImpl_Driver* aDriver = NULL;
1294 // if there is an associated Engine call its method for saving
1295 std::string IOREngine;
1297 if (!sco.ComponentIOR(IOREngine)) {
1298 if (!aCompType.empty()) {
1300 aDriver = theFactory->GetDriverByType(aCompType);
1302 if (aDriver != NULL) {
1303 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1304 if(!SB->LoadWith(sco, aDriver)) {
1305 _errorCode = SB->GetErrorCode();
1313 aDriver = theFactory->GetDriverByIOR(IOREngine);
1316 _errorCode = "Can not restore information to dump it";
1320 if(aDriver == NULL) continue;
1323 long aStreamLength = 0;
1324 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
1325 if ( !isValidScript )
1328 //Create a file that will contain the component specific script
1331 aFileName=thePath+std::string("\\");
1333 aFileName=thePath+std::string("/");
1335 std::string aScriptName;
1336 aScriptName += theBaseName;
1338 aScriptName += aCompType;
1340 aFileName += aScriptName+ std::string(".py");
1341 aSeqOfFileNames.push_back(aFileName);
1343 fp2.open(aFileName.c_str(), std::ios::out);
1346 isOpened = fp2.is_open();
1348 isOpened = fp2.rdbuf()->is_open();
1352 _errorCode = std::string("Can't create a file ")+aFileName;
1353 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1357 std::stringstream sfp2;
1359 //Output the Python script generated by the component in the newly created file.
1360 sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
1361 sfp2 << aStream->Data();
1363 // replace '\t' symbols
1364 fp2 << replace_tabs( sfp2.str() );
1368 if(aStream) delete aStream;
1370 //Add to the main script a call to RebuildData of the generated by the component the Python script
1371 sfp << "import " << aScriptName << std::endl;
1372 sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
1376 sfp << "if salome.sg.hasDesktop():" << std::endl;
1377 sfp << "\tsalome.sg.updateObjBrowser(1)" << std::endl;
1379 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1380 sfp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
1383 // replace '\t' symbols
1384 fp << replace_tabs( sfp.str() );
1391 //=======================================================================
1392 //function : GetDumpStudyComment
1393 //purpose : return a header comment for a DumpStudy script
1394 //=======================================================================
1396 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1398 std::stringstream txt;
1399 txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl;
1400 txt << "###" << std::endl;
1401 txt << "### This file is generated automatically by SALOME v"
1402 << KERNEL_VERSION_STR
1403 << " with dump python functionality";
1404 if ( theComponentName )
1405 txt << " (" << theComponentName << " component)";
1407 txt << "###" << std::endl;
1411 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1413 const std::string& Tab,
1414 SALOMEDSImpl_Study* theStudy);
1416 //============================================================================
1420 //============================================================================
1421 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
1423 //Create a file that will contain a main Study script
1425 fp.open(theFileName.c_str(), std::ios::out);
1428 bool isOpened = fp.is_open();
1430 bool isOpened = fp.rdbuf()->is_open();
1434 _errorCode = std::string("Can't create a file ")+theFileName;
1435 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
1439 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1440 fp << "0:1" << std::endl;
1441 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1442 std::string aTab(" ");
1443 for(; Itr.More(); Itr.Next()) {
1444 dumpSO(Itr.Value(), fp, aTab, this);
1451 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1453 const std::string& Tab,
1454 SALOMEDSImpl_Study* theStudy)
1456 std::string aTab(Tab), anID(theSO.GetID());
1457 fp << aTab << anID << std::endl;
1458 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1459 for(int i = 0; i<attribs.size(); i++) {
1460 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1466 std::string aType = anAttr->GetClassType();
1467 fp << Tab << " -- " << aType;
1469 if(aType == std::string("AttributeReal")) {
1470 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1472 else if(aType == std::string("AttributeInteger")) {
1473 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1475 else if(aType == std::string("AttributeName")) {
1476 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1478 else if(aType == std::string("AttributeComment")) {
1479 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1481 else if(aType == std::string("AttributeReference")) {
1482 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1487 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1488 std::string aNewTab(" ");
1490 for(; Itr.More(); Itr.Next()) {
1491 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1497 void SALOMEDSImpl_Study::Modify()
1500 _doc->SetModified(true);
1503 //============================================================================
1507 //============================================================================
1508 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1510 if (theSavePoint < 0) return NULL;
1511 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1512 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1513 if (!so) so = builder->NewComponent((char*)theID);
1514 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1516 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1517 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1518 if ( !savePointLabel.IsNull() )
1519 so = GetSObject( savePointLabel );
1520 else // ... if it does not exist - create a new one
1521 so = builder->NewObjectToTag( so, theSavePoint );
1526 builder->FindAttribute(so, A, "AttributeParameter");
1527 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1528 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1530 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1535 //============================================================================
1539 //============================================================================
1540 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1541 const char* theModuleName,
1544 if(theSavePoint <= 0) return NULL;
1545 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1546 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1547 SALOMEDSImpl_AttributeParameter* par = NULL;
1549 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1550 std::string moduleName(theModuleName);
1551 for(; it.More(); it.Next()) {
1552 SALOMEDSImpl_SObject so(it.Value());
1553 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1554 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1555 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1559 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1560 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1561 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1562 par->SetString("AP_MODULE_NAME", moduleName);
1566 //============================================================================
1567 /*! Function : SetStudyLock
1570 //============================================================================
1571 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1573 _lockers.push_back(theLockerID);
1576 //============================================================================
1577 /*! Function : IsStudyLocked
1580 //============================================================================
1581 bool SALOMEDSImpl_Study::IsStudyLocked()
1583 return (_lockers.size() > 0);
1586 //============================================================================
1587 /*! Function : UnLockStudy
1590 //============================================================================
1591 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1593 std::vector<std::string>::iterator vsI = _lockers.begin();
1594 int length = _lockers.size();
1595 bool isFound = false;
1596 std::string id(theLockerID);
1597 for(int i = 0; i<length; i++, vsI++) {
1598 if(id == _lockers[i]) {
1603 if(isFound) _lockers.erase(vsI);
1606 //============================================================================
1607 /*! Function : GetLockerID
1610 //============================================================================
1611 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
1616 //============================================================================
1617 /*! Function : SetVariable
1620 //============================================================================
1621 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
1622 const double 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->setValue(theValue);
1633 myNoteBookVars.push_back(aSVar);
1637 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1638 modified = aSVar->setValue(theValue) || modified;
1639 modified = aSVar->setType(theType) || modified;
1646 //============================================================================
1647 /*! Function : SetStringVariable
1650 //============================================================================
1651 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
1652 const std::string& theValue,
1653 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1655 bool modified = false;
1656 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1658 if( aGVar == NULL ) {
1660 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1662 aSVar->setStringValue(theValue);
1663 myNoteBookVars.push_back(aSVar);
1667 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1668 modified = aSVar->setStringValue(theValue) || modified;
1669 modified = aSVar->setType(theType) || modified;
1676 //============================================================================
1677 /*! Function : SetStringVariableAsDouble
1680 //============================================================================
1681 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
1682 const double theValue,
1683 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1685 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1686 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1687 aSVar->setValue(theValue);
1690 //============================================================================
1691 /*! Function : GetReal
1694 //============================================================================
1695 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
1697 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1700 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1701 return aSVar->getValue();
1706 //============================================================================
1707 /*! Function : GetString
1710 //============================================================================
1711 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
1713 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1716 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1717 return aSVar->getStringValue();
1722 //============================================================================
1723 /*! Function : IsTypeOf
1726 //============================================================================
1727 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
1728 SALOMEDSImpl_GenericVariable::
1729 VariableTypes theType) const
1731 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1734 return aGVar->Type() == theType;
1739 //============================================================================
1740 /*! Function : IsVariable
1743 //============================================================================
1744 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
1746 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1747 return (aGVar != NULL);
1750 //============================================================================
1751 /*! Function : GetVariableNames
1754 //============================================================================
1755 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
1757 std::vector<std::string> aResult;
1759 for(int i = 0; i < myNoteBookVars.size(); i++)
1760 aResult.push_back(myNoteBookVars[i]->Name());
1765 //============================================================================
1766 /*! Function : AddVariable
1769 //============================================================================
1770 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1772 myNoteBookVars.push_back(theVariable);
1775 //============================================================================
1776 /*! Function : AddVariable
1779 //============================================================================
1780 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1782 SALOMEDSImpl_GenericVariable* aResult = NULL;
1783 for(int i = 0; i < myNoteBookVars.size();i++) {
1784 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1785 aResult = myNoteBookVars[i];
1792 //============================================================================
1793 /*! Function : RemoveVariable
1796 //============================================================================
1797 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
1799 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1803 std::string aValue = aVariable->SaveToScript();
1804 ReplaceVariableAttribute( theVarName, aValue );
1806 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1807 for( ; it != itEnd; it++ )
1809 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1810 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1812 myNoteBookVars.erase( it );
1821 //============================================================================
1822 /*! Function : RenameVariable
1825 //============================================================================
1826 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
1828 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1832 ReplaceVariableAttribute( theVarName, theNewVarName );
1834 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1835 for( ; it != itEnd; it++ )
1837 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1838 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1840 aVariableRef->setName( theNewVarName );
1849 //============================================================================
1850 /*! Function : IsVariableUsed
1853 //============================================================================
1854 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
1856 return FindVariableAttribute( theVarName );
1859 //============================================================================
1860 /*! Function : FindVariableAttribute
1863 //============================================================================
1864 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1865 SALOMEDSImpl_SObject theSObject,
1866 const std::string& theName)
1868 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1869 for( ; anIter.More(); anIter.Next() )
1870 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1873 DF_Attribute* anAttr;
1874 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1876 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1878 std::string aString = aStringAttr->Value();
1880 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
1881 for( int i = 0, n = aSections.size(); i < n; i++ )
1883 std::vector<std::string> aVector = aSections[i];
1884 for( int j = 0, m = aVector.size(); j < m; j++ )
1886 std::string aStr = aVector[j];
1887 if( aStr.compare( theName ) == 0 )
1896 //============================================================================
1897 /*! Function : FindVariableAttribute
1900 //============================================================================
1901 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1903 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1904 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1905 for( ; aCompIter.More(); aCompIter.Next() )
1907 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1908 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1914 //============================================================================
1915 /*! Function : ReplaceVariableAttribute
1918 //============================================================================
1919 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1920 SALOMEDSImpl_SObject theSObject,
1921 const std::string& theSource,
1922 const std::string& theDest)
1924 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1925 for( ; anIter.More(); anIter.Next() )
1926 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1928 DF_Attribute* anAttr;
1929 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1931 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1933 bool isChanged = false;
1934 std::string aNewString, aCurrentString = aStringAttr->Value();
1936 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
1937 for( int i = 0, n = aSections.size(); i < n; i++ )
1939 std::vector<std::string> aVector = aSections[i];
1940 for( int j = 0, m = aVector.size(); j < m; j++ )
1942 std::string aStr = aVector[j];
1943 if( aStr.compare( theSource ) == 0 )
1949 aNewString.append( aStr );
1951 aNewString.append( ":" );
1954 aNewString.append( "|" );
1958 aStringAttr->SetValue( aNewString );
1963 //============================================================================
1964 /*! Function : ReplaceVariableAttribute
1967 //============================================================================
1968 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
1970 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1971 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1972 for( ; aCompIter.More(); aCompIter.Next() )
1974 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1975 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
1979 //============================================================================
1980 /*! Function : ParseVariables
1983 //============================================================================
1984 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
1986 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
1989 //============================================================================
1990 /*! Function : EnableUseCaseAutoFilling
1993 //============================================================================
1994 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
1996 _errorCode = ""; _autoFill = isEnabled;
1998 _builder->SetOnAddSObject(_cb);
1999 _builder->SetOnRemoveSObject(_cb);
2002 _builder->SetOnAddSObject(NULL);
2003 _builder->SetOnRemoveSObject(NULL);
2007 //============================================================================
2008 /*! Function : GetIORs
2011 //============================================================================
2012 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
2014 std::vector<std::string> anIORs;
2015 std::map<std::string, DF_Label>::const_iterator MI;
2016 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
2017 anIORs.push_back(MI->first);
2022 //============================================================================
2023 /*! Function : addSO_Notification
2024 * Purpose : This function tells all the observers that a SO has been added
2026 //============================================================================
2027 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2030 return _notifier->addSO_Notification(theSObject);
2035 //============================================================================
2036 /*! Function : removeSO_Notification
2037 * Purpose : This function tells all the observers that a SO has been removed
2039 //============================================================================
2040 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2043 return _notifier->removeSO_Notification(theSObject);
2048 //============================================================================
2049 /*! Function : modifySO_Notification
2050 * Purpose : This function tells all the observers that a SO has been modified and
2051 pass the mofification reason
2053 //============================================================================
2054 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
2057 return _notifier->modifySO_Notification(theSObject, reason);
2062 //============================================================================
2063 /*! Function : setNotifier
2064 * Purpose : register a notifier
2066 //============================================================================
2067 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)