1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_Study.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_Study.hxx"
30 #include <KERNEL_version.h>
31 #include <Basics_Utils.hxx>
33 #include "DF_Application.hxx"
34 #include "DF_ChildIterator.hxx"
36 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
37 #include "SALOMEDSImpl_Attributes.hxx"
38 #include "SALOMEDSImpl_UseCaseIterator.hxx"
39 #include "SALOMEDSImpl_AttributeReference.hxx"
40 #include "SALOMEDSImpl_StudyHandle.hxx"
41 #include "SALOMEDSImpl_Tool.hxx"
42 #include "SALOMEDSImpl_IParameters.hxx"
43 #include "SALOMEDSImpl_ScalarVariable.hxx"
48 #define DIRECTORYID 16661
49 #define FILELOCALID 26662
50 #define FILEID "FILE: "
51 #define VARIABLE_SEPARATOR ':'
52 #define OPERATION_SEPARATOR '|'
54 //============================================================================
55 /*! Function : SALOMEDSImpl_Study
56 * Purpose : SALOMEDSImpl_Study constructor
58 //============================================================================
59 SALOMEDSImpl_Study::SALOMEDSImpl_Study(const DF_Document* doc,
60 const std::string& study_name)
63 _doc = (DF_Document*)doc;
69 _useCaseBuilder = new SALOMEDSImpl_UseCaseBuilder(_doc);
70 _builder = new SALOMEDSImpl_StudyBuilder(this);
71 _cb = new SALOMEDSImpl_Callback(_useCaseBuilder);
73 //Put on the root label a StudyHandle attribute to store the address of this object
74 //It will be used to retrieve the study object by DF_Label that belongs to the study
75 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
79 //============================================================================
80 /*! Function : ~SALOMEDSImpl_Study
81 * Purpose : SALOMEDSImpl_Study destructor
83 //============================================================================
84 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
88 delete _useCaseBuilder;
91 //============================================================================
92 /*! Function : GetPersistentReference
93 * Purpose : Get persistent reference of study (idem URL())
95 //============================================================================
96 std::string SALOMEDSImpl_Study::GetPersistentReference()
101 //============================================================================
102 /*! Function : GetTransientReference
103 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
105 //============================================================================
106 std::string SALOMEDSImpl_Study::GetTransientReference()
109 std::string IOR = "";
111 SALOMEDSImpl_AttributeIOR* Att;
112 DF_Label _lab = _doc->Root();
113 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
117 _errorCode = "IOR is empty";
123 void SALOMEDSImpl_Study::SetTransientReference(const std::string& theIOR)
127 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
128 int aLocked = aProp->IsLocked();
129 if (aLocked) aProp->SetLocked(false);
131 // Assign the value of the IOR in the study->root
132 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
134 if (aLocked) aProp->SetLocked(true);
137 //============================================================================
138 /*! Function : IsEmpty
139 * Purpose : Detect if study is empty
141 //============================================================================
142 bool SALOMEDSImpl_Study::IsEmpty()
145 if (!_doc) return true;
146 return _doc->IsEmpty();
149 //============================================================================
150 /*! Function : FindComponent
151 * Purpose : Find a Component with ComponentDataType = aComponentName
153 //============================================================================
154 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName)
159 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
160 SALOMEDSImpl_SComponent compo;
162 for (; itcomp.More(); itcomp.Next()) {
163 SALOMEDSImpl_SComponent SC = itcomp.Value();
164 name = SC.ComponentDataType();
165 if(aComponentName == name) {
173 _errorCode = "No component was found";
179 //============================================================================
180 /*! Function : FindComponentID
181 * Purpose : Find a Component from it's ID
183 //============================================================================
184 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID)
188 // Iterate on each components defined in the study
189 // Get the component ID and compare with aComponentID
192 SALOMEDSImpl_SComponent compo;
194 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
195 for (; itcomp.More(); itcomp.Next()) {
196 SALOMEDSImpl_SComponent SC = itcomp.Value();
198 if(aComponentID == ID)
207 _errorCode = "No component was found";
214 //============================================================================
215 /*! Function : FindObject
216 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
218 //============================================================================
219 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName)
223 // Iterate to all components defined in the study
224 // After testing the component name, iterate in all objects defined under
225 // components (function _FindObject)
227 SALOMEDSImpl_SObject RefSO;
229 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
230 for (; it.More();it.Next()){
233 SALOMEDSImpl_SComponent SC = it.Value();
234 if (SC.GetName() == anObjectName)
240 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
243 if(!RefSO) _errorCode = "No object was found";
247 //============================================================================
248 /*! Function : FindObjectID
249 * Purpose : Find an Object with ID = anObjectID
251 //============================================================================
252 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID)
255 SALOMEDSImpl_SObject so;
257 // Convert aSO->GetID in DF_Label.
258 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
261 _errorCode = "No label was found by ID";
264 return GetSObject(Lab);
268 //============================================================================
269 /*! Function : CreateObjectID
270 * Purpose : Creates an Object with ID = anObjectID
272 //============================================================================
273 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID)
276 SALOMEDSImpl_SObject so;
278 // Convert aSO->GetID in DF_Label.
279 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
282 _errorCode = "Can not create a label";
285 return GetSObject(Lab);
289 //============================================================================
290 /*! Function : FindObjectByName
291 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
292 * : with ComponentDataType = aComponentName
294 //============================================================================
295 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName,
296 const std::string& aComponentName)
300 std::vector<SALOMEDSImpl_SObject> listSO;
302 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
304 _errorCode = "Can not find the component";
308 // Iterate on each object and subobject of the component
309 // If objectName is found add it to the list of SObjects
310 std::string childName ;
312 std::string compoId = compo.GetID();
313 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
314 for ( ; it.More(); it.Next() ) {
316 SALOMEDSImpl_SObject CSO = it.Value();
317 if ( CSO.GetName() == anObjectName ) {
319 listSO.push_back(CSO) ;
322 /* looks also for eventual children */
324 CSO = _FindObject( CSO, anObjectName, found ) ;
326 listSO.push_back(CSO) ;
335 //============================================================================
336 /*! Function : FindObjectIOR
337 * Purpose : Find an Object with IOR = anObjectIOR
339 //============================================================================
340 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR)
344 SALOMEDSImpl_SObject aResult ;
346 // searching in the datamap for optimization
347 if (myIORLabels.find(anObjectIOR) != myIORLabels.end()) {
348 aResult = GetSObject(myIORLabels[anObjectIOR]);
349 // 11 oct 2002: forbidden attributes must be checked here
350 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
351 myIORLabels.erase(anObjectIOR);
352 aResult = SALOMEDSImpl_SObject();
356 if(!aResult) _errorCode = "No object was found";
360 //============================================================================
361 /*! Function : FindObjectByPath
362 * Purpose : Find an Object by its path = thePath
364 //============================================================================
365 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath)
369 std::string aPath(thePath), aToken;
370 SALOMEDSImpl_SObject aSO;
371 int aLength = aPath.size();
372 bool isRelative = false;
374 if(aLength == 0) { //Empty path - return the current context
375 return GetSObject(_current);
378 if(aPath[0] != '/') //Relative path
381 DF_ChildIterator anIterator;
383 SALOMEDSImpl_AttributeName* anAttr;
386 if(_current.IsNull()) return aSO;
387 anIterator.Init(_current, false);
390 if(aPath.size() == 1 && aPath[0] == '/') { //Root
391 return GetSObject(_doc->Main());
393 anIterator.Init(_doc->Main(), false);
396 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
397 for(int i = 0, len = vs.size(); i<len; i++) {
400 if(aToken.size() == 0) break;
402 for ( ; anIterator.More(); anIterator.Next() ) {
403 aLabel = anIterator.Value();
404 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
405 if(anAttr->Value() == aToken) {
406 if(i == (len-1)) { //The searched label is found (no part of the path is left)
407 return GetSObject(aLabel);
410 anIterator.Init(aLabel, false);
418 if(!aSO) _errorCode = "No object was found";
422 //============================================================================
423 /*! Function : GetObjectPath
426 //============================================================================
427 std::string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
431 std::string aPath("");
433 _errorCode = "Null object";
437 std::string aName = theObject.GetName();
438 if(!aName.empty() && aName != "" ) {
439 std::string aValue("/");
443 SALOMEDSImpl_SObject aFather = theObject.GetFather();
445 aName = aFather.GetName();
446 if(!aName.empty() && aName != "") {
447 aValue = GetObjectPath(aFather);
448 aPath = aValue + aPath;
457 //============================================================================
458 /*! Function : GetObjectPathByIOR
461 //============================================================================
462 std::string SALOMEDSImpl_Study::GetObjectPathByIOR(const std::string& theIOR)
467 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
469 _errorCode = "No SObject was found by IOR";
473 return GetObjectPath(so);
477 //============================================================================
478 /*! Function : SetContext
479 * Purpose : Sets the current context
481 //============================================================================
482 bool SALOMEDSImpl_Study::SetContext(const std::string& thePath)
485 if(thePath.empty()) {
486 _errorCode = "InvalidPath";
490 std::string aPath(thePath), aContext("");
491 bool isInvalid = false;
492 SALOMEDSImpl_SObject aSO;
494 if(aPath[0] != '/') { //Relative path
495 aContext = GetContext();
503 aSO = FindObjectByPath(aContext);
509 if(isInvalid || !aSO) {
510 _errorCode = "InvalidContext";
514 DF_Label aLabel = aSO.GetLabel();
515 if(aLabel.IsNull()) {
516 _errorCode = "InvalidContext";
520 _current = aLabel; //Set the current context
525 //============================================================================
526 /*! Function : GetContext
527 * Purpose : Gets the current context
529 //============================================================================
530 std::string SALOMEDSImpl_Study::GetContext()
534 if(_current.IsNull()) {
535 _errorCode = "InvaidContext";
538 SALOMEDSImpl_SObject so = GetSObject(_current);
539 return GetObjectPath(so);
542 //============================================================================
543 /*! Function : GetObjectNames
544 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
546 //============================================================================
547 std::vector<std::string> SALOMEDSImpl_Study::GetObjectNames(const std::string& theContext)
551 std::vector<std::string> aResultSeq;
553 if (theContext.empty()) {
556 DF_Label aTmp = _current;
557 SetContext(theContext);
561 if (aLabel.IsNull()) {
562 _errorCode = "InvalidContext";
566 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
567 for (; anIter.More(); anIter.Next()) {
568 DF_Label aLabel = anIter.Value();
569 SALOMEDSImpl_AttributeName* aName;
570 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
571 aResultSeq.push_back(aName->Value());
577 //============================================================================
578 /*! Function : GetDirectoryNames
579 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
581 //============================================================================
582 std::vector<std::string> SALOMEDSImpl_Study::GetDirectoryNames(const std::string& theContext)
586 std::vector<std::string> aResultSeq;
588 if (theContext.empty()) {
591 DF_Label aTmp = _current;
592 SetContext(theContext);
596 if (aLabel.IsNull()) {
597 _errorCode = "InvalidContext";
601 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
602 for (; anIter.More(); anIter.Next()) {
603 DF_Label aLabel = anIter.Value();
604 SALOMEDSImpl_AttributeLocalID* anID;
605 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
606 if (anID->Value() == DIRECTORYID) {
607 SALOMEDSImpl_AttributeName* aName;
608 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
609 aResultSeq.push_back(aName->Value());
618 //============================================================================
619 /*! Function : GetFileNames
620 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
622 //============================================================================
623 std::vector<std::string> SALOMEDSImpl_Study::GetFileNames(const std::string& theContext)
627 std::vector<std::string> aResultSeq;
629 if (theContext.empty()) {
632 DF_Label aTmp = _current;
633 SetContext(theContext);
637 if (aLabel.IsNull()) {
638 _errorCode = "InvalidContext";
642 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
643 for (; anIter.More(); anIter.Next()) {
644 DF_Label aLabel = anIter.Value();
645 SALOMEDSImpl_AttributeLocalID* anID;
646 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
647 if (anID->Value() == FILELOCALID) {
648 SALOMEDSImpl_AttributePersistentRef* aName;
649 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
650 std::string aFileName = aName->Value();
651 if (aFileName.size() > 0)
652 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
661 //============================================================================
662 /*! Function : GetComponentNames
663 * Purpose : method to get all components names
665 //============================================================================
666 std::vector<std::string> SALOMEDSImpl_Study::GetComponentNames(const std::string& theContext)
670 std::vector<std::string> aResultSeq;
671 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
672 for(; anIter.More(); anIter.Next()) {
673 DF_Label aLabel = anIter.Value();
674 SALOMEDSImpl_AttributeName* aName;
675 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
676 aResultSeq.push_back(aName->Value());
682 //============================================================================
683 /*! Function : NewChildIterator
684 * Purpose : Create a ChildIterator from an SObject
686 //============================================================================
687 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
690 return SALOMEDSImpl_ChildIterator(aSO);
694 //============================================================================
695 /*! Function : NewComponentIterator
696 * Purpose : Create a SComponentIterator
698 //============================================================================
699 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
702 return SALOMEDSImpl_SComponentIterator(_doc);
706 //============================================================================
707 /*! Function : NewBuilder
708 * Purpose : Create a StudyBuilder
710 //============================================================================
711 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
715 _builder->SetOnAddSObject(_cb);
716 _builder->SetOnRemoveSObject(_cb);
722 //============================================================================
724 * Purpose : get study name
726 //============================================================================
727 std::string SALOMEDSImpl_Study::Name()
733 //============================================================================
735 * Purpose : set study name
737 //============================================================================
738 void SALOMEDSImpl_Study::Name(const std::string& name)
744 //============================================================================
745 /*! Function : IsSaved
746 * Purpose : get if study has been saved
748 //============================================================================
749 bool SALOMEDSImpl_Study::IsSaved()
755 //============================================================================
756 /*! Function : IsSaved
757 * Purpose : set if study has been saved
759 //============================================================================
760 void SALOMEDSImpl_Study::IsSaved(bool save)
764 if(save) _doc->SetModified(false);
767 //============================================================================
768 /*! Function : IsModified
769 * Purpose : Detect if a Study has been modified since it has been saved
771 //============================================================================
772 bool SALOMEDSImpl_Study::IsModified()
776 // True if is modified
777 if (_doc && _doc->IsModified()) return true;
782 //============================================================================
784 * Purpose : get URL of the study (persistent reference of the study)
786 //============================================================================
787 std::string SALOMEDSImpl_Study::URL()
793 //============================================================================
795 * Purpose : set URL of the study (persistent reference of the study)
797 //============================================================================
798 void SALOMEDSImpl_Study::URL(const std::string& url)
803 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
804 std::string tmp(_URL);
806 char *aName = (char*)tmp.ToCString();
807 char *adr = strtok(aName, "/");
811 adr = strtok(NULL, "/");
818 //============================================================================
819 /*! Function : _FindObject
820 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
822 //============================================================================
823 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
824 const std::string& theObjectName,
827 SALOMEDSImpl_SObject RefSO;
828 if(!SO) return RefSO;
830 // Iterate on each objects and subobjects of the component
831 // If objectName find, stop the loop and get the object reference
832 SALOMEDSImpl_AttributeName* anAttr;
834 std::string soid = SO.GetID();
835 DF_ChildIterator it(SO.GetLabel());
836 for (; it.More(); it.Next()){
839 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
841 std::string Val(anAttr->Value());
842 if (Val == theObjectName)
844 RefSO = GetSObject(it.Value());
848 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
854 //============================================================================
855 /*! Function : _FindObjectIOR
856 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
858 //============================================================================
860 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
861 const std::string& theObjectIOR,
864 SALOMEDSImpl_SObject RefSO, aSO;
865 if(!SO) return RefSO;
867 // Iterate on each objects and subobjects of the component
868 // If objectName find, stop the loop and get the object reference
869 SALOMEDSImpl_AttributeIOR* anAttr;
871 DF_ChildIterator it(SO.GetLabel());
872 for (; it.More();it.Next()){
875 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
877 std::string Val(anAttr->Value());
878 if (Val == theObjectIOR)
880 RefSO = GetSObject(it.Value());
884 aSO = GetSObject(it.Value());
885 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
891 //============================================================================
892 /*! Function : _GetNoteBookAccessor
893 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
895 //============================================================================
896 std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
897 return std::string("notebook");
900 //============================================================================
901 /*! Function : _GetStudyVariablesScript
904 //============================================================================
905 std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
907 std::string dump("");
909 if(myNoteBookVars.empty())
912 Kernel_Utils::Localizer loc;
914 dump += "####################################################\n";
915 dump += "## Begin of NoteBook variables section ##\n";
916 dump += "####################################################\n";
918 std::string set_method = _GetNoteBookAccessor()+".set(";
920 std::string varValue;
921 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
922 varName = myNoteBookVars[i]->Name();
923 varValue = myNoteBookVars[i]->SaveToScript();
924 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
927 dump += "####################################################\n";
928 dump += "## End of NoteBook variables section ##\n";
929 dump += "####################################################\n";
934 //============================================================================
935 /*! Function : _GetNoteBookAccess
938 //============================================================================
939 std::string SALOMEDSImpl_Study::_GetNoteBookAccess()
941 std::string accessor = _GetNoteBookAccessor();
942 std::string notebook = "import salome_notebook\n";
943 notebook += accessor+" = salome_notebook."+accessor + "\n";
947 bool SALOMEDSImpl_Study::IsLocked()
950 return GetProperties()->IsLocked();
953 int SALOMEDSImpl_Study::StudyId()
959 void SALOMEDSImpl_Study::StudyId(int id)
965 void SALOMEDSImpl_Study::UpdateIORLabelMap(const std::string& anIOR,const std::string& anEntry)
968 DF_Label aLabel = DF_Label::Label(_doc->Main(), anEntry, true);
969 if (myIORLabels.find(anIOR) != myIORLabels.end()) myIORLabels.erase(anIOR);
970 myIORLabels[anIOR] = aLabel;
973 void SALOMEDSImpl_Study::DeleteIORLabelMapItem(const std::string& anIOR)
975 if (myIORLabels.find(anIOR) != myIORLabels.end())
977 //remove the ior entry and decref the genericobj (if it's one)
978 myIORLabels.erase(anIOR);
982 SALOMEDSImpl_Study* SALOMEDSImpl_Study::GetStudy(const DF_Label& theLabel)
984 SALOMEDSImpl_StudyHandle* Att;
985 if ((Att=(SALOMEDSImpl_StudyHandle*)theLabel.Root().FindAttribute(SALOMEDSImpl_StudyHandle::GetID()))) {
991 SALOMEDSImpl_SObject SALOMEDSImpl_Study::SObject(const DF_Label& theLabel)
993 return GetStudy(theLabel)->GetSObject(theLabel);
996 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::SComponent(const DF_Label& theLabel)
998 return GetStudy(theLabel)->GetSComponent(theLabel);
1002 void SALOMEDSImpl_Study::IORUpdated(const SALOMEDSImpl_AttributeIOR* theAttribute)
1004 std::string aString = theAttribute->Label().Entry();
1005 GetStudy(theAttribute->Label())->UpdateIORLabelMap(theAttribute->Value(), aString);
1008 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindDependances(const SALOMEDSImpl_SObject& anObject)
1011 std::vector<SALOMEDSImpl_SObject> aSeq;
1013 SALOMEDSImpl_AttributeTarget* aTarget;
1014 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)anObject.GetLabel().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
1015 return aTarget->Get();
1022 SALOMEDSImpl_AttributeStudyProperties* SALOMEDSImpl_Study::GetProperties()
1025 return SALOMEDSImpl_AttributeStudyProperties::Set(_doc->Main());
1028 std::string SALOMEDSImpl_Study::GetLastModificationDate()
1031 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1033 std::vector<std::string> aNames;
1034 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1035 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1037 int aLastIndex = aNames.size()-1;
1039 sprintf(aResult, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1040 (int)(aDays[aLastIndex]),(int)(aMonths[aLastIndex]), (int)(aYears[aLastIndex]),
1041 (int)(aHours[aLastIndex]), (int)(aMinutes[aLastIndex]));
1042 std::string aResStr (aResult);
1046 std::vector<std::string> SALOMEDSImpl_Study::GetModificationsDate()
1049 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
1051 std::vector<std::string> aNames;
1052 std::vector<int> aMinutes, aHours, aDays, aMonths, aYears;
1053 aProp->GetModifications(aNames, aMinutes, aHours, aDays, aMonths, aYears);
1055 int anIndex, aLength = aNames.size();
1056 std::vector<std::string> aDates;
1058 for (anIndex = 1; anIndex < aLength; anIndex++) {
1060 sprintf(aDate, "%2.2d/%2.2d/%4.4d %2.2d:%2.2d",
1061 (int)(aDays[anIndex]), (int)(aMonths[anIndex]), (int)(aYears[anIndex]),
1062 (int)(aHours[anIndex]), (int)(aMinutes[anIndex]));
1063 aDates.push_back(aDate);
1070 //============================================================================
1071 /*! Function : GetUseCaseBuilder
1072 * Purpose : Returns a UseCase builder
1074 //============================================================================
1075 SALOMEDSImpl_UseCaseBuilder* SALOMEDSImpl_Study::GetUseCaseBuilder()
1078 return _useCaseBuilder;
1082 //============================================================================
1083 /*! Function : Close
1086 //============================================================================
1087 void SALOMEDSImpl_Study::Close()
1090 _doc->GetApplication()->Close(_doc);
1097 //============================================================================
1098 /*! Function : GetSComponent
1101 //============================================================================
1102 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry)
1104 SALOMEDSImpl_SComponent aSCO;
1105 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1106 aSCO = _mapOfSCO[theEntry];
1108 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1109 aSCO = SALOMEDSImpl_SComponent(aLabel);
1110 _mapOfSCO[theEntry] = aSCO;
1116 //============================================================================
1117 /*! Function : GetSComponent
1120 //============================================================================
1121 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1123 return SALOMEDSImpl_SComponent(theLabel);
1126 //============================================================================
1127 /*! Function : GetSObject
1130 //============================================================================
1131 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry)
1133 SALOMEDSImpl_SObject aSO;
1134 if(_mapOfSO.find(theEntry) != _mapOfSO.end())
1135 aSO = _mapOfSO[theEntry];
1137 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1138 aSO = SALOMEDSImpl_SObject(aLabel);
1139 _mapOfSO[theEntry] = aSO;
1145 //============================================================================
1146 /*! Function : GetSObject
1149 //============================================================================
1150 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1152 return SALOMEDSImpl_SObject(theLabel);
1155 //============================================================================
1156 /*! Function : GetAttribute
1159 //============================================================================
1160 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry,
1161 const std::string& theType)
1163 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1164 DF_Attribute* anAttr;
1165 aSO.FindAttribute(anAttr, theType);
1169 //============================================================================
1170 /*! Function : DumpStudy
1173 //============================================================================
1174 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
1175 const std::string& theBaseName,
1177 SALOMEDSImpl_DriverFactory* theFactory)
1181 if(theFactory == NULL) {
1182 _errorCode = "Null factory for creation of Engines";
1186 std::vector<std::string> aSeq;
1187 std::string aCompType, aFactoryType;
1189 //Build a list of all components in the Study
1190 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1192 for (; itcomponent.More(); itcomponent.Next()) {
1193 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1194 aCompType = sco.ComponentDataType();
1195 //GEOM and MED are independent components
1196 if (aCompType == "GEOM" || aCompType == "MED")
1197 aSeq.insert(aSeq.begin(), aCompType);
1199 aSeq.push_back(aCompType);
1203 std::string aFileName =
1204 thePath + std::string("\\") + theBaseName + std::string(".py");
1206 std::string aFileName =
1207 thePath + std::string("/") + theBaseName + std::string(".py");
1210 //Create a file that will contain a main Study script
1212 fp.open(aFileName.c_str(), std::ios::out);
1215 bool isOpened = fp.is_open();
1217 bool isOpened = fp.rdbuf()->is_open();
1221 _errorCode = std::string("Can't create a file ")+aFileName;
1225 std::string aBatchModeScript = "salome";
1227 //Output to the main Study script required Python modules import,
1228 //set sys.path and add a creation of the study.
1231 fp << GetDumpStudyComment() << std::endl;
1234 fp << "import sys" << std::endl;
1235 fp << "import " << aBatchModeScript << std::endl << std::endl;
1237 // initialization function
1238 fp << aBatchModeScript << ".salome_init()" << std::endl << std::endl;
1240 // notebook initialization
1241 fp << _GetNoteBookAccess();
1243 // extend sys.path with the directory where the script is being dumped to
1244 fp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
1246 // dump NoteBook variables
1247 fp << _GetStudyVariablesScript();
1249 // dump visual parameters if necessary
1250 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1251 int lastSavePoint = -1;
1253 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1254 if(lastSavePoint > 0) {
1255 fp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
1259 std::vector<std::string> aSeqOfFileNames;
1261 // dump all components and create the components specific scripts
1263 int aLength = aSeq.size();
1264 for(int i = 1; i <= aLength; i++) {
1266 aCompType = aSeq[i-1];
1267 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1268 SALOMEDSImpl_Driver* aDriver = NULL;
1269 // if there is an associated Engine call its method for saving
1270 std::string IOREngine;
1272 if (!sco.ComponentIOR(IOREngine)) {
1273 if (!aCompType.empty()) {
1275 aDriver = theFactory->GetDriverByType(aCompType);
1277 if (aDriver != NULL) {
1278 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1279 if(!SB->LoadWith(sco, aDriver)) {
1280 _errorCode = SB->GetErrorCode();
1288 aDriver = theFactory->GetDriverByIOR(IOREngine);
1291 _errorCode = "Can not restore information to dump it";
1295 if(aDriver == NULL) continue;
1298 long aStreamLength = 0;
1299 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
1300 if ( !isValidScript )
1303 //Create a file that will contain the component specific script
1306 aFileName=thePath+std::string("\\");
1308 aFileName=thePath+std::string("/");
1310 std::string aScriptName;
1311 aScriptName += theBaseName;
1313 aScriptName += aCompType;
1315 aFileName += aScriptName+ std::string(".py");
1316 aSeqOfFileNames.push_back(aFileName);
1318 fp2.open(aFileName.c_str(), std::ios::out);
1321 isOpened = fp2.is_open();
1323 isOpened = fp2.rdbuf()->is_open();
1327 _errorCode = std::string("Can't create a file ")+aFileName;
1328 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1332 //Output the Python script generated by the component in the newly created file.
1333 fp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
1334 fp2 << aStream->Data();
1337 if(aStream) delete aStream;
1339 //Add to the main script a call to RebuildData of the generated by the component the Python script
1340 fp << "import " << aScriptName << std::endl;
1341 fp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
1345 fp << "if salome.sg.hasDesktop():" << std::endl;
1346 fp << "\tsalome.sg.updateObjBrowser(1)" << std::endl;
1348 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1349 fp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
1357 //=======================================================================
1358 //function : GetDumpStudyComment
1359 //purpose : return a header comment for a DumpStudy script
1360 //=======================================================================
1362 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1364 std::stringstream txt;
1365 txt << "# -*- coding: iso-8859-1 -*-" << std::endl << std::endl;
1366 txt << "###" << std::endl;
1367 txt << "### This file is generated automatically by SALOME v"
1368 << KERNEL_VERSION_STR
1369 << " with dump python functionality";
1370 if ( theComponentName )
1371 txt << " (" << theComponentName << " component)";
1373 txt << "###" << std::endl;
1377 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1379 const std::string& Tab,
1380 SALOMEDSImpl_Study* theStudy);
1382 //============================================================================
1386 //============================================================================
1387 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
1389 //Create a file that will contain a main Study script
1391 fp.open(theFileName.c_str(), std::ios::out);
1394 bool isOpened = fp.is_open();
1396 bool isOpened = fp.rdbuf()->is_open();
1400 _errorCode = std::string("Can't create a file ")+theFileName;
1401 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
1405 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1406 fp << "0:1" << std::endl;
1407 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1408 std::string aTab(" ");
1409 for(; Itr.More(); Itr.Next()) {
1410 dumpSO(Itr.Value(), fp, aTab, this);
1417 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1419 const std::string& Tab,
1420 SALOMEDSImpl_Study* theStudy)
1422 std::string aTab(Tab), anID(theSO.GetID());
1423 fp << aTab << anID << std::endl;
1424 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1425 for(int i = 0; i<attribs.size(); i++) {
1426 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1432 std::string aType = anAttr->GetClassType();
1433 fp << Tab << " -- " << aType;
1435 if(aType == std::string("AttributeReal")) {
1436 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1438 else if(aType == std::string("AttributeInteger")) {
1439 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1441 else if(aType == std::string("AttributeName")) {
1442 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1444 else if(aType == std::string("AttributeComment")) {
1445 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1447 else if(aType == std::string("AttributeReference")) {
1448 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1453 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1454 std::string aNewTab(" ");
1456 for(; Itr.More(); Itr.Next()) {
1457 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1463 void SALOMEDSImpl_Study::Modify()
1466 _doc->SetModified(true);
1469 //============================================================================
1473 //============================================================================
1474 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1476 if (theSavePoint < 0) return NULL;
1477 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1478 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1479 if (!so) so = builder->NewComponent((char*)theID);
1480 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1482 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1483 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1484 if ( !savePointLabel.IsNull() )
1485 so = GetSObject( savePointLabel );
1486 else // ... if it does not exist - create a new one
1487 so = builder->NewObjectToTag( so, theSavePoint );
1492 builder->FindAttribute(so, A, "AttributeParameter");
1493 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1494 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1496 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1501 //============================================================================
1505 //============================================================================
1506 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1507 const char* theModuleName,
1510 if(theSavePoint <= 0) return NULL;
1511 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1512 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1513 SALOMEDSImpl_AttributeParameter* par = NULL;
1515 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1516 std::string moduleName(theModuleName);
1517 for(; it.More(); it.Next()) {
1518 SALOMEDSImpl_SObject so(it.Value());
1519 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1520 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1521 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1525 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1526 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1527 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1528 par->SetString("AP_MODULE_NAME", moduleName);
1532 //============================================================================
1533 /*! Function : SetStudyLock
1536 //============================================================================
1537 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1539 _lockers.push_back(theLockerID);
1542 //============================================================================
1543 /*! Function : IsStudyLocked
1546 //============================================================================
1547 bool SALOMEDSImpl_Study::IsStudyLocked()
1549 return (_lockers.size() > 0);
1552 //============================================================================
1553 /*! Function : UnLockStudy
1556 //============================================================================
1557 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1559 std::vector<std::string>::iterator vsI = _lockers.begin();
1560 int length = _lockers.size();
1561 bool isFound = false;
1562 std::string id(theLockerID);
1563 for(int i = 0; i<length; i++, vsI++) {
1564 if(id == _lockers[i]) {
1569 if(isFound) _lockers.erase(vsI);
1572 //============================================================================
1573 /*! Function : GetLockerID
1576 //============================================================================
1577 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
1582 //============================================================================
1583 /*! Function : SetVariable
1586 //============================================================================
1587 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
1588 const double theValue,
1589 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1591 bool modified = false;
1592 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1594 if( aGVar == NULL ) {
1596 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1598 aSVar->setValue(theValue);
1599 myNoteBookVars.push_back(aSVar);
1603 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1604 modified = aSVar->setValue(theValue) || modified;
1605 modified = aSVar->setType(theType) || modified;
1612 //============================================================================
1613 /*! Function : SetStringVariable
1616 //============================================================================
1617 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
1618 const std::string& theValue,
1619 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1621 bool modified = false;
1622 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1624 if( aGVar == NULL ) {
1626 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1628 aSVar->setStringValue(theValue);
1629 myNoteBookVars.push_back(aSVar);
1633 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1634 modified = aSVar->setStringValue(theValue) || modified;
1635 modified = aSVar->setType(theType) || modified;
1642 //============================================================================
1643 /*! Function : SetStringVariableAsDouble
1646 //============================================================================
1647 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
1648 const double theValue,
1649 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1651 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1652 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1653 aSVar->setValue(theValue);
1656 //============================================================================
1657 /*! Function : GetReal
1660 //============================================================================
1661 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
1663 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1666 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1667 return aSVar->getValue();
1672 //============================================================================
1673 /*! Function : GetString
1676 //============================================================================
1677 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
1679 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1682 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1683 return aSVar->getStringValue();
1688 //============================================================================
1689 /*! Function : IsTypeOf
1692 //============================================================================
1693 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
1694 SALOMEDSImpl_GenericVariable::
1695 VariableTypes theType) const
1697 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1700 return aGVar->Type() == theType;
1705 //============================================================================
1706 /*! Function : IsVariable
1709 //============================================================================
1710 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
1712 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1713 return (aGVar != NULL);
1716 //============================================================================
1717 /*! Function : GetVariableNames
1720 //============================================================================
1721 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
1723 std::vector<std::string> aResult;
1725 for(int i = 0; i < myNoteBookVars.size(); i++)
1726 aResult.push_back(myNoteBookVars[i]->Name());
1731 //============================================================================
1732 /*! Function : AddVariable
1735 //============================================================================
1736 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1738 myNoteBookVars.push_back(theVariable);
1741 //============================================================================
1742 /*! Function : AddVariable
1745 //============================================================================
1746 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1748 SALOMEDSImpl_GenericVariable* aResult = NULL;
1749 for(int i = 0; i < myNoteBookVars.size();i++) {
1750 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1751 aResult = myNoteBookVars[i];
1758 //============================================================================
1759 /*! Function : RemoveVariable
1762 //============================================================================
1763 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
1765 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1769 std::string aValue = aVariable->SaveToScript();
1770 ReplaceVariableAttribute( theVarName, aValue );
1772 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1773 for( ; it != itEnd; it++ )
1775 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1776 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1778 myNoteBookVars.erase( it );
1787 //============================================================================
1788 /*! Function : RenameVariable
1791 //============================================================================
1792 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
1794 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1798 ReplaceVariableAttribute( theVarName, theNewVarName );
1800 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1801 for( ; it != itEnd; it++ )
1803 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1804 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1806 aVariableRef->setName( theNewVarName );
1815 //============================================================================
1816 /*! Function : IsVariableUsed
1819 //============================================================================
1820 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
1822 return FindVariableAttribute( theVarName );
1825 //============================================================================
1826 /*! Function : FindVariableAttribute
1829 //============================================================================
1830 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1831 SALOMEDSImpl_SObject theSObject,
1832 const std::string& theName)
1834 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1835 for( ; anIter.More(); anIter.Next() )
1836 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1839 DF_Attribute* anAttr;
1840 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1842 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1844 std::string aString = aStringAttr->Value();
1846 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
1847 for( int i = 0, n = aSections.size(); i < n; i++ )
1849 std::vector<std::string> aVector = aSections[i];
1850 for( int j = 0, m = aVector.size(); j < m; j++ )
1852 std::string aStr = aVector[j];
1853 if( aStr.compare( theName ) == 0 )
1862 //============================================================================
1863 /*! Function : FindVariableAttribute
1866 //============================================================================
1867 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1869 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1870 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1871 for( ; aCompIter.More(); aCompIter.Next() )
1873 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1874 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1880 //============================================================================
1881 /*! Function : ReplaceVariableAttribute
1884 //============================================================================
1885 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1886 SALOMEDSImpl_SObject theSObject,
1887 const std::string& theSource,
1888 const std::string& theDest)
1890 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1891 for( ; anIter.More(); anIter.Next() )
1892 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1894 DF_Attribute* anAttr;
1895 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1897 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1899 bool isChanged = false;
1900 std::string aNewString, aCurrentString = aStringAttr->Value();
1902 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
1903 for( int i = 0, n = aSections.size(); i < n; i++ )
1905 std::vector<std::string> aVector = aSections[i];
1906 for( int j = 0, m = aVector.size(); j < m; j++ )
1908 std::string aStr = aVector[j];
1909 if( aStr.compare( theSource ) == 0 )
1915 aNewString.append( aStr );
1917 aNewString.append( ":" );
1920 aNewString.append( "|" );
1924 aStringAttr->SetValue( aNewString );
1929 //============================================================================
1930 /*! Function : ReplaceVariableAttribute
1933 //============================================================================
1934 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
1936 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1937 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1938 for( ; aCompIter.More(); aCompIter.Next() )
1940 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1941 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
1945 //============================================================================
1946 /*! Function : ParseVariables
1949 //============================================================================
1950 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
1952 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
1955 //============================================================================
1956 /*! Function : EnableUseCaseAutoFilling
1959 //============================================================================
1960 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
1962 _errorCode = ""; _autoFill = isEnabled;
1964 _builder->SetOnAddSObject(_cb);
1965 _builder->SetOnRemoveSObject(_cb);
1968 _builder->SetOnAddSObject(NULL);
1969 _builder->SetOnRemoveSObject(NULL);
1973 //============================================================================
1974 /*! Function : GetIORs
1977 //============================================================================
1978 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
1980 std::vector<std::string> anIORs;
1981 std::map<std::string, DF_Label>::const_iterator MI;
1982 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
1983 anIORs.push_back(MI->first);
1988 //============================================================================
1989 /*! Function : addSO_Notification
1990 * Purpose : This function tells all the observers that a SO has been added
1992 //============================================================================
1993 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
1996 return _notifier->addSO_Notification(theSObject);
2001 //============================================================================
2002 /*! Function : removeSO_Notification
2003 * Purpose : This function tells all the observers that a SO has been removed
2005 //============================================================================
2006 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2009 return _notifier->removeSO_Notification(theSObject);
2014 //============================================================================
2015 /*! Function : modifySO_Notification
2016 * Purpose : This function tells all the observers that a SO has been modified
2018 //============================================================================
2019 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject)
2022 return _notifier->modifySO_Notification(theSObject);
2027 //============================================================================
2028 /*! Function : setNotifier
2029 * Purpose : register a notifier
2031 //============================================================================
2032 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)