1 // Copyright (C) 2007-2011 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 static std::string GetComponentHeader(const char* theComponentName)
1194 std::stringstream txt;
1195 txt << "###" << std::endl;
1196 txt << "### " << theComponentName << " component" << std::endl;
1197 txt << "###" << std::endl;
1201 //============================================================================
1202 /*! Function : DumpStudy
1205 //============================================================================
1206 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
1207 const std::string& theBaseName,
1210 SALOMEDSImpl_DriverFactory* theFactory)
1214 if(theFactory == NULL) {
1215 _errorCode = "Null factory for creation of Engines";
1219 std::vector<std::string> aSeq;
1220 std::string aCompType, aFactoryType;
1222 //Build a list of all components in the Study
1223 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1225 for (; itcomponent.More(); itcomponent.Next()) {
1226 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1227 aCompType = sco.ComponentDataType();
1228 //GEOM and MED are independent components
1229 if (aCompType == "GEOM" || aCompType == "MED")
1230 aSeq.insert(aSeq.begin(), aCompType);
1232 aSeq.push_back(aCompType);
1236 std::string aFileName =
1237 thePath + std::string("\\") + theBaseName + std::string(".py");
1239 std::string aFileName =
1240 thePath + std::string("/") + theBaseName + std::string(".py");
1243 //Create a file that will contain a main Study script
1245 fp.open(aFileName.c_str(), std::ios::out);
1248 bool isOpened = fp.is_open();
1250 bool isOpened = fp.rdbuf()->is_open();
1254 _errorCode = std::string("Can't create a file ")+aFileName;
1258 std::stringstream sfp;
1260 std::string aBatchModeScript = "salome";
1262 //Output to the main Study script required Python modules import,
1263 //set sys.path and add a creation of the study.
1266 sfp << GetDumpStudyComment() << std::endl;
1269 sfp << "import sys" << std::endl;
1270 sfp << "import " << aBatchModeScript << std::endl << std::endl;
1272 // initialization function
1273 sfp << aBatchModeScript << ".salome_init()" << std::endl;
1275 sfp << "theStudy = salome.myStudy" <<std::endl << std::endl;
1277 // notebook initialization
1278 sfp << _GetNoteBookAccess();
1280 // extend sys.path with the directory where the script is being dumped to
1281 sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
1283 // dump NoteBook variables
1284 sfp << _GetStudyVariablesScript();
1286 // dump visual parameters if necessary
1287 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1288 int lastSavePoint = -1;
1290 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1291 if(lastSavePoint > 0) {
1292 sfp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
1296 std::vector<std::string> aSeqOfFileNames;
1298 // dump all components and create the components specific scripts
1300 int aLength = aSeq.size();
1301 for(int i = 1; i <= aLength; i++) {
1303 aCompType = aSeq[i-1];
1304 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1305 SALOMEDSImpl_Driver* aDriver = NULL;
1306 // if there is an associated Engine call its method for saving
1307 std::string IOREngine;
1309 if (!sco.ComponentIOR(IOREngine)) {
1310 if (!aCompType.empty()) {
1312 aDriver = theFactory->GetDriverByType(aCompType);
1314 if (aDriver != NULL) {
1315 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1316 if(!SB->LoadWith(sco, aDriver)) {
1317 _errorCode = SB->GetErrorCode();
1325 aDriver = theFactory->GetDriverByIOR(IOREngine);
1328 _errorCode = "Can not restore information to dump it";
1332 if(aDriver == NULL) continue;
1335 long aStreamLength = 0;
1336 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isMultiFile, isValidScript, aStreamLength);
1337 if ( !isValidScript )
1340 std::stringstream sfp2;
1342 //Output the Python script generated by the component in the newly created file.
1344 sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
1346 sfp2 << GetComponentHeader( aCompType.c_str() ) << std::endl;
1347 sfp2 << aStream->Data();
1349 if ( isMultiFile ) {
1350 //Create a file that will contain the component specific script
1353 aFileName=thePath+std::string("\\");
1355 aFileName=thePath+std::string("/");
1357 std::string aScriptName;
1358 aScriptName += theBaseName;
1360 aScriptName += aCompType;
1362 aFileName += aScriptName+ std::string(".py");
1363 aSeqOfFileNames.push_back(aFileName);
1365 fp2.open(aFileName.c_str(), std::ios::out);
1368 isOpened = fp2.is_open();
1370 isOpened = fp2.rdbuf()->is_open();
1374 _errorCode = std::string("Can't create a file ")+aFileName;
1375 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1379 // replace '\t' symbols
1380 fp2 << replace_tabs( sfp2.str() );
1384 //Add to the main script a call to RebuildData of the generated by the component the Python script
1385 sfp << "import " << aScriptName << std::endl;
1386 sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
1391 if(aStream) delete aStream;
1395 sfp << "if salome.sg.hasDesktop():" << std::endl;
1396 sfp << "\tsalome.sg.updateObjBrowser(1)" << std::endl;
1398 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1399 sfp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
1402 // replace '\t' symbols
1403 fp << replace_tabs( sfp.str() );
1410 //=======================================================================
1411 //function : GetDumpStudyComment
1412 //purpose : return a header comment for a DumpStudy script
1413 //=======================================================================
1415 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1417 std::stringstream txt;
1418 txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl;
1419 txt << "###" << std::endl;
1420 txt << "### This file is generated automatically by SALOME v"
1421 << KERNEL_VERSION_STR
1422 << " with dump python functionality";
1423 if ( theComponentName )
1424 txt << " (" << theComponentName << " component)";
1426 txt << "###" << std::endl;
1430 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1432 const std::string& Tab,
1433 SALOMEDSImpl_Study* theStudy);
1435 //============================================================================
1439 //============================================================================
1440 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
1442 //Create a file that will contain a main Study script
1444 fp.open(theFileName.c_str(), std::ios::out);
1447 bool isOpened = fp.is_open();
1449 bool isOpened = fp.rdbuf()->is_open();
1453 _errorCode = std::string("Can't create a file ")+theFileName;
1454 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
1458 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1459 fp << "0:1" << std::endl;
1460 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1461 std::string aTab(" ");
1462 for(; Itr.More(); Itr.Next()) {
1463 dumpSO(Itr.Value(), fp, aTab, this);
1470 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1472 const std::string& Tab,
1473 SALOMEDSImpl_Study* theStudy)
1475 std::string aTab(Tab), anID(theSO.GetID());
1476 fp << aTab << anID << std::endl;
1477 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1478 for(int i = 0; i<attribs.size(); i++) {
1479 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1485 std::string aType = anAttr->GetClassType();
1486 fp << Tab << " -- " << aType;
1488 if(aType == std::string("AttributeReal")) {
1489 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1491 else if(aType == std::string("AttributeInteger")) {
1492 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1494 else if(aType == std::string("AttributeName")) {
1495 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1497 else if(aType == std::string("AttributeComment")) {
1498 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1500 else if(aType == std::string("AttributeReference")) {
1501 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1506 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1507 std::string aNewTab(" ");
1509 for(; Itr.More(); Itr.Next()) {
1510 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1516 void SALOMEDSImpl_Study::Modify()
1519 _doc->SetModified(true);
1522 //============================================================================
1526 //============================================================================
1527 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1529 if (theSavePoint < -1) return NULL;
1530 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1531 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1532 if (!so) so = builder->NewComponent((char*)theID);
1533 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1535 if (theSavePoint == -1) {
1537 DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
1538 DF_Label prevPointLabel;
1539 while ( !savePointLabel.IsNull() ) {
1541 prevPointLabel = savePointLabel;
1542 savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
1544 if ( !prevPointLabel.IsNull() )
1545 so = GetSObject( prevPointLabel );
1547 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1548 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1549 if ( !savePointLabel.IsNull() )
1550 so = GetSObject( savePointLabel );
1551 else // ... if it does not exist - create a new one
1552 so = builder->NewObjectToTag( so, theSavePoint );
1557 builder->FindAttribute(so, A, "AttributeParameter");
1558 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1559 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1561 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1566 //============================================================================
1570 //============================================================================
1571 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1572 const char* theModuleName,
1575 if(theSavePoint < -1) return NULL;
1576 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1577 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1578 SALOMEDSImpl_AttributeParameter* par = NULL;
1580 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1581 std::string moduleName(theModuleName);
1582 for(; it.More(); it.Next()) {
1583 SALOMEDSImpl_SObject so(it.Value());
1584 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1585 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1586 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1590 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1591 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1592 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1593 par->SetString("AP_MODULE_NAME", moduleName);
1597 //============================================================================
1598 /*! Function : SetStudyLock
1601 //============================================================================
1602 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1604 _lockers.push_back(theLockerID);
1607 //============================================================================
1608 /*! Function : IsStudyLocked
1611 //============================================================================
1612 bool SALOMEDSImpl_Study::IsStudyLocked()
1614 return (_lockers.size() > 0);
1617 //============================================================================
1618 /*! Function : UnLockStudy
1621 //============================================================================
1622 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1624 std::vector<std::string>::iterator vsI = _lockers.begin();
1625 int length = _lockers.size();
1626 bool isFound = false;
1627 std::string id(theLockerID);
1628 for(int i = 0; i<length; i++, vsI++) {
1629 if(id == _lockers[i]) {
1634 if(isFound) _lockers.erase(vsI);
1637 //============================================================================
1638 /*! Function : GetLockerID
1641 //============================================================================
1642 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
1647 //============================================================================
1648 /*! Function : SetVariable
1651 //============================================================================
1652 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
1653 const double theValue,
1654 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1656 bool modified = false;
1657 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1659 if( aGVar == NULL ) {
1661 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1663 aSVar->setValue(theValue);
1664 myNoteBookVars.push_back(aSVar);
1668 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1669 modified = aSVar->setValue(theValue) || modified;
1670 modified = aSVar->setType(theType) || modified;
1677 //============================================================================
1678 /*! Function : SetStringVariable
1681 //============================================================================
1682 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
1683 const std::string& theValue,
1684 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1686 bool modified = false;
1687 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1689 if( aGVar == NULL ) {
1691 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1693 aSVar->setStringValue(theValue);
1694 myNoteBookVars.push_back(aSVar);
1698 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1699 modified = aSVar->setStringValue(theValue) || modified;
1700 modified = aSVar->setType(theType) || modified;
1707 //============================================================================
1708 /*! Function : SetStringVariableAsDouble
1711 //============================================================================
1712 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
1713 const double theValue,
1714 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1716 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1717 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1718 aSVar->setValue(theValue);
1721 //============================================================================
1722 /*! Function : GetReal
1725 //============================================================================
1726 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
1728 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1731 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1732 return aSVar->getValue();
1737 //============================================================================
1738 /*! Function : GetString
1741 //============================================================================
1742 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
1744 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1747 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1748 return aSVar->getStringValue();
1753 //============================================================================
1754 /*! Function : IsTypeOf
1757 //============================================================================
1758 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
1759 SALOMEDSImpl_GenericVariable::
1760 VariableTypes theType) const
1762 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1765 return aGVar->Type() == theType;
1770 //============================================================================
1771 /*! Function : IsVariable
1774 //============================================================================
1775 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
1777 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1778 return (aGVar != NULL);
1781 //============================================================================
1782 /*! Function : GetVariableNames
1785 //============================================================================
1786 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
1788 std::vector<std::string> aResult;
1790 for(int i = 0; i < myNoteBookVars.size(); i++)
1791 aResult.push_back(myNoteBookVars[i]->Name());
1796 //============================================================================
1797 /*! Function : AddVariable
1800 //============================================================================
1801 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1803 myNoteBookVars.push_back(theVariable);
1806 //============================================================================
1807 /*! Function : AddVariable
1810 //============================================================================
1811 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1813 SALOMEDSImpl_GenericVariable* aResult = NULL;
1814 for(int i = 0; i < myNoteBookVars.size();i++) {
1815 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1816 aResult = myNoteBookVars[i];
1823 //============================================================================
1824 /*! Function : RemoveVariable
1827 //============================================================================
1828 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
1830 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1834 std::string aValue = aVariable->SaveToScript();
1835 ReplaceVariableAttribute( theVarName, aValue );
1837 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1838 for( ; it != itEnd; it++ )
1840 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1841 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1843 myNoteBookVars.erase( it );
1852 //============================================================================
1853 /*! Function : RenameVariable
1856 //============================================================================
1857 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
1859 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1863 ReplaceVariableAttribute( theVarName, theNewVarName );
1865 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1866 for( ; it != itEnd; it++ )
1868 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1869 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1871 aVariableRef->setName( theNewVarName );
1880 //============================================================================
1881 /*! Function : IsVariableUsed
1884 //============================================================================
1885 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
1887 return FindVariableAttribute( theVarName );
1890 //============================================================================
1891 /*! Function : FindVariableAttribute
1894 //============================================================================
1895 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1896 SALOMEDSImpl_SObject theSObject,
1897 const std::string& theName)
1899 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1900 for( ; anIter.More(); anIter.Next() )
1901 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1904 DF_Attribute* anAttr;
1905 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1907 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1909 std::string aString = aStringAttr->Value();
1911 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
1912 for( int i = 0, n = aSections.size(); i < n; i++ )
1914 std::vector<std::string> aVector = aSections[i];
1915 for( int j = 0, m = aVector.size(); j < m; j++ )
1917 std::string aStr = aVector[j];
1918 if( aStr.compare( theName ) == 0 )
1927 //============================================================================
1928 /*! Function : FindVariableAttribute
1931 //============================================================================
1932 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1934 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1935 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1936 for( ; aCompIter.More(); aCompIter.Next() )
1938 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1939 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1945 //============================================================================
1946 /*! Function : ReplaceVariableAttribute
1949 //============================================================================
1950 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1951 SALOMEDSImpl_SObject theSObject,
1952 const std::string& theSource,
1953 const std::string& theDest)
1955 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1956 for( ; anIter.More(); anIter.Next() )
1957 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1959 DF_Attribute* anAttr;
1960 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1962 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1964 bool isChanged = false;
1965 std::string aNewString, aCurrentString = aStringAttr->Value();
1967 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
1968 for( int i = 0, n = aSections.size(); i < n; i++ )
1970 std::vector<std::string> aVector = aSections[i];
1971 for( int j = 0, m = aVector.size(); j < m; j++ )
1973 std::string aStr = aVector[j];
1974 if( aStr.compare( theSource ) == 0 )
1980 aNewString.append( aStr );
1982 aNewString.append( ":" );
1985 aNewString.append( "|" );
1989 aStringAttr->SetValue( aNewString );
1994 //============================================================================
1995 /*! Function : ReplaceVariableAttribute
1998 //============================================================================
1999 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
2001 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
2002 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
2003 for( ; aCompIter.More(); aCompIter.Next() )
2005 SALOMEDSImpl_SObject aComp = aCompIter.Value();
2006 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
2010 //============================================================================
2011 /*! Function : ParseVariables
2014 //============================================================================
2015 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
2017 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
2020 //============================================================================
2021 /*! Function : EnableUseCaseAutoFilling
2024 //============================================================================
2025 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
2027 _errorCode = ""; _autoFill = isEnabled;
2029 _builder->SetOnAddSObject(_cb);
2030 _builder->SetOnRemoveSObject(_cb);
2033 _builder->SetOnAddSObject(NULL);
2034 _builder->SetOnRemoveSObject(NULL);
2038 //============================================================================
2039 /*! Function : GetIORs
2042 //============================================================================
2043 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
2045 std::vector<std::string> anIORs;
2046 std::map<std::string, DF_Label>::const_iterator MI;
2047 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
2048 anIORs.push_back(MI->first);
2053 //============================================================================
2054 /*! Function : addSO_Notification
2055 * Purpose : This function tells all the observers that a SO has been added
2057 //============================================================================
2058 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2061 return _notifier->addSO_Notification(theSObject);
2066 //============================================================================
2067 /*! Function : removeSO_Notification
2068 * Purpose : This function tells all the observers that a SO has been removed
2070 //============================================================================
2071 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2074 return _notifier->removeSO_Notification(theSObject);
2079 //============================================================================
2080 /*! Function : modifySO_Notification
2081 * Purpose : This function tells all the observers that a SO has been modified and
2082 pass the mofification reason
2084 //============================================================================
2085 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
2088 return _notifier->modifySO_Notification(theSObject, reason);
2093 //============================================================================
2094 /*! Function : setNotifier
2095 * Purpose : register a notifier
2097 //============================================================================
2098 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)