1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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);
77 //Put on the root label a StudyHandle attribute to store the address of this object
78 //It will be used to retrieve the study object by DF_Label that belongs to the study
79 SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this);
83 //============================================================================
84 /*! Function : ~SALOMEDSImpl_Study
85 * Purpose : SALOMEDSImpl_Study destructor
87 //============================================================================
88 SALOMEDSImpl_Study::~SALOMEDSImpl_Study()
92 delete _useCaseBuilder;
95 //============================================================================
96 /*! Function : GetPersistentReference
97 * Purpose : Get persistent reference of study (idem URL())
99 //============================================================================
100 std::string SALOMEDSImpl_Study::GetPersistentReference()
105 //============================================================================
106 /*! Function : GetTransientReference
107 * Purpose : Get IOR of the Study (registred in Document in doc->Root)
109 //============================================================================
110 std::string SALOMEDSImpl_Study::GetTransientReference()
113 std::string IOR = "";
115 SALOMEDSImpl_AttributeIOR* Att;
116 DF_Label _lab = _doc->Root();
117 if ((Att=(SALOMEDSImpl_AttributeIOR*)_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
121 _errorCode = "IOR is empty";
127 void SALOMEDSImpl_Study::SetTransientReference(const std::string& theIOR)
131 SALOMEDSImpl_AttributeStudyProperties* aProp = GetProperties();
132 int aLocked = aProp->IsLocked();
133 if (aLocked) aProp->SetLocked(false);
135 // Assign the value of the IOR in the study->root
136 SALOMEDSImpl_AttributeIOR::Set(_doc->Main().Root(), theIOR);
138 if (aLocked) aProp->SetLocked(true);
141 //============================================================================
142 /*! Function : IsEmpty
143 * Purpose : Detect if study is empty
145 //============================================================================
146 bool SALOMEDSImpl_Study::IsEmpty()
149 if (!_doc) return true;
150 return _doc->IsEmpty();
153 //============================================================================
154 /*! Function : FindComponent
155 * Purpose : Find a Component with ComponentDataType = aComponentName
157 //============================================================================
158 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponent (const std::string& aComponentName)
163 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
164 SALOMEDSImpl_SComponent compo;
166 for (; itcomp.More(); itcomp.Next()) {
167 SALOMEDSImpl_SComponent SC = itcomp.Value();
168 name = SC.ComponentDataType();
169 if(aComponentName == name) {
177 _errorCode = "No component was found";
183 //============================================================================
184 /*! Function : FindComponentID
185 * Purpose : Find a Component from it's ID
187 //============================================================================
188 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::FindComponentID(const std::string& aComponentID)
192 // Iterate on each components defined in the study
193 // Get the component ID and compare with aComponentID
196 SALOMEDSImpl_SComponent compo;
198 SALOMEDSImpl_SComponentIterator itcomp = NewComponentIterator();
199 for (; itcomp.More(); itcomp.Next()) {
200 SALOMEDSImpl_SComponent SC = itcomp.Value();
202 if(aComponentID == ID)
211 _errorCode = "No component was found";
218 //============================================================================
219 /*! Function : FindObject
220 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
222 //============================================================================
223 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObject(const std::string& anObjectName)
227 // Iterate to all components defined in the study
228 // After testing the component name, iterate in all objects defined under
229 // components (function _FindObject)
231 SALOMEDSImpl_SObject RefSO;
233 SALOMEDSImpl_SComponentIterator it = NewComponentIterator();
234 for (; it.More();it.Next()){
237 SALOMEDSImpl_SComponent SC = it.Value();
238 if (SC.GetName() == anObjectName)
244 if (!_find) RefSO = _FindObject(SC, anObjectName, _find);
247 if(!RefSO) _errorCode = "No object was found";
251 //============================================================================
252 /*! Function : FindObjectID
253 * Purpose : Find an Object with ID = anObjectID
255 //============================================================================
256 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectID(const std::string& anObjectID)
259 SALOMEDSImpl_SObject so;
261 // Convert aSO->GetID in DF_Label.
262 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, false);
265 _errorCode = "No label was found by ID";
268 return GetSObject(Lab);
272 //============================================================================
273 /*! Function : CreateObjectID
274 * Purpose : Creates an Object with ID = anObjectID
276 //============================================================================
277 SALOMEDSImpl_SObject SALOMEDSImpl_Study::CreateObjectID(const std::string& anObjectID)
280 SALOMEDSImpl_SObject so;
282 // Convert aSO->GetID in DF_Label.
283 DF_Label Lab = DF_Label::Label(_doc->Main(), anObjectID, true);
286 _errorCode = "Can not create a label";
289 return GetSObject(Lab);
293 //============================================================================
294 /*! Function : FindObjectByName
295 * Purpose : Find Objects with SALOMEDSImpl_Name = anObjectName in a Component
296 * : with ComponentDataType = aComponentName
298 //============================================================================
299 std::vector<SALOMEDSImpl_SObject> SALOMEDSImpl_Study::FindObjectByName(const std::string& anObjectName,
300 const std::string& aComponentName)
304 std::vector<SALOMEDSImpl_SObject> listSO;
306 SALOMEDSImpl_SComponent compo = FindComponent(aComponentName) ;
308 _errorCode = "Can not find the component";
312 // Iterate on each object and subobject of the component
313 // If objectName is found add it to the list of SObjects
314 std::string childName ;
316 std::string compoId = compo.GetID();
317 SALOMEDSImpl_ChildIterator it = NewChildIterator(compo);
318 for ( ; it.More(); it.Next() ) {
320 SALOMEDSImpl_SObject CSO = it.Value();
321 if ( CSO.GetName() == anObjectName ) {
323 listSO.push_back(CSO) ;
326 /* looks also for eventual children */
328 CSO = _FindObject( CSO, anObjectName, found ) ;
330 listSO.push_back(CSO) ;
339 //============================================================================
340 /*! Function : FindObjectIOR
341 * Purpose : Find an Object with IOR = anObjectIOR
343 //============================================================================
344 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectIOR(const std::string& anObjectIOR)
348 SALOMEDSImpl_SObject aResult ;
350 // searching in the datamap for optimization
351 std::map<std::string, DF_Label>::iterator it=myIORLabels.find(anObjectIOR);
352 if (it != myIORLabels.end()) {
353 aResult = GetSObject(it->second);
354 // 11 oct 2002: forbidden attributes must be checked here
355 if (!aResult.GetLabel().IsAttribute(SALOMEDSImpl_AttributeIOR::GetID())) {
356 myIORLabels.erase(anObjectIOR);
357 aResult = SALOMEDSImpl_SObject();
361 if(!aResult) _errorCode = "No object was found";
365 //============================================================================
366 /*! Function : FindObjectByPath
367 * Purpose : Find an Object by its path = thePath
369 //============================================================================
370 SALOMEDSImpl_SObject SALOMEDSImpl_Study::FindObjectByPath(const std::string& thePath)
374 std::string aPath(thePath), aToken;
375 SALOMEDSImpl_SObject aSO;
376 int aLength = aPath.size();
377 bool isRelative = false;
379 if(aLength == 0) { //Empty path - return the current context
380 return GetSObject(_current);
383 if(aPath[0] != '/') //Relative path
386 DF_ChildIterator anIterator;
388 SALOMEDSImpl_AttributeName* anAttr;
391 if(_current.IsNull()) return aSO;
392 anIterator.Init(_current, false);
395 if(aPath.size() == 1 && aPath[0] == '/') { //Root
396 return GetSObject(_doc->Main());
398 anIterator.Init(_doc->Main(), false);
401 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
402 for(int i = 0, len = vs.size(); i<len; i++) {
405 if(aToken.size() == 0) break;
407 for ( ; anIterator.More(); anIterator.Next() ) {
408 aLabel = anIterator.Value();
409 if((anAttr=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
410 if(anAttr->Value() == aToken) {
411 if(i == (len-1)) { //The searched label is found (no part of the path is left)
412 return GetSObject(aLabel);
415 anIterator.Init(aLabel, false);
423 if(!aSO) _errorCode = "No object was found";
427 //============================================================================
428 /*! Function : GetObjectPath
431 //============================================================================
432 std::string SALOMEDSImpl_Study::GetObjectPath(const SALOMEDSImpl_SObject& theObject)
436 std::string aPath("");
438 _errorCode = "Null object";
442 std::string aName = theObject.GetName();
443 if(!aName.empty() && aName != "" ) {
444 std::string aValue("/");
448 SALOMEDSImpl_SObject aFather = theObject.GetFather();
450 aName = aFather.GetName();
451 if(!aName.empty() && aName != "") {
452 aValue = GetObjectPath(aFather);
453 aPath = aValue + aPath;
462 //============================================================================
463 /*! Function : GetObjectPathByIOR
466 //============================================================================
467 std::string SALOMEDSImpl_Study::GetObjectPathByIOR(const std::string& theIOR)
472 SALOMEDSImpl_SObject so = FindObjectIOR(theIOR);
474 _errorCode = "No SObject was found by IOR";
478 return GetObjectPath(so);
482 //============================================================================
483 /*! Function : SetContext
484 * Purpose : Sets the current context
486 //============================================================================
487 bool SALOMEDSImpl_Study::SetContext(const std::string& thePath)
490 if(thePath.empty()) {
491 _errorCode = "InvalidPath";
495 std::string aPath(thePath), aContext("");
496 bool isInvalid = false;
497 SALOMEDSImpl_SObject aSO;
499 if(aPath[0] != '/') { //Relative path
500 aContext = GetContext();
508 aSO = FindObjectByPath(aContext);
514 if(isInvalid || !aSO) {
515 _errorCode = "InvalidContext";
519 DF_Label aLabel = aSO.GetLabel();
520 if(aLabel.IsNull()) {
521 _errorCode = "InvalidContext";
525 _current = aLabel; //Set the current context
530 //============================================================================
531 /*! Function : GetContext
532 * Purpose : Gets the current context
534 //============================================================================
535 std::string SALOMEDSImpl_Study::GetContext()
539 if(_current.IsNull()) {
540 _errorCode = "InvaidContext";
543 SALOMEDSImpl_SObject so = GetSObject(_current);
544 return GetObjectPath(so);
547 //============================================================================
548 /*! Function : GetObjectNames
549 * Purpose : method to get all object names in the given context (or in the current context, if 'theContext' is empty)
551 //============================================================================
552 std::vector<std::string> SALOMEDSImpl_Study::GetObjectNames(const std::string& theContext)
556 std::vector<std::string> aResultSeq;
558 if (theContext.empty()) {
561 DF_Label aTmp = _current;
562 SetContext(theContext);
566 if (aLabel.IsNull()) {
567 _errorCode = "InvalidContext";
571 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
572 for (; anIter.More(); anIter.Next()) {
573 DF_Label aLabel = anIter.Value();
574 SALOMEDSImpl_AttributeName* aName;
575 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
576 aResultSeq.push_back(aName->Value());
582 //============================================================================
583 /*! Function : GetDirectoryNames
584 * Purpose : method to get all directory names in the given context (or in the current context, if 'theContext' is empty)
586 //============================================================================
587 std::vector<std::string> SALOMEDSImpl_Study::GetDirectoryNames(const std::string& theContext)
591 std::vector<std::string> aResultSeq;
593 if (theContext.empty()) {
596 DF_Label aTmp = _current;
597 SetContext(theContext);
601 if (aLabel.IsNull()) {
602 _errorCode = "InvalidContext";
606 DF_ChildIterator anIter (aLabel, true); // iterate first-level children at all sublevels
607 for (; anIter.More(); anIter.Next()) {
608 DF_Label aLabel = anIter.Value();
609 SALOMEDSImpl_AttributeLocalID* anID;
610 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
611 if (anID->Value() == DIRECTORYID) {
612 SALOMEDSImpl_AttributeName* aName;
613 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID()))) {
614 aResultSeq.push_back(aName->Value());
623 //============================================================================
624 /*! Function : GetFileNames
625 * Purpose : method to get all file names in the given context (or in the current context, if 'theContext' is empty)
627 //============================================================================
628 std::vector<std::string> SALOMEDSImpl_Study::GetFileNames(const std::string& theContext)
632 std::vector<std::string> aResultSeq;
634 if (theContext.empty()) {
637 DF_Label aTmp = _current;
638 SetContext(theContext);
642 if (aLabel.IsNull()) {
643 _errorCode = "InvalidContext";
647 DF_ChildIterator anIter (aLabel, true); // iterate all subchildren at all sublevels
648 for (; anIter.More(); anIter.Next()) {
649 DF_Label aLabel = anIter.Value();
650 SALOMEDSImpl_AttributeLocalID* anID;
651 if ((anID=(SALOMEDSImpl_AttributeLocalID*)aLabel.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID()))) {
652 if (anID->Value() == FILELOCALID) {
653 SALOMEDSImpl_AttributePersistentRef* aName;
654 if ((aName=(SALOMEDSImpl_AttributePersistentRef*)aLabel.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
655 std::string aFileName = aName->Value();
656 if (aFileName.size() > 0)
657 aResultSeq.push_back(aFileName.substr(strlen(FILEID), aFileName.size()));
666 //============================================================================
667 /*! Function : GetComponentNames
668 * Purpose : method to get all components names
670 //============================================================================
671 std::vector<std::string> SALOMEDSImpl_Study::GetComponentNames(const std::string& theContext)
675 std::vector<std::string> aResultSeq;
676 DF_ChildIterator anIter(_doc->Main(), false); // iterate all subchildren at first level
677 for(; anIter.More(); anIter.Next()) {
678 DF_Label aLabel = anIter.Value();
679 SALOMEDSImpl_AttributeName* aName;
680 if ((aName=(SALOMEDSImpl_AttributeName*)aLabel.FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
681 aResultSeq.push_back(aName->Value());
687 //============================================================================
688 /*! Function : NewChildIterator
689 * Purpose : Create a ChildIterator from an SObject
691 //============================================================================
692 SALOMEDSImpl_ChildIterator SALOMEDSImpl_Study::NewChildIterator(const SALOMEDSImpl_SObject& aSO)
695 return SALOMEDSImpl_ChildIterator(aSO);
699 //============================================================================
700 /*! Function : NewComponentIterator
701 * Purpose : Create a SComponentIterator
703 //============================================================================
704 SALOMEDSImpl_SComponentIterator SALOMEDSImpl_Study::NewComponentIterator()
707 return SALOMEDSImpl_SComponentIterator(_doc);
711 //============================================================================
712 /*! Function : NewBuilder
713 * Purpose : Create a StudyBuilder
715 //============================================================================
716 SALOMEDSImpl_StudyBuilder* SALOMEDSImpl_Study::NewBuilder()
720 _builder->SetOnAddSObject(_cb);
721 _builder->SetOnRemoveSObject(_cb);
727 //============================================================================
729 * Purpose : get study name
731 //============================================================================
732 std::string SALOMEDSImpl_Study::Name()
738 //============================================================================
740 * Purpose : set study name
742 //============================================================================
743 void SALOMEDSImpl_Study::Name(const std::string& name)
749 //============================================================================
750 /*! Function : IsSaved
751 * Purpose : get if study has been saved
753 //============================================================================
754 bool SALOMEDSImpl_Study::IsSaved()
760 //============================================================================
761 /*! Function : IsSaved
762 * Purpose : set if study has been saved
764 //============================================================================
765 void SALOMEDSImpl_Study::IsSaved(bool save)
769 if(save) _doc->SetModified(false);
772 //============================================================================
773 /*! Function : IsModified
774 * Purpose : Detect if a Study has been modified since it has been saved
776 //============================================================================
777 bool SALOMEDSImpl_Study::IsModified()
781 // True if is modified
782 if (_doc && _doc->IsModified()) return true;
787 //============================================================================
789 * Purpose : get URL of the study (persistent reference of the study)
791 //============================================================================
792 std::string SALOMEDSImpl_Study::URL()
798 //============================================================================
800 * Purpose : set URL of the study (persistent reference of the study)
802 //============================================================================
803 void SALOMEDSImpl_Study::URL(const std::string& url)
808 /*jfa: Now name of SALOMEDS study will correspond to name of SalomeApp study
809 std::string tmp(_URL);
811 char *aName = (char*)tmp.ToCString();
812 char *adr = strtok(aName, "/");
816 adr = strtok(NULL, "/");
823 //============================================================================
824 /*! Function : _FindObject
825 * Purpose : Find an Object with SALOMEDSImpl_Name = anObjectName
827 //============================================================================
828 SALOMEDSImpl_SObject SALOMEDSImpl_Study::_FindObject(const SALOMEDSImpl_SObject& SO,
829 const std::string& theObjectName,
832 SALOMEDSImpl_SObject RefSO;
833 if(!SO) return RefSO;
835 // Iterate on each objects and subobjects of the component
836 // If objectName find, stop the loop and get the object reference
837 SALOMEDSImpl_AttributeName* anAttr;
839 std::string soid = SO.GetID();
840 DF_ChildIterator it(SO.GetLabel());
841 for (; it.More(); it.Next()){
844 if ((anAttr=(SALOMEDSImpl_AttributeName*)it.Value().FindAttribute(SALOMEDSImpl_AttributeName::GetID())))
846 std::string Val(anAttr->Value());
847 if (Val == theObjectName)
849 RefSO = GetSObject(it.Value());
853 if (!_find) RefSO = _FindObject(GetSObject(it.Value()), theObjectName, _find);
859 //============================================================================
860 /*! Function : _FindObjectIOR
861 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
863 //============================================================================
865 SALOMEDSImpl_Study::_FindObjectIOR(const SALOMEDSImpl_SObject& SO,
866 const std::string& theObjectIOR,
869 SALOMEDSImpl_SObject RefSO, aSO;
870 if(!SO) return RefSO;
872 // Iterate on each objects and subobjects of the component
873 // If objectName find, stop the loop and get the object reference
874 SALOMEDSImpl_AttributeIOR* anAttr;
876 DF_ChildIterator it(SO.GetLabel());
877 for (; it.More();it.Next()){
880 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)it.Value().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID())))
882 std::string Val(anAttr->Value());
883 if (Val == theObjectIOR)
885 RefSO = GetSObject(it.Value());
889 aSO = GetSObject(it.Value());
890 if (!_find) RefSO = _FindObjectIOR(aSO, theObjectIOR, _find);
896 //============================================================================
897 /*! Function : _GetNoteBookAccessor
898 * Purpose : Find an Object with SALOMEDSImpl_IOR = anObjectIOR
900 //============================================================================
901 std::string SALOMEDSImpl_Study::_GetNoteBookAccessor(){
902 return std::string("notebook");
905 //============================================================================
906 /*! Function : _GetStudyVariablesScript
909 //============================================================================
910 std::string SALOMEDSImpl_Study::_GetStudyVariablesScript()
912 std::string dump("");
914 if(myNoteBookVars.empty())
917 Kernel_Utils::Localizer loc;
919 dump += "####################################################\n";
920 dump += "## Begin of NoteBook variables section ##\n";
921 dump += "####################################################\n";
923 std::string set_method = _GetNoteBookAccessor()+".set(";
925 std::string varValue;
926 for(int i = 0 ; i < myNoteBookVars.size();i++ ) {
927 varName = myNoteBookVars[i]->Name();
928 varValue = myNoteBookVars[i]->SaveToScript();
929 dump+=set_method+"\""+varName+"\", "+varValue+")\n";
932 dump += "####################################################\n";
933 dump += "## End of NoteBook variables section ##\n";
934 dump += "####################################################\n";
939 //============================================================================
940 /*! Function : _GetNoteBookAccess
943 //============================================================================
944 std::string SALOMEDSImpl_Study::_GetNoteBookAccess(const std::string& theStudyVar)
946 std::string notebook = "import salome_notebook\n";
947 notebook += _GetNoteBookAccessor() + " = salome_notebook.NoteBook(" + theStudyVar + ")" ;
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()
1097 _doc->GetApplication()->Close(_doc);
1104 //============================================================================
1105 /*! Function : GetSComponent
1108 //============================================================================
1109 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const std::string& theEntry)
1111 SALOMEDSImpl_SComponent aSCO;
1112 if(_mapOfSCO.find(theEntry) != _mapOfSCO.end())
1113 aSCO = _mapOfSCO[theEntry];
1115 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1116 aSCO = SALOMEDSImpl_SComponent(aLabel);
1117 _mapOfSCO[theEntry] = aSCO;
1123 //============================================================================
1124 /*! Function : GetSComponent
1127 //============================================================================
1128 SALOMEDSImpl_SComponent SALOMEDSImpl_Study::GetSComponent(const DF_Label& theLabel)
1130 return SALOMEDSImpl_SComponent(theLabel);
1133 //============================================================================
1134 /*! Function : GetSObject
1137 //============================================================================
1138 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const std::string& theEntry)
1140 SALOMEDSImpl_SObject aSO;
1141 std::map<std::string, SALOMEDSImpl_SObject>::iterator it=_mapOfSO.find(theEntry);
1142 if(it != _mapOfSO.end())
1145 DF_Label aLabel = DF_Label::Label(_doc->Main(), theEntry);
1146 aSO = SALOMEDSImpl_SObject(aLabel);
1147 _mapOfSO[theEntry] = aSO;
1153 //============================================================================
1154 /*! Function : GetSObject
1157 //============================================================================
1158 SALOMEDSImpl_SObject SALOMEDSImpl_Study::GetSObject(const DF_Label& theLabel)
1160 return SALOMEDSImpl_SObject(theLabel);
1163 //============================================================================
1164 /*! Function : GetAttribute
1167 //============================================================================
1168 DF_Attribute* SALOMEDSImpl_Study::GetAttribute(const std::string& theEntry,
1169 const std::string& theType)
1171 SALOMEDSImpl_SObject aSO = GetSObject(theEntry);
1172 DF_Attribute* anAttr;
1173 aSO.FindAttribute(anAttr, theType);
1177 //! number of spaces for indentation in Python dump files (to replace \t symbols)
1178 static const int indent_size = 2;
1180 static std::string replace_tabs( const std::string& in )
1182 std::string out = in;
1184 size_t pos = out.find( '\t' );
1185 while ( pos != std::string::npos ) {
1186 out.replace( pos, 1, indent_size, ' ' );
1187 pos = out.find( '\t' );
1193 static std::string GetComponentHeader(const char* theComponentName)
1195 std::stringstream txt;
1196 txt << "###" << std::endl;
1197 txt << "### " << theComponentName << " component" << std::endl;
1198 txt << "###" << std::endl;
1202 //============================================================================
1203 /*! Function : DumpStudy
1206 //============================================================================
1207 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
1208 const std::string& theBaseName,
1211 SALOMEDSImpl_DriverFactory* theFactory)
1215 if(theFactory == NULL) {
1216 _errorCode = "Null factory for creation of Engines";
1220 std::vector<std::string> aSeq;
1221 std::string aCompType, aFactoryType;
1223 //Build a list of all components in the Study
1224 SALOMEDSImpl_SComponentIterator itcomponent = NewComponentIterator();
1226 for (; itcomponent.More(); itcomponent.Next()) {
1227 SALOMEDSImpl_SComponent sco = itcomponent.Value();
1228 aCompType = sco.ComponentDataType();
1229 //GEOM and MED are independent components
1230 if (aCompType == "GEOM" || aCompType == "MED")
1231 aSeq.insert(aSeq.begin(), aCompType);
1233 aSeq.push_back(aCompType);
1237 std::string aFileName =
1238 thePath + std::string("\\") + theBaseName + std::string(".py");
1240 std::string aFileName =
1241 thePath + std::string("/") + theBaseName + std::string(".py");
1244 //Create a file that will contain a main Study script
1246 fp.open(aFileName.c_str(), std::ios::out);
1249 bool isOpened = fp.is_open();
1251 bool isOpened = fp.rdbuf()->is_open();
1255 _errorCode = std::string("Can't create a file ")+aFileName;
1259 std::stringstream sfp;
1261 std::string aBatchModeScript = "salome";
1263 //Output to the main Study script required Python modules import,
1264 //set sys.path and add a creation of the study.
1267 sfp << GetDumpStudyComment() << std::endl;
1270 sfp << "import sys" << std::endl;
1271 sfp << "import " << aBatchModeScript << std::endl << std::endl;
1273 std::string aStudyVar = "salome.myStudy";
1274 // initialization function
1275 sfp << aBatchModeScript << ".salome_init()" << std::endl;
1276 if ( !isMultiFile ) {
1277 sfp << "theStudy = " << aStudyVar << std::endl << std::endl;
1278 aStudyVar = "theStudy";
1280 // notebook initialization
1281 sfp << _GetNoteBookAccess(aStudyVar) << std::endl;
1283 // extend sys.path with the directory where the script is being dumped to
1284 sfp << "sys.path.insert( 0, r\'" << thePath << "\')" << std::endl << std::endl;
1286 // dump NoteBook variables
1287 sfp << _GetStudyVariablesScript();
1289 // dump visual parameters if necessary
1290 bool isDumpVisuals = SALOMEDSImpl_IParameters::isDumpPython(this);
1291 int lastSavePoint = -1;
1293 lastSavePoint = SALOMEDSImpl_IParameters::getLastSavePoint(this);
1294 if(lastSavePoint > 0) {
1295 sfp << SALOMEDSImpl_IParameters::getStudyScript(this, lastSavePoint) << std::endl << std::endl;
1299 std::vector<std::string> aSeqOfFileNames;
1301 // dump all components and create the components specific scripts
1303 int aLength = aSeq.size();
1304 for(int i = 1; i <= aLength; i++) {
1306 aCompType = aSeq[i-1];
1307 SALOMEDSImpl_SComponent sco = FindComponent(aCompType);
1308 SALOMEDSImpl_Driver* aDriver = NULL;
1309 // if there is an associated Engine call its method for saving
1310 std::string IOREngine;
1312 if (!sco.ComponentIOR(IOREngine)) {
1313 if (!aCompType.empty()) {
1315 aDriver = theFactory->GetDriverByType(aCompType);
1317 if (aDriver != NULL) {
1318 SALOMEDSImpl_StudyBuilder* SB = NewBuilder();
1319 if(!SB->LoadWith(sco, aDriver)) {
1320 _errorCode = SB->GetErrorCode();
1328 aDriver = theFactory->GetDriverByIOR(IOREngine);
1331 _errorCode = "Can not restore information to dump it";
1335 if(aDriver == NULL) continue;
1338 long aStreamLength = 0;
1339 SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isMultiFile, isValidScript, aStreamLength);
1340 if ( !isValidScript )
1343 std::stringstream sfp2;
1345 //Output the Python script generated by the component in the newly created file.
1347 sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
1349 sfp2 << GetComponentHeader( aCompType.c_str() ) << std::endl;
1350 sfp2 << aStream->Data();
1352 if ( isMultiFile ) {
1353 //Create a file that will contain the component specific script
1356 aFileName=thePath+std::string("\\");
1358 aFileName=thePath+std::string("/");
1360 std::string aScriptName;
1361 aScriptName += theBaseName;
1363 aScriptName += aCompType;
1365 aFileName += aScriptName+ std::string(".py");
1366 aSeqOfFileNames.push_back(aFileName);
1368 fp2.open(aFileName.c_str(), std::ios::out);
1371 isOpened = fp2.is_open();
1373 isOpened = fp2.rdbuf()->is_open();
1377 _errorCode = std::string("Can't create a file ")+aFileName;
1378 SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
1382 // replace '\t' symbols
1383 fp2 << replace_tabs( sfp2.str() );
1387 //Add to the main script a call to RebuildData of the generated by the component the Python script
1388 sfp << "import " << aScriptName << std::endl;
1389 sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
1394 if(aStream) delete aStream;
1398 sfp << "if salome.sg.hasDesktop():" << std::endl;
1399 sfp << "\tsalome.sg.updateObjBrowser(1)" << std::endl;
1401 if(isDumpVisuals) { //Output the call to Session's method restoreVisualState
1402 sfp << "\tiparameters.getSession().restoreVisualState(1)" << std::endl;
1405 // replace '\t' symbols
1406 fp << replace_tabs( sfp.str() );
1413 //=======================================================================
1414 //function : GetDumpStudyComment
1415 //purpose : return a header comment for a DumpStudy script
1416 //=======================================================================
1418 std::string SALOMEDSImpl_Study::GetDumpStudyComment(const char* theComponentName)
1420 std::stringstream txt;
1421 txt << "# -*- coding: utf-8 -*-" << std::endl << std::endl;
1422 txt << "###" << std::endl;
1423 txt << "### This file is generated automatically by SALOME v"
1424 << KERNEL_VERSION_STR
1425 << " with dump python functionality";
1426 if ( theComponentName )
1427 txt << " (" << theComponentName << " component)";
1429 txt << "###" << std::endl;
1433 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1435 const std::string& Tab,
1436 SALOMEDSImpl_Study* theStudy);
1438 //============================================================================
1442 //============================================================================
1443 void SALOMEDSImpl_Study::dump(const std::string& theFileName)
1445 //Create a file that will contain a main Study script
1447 fp.open(theFileName.c_str(), std::ios::out);
1450 bool isOpened = fp.is_open();
1452 bool isOpened = fp.rdbuf()->is_open();
1456 _errorCode = std::string("Can't create a file ")+theFileName;
1457 std::cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << std::endl;
1461 SALOMEDSImpl_SObject aSO = FindObjectID("0:1");
1462 fp << "0:1" << std::endl;
1463 SALOMEDSImpl_ChildIterator Itr = NewChildIterator(aSO);
1464 std::string aTab(" ");
1465 for(; Itr.More(); Itr.Next()) {
1466 dumpSO(Itr.Value(), fp, aTab, this);
1473 void dumpSO(const SALOMEDSImpl_SObject& theSO,
1475 const std::string& Tab,
1476 SALOMEDSImpl_Study* theStudy)
1478 std::string aTab(Tab), anID(theSO.GetID());
1479 fp << aTab << anID << std::endl;
1480 std::vector<DF_Attribute*> attribs = theSO.GetLabel().GetAttributes();
1481 for(int i = 0; i<attribs.size(); i++) {
1482 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(attribs[i]);
1488 std::string aType = anAttr->GetClassType();
1489 fp << Tab << " -- " << aType;
1491 if(aType == std::string("AttributeReal")) {
1492 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReal*>(anAttr)->Value();
1494 else if(aType == std::string("AttributeInteger")) {
1495 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeInteger*>(anAttr)->Value();
1497 else if(aType == std::string("AttributeName")) {
1498 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeName*>(anAttr)->Value();
1500 else if(aType == std::string("AttributeComment")) {
1501 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeComment*>(anAttr)->Value();
1503 else if(aType == std::string("AttributeReference")) {
1504 fp << " : " << dynamic_cast<SALOMEDSImpl_AttributeReference*>(anAttr)->Save();
1509 SALOMEDSImpl_ChildIterator Itr = theStudy->NewChildIterator(theSO);
1510 std::string aNewTab(" ");
1512 for(; Itr.More(); Itr.Next()) {
1513 dumpSO(Itr.Value(), fp, aNewTab, theStudy);
1519 void SALOMEDSImpl_Study::Modify()
1522 _doc->SetModified(true);
1525 //============================================================================
1529 //============================================================================
1530 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
1532 if (theSavePoint < -1) return NULL;
1533 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1534 SALOMEDSImpl_SObject so = FindComponent((char*)theID);
1535 if (!so) so = builder->NewComponent((char*)theID);
1536 SALOMEDSImpl_AttributeParameter* attParam = NULL;
1538 if (theSavePoint == -1) {
1540 DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
1541 DF_Label prevPointLabel;
1542 while ( !savePointLabel.IsNull() ) {
1544 prevPointLabel = savePointLabel;
1545 savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
1547 if ( !prevPointLabel.IsNull() )
1548 so = GetSObject( prevPointLabel );
1550 if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
1551 DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
1552 if ( !savePointLabel.IsNull() )
1553 so = GetSObject( savePointLabel );
1554 else // ... if it does not exist - create a new one
1555 so = builder->NewObjectToTag( so, theSavePoint );
1560 builder->FindAttribute(so, A, "AttributeParameter");
1561 if ( !A ) { // first call of GetCommonParameters on "Interface Applicative" component
1562 A = builder->FindOrCreateAttribute(so, "AttributeParameter");
1564 attParam = dynamic_cast<SALOMEDSImpl_AttributeParameter*>( A );
1569 //============================================================================
1573 //============================================================================
1574 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const char* theID,
1575 const char* theModuleName,
1578 if(theSavePoint < -1) return NULL;
1579 SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
1580 SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
1581 SALOMEDSImpl_AttributeParameter* par = NULL;
1583 SALOMEDSImpl_ChildIterator it = NewChildIterator(main_so);
1584 std::string moduleName(theModuleName);
1585 for(; it.More(); it.Next()) {
1586 SALOMEDSImpl_SObject so(it.Value());
1587 if((par=(SALOMEDSImpl_AttributeParameter*)so.GetLabel().FindAttribute(SALOMEDSImpl_AttributeParameter::GetID()))) {
1588 if(!par->IsSet("AP_MODULE_NAME", (Parameter_Types)3)) continue; //3 -> PT_STRING
1589 if(par->GetString("AP_MODULE_NAME") == moduleName) return par;
1593 SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
1594 SALOMEDSImpl_SObject so = builder->NewObject(main_so);
1595 par = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(builder->FindOrCreateAttribute(so, "AttributeParameter"));
1596 par->SetString("AP_MODULE_NAME", moduleName);
1600 //============================================================================
1601 /*! Function : SetStudyLock
1604 //============================================================================
1605 void SALOMEDSImpl_Study::SetStudyLock(const char* theLockerID)
1607 _lockers.push_back(theLockerID);
1610 //============================================================================
1611 /*! Function : IsStudyLocked
1614 //============================================================================
1615 bool SALOMEDSImpl_Study::IsStudyLocked()
1617 return (_lockers.size() > 0);
1620 //============================================================================
1621 /*! Function : UnLockStudy
1624 //============================================================================
1625 void SALOMEDSImpl_Study::UnLockStudy(const char* theLockerID)
1627 std::vector<std::string>::iterator vsI = _lockers.begin();
1628 int length = _lockers.size();
1629 bool isFound = false;
1630 std::string id(theLockerID);
1631 for(int i = 0; i<length; i++, vsI++) {
1632 if(id == _lockers[i]) {
1637 if(isFound) _lockers.erase(vsI);
1640 //============================================================================
1641 /*! Function : GetLockerID
1644 //============================================================================
1645 std::vector<std::string> SALOMEDSImpl_Study::GetLockerID()
1650 //============================================================================
1651 /*! Function : SetVariable
1654 //============================================================================
1655 void SALOMEDSImpl_Study::SetVariable(const std::string& theVarName,
1656 const double theValue,
1657 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1659 bool modified = false;
1660 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1662 if( aGVar == NULL ) {
1664 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1666 aSVar->setValue(theValue);
1667 myNoteBookVars.push_back(aSVar);
1671 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1672 modified = aSVar->setValue(theValue) || modified;
1673 modified = aSVar->setType(theType) || modified;
1680 //============================================================================
1681 /*! Function : SetStringVariable
1684 //============================================================================
1685 void SALOMEDSImpl_Study::SetStringVariable(const std::string& theVarName,
1686 const std::string& theValue,
1687 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1689 bool modified = false;
1690 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1692 if( aGVar == NULL ) {
1694 SALOMEDSImpl_ScalarVariable* aSVar = new SALOMEDSImpl_ScalarVariable(theType, theVarName);
1696 aSVar->setStringValue(theValue);
1697 myNoteBookVars.push_back(aSVar);
1701 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar)) {
1702 modified = aSVar->setStringValue(theValue) || modified;
1703 modified = aSVar->setType(theType) || modified;
1710 //============================================================================
1711 /*! Function : SetStringVariableAsDouble
1714 //============================================================================
1715 void SALOMEDSImpl_Study::SetStringVariableAsDouble(const std::string& theVarName,
1716 const double theValue,
1717 const SALOMEDSImpl_GenericVariable::VariableTypes theType)
1719 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1720 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1721 aSVar->setValue(theValue);
1724 //============================================================================
1725 /*! Function : GetReal
1728 //============================================================================
1729 double SALOMEDSImpl_Study::GetVariableValue(const std::string& theVarName)
1731 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1734 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1735 return aSVar->getValue();
1740 //============================================================================
1741 /*! Function : GetString
1744 //============================================================================
1745 std::string SALOMEDSImpl_Study::GetStringVariableValue(const std::string& theVarName)
1747 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1750 if(SALOMEDSImpl_ScalarVariable* aSVar = dynamic_cast<SALOMEDSImpl_ScalarVariable*>(aGVar))
1751 return aSVar->getStringValue();
1756 //============================================================================
1757 /*! Function : IsTypeOf
1760 //============================================================================
1761 bool SALOMEDSImpl_Study::IsTypeOf(const std::string& theVarName,
1762 SALOMEDSImpl_GenericVariable::
1763 VariableTypes theType) const
1765 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1768 return aGVar->Type() == theType;
1773 //============================================================================
1774 /*! Function : IsVariable
1777 //============================================================================
1778 bool SALOMEDSImpl_Study::IsVariable(const std::string& theVarName) const
1780 SALOMEDSImpl_GenericVariable* aGVar = GetVariable(theVarName);
1781 return (aGVar != NULL);
1784 //============================================================================
1785 /*! Function : GetVariableNames
1788 //============================================================================
1789 std::vector<std::string> SALOMEDSImpl_Study::GetVariableNames() const
1791 std::vector<std::string> aResult;
1793 for(int i = 0; i < myNoteBookVars.size(); i++)
1794 aResult.push_back(myNoteBookVars[i]->Name());
1799 //============================================================================
1800 /*! Function : AddVariable
1803 //============================================================================
1804 void SALOMEDSImpl_Study::AddVariable(SALOMEDSImpl_GenericVariable* theVariable)
1806 myNoteBookVars.push_back(theVariable);
1809 //============================================================================
1810 /*! Function : AddVariable
1813 //============================================================================
1814 SALOMEDSImpl_GenericVariable* SALOMEDSImpl_Study::GetVariable(const std::string& theName) const
1816 SALOMEDSImpl_GenericVariable* aResult = NULL;
1817 for(int i = 0; i < myNoteBookVars.size();i++) {
1818 if(theName.compare(myNoteBookVars[i]->Name()) == 0) {
1819 aResult = myNoteBookVars[i];
1826 //============================================================================
1827 /*! Function : RemoveVariable
1830 //============================================================================
1831 bool SALOMEDSImpl_Study::RemoveVariable(const std::string& theVarName)
1833 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1837 std::string aValue = aVariable->SaveToScript();
1838 ReplaceVariableAttribute( theVarName, aValue );
1840 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1841 for( ; it != itEnd; it++ )
1843 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1844 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1846 myNoteBookVars.erase( it );
1855 //============================================================================
1856 /*! Function : RenameVariable
1859 //============================================================================
1860 bool SALOMEDSImpl_Study::RenameVariable(const std::string& theVarName, const std::string& theNewVarName)
1862 SALOMEDSImpl_GenericVariable* aVariable = GetVariable( theVarName );
1866 ReplaceVariableAttribute( theVarName, theNewVarName );
1868 std::vector<SALOMEDSImpl_GenericVariable*>::iterator it = myNoteBookVars.begin(), itEnd = myNoteBookVars.end();
1869 for( ; it != itEnd; it++ )
1871 SALOMEDSImpl_GenericVariable* aVariableRef = *it;
1872 if( aVariableRef && theVarName.compare( aVariableRef->Name() ) == 0 )
1874 aVariableRef->setName( theNewVarName );
1883 //============================================================================
1884 /*! Function : IsVariableUsed
1887 //============================================================================
1888 bool SALOMEDSImpl_Study::IsVariableUsed(const std::string& theVarName)
1890 return FindVariableAttribute( theVarName );
1893 //============================================================================
1894 /*! Function : FindVariableAttribute
1897 //============================================================================
1898 bool SALOMEDSImpl_Study::FindVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1899 SALOMEDSImpl_SObject theSObject,
1900 const std::string& theName)
1902 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1903 for( ; anIter.More(); anIter.Next() )
1904 if( FindVariableAttribute( theStudyBuilder, anIter.Value(), theName ) )
1907 DF_Attribute* anAttr;
1908 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1910 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1912 std::string aString = aStringAttr->Value();
1914 std::vector< std::vector<std::string> > aSections = ParseVariables( aString );
1915 for( int i = 0, n = aSections.size(); i < n; i++ )
1917 std::vector<std::string> aVector = aSections[i];
1918 for( int j = 0, m = aVector.size(); j < m; j++ )
1920 std::string aStr = aVector[j];
1921 if( aStr.compare( theName ) == 0 )
1930 //============================================================================
1931 /*! Function : FindVariableAttribute
1934 //============================================================================
1935 bool SALOMEDSImpl_Study::FindVariableAttribute(const std::string& theName)
1937 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
1938 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
1939 for( ; aCompIter.More(); aCompIter.Next() )
1941 SALOMEDSImpl_SObject aComp = aCompIter.Value();
1942 if( FindVariableAttribute( aStudyBuilder, aComp, theName ) )
1948 //============================================================================
1949 /*! Function : ReplaceVariableAttribute
1952 //============================================================================
1953 void SALOMEDSImpl_Study::ReplaceVariableAttribute(SALOMEDSImpl_StudyBuilder* theStudyBuilder,
1954 SALOMEDSImpl_SObject theSObject,
1955 const std::string& theSource,
1956 const std::string& theDest)
1958 SALOMEDSImpl_ChildIterator anIter = NewChildIterator( theSObject );
1959 for( ; anIter.More(); anIter.Next() )
1960 ReplaceVariableAttribute( theStudyBuilder, anIter.Value(), theSource, theDest );
1962 DF_Attribute* anAttr;
1963 if( theStudyBuilder->FindAttribute( theSObject, anAttr, "AttributeString" ) )
1965 if( SALOMEDSImpl_AttributeString* aStringAttr = ( SALOMEDSImpl_AttributeString* )anAttr )
1967 bool isChanged = false;
1968 std::string aNewString, aCurrentString = aStringAttr->Value();
1970 std::vector< std::vector<std::string> > aSections = ParseVariables( aCurrentString );
1971 for( int i = 0, n = aSections.size(); i < n; i++ )
1973 std::vector<std::string> aVector = aSections[i];
1974 for( int j = 0, m = aVector.size(); j < m; j++ )
1976 std::string aStr = aVector[j];
1977 if( aStr.compare( theSource ) == 0 )
1983 aNewString.append( aStr );
1985 aNewString.append( ":" );
1988 aNewString.append( "|" );
1992 aStringAttr->SetValue( aNewString );
1997 //============================================================================
1998 /*! Function : ReplaceVariableAttribute
2001 //============================================================================
2002 void SALOMEDSImpl_Study::ReplaceVariableAttribute(const std::string& theSource, const std::string& theDest)
2004 SALOMEDSImpl_StudyBuilder* aStudyBuilder = NewBuilder();
2005 SALOMEDSImpl_SComponentIterator aCompIter = NewComponentIterator();
2006 for( ; aCompIter.More(); aCompIter.Next() )
2008 SALOMEDSImpl_SObject aComp = aCompIter.Value();
2009 ReplaceVariableAttribute( aStudyBuilder, aComp, theSource, theDest );
2013 //============================================================================
2014 /*! Function : ParseVariables
2017 //============================================================================
2018 std::vector< std::vector< std::string > > SALOMEDSImpl_Study::ParseVariables(const std::string& theVariables) const
2020 return SALOMEDSImpl_Tool::splitStringWithEmpty( theVariables, OPERATION_SEPARATOR, VARIABLE_SEPARATOR );
2023 //============================================================================
2024 /*! Function : EnableUseCaseAutoFilling
2027 //============================================================================
2028 void SALOMEDSImpl_Study::EnableUseCaseAutoFilling(bool isEnabled)
2030 _errorCode = ""; _autoFill = isEnabled;
2032 _builder->SetOnAddSObject(_cb);
2033 _builder->SetOnRemoveSObject(_cb);
2036 _builder->SetOnAddSObject(NULL);
2037 _builder->SetOnRemoveSObject(NULL);
2041 //============================================================================
2042 /*! Function : GetIORs
2045 //============================================================================
2046 std::vector<std::string> SALOMEDSImpl_Study::GetIORs()
2048 std::vector<std::string> anIORs;
2049 std::map<std::string, DF_Label>::const_iterator MI;
2050 for(MI = myIORLabels.begin(); MI!=myIORLabels.end(); MI++)
2051 anIORs.push_back(MI->first);
2056 //============================================================================
2057 /*! Function : addSO_Notification
2058 * Purpose : This function tells all the observers that a SO has been added
2060 //============================================================================
2061 bool SALOMEDSImpl_Study::addSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2064 return _notifier->addSO_Notification(theSObject);
2069 //============================================================================
2070 /*! Function : removeSO_Notification
2071 * Purpose : This function tells all the observers that a SO has been removed
2073 //============================================================================
2074 bool SALOMEDSImpl_Study::removeSO_Notification (const SALOMEDSImpl_SObject& theSObject)
2077 return _notifier->removeSO_Notification(theSObject);
2082 //============================================================================
2083 /*! Function : modifySO_Notification
2084 * Purpose : This function tells all the observers that a SO has been modified and
2085 pass the mofification reason
2087 //============================================================================
2088 bool SALOMEDSImpl_Study::modifySO_Notification (const SALOMEDSImpl_SObject& theSObject, int reason)
2091 return _notifier->modifySO_Notification(theSObject, reason);
2096 //============================================================================
2097 /*! Function : setNotifier
2098 * Purpose : register a notifier
2100 //============================================================================
2101 void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier)
2106 static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc )
2108 static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec;
2109 if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() )
2110 _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 );
2111 return _genObjRegVec[ doc->GetDocumentID() ];
2114 //================================================================================
2116 * \brief Stores theRegister
2118 //================================================================================
2120 void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister)
2122 getGenObjRegister( _doc ) = theRegister;
2125 //================================================================================
2127 * \brief Indirectly invokes GenericObj_i::Register()
2129 //================================================================================
2131 void SALOMEDSImpl_Study::RegisterGenObj (const std::string& theIOR, DF_Label label)
2133 if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
2134 goRegister->RegisterGenObj( theIOR );
2137 //================================================================================
2139 * \brief Indirectly invokes GenericObj_i::UnRegister()
2141 //================================================================================
2143 void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label)
2145 if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() ))
2146 goRegister->UnRegisterGenObj( theIOR );