1 // Copyright (C) 2007-2008 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
22 // File : SALOMEDSImpl_StudyBuilder.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDSImpl_Attributes.hxx"
27 #include "SALOMEDSImpl_Study.hxx"
28 #include "SALOMEDSImpl_StudyBuilder.hxx"
29 #include "SALOMEDSImpl_SObject.hxx"
30 #include "SALOMEDSImpl_SComponent.hxx"
31 #include "SALOMEDSImpl_Tool.hxx"
32 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
34 #include "DF_ChildIterator.hxx"
35 #include "DF_Label.hxx"
43 #define USE_CASE_LABEL_TAG 2
44 #define DIRECTORYID 16661
45 #define FILELOCALID 26662
47 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII);
49 //============================================================================
50 /*! Function : constructor
53 //============================================================================
54 SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const SALOMEDSImpl_Study* theOwner)
58 _callbackOnRemove = NULL;
59 _study = (SALOMEDSImpl_Study*)theOwner;
60 _doc = _study->GetDocument();
63 //============================================================================
64 /*! Function : destructor
67 //============================================================================
68 SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
71 //============================================================================
72 /*! Function : NewComponent
73 * Purpose : Create a new component (Scomponent)
75 //============================================================================
76 SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const string& DataType)
81 SALOMEDSImpl_SComponent sco;
83 if(DataType.size() == 0) return sco;
85 //Always create component under main label.
86 DF_Label L = _doc->Main();
88 DF_Label NL = L.NewChild();
90 SALOMEDSImpl_AttributeComment::Set(NL, DataType);
92 SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
94 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
96 _doc->SetModified(true);
101 //============================================================================
102 /*! Function : DefineComponentInstance
103 * Purpose : Add IOR attribute of a Scomponent
105 //============================================================================
106 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const SALOMEDSImpl_SComponent& aComponent,
112 if(!aComponent || IOR.empty()) {
113 _errorCode = "Invalid arguments";
117 SALOMEDSImpl_AttributeIOR::Set(aComponent.GetLabel(), IOR);
122 //============================================================================
123 /*! Function : RemoveComponent
124 * Purpose : Delete a Scomponent
126 //============================================================================
127 bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const SALOMEDSImpl_SComponent& aComponent)
131 return RemoveObject(aComponent);
134 //============================================================================
135 /*! Function : NewObject
136 * Purpose : Create a new SObject
138 //============================================================================
139 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SObject& theFatherObject)
144 //Find label of father
145 DF_Label Lab = theFatherObject.GetLabel();
148 DF_Label NewLab = Lab.NewChild();
150 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
151 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
153 _doc->SetModified(true);
157 //============================================================================
158 /*! Function : NewObjectToTag
161 //============================================================================
162 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject,
167 //Find label of father
168 DF_Label Lab = theFatherObject.GetLabel();
170 //Create or find label
171 DF_Label NewLab = Lab.FindChild(theTag, 1);
173 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
175 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
177 _doc->SetModified(true);
181 //============================================================================
182 /*! Function : RemoveObject
185 //============================================================================
186 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObject)
191 _errorCode = "Null object";
195 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
197 DF_Label Lab = anObject.GetLabel();
199 SALOMEDSImpl_AttributeReference* aReference = NULL;
200 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
201 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
202 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
203 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
206 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
207 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
210 Lab.ForgetAllAttributes();
212 _doc->SetModified(true);
217 //============================================================================
218 /*! Function : RemoveObjectWithChildren
221 //============================================================================
222 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObject& anObject)
227 _errorCode = "Null object";
231 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
233 DF_Label Lab = anObject.GetLabel();
235 SALOMEDSImpl_AttributeReference* aReference = NULL;
236 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
237 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
238 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
239 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
241 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
242 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
245 DF_ChildIterator it(Lab, true);
246 for(;it.More();it.Next()) {
247 DF_Label aLabel = it.Value();
248 if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
249 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
250 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
251 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
253 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
254 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
258 Lab.ForgetAllAttributes(true);
260 _doc->SetModified(true);
265 //============================================================================
266 /*! Function : LoadWith
269 //============================================================================
270 bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
271 SALOMEDSImpl_Driver* aDriver)
275 DF_Label Lab = anSCO.GetLabel();
276 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
278 //Find the current Url of the study
279 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
280 int aLocked = _study->GetProperties()->IsLocked();
281 if (aLocked) _study->GetProperties()->SetLocked(false);
283 std::string Res(Att->Value());
284 string aHDFPath(Res);
286 SALOMEDSImpl_AttributeComment* type = NULL;
287 std::string DataType;
288 if ((type=(SALOMEDSImpl_AttributeComment*)Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID())))
289 DataType = type->Value();
291 // associate the driver to the SComponent
292 if(aDriver == NULL) {
293 _errorCode = "Driver is null";
297 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
298 SALOMEDSImpl_AttributeIOR* attrIOR = NULL;
299 if ((attrIOR=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
300 if (aLocked) _study->GetProperties()->SetLocked(true);
304 DefineComponentInstance (anSCO, aDriver->GetIOR());
307 bool isASCII = false;
308 if (HDFascii::isASCII(aHDFPath.c_str())) {
310 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.c_str());
311 aHDFUrl += "hdf_from_ascii.hdf";
316 //Open the Study HDF file
317 HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
319 char aMultifileState[2];
320 char ASCIIfileState[2];
322 string scoid = anSCO.GetID();
323 hdf_file->OpenOnDisk(HDF_RDONLY);
324 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
325 hdf_group->OpenOnDisk();
326 HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
327 hdf_sco_group->OpenOnDisk();
329 unsigned char* aStreamFile = NULL;
332 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
333 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
334 hdf_dataset->OpenOnDisk();
335 aStreamSize = hdf_dataset->GetSize();
336 aStreamFile = new unsigned char[aStreamSize];
337 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
338 hdf_dataset->ReadFromDisk(aStreamFile);
339 hdf_dataset->CloseOnDisk();
344 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
345 multifile_hdf_dataset->OpenOnDisk();
346 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
348 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
349 ascii_hdf_dataset->OpenOnDisk();
350 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
352 string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
354 bool aResult = (ASCIIfileState[0]=='A')?
355 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
356 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
358 if(aStreamFile != NULL) delete []aStreamFile;
361 RemoveAttribute( anSCO, "AttributeIOR" );
363 _errorCode = "Can't load component";
364 throw HDFexception("Unable to load component");
367 //if(aDir != NULL) delete []aDir;
369 multifile_hdf_dataset->CloseOnDisk();
370 multifile_hdf_dataset = 0;
371 ascii_hdf_dataset->CloseOnDisk();
372 ascii_hdf_dataset = 0;
374 hdf_sco_group->CloseOnDisk();
376 hdf_group->CloseOnDisk();
378 hdf_file->CloseOnDisk();
382 vector<string> aFilesToRemove;
383 aFilesToRemove.push_back("hdf_from_ascii.hdf");
384 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
385 aFilesToRemove, true);
388 catch (HDFexception) {
392 vector<string> aFilesToRemove;
393 aFilesToRemove.push_back(aHDFUrl);
394 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
397 if (aLocked) _study->GetProperties()->SetLocked(true);
398 _errorCode = "No persistent file";
403 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
405 _errorCode = "Can not convert persistent IDs to IORs";
409 if (aLocked) _study->GetProperties()->SetLocked(true);
411 _errorCode = "No persistent file";
418 //============================================================================
422 //============================================================================
423 bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
425 _errorCode = "Not implemented";
429 //============================================================================
430 /*! Function : FindOrCreateAttribute
431 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
434 //============================================================================
435 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
436 const string& aTypeOfAttribute)
440 _errorCode = "Invalid arguments";
444 DF_Label Lab = anObject.GetLabel();
446 _errorCode = "Null label";
450 _doc->SetModified(true);
452 //The macro adds all necessary checks for standardly behaiving attributes
453 __FindOrCreateAttributeForBuilder
456 //Add checks for TreeNode and UserID attributes
457 if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
459 string aTreeNodeGUID;
460 if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
461 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
463 aTreeNodeGUID = aTypeOfAttribute.substr(21, aTypeOfAttribute.size()); // create tree node GUID by name
465 SALOMEDSImpl_AttributeTreeNode* anAttr = NULL;
466 if (!(anAttr=(SALOMEDSImpl_AttributeTreeNode*)Lab.FindAttribute(aTreeNodeGUID))) {
468 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
473 if (strncmp(aTypeOfAttribute.c_str(), "AttributeUserID",15) == 0 ) {
474 std::string aUserGUID;
475 if (strcmp(aTypeOfAttribute.c_str(), "AttributeUserID") == 0) {
476 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
478 aUserGUID = aTypeOfAttribute.substr(15, aTypeOfAttribute.size()); // create tree node GUID by name
480 SALOMEDSImpl_AttributeUserID* anAttr = NULL;
481 if (!(anAttr=(SALOMEDSImpl_AttributeUserID*)Lab.FindAttribute(aUserGUID))) {
483 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
487 _errorCode = "Can not create an attribute";
492 //============================================================================
493 /*! Function : FindAttribute
494 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
496 //============================================================================
498 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
499 DF_Attribute*& anAttribute,
500 const string& aTypeOfAttribute)
504 _errorCode = "Invalid arguments";
507 DF_Label Lab = anObject.GetLabel();
508 if ((anAttribute=Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)))) {
509 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
516 //============================================================================
517 /*! Function : RemoveAttribute
518 * Purpose : Remove attribute of given type assigned SObject
520 //============================================================================
522 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
523 const string& aTypeOfAttribute)
528 _errorCode = "Invalid arguments";
531 DF_Label Lab = anObject.GetLabel();
533 if (aTypeOfAttribute == string("AttributeIOR")) { // Remove from IORLabel map
534 SALOMEDSImpl_AttributeIOR* anAttr = NULL;
535 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
539 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
541 _doc->SetModified(true);
546 //============================================================================
547 /*! Function : Addreference
550 //============================================================================
551 bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
552 const SALOMEDSImpl_SObject& theReferencedObject)
555 if(!me || !theReferencedObject) {
556 _errorCode = "Invalid arguments";
560 DF_Label Lab = me.GetLabel();
561 DF_Label RefLab = theReferencedObject.GetLabel();
562 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
564 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
566 if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
571 //============================================================================
572 /*! Function : RemoveReference
575 //============================================================================
576 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
579 SALOMEDSImpl_SObject theReferencedObject;
581 if(!me.ReferencedObject(theReferencedObject)) return false; //No reference is found
584 DF_Label Lab = me.GetLabel();
586 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
588 DF_Label RefLab = theReferencedObject.GetLabel();
590 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
591 if((aTarget=(SALOMEDSImpl_AttributeTarget*)RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
592 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
595 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
597 _doc->SetModified(true);
604 //============================================================================
605 /*! Function : AddDirectory
606 * Purpose : adds a new directory with a path = thePath
608 //============================================================================
609 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
613 if(thePath.empty()) {
614 _errorCode = "Invalid path";
618 string aPath(thePath), aContext(""), aFatherPath;
620 SALOMEDSImpl_SObject anObject;
623 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
628 _errorCode = "StudyNameAlreadyUsed";
632 if(aPath[0] != '/') { //Relative path
633 aPath.insert(aPath.begin(), '/');
634 aPath = _study->GetContext() + aPath;
637 vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
641 for(int i = 0, len = vs.size()-1; i<len; i++) {
643 aFatherPath += vs[i];
648 anObject = _study->FindObjectByPath(aFatherPath); //Check if the father directory exists
652 _errorCode = "StudyInvalidDirectory";
656 SALOMEDSImpl_SObject aNewObject = NewObject(anObject);
657 aLabel = aNewObject.GetLabel();
658 if(aLabel.IsNull()) {
659 _errorCode = "StudyInvalidComponent";
663 SALOMEDSImpl_AttributeName::Set(aLabel, vs.back());
665 //Set LocalID attribute to identify the directory object
666 SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
668 _doc->SetModified(true);
674 //============================================================================
675 /*! Function : SetGUID
678 //============================================================================
679 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
680 const string& theGUID)
685 _errorCode = "Invalid arguments";
689 DF_Label aLabel = anObject.GetLabel();
690 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID);
692 _doc->SetModified(true);
697 //============================================================================
698 /*! Function : IsGUID
701 //============================================================================
702 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
703 const string& theGUID)
707 _errorCode = "Invalid arguments";
710 DF_Label aLabel = anObject.GetLabel();
711 return aLabel.IsAttribute(theGUID);
715 //============================================================================
716 /*! Function : NewCommand
719 //============================================================================
720 void SALOMEDSImpl_StudyBuilder::NewCommand()
724 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
725 _study->GetProperties()->IsLockChanged(true);
730 //============================================================================
731 /*! Function : CommitCommand
734 //============================================================================
735 void SALOMEDSImpl_StudyBuilder::CommitCommand()
738 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
739 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
740 _errorCode = "LockProtection";
741 throw LockProtection("LockProtection");
743 int aModif = anAttr->GetModified();
744 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
745 anAttr->SetModified(aModif+1);
750 _doc->SetModified(true);
753 //============================================================================
754 /*! Function : HasOpenCommand
757 //============================================================================
758 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
766 //============================================================================
767 /*! Function : AbortCommand
770 //============================================================================
771 void SALOMEDSImpl_StudyBuilder::AbortCommand()
777 //============================================================================
781 //============================================================================
782 void SALOMEDSImpl_StudyBuilder::Undo()
786 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
787 if (anAttr->IsLocked()) {
788 _errorCode = "LockProtection";
789 throw LockProtection("LockProtection");
791 anAttr->SetModified(anAttr->GetModified()-1);
794 _doc->SetModified(true);
797 //============================================================================
801 //============================================================================
802 void SALOMEDSImpl_StudyBuilder::Redo()
805 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
806 if (anAttr->IsLocked()) {
807 _errorCode = "LockProtection";
808 throw LockProtection("LockProtection");
810 anAttr->SetModified(anAttr->GetModified()+1);
815 _doc->SetModified(true);
818 //============================================================================
819 /*! Function : GetAvailableUndos
822 //============================================================================
823 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
829 //============================================================================
830 /*! Function : GetAvailableRedos
833 //============================================================================
834 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
840 //============================================================================
841 /*! Function : UndoLimit
844 //============================================================================
845 int SALOMEDSImpl_StudyBuilder::UndoLimit()
851 //============================================================================
852 /*! Function : UndoLimit
855 //============================================================================
856 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
863 //============================================================================
864 /*! Function : SetOnAddSObject
867 //============================================================================
868 SALOMEDSImpl_Callback*
869 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const SALOMEDSImpl_Callback* theCallback)
872 SALOMEDSImpl_Callback* aRet = _callbackOnAdd;
873 _callbackOnAdd = (SALOMEDSImpl_Callback*)theCallback;
877 //============================================================================
878 /*! Function : SetOnNewSObject
881 //============================================================================
882 SALOMEDSImpl_Callback*
883 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const SALOMEDSImpl_Callback* theCallback)
886 SALOMEDSImpl_Callback* aRet = _callbackOnRemove;
887 _callbackOnRemove = (SALOMEDSImpl_Callback*)theCallback;
891 //============================================================================
892 /*! Function : CheckLocked
895 //============================================================================
896 void SALOMEDSImpl_StudyBuilder::CheckLocked()
899 if (HasOpenCommand()) return;
900 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
901 if (anAttr->IsLocked()) {
902 _errorCode = "LockProtection";
903 throw LockProtection("LockProtection");
907 //============================================================================
908 /*! Function : SetName
911 //============================================================================
912 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
913 const string& theValue)
918 _errorCode = "Invalid arguments";
921 SALOMEDSImpl_AttributeName::Set(theSO.GetLabel(), theValue);
923 _doc->SetModified(true);
928 //============================================================================
929 /*! Function : SetComment
932 //============================================================================
933 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
934 const string& theValue)
939 _errorCode = "Invalid arguments";
942 SALOMEDSImpl_AttributeComment::Set(theSO.GetLabel(), theValue);
944 _doc->SetModified(true);
949 //============================================================================
950 /*! Function : SetIOR
953 //============================================================================
954 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
955 const string& theValue)
960 _errorCode = "Invalid arguments";
963 SALOMEDSImpl_AttributeIOR::Set(theSO.GetLabel(), theValue);
965 _doc->SetModified(true);
971 //============================================================================
972 /*! Function : Translate_persistentID_to_IOR
975 //============================================================================
976 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
978 if(driver == NULL) return;
979 DF_ChildIterator itchild (Lab);
981 for (; itchild.More(); itchild.Next()) {
982 DF_Label current = itchild.Value();
983 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
984 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
986 SALOMEDSImpl_AttributeLocalID* anID = NULL;
987 if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID())))
988 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
990 string persist_ref = Att->Value();
991 SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
992 string ior_string = driver->LocalPersistentIDToIOR(so,
996 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
999 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);