1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_StudyBuilder.cxx
21 // Author : Sergey RUIN
26 #include "SALOMEDSImpl_Attributes.hxx"
30 #include "SALOMEDSImpl_Study.hxx"
31 #include "SALOMEDSImpl_StudyBuilder.hxx"
32 #include "SALOMEDSImpl_SObject.hxx"
33 #include "SALOMEDSImpl_SComponent.hxx"
34 #include "SALOMEDSImpl_Tool.hxx"
36 #include <SALOMEDSImpl_ChildNodeIterator.hxx>
38 #include <TDF_ChildIterator.hxx>
39 #include <TDF_Label.hxx>
40 #include <TDF_Tool.hxx>
41 #include <TDF_Data.hxx>
42 #include <TDF_ListIteratorOfAttributeList.hxx>
44 #include <OSD_Path.hxx>
49 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_StudyBuilder, MMgt_TShared )
50 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_StudyBuilder, MMgt_TShared )
52 #define USE_CASE_LABEL_TAG 2
53 #define DIRECTORYID 16661
54 #define FILELOCALID 26662
56 static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII);
58 //============================================================================
59 /*! Function : constructor
62 //============================================================================
63 SALOMEDSImpl_StudyBuilder::SALOMEDSImpl_StudyBuilder(const Handle(Standard_Transient)& theOwner)
67 _doc = Handle(SALOMEDSImpl_Study)::DownCast(theOwner)->GetDocument();
70 //============================================================================
71 /*! Function : destructor
74 //============================================================================
75 SALOMEDSImpl_StudyBuilder::~SALOMEDSImpl_StudyBuilder()
78 //============================================================================
79 /*! Function : NewComponent
80 * Purpose : Create a new component (Scomponent)
82 //============================================================================
83 Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_StudyBuilder::NewComponent(const TCollection_AsciiString& DataType)
88 if(DataType.Length() == 0) return 0;
90 //Always create component under main label.
91 TDF_Label L = _doc->Main();
94 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
95 if (it.Value().Tag() > imax)
96 imax = it.Value().Tag();
99 TDF_Label NL = L.FindChild(imax);
101 SALOMEDSImpl_AttributeComment::Set(NL, DataType);
103 Handle(SALOMEDSImpl_SComponent) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSComponent (NL);
105 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
112 //============================================================================
113 /*! Function : DefineComponentInstance
114 * Purpose : Add IOR attribute of a Scomponent
116 //============================================================================
117 bool SALOMEDSImpl_StudyBuilder::DefineComponentInstance(const Handle(SALOMEDSImpl_SComponent)& aComponent,
118 const TCollection_AsciiString& IOR)
123 if(aComponent.IsNull() || IOR.IsEmpty()) {
124 _errorCode = "Invalid arguments";
128 SALOMEDSImpl_AttributeIOR::Set(aComponent->GetLabel(), IOR);
135 //============================================================================
136 /*! Function : RemoveComponent
137 * Purpose : Delete a Scomponent
139 //============================================================================
140 bool SALOMEDSImpl_StudyBuilder::RemoveComponent(const Handle(SALOMEDSImpl_SComponent)& aComponent)
144 return RemoveObject(aComponent);
147 //============================================================================
148 /*! Function : NewObject
149 * Purpose : Create a new SObject
151 //============================================================================
152 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObject(const Handle(SALOMEDSImpl_SObject)& theFatherObject)
157 //Find label of father
158 TDF_Label Lab = theFatherObject->GetLabel();
162 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
163 if (it.Value().Tag() > imax)
164 imax = it.Value().Tag();
167 TDF_Label NewLab = Lab.FindChild(imax);
169 Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab);
170 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
176 //============================================================================
177 /*! Function : NewObjectToTag
180 //============================================================================
181 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_StudyBuilder::NewObjectToTag(const Handle(SALOMEDSImpl_SObject)& theFatherObject,
186 //Find label of father
187 TDF_Label Lab = theFatherObject->GetLabel();
189 //Create or find label
190 TDF_Label NewLab = Lab.FindChild(theTag, 1);
192 Handle(SALOMEDSImpl_SObject) so = Handle(SALOMEDSImpl_Study)::DownCast(_study)->GetSObject(NewLab);
194 if(!_callbackOnAdd.IsNull()) _callbackOnAdd->OnAddSObject(so);
200 //============================================================================
201 /*! Function : RemoveObject
204 //============================================================================
205 bool SALOMEDSImpl_StudyBuilder::RemoveObject(const Handle(SALOMEDSImpl_SObject)& anObject)
209 if(anObject.IsNull()) {
210 _errorCode = "Null object";
214 if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject);
216 TDF_Label Lab = anObject->GetLabel();
218 Handle(SALOMEDSImpl_AttributeReference) aReference;
219 if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
220 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
221 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
222 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
225 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
226 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
227 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
229 Lab.ForgetAllAttributes();
236 //============================================================================
237 /*! Function : RemoveObjectWithChildren
240 //============================================================================
241 bool SALOMEDSImpl_StudyBuilder::RemoveObjectWithChildren(const Handle(SALOMEDSImpl_SObject)& anObject)
245 if(anObject.IsNull()) {
246 _errorCode = "Null object";
250 if(!_callbackOnRemove.IsNull()) _callbackOnRemove->OnRemoveSObject(anObject);
252 TDF_Label Lab = anObject->GetLabel();
254 Handle(SALOMEDSImpl_AttributeReference) aReference;
255 if (Lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
256 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
257 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
258 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
260 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
261 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
262 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
264 TDF_ChildIterator it(Lab, Standard_True);
265 for(;it.More();it.Next()) {
266 TDF_Label aLabel = it.Value();
267 if (aLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(), aReference)) {
268 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
269 if (aReference->Get().FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(),aTarget))
270 aTarget->Remove(SALOMEDSImpl_Study::SObject(aLabel));
272 Handle(SALOMEDSImpl_AttributeIOR) anAttr; // postponed removing of CORBA objects
273 if (aLabel.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
274 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(TCollection_AsciiString(anAttr->Value()).ToCString());
277 Lab.ForgetAllAttributes(Standard_True);
284 //============================================================================
285 /*! Function : LoadWith
288 //============================================================================
289 bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)& anSCO,
290 SALOMEDSImpl_Driver* aDriver)
294 TDF_Label Lab = anSCO->GetLabel();
295 Handle(SALOMEDSImpl_AttributePersistentRef) Att;
297 //Find the current Url of the study
298 if (_doc->Main().FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) {
299 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
300 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
302 TCollection_ExtendedString Res(Att->Value());
303 TCollection_AsciiString aHDFPath(Res);
305 Handle(SALOMEDSImpl_AttributeComment) type;
306 TCollection_ExtendedString DataType;
307 if (Lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(),type))
308 DataType = type->Value();
310 // associate the driver to the SComponent
311 if(aDriver == NULL) {
312 _errorCode = "Driver is null";
316 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
317 Handle(SALOMEDSImpl_AttributeIOR) attrIOR;
318 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), attrIOR)) {
319 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
323 DefineComponentInstance (anSCO, aDriver->GetIOR());
325 TCollection_AsciiString aHDFUrl;
326 bool isASCII = false;
327 if (HDFascii::isASCII(aHDFPath.ToCString())) {
329 aHDFUrl = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString());
330 aHDFUrl += "hdf_from_ascii.hdf";
335 //Open the Study HDF file
336 HDFfile *hdf_file = new HDFfile(aHDFUrl.ToCString());
338 char aMultifileState[2] = "S"; // default: single
339 char ASCIIfileState[2] = "B"; // default: binary
341 TCollection_AsciiString scoid = anSCO->GetID();
342 hdf_file->OpenOnDisk(HDF_RDONLY);
343 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
344 hdf_group->OpenOnDisk();
345 HDFgroup *hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group);
346 hdf_sco_group->OpenOnDisk();
348 unsigned char* aStreamFile = NULL;
351 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
352 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
353 hdf_dataset->OpenOnDisk();
354 aStreamSize = hdf_dataset->GetSize();
355 aStreamFile = new unsigned char[aStreamSize];
356 if(aStreamFile == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
357 hdf_dataset->ReadFromDisk(aStreamFile);
358 hdf_dataset->CloseOnDisk();
364 if (hdf_sco_group->ExistInternalObject("MULTIFILE_STATE")) {
365 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
366 multifile_hdf_dataset->OpenOnDisk();
367 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
369 multifile_hdf_dataset->CloseOnDisk();
370 multifile_hdf_dataset = 0;
373 if (hdf_sco_group->ExistInternalObject("ASCII_STATE")) {
374 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
375 ascii_hdf_dataset->OpenOnDisk();
376 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
378 ascii_hdf_dataset->CloseOnDisk();
379 ascii_hdf_dataset = 0;
382 // set path without file name from URL
383 //int aFileNameSize = Res.Length();
384 //char* aDir = new char[aFileNameSize];
385 //memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
386 //for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
387 //if (aDir[aCounter] == '/') {
388 // aDir[aCounter+1] = 0;
391 // Above code was working wrong for paths without '/' inside.
392 TCollection_AsciiString aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
394 bool aResult = (ASCIIfileState[0]=='A')?
395 aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.ToCString(), aMultifileState[0]=='M'):
396 aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.ToCString(), aMultifileState[0]=='M');
398 if(aStreamFile != NULL) delete []aStreamFile;
401 RemoveAttribute( anSCO, "AttributeIOR" );
403 _errorCode = "Can't load component";
404 throw HDFexception("Unable to load component");
407 //if(aDir != NULL) delete []aDir;
409 hdf_sco_group->CloseOnDisk();
411 hdf_group->CloseOnDisk();
413 hdf_file->CloseOnDisk();
417 Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
418 aFilesToRemove->Append("hdf_from_ascii.hdf");
419 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
420 aFilesToRemove, true);
423 catch (HDFexception) {
427 Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
428 aFilesToRemove->Append(aHDFUrl);
429 SALOMEDSImpl_Tool::RemoveTemporaryFiles(SALOMEDSImpl_Tool::GetDirFromPath(aHDFUrl),
430 aFilesToRemove, true);
433 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
434 _errorCode = "No persistent file";
439 Translate_persistentID_to_IOR (Lab, aDriver, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
441 _errorCode = "Can not convert persistent IDs to IORs";
445 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
447 _errorCode = "No persistent file";
454 //============================================================================
458 //============================================================================
459 bool SALOMEDSImpl_StudyBuilder::Load(const Handle(SALOMEDSImpl_SObject)& sco)
461 _errorCode = "Not implemented";
465 //============================================================================
466 /*! Function : FindOrCreateAttribute
467 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
470 //============================================================================
471 Handle(TDF_Attribute) SALOMEDSImpl_StudyBuilder::FindOrCreateAttribute(const Handle(SALOMEDSImpl_SObject)& anObject,
472 const TCollection_AsciiString& aTypeOfAttribute)
475 if(anObject.IsNull()) {
476 _errorCode = "Invalid arguments";
480 TDF_Label Lab = anObject->GetLabel();
482 _errorCode = "Null label";
488 //The macro adds all necessary checks for standardly behaiving attributes
489 __FindOrCreateAttributeForBuilder
492 //Add checks for TreeNode and UserID attributes
493 if (strncmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode",17) == 0 ) {
495 Standard_GUID aTreeNodeGUID;
496 if (strcmp(aTypeOfAttribute.ToCString(), "AttributeTreeNode") == 0) {
497 aTreeNodeGUID = SALOMEDSImpl_AttributeTreeNode::GetDefaultTreeID();
499 char* aGUIDString = new char[41];
500 char* aType = (char*)aTypeOfAttribute.ToCString();
501 sprintf(aGUIDString, &(aType[17]));
502 if(!Standard_GUID::CheckGUIDFormat(aGUIDString)) {
506 aTreeNodeGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
509 Handle(SALOMEDSImpl_AttributeTreeNode) anAttr;
510 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr)) {
512 anAttr = SALOMEDSImpl_AttributeTreeNode::Set(Lab, aTreeNodeGUID);
517 if (strncmp(aTypeOfAttribute.ToCString(), "AttributeUserID",15) == 0 ) {
518 Standard_GUID aUserGUID;
519 if (strcmp(aTypeOfAttribute.ToCString(), "AttributeUserID") == 0) {
520 aUserGUID = SALOMEDSImpl_AttributeUserID::DefaultID();
522 char* aGUIDString = new char[41];
523 char* aType = (char*)aTypeOfAttribute.ToCString();
524 sprintf(aGUIDString, &(aType[15]));
525 if(!Standard_GUID::CheckGUIDFormat(aGUIDString)) {
529 aUserGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
532 Handle(SALOMEDSImpl_AttributeUserID) anAttr;
533 if (!Lab.FindAttribute(SALOMEDSImpl_AttributeUserID::DefaultID(), anAttr)) {
535 anAttr = SALOMEDSImpl_AttributeUserID::Set(Lab, aUserGUID);
539 _errorCode = "Can not create an attribute";
544 //============================================================================
545 /*! Function : FindAttribute
546 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
548 //============================================================================
550 bool SALOMEDSImpl_StudyBuilder::FindAttribute(const Handle(SALOMEDSImpl_SObject)& anObject,
551 Handle(TDF_Attribute)& anAttribute,
552 const TCollection_AsciiString& aTypeOfAttribute)
555 if(anObject.IsNull()) {
556 _errorCode = "Invalid arguments";
559 TDF_Label Lab = anObject->GetLabel();
560 if (Lab.FindAttribute(SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute), anAttribute)) {
561 // commented out because NO MODIFICATION is done to attributes when calling FindAttribute()
563 return Standard_True;
565 return Standard_False;
568 //============================================================================
569 /*! Function : RemoveAttribute
570 * Purpose : Remove attribute of given type assigned SObject
572 //============================================================================
574 bool SALOMEDSImpl_StudyBuilder::RemoveAttribute(const Handle(SALOMEDSImpl_SObject)& anObject,
575 const TCollection_AsciiString& aTypeOfAttribute)
579 if(anObject.IsNull()) {
580 _errorCode = "Invalid arguments";
583 TDF_Label Lab = anObject->GetLabel();
585 if (aTypeOfAttribute == "AttributeIOR") { // postponed removing of CORBA objects
586 Handle(SALOMEDSImpl_AttributeIOR) anAttr;
587 if (Lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anAttr))
588 SALOMEDSImpl_Study::GetStudy(_doc->Main())->AddPostponed(anAttr->Value());
591 Lab.ForgetAttribute (SALOMEDSImpl_SObject::GetGUID(aTypeOfAttribute));
598 //============================================================================
599 /*! Function : Addreference
602 //============================================================================
603 bool SALOMEDSImpl_StudyBuilder::Addreference(const Handle(SALOMEDSImpl_SObject)& me,
604 const Handle(SALOMEDSImpl_SObject)& theReferencedObject)
607 if(me.IsNull() || theReferencedObject.IsNull()) {
608 _errorCode = "Invalid arguments";
612 TDF_Label Lab = me->GetLabel();
613 TDF_Label RefLab = theReferencedObject->GetLabel();
614 SALOMEDSImpl_AttributeReference::Set(Lab,RefLab);
616 SALOMEDSImpl_AttributeTarget::Set(RefLab)->Add(SALOMEDSImpl_Study::SObject(Lab));
618 if(!_callbackOnRemove.IsNull() && Lab.IsDescendant(_doc->Main())) _callbackOnRemove->OnRemoveSObject(me);
623 //============================================================================
624 /*! Function : RemoveReference
627 //============================================================================
628 bool SALOMEDSImpl_StudyBuilder::RemoveReference(const Handle(SALOMEDSImpl_SObject)& me)
631 Handle(SALOMEDSImpl_SObject) theReferencedObject;
632 if(!me->ReferencedObject(theReferencedObject)) return false; //No reference is found
635 TDF_Label Lab = me->GetLabel();
637 Lab.ForgetAttribute(SALOMEDSImpl_AttributeReference::GetID());
639 //SRN: 30 Aug, 2004 : fix from Ecole l'ete version
641 TDF_Label RefLab = theReferencedObject->GetLabel();
643 Handle(SALOMEDSImpl_AttributeTarget) aTarget;
644 if(RefLab.FindAttribute(SALOMEDSImpl_AttributeTarget::GetID(), aTarget))
645 aTarget->Remove(SALOMEDSImpl_Study::SObject(Lab));
654 //============================================================================
655 /*! Function : AddDirectory
656 * Purpose : adds a new directory with a path = thePath
658 //============================================================================
659 bool SALOMEDSImpl_StudyBuilder::AddDirectory(const TCollection_AsciiString& thePath)
663 if(thePath.IsEmpty() || thePath == "") {
664 _errorCode = "Invalid path";
668 TCollection_AsciiString aPath(thePath), aContext(""), aFatherPath;
670 Handle(SALOMEDSImpl_Study) aStudy = SALOMEDSImpl_Study::GetStudy(_doc->Main());
671 Handle(SALOMEDSImpl_SObject) anObject;
674 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
678 if(!anObject.IsNull()) {
679 _errorCode = "StudyNameAlreadyUsed";
683 if(aPath.Value(1) != '/') { //Relative path
685 aPath = aStudy->GetContext() + aPath;
688 TCollection_AsciiString aToken = aPath.Token("/", 1);
689 if(aToken.Length() == 0) aFatherPath = "/";
692 while(aToken.Length() != 0) {
693 if(aPath.Token("/", i+1).Length() > 0) {
695 aFatherPath += aToken;
697 aToken = aPath.Token("/", ++i);
702 anObject = aStudy->FindObjectByPath(aFatherPath); //Check if the father directory exists
705 if(anObject.IsNull()) {
706 _errorCode = "StudyInvalidDirectory";
710 Handle(SALOMEDSImpl_SObject) aNewObject = NewObject(anObject);
711 aLabel = aNewObject->GetLabel();
712 if(aLabel.IsNull()) {
713 _errorCode = "StudyInvalidComponent";
717 SALOMEDSImpl_AttributeName::Set(aLabel, aPath.Token("/", i-1));
719 //Set LocalID attribute to identify the directory object
720 Handle(SALOMEDSImpl_AttributeLocalID) aLocalID = SALOMEDSImpl_AttributeLocalID::Set(aLabel, DIRECTORYID);
728 //============================================================================
729 /*! Function : SetGUID
732 //============================================================================
733 bool SALOMEDSImpl_StudyBuilder::SetGUID(const Handle(SALOMEDSImpl_SObject)& anObject,
734 const TCollection_AsciiString& theGUID)
738 if(anObject.IsNull()) {
739 _errorCode = "Invalid arguments";
743 TDF_Label aLabel = anObject->GetLabel();
744 SALOMEDSImpl_AttributeUserID::Set(aLabel, theGUID.ToCString());
751 //============================================================================
752 /*! Function : IsGUID
755 //============================================================================
756 bool SALOMEDSImpl_StudyBuilder::IsGUID(const Handle(SALOMEDSImpl_SObject)& anObject,
757 const TCollection_AsciiString& theGUID)
760 if(anObject.IsNull()) {
761 _errorCode = "Invalid arguments";
764 TDF_Label aLabel = anObject->GetLabel();
765 return aLabel.IsAttribute(theGUID.ToCString());
769 //============================================================================
770 /*! Function : NewCommand
773 //============================================================================
774 void SALOMEDSImpl_StudyBuilder::NewCommand()
777 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
778 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
779 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
780 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
781 _doc->Main().AddAttribute(anAttr);
783 anAttr->IsLockChanged(true);
788 //============================================================================
789 /*! Function : CommitCommand
792 //============================================================================
793 void SALOMEDSImpl_StudyBuilder::CommitCommand()
796 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
797 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
798 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
799 _doc->Main().AddAttribute(anAttr);
801 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
803 _errorCode = "LockProtection";
804 throw LockProtection("LockProtection");
806 SALOMEDSImpl_Study::GetStudy(_doc->Main())->RemovePostponed(_doc->GetUndoLimit());
808 int aModif = anAttr->GetModified();
809 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
810 anAttr->SetModified(aModif+1);
811 _doc->CommitCommand();
817 //============================================================================
818 /*! Function : HasOpenCommand
821 //============================================================================
822 bool SALOMEDSImpl_StudyBuilder::HasOpenCommand()
825 return _doc->HasOpenCommand();
828 //============================================================================
829 /*! Function : AbortCommand
832 //============================================================================
833 void SALOMEDSImpl_StudyBuilder::AbortCommand()
836 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(0);
838 _doc->AbortCommand();
841 //============================================================================
845 //============================================================================
846 void SALOMEDSImpl_StudyBuilder::Undo()
849 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
850 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
851 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
852 _doc->Main().AddAttribute(anAttr);
854 if (anAttr->IsLocked()) {
855 _errorCode = "LockProtection";
856 throw LockProtection("LockProtection");
858 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(1);
860 anAttr->SetModified(anAttr->GetModified()-1);
866 //============================================================================
870 //============================================================================
871 void SALOMEDSImpl_StudyBuilder::Redo()
874 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
875 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
876 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
877 _doc->Main().AddAttribute(anAttr);
880 if (anAttr->IsLocked()) {
881 _errorCode = "LockProtection";
882 throw LockProtection("LockProtection");
885 SALOMEDSImpl_Study::GetStudy(_doc->Main())->UndoPostponed(-1);
886 anAttr->SetModified(anAttr->GetModified()+1);
892 //============================================================================
893 /*! Function : GetAvailableUndos
896 //============================================================================
897 bool SALOMEDSImpl_StudyBuilder::GetAvailableUndos()
900 return _doc->GetAvailableUndos();
903 //============================================================================
904 /*! Function : GetAvailableRedos
907 //============================================================================
908 bool SALOMEDSImpl_StudyBuilder::GetAvailableRedos()
911 return _doc->GetAvailableRedos();
914 //============================================================================
915 /*! Function : UndoLimit
918 //============================================================================
919 int SALOMEDSImpl_StudyBuilder::UndoLimit()
922 return _doc->GetUndoLimit();
925 //============================================================================
926 /*! Function : UndoLimit
929 //============================================================================
930 void SALOMEDSImpl_StudyBuilder::UndoLimit(int n)
934 _doc->SetUndoLimit (n);
937 //============================================================================
938 /*! Function : SetOnAddSObject
941 //============================================================================
942 Handle(SALOMEDSImpl_Callback)
943 SALOMEDSImpl_StudyBuilder::SetOnAddSObject(const Handle(SALOMEDSImpl_Callback)& theCallback)
946 Handle(SALOMEDSImpl_Callback) aRet = _callbackOnAdd;
947 _callbackOnAdd = theCallback;
951 //============================================================================
952 /*! Function : SetOnNewSObject
955 //============================================================================
956 Handle(SALOMEDSImpl_Callback)
957 SALOMEDSImpl_StudyBuilder::SetOnRemoveSObject(const Handle(SALOMEDSImpl_Callback)& theCallback)
960 Handle(SALOMEDSImpl_Callback) aRet = _callbackOnRemove;
961 _callbackOnRemove = theCallback;
965 //============================================================================
966 /*! Function : CheckLocked
969 //============================================================================
970 void SALOMEDSImpl_StudyBuilder::CheckLocked()
973 if (_doc->HasOpenCommand()) return;
974 Handle(SALOMEDSImpl_AttributeStudyProperties) anAttr;
975 if (!_doc->Main().FindAttribute(SALOMEDSImpl_AttributeStudyProperties::GetID(), anAttr)) {
976 anAttr = new SALOMEDSImpl_AttributeStudyProperties;
977 _doc->Main().AddAttribute(anAttr);
979 if (anAttr->IsLocked()) {
980 _errorCode = "LockProtection";
981 throw LockProtection("LockProtection");
985 //============================================================================
986 /*! Function : SetName
989 //============================================================================
990 bool SALOMEDSImpl_StudyBuilder::SetName(const Handle(SALOMEDSImpl_SObject)& theSO,
991 const TCollection_AsciiString& theValue)
996 _errorCode = "Invalid arguments";
999 SALOMEDSImpl_AttributeName::Set(theSO->GetLabel(), theValue);
1006 //============================================================================
1007 /*! Function : SetComment
1010 //============================================================================
1011 bool SALOMEDSImpl_StudyBuilder::SetComment(const Handle(SALOMEDSImpl_SObject)& theSO,
1012 const TCollection_AsciiString& theValue)
1016 if(theSO.IsNull()) {
1017 _errorCode = "Invalid arguments";
1020 SALOMEDSImpl_AttributeComment::Set(theSO->GetLabel(), theValue);
1027 //============================================================================
1028 /*! Function : SetIOR
1031 //============================================================================
1032 bool SALOMEDSImpl_StudyBuilder::SetIOR(const Handle(SALOMEDSImpl_SObject)& theSO,
1033 const TCollection_AsciiString& theValue)
1037 if(theSO.IsNull()) {
1038 _errorCode = "Invalid arguments";
1041 SALOMEDSImpl_AttributeIOR::Set(theSO->GetLabel(), theValue);
1049 //============================================================================
1050 /*! Function : Translate_persistentID_to_IOR
1053 //============================================================================
1054 static void Translate_persistentID_to_IOR(TDF_Label& Lab, SALOMEDSImpl_Driver* driver, bool isMultiFile, bool isASCII)
1056 if(driver == NULL) return;
1057 TDF_ChildIterator itchild (Lab);
1059 for (; itchild.More(); itchild.Next()) {
1060 TDF_Label current = itchild.Value();
1061 Handle(SALOMEDSImpl_AttributePersistentRef) Att;
1062 if (current.FindAttribute(SALOMEDSImpl_AttributePersistentRef::GetID(),Att)) {
1064 Handle(SALOMEDSImpl_AttributeLocalID) anID;
1065 if (current.FindAttribute(SALOMEDSImpl_AttributeLocalID::GetID(), anID))
1066 if (anID->Value() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
1068 TCollection_AsciiString persist_ref(Att->Value());
1069 Handle(SALOMEDSImpl_SObject) so = SALOMEDSImpl_Study::SObject(current);
1070 TCollection_AsciiString ior_string = driver->LocalPersistentIDToIOR(so,
1074 SALOMEDSImpl_AttributeIOR::Set (current, ior_string);
1077 Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII);