1 // File : SALOMEDSImpl_StudyBuilder.cxx
2 // Author : Sergey RUIN
7 #include "SALOMEDSImpl_Attributes.hxx"
11 #include "SALOMEDSImpl_Study.hxx"
12 #include "SALOMEDSImpl_StudyBuilder.hxx"
13 #include "SALOMEDSImpl_SObject.hxx"
14 #include "SALOMEDSImpl_SComponent.hxx"
15 #include "SALOMEDSImpl_Tool.hxx"
17 #include <TDF_ChildIterator.hxx>
18 #include <TDF_Label.hxx>
19 #include <TDF_Tool.hxx>
20 #include <TDF_Data.hxx>
21 #include <SALOMEDSImpl_ChildNodeIterator.hxx>
22 #include <TDF_ListIteratorOfAttributeList.hxx>
27 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_StudyBuilder, MMgt_TShared )
28 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_StudyBuilder, MMgt_TShared )
30 #define USE_CASE_LABEL_TAG 2
31 #define DIRECTORYID 16661
32 #define FILELOCALID 26662
34 static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII);
36 //============================================================================
37 /*! Function : constructor
40 //============================================================================
41 SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const Handle(Standard_Transient)& theOwner)
45 _doc = Handle(SALOMEDSImpl_Study)::DownCast(theOwner)->GetDocument();
48 //============================================================================
49 /*! Function : destructor
52 //============================================================================
53 SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
56 //============================================================================
57 /*! Function : NewComponent
58 * Purpose : Create a new component (Scomponent)
60 //============================================================================
61 Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_StudyBuilder::NewComponent(const TCollection_AsciiString& DataType)
65 //Always create component under main label.
66 TDF_Label L = _doc->Main();
69 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
70 if (it.Value().Tag() > imax)
71 imax = it.Value().Tag();
74 TDF_Label NL = L.FindChild(imax);
76 SALOMEDSImpl_AttributeComment::Set(NL, DataType);
78 Handle(SALOMEDSImpl_SComponent) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSComponent (NL);
80 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
87 //============================================================================
88 /*! Function : DefineComponentInstance
89 * Purpose : Add IOR attribute of a Scomponent
91 //============================================================================
92 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const Handle(SALOMEDSImpl_SComponent)& aComponent,
93 const TCollection_AsciiString& IOR)
98 if(aComponent.IsNull() || IOR.IsEmpty()) {
99 _errorCode = "Invalid arguments";
103 SALOMEDSImpl_AttributeIOR::Set(aComponent->GetLabel(), IOR);
110 //============================================================================
111 /*! Function : RemoveComponent
112 * Purpose : Delete a Scomponent
114 //============================================================================
115 bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const Handle(SALOMEDSImpl_SComponent)& aComponent)
119 return RemoveObject(aComponent);
122 //============================================================================
123 /*! Function : NewObject
124 * Purpose : Create a new SObject
126 //============================================================================
127 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObject(const Handle(SALOMEDSImpl_SObject)& theFatherObject)
132 //Find label of father
133 TDF_Label Lab = theFatherObject->GetLabel();
137 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
138 if (it.Value().Tag() > imax)
139 imax = it.Value().Tag();
142 TDF_Label NewLab = Lab.FindChild(imax);
144 Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab);
145 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
151 //============================================================================
152 /*! Function : NewObjectToTag
155 //============================================================================
156 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObjectToTag(const Handle(SALOMEDSImpl_SObject)& theFatherObject,
161 //Find label of father
162 TDF_Label Lab = theFatherObject->GetLabel();
164 //Create or find label
165 TDF_Label NewLab = Lab.FindChild(theTag, 1);
167 Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab);
169 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
175 //============================================================================
176 /*! Function : RemoveObject
179 //============================================================================
180 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const Handle(SALOMEDSImpl_SObject)& anObject)
184 if(anObject.IsNull()) {
185 _errorCode = "Null object";
189 if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject);
191 TDF_Label Lab = anObject->GetLabel();
193 Handle(SALOMEDSImpl_AttributeReference) aReference;
194 if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
195 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
196 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
197 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
200 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
201 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
202 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
204 Lab.ForgetAllAttributes();
211 //============================================================================
212 /*! Function : RemoveObjectWithChildren
215 //============================================================================
216 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const Handle(SALOMEDSImpl_SObject)& anObject)
220 if(anObject.IsNull()) {
221 _errorCode = "Null object";
225 if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject);
227 TDF_Label Lab = anObject->GetLabel();
229 Handle(SALOMEDSImpl_AttributeReference) aReference;
230 if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
231 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
232 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
233 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
235 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
236 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
237 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
239 TDF_ChildIterator it(Lab, Standard_True);
240 for(;it.More();it.Next()) {
241 TDF_Label aLabel = it.Value();
242 if (aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
243 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
244 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
245 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
247 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
248 if (aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
249 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
252 Lab.ForgetAllAttributes(Standard_True);
259 //============================================================================
260 /*! Function : LoadWith
263 //============================================================================
264 bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)& anSCO, SALOMEDSImpl_Driver* aDriver)
268 TDF_Label Lab = anSCO->GetLabel();
269 Handle(SALOMEDSImpl_AttributePersistentRef) Att;
271 //Find the current Url of the study
272 if (_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) {
273 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
274 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
276 TCollection_ExtendedString Res(Att->Value());
278 Handle(SALOMEDSImpl_AttributeComment) type;
279 TCollection_ExtendedString DataType;
280 if (Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(),type))
281 DataType = type->Value();
283 // associate the driver to the SComponent
284 if(aDriver == NULL) {
285 _errorCode = "Driver is null";
289 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
290 Handle(SALOMEDSImpl_AttributeIOR) attrIOR;
291 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), attrIOR)) {
292 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
296 DefineComponentInstance (anSCO, aDriver->GetIOR());
298 TCollection_AsciiString aHDFPath(Res);
301 bool isASCII = false;
302 if (HDFascii::isASCII(aHDFPath.ToCString())) {
304 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString());
305 aHDFUrl = new char[strlen(aResultPath) + 19];
306 sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath);
309 aHDFUrl = aHDFPath.ToCString();
312 //Open the Study HDF file
313 HDFfile *hdf_file = new HDFfile(aHDFUrl);
315 char aMultifileState[2];
316 char ASCIIfileState[2];
318 TCollection_AsciiString scoid = anSCO->GetID();
319 hdf_file->OpenOnDisk(HDF_RDONLY);
320 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
321 hdf_group->OpenOnDisk();
322 HDFgroup *hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group);
323 hdf_sco_group->OpenOnDisk();
325 unsigned char* aStreamFile = NULL;
328 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
329 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
330 hdf_dataset->OpenOnDisk();
331 aStreamSize = hdf_dataset->GetSize();
332 aStreamFile = new unsigned char[aStreamSize];
333 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
334 hdf_dataset->ReadFromDisk(aStreamFile);
335 hdf_dataset->CloseOnDisk();
337 } else aStreamFile = NULL;
339 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
340 multifile_hdf_dataset->OpenOnDisk();
341 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
343 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
344 ascii_hdf_dataset->OpenOnDisk();
345 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
347 // set path without file name from URL
348 int aFileNameSize = Res.Length();
349 char* aDir = new char[aFileNameSize];
350 memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
351 for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
352 if (aDir[aCounter] == '/') {
353 aDir[aCounter+1] = 0;
357 bool aResult = (ASCIIfileState[0]=='A')?
358 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir, aMultifileState[0]=='M'):
359 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir, 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 Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
386 aFilesToRemove->Append(aHDFUrl);
387 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
392 catch (HDFexception) {
396 Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
397 aFilesToRemove->Append(aHDFUrl);
398 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
402 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
403 _errorCode = "No persistent file";
408 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
410 _errorCode = "Can not convert persistent IDs to IORs";
414 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
416 _errorCode = "No persistent file";
423 //============================================================================
427 //============================================================================
428 bool SALOMEDSImpl_StudyBuilder::Load(const Handle(SALOMEDSImpl_SObject)& sco)
430 _errorCode = "Not implemented";
434 //============================================================================
435 /*! Function : FindOrCreateAttribute
436 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
439 //============================================================================
440 Handle(TDF_Attribute) SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const Handle(SALOMEDSImpl_SObject)& anObject,
441 const TCollection_AsciiString& aTypeOfAttribute)
444 if(anObject.IsNull()) {
445 _errorCode = "Invalid arguments";
449 TDF_Label Lab = anObject->GetLabel();
451 _errorCode = "Null label";
457 //The macro adds all necessary checks for standardly behaiving attributes
458 __FindOrCreateAttributeForBuilder
460 //Add checks for TreeNode and UserID attributes
461 if (strncmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode",17) == 0 ) {
462 Standard_GUID aTreeNodeGUID;
463 if (strcmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode") == 0) {
464 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
466 char* aGUIDString = new char[40];
467 char* aType = (char*)aTypeOfAttribute.ToCString();
468 sprintf(aGUIDString, &(aType[21]));
469 aTreeNodeGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
472 Handle(SALOMEDSImpl_AttributeTreeNode) anAttr;
473 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr)) {
475 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
480 if (strncmp(aTypeOfAttribute.ToCString(), "AttributeUserID",15) == 0 ) {
481 Handle(SALOMEDSImpl_AttributeUserID) anAttr;
482 if (!Lab.FindAttribute(SALOMEDSImpl_AttributeUserID::DefaultID(), anAttr)) {
484 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, SALOMEDSImpl_AttributeUserID::DefaultID());
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 Handle(SALOMEDSImpl_SObject)& anObject,
500 Handle(TDF_Attribute)& anAttribute,
501 const TCollection_AsciiString& aTypeOfAttribute)
504 if(anObject.IsNull()) {
505 _errorCode = "Invalid arguments";
508 TDF_Label Lab = anObject->GetLabel();
509 if (Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute), anAttribute)) {
511 return Standard_True;
513 return Standard_False;
516 //============================================================================
517 /*! Function : RemoveAttribute
518 * Purpose : Remove attribute of given type assigned SObject
520 //============================================================================
522 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const Handle(SALOMEDSImpl_SObject)& anObject,
523 const TCollection_AsciiString& aTypeOfAttribute)
527 if(anObject.IsNull()) {
528 _errorCode = "Invalid arguments";
531 TDF_Label Lab = anObject->GetLabel();
533 if (aTypeOfAttribute == "AttributeIOR") { // postponed removing of CORBA objects
534 Handle(SALOMEDSImpl_AttributeIOR) anAttr;
535 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
536 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(anAttr->Value());
539 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
546 //============================================================================
547 /*! Function : Addreference
550 //============================================================================
551 bool SALOMEDSImpl_StudyBuilder::Addreference(const Handle(SALOMEDSImpl_SObject)& me,
552 const Handle(SALOMEDSImpl_SObject)& theReferencedObject)
555 if(me.IsNull() || theReferencedObject.IsNull()) {
556 _errorCode = "Invalid arguments";
560 TDF_Label Lab = me->GetLabel();
561 TDF_Label RefLab = theReferencedObject->GetLabel();
562 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
564 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
566 if(!_callbackOnRemove.IsNull() && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
571 //============================================================================
572 /*! Function : RemoveReference
575 //============================================================================
576 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const Handle(SALOMEDSImpl_SObject)& me)
579 Handle(SALOMEDSImpl_SObject) theReferencedObject;
580 if(!me->ReferencedObject(theReferencedObject)) return false; //No reference is found
583 TDF_Label Lab = me->GetLabel();
585 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
587 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
589 TDF_Label RefLab = theReferencedObject->GetLabel();
591 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
592 if(RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(), aTarget))
593 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
602 //============================================================================
603 /*! Function : AddDirectory
604 * Purpose : adds a new directory with a path = thePath
606 //============================================================================
607 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const TCollection_AsciiString& thePath)
611 if(thePath.IsEmpty() || thePath == "") {
612 _errorCode = "Invalid path";
616 TCollection_AsciiString aPath(thePath), aContext(""), aFatherPath;
618 Handle(SALOMEDSImpl_Study) aStudy = SALOMEDSImpl_Study::GetStudy(_doc->Main());
619 Handle(SALOMEDSImpl_SObject) anObject;
622 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
626 if(!anObject.IsNull()) {
627 _errorCode = "StudyNameAlreadyUsed";
631 if(aPath.Value(1) != '/') { //Relative path
633 aPath = aStudy->GetContext() + aPath;
636 TCollection_AsciiString aToken = aPath.Token("/", 1);
637 if(aToken.Length() == 0) aFatherPath = "/";
640 while(aToken.Length() != 0) {
641 if(aPath.Token("/", i+1).Length() > 0) {
643 aFatherPath += aToken;
645 aToken = aPath.Token("/", ++i);
650 anObject = aStudy->FindObjectByPath(aFatherPath); //Check if the father directory exists
653 if(anObject.IsNull()) {
654 _errorCode = "StudyInvalidDirectory";
658 Handle(SALOMEDSImpl_SObject) aNewObject = NewObject(anObject);
659 aLabel = aNewObject->GetLabel();
660 if(aLabel.IsNull()) {
661 _errorCode = "StudyInvalidComponent";
665 SALOMEDSImpl_AttributeName::Set(aLabel, aPath.Token("/", i-1));
667 //Set LocalID attribute to identify the directory object
668 Handle(SALOMEDSImpl_AttributeLocalID) aLocalID = SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
676 //============================================================================
677 /*! Function : SetGUID
680 //============================================================================
681 bool SALOMEDSImpl_StudyBuilder::SetGUID(const Handle(SALOMEDSImpl_SObject)& anObject,
682 const TCollection_AsciiString& theGUID)
686 if(anObject.IsNull()) {
687 _errorCode = "Invalid arguments";
691 TDF_Label aLabel = anObject->GetLabel();
692 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID.ToCString());
699 //============================================================================
700 /*! Function : IsGUID
703 //============================================================================
704 bool SALOMEDSImpl_StudyBuilder::IsGUID(const Handle(SALOMEDSImpl_SObject)& anObject,
705 const TCollection_AsciiString& theGUID)
708 if(anObject.IsNull()) {
709 _errorCode = "Invalid arguments";
712 TDF_Label aLabel = anObject->GetLabel();
713 return aLabel.IsAttribute(theGUID.ToCString());
717 //============================================================================
718 /*! Function : NewCommand
721 //============================================================================
722 void SALOMEDSImpl_StudyBuilder::NewCommand()
725 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
726 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
727 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
728 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
729 _doc->Main().AddAttribute(anAttr);
731 anAttr->IsLockChanged(true);
736 //============================================================================
737 /*! Function : CommitCommand
740 //============================================================================
741 void SALOMEDSImpl_StudyBuilder::CommitCommand()
744 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
745 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
746 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
747 _doc->Main().AddAttribute(anAttr);
749 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
751 _errorCode = "LockProtection";
752 throw LockProtection("LockProtection");
754 SALOMEDSImpl_Study::GetStudy(_doc->Main())->RemovePostponed(_doc->GetUndoLimit());
756 int aModif = anAttr->GetModified();
757 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
758 anAttr->SetModified(aModif+1);
759 _doc->CommitCommand();
765 //============================================================================
766 /*! Function : HasOpenCommand
769 //============================================================================
770 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
773 return _doc->HasOpenCommand();
776 //============================================================================
777 /*! Function : AbortCommand
780 //============================================================================
781 void SALOMEDSImpl_StudyBuilder::AbortCommand()
784 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(0);
786 _doc->AbortCommand();
789 //============================================================================
793 //============================================================================
794 void SALOMEDSImpl_StudyBuilder::Undo()
797 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
798 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
799 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
800 _doc->Main().AddAttribute(anAttr);
802 if (anAttr->IsLocked()) {
803 _errorCode = "LockProtection";
804 throw LockProtection("LockProtection");
806 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(1);
808 anAttr->SetModified(anAttr->GetModified()-1);
814 //============================================================================
818 //============================================================================
819 void SALOMEDSImpl_StudyBuilder::Redo()
822 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
823 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
824 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
825 _doc->Main().AddAttribute(anAttr);
828 if (anAttr->IsLocked()) {
829 _errorCode = "LockProtection";
830 throw LockProtection("LockProtection");
833 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(-1);
834 anAttr->SetModified(anAttr->GetModified()+1);
840 //============================================================================
841 /*! Function : GetAvailableUndos
844 //============================================================================
845 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
848 return _doc->GetAvailableUndos();
851 //============================================================================
852 /*! Function : GetAvailableRedos
855 //============================================================================
856 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
859 return _doc->GetAvailableRedos();
862 //============================================================================
863 /*! Function : UndoLimit
866 //============================================================================
867 int SALOMEDSImpl_StudyBuilder::UndoLimit()
870 return _doc->GetUndoLimit();
873 //============================================================================
874 /*! Function : UndoLimit
877 //============================================================================
878 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
882 _doc->SetUndoLimit (n);
885 //============================================================================
886 /*! Function : SetOnAddSObject
889 //============================================================================
890 Handle(SALOMEDSImpl_Callback)
891 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const Handle(SALOMEDSImpl_Callback)& theCallback)
894 Handle(SALOMEDSImpl_Callback) aRet = _callbackOnAdd;
895 _callbackOnAdd = theCallback;
899 //============================================================================
900 /*! Function : SetOnNewSObject
903 //============================================================================
904 Handle(SALOMEDSImpl_Callback)
905 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const Handle(SALOMEDSImpl_Callback)& theCallback)
908 Handle(SALOMEDSImpl_Callback) aRet = _callbackOnRemove;
909 _callbackOnRemove = theCallback;
913 //============================================================================
914 /*! Function : CheckLocked
917 //============================================================================
918 void SALOMEDSImpl_StudyBuilder::CheckLocked()
921 if (_doc->HasOpenCommand()) return;
922 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
923 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
924 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
925 _doc->Main().AddAttribute(anAttr);
927 if (anAttr->IsLocked()) {
928 _errorCode = "LockProtection";
929 throw LockProtection("LockProtection");
933 //============================================================================
934 /*! Function : SetName
937 //============================================================================
938 bool SALOMEDSImpl_StudyBuilder::SetName(const Handle(SALOMEDSImpl_SObject)& theSO,
939 const TCollection_AsciiString& theValue)
944 _errorCode = "Invalid arguments";
947 SALOMEDSImpl_AttributeName::Set(theSO->GetLabel(), theValue);
954 //============================================================================
955 /*! Function : SetComment
958 //============================================================================
959 bool SALOMEDSImpl_StudyBuilder::SetComment(const Handle(SALOMEDSImpl_SObject)& theSO,
960 const TCollection_AsciiString& theValue)
965 _errorCode = "Invalid arguments";
968 SALOMEDSImpl_AttributeComment::Set(theSO->GetLabel(), theValue);
975 //============================================================================
976 /*! Function : SetIOR
979 //============================================================================
980 bool SALOMEDSImpl_StudyBuilder::SetIOR(const Handle(SALOMEDSImpl_SObject)& theSO,
981 const TCollection_AsciiString& theValue)
986 _errorCode = "Invalid arguments";
989 SALOMEDSImpl_AttributeIOR::Set(theSO->GetLabel(), theValue);
997 //============================================================================
998 /*! Function : Translate_persistentID_to_IOR
1001 //============================================================================
1002 static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
1004 if(driver == NULL) return;
1005 TDF_ChildIterator itchild (Lab);
1007 for (; itchild.More(); itchild.Next()) {
1008 TDF_Label current = itchild.Value();
1009 Handle(SALOMEDSImpl_AttributePersistentRef) Att;
1010 if (current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) {
1012 Handle(SALOMEDSImpl_AttributeLocalID) anID;
1013 if (current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(), anID))
1014 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
1016 TCollection_AsciiString persist_ref(Att->Value());
1017 Handle(SALOMEDSImpl_SObject) so = SALOMEDSImpl_Study::SObject(current);
1018 TCollection_AsciiString ior_string = driver->LocalPersistentIDToIOR(so,
1022 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
1025 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);