2 // File : SALOMEDS_StudyBuilder_i.cxx
3 // Created : Wed Nov 28 16:26:28 2001
4 // Author : Yves FRICAUD
8 // Copyright : Open CASCADE 2001
11 #include "utilities.h"
12 #include "SALOMEDS_StudyBuilder_i.hxx"
13 #include "SALOMEDS_SObject_i.hxx"
14 #include "SALOMEDS_SComponent_i.hxx"
16 #include "SALOMEDS_IORAttribute.hxx"
17 #include "SALOMEDS_PersRefAttribute.hxx"
18 #include "SALOMEDS_TargetAttribute.hxx"
19 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
20 #include "SALOMEDS_PythonObjectAttribute.hxx"
21 #include <TDF_ChildIterator.hxx>
22 #include <TDF_Label.hxx>
23 #include <TDataStd_Name.hxx>
24 #include <TDataStd_Comment.hxx>
25 #include <TDataStd_UAttribute.hxx>
26 #include <TDF_Tool.hxx>
27 #include <TDF_Reference.hxx>
28 #include <TDF_Data.hxx>
29 #include <TDataStd_ChildNodeIterator.hxx>
30 #include <TDF_ListIteratorOfAttributeList.hxx>
31 #include "SALOMEDS_AttributePersistentRef_i.hxx"
32 #include "SALOMEDS_AttributeIOR_i.hxx"
33 #include "SALOMEDS_AttributeComment_i.hxx"
34 #include "SALOMEDS_AttributeName_i.hxx"
35 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
36 #include "SALOMEDS_AttributeSequenceOfReal_i.hxx"
37 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
38 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
39 #include "SALOMEDS_AttributeTableOfString_i.hxx"
40 #include "SALOMEDS_AttributeInteger_i.hxx"
41 #include "SALOMEDS_AttributeReal_i.hxx"
42 #include "SALOMEDS_AttributeDrawable_i.hxx"
43 #include "SALOMEDS_AttributeSelectable_i.hxx"
44 #include "SALOMEDS_AttributeExpandable_i.hxx"
45 #include "SALOMEDS_AttributeOpened_i.hxx"
46 #include "SALOMEDS_AttributeTextColor_i.hxx"
47 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
48 #include "SALOMEDS_AttributePixMap_i.hxx"
49 #include "SALOMEDS_AttributeTreeNode_i.hxx"
50 #include "SALOMEDS_AttributeTarget_i.hxx"
51 #include "SALOMEDS_AttributeLocalID_i.hxx"
52 #include "SALOMEDS_AttributeUserID_i.hxx"
53 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
54 #include "SALOMEDS_AttributePythonObject_i.hxx"
55 #include "Utils_CorbaException.hxx"
60 #define USE_CASE_LABEL_TAG 2
61 #define DIRECTORYID "DIRECTORY:"
63 //============================================================================
64 /*! Function : constructor
67 //============================================================================
68 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) doc,
69 CORBA::ORB_ptr orb) : _doc(doc)
71 _orb = CORBA::ORB::_duplicate(orb);
74 //============================================================================
75 /*! Function : destructor
78 //============================================================================
79 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
83 //============================================================================
84 /*! Function : NewComponent
85 * Purpose : Create a new component (Scomponent)
87 //============================================================================
88 SALOMEDS::SComponent_ptr
89 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
91 //Always create component under main label.
92 TDF_Label L = _doc->Main();
94 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
96 Standard_Integer imax = 0;
97 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
98 if (it.Value().Tag() > imax)
99 imax = it.Value().Tag();
102 TDF_Label NL = L.FindChild(imax);
104 // TDataStd_Comment::Set(NL,Standard_CString(DataType));
105 TDataStd_Comment::Set(NL,Standard_CString(strdup(DataType)));
107 SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (NL,_orb);
108 SALOMEDS::SComponent_var so;
109 so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this());
111 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
116 //============================================================================
117 /*! Function : DefineComponentInstance
118 * Purpose : Add IOR attribute of a Scomponent
120 //============================================================================
121 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
122 CORBA::Object_ptr IOR)
126 ASSERT(!CORBA::is_nil(aComponent));
127 CORBA::String_var compid = aComponent->GetID();
128 TDF_Tool::Label(_doc->GetData(),strdup(compid),Lab);
131 ASSERT(!CORBA::is_nil(IOR));
132 CORBA::String_var iorstr = _orb->object_to_string(IOR);
133 SALOMEDS_IORAttribute::Set(Lab,strdup(iorstr),_orb);
137 //============================================================================
138 /*! Function : RemoveComponent
139 * Purpose : Delete a Scomponent
141 //============================================================================
143 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
145 ASSERT(!CORBA::is_nil(aComponent));
146 RemoveObject(aComponent);
149 //============================================================================
150 /*! Function : NewObject
151 * Purpose : Create a new SObject
153 //============================================================================
154 SALOMEDS::SObject_ptr
155 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
157 TCollection_AsciiString anEntry;
159 //Find label of father
162 ASSERT(!CORBA::is_nil(theFatherObject));
163 CORBA::String_var fatherid = theFatherObject->GetID();
164 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
167 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
168 Standard_Integer imax = 0;
169 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
170 if (it.Value().Tag() > imax)
171 imax = it.Value().Tag();
174 TDF_Label NewLab = Lab.FindChild(imax);
176 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
177 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
179 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
184 //============================================================================
185 /*! Function : NewObjectToTag
188 //============================================================================
189 SALOMEDS::SObject_ptr
190 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
193 //Find label of father
196 ASSERT(!CORBA::is_nil(theFatherObject));
197 CORBA::String_var fatherid = theFatherObject->GetID();
198 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
199 //Create or find label
200 TDF_Label NewLab = Lab.FindChild(atag,1);
202 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
203 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
205 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
210 //============================================================================
211 /*! Function : RemoveObject
214 //============================================================================
215 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
217 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
220 ASSERT(!CORBA::is_nil(anObject));
221 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
222 Lab.ForgetAllAttributes();
225 //============================================================================
226 /*! Function : RemoveObjectWithChildren
229 //============================================================================
230 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
232 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
235 ASSERT(!CORBA::is_nil(anObject));
236 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
237 Lab.ForgetAllAttributes(Standard_True);
240 //============================================================================
241 /*! Function : Translate_persistentID_to_IOR
244 //============================================================================
245 static void Translate_persistentID_to_IOR(TDF_Label Lab,
246 SALOMEDS::Driver_ptr driver,
248 CORBA::Boolean isMultiFile)
250 TDF_ChildIterator itchild (Lab);
252 for (; itchild.More(); itchild.Next()) {
253 TDF_Label current = itchild.Value();
254 Handle(TDF_Attribute) Att;
255 if (current.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
256 TCollection_ExtendedString res;
257 res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
258 TCollection_AsciiString ch(res);
260 CORBA::String_var persistent_string = CORBA::string_dup(ch.ToCString());
261 ASSERT(! CORBA::is_nil(driver));
262 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (current,orb);
263 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
265 CORBA::String_var ior_string = driver->LocalPersistentIDToIOR(so, persistent_string, isMultiFile);
267 TCollection_ExtendedString value(strdup(ior_string ));
268 SALOMEDS_IORAttribute::Set (current,value,orb);
270 TCollection_AsciiString anEntry;TDF_Tool::Entry (current,anEntry);
272 //delete persistent_string;
275 Translate_persistentID_to_IOR (current,driver,orb,isMultiFile);
279 //============================================================================
280 /*! Function : LoadWith
283 //============================================================================
285 //============================================================================
286 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
287 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
290 ASSERT(!CORBA::is_nil(anSCO));
291 CORBA::String_var scoid = anSCO->GetID();
292 TDF_Tool::Label(_doc->GetData(),strdup(scoid),Lab);
293 Handle(TDF_Attribute) Att;
295 //Find the current Url of the study
296 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
297 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
298 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
300 TCollection_ExtendedString Res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
302 Handle(TDataStd_Comment) type;
303 TCollection_ExtendedString DataType;
304 if (Lab.FindAttribute(TDataStd_Comment::GetID(),type))
305 DataType = type->Get();
307 MESSAGE("No Data Type");
309 // associate the driver to the SComponent
310 ASSERT(!CORBA::is_nil(aDriver));
311 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
312 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
313 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
316 DefineComponentInstance (anSCO, aDriver);
318 //Open the Study HDF file
319 TCollection_AsciiString aHDFPath(Res);
320 HDFfile *hdf_file = new HDFfile(aHDFPath.ToCString());
322 char aMultifileState[2];
324 CORBA::String_var scoid = anSCO->GetID();
325 hdf_file->OpenOnDisk(HDF_RDONLY);
326 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
327 hdf_group->OpenOnDisk();
328 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
329 hdf_sco_group->OpenOnDisk();
331 SALOMEDS::TMPFile_var aStreamFile;
332 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
333 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
334 hdf_dataset->OpenOnDisk();
335 int aStreamSize = hdf_dataset->GetSize();
336 unsigned char* aBuffer = new unsigned char[aStreamSize];
337 if(aBuffer == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
338 hdf_dataset->ReadFromDisk(aBuffer);
339 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
340 hdf_dataset->CloseOnDisk();
342 } else aStreamFile = new SALOMEDS::TMPFile(0);
344 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
345 multifile_hdf_dataset->OpenOnDisk();
346 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
349 // set path without file name from URL
350 int aFileNameSize = Res.Length();
351 char* aDir = new char[aFileNameSize];
352 memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
353 for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
354 if (aDir[aCounter] == '/') {
355 aDir[aCounter+1] = 0;
359 if(!aDriver->Load(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M')) {
360 MESSAGE("Can't load component");
361 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
362 // throw HDFexception("Unable to load component");
367 multifile_hdf_dataset->CloseOnDisk();
368 multifile_hdf_dataset = 0;
369 hdf_sco_group->CloseOnDisk();
371 hdf_group->CloseOnDisk();
373 hdf_file->CloseOnDisk();
376 catch (HDFexception) {
377 MESSAGE("No persistent file Name");
379 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
384 Translate_persistentID_to_IOR (Lab,aDriver,_orb, aMultifileState[0]=='M');
385 } catch (SALOME::SALOME_Exception) {
386 MESSAGE("Can't translate PersRef to IOR");
387 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
388 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
389 // throw HDFexception("Unable to load component data");
391 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
393 MESSAGE("No persistent file Name");
397 //============================================================================
401 //============================================================================
402 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
404 MESSAGE ( "This function is not yet implemented");
407 //============================================================================
408 /*! Function : AddAttribute
411 //============================================================================
413 void SALOMEDS_StudyBuilder_i::AddAttribute(SALOMEDS::SObject_ptr anObject,
414 SALOMEDS::AttributeType aType,
415 const char * AttributeValue )
418 ASSERT(!CORBA::is_nil(anObject));
419 CORBA::String_var anobid = anObject->GetID();
420 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
422 TCollection_ExtendedString Value(strdup(AttributeValue));
424 Standard_GUID ID = SALOMEDS_SObject_i::TypeToAttributeID(aType);
426 if (ID == TDataStd_Name::GetID()) TDataStd_Name::Set (Lab,Value);
427 else if (ID == TDataStd_Comment::GetID()) TDataStd_Comment::Set (Lab,Value);
428 else if (ID == SALOMEDS_IORAttribute::GetID()) SALOMEDS_IORAttribute::Set (Lab,Value);
429 else if (ID == SALOMEDS_PersRefAttribute::GetID()) SALOMEDS_PersRefAttribute::Set(Lab,Value);
432 //============================================================================
433 /*! Function : FindOrCreateAttribute
434 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
437 //============================================================================
439 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
440 const char* aTypeOfAttribute)
443 ASSERT(!CORBA::is_nil(anObject));
444 CORBA::String_var anobid = anObject->GetID();
445 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
447 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
448 Handle(TDataStd_Real) anAttr;
449 if (!Lab.FindAttribute(TDataStd_Real::GetID(), anAttr)) {
450 anAttr = new TDataStd_Real;
451 Lab.AddAttribute(anAttr);
453 SALOMEDS_AttributeReal_i* aRealAttr = new SALOMEDS_AttributeReal_i(anAttr, _orb);
454 SALOMEDS::AttributeReal_var aRA = aRealAttr->AttributeReal::_this();
457 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
458 Handle(TDataStd_Integer) anAttr;
459 if (!Lab.FindAttribute(TDataStd_Integer::GetID(), anAttr)) {
460 anAttr = new TDataStd_Integer;
461 Lab.AddAttribute(anAttr);
463 SALOMEDS_AttributeInteger_i* aIntAttr = new SALOMEDS_AttributeInteger_i(anAttr, _orb);
464 SALOMEDS::AttributeInteger_var aIA = aIntAttr->AttributeInteger::_this();
467 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
468 Handle(SALOMEDS_SequenceOfRealAttribute) anAttr;
469 if (!Lab.FindAttribute(SALOMEDS_SequenceOfRealAttribute::GetID(), anAttr)) {
470 anAttr = new SALOMEDS_SequenceOfRealAttribute;
471 Lab.AddAttribute(anAttr);
473 SALOMEDS_AttributeSequenceOfReal_i* aSeqRealAttr = new SALOMEDS_AttributeSequenceOfReal_i(anAttr, _orb);
474 SALOMEDS::AttributeSequenceOfReal_var aSRA = aSeqRealAttr->AttributeSequenceOfReal::_this();
477 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
478 Handle(SALOMEDS_SequenceOfIntegerAttribute) anAttr;
479 if (!Lab.FindAttribute(SALOMEDS_SequenceOfIntegerAttribute::GetID(), anAttr)) {
480 anAttr = new SALOMEDS_SequenceOfIntegerAttribute;
481 Lab.AddAttribute(anAttr);
483 SALOMEDS_AttributeSequenceOfInteger_i* aSeqIntegerAttr = new SALOMEDS_AttributeSequenceOfInteger_i(anAttr, _orb);
484 SALOMEDS::AttributeSequenceOfInteger_var aSIA = aSeqIntegerAttr->AttributeSequenceOfInteger::_this();
487 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
488 Handle(TDataStd_Name) anAttr;
489 if (!Lab.FindAttribute(TDataStd_Name::GetID(), anAttr)) {
490 anAttr = new TDataStd_Name;
491 Lab.AddAttribute(anAttr);
493 SALOMEDS_AttributeName_i* aNameAttr = new SALOMEDS_AttributeName_i(anAttr, _orb);
494 SALOMEDS::AttributeName_var aSNA = aNameAttr->AttributeName::_this();
497 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
498 Handle(TDataStd_Comment) anAttr;
499 if (!Lab.FindAttribute(TDataStd_Comment::GetID(), anAttr)) {
500 anAttr = new TDataStd_Comment;
501 Lab.AddAttribute(anAttr);
503 SALOMEDS_AttributeComment_i* aCommentAttr = new SALOMEDS_AttributeComment_i(anAttr, _orb);
504 SALOMEDS::AttributeComment_var aCA = aCommentAttr->AttributeComment::_this();
507 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
508 Handle(SALOMEDS_IORAttribute) anAttr;
509 if (!Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) {
510 anAttr = new SALOMEDS_IORAttribute;
511 Lab.AddAttribute(anAttr);
513 SALOMEDS_AttributeIOR_i* aIORAttr = new SALOMEDS_AttributeIOR_i(anAttr, _orb);
514 SALOMEDS::AttributeIOR_var aIA = aIORAttr->AttributeIOR::_this();
517 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
518 Handle(SALOMEDS_PersRefAttribute) anAttr;
519 if (!Lab.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), anAttr)) {
520 anAttr = new SALOMEDS_PersRefAttribute;
521 Lab.AddAttribute(anAttr);
523 SALOMEDS_AttributePersistentRef_i* aPerRefAttr = new SALOMEDS_AttributePersistentRef_i(anAttr, _orb);
524 SALOMEDS::AttributePersistentRef_var aPRA = aPerRefAttr->AttributePersistentRef::_this();
527 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
528 Handle(SALOMEDS_DrawableAttribute) anAttr;
529 if (!Lab.FindAttribute(SALOMEDS_DrawableAttribute::GetID(), anAttr)) {
530 anAttr = new SALOMEDS_DrawableAttribute;
531 Lab.AddAttribute(anAttr);
533 SALOMEDS_AttributeDrawable_i* aDrawableAttr = new SALOMEDS_AttributeDrawable_i(anAttr, _orb);
534 SALOMEDS::AttributeDrawable_var aDrawA = aDrawableAttr->AttributeDrawable::_this();
535 return aDrawA._retn();
537 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
538 Handle(SALOMEDS_SelectableAttribute) anAttr;
539 if (!Lab.FindAttribute(SALOMEDS_SelectableAttribute::GetID(), anAttr)) {
540 anAttr = new SALOMEDS_SelectableAttribute;
541 Lab.AddAttribute(anAttr);
543 SALOMEDS_AttributeSelectable_i* aSelectableAttr = new SALOMEDS_AttributeSelectable_i(anAttr, _orb);
544 SALOMEDS::AttributeSelectable_var aSelA = aSelectableAttr->AttributeSelectable::_this();
545 return aSelA._retn();
547 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
548 Handle(SALOMEDS_ExpandableAttribute) anAttr;
549 if (!Lab.FindAttribute(SALOMEDS_ExpandableAttribute::GetID(), anAttr)) {
550 anAttr = new SALOMEDS_ExpandableAttribute;
551 Lab.AddAttribute(anAttr);
553 SALOMEDS_AttributeExpandable_i* aExpandableAttr = new SALOMEDS_AttributeExpandable_i(anAttr, _orb);
554 SALOMEDS::AttributeExpandable_var aExpA = aExpandableAttr->AttributeExpandable::_this();
555 return aExpA._retn();
557 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
558 Handle(SALOMEDS_OpenedAttribute) anAttr;
559 if (!Lab.FindAttribute(SALOMEDS_OpenedAttribute::GetID(), anAttr)) {
560 anAttr = new SALOMEDS_OpenedAttribute;
561 Lab.AddAttribute(anAttr);
563 SALOMEDS_AttributeOpened_i* aOpenedAttr = new SALOMEDS_AttributeOpened_i(anAttr, _orb);
564 SALOMEDS::AttributeOpened_var aOpenA = aOpenedAttr->AttributeOpened::_this();
565 return aOpenA._retn();
567 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
568 Handle(SALOMEDS_TextColorAttribute) anAttr;
569 if (!Lab.FindAttribute(SALOMEDS_TextColorAttribute::GetID(), anAttr)) {
570 anAttr = new SALOMEDS_TextColorAttribute;
571 Lab.AddAttribute(anAttr);
573 SALOMEDS_AttributeTextColor_i* aTextColorAttr = new SALOMEDS_AttributeTextColor_i(anAttr, _orb);
574 SALOMEDS::AttributeTextColor_var aTCA = aTextColorAttr->AttributeTextColor::_this();
577 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
578 Handle(SALOMEDS_TextHighlightColorAttribute) anAttr;
579 if (!Lab.FindAttribute(SALOMEDS_TextHighlightColorAttribute::GetID(), anAttr)) {
580 anAttr = new SALOMEDS_TextHighlightColorAttribute;
581 Lab.AddAttribute(anAttr);
583 SALOMEDS_AttributeTextHighlightColor_i* aTextHighlightColorAttr = new SALOMEDS_AttributeTextHighlightColor_i(anAttr, _orb);
584 SALOMEDS::AttributeTextHighlightColor_var aTHCA = aTextHighlightColorAttr->AttributeTextHighlightColor::_this();
585 return aTHCA._retn();
587 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
588 Handle(SALOMEDS_PixMapAttribute) anAttr;
589 if (!Lab.FindAttribute(SALOMEDS_PixMapAttribute::GetID(), anAttr)) {
590 anAttr = new SALOMEDS_PixMapAttribute;
591 Lab.AddAttribute(anAttr);
593 SALOMEDS_AttributePixMap_i* aPixMapAttr = new SALOMEDS_AttributePixMap_i(anAttr, _orb);
594 SALOMEDS::AttributePixMap_var aPMA = aPixMapAttr->AttributePixMap::_this();
597 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
598 Standard_GUID aTreeNodeGUID;
599 if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0)
600 aTreeNodeGUID = TDataStd_TreeNode::GetDefaultTreeID();
602 char* aGUIDString = new char[40];
603 sprintf(aGUIDString, &(aTypeOfAttribute[21]));
604 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
607 Handle(TDataStd_TreeNode) anAttr;
608 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr))
609 anAttr = TDataStd_TreeNode::Set(Lab, aTreeNodeGUID);
610 SALOMEDS_AttributeTreeNode_i* aTreeNodeAttr = new SALOMEDS_AttributeTreeNode_i(anAttr, _orb);
611 SALOMEDS::AttributeTreeNode_var aTNA = aTreeNodeAttr->AttributeTreeNode::_this();
614 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
615 Handle(TDataStd_UAttribute) anAttr;
616 if (!Lab.FindAttribute(SALOMEDS_AttributeUserID_i::DefaultID(), anAttr))
617 anAttr = TDataStd_UAttribute::Set(Lab, SALOMEDS_AttributeUserID_i::DefaultID());
618 SALOMEDS_AttributeUserID_i* aUAttr = new SALOMEDS_AttributeUserID_i(anAttr, _orb);
619 SALOMEDS::AttributeUserID_var aUA = aUAttr->AttributeUserID::_this();
622 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
623 Handle(SALOMEDS_LocalIDAttribute) anAttr;
624 if (!Lab.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttr)) {
625 anAttr = new SALOMEDS_LocalIDAttribute;
626 Lab.AddAttribute(anAttr);
628 SALOMEDS_AttributeLocalID_i* aLIDAttr = new SALOMEDS_AttributeLocalID_i(anAttr, _orb);
629 SALOMEDS::AttributeLocalID_var aLIDA = aLIDAttr->AttributeLocalID::_this();
630 return aLIDA._retn();
632 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
633 Handle(SALOMEDS_TargetAttribute) anAttr;
634 if (!Lab.FindAttribute(SALOMEDS_TargetAttribute::GetID(), anAttr)) {
635 anAttr = new SALOMEDS_TargetAttribute;
636 Lab.AddAttribute(anAttr);
638 SALOMEDS_AttributeTarget_i* aLIDAttr = new SALOMEDS_AttributeTarget_i(anAttr, _orb);
639 SALOMEDS::AttributeTarget_var aLIDA = aLIDAttr->AttributeTarget::_this();
640 return aLIDA._retn();
642 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
643 Handle(SALOMEDS_TableOfIntegerAttribute) anAttr;
644 if (!Lab.FindAttribute(SALOMEDS_TableOfIntegerAttribute::GetID(), anAttr)) {
645 anAttr = new SALOMEDS_TableOfIntegerAttribute;
646 Lab.AddAttribute(anAttr);
648 SALOMEDS_AttributeTableOfInteger_i* aTabIntegerAttr = new SALOMEDS_AttributeTableOfInteger_i(anAttr, _orb);
649 SALOMEDS::AttributeTableOfInteger_var aTIA = aTabIntegerAttr->AttributeTableOfInteger::_this();
652 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
653 Handle(SALOMEDS_TableOfRealAttribute) anAttr;
654 if (!Lab.FindAttribute(SALOMEDS_TableOfRealAttribute::GetID(), anAttr)) {
655 anAttr = new SALOMEDS_TableOfRealAttribute;
656 Lab.AddAttribute(anAttr);
658 SALOMEDS_AttributeTableOfReal_i* aTabRealAttr = new SALOMEDS_AttributeTableOfReal_i(anAttr, _orb);
659 SALOMEDS::AttributeTableOfReal_var aTRA = aTabRealAttr->AttributeTableOfReal::_this();
662 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
663 Handle(SALOMEDS_TableOfStringAttribute) anAttr;
664 if (!Lab.FindAttribute(SALOMEDS_TableOfStringAttribute::GetID(), anAttr)) {
665 anAttr = new SALOMEDS_TableOfStringAttribute;
666 Lab.AddAttribute(anAttr);
668 SALOMEDS_AttributeTableOfString_i* aTabStringAttr = new SALOMEDS_AttributeTableOfString_i(anAttr, _orb);
669 SALOMEDS::AttributeTableOfString_var aTRA = aTabStringAttr->AttributeTableOfString::_this();
672 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
673 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
674 if (!Lab.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
675 anAttr = new SALOMEDS_StudyPropertiesAttribute;
676 Lab.AddAttribute(anAttr);
677 anAttr->SetModified(0);
679 SALOMEDS_AttributeStudyProperties_i* aStPropAttr = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
680 SALOMEDS::AttributeStudyProperties_var aSPA = aStPropAttr->AttributeStudyProperties::_this();
683 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
684 Handle(SALOMEDS_PythonObjectAttribute) anAttr;
685 if (!Lab.FindAttribute(SALOMEDS_PythonObjectAttribute::GetID(), anAttr)) {
686 anAttr = new SALOMEDS_PythonObjectAttribute;
687 Lab.AddAttribute(anAttr);
689 SALOMEDS_AttributePythonObject_i* aPObjAttr = new SALOMEDS_AttributePythonObject_i(anAttr, _orb);
690 SALOMEDS::AttributePythonObject_var aPOA = aPObjAttr->AttributePythonObject::_this();
695 //============================================================================
696 /*! Function : FindAttribute
697 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
699 //============================================================================
701 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
702 SALOMEDS::GenericAttribute_out anAttribute,
703 const char* aTypeOfAttribute)
706 ASSERT(!CORBA::is_nil(anObject));
707 CORBA::String_var anobid = anObject->GetID();
708 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
709 Handle(TDF_Attribute) anAttr;
710 Standard_Boolean found = Lab.FindAttribute(SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute), anAttr);
712 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
713 SALOMEDS_AttributeReal_i* Attr= new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
714 anAttribute = Attr->AttributeReal::_this();
715 return Standard_True;
717 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
718 SALOMEDS_AttributeInteger_i* Attr= new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
719 anAttribute = Attr->AttributeInteger::_this();
720 return Standard_True;
722 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
723 SALOMEDS_AttributeSequenceOfReal_i* Attr= new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
724 anAttribute = Attr->AttributeSequenceOfReal::_this();
725 return Standard_True;
727 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
728 SALOMEDS_AttributeSequenceOfInteger_i* Attr= new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
729 anAttribute = Attr->AttributeSequenceOfInteger::_this();
730 return Standard_True;
732 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
733 SALOMEDS_AttributeName_i* Attr= new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
734 anAttribute = Attr->AttributeName::_this();
735 return Standard_True;
737 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
738 SALOMEDS_AttributeComment_i* Attr= new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
739 anAttribute = Attr->AttributeComment::_this();
740 return Standard_True;
742 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
743 SALOMEDS_AttributeIOR_i* Attr= new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
744 anAttribute = Attr->AttributeIOR::_this();
745 return Standard_True;
747 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
748 SALOMEDS_AttributePersistentRef_i* Attr= new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
749 anAttribute = Attr->AttributePersistentRef::_this();
750 return Standard_True;
752 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
753 SALOMEDS_AttributeDrawable_i* Attr= new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
754 anAttribute = Attr->AttributeDrawable::_this();
755 return Standard_True;
757 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
758 SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
759 anAttribute = Attr->AttributeSelectable::_this();
760 return Standard_True;
762 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
763 SALOMEDS_AttributeExpandable_i* Attr= new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
764 anAttribute = Attr->AttributeExpandable::_this();
765 return Standard_True;
767 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
768 SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
769 anAttribute = Attr->AttributeOpened::_this();
770 return Standard_True;
772 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
773 SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
774 anAttribute = Attr->AttributeTextColor::_this();
775 return Standard_True;
777 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
778 SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
779 anAttribute = Attr->AttributeTextHighlightColor::_this();
780 return Standard_True;
782 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
783 SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
784 anAttribute = Attr->AttributePixMap::_this();
785 return Standard_True;
787 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
788 SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
789 anAttribute = Attr->AttributeTreeNode::_this();
790 return Standard_True;
792 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
793 SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
794 anAttribute = Attr->AttributeUserID::_this();
795 return Standard_True;
797 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
798 SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
799 anAttribute = Attr->AttributeLocalID::_this();
800 return Standard_True;
802 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
803 SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
804 anAttribute = Attr->AttributeTarget::_this();
805 return Standard_True;
807 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
808 SALOMEDS_AttributeTableOfInteger_i* Attr= new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
809 anAttribute = Attr->AttributeTableOfInteger::_this();
810 return Standard_True;
812 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
813 SALOMEDS_AttributeTableOfReal_i* Attr= new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
814 anAttribute = Attr->AttributeTableOfReal::_this();
815 return Standard_True;
817 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
818 SALOMEDS_AttributeTableOfString_i* Attr= new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
819 anAttribute = Attr->AttributeTableOfString::_this();
820 return Standard_True;
822 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
823 SALOMEDS_AttributeStudyProperties_i* Attr= new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
824 anAttribute = Attr->AttributeStudyProperties::_this();
825 return Standard_True;
827 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
828 SALOMEDS_AttributePythonObject_i* Attr= new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
829 anAttribute = Attr->AttributePythonObject::_this();
830 return Standard_True;
832 } else return Standard_False;
835 //============================================================================
836 /*! Function : RemoveAttribute
837 * Purpose : Remove attribute of given type assigned SObject
839 //============================================================================
841 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
842 const char* aTypeOfAttribute)
845 ASSERT(!CORBA::is_nil(anObject));
846 CORBA::String_var anobid = anObject->GetID();
847 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
848 Lab.ForgetAttribute (SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute));
851 //============================================================================
852 /*! Function : Addreference
855 //============================================================================
857 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
858 SALOMEDS::SObject_ptr theReferencedObject)
861 ASSERT(!CORBA::is_nil(me));
862 CORBA::String_var meid = me->GetID();
863 TDF_Tool::Label(_doc->GetData(),strdup(meid),Lab);
865 ASSERT(!CORBA::is_nil(theReferencedObject));
866 CORBA::String_var roid = theReferencedObject->GetID();
867 TDF_Tool::Label(_doc->GetData(),strdup(roid),RefLab);
868 TDF_Reference::Set(Lab,RefLab);
870 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
872 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(me);
876 //============================================================================
877 /*! Function : AddDirectory
878 * Purpose : adds a new directory with a path = thePath
880 //============================================================================
881 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
883 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
885 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
886 TDF_ChildIterator anIterator(_doc->Main());
887 Handle(TDataStd_Name) aName;
889 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb);
890 SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(so_servant->_this());
891 SALOMEDS::Study_var aStudy = anObject->GetStudy();
894 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
898 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
900 if(aPath.Value(1) != '/') { //Relative path
902 aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
905 TCollection_AsciiString aToken = aPath.Token("/", 1);
906 if(aToken.Length() == 0) aFatherPath = "/";
909 while(aToken.Length() != 0) {
910 if(aPath.Token("/", i+1).Length() > 0) {
912 aFatherPath += aToken;
914 aToken = aPath.Token("/", ++i);
917 anObject = SALOMEDS::SObject::_nil();
919 anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
922 if(anObject->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
924 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
925 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
926 if(aLabel.IsNull()) {
927 MESSAGE("### NULL label");
928 throw SALOMEDS::Study::StudyInvalidComponent();
931 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
933 //Set PersistentRef attribute to identify the directory object
934 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributePersistentRef");
935 SALOMEDS::AttributePersistentRef_var aPersRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
936 if(aPersRef->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
938 aPersRef->SetValue(DIRECTORYID);
942 //============================================================================
943 /*! Function : SetGUID
946 //============================================================================
947 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
950 ASSERT(!CORBA::is_nil(anObject));
951 CORBA::String_var anEntry = anObject->GetID();
952 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
953 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
956 //============================================================================
957 /*! Function : IsGUID
960 //============================================================================
961 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
964 ASSERT(!CORBA::is_nil(anObject));
965 CORBA::String_var anEntry = anObject->GetID();
966 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
967 return aLabel.IsAttribute((char*)theGUID);
971 //============================================================================
972 /*! Function : NewCommand
975 //============================================================================
976 void SALOMEDS_StudyBuilder_i::NewCommand()
978 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
979 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
980 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
981 anAttr = new SALOMEDS_StudyPropertiesAttribute;
982 _doc->Main().AddAttribute(anAttr);
984 anAttr->IsLockChanged(true);
989 //============================================================================
990 /*! Function : CommitCommand
993 //============================================================================
994 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
996 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
997 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
998 anAttr = new SALOMEDS_StudyPropertiesAttribute;
999 _doc->Main().AddAttribute(anAttr);
1001 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
1002 INFOS("Locked document modification !!!");
1004 throw SALOMEDS::StudyBuilder::LockProtection();
1006 int aModif = anAttr->GetModified();
1007 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
1008 anAttr->SetModified(aModif+1);
1009 _doc->CommitCommand();
1013 //============================================================================
1014 /*! Function : HasOpenCommand
1017 //============================================================================
1018 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
1020 _doc->HasOpenCommand();
1023 //============================================================================
1024 /*! Function : AbortCommand
1027 //============================================================================
1028 void SALOMEDS_StudyBuilder_i::AbortCommand()
1030 _doc->AbortCommand();
1033 //============================================================================
1037 //============================================================================
1038 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
1040 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1041 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1042 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1043 _doc->Main().AddAttribute(anAttr);
1045 if (anAttr->IsLocked()) {
1046 INFOS("Locked document modification !!!");
1047 throw SALOMEDS::StudyBuilder::LockProtection();
1050 anAttr->SetModified(anAttr->GetModified()-1);
1054 //============================================================================
1058 //============================================================================
1059 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
1061 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1062 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1063 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1064 _doc->Main().AddAttribute(anAttr);
1067 if (anAttr->IsLocked()) {
1068 INFOS("Locked document modification !!!");
1069 throw SALOMEDS::StudyBuilder::LockProtection();
1072 anAttr->SetModified(anAttr->GetModified()+1);
1076 //============================================================================
1077 /*! Function : GetAvailableUndos
1080 //============================================================================
1081 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
1083 return _doc->GetAvailableUndos();
1086 //============================================================================
1087 /*! Function : GetAvailableRedos
1090 //============================================================================
1091 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
1093 return _doc->GetAvailableRedos();
1097 //============================================================================
1098 /*! Function : UndoLimit
1101 //============================================================================
1102 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
1104 return _doc->GetUndoLimit();
1107 //============================================================================
1108 /*! Function : UndoLimit
1111 //============================================================================
1112 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
1114 _doc->SetUndoLimit (n);
1117 //============================================================================
1118 /*! Function : SetOnAddSObject
1121 //============================================================================
1122 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
1124 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnAdd))?NULL:_callbackOnAdd._retn();
1125 _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
1129 //============================================================================
1130 /*! Function : SetOnNewSObject
1133 //============================================================================
1134 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
1136 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnRemove))?NULL:_callbackOnRemove._retn();
1137 _callbackOnRemove = SALOMEDS::Callback::_duplicate(theCallback);