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"
41 #define USE_CASE_LABEL_TAG 2
42 #define DIRECTORYID 16661
43 #define FILELOCALID 26662
45 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII);
47 //============================================================================
48 /*! Function : constructor
51 //============================================================================
52 SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const SALOMEDSImpl_Study* theOwner)
56 _callbackOnRemove = NULL;
57 _study = (SALOMEDSImpl_Study*)theOwner;
58 _doc = _study->GetDocument();
61 //============================================================================
62 /*! Function : destructor
65 //============================================================================
66 SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
69 //============================================================================
70 /*! Function : NewComponent
71 * Purpose : Create a new component (Scomponent)
73 //============================================================================
74 SALOMEDSImpl_SComponent SALOMEDSImpl_StudyBuilder::NewComponent(const std::string& DataType)
79 SALOMEDSImpl_SComponent sco;
81 if(DataType.size() == 0) return sco;
83 //Always create component under main label.
84 DF_Label L = _doc->Main();
86 DF_Label NL = L.NewChild();
88 SALOMEDSImpl_AttributeComment::Set(NL, DataType);
90 SALOMEDSImpl_SComponent so = _study->GetSComponent (NL);
92 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
94 _doc->SetModified(true);
99 //============================================================================
100 /*! Function : DefineComponentInstance
101 * Purpose : Add IOR attribute of a Scomponent
103 //============================================================================
104 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const SALOMEDSImpl_SComponent& aComponent,
105 const std::string& IOR)
110 if(!aComponent || IOR.empty()) {
111 _errorCode = "Invalid arguments";
115 SALOMEDSImpl_AttributeIOR::Set(aComponent.GetLabel(), IOR);
120 //============================================================================
121 /*! Function : RemoveComponent
122 * Purpose : Delete a Scomponent
124 //============================================================================
125 bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const SALOMEDSImpl_SComponent& aComponent)
129 return RemoveObject(aComponent);
132 //============================================================================
133 /*! Function : NewObject
134 * Purpose : Create a new SObject
136 //============================================================================
137 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObject(const SALOMEDSImpl_SObject& theFatherObject)
142 //Find label of father
143 DF_Label Lab = theFatherObject.GetLabel();
146 DF_Label NewLab = Lab.NewChild();
148 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
149 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
151 _doc->SetModified(true);
155 //============================================================================
156 /*! Function : NewObjectToTag
159 //============================================================================
160 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject,
165 //Find label of father
166 DF_Label Lab = theFatherObject.GetLabel();
168 //Create or find label
169 DF_Label NewLab = Lab.FindChild(theTag, 1);
171 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
173 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
175 _doc->SetModified(true);
179 //============================================================================
180 /*! Function : RemoveObject
183 //============================================================================
184 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObject)
189 _errorCode = "Null object";
193 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
195 DF_Label Lab = anObject.GetLabel();
197 SALOMEDSImpl_AttributeReference* aReference = NULL;
198 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
199 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
200 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
201 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
204 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
205 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
206 _study->DeleteIORLabelMapItem(anAttr->Value());
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()))) {
242 _study->DeleteIORLabelMapItem(anAttr->Value());
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()))) {
255 _study->DeleteIORLabelMapItem(anAttr->Value());
259 Lab.ForgetAllAttributes(true);
261 _doc->SetModified(true);
266 //============================================================================
267 /*! Function : LoadWith
270 //============================================================================
271 bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
272 SALOMEDSImpl_Driver* aDriver)
276 DF_Label Lab = anSCO.GetLabel();
277 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
279 //Find the current Url of the study
280 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
281 int aLocked = _study->GetProperties()->IsLocked();
282 if (aLocked) _study->GetProperties()->SetLocked(false);
284 std::string Res(Att->Value());
285 std::string aHDFPath(Res);
287 SALOMEDSImpl_AttributeComment* type = NULL;
288 std::string DataType;
289 if ((type=(SALOMEDSImpl_AttributeComment*)Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID())))
290 DataType = type->Value();
292 // associate the driver to the SComponent
293 if(aDriver == NULL) {
294 _errorCode = "Driver is null";
298 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
299 SALOMEDSImpl_AttributeIOR* attrIOR = NULL;
300 if ((attrIOR=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
301 if (aLocked) _study->GetProperties()->SetLocked(true);
305 DefineComponentInstance (anSCO, aDriver->GetIOR());
308 bool isASCII = false;
309 if (HDFascii::isASCII(aHDFPath.c_str())) {
311 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.c_str());
312 aHDFUrl += "hdf_from_ascii.hdf";
317 //Open the Study HDF file
318 HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
320 char aMultifileState[2];
321 char ASCIIfileState[2];
323 std::string scoid = anSCO.GetID();
324 hdf_file->OpenOnDisk(HDF_RDONLY);
325 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
326 hdf_group->OpenOnDisk();
327 HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
328 hdf_sco_group->OpenOnDisk();
330 unsigned char* aStreamFile = NULL;
333 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
334 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
335 hdf_dataset->OpenOnDisk();
336 aStreamSize = hdf_dataset->GetSize();
337 aStreamFile = new unsigned char[aStreamSize];
338 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
339 hdf_dataset->ReadFromDisk(aStreamFile);
340 hdf_dataset->CloseOnDisk();
345 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
346 multifile_hdf_dataset->OpenOnDisk();
347 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
349 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
350 ascii_hdf_dataset->OpenOnDisk();
351 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
353 std::string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
355 bool aResult = (ASCIIfileState[0]=='A')?
356 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
357 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
359 if(aStreamFile != NULL) delete []aStreamFile;
362 RemoveAttribute( anSCO, "AttributeIOR" );
364 _errorCode = "Can't load component";
365 throw HDFexception("Unable to load component");
368 //if(aDir != NULL) delete []aDir;
370 multifile_hdf_dataset->CloseOnDisk();
371 multifile_hdf_dataset = 0;
372 ascii_hdf_dataset->CloseOnDisk();
373 ascii_hdf_dataset = 0;
375 hdf_sco_group->CloseOnDisk();
377 hdf_group->CloseOnDisk();
379 hdf_file->CloseOnDisk();
383 std::vector<std::string> aFilesToRemove;
384 aFilesToRemove.push_back("hdf_from_ascii.hdf");
385 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
386 aFilesToRemove, true);
389 catch (HDFexception) {
393 std::vector<std::string> aFilesToRemove;
394 aFilesToRemove.push_back(aHDFUrl);
395 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
398 if (aLocked) _study->GetProperties()->SetLocked(true);
399 _errorCode = "No persistent file";
404 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
406 _errorCode = "Can not convert persistent IDs to IORs";
410 if (aLocked) _study->GetProperties()->SetLocked(true);
412 _errorCode = "No persistent file";
419 //============================================================================
423 //============================================================================
424 bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
426 _errorCode = "Not implemented";
430 //============================================================================
431 /*! Function : FindOrCreateAttribute
432 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
435 //============================================================================
436 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
437 const std::string& aTypeOfAttribute)
441 _errorCode = "Invalid arguments";
445 DF_Label Lab = anObject.GetLabel();
447 _errorCode = "Null label";
451 _doc->SetModified(true);
453 //The macro adds all necessary checks for standardly behaiving attributes
454 __FindOrCreateAttributeForBuilder
457 //Add checks for TreeNode and UserID attributes
458 if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
460 std::string aTreeNodeGUID;
461 if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
462 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
464 aTreeNodeGUID = aTypeOfAttribute.substr(21, aTypeOfAttribute.size()); // create tree node GUID by name
466 SALOMEDSImpl_AttributeTreeNode* anAttr = NULL;
467 if (!(anAttr=(SALOMEDSImpl_AttributeTreeNode*)Lab.FindAttribute(aTreeNodeGUID))) {
469 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
474 if (strncmp(aTypeOfAttribute.c_str(), "AttributeUserID",15) == 0 ) {
475 std::string aUserGUID;
476 if (strcmp(aTypeOfAttribute.c_str(), "AttributeUserID") == 0) {
477 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
479 aUserGUID = aTypeOfAttribute.substr(15, aTypeOfAttribute.size()); // create tree node GUID by name
481 SALOMEDSImpl_AttributeUserID* anAttr = NULL;
482 if (!(anAttr=(SALOMEDSImpl_AttributeUserID*)Lab.FindAttribute(aUserGUID))) {
484 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
488 _errorCode = "Can not create an attribute";
493 //============================================================================
494 /*! Function : FindAttribute
495 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
497 //============================================================================
499 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
500 DF_Attribute*& anAttribute,
501 const std::string& aTypeOfAttribute)
505 _errorCode = "Invalid arguments";
508 DF_Label Lab = anObject.GetLabel();
509 if ((anAttribute=Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)))) {
510 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
517 //============================================================================
518 /*! Function : RemoveAttribute
519 * Purpose : Remove attribute of given type assigned SObject
521 //============================================================================
523 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
524 const std::string& aTypeOfAttribute)
529 _errorCode = "Invalid arguments";
532 DF_Label Lab = anObject.GetLabel();
534 if (aTypeOfAttribute == std::string("AttributeIOR")) { // Remove from IORLabel map
535 SALOMEDSImpl_AttributeIOR* anAttr = NULL;
536 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
537 _study->DeleteIORLabelMapItem(anAttr->Value());
541 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
543 _doc->SetModified(true);
548 //============================================================================
549 /*! Function : Addreference
552 //============================================================================
553 bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
554 const SALOMEDSImpl_SObject& theReferencedObject)
557 if(!me || !theReferencedObject) {
558 _errorCode = "Invalid arguments";
562 DF_Label Lab = me.GetLabel();
563 DF_Label RefLab = theReferencedObject.GetLabel();
564 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
566 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
568 if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
573 //============================================================================
574 /*! Function : RemoveReference
577 //============================================================================
578 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
581 SALOMEDSImpl_SObject theReferencedObject;
583 if(!me.ReferencedObject(theReferencedObject)) return false; //No reference is found
586 DF_Label Lab = me.GetLabel();
588 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
590 DF_Label RefLab = theReferencedObject.GetLabel();
592 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
593 if((aTarget=(SALOMEDSImpl_AttributeTarget*)RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
594 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
597 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
599 _doc->SetModified(true);
606 //============================================================================
607 /*! Function : AddDirectory
608 * Purpose : adds a new directory with a path = thePath
610 //============================================================================
611 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const std::string& thePath)
615 if(thePath.empty()) {
616 _errorCode = "Invalid path";
620 std::string aPath(thePath), aContext(""), aFatherPath;
622 SALOMEDSImpl_SObject anObject;
625 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
630 _errorCode = "StudyNameAlreadyUsed";
634 if(aPath[0] != '/') { //Relative path
635 aPath.insert(aPath.begin(), '/');
636 aPath = _study->GetContext() + aPath;
639 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
643 for(int i = 0, len = vs.size()-1; i<len; i++) {
645 aFatherPath += vs[i];
650 anObject = _study->FindObjectByPath(aFatherPath); //Check if the father directory exists
654 _errorCode = "StudyInvalidDirectory";
658 SALOMEDSImpl_SObject aNewObject = NewObject(anObject);
659 aLabel = aNewObject.GetLabel();
660 if(aLabel.IsNull()) {
661 _errorCode = "StudyInvalidComponent";
665 SALOMEDSImpl_AttributeName::Set(aLabel, vs.back());
667 //Set LocalID attribute to identify the directory object
668 SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
670 _doc->SetModified(true);
676 //============================================================================
677 /*! Function : SetGUID
680 //============================================================================
681 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
682 const std::string& theGUID)
687 _errorCode = "Invalid arguments";
691 DF_Label aLabel = anObject.GetLabel();
692 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID);
694 _doc->SetModified(true);
699 //============================================================================
700 /*! Function : IsGUID
703 //============================================================================
704 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
705 const std::string& theGUID)
709 _errorCode = "Invalid arguments";
712 DF_Label aLabel = anObject.GetLabel();
713 return aLabel.IsAttribute(theGUID);
717 //============================================================================
718 /*! Function : NewCommand
721 //============================================================================
722 void SALOMEDSImpl_StudyBuilder::NewCommand()
726 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
727 _study->GetProperties()->IsLockChanged(true);
732 //============================================================================
733 /*! Function : CommitCommand
736 //============================================================================
737 void SALOMEDSImpl_StudyBuilder::CommitCommand()
740 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
741 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
742 _errorCode = "LockProtection";
743 throw LockProtection("LockProtection");
745 int aModif = anAttr->GetModified();
746 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
747 anAttr->SetModified(aModif+1);
752 _doc->SetModified(true);
755 //============================================================================
756 /*! Function : HasOpenCommand
759 //============================================================================
760 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
768 //============================================================================
769 /*! Function : AbortCommand
772 //============================================================================
773 void SALOMEDSImpl_StudyBuilder::AbortCommand()
779 //============================================================================
783 //============================================================================
784 void SALOMEDSImpl_StudyBuilder::Undo()
788 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
789 if (anAttr->IsLocked()) {
790 _errorCode = "LockProtection";
791 throw LockProtection("LockProtection");
793 anAttr->SetModified(anAttr->GetModified()-1);
796 _doc->SetModified(true);
799 //============================================================================
803 //============================================================================
804 void SALOMEDSImpl_StudyBuilder::Redo()
807 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
808 if (anAttr->IsLocked()) {
809 _errorCode = "LockProtection";
810 throw LockProtection("LockProtection");
812 anAttr->SetModified(anAttr->GetModified()+1);
817 _doc->SetModified(true);
820 //============================================================================
821 /*! Function : GetAvailableUndos
824 //============================================================================
825 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
831 //============================================================================
832 /*! Function : GetAvailableRedos
835 //============================================================================
836 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
842 //============================================================================
843 /*! Function : UndoLimit
846 //============================================================================
847 int SALOMEDSImpl_StudyBuilder::UndoLimit()
853 //============================================================================
854 /*! Function : UndoLimit
857 //============================================================================
858 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
865 //============================================================================
866 /*! Function : SetOnAddSObject
869 //============================================================================
870 SALOMEDSImpl_Callback*
871 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const SALOMEDSImpl_Callback* theCallback)
874 SALOMEDSImpl_Callback* aRet = _callbackOnAdd;
875 _callbackOnAdd = (SALOMEDSImpl_Callback*)theCallback;
879 //============================================================================
880 /*! Function : SetOnNewSObject
883 //============================================================================
884 SALOMEDSImpl_Callback*
885 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const SALOMEDSImpl_Callback* theCallback)
888 SALOMEDSImpl_Callback* aRet = _callbackOnRemove;
889 _callbackOnRemove = (SALOMEDSImpl_Callback*)theCallback;
893 //============================================================================
894 /*! Function : CheckLocked
897 //============================================================================
898 void SALOMEDSImpl_StudyBuilder::CheckLocked()
901 if (HasOpenCommand()) return;
902 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
903 if (anAttr->IsLocked()) {
904 _errorCode = "LockProtection";
905 throw LockProtection("LockProtection");
909 //============================================================================
910 /*! Function : SetName
913 //============================================================================
914 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
915 const std::string& theValue)
920 _errorCode = "Invalid arguments";
923 SALOMEDSImpl_AttributeName::Set(theSO.GetLabel(), theValue);
925 _doc->SetModified(true);
930 //============================================================================
931 /*! Function : SetComment
934 //============================================================================
935 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
936 const std::string& theValue)
941 _errorCode = "Invalid arguments";
944 SALOMEDSImpl_AttributeComment::Set(theSO.GetLabel(), theValue);
946 _doc->SetModified(true);
951 //============================================================================
952 /*! Function : SetIOR
955 //============================================================================
956 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
957 const std::string& theValue)
962 _errorCode = "Invalid arguments";
965 SALOMEDSImpl_AttributeIOR::Set(theSO.GetLabel(), theValue);
967 _doc->SetModified(true);
973 //============================================================================
974 /*! Function : Translate_persistentID_to_IOR
977 //============================================================================
978 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
980 if(driver == NULL) return;
981 DF_ChildIterator itchild (Lab);
983 for (; itchild.More(); itchild.Next()) {
984 DF_Label current = itchild.Value();
985 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
986 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
988 SALOMEDSImpl_AttributeLocalID* anID = NULL;
989 if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID())))
990 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
992 std::string persist_ref = Att->Value();
993 SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
994 std::string ior_string = driver->LocalPersistentIDToIOR(so,
998 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
1001 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);