1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SALOMEDSImpl_StudyBuilder.cxx
24 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_Attributes.hxx"
28 #include "SALOMEDSImpl_Study.hxx"
29 #include "SALOMEDSImpl_StudyBuilder.hxx"
30 #include "SALOMEDSImpl_SObject.hxx"
31 #include "SALOMEDSImpl_SComponent.hxx"
32 #include "SALOMEDSImpl_Tool.hxx"
33 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
35 #include "DF_ChildIterator.hxx"
36 #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 std::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);
94 _study->addSO_Notification(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,
107 const std::string& IOR)
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);
152 _study->addSO_Notification(so);
154 _doc->SetModified(true);
158 //============================================================================
159 /*! Function : NewObjectToTag
162 //============================================================================
163 SALOMEDSImpl_SObject SALOMEDSImpl_StudyBuilder::NewObjectToTag(const SALOMEDSImpl_SObject& theFatherObject,
168 //Find label of father
169 DF_Label Lab = theFatherObject.GetLabel();
171 //Create or find label
172 DF_Label NewLab = Lab.FindChild(theTag, 1);
174 SALOMEDSImpl_SObject so = _study->GetSObject(NewLab);
176 if(_callbackOnAdd) _callbackOnAdd->OnAddSObject(so);
177 _study->addSO_Notification(so);
179 _doc->SetModified(true);
183 //============================================================================
184 /*! Function : RemoveObject
187 //============================================================================
188 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const SALOMEDSImpl_SObject& anObject)
193 _errorCode = "Null object";
197 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
199 DF_Label Lab = anObject.GetLabel();
201 SALOMEDSImpl_AttributeReference* aReference = NULL;
202 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
203 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
204 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
205 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
208 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
209 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
210 _study->DeleteIORLabelMapItem(anAttr->Value());
213 Lab.ForgetAllAttributes();
215 _doc->SetModified(true);
216 _study->removeSO_Notification(anObject);
221 //============================================================================
222 /*! Function : RemoveObjectWithChildren
225 //============================================================================
226 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const SALOMEDSImpl_SObject& anObject)
231 _errorCode = "Null object";
235 if(_callbackOnRemove) _callbackOnRemove->OnRemoveSObject(anObject);
237 DF_Label Lab = anObject.GetLabel();
239 SALOMEDSImpl_AttributeReference* aReference = NULL;
240 if ((aReference=(SALOMEDSImpl_AttributeReference*)Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
241 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
242 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
243 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
245 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
246 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
247 _study->DeleteIORLabelMapItem(anAttr->Value());
250 DF_ChildIterator it(Lab, true);
251 for(;it.More();it.Next()) {
252 DF_Label aLabel = it.Value();
253 if ((aReference=(SALOMEDSImpl_AttributeReference*)aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) {
254 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
255 if ((aTarget=(SALOMEDSImpl_AttributeTarget*)aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID())))
256 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
258 SALOMEDSImpl_AttributeIOR* anAttr = NULL; //Remove from IORLabel map
259 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
260 _study->DeleteIORLabelMapItem(anAttr->Value());
264 Lab.ForgetAllAttributes(true);
266 _doc->SetModified(true);
267 _study->removeSO_Notification(anObject);
272 //============================================================================
273 /*! Function : LoadWith
276 //============================================================================
277 bool SALOMEDSImpl_StudyBuilder::LoadWith(const SALOMEDSImpl_SComponent& anSCO,
278 SALOMEDSImpl_Driver* aDriver)
282 DF_Label Lab = anSCO.GetLabel();
283 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
285 //Find the current Url of the study
286 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
287 int aLocked = _study->GetProperties()->IsLocked();
288 if (aLocked) _study->GetProperties()->SetLocked(false);
290 std::string Res(Att->Value());
291 std::string aHDFPath(Res);
293 SALOMEDSImpl_AttributeComment* type = NULL;
294 std::string DataType;
295 if ((type=(SALOMEDSImpl_AttributeComment*)Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID())))
296 DataType = type->Value();
298 // associate the driver to the SComponent
299 if(aDriver == NULL) {
300 _errorCode = "Driver is null";
304 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
305 SALOMEDSImpl_AttributeIOR* attrIOR = NULL;
306 if ((attrIOR=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
307 if (aLocked) _study->GetProperties()->SetLocked(true);
311 DefineComponentInstance (anSCO, aDriver->GetIOR());
314 bool isASCII = false;
315 if (HDFascii::isASCII(aHDFPath.c_str())) {
317 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.c_str());
318 aHDFUrl += "hdf_from_ascii.hdf";
323 //Open the Study HDF file
324 HDFfile *hdf_file = new HDFfile((char*)aHDFUrl.c_str());
326 char aMultifileState[2];
327 char ASCIIfileState[2];
328 bool hasModuleData = false;
330 std::string scoid = anSCO.GetID();
331 hdf_file->OpenOnDisk(HDF_RDONLY);
332 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
333 hdf_group->OpenOnDisk();
334 HDFgroup *hdf_sco_group = new HDFgroup((char*)scoid.c_str(), hdf_group);
335 hdf_sco_group->OpenOnDisk();
336 hasModuleData = true;
338 unsigned char* aStreamFile = NULL;
341 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
342 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
343 hdf_dataset->OpenOnDisk();
344 aStreamSize = hdf_dataset->GetSize();
345 aStreamFile = new unsigned char[aStreamSize];
346 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
347 hdf_dataset->ReadFromDisk(aStreamFile);
348 hdf_dataset->CloseOnDisk();
353 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
354 multifile_hdf_dataset->OpenOnDisk();
355 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
357 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
358 ascii_hdf_dataset->OpenOnDisk();
359 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
361 std::string aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
364 if(aStreamFile && aStreamSize > 0 ) {
365 aResult = (ASCIIfileState[0]=='A')?
366 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M'):
367 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.c_str(), aMultifileState[0]=='M');
370 if(aStreamFile != NULL) delete []aStreamFile;
373 RemoveAttribute( anSCO, "AttributeIOR" );
375 _errorCode = "Can't load component";
376 throw HDFexception("Unable to load component");
379 //if(aDir != NULL) delete []aDir;
381 multifile_hdf_dataset->CloseOnDisk();
382 multifile_hdf_dataset = 0;
383 ascii_hdf_dataset->CloseOnDisk();
384 ascii_hdf_dataset = 0;
386 hdf_sco_group->CloseOnDisk();
388 hdf_group->CloseOnDisk();
390 hdf_file->CloseOnDisk();
394 std::vector<std::string> aFilesToRemove;
395 aFilesToRemove.push_back("hdf_from_ascii.hdf");
396 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
397 aFilesToRemove, true);
400 catch (HDFexception) {
404 std::vector<std::string> aFilesToRemove;
405 aFilesToRemove.push_back(aHDFUrl);
406 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
409 if (aLocked) _study->GetProperties()->SetLocked(true);
414 _errorCode = "No persistent file";
419 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
421 _errorCode = "Can not convert persistent IDs to IORs";
425 if (aLocked) _study->GetProperties()->SetLocked(true);
427 _errorCode = "No persistent file";
434 //============================================================================
438 //============================================================================
439 bool SALOMEDSImpl_StudyBuilder::Load(const SALOMEDSImpl_SObject& sco)
441 _errorCode = "Not implemented";
445 //============================================================================
446 /*! Function : FindOrCreateAttribute
447 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
450 //============================================================================
451 DF_Attribute* SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const SALOMEDSImpl_SObject& anObject,
452 const std::string& aTypeOfAttribute)
456 _errorCode = "Invalid arguments";
460 DF_Label Lab = anObject.GetLabel();
462 _errorCode = "Null label";
466 _doc->SetModified(true);
468 //The macro adds all necessary checks for standardly behaiving attributes
469 __FindOrCreateAttributeForBuilder
472 //Add checks for TreeNode and UserID attributes
473 if (strncmp(aTypeOfAttribute.c_str(), "AttributeTreeNode",17) == 0 ) {
475 std::string aTreeNodeGUID;
476 if (strcmp(aTypeOfAttribute.c_str(), "AttributeTreeNode") == 0) {
477 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
479 aTreeNodeGUID = aTypeOfAttribute.substr(21, aTypeOfAttribute.size()); // create tree node GUID by name
481 SALOMEDSImpl_AttributeTreeNode* anAttr = NULL;
482 if (!(anAttr=(SALOMEDSImpl_AttributeTreeNode*)Lab.FindAttribute(aTreeNodeGUID))) {
484 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
489 if (strncmp(aTypeOfAttribute.c_str(), "AttributeUserID",15) == 0 ) {
490 std::string aUserGUID;
491 if (strcmp(aTypeOfAttribute.c_str(), "AttributeUserID") == 0) {
492 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
494 aUserGUID = aTypeOfAttribute.substr(15, aTypeOfAttribute.size()); // create tree node GUID by name
496 SALOMEDSImpl_AttributeUserID* anAttr = NULL;
497 if (!(anAttr=(SALOMEDSImpl_AttributeUserID*)Lab.FindAttribute(aUserGUID))) {
499 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
503 _errorCode = "Can not create an attribute";
508 //============================================================================
509 /*! Function : FindAttribute
510 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
512 //============================================================================
514 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const SALOMEDSImpl_SObject& anObject,
515 DF_Attribute*& anAttribute,
516 const std::string& aTypeOfAttribute)
520 _errorCode = "Invalid arguments";
523 DF_Label Lab = anObject.GetLabel();
524 if ((anAttribute=Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute)))) {
525 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
532 //============================================================================
533 /*! Function : RemoveAttribute
534 * Purpose : Remove attribute of given type assigned SObject
536 //============================================================================
538 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const SALOMEDSImpl_SObject& anObject,
539 const std::string& aTypeOfAttribute)
544 _errorCode = "Invalid arguments";
547 DF_Label Lab = anObject.GetLabel();
549 if (aTypeOfAttribute == std::string("AttributeIOR")) { // Remove from IORLabel map
550 SALOMEDSImpl_AttributeIOR* anAttr = NULL;
551 if ((anAttr=(SALOMEDSImpl_AttributeIOR*)Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))) {
552 _study->DeleteIORLabelMapItem(anAttr->Value());
556 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
558 _doc->SetModified(true);
559 _study->modifySO_Notification(anObject,0);
564 //============================================================================
565 /*! Function : Addreference
568 //============================================================================
569 bool SALOMEDSImpl_StudyBuilder::Addreference(const SALOMEDSImpl_SObject& me,
570 const SALOMEDSImpl_SObject& theReferencedObject)
573 if(!me || !theReferencedObject) {
574 _errorCode = "Invalid arguments";
578 DF_Label Lab = me.GetLabel();
579 DF_Label RefLab = theReferencedObject.GetLabel();
580 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
582 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
584 if(_callbackOnRemove && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
589 //============================================================================
590 /*! Function : RemoveReference
593 //============================================================================
594 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const SALOMEDSImpl_SObject& me)
597 SALOMEDSImpl_SObject theReferencedObject;
599 if(!me.ReferencedObject(theReferencedObject)) return false; //No reference is found
602 DF_Label Lab = me.GetLabel();
604 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
606 DF_Label RefLab = theReferencedObject.GetLabel();
608 SALOMEDSImpl_AttributeTarget* aTarget = NULL;
609 if((aTarget=(SALOMEDSImpl_AttributeTarget*)RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID()))) {
610 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
613 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
615 _doc->SetModified(true);
622 //============================================================================
623 /*! Function : AddDirectory
624 * Purpose : adds a new directory with a path = thePath
626 //============================================================================
627 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const std::string& thePath)
631 if(thePath.empty()) {
632 _errorCode = "Invalid path";
636 std::string aPath(thePath), aContext(""), aFatherPath;
638 SALOMEDSImpl_SObject anObject;
641 anObject = _study->FindObjectByPath(thePath); //Check if the directory already exists
646 _errorCode = "StudyNameAlreadyUsed";
650 if(aPath[0] != '/') { //Relative path
651 aPath.insert(aPath.begin(), '/');
652 aPath = _study->GetContext() + aPath;
655 std::vector<std::string> vs = SALOMEDSImpl_Tool::splitString(aPath, '/');
659 for(int i = 0, len = vs.size()-1; i<len; i++) {
661 aFatherPath += vs[i];
666 anObject = _study->FindObjectByPath(aFatherPath); //Check if the father directory exists
670 _errorCode = "StudyInvalidDirectory";
674 SALOMEDSImpl_SObject aNewObject = NewObject(anObject);
675 aLabel = aNewObject.GetLabel();
676 if(aLabel.IsNull()) {
677 _errorCode = "StudyInvalidComponent";
681 SALOMEDSImpl_AttributeName::Set(aLabel, vs.back());
683 //Set LocalID attribute to identify the directory object
684 SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
686 _doc->SetModified(true);
692 //============================================================================
693 /*! Function : SetGUID
696 //============================================================================
697 bool SALOMEDSImpl_StudyBuilder::SetGUID(const SALOMEDSImpl_SObject& anObject,
698 const std::string& theGUID)
703 _errorCode = "Invalid arguments";
707 DF_Label aLabel = anObject.GetLabel();
708 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID);
710 _doc->SetModified(true);
715 //============================================================================
716 /*! Function : IsGUID
719 //============================================================================
720 bool SALOMEDSImpl_StudyBuilder::IsGUID(const SALOMEDSImpl_SObject& anObject,
721 const std::string& theGUID)
725 _errorCode = "Invalid arguments";
728 DF_Label aLabel = anObject.GetLabel();
729 return aLabel.IsAttribute(theGUID);
733 //============================================================================
734 /*! Function : NewCommand
737 //============================================================================
738 void SALOMEDSImpl_StudyBuilder::NewCommand()
742 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
743 _study->GetProperties()->IsLockChanged(true);
748 //============================================================================
749 /*! Function : CommitCommand
752 //============================================================================
753 void SALOMEDSImpl_StudyBuilder::CommitCommand()
756 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
757 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
758 _errorCode = "LockProtection";
759 throw LockProtection("LockProtection");
761 int aModif = anAttr->GetModified();
762 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
763 anAttr->SetModified(aModif+1);
768 _doc->SetModified(true);
771 //============================================================================
772 /*! Function : HasOpenCommand
775 //============================================================================
776 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
784 //============================================================================
785 /*! Function : AbortCommand
788 //============================================================================
789 void SALOMEDSImpl_StudyBuilder::AbortCommand()
795 //============================================================================
799 //============================================================================
800 void SALOMEDSImpl_StudyBuilder::Undo()
804 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
805 if (anAttr->IsLocked()) {
806 _errorCode = "LockProtection";
807 throw LockProtection("LockProtection");
809 anAttr->SetModified(anAttr->GetModified()-1);
812 _doc->SetModified(true);
815 //============================================================================
819 //============================================================================
820 void SALOMEDSImpl_StudyBuilder::Redo()
823 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
824 if (anAttr->IsLocked()) {
825 _errorCode = "LockProtection";
826 throw LockProtection("LockProtection");
828 anAttr->SetModified(anAttr->GetModified()+1);
833 _doc->SetModified(true);
836 //============================================================================
837 /*! Function : GetAvailableUndos
840 //============================================================================
841 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
847 //============================================================================
848 /*! Function : GetAvailableRedos
851 //============================================================================
852 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
858 //============================================================================
859 /*! Function : UndoLimit
862 //============================================================================
863 int SALOMEDSImpl_StudyBuilder::UndoLimit()
869 //============================================================================
870 /*! Function : UndoLimit
873 //============================================================================
874 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
881 //============================================================================
882 /*! Function : SetOnAddSObject
885 //============================================================================
886 SALOMEDSImpl_Callback*
887 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const SALOMEDSImpl_Callback* theCallback)
890 SALOMEDSImpl_Callback* aRet = _callbackOnAdd;
891 _callbackOnAdd = (SALOMEDSImpl_Callback*)theCallback;
895 //============================================================================
896 /*! Function : SetOnNewSObject
899 //============================================================================
900 SALOMEDSImpl_Callback*
901 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const SALOMEDSImpl_Callback* theCallback)
904 SALOMEDSImpl_Callback* aRet = _callbackOnRemove;
905 _callbackOnRemove = (SALOMEDSImpl_Callback*)theCallback;
909 //============================================================================
910 /*! Function : CheckLocked
913 //============================================================================
914 void SALOMEDSImpl_StudyBuilder::CheckLocked()
917 if (HasOpenCommand()) return;
918 SALOMEDSImpl_AttributeStudyProperties* anAttr = _study->GetProperties();
919 if (anAttr->IsLocked()) {
920 _errorCode = "LockProtection";
921 throw LockProtection("LockProtection");
925 //============================================================================
926 /*! Function : SetName
929 //============================================================================
930 bool SALOMEDSImpl_StudyBuilder::SetName(const SALOMEDSImpl_SObject& theSO,
931 const std::string& theValue)
936 _errorCode = "Invalid arguments";
939 SALOMEDSImpl_AttributeName::Set(theSO.GetLabel(), theValue);
941 _doc->SetModified(true);
946 //============================================================================
947 /*! Function : SetComment
950 //============================================================================
951 bool SALOMEDSImpl_StudyBuilder::SetComment(const SALOMEDSImpl_SObject& theSO,
952 const std::string& theValue)
957 _errorCode = "Invalid arguments";
960 SALOMEDSImpl_AttributeComment::Set(theSO.GetLabel(), theValue);
962 _doc->SetModified(true);
967 //============================================================================
968 /*! Function : SetIOR
971 //============================================================================
972 bool SALOMEDSImpl_StudyBuilder::SetIOR(const SALOMEDSImpl_SObject& theSO,
973 const std::string& theValue)
978 _errorCode = "Invalid arguments";
981 SALOMEDSImpl_AttributeIOR::Set(theSO.GetLabel(), theValue);
983 _doc->SetModified(true);
989 //============================================================================
990 /*! Function : Translate_persistentID_to_IOR
993 //============================================================================
994 static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
996 if(driver == NULL) return;
997 DF_ChildIterator itchild (Lab);
999 for (; itchild.More(); itchild.Next()) {
1000 DF_Label current = itchild.Value();
1001 SALOMEDSImpl_AttributePersistentRef* Att = NULL;
1002 if ((Att=(SALOMEDSImpl_AttributePersistentRef*)current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID()))) {
1004 SALOMEDSImpl_AttributeLocalID* anID = NULL;
1005 if ((anID=(SALOMEDSImpl_AttributeLocalID*)current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID())))
1006 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
1008 std::string persist_ref = Att->Value();
1009 SALOMEDSImpl_SObject so = SALOMEDSImpl_Study::SObject(current);
1010 std::string ior_string = driver->LocalPersistentIDToIOR(so,
1014 SALOMEDSImpl_AttributeIOR* iorAttr = SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
1016 // make myRefCounter of a loaded GenericObj == 1
1017 SALOMEDSImpl_Study::UnRegisterGenObj( ior_string, iorAttr->Label());
1019 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);