1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOMEDS_StudyBuilder_i.cxx
25 // Author : Yves FRICAUD
30 #include "utilities.h"
31 #include "SALOMEDS_Study_i.hxx"
32 //#include "SALOMEDS_StudyBuilder_i.hxx"
33 #include "SALOMEDS_SObject_i.hxx"
34 #include "SALOMEDS_SComponent_i.hxx"
36 #include "SALOMEDS_IORAttribute.hxx"
37 #include "SALOMEDS_PersRefAttribute.hxx"
38 #include "SALOMEDS_TargetAttribute.hxx"
39 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
40 #include "SALOMEDS_PythonObjectAttribute.hxx"
41 #include <TDF_ChildIterator.hxx>
42 #include <TDF_Label.hxx>
43 #include <TDataStd_Name.hxx>
44 #include <TDataStd_Comment.hxx>
45 #include <TDataStd_UAttribute.hxx>
46 #include <TDF_Tool.hxx>
47 #include <TDF_Reference.hxx>
48 #include <TDF_Data.hxx>
49 #include <TDataStd_ChildNodeIterator.hxx>
50 #include <TDF_ListIteratorOfAttributeList.hxx>
51 #include "SALOMEDS_AttributePersistentRef_i.hxx"
52 #include "SALOMEDS_AttributeIOR_i.hxx"
53 #include "SALOMEDS_AttributeComment_i.hxx"
54 #include "SALOMEDS_AttributeExternalFileDef_i.hxx"
55 #include "SALOMEDS_AttributeFileType_i.hxx"
56 #include "SALOMEDS_AttributeName_i.hxx"
57 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
58 #include "SALOMEDS_AttributeSequenceOfReal_i.hxx"
59 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
60 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
61 #include "SALOMEDS_AttributeTableOfString_i.hxx"
62 #include "SALOMEDS_AttributeInteger_i.hxx"
63 #include "SALOMEDS_AttributeReal_i.hxx"
64 #include "SALOMEDS_AttributeDrawable_i.hxx"
65 #include "SALOMEDS_AttributeSelectable_i.hxx"
66 #include "SALOMEDS_AttributeExpandable_i.hxx"
67 #include "SALOMEDS_AttributeOpened_i.hxx"
68 #include "SALOMEDS_AttributeTextColor_i.hxx"
69 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
70 #include "SALOMEDS_AttributePixMap_i.hxx"
71 #include "SALOMEDS_AttributeTreeNode_i.hxx"
72 #include "SALOMEDS_AttributeTarget_i.hxx"
73 #include "SALOMEDS_AttributeLocalID_i.hxx"
74 #include "SALOMEDS_AttributeUserID_i.hxx"
75 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
76 #include "SALOMEDS_AttributePythonObject_i.hxx"
77 #include "SALOMEDS_Tool.hxx"
78 #include "Utils_CorbaException.hxx"
83 #define USE_CASE_LABEL_TAG 2
84 #define DIRECTORYID 16661
85 #define FILELOCALID 26662
87 //============================================================================
88 /*! Function : constructor
91 //============================================================================
92 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) doc,
93 CORBA::ORB_ptr orb) : _doc(doc)
95 _orb = CORBA::ORB::_duplicate(orb);
98 //============================================================================
99 /*! Function : destructor
102 //============================================================================
103 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
107 //============================================================================
108 /*! Function : NewComponent
109 * Purpose : Create a new component (Scomponent)
111 //============================================================================
112 SALOMEDS::SComponent_ptr
113 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
116 //Always create component under main label.
117 TDF_Label L = _doc->Main();
119 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
121 Standard_Integer imax = 0;
122 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
123 if (it.Value().Tag() > imax)
124 imax = it.Value().Tag();
127 TDF_Label NL = L.FindChild(imax);
129 // TDataStd_Comment::Set(NL,Standard_CString(DataType));
130 TDataStd_Comment::Set(NL,Standard_CString(strdup(DataType)));
132 SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (NL,_orb);
133 SALOMEDS::SComponent_var so;
134 so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this());
136 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
141 //============================================================================
142 /*! Function : DefineComponentInstance
143 * Purpose : Add IOR attribute of a Scomponent
145 //============================================================================
146 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
147 CORBA::Object_ptr IOR)
152 ASSERT(!CORBA::is_nil(aComponent));
153 CORBA::String_var compid = aComponent->GetID();
154 TDF_Tool::Label(_doc->GetData(),strdup(compid),Lab);
157 ASSERT(!CORBA::is_nil(IOR));
158 CORBA::String_var iorstr = _orb->object_to_string(IOR);
159 SALOMEDS_IORAttribute::Set(Lab,strdup(iorstr),_orb);
163 //============================================================================
164 /*! Function : RemoveComponent
165 * Purpose : Delete a Scomponent
167 //============================================================================
169 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
172 ASSERT(!CORBA::is_nil(aComponent));
173 RemoveObject(aComponent);
176 //============================================================================
177 /*! Function : NewObject
178 * Purpose : Create a new SObject
180 //============================================================================
181 SALOMEDS::SObject_ptr
182 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
185 TCollection_AsciiString anEntry;
187 //Find label of father
190 ASSERT(!CORBA::is_nil(theFatherObject));
191 CORBA::String_var fatherid = theFatherObject->GetID();
192 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
195 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
196 Standard_Integer imax = 0;
197 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
198 if (it.Value().Tag() > imax)
199 imax = it.Value().Tag();
202 TDF_Label NewLab = Lab.FindChild(imax);
204 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
205 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
207 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
212 //============================================================================
213 /*! Function : NewObjectToTag
216 //============================================================================
217 SALOMEDS::SObject_ptr
218 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
222 //Find label of father
225 ASSERT(!CORBA::is_nil(theFatherObject));
226 CORBA::String_var fatherid = theFatherObject->GetID();
227 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
228 //Create or find label
229 TDF_Label NewLab = Lab.FindChild(atag,1);
231 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
232 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
234 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
239 //============================================================================
240 /*! Function : RemoveObject
243 //============================================================================
244 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
247 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
250 ASSERT(!CORBA::is_nil(anObject));
251 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
253 Handle(TDF_Reference) aReference;
254 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
255 Handle(SALOMEDS_TargetAttribute) aTarget;
256 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
257 aTarget->Remove(Lab);
260 Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
261 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
262 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(strdup(TCollection_AsciiString(anAttr->Get()).ToCString()));
264 Lab.ForgetAllAttributes();
267 //============================================================================
268 /*! Function : RemoveObjectWithChildren
271 //============================================================================
272 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
275 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
278 ASSERT(!CORBA::is_nil(anObject));
279 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
281 Handle(TDF_Reference) aReference;
282 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
283 Handle(SALOMEDS_TargetAttribute) aTarget;
284 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
285 aTarget->Remove(Lab);
287 Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
288 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
289 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(strdup(TCollection_AsciiString(anAttr->Get()).ToCString()));
291 TDF_ChildIterator it(Lab);
292 for(;it.More();it.Next()) {
293 TDF_Label aLabel = it.Value();
294 if (aLabel.FindAttribute(TDF_Reference::GetID(), aReference)) {
295 Handle(SALOMEDS_TargetAttribute) aTarget;
296 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
297 aTarget->Remove(aLabel);
299 Handle(SALOMEDS_IORAttribute) anAttr; // postponed removing of CORBA objects
300 if (aLabel.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
301 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(strdup(TCollection_AsciiString(anAttr->Get()).ToCString()));
304 Lab.ForgetAllAttributes(Standard_True);
307 //============================================================================
308 /*! Function : Translate_persistentID_to_IOR
311 //============================================================================
312 static void Translate_persistentID_to_IOR(TDF_Label Lab,
313 SALOMEDS::Driver_ptr driver,
315 CORBA::Boolean isMultiFile,
316 CORBA::Boolean isASCII)
318 TDF_ChildIterator itchild (Lab);
320 for (; itchild.More(); itchild.Next()) {
321 TDF_Label current = itchild.Value();
322 Handle(TDF_Attribute) Att;
323 if (current.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
325 Handle(SALOMEDS_LocalIDAttribute) anID;
326 if (current.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID))
327 if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
329 TCollection_ExtendedString res;
330 res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
331 TCollection_AsciiString ch(res);
333 CORBA::String_var persistent_string = CORBA::string_dup(ch.ToCString());
334 ASSERT(! CORBA::is_nil(driver));
335 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (current,orb);
336 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
338 CORBA::String_var ior_string = driver->LocalPersistentIDToIOR(so, persistent_string, isMultiFile, isASCII);
340 TCollection_ExtendedString value(strdup(ior_string ));
341 SALOMEDS_IORAttribute::Set (current,value,orb);
343 //TCollection_AsciiString anEntry;TDF_Tool::Entry (current,anEntry); //SRN: No use here
344 //delete persistent_string;
347 Translate_persistentID_to_IOR (current,driver,orb,isMultiFile, isASCII);
351 //============================================================================
352 /*! Function : LoadWith
355 //============================================================================
357 //============================================================================
358 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
359 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
362 ASSERT(!CORBA::is_nil(anSCO));
363 CORBA::String_var scoid = anSCO->GetID();
364 TDF_Tool::Label(_doc->GetData(),strdup(scoid),Lab);
365 Handle(TDF_Attribute) Att;
367 //Find the current Url of the study
368 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
369 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
370 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
372 TCollection_ExtendedString Res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
374 Handle(TDataStd_Comment) type;
375 TCollection_ExtendedString DataType;
376 if (Lab.FindAttribute(TDataStd_Comment::GetID(),type))
377 DataType = type->Get();
379 MESSAGE("No Data Type");
381 // associate the driver to the SComponent
382 ASSERT(!CORBA::is_nil(aDriver));
383 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
384 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
385 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
388 DefineComponentInstance (anSCO, aDriver);
390 TCollection_AsciiString aHDFPath(Res);
393 bool isASCII = false;
394 if (HDFascii::isASCII(aHDFPath.ToCString())) {
396 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString());
397 aHDFUrl = new char[strlen(aResultPath) + 19];
398 sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath);
401 aHDFUrl = strdup(aHDFPath.ToCString());
404 //Open the Study HDF file
405 HDFfile *hdf_file = new HDFfile(aHDFUrl);
407 char aMultifileState[2];
408 char ASCIIfileState[2];
410 CORBA::String_var scoid = anSCO->GetID();
411 hdf_file->OpenOnDisk(HDF_RDONLY);
412 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
413 hdf_group->OpenOnDisk();
414 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
415 hdf_sco_group->OpenOnDisk();
417 SALOMEDS::TMPFile_var aStreamFile;
418 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
419 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
420 hdf_dataset->OpenOnDisk();
421 int aStreamSize = hdf_dataset->GetSize();
422 unsigned char* aBuffer = new unsigned char[aStreamSize];
423 if(aBuffer == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
424 hdf_dataset->ReadFromDisk(aBuffer);
425 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
426 hdf_dataset->CloseOnDisk();
428 } else aStreamFile = new SALOMEDS::TMPFile(0);
430 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
431 multifile_hdf_dataset->OpenOnDisk();
432 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
434 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
435 ascii_hdf_dataset->OpenOnDisk();
436 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
438 // set path without file name from URL
439 int aFileNameSize = Res.Length();
440 char* aDir = new char[aFileNameSize];
441 memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
442 for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
443 if (aDir[aCounter] == '/') {
444 aDir[aCounter+1] = 0;
448 CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
449 aDriver->LoadASCII(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M'):
450 aDriver->Load(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M');
452 RemoveAttribute( anSCO, "AttributeIOR" );
454 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
455 aFilesToRemove->length(1);
456 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
457 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
460 MESSAGE("Can't load component");
461 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
462 // throw HDFexception("Unable to load component");
467 multifile_hdf_dataset->CloseOnDisk();
468 multifile_hdf_dataset = 0;
469 ascii_hdf_dataset->CloseOnDisk();
470 ascii_hdf_dataset = 0;
471 hdf_sco_group->CloseOnDisk();
473 hdf_group->CloseOnDisk();
475 hdf_file->CloseOnDisk();
479 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
480 aFilesToRemove->length(1);
481 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
482 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
486 catch (HDFexception) {
487 MESSAGE("No persistent file Name");
490 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
491 aFilesToRemove->length(1);
492 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
493 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
496 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
501 Translate_persistentID_to_IOR (Lab,aDriver,_orb, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
502 } catch (SALOME::SALOME_Exception) {
503 MESSAGE("Can't translate PersRef to IOR");
504 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
505 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
506 // throw HDFexception("Unable to load component data");
508 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
510 MESSAGE("No persistent file Name");
514 //============================================================================
518 //============================================================================
519 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
521 MESSAGE ( "This function is not yet implemented");
524 //============================================================================
525 /*! Function : AddAttribute
528 //============================================================================
530 void SALOMEDS_StudyBuilder_i::AddAttribute(SALOMEDS::SObject_ptr anObject,
531 SALOMEDS::AttributeType aType,
532 const char * AttributeValue )
535 ASSERT(!CORBA::is_nil(anObject));
536 CORBA::String_var anobid = anObject->GetID();
537 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
539 TCollection_ExtendedString Value(strdup(AttributeValue));
541 Standard_GUID ID = SALOMEDS_SObject_i::TypeToAttributeID(aType);
543 if (ID == TDataStd_Name::GetID()) TDataStd_Name::Set (Lab,Value);
544 else if (ID == TDataStd_Comment::GetID()) TDataStd_Comment::Set (Lab,Value);
545 else if (ID == SALOMEDS_IORAttribute::GetID()) SALOMEDS_IORAttribute::Set (Lab,Value);
546 else if (ID == SALOMEDS_PersRefAttribute::GetID()) SALOMEDS_PersRefAttribute::Set(Lab,Value);
549 //============================================================================
550 /*! Function : FindOrCreateAttribute
551 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
554 //============================================================================
556 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
557 const char* aTypeOfAttribute)
560 ASSERT(!CORBA::is_nil(anObject));
561 CORBA::String_var anobid = anObject->GetID();
562 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
564 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
565 Handle(TDataStd_Real) anAttr;
566 if (!Lab.FindAttribute(TDataStd_Real::GetID(), anAttr)) {
568 anAttr = new TDataStd_Real;
569 Lab.AddAttribute(anAttr);
571 SALOMEDS_AttributeReal_i* aRealAttr = new SALOMEDS_AttributeReal_i(anAttr, _orb);
572 SALOMEDS::AttributeReal_var aRA = aRealAttr->AttributeReal::_this();
575 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
576 Handle(TDataStd_Integer) anAttr;
577 if (!Lab.FindAttribute(TDataStd_Integer::GetID(), anAttr)) {
579 anAttr = new TDataStd_Integer;
580 Lab.AddAttribute(anAttr);
582 SALOMEDS_AttributeInteger_i* aIntAttr = new SALOMEDS_AttributeInteger_i(anAttr, _orb);
583 SALOMEDS::AttributeInteger_var aIA = aIntAttr->AttributeInteger::_this();
586 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
587 Handle(SALOMEDS_SequenceOfRealAttribute) anAttr;
588 if (!Lab.FindAttribute(SALOMEDS_SequenceOfRealAttribute::GetID(), anAttr)) {
590 anAttr = new SALOMEDS_SequenceOfRealAttribute;
591 Lab.AddAttribute(anAttr);
593 SALOMEDS_AttributeSequenceOfReal_i* aSeqRealAttr = new SALOMEDS_AttributeSequenceOfReal_i(anAttr, _orb);
594 SALOMEDS::AttributeSequenceOfReal_var aSRA = aSeqRealAttr->AttributeSequenceOfReal::_this();
597 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
598 Handle(SALOMEDS_SequenceOfIntegerAttribute) anAttr;
599 if (!Lab.FindAttribute(SALOMEDS_SequenceOfIntegerAttribute::GetID(), anAttr)) {
601 anAttr = new SALOMEDS_SequenceOfIntegerAttribute;
602 Lab.AddAttribute(anAttr);
604 SALOMEDS_AttributeSequenceOfInteger_i* aSeqIntegerAttr = new SALOMEDS_AttributeSequenceOfInteger_i(anAttr, _orb);
605 SALOMEDS::AttributeSequenceOfInteger_var aSIA = aSeqIntegerAttr->AttributeSequenceOfInteger::_this();
608 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
609 Handle(TDataStd_Name) anAttr;
610 if (!Lab.FindAttribute(TDataStd_Name::GetID(), anAttr)) {
612 anAttr = new TDataStd_Name;
613 Lab.AddAttribute(anAttr);
615 SALOMEDS_AttributeName_i* aNameAttr = new SALOMEDS_AttributeName_i(anAttr, _orb);
616 SALOMEDS::AttributeName_var aSNA = aNameAttr->AttributeName::_this();
619 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
620 Handle(TDataStd_Comment) anAttr;
621 if (!Lab.FindAttribute(TDataStd_Comment::GetID(), anAttr)) {
623 anAttr = new TDataStd_Comment;
624 Lab.AddAttribute(anAttr);
626 SALOMEDS_AttributeComment_i* aCommentAttr = new SALOMEDS_AttributeComment_i(anAttr, _orb);
627 SALOMEDS::AttributeComment_var aCA = aCommentAttr->AttributeComment::_this();
630 else if (strcmp(aTypeOfAttribute, "AttributeExternalFileDef") == 0 ) {
631 Handle(SALOMEDS_ExternalFileDef) anAttr;
632 if (!Lab.FindAttribute(SALOMEDS_ExternalFileDef::GetID(), anAttr)) {
633 anAttr = new SALOMEDS_ExternalFileDef;
634 Lab.AddAttribute(anAttr);
636 SALOMEDS_AttributeExternalFileDef_i* anExternalFileDefAttr = new SALOMEDS_AttributeExternalFileDef_i(anAttr, _orb);
637 SALOMEDS::AttributeExternalFileDef_var aCA = anExternalFileDefAttr->AttributeExternalFileDef::_this();
640 else if (strcmp(aTypeOfAttribute, "AttributeFileType") == 0 ) {
641 Handle(SALOMEDS_FileType) anAttr;
642 if (!Lab.FindAttribute(SALOMEDS_FileType::GetID(), anAttr)) {
643 anAttr = new SALOMEDS_FileType;
644 Lab.AddAttribute(anAttr);
646 SALOMEDS_AttributeFileType_i* anFileTypeAttr = new SALOMEDS_AttributeFileType_i(anAttr, _orb);
647 SALOMEDS::AttributeFileType_var aCA = anFileTypeAttr->AttributeFileType::_this();
650 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
651 Handle(SALOMEDS_IORAttribute) anAttr;
652 if (!Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) {
654 anAttr = new SALOMEDS_IORAttribute;
655 Lab.AddAttribute(anAttr);
657 SALOMEDS_AttributeIOR_i* aIORAttr = new SALOMEDS_AttributeIOR_i(anAttr, _orb);
658 SALOMEDS::AttributeIOR_var aIA = aIORAttr->AttributeIOR::_this();
661 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
662 Handle(SALOMEDS_PersRefAttribute) anAttr;
663 if (!Lab.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), anAttr)) {
664 anAttr = new SALOMEDS_PersRefAttribute;
665 Lab.AddAttribute(anAttr);
667 SALOMEDS_AttributePersistentRef_i* aPerRefAttr = new SALOMEDS_AttributePersistentRef_i(anAttr, _orb);
668 SALOMEDS::AttributePersistentRef_var aPRA = aPerRefAttr->AttributePersistentRef::_this();
671 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
672 Handle(SALOMEDS_DrawableAttribute) anAttr;
673 if (!Lab.FindAttribute(SALOMEDS_DrawableAttribute::GetID(), anAttr)) {
674 anAttr = new SALOMEDS_DrawableAttribute;
675 Lab.AddAttribute(anAttr);
677 SALOMEDS_AttributeDrawable_i* aDrawableAttr = new SALOMEDS_AttributeDrawable_i(anAttr, _orb);
678 SALOMEDS::AttributeDrawable_var aDrawA = aDrawableAttr->AttributeDrawable::_this();
679 return aDrawA._retn();
681 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
682 Handle(SALOMEDS_SelectableAttribute) anAttr;
683 if (!Lab.FindAttribute(SALOMEDS_SelectableAttribute::GetID(), anAttr)) {
684 anAttr = new SALOMEDS_SelectableAttribute;
685 Lab.AddAttribute(anAttr);
687 SALOMEDS_AttributeSelectable_i* aSelectableAttr = new SALOMEDS_AttributeSelectable_i(anAttr, _orb);
688 SALOMEDS::AttributeSelectable_var aSelA = aSelectableAttr->AttributeSelectable::_this();
689 return aSelA._retn();
691 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
692 Handle(SALOMEDS_ExpandableAttribute) anAttr;
693 if (!Lab.FindAttribute(SALOMEDS_ExpandableAttribute::GetID(), anAttr)) {
694 anAttr = new SALOMEDS_ExpandableAttribute;
695 Lab.AddAttribute(anAttr);
697 SALOMEDS_AttributeExpandable_i* aExpandableAttr = new SALOMEDS_AttributeExpandable_i(anAttr, _orb);
698 SALOMEDS::AttributeExpandable_var aExpA = aExpandableAttr->AttributeExpandable::_this();
699 return aExpA._retn();
701 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
702 Handle(SALOMEDS_OpenedAttribute) anAttr;
703 if (!Lab.FindAttribute(SALOMEDS_OpenedAttribute::GetID(), anAttr)) {
704 anAttr = new SALOMEDS_OpenedAttribute;
705 Lab.AddAttribute(anAttr);
707 SALOMEDS_AttributeOpened_i* aOpenedAttr = new SALOMEDS_AttributeOpened_i(anAttr, _orb);
708 SALOMEDS::AttributeOpened_var aOpenA = aOpenedAttr->AttributeOpened::_this();
709 return aOpenA._retn();
711 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
712 Handle(SALOMEDS_TextColorAttribute) anAttr;
713 if (!Lab.FindAttribute(SALOMEDS_TextColorAttribute::GetID(), anAttr)) {
715 anAttr = new SALOMEDS_TextColorAttribute;
716 Lab.AddAttribute(anAttr);
718 SALOMEDS_AttributeTextColor_i* aTextColorAttr = new SALOMEDS_AttributeTextColor_i(anAttr, _orb);
719 SALOMEDS::AttributeTextColor_var aTCA = aTextColorAttr->AttributeTextColor::_this();
722 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
723 Handle(SALOMEDS_TextHighlightColorAttribute) anAttr;
724 if (!Lab.FindAttribute(SALOMEDS_TextHighlightColorAttribute::GetID(), anAttr)) {
726 anAttr = new SALOMEDS_TextHighlightColorAttribute;
727 Lab.AddAttribute(anAttr);
729 SALOMEDS_AttributeTextHighlightColor_i* aTextHighlightColorAttr = new SALOMEDS_AttributeTextHighlightColor_i(anAttr, _orb);
730 SALOMEDS::AttributeTextHighlightColor_var aTHCA = aTextHighlightColorAttr->AttributeTextHighlightColor::_this();
731 return aTHCA._retn();
733 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
734 Handle(SALOMEDS_PixMapAttribute) anAttr;
735 if (!Lab.FindAttribute(SALOMEDS_PixMapAttribute::GetID(), anAttr)) {
737 anAttr = new SALOMEDS_PixMapAttribute;
738 Lab.AddAttribute(anAttr);
740 SALOMEDS_AttributePixMap_i* aPixMapAttr = new SALOMEDS_AttributePixMap_i(anAttr, _orb);
741 SALOMEDS::AttributePixMap_var aPMA = aPixMapAttr->AttributePixMap::_this();
744 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
745 Standard_GUID aTreeNodeGUID;
746 if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0)
747 aTreeNodeGUID = TDataStd_TreeNode::GetDefaultTreeID();
749 char* aGUIDString = new char[40];
750 sprintf(aGUIDString, &(aTypeOfAttribute[21]));
751 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
754 Handle(TDataStd_TreeNode) anAttr;
755 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr)) {
757 anAttr = TDataStd_TreeNode::Set(Lab, aTreeNodeGUID);
759 SALOMEDS_AttributeTreeNode_i* aTreeNodeAttr = new SALOMEDS_AttributeTreeNode_i(anAttr, _orb);
760 SALOMEDS::AttributeTreeNode_var aTNA = aTreeNodeAttr->AttributeTreeNode::_this();
763 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
764 Handle(TDataStd_UAttribute) anAttr;
765 if (!Lab.FindAttribute(SALOMEDS_AttributeUserID_i::DefaultID(), anAttr)) {
767 anAttr = TDataStd_UAttribute::Set(Lab, SALOMEDS_AttributeUserID_i::DefaultID());
769 SALOMEDS_AttributeUserID_i* aUAttr = new SALOMEDS_AttributeUserID_i(anAttr, _orb);
770 SALOMEDS::AttributeUserID_var aUA = aUAttr->AttributeUserID::_this();
773 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
774 Handle(SALOMEDS_LocalIDAttribute) anAttr;
775 if (!Lab.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttr)) {
777 anAttr = new SALOMEDS_LocalIDAttribute;
778 Lab.AddAttribute(anAttr);
780 SALOMEDS_AttributeLocalID_i* aLIDAttr = new SALOMEDS_AttributeLocalID_i(anAttr, _orb);
781 SALOMEDS::AttributeLocalID_var aLIDA = aLIDAttr->AttributeLocalID::_this();
782 return aLIDA._retn();
784 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
785 Handle(SALOMEDS_TargetAttribute) anAttr;
786 if (!Lab.FindAttribute(SALOMEDS_TargetAttribute::GetID(), anAttr)) {
787 anAttr = new SALOMEDS_TargetAttribute;
788 Lab.AddAttribute(anAttr);
790 SALOMEDS_AttributeTarget_i* aLIDAttr = new SALOMEDS_AttributeTarget_i(anAttr, _orb);
791 SALOMEDS::AttributeTarget_var aLIDA = aLIDAttr->AttributeTarget::_this();
792 return aLIDA._retn();
794 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
795 Handle(SALOMEDS_TableOfIntegerAttribute) anAttr;
796 if (!Lab.FindAttribute(SALOMEDS_TableOfIntegerAttribute::GetID(), anAttr)) {
798 anAttr = new SALOMEDS_TableOfIntegerAttribute;
799 Lab.AddAttribute(anAttr);
801 SALOMEDS_AttributeTableOfInteger_i* aTabIntegerAttr = new SALOMEDS_AttributeTableOfInteger_i(anAttr, _orb);
802 SALOMEDS::AttributeTableOfInteger_var aTIA = aTabIntegerAttr->AttributeTableOfInteger::_this();
805 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
806 Handle(SALOMEDS_TableOfRealAttribute) anAttr;
807 if (!Lab.FindAttribute(SALOMEDS_TableOfRealAttribute::GetID(), anAttr)) {
809 anAttr = new SALOMEDS_TableOfRealAttribute;
810 Lab.AddAttribute(anAttr);
812 SALOMEDS_AttributeTableOfReal_i* aTabRealAttr = new SALOMEDS_AttributeTableOfReal_i(anAttr, _orb);
813 SALOMEDS::AttributeTableOfReal_var aTRA = aTabRealAttr->AttributeTableOfReal::_this();
816 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
817 Handle(SALOMEDS_TableOfStringAttribute) anAttr;
818 if (!Lab.FindAttribute(SALOMEDS_TableOfStringAttribute::GetID(), anAttr)) {
820 anAttr = new SALOMEDS_TableOfStringAttribute;
821 Lab.AddAttribute(anAttr);
823 SALOMEDS_AttributeTableOfString_i* aTabStringAttr = new SALOMEDS_AttributeTableOfString_i(anAttr, _orb);
824 SALOMEDS::AttributeTableOfString_var aTRA = aTabStringAttr->AttributeTableOfString::_this();
827 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
828 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
829 if (!Lab.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
831 if (!Lab.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
832 anAttr = new SALOMEDS_StudyPropertiesAttribute;
833 Lab.AddAttribute(anAttr);
834 anAttr->SetModified(0);
837 SALOMEDS_AttributeStudyProperties_i* aStPropAttr = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
838 SALOMEDS::AttributeStudyProperties_var aSPA = aStPropAttr->AttributeStudyProperties::_this();
841 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
842 Handle(SALOMEDS_PythonObjectAttribute) anAttr;
843 if (!Lab.FindAttribute(SALOMEDS_PythonObjectAttribute::GetID(), anAttr)) {
845 anAttr = new SALOMEDS_PythonObjectAttribute;
846 Lab.AddAttribute(anAttr);
848 SALOMEDS_AttributePythonObject_i* aPObjAttr = new SALOMEDS_AttributePythonObject_i(anAttr, _orb);
849 SALOMEDS::AttributePythonObject_var aPOA = aPObjAttr->AttributePythonObject::_this();
854 //============================================================================
855 /*! Function : FindAttribute
856 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
858 //============================================================================
860 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
861 SALOMEDS::GenericAttribute_out anAttribute,
862 const char* aTypeOfAttribute)
865 ASSERT(!CORBA::is_nil(anObject));
866 CORBA::String_var anobid = anObject->GetID();
867 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
868 Handle(TDF_Attribute) anAttr;
869 Standard_Boolean found = Lab.FindAttribute(SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute), anAttr);
871 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
872 SALOMEDS_AttributeReal_i* Attr= new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
873 anAttribute = Attr->AttributeReal::_this();
874 return Standard_True;
876 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
877 SALOMEDS_AttributeInteger_i* Attr= new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
878 anAttribute = Attr->AttributeInteger::_this();
879 return Standard_True;
881 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
882 SALOMEDS_AttributeSequenceOfReal_i* Attr= new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
883 anAttribute = Attr->AttributeSequenceOfReal::_this();
884 return Standard_True;
886 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
887 SALOMEDS_AttributeSequenceOfInteger_i* Attr= new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
888 anAttribute = Attr->AttributeSequenceOfInteger::_this();
889 return Standard_True;
891 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
892 SALOMEDS_AttributeName_i* Attr= new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
893 anAttribute = Attr->AttributeName::_this();
894 return Standard_True;
896 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
897 SALOMEDS_AttributeComment_i* Attr= new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
898 anAttribute = Attr->AttributeComment::_this();
899 return Standard_True;
901 else if (strcmp(aTypeOfAttribute, "AttributeExternalFileDef") == 0 ) {
902 SALOMEDS_AttributeExternalFileDef_i* Attr= new SALOMEDS_AttributeExternalFileDef_i(Handle(SALOMEDS_ExternalFileDef)::DownCast(anAttr), _orb);
903 anAttribute = Attr->AttributeExternalFileDef::_this();
904 return Standard_True;
906 else if (strcmp(aTypeOfAttribute, "AttributeFileType") == 0 ) {
907 SALOMEDS_AttributeFileType_i* Attr= new SALOMEDS_AttributeFileType_i(Handle(SALOMEDS_FileType)::DownCast(anAttr), _orb);
908 anAttribute = Attr->AttributeFileType::_this();
909 return Standard_True;
911 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
912 SALOMEDS_AttributeIOR_i* Attr= new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
913 anAttribute = Attr->AttributeIOR::_this();
914 return Standard_True;
916 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
917 SALOMEDS_AttributePersistentRef_i* Attr= new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
918 anAttribute = Attr->AttributePersistentRef::_this();
919 return Standard_True;
921 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
922 SALOMEDS_AttributeDrawable_i* Attr= new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
923 anAttribute = Attr->AttributeDrawable::_this();
924 return Standard_True;
926 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
927 SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
928 anAttribute = Attr->AttributeSelectable::_this();
929 return Standard_True;
931 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
932 SALOMEDS_AttributeExpandable_i* Attr= new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
933 anAttribute = Attr->AttributeExpandable::_this();
934 return Standard_True;
936 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
937 SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
938 anAttribute = Attr->AttributeOpened::_this();
939 return Standard_True;
941 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
942 SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
943 anAttribute = Attr->AttributeTextColor::_this();
944 return Standard_True;
946 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
947 SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
948 anAttribute = Attr->AttributeTextHighlightColor::_this();
949 return Standard_True;
951 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
952 SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
953 anAttribute = Attr->AttributePixMap::_this();
954 return Standard_True;
956 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
957 SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
958 anAttribute = Attr->AttributeTreeNode::_this();
959 return Standard_True;
961 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
962 SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
963 anAttribute = Attr->AttributeUserID::_this();
964 return Standard_True;
966 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
967 SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
968 anAttribute = Attr->AttributeLocalID::_this();
969 return Standard_True;
971 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
972 SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
973 anAttribute = Attr->AttributeTarget::_this();
974 return Standard_True;
976 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
977 SALOMEDS_AttributeTableOfInteger_i* Attr= new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
978 anAttribute = Attr->AttributeTableOfInteger::_this();
979 return Standard_True;
981 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
982 SALOMEDS_AttributeTableOfReal_i* Attr= new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
983 anAttribute = Attr->AttributeTableOfReal::_this();
984 return Standard_True;
986 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
987 SALOMEDS_AttributeTableOfString_i* Attr= new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
988 anAttribute = Attr->AttributeTableOfString::_this();
989 return Standard_True;
991 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
992 SALOMEDS_AttributeStudyProperties_i* Attr= new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
993 anAttribute = Attr->AttributeStudyProperties::_this();
994 return Standard_True;
996 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
997 SALOMEDS_AttributePythonObject_i* Attr= new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
998 anAttribute = Attr->AttributePythonObject::_this();
999 return Standard_True;
1001 } else return Standard_False;
1004 //============================================================================
1005 /*! Function : RemoveAttribute
1006 * Purpose : Remove attribute of given type assigned SObject
1008 //============================================================================
1010 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
1011 const char* aTypeOfAttribute)
1015 ASSERT(!CORBA::is_nil(anObject));
1016 CORBA::String_var anobid = anObject->GetID();
1017 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
1019 if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0) { // postponed removing of CORBA objects
1020 Handle(SALOMEDS_IORAttribute) anAttr;
1021 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr))
1022 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->AddPostponed(strdup(TCollection_AsciiString(anAttr->Get()).ToCString()));
1026 Lab.ForgetAttribute (SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute));
1029 //============================================================================
1030 /*! Function : Addreference
1033 //============================================================================
1035 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
1036 SALOMEDS::SObject_ptr theReferencedObject)
1040 ASSERT(!CORBA::is_nil(me));
1041 CORBA::String_var meid = me->GetID();
1042 TDF_Tool::Label(_doc->GetData(),strdup(meid),Lab);
1044 ASSERT(!CORBA::is_nil(theReferencedObject));
1045 CORBA::String_var roid = theReferencedObject->GetID();
1046 TDF_Tool::Label(_doc->GetData(),strdup(roid),RefLab);
1047 TDF_Reference::Set(Lab,RefLab);
1049 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
1051 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(me);
1055 //============================================================================
1056 /*! Function : AddDirectory
1057 * Purpose : adds a new directory with a path = thePath
1059 //============================================================================
1060 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
1063 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
1065 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
1066 TDF_ChildIterator anIterator(_doc->Main());
1067 Handle(TDataStd_Name) aName;
1069 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb);
1070 SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(so_servant->_this());
1071 SALOMEDS::Study_var aStudy = anObject->GetStudy();
1074 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
1078 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
1080 if(aPath.Value(1) != '/') { //Relative path
1082 aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
1085 TCollection_AsciiString aToken = aPath.Token("/", 1);
1086 if(aToken.Length() == 0) aFatherPath = "/";
1089 while(aToken.Length() != 0) {
1090 if(aPath.Token("/", i+1).Length() > 0) {
1092 aFatherPath += aToken;
1094 aToken = aPath.Token("/", ++i);
1097 anObject = SALOMEDS::SObject::_nil();
1099 anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
1102 if(anObject->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1104 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
1105 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
1106 if(aLabel.IsNull()) {
1107 MESSAGE("### NULL label");
1108 throw SALOMEDS::Study::StudyInvalidComponent();
1111 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
1113 //Set LocalID attribute to identify the directory object
1114 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID");
1115 SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr);
1116 if(aPersRef->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1118 aPersRef->SetValue(DIRECTORYID);
1122 //============================================================================
1123 /*! Function : SetGUID
1126 //============================================================================
1127 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1131 ASSERT(!CORBA::is_nil(anObject));
1132 CORBA::String_var anEntry = anObject->GetID();
1133 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1134 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
1137 //============================================================================
1138 /*! Function : IsGUID
1141 //============================================================================
1142 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1145 ASSERT(!CORBA::is_nil(anObject));
1146 CORBA::String_var anEntry = anObject->GetID();
1147 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1148 return aLabel.IsAttribute((char*)theGUID);
1152 //============================================================================
1153 /*! Function : NewCommand
1156 //============================================================================
1157 void SALOMEDS_StudyBuilder_i::NewCommand()
1159 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
1160 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1161 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1162 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1163 _doc->Main().AddAttribute(anAttr);
1165 anAttr->IsLockChanged(true);
1170 //============================================================================
1171 /*! Function : CommitCommand
1174 //============================================================================
1175 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
1177 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1178 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1179 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1180 _doc->Main().AddAttribute(anAttr);
1182 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
1183 INFOS("Locked document modification !!!");
1185 throw SALOMEDS::StudyBuilder::LockProtection();
1187 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->RemovePostponed(_doc->GetUndoLimit());
1189 int aModif = anAttr->GetModified();
1190 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
1191 anAttr->SetModified(aModif+1);
1192 _doc->CommitCommand();
1196 //============================================================================
1197 /*! Function : HasOpenCommand
1200 //============================================================================
1201 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
1203 _doc->HasOpenCommand();
1206 //============================================================================
1207 /*! Function : AbortCommand
1210 //============================================================================
1211 void SALOMEDS_StudyBuilder_i::AbortCommand()
1213 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(0);
1215 _doc->AbortCommand();
1218 //============================================================================
1222 //============================================================================
1223 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
1225 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1226 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1227 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1228 _doc->Main().AddAttribute(anAttr);
1230 if (anAttr->IsLocked()) {
1231 INFOS("Locked document modification !!!");
1232 throw SALOMEDS::StudyBuilder::LockProtection();
1234 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(1);
1236 anAttr->SetModified(anAttr->GetModified()-1);
1240 //============================================================================
1244 //============================================================================
1245 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
1247 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1248 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1249 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1250 _doc->Main().AddAttribute(anAttr);
1253 if (anAttr->IsLocked()) {
1254 INFOS("Locked document modification !!!");
1255 throw SALOMEDS::StudyBuilder::LockProtection();
1258 SALOMEDS_Study_i::GetStudy(_doc->Main(), _orb)->UndoPostponed(-1);
1259 anAttr->SetModified(anAttr->GetModified()+1);
1263 //============================================================================
1264 /*! Function : GetAvailableUndos
1267 //============================================================================
1268 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
1270 return _doc->GetAvailableUndos();
1273 //============================================================================
1274 /*! Function : GetAvailableRedos
1277 //============================================================================
1278 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
1280 return _doc->GetAvailableRedos();
1283 //============================================================================
1284 /*! Function : UndoLimit
1287 //============================================================================
1288 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
1290 return _doc->GetUndoLimit();
1293 //============================================================================
1294 /*! Function : UndoLimit
1297 //============================================================================
1298 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
1301 _doc->SetUndoLimit (n);
1304 //============================================================================
1305 /*! Function : SetOnAddSObject
1308 //============================================================================
1309 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
1311 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnAdd))?NULL:_callbackOnAdd._retn();
1312 _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
1316 //============================================================================
1317 /*! Function : SetOnNewSObject
1320 //============================================================================
1321 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
1323 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnRemove))?NULL:_callbackOnRemove._retn();
1324 _callbackOnRemove = SALOMEDS::Callback::_duplicate(theCallback);
1328 void SALOMEDS_StudyBuilder_i::CheckLocked() throw (SALOMEDS::StudyBuilder::LockProtection) {
1329 if (_doc->HasOpenCommand()) return;
1330 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1331 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1332 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1333 _doc->Main().AddAttribute(anAttr);
1335 if (anAttr->IsLocked()) throw SALOMEDS::StudyBuilder::LockProtection();