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()))) {
208 _study->DeleteIORLabelMapItem(anAttr->Value());
211 Lab.ForgetAllAttributes();
213 _doc->SetModified(true);
218 //============================================================================
219 /*! Function : RemoveObjectWithChildren
222 //============================================================================
223 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObject& anObject)
228 _errorCode = "Null object";
232 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
234 DF_Label Lab = anObject.GetLabel();
236 SALOMEDSImpl_AttributeReference* aReference = NULL;
237 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
238 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
239 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
240 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
242 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
243 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
244 _study->DeleteIORLabelMapItem(anAttr->Value());
247 DF_ChildIterator it(Lab, true);
248 for(;it.More();it.Next()) {
249 DF_Label aLabel = it.Value();
250 if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
251 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
252 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
253 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
255 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
256 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
257 _study->DeleteIORLabelMapItem(anAttr->Value());
261 Lab.ForgetAllAttributes(true);
263 _doc->SetModified(true);
268 //============================================================================
269 /*! Function : LoadWith
272 //============================================================================
273 bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
274 SALOMEDSImpl_Driver* aDriver)
278 DF_Label Lab = anSCO.GetLabel();
279 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
281 //Find the current Url of the study
282 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
283 int aLocked = _study->GetProperties()->IsLocked();
284 if (aLocked) _study->GetProperties()->SetLocked(false);
286 std::string Res(Att->Value());
287 string aHDFPath(Res);
289 SALOMEDSImpl_AttributeComment* type = NULL;
290 std::string DataType;
291 if ((type=(SALOMEDSImpl_AttributeComment*)Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID())))
292 DataType = type->Value();
294 // associate the driver to the SComponent
295 if(aDriver == NULL) {
296 _errorCode = "Driver is null";
300 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
301 SALOMEDSImpl_AttributeIOR* attrIOR = NULL;
302 if ((attrIOR=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
303 if (aLocked) _study->GetProperties()->SetLocked(true);
307 DefineComponentInstance (anSCO, aDriver->GetIOR());
310 bool isASCII = false;
311 if (HDFascii::isASCII(aHDFPath.c_str())) {
313 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.c_str());
314 aHDFUrl += "hdf_from_ascii.hdf";
319 //Open the Study HDF file
320 HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
322 char aMultifileState[2];
323 char ASCIIfileState[2];
325 string scoid = anSCO.GetID();
326 hdf_file->OpenOnDisk(HDF_RDONLY);
327 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
328 hdf_group->OpenOnDisk();
329 HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
330 hdf_sco_group->OpenOnDisk();
332 unsigned char* aStreamFile = NULL;
335 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
336 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
337 hdf_dataset->OpenOnDisk();
338 aStreamSize = hdf_dataset->GetSize();
339 aStreamFile = new unsigned char[aStreamSize];
340 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
341 hdf_dataset->ReadFromDisk(aStreamFile);
342 hdf_dataset->CloseOnDisk();
347 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
348 multifile_hdf_dataset->OpenOnDisk();
349 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
351 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
352 ascii_hdf_dataset->OpenOnDisk();
353 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
355 string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
357 bool aResult = (ASCIIfileState[0]=='A')?
358 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
359 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
361 if(aStreamFile != NULL) delete []aStreamFile;
364 RemoveAttribute( anSCO, "AttributeIOR" );
366 _errorCode = "Can't load component";
367 throw HDFexception("Unable to load component");
370 //if(aDir != NULL) delete []aDir;
372 multifile_hdf_dataset->CloseOnDisk();
373 multifile_hdf_dataset = 0;
374 ascii_hdf_dataset->CloseOnDisk();
375 ascii_hdf_dataset = 0;
377 hdf_sco_group->CloseOnDisk();
379 hdf_group->CloseOnDisk();
381 hdf_file->CloseOnDisk();
385 vector<string> aFilesToRemove;
386 aFilesToRemove.push_back("hdf_from_ascii.hdf");
387 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
388 aFilesToRemove, true);
391 catch (HDFexception) {
395 vector<string> aFilesToRemove;
396 aFilesToRemove.push_back(aHDFUrl);
397 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
400 if (aLocked) _study->GetProperties()->SetLocked(true);
401 _errorCode = "No persistent file";
406 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
408 _errorCode = "Can not convert persistent IDs to IORs";
412 if (aLocked) _study->GetProperties()->SetLocked(true);
414 _errorCode = "No persistent file";
421 //============================================================================
425 //============================================================================
426 bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
428 _errorCode = "Not implemented";
432 //============================================================================
433 /*! Function : FindOrCreateAttribute
434 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
437 //============================================================================
438 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
439 const string& aTypeOfAttribute)
443 _errorCode = "Invalid arguments";
447 DF_Label Lab = anObject.GetLabel();
449 _errorCode = "Null label";
453 _doc->SetModified(true);
455 //The macro adds all necessary checks for standardly behaiving attributes
456 __FindOrCreateAttributeForBuilder
459 //Add checks for TreeNode and UserID attributes
460 if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
462 string aTreeNodeGUID;
463 if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
464 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
466 aTreeNodeGUID = aTypeOfAttribute.substr(21, aTypeOfAttribute.size()); // create tree node GUID by name
468 SALOMEDSImpl_AttributeTreeNode* anAttr = NULL;
469 if (!(anAttr=(SALOMEDSImpl_AttributeTreeNode*)Lab.FindAttribute(aTreeNodeGUID))) {
471 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
476 if (strncmp(aTypeOfAttribute.c_str(), "AttributeUserID",15) == 0 ) {
477 std::string aUserGUID;
478 if (strcmp(aTypeOfAttribute.c_str(), "AttributeUserID") == 0) {
479 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
481 aUserGUID = aTypeOfAttribute.substr(15, aTypeOfAttribute.size()); // create tree node GUID by name
483 SALOMEDSImpl_AttributeUserID* anAttr = NULL;
484 if (!(anAttr=(SALOMEDSImpl_AttributeUserID*)Lab.FindAttribute(aUserGUID))) {
486 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
490 _errorCode = "Can not create an attribute";
495 //============================================================================
496 /*! Function : FindAttribute
497 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
499 //============================================================================
501 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
502 DF_Attribute*& anAttribute,
503 const string& aTypeOfAttribute)
507 _errorCode = "Invalid arguments";
510 DF_Label Lab = anObject.GetLabel();
511 if ((anAttribute=Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)))) {
512 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
519 //============================================================================
520 /*! Function : RemoveAttribute
521 * Purpose : Remove attribute of given type assigned SObject
523 //============================================================================
525 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
526 const string& aTypeOfAttribute)
531 _errorCode = "Invalid arguments";
534 DF_Label Lab = anObject.GetLabel();
536 if (aTypeOfAttribute == string("AttributeIOR")) { // Remove from IORLabel map
537 SALOMEDSImpl_AttributeIOR* anAttr = NULL;
538 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
539 _study->DeleteIORLabelMapItem(anAttr->Value());
543 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
545 _doc->SetModified(true);
550 //============================================================================
551 /*! Function : Addreference
554 //============================================================================
555 bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
556 const SALOMEDSImpl_SObject& theReferencedObject)
559 if(!me || !theReferencedObject) {
560 _errorCode = "Invalid arguments";
564 DF_Label Lab = me.GetLabel();
565 DF_Label RefLab = theReferencedObject.GetLabel();
566 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
568 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
570 if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
575 //============================================================================
576 /*! Function : RemoveReference
579 //============================================================================
580 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
583 SALOMEDSImpl_SObject theReferencedObject;
585 if(!me.ReferencedObject(theReferencedObject)) return false; //No reference is found
588 DF_Label Lab = me.GetLabel();
590 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
592 DF_Label RefLab = theReferencedObject.GetLabel();
594 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
595 if((aTarget=(SALOMEDSImpl_AttributeTarget*)RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
596 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
599 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
601 _doc->SetModified(true);
608 //============================================================================
609 /*! Function : AddDirectory
610 * Purpose : adds a new directory with a path = thePath
612 //============================================================================
613 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
617 if(thePath.empty()) {
618 _errorCode = "Invalid path";
622 string aPath(thePath), aContext(""), aFatherPath;
624 SALOMEDSImpl_SObject anObject;
627 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
632 _errorCode = "StudyNameAlreadyUsed";
636 if(aPath[0] != '/') { //Relative path
637 aPath.insert(aPath.begin(), '/');
638 aPath = _study->GetContext() + aPath;
641 vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
645 for(int i = 0, len = vs.size()-1; i<len; i++) {
647 aFatherPath += vs[i];
652 anObject = _study->FindObjectByPath(aFatherPath); //Check if the father directory exists
656 _errorCode = "StudyInvalidDirectory";
660 SALOMEDSImpl_SObject aNewObject = NewObject(anObject);
661 aLabel = aNewObject.GetLabel();
662 if(aLabel.IsNull()) {
663 _errorCode = "StudyInvalidComponent";
667 SALOMEDSImpl_AttributeName::Set(aLabel, vs.back());
669 //Set LocalID attribute to identify the directory object
670 SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
672 _doc->SetModified(true);
678 //============================================================================
679 /*! Function : SetGUID
682 //============================================================================
683 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
684 const string& theGUID)
689 _errorCode = "Invalid arguments";
693 DF_Label aLabel = anObject.GetLabel();
694 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID);
696 _doc->SetModified(true);
701 //============================================================================
702 /*! Function : IsGUID
705 //============================================================================
706 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
707 const string& theGUID)
711 _errorCode = "Invalid arguments";
714 DF_Label aLabel = anObject.GetLabel();
715 return aLabel.IsAttribute(theGUID);
719 //============================================================================
720 /*! Function : NewCommand
723 //============================================================================
724 void SALOMEDSImpl_StudyBuilder::NewCommand()
728 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
729 _study->GetProperties()->IsLockChanged(true);
734 //============================================================================
735 /*! Function : CommitCommand
738 //============================================================================
739 void SALOMEDSImpl_StudyBuilder::CommitCommand()
742 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
743 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
744 _errorCode = "LockProtection";
745 throw LockProtection("LockProtection");
747 int aModif = anAttr->GetModified();
748 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
749 anAttr->SetModified(aModif+1);
754 _doc->SetModified(true);
757 //============================================================================
758 /*! Function : HasOpenCommand
761 //============================================================================
762 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
770 //============================================================================
771 /*! Function : AbortCommand
774 //============================================================================
775 void SALOMEDSImpl_StudyBuilder::AbortCommand()
781 //============================================================================
785 //============================================================================
786 void SALOMEDSImpl_StudyBuilder::Undo()
790 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
791 if (anAttr->IsLocked()) {
792 _errorCode = "LockProtection";
793 throw LockProtection("LockProtection");
795 anAttr->SetModified(anAttr->GetModified()-1);
798 _doc->SetModified(true);
801 //============================================================================
805 //============================================================================
806 void SALOMEDSImpl_StudyBuilder::Redo()
809 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
810 if (anAttr->IsLocked()) {
811 _errorCode = "LockProtection";
812 throw LockProtection("LockProtection");
814 anAttr->SetModified(anAttr->GetModified()+1);
819 _doc->SetModified(true);
822 //============================================================================
823 /*! Function : GetAvailableUndos
826 //============================================================================
827 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
833 //============================================================================
834 /*! Function : GetAvailableRedos
837 //============================================================================
838 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
844 //============================================================================
845 /*! Function : UndoLimit
848 //============================================================================
849 int SALOMEDSImpl_StudyBuilder::UndoLimit()
855 //============================================================================
856 /*! Function : UndoLimit
859 //============================================================================
860 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
867 //============================================================================
868 /*! Function : SetOnAddSObject
871 //============================================================================
872 SALOMEDSImpl_Callback*
873 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const SALOMEDSImpl_Callback* theCallback)
876 SALOMEDSImpl_Callback* aRet = _callbackOnAdd;
877 _callbackOnAdd = (SALOMEDSImpl_Callback*)theCallback;
881 //============================================================================
882 /*! Function : SetOnNewSObject
885 //============================================================================
886 SALOMEDSImpl_Callback*
887 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const SALOMEDSImpl_Callback* theCallback)
890 SALOMEDSImpl_Callback* aRet = _callbackOnRemove;
891 _callbackOnRemove = (SALOMEDSImpl_Callback*)theCallback;
895 //============================================================================
896 /*! Function : CheckLocked
899 //============================================================================
900 void SALOMEDSImpl_StudyBuilder::CheckLocked()
903 if (HasOpenCommand()) return;
904 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
905 if (anAttr->IsLocked()) {
906 _errorCode = "LockProtection";
907 throw LockProtection("LockProtection");
911 //============================================================================
912 /*! Function : SetName
915 //============================================================================
916 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
917 const string& theValue)
922 _errorCode = "Invalid arguments";
925 SALOMEDSImpl_AttributeName::Set(theSO.GetLabel(), theValue);
927 _doc->SetModified(true);
932 //============================================================================
933 /*! Function : SetComment
936 //============================================================================
937 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
938 const string& theValue)
943 _errorCode = "Invalid arguments";
946 SALOMEDSImpl_AttributeComment::Set(theSO.GetLabel(), theValue);
948 _doc->SetModified(true);
953 //============================================================================
954 /*! Function : SetIOR
957 //============================================================================
958 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
959 const string& theValue)
964 _errorCode = "Invalid arguments";
967 SALOMEDSImpl_AttributeIOR::Set(theSO.GetLabel(), theValue);
969 _doc->SetModified(true);
975 //============================================================================
976 /*! Function : Translate_persistentID_to_IOR
979 //============================================================================
980 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
982 if(driver == NULL) return;
983 DF_ChildIterator itchild (Lab);
985 for (; itchild.More(); itchild.Next()) {
986 DF_Label current = itchild.Value();
987 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
988 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
990 SALOMEDSImpl_AttributeLocalID* anID = NULL;
991 if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID())))
992 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
994 string persist_ref = Att->Value();
995 SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
996 string ior_string = driver->LocalPersistentIDToIOR(so,
1000 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
1003 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);