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"
42 #define USE_CASE_LABEL_TAG 2
43 #define DIRECTORYID 16661
44 #define FILELOCALID 26662
46 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII);
48 //============================================================================
49 /*! Function : constructor
52 //============================================================================
53 SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const SALOMEDSImpl_Study* theOwner)
57 _callbackOnRemove = NULL;
58 _study = (SALOMEDSImpl_Study*)theOwner;
59 _doc = _study->GetDocument();
62 //============================================================================
63 /*! Function : destructor
66 //============================================================================
67 SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
70 //============================================================================
71 /*! Function : NewComponent
72 * Purpose : Create a new component (Scomponent)
74 //============================================================================
75 SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const string& DataType)
80 SALOMEDSImpl_SComponent sco;
82 if(DataType.size() == 0) return sco;
84 //Always create component under main label.
85 DF_Label L = _doc->Main();
87 DF_Label NL = L.NewChild();
89 SALOMEDSImpl_AttributeComment::Set(NL, DataType);
91 SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
93 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
95 _doc->SetModified(true);
100 //============================================================================
101 /*! Function : DefineComponentInstance
102 * Purpose : Add IOR attribute of a Scomponent
104 //============================================================================
105 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const SALOMEDSImpl_SComponent& aComponent,
111 if(!aComponent || IOR.empty()) {
112 _errorCode = "Invalid arguments";
116 SALOMEDSImpl_AttributeIOR::Set(aComponent.GetLabel(), IOR);
121 //============================================================================
122 /*! Function : RemoveComponent
123 * Purpose : Delete a Scomponent
125 //============================================================================
126 bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const SALOMEDSImpl_SComponent& aComponent)
130 return RemoveObject(aComponent);
133 //============================================================================
134 /*! Function : NewObject
135 * Purpose : Create a new SObject
137 //============================================================================
138 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SObject& theFatherObject)
143 //Find label of father
144 DF_Label Lab = theFatherObject.GetLabel();
147 DF_Label NewLab = Lab.NewChild();
149 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
150 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
152 _doc->SetModified(true);
156 //============================================================================
157 /*! Function : NewObjectToTag
160 //============================================================================
161 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject,
166 //Find label of father
167 DF_Label Lab = theFatherObject.GetLabel();
169 //Create or find label
170 DF_Label NewLab = Lab.FindChild(theTag, 1);
172 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
174 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
176 _doc->SetModified(true);
180 //============================================================================
181 /*! Function : RemoveObject
184 //============================================================================
185 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObject)
190 _errorCode = "Null object";
194 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
196 DF_Label Lab = anObject.GetLabel();
198 SALOMEDSImpl_AttributeReference* aReference = NULL;
199 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
200 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
201 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
202 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
205 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
206 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
209 Lab.ForgetAllAttributes();
211 _doc->SetModified(true);
216 //============================================================================
217 /*! Function : RemoveObjectWithChildren
220 //============================================================================
221 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObject& anObject)
226 _errorCode = "Null object";
230 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
232 DF_Label Lab = anObject.GetLabel();
234 SALOMEDSImpl_AttributeReference* aReference = NULL;
235 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
236 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
237 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
238 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
240 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
241 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
244 DF_ChildIterator it(Lab, true);
245 for(;it.More();it.Next()) {
246 DF_Label aLabel = it.Value();
247 if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
248 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
249 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
250 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
252 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
253 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
257 Lab.ForgetAllAttributes(true);
259 _doc->SetModified(true);
264 //============================================================================
265 /*! Function : LoadWith
268 //============================================================================
269 bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
270 SALOMEDSImpl_Driver* aDriver)
274 DF_Label Lab = anSCO.GetLabel();
275 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
277 //Find the current Url of the study
278 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
279 int aLocked = _study->GetProperties()->IsLocked();
280 if (aLocked) _study->GetProperties()->SetLocked(false);
282 std::string Res(Att->Value());
283 string aHDFPath(Res);
285 SALOMEDSImpl_AttributeComment* type = NULL;
286 std::string DataType;
287 if ((type=(SALOMEDSImpl_AttributeComment*)Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID())))
288 DataType = type->Value();
290 // associate the driver to the SComponent
291 if(aDriver == NULL) {
292 _errorCode = "Driver is null";
296 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
297 SALOMEDSImpl_AttributeIOR* attrIOR = NULL;
298 if ((attrIOR=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
299 if (aLocked) _study->GetProperties()->SetLocked(true);
303 DefineComponentInstance (anSCO, aDriver->GetIOR());
306 bool isASCII = false;
307 if (HDFascii::isASCII(aHDFPath.c_str())) {
309 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.c_str());
310 aHDFUrl += "hdf_from_ascii.hdf";
315 //Open the Study HDF file
316 HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
318 char aMultifileState[2];
319 char ASCIIfileState[2];
321 string scoid = anSCO.GetID();
322 hdf_file->OpenOnDisk(HDF_RDONLY);
323 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
324 hdf_group->OpenOnDisk();
325 HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
326 hdf_sco_group->OpenOnDisk();
328 unsigned char* aStreamFile = NULL;
331 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
332 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
333 hdf_dataset->OpenOnDisk();
334 aStreamSize = hdf_dataset->GetSize();
335 aStreamFile = new unsigned char[aStreamSize];
336 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
337 hdf_dataset->ReadFromDisk(aStreamFile);
338 hdf_dataset->CloseOnDisk();
343 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
344 multifile_hdf_dataset->OpenOnDisk();
345 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
347 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
348 ascii_hdf_dataset->OpenOnDisk();
349 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
351 string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
353 bool aResult = (ASCIIfileState[0]=='A')?
354 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
355 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
357 if(aStreamFile != NULL) delete []aStreamFile;
360 RemoveAttribute( anSCO, "AttributeIOR" );
362 _errorCode = "Can't load component";
363 throw HDFexception("Unable to load component");
366 //if(aDir != NULL) delete []aDir;
368 multifile_hdf_dataset->CloseOnDisk();
369 multifile_hdf_dataset = 0;
370 ascii_hdf_dataset->CloseOnDisk();
371 ascii_hdf_dataset = 0;
373 hdf_sco_group->CloseOnDisk();
375 hdf_group->CloseOnDisk();
377 hdf_file->CloseOnDisk();
381 vector<string> aFilesToRemove;
382 aFilesToRemove.push_back("hdf_from_ascii.hdf");
383 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
384 aFilesToRemove, true);
387 catch (HDFexception) {
391 vector<string> aFilesToRemove;
392 aFilesToRemove.push_back(aHDFUrl);
393 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
396 if (aLocked) _study->GetProperties()->SetLocked(true);
397 _errorCode = "No persistent file";
402 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
404 _errorCode = "Can not convert persistent IDs to IORs";
408 if (aLocked) _study->GetProperties()->SetLocked(true);
410 _errorCode = "No persistent file";
417 //============================================================================
421 //============================================================================
422 bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
424 _errorCode = "Not implemented";
428 //============================================================================
429 /*! Function : FindOrCreateAttribute
430 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
433 //============================================================================
434 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
435 const string& aTypeOfAttribute)
439 _errorCode = "Invalid arguments";
443 DF_Label Lab = anObject.GetLabel();
445 _errorCode = "Null label";
449 _doc->SetModified(true);
451 //The macro adds all necessary checks for standardly behaiving attributes
452 __FindOrCreateAttributeForBuilder
455 //Add checks for TreeNode and UserID attributes
456 if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
458 string aTreeNodeGUID;
459 if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
460 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
462 aTreeNodeGUID = aTypeOfAttribute.substr(21, aTypeOfAttribute.size()); // create tree node GUID by name
464 SALOMEDSImpl_AttributeTreeNode* anAttr = NULL;
465 if (!(anAttr=(SALOMEDSImpl_AttributeTreeNode*)Lab.FindAttribute(aTreeNodeGUID))) {
467 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
472 if (strncmp(aTypeOfAttribute.c_str(), "AttributeUserID",15) == 0 ) {
473 std::string aUserGUID;
474 if (strcmp(aTypeOfAttribute.c_str(), "AttributeUserID") == 0) {
475 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
477 aUserGUID = aTypeOfAttribute.substr(15, aTypeOfAttribute.size()); // create tree node GUID by name
479 SALOMEDSImpl_AttributeUserID* anAttr = NULL;
480 if (!(anAttr=(SALOMEDSImpl_AttributeUserID*)Lab.FindAttribute(aUserGUID))) {
482 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
486 _errorCode = "Can not create an attribute";
491 //============================================================================
492 /*! Function : FindAttribute
493 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
495 //============================================================================
497 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
498 DF_Attribute*& anAttribute,
499 const string& aTypeOfAttribute)
503 _errorCode = "Invalid arguments";
506 DF_Label Lab = anObject.GetLabel();
507 if ((anAttribute=Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)))) {
508 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
515 //============================================================================
516 /*! Function : RemoveAttribute
517 * Purpose : Remove attribute of given type assigned SObject
519 //============================================================================
521 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
522 const string& aTypeOfAttribute)
527 _errorCode = "Invalid arguments";
530 DF_Label Lab = anObject.GetLabel();
532 if (aTypeOfAttribute == string("AttributeIOR")) { // Remove from IORLabel map
533 SALOMEDSImpl_AttributeIOR* anAttr = NULL;
534 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
538 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
540 _doc->SetModified(true);
545 //============================================================================
546 /*! Function : Addreference
549 //============================================================================
550 bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
551 const SALOMEDSImpl_SObject& theReferencedObject)
554 if(!me || !theReferencedObject) {
555 _errorCode = "Invalid arguments";
559 DF_Label Lab = me.GetLabel();
560 DF_Label RefLab = theReferencedObject.GetLabel();
561 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
563 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
565 if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
570 //============================================================================
571 /*! Function : RemoveReference
574 //============================================================================
575 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
578 SALOMEDSImpl_SObject theReferencedObject;
580 if(!me.ReferencedObject(theReferencedObject)) return false; //No reference is found
583 DF_Label Lab = me.GetLabel();
585 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
587 DF_Label RefLab = theReferencedObject.GetLabel();
589 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
590 if((aTarget=(SALOMEDSImpl_AttributeTarget*)RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
591 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
594 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
596 _doc->SetModified(true);
603 //============================================================================
604 /*! Function : AddDirectory
605 * Purpose : adds a new directory with a path = thePath
607 //============================================================================
608 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const string& thePath)
612 if(thePath.empty()) {
613 _errorCode = "Invalid path";
617 string aPath(thePath), aContext(""), aFatherPath;
619 SALOMEDSImpl_SObject anObject;
622 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
627 _errorCode = "StudyNameAlreadyUsed";
631 if(aPath[0] != '/') { //Relative path
632 aPath.insert(aPath.begin(), '/');
633 aPath = _study->GetContext() + aPath;
636 vector<string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
640 for(int i = 0, len = vs.size()-1; i<len; i++) {
642 aFatherPath += vs[i];
647 anObject = _study->FindObjectByPath(aFatherPath); //Check if the father directory exists
651 _errorCode = "StudyInvalidDirectory";
655 SALOMEDSImpl_SObject aNewObject = NewObject(anObject);
656 aLabel = aNewObject.GetLabel();
657 if(aLabel.IsNull()) {
658 _errorCode = "StudyInvalidComponent";
662 SALOMEDSImpl_AttributeName::Set(aLabel, vs.back());
664 //Set LocalID attribute to identify the directory object
665 SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
667 _doc->SetModified(true);
673 //============================================================================
674 /*! Function : SetGUID
677 //============================================================================
678 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
679 const string& theGUID)
684 _errorCode = "Invalid arguments";
688 DF_Label aLabel = anObject.GetLabel();
689 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID);
691 _doc->SetModified(true);
696 //============================================================================
697 /*! Function : IsGUID
700 //============================================================================
701 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
702 const string& theGUID)
706 _errorCode = "Invalid arguments";
709 DF_Label aLabel = anObject.GetLabel();
710 return aLabel.IsAttribute(theGUID);
714 //============================================================================
715 /*! Function : NewCommand
718 //============================================================================
719 void SALOMEDSImpl_StudyBuilder::NewCommand()
723 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
724 _study->GetProperties()->IsLockChanged(true);
729 //============================================================================
730 /*! Function : CommitCommand
733 //============================================================================
734 void SALOMEDSImpl_StudyBuilder::CommitCommand()
737 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
738 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
739 _errorCode = "LockProtection";
740 throw LockProtection("LockProtection");
742 int aModif = anAttr->GetModified();
743 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
744 anAttr->SetModified(aModif+1);
749 _doc->SetModified(true);
752 //============================================================================
753 /*! Function : HasOpenCommand
756 //============================================================================
757 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
765 //============================================================================
766 /*! Function : AbortCommand
769 //============================================================================
770 void SALOMEDSImpl_StudyBuilder::AbortCommand()
776 //============================================================================
780 //============================================================================
781 void SALOMEDSImpl_StudyBuilder::Undo()
785 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
786 if (anAttr->IsLocked()) {
787 _errorCode = "LockProtection";
788 throw LockProtection("LockProtection");
790 anAttr->SetModified(anAttr->GetModified()-1);
793 _doc->SetModified(true);
796 //============================================================================
800 //============================================================================
801 void SALOMEDSImpl_StudyBuilder::Redo()
804 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
805 if (anAttr->IsLocked()) {
806 _errorCode = "LockProtection";
807 throw LockProtection("LockProtection");
809 anAttr->SetModified(anAttr->GetModified()+1);
814 _doc->SetModified(true);
817 //============================================================================
818 /*! Function : GetAvailableUndos
821 //============================================================================
822 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
828 //============================================================================
829 /*! Function : GetAvailableRedos
832 //============================================================================
833 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
839 //============================================================================
840 /*! Function : UndoLimit
843 //============================================================================
844 int SALOMEDSImpl_StudyBuilder::UndoLimit()
850 //============================================================================
851 /*! Function : UndoLimit
854 //============================================================================
855 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
862 //============================================================================
863 /*! Function : SetOnAddSObject
866 //============================================================================
867 SALOMEDSImpl_Callback*
868 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const SALOMEDSImpl_Callback* theCallback)
871 SALOMEDSImpl_Callback* aRet = _callbackOnAdd;
872 _callbackOnAdd = (SALOMEDSImpl_Callback*)theCallback;
876 //============================================================================
877 /*! Function : SetOnNewSObject
880 //============================================================================
881 SALOMEDSImpl_Callback*
882 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const SALOMEDSImpl_Callback* theCallback)
885 SALOMEDSImpl_Callback* aRet = _callbackOnRemove;
886 _callbackOnRemove = (SALOMEDSImpl_Callback*)theCallback;
890 //============================================================================
891 /*! Function : CheckLocked
894 //============================================================================
895 void SALOMEDSImpl_StudyBuilder::CheckLocked()
898 if (HasOpenCommand()) return;
899 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
900 if (anAttr->IsLocked()) {
901 _errorCode = "LockProtection";
902 throw LockProtection("LockProtection");
906 //============================================================================
907 /*! Function : SetName
910 //============================================================================
911 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
912 const string& theValue)
917 _errorCode = "Invalid arguments";
920 SALOMEDSImpl_AttributeName::Set(theSO.GetLabel(), theValue);
922 _doc->SetModified(true);
927 //============================================================================
928 /*! Function : SetComment
931 //============================================================================
932 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
933 const string& theValue)
938 _errorCode = "Invalid arguments";
941 SALOMEDSImpl_AttributeComment::Set(theSO.GetLabel(), theValue);
943 _doc->SetModified(true);
948 //============================================================================
949 /*! Function : SetIOR
952 //============================================================================
953 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
954 const string& theValue)
959 _errorCode = "Invalid arguments";
962 SALOMEDSImpl_AttributeIOR::Set(theSO.GetLabel(), theValue);
964 _doc->SetModified(true);
970 //============================================================================
971 /*! Function : Translate_persistentID_to_IOR
974 //============================================================================
975 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
977 if(driver == NULL) return;
978 DF_ChildIterator itchild (Lab);
980 for (; itchild.More(); itchild.Next()) {
981 DF_Label current = itchild.Value();
982 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
983 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
985 SALOMEDSImpl_AttributeLocalID* anID = NULL;
986 if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID())))
987 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
989 string persist_ref = Att->Value();
990 SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
991 string ior_string = driver->LocalPersistentIDToIOR(so,
995 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
998 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);