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_StudyBuilder_i.hxx"
32 #include "SALOMEDS_SObject_i.hxx"
33 #include "SALOMEDS_SComponent_i.hxx"
35 #include "SALOMEDS_IORAttribute.hxx"
36 #include "SALOMEDS_PersRefAttribute.hxx"
37 #include "SALOMEDS_TargetAttribute.hxx"
38 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
39 #include "SALOMEDS_PythonObjectAttribute.hxx"
40 #include <TDF_ChildIterator.hxx>
41 #include <TDF_Label.hxx>
42 #include <TDataStd_Name.hxx>
43 #include <TDataStd_Comment.hxx>
44 #include <TDataStd_UAttribute.hxx>
45 #include <TDF_Tool.hxx>
46 #include <TDF_Reference.hxx>
47 #include <TDF_Data.hxx>
48 #include <TDataStd_ChildNodeIterator.hxx>
49 #include <TDF_ListIteratorOfAttributeList.hxx>
50 #include "SALOMEDS_AttributePersistentRef_i.hxx"
51 #include "SALOMEDS_AttributeIOR_i.hxx"
52 #include "SALOMEDS_AttributeComment_i.hxx"
53 #include "SALOMEDS_AttributeExternalFileDef_i.hxx"
54 #include "SALOMEDS_AttributeFileType_i.hxx"
55 #include "SALOMEDS_AttributeName_i.hxx"
56 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
57 #include "SALOMEDS_AttributeSequenceOfReal_i.hxx"
58 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
59 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
60 #include "SALOMEDS_AttributeTableOfString_i.hxx"
61 #include "SALOMEDS_AttributeInteger_i.hxx"
62 #include "SALOMEDS_AttributeReal_i.hxx"
63 #include "SALOMEDS_AttributeDrawable_i.hxx"
64 #include "SALOMEDS_AttributeSelectable_i.hxx"
65 #include "SALOMEDS_AttributeExpandable_i.hxx"
66 #include "SALOMEDS_AttributeOpened_i.hxx"
67 #include "SALOMEDS_AttributeTextColor_i.hxx"
68 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
69 #include "SALOMEDS_AttributePixMap_i.hxx"
70 #include "SALOMEDS_AttributeTreeNode_i.hxx"
71 #include "SALOMEDS_AttributeTarget_i.hxx"
72 #include "SALOMEDS_AttributeLocalID_i.hxx"
73 #include "SALOMEDS_AttributeUserID_i.hxx"
74 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
75 #include "SALOMEDS_AttributePythonObject_i.hxx"
76 #include "SALOMEDS_Tool.hxx"
77 #include "Utils_CorbaException.hxx"
82 #define USE_CASE_LABEL_TAG 2
83 #define DIRECTORYID 16661
84 #define FILELOCALID 26662
86 //============================================================================
87 /*! Function : constructor
90 //============================================================================
91 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) doc,
92 CORBA::ORB_ptr orb) : _doc(doc)
94 _orb = CORBA::ORB::_duplicate(orb);
97 //============================================================================
98 /*! Function : destructor
101 //============================================================================
102 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
106 //============================================================================
107 /*! Function : NewComponent
108 * Purpose : Create a new component (Scomponent)
110 //============================================================================
111 SALOMEDS::SComponent_ptr
112 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
114 //Always create component under main label.
115 TDF_Label L = _doc->Main();
117 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
119 Standard_Integer imax = 0;
120 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
121 if (it.Value().Tag() > imax)
122 imax = it.Value().Tag();
125 TDF_Label NL = L.FindChild(imax);
127 // TDataStd_Comment::Set(NL,Standard_CString(DataType));
128 TDataStd_Comment::Set(NL,Standard_CString(strdup(DataType)));
130 SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (NL,_orb);
131 SALOMEDS::SComponent_var so;
132 so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this());
134 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
139 //============================================================================
140 /*! Function : DefineComponentInstance
141 * Purpose : Add IOR attribute of a Scomponent
143 //============================================================================
144 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
145 CORBA::Object_ptr IOR)
149 ASSERT(!CORBA::is_nil(aComponent));
150 CORBA::String_var compid = aComponent->GetID();
151 TDF_Tool::Label(_doc->GetData(),strdup(compid),Lab);
154 ASSERT(!CORBA::is_nil(IOR));
155 CORBA::String_var iorstr = _orb->object_to_string(IOR);
156 SALOMEDS_IORAttribute::Set(Lab,strdup(iorstr),_orb);
160 //============================================================================
161 /*! Function : RemoveComponent
162 * Purpose : Delete a Scomponent
164 //============================================================================
166 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
168 ASSERT(!CORBA::is_nil(aComponent));
169 RemoveObject(aComponent);
172 //============================================================================
173 /*! Function : NewObject
174 * Purpose : Create a new SObject
176 //============================================================================
177 SALOMEDS::SObject_ptr
178 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
180 TCollection_AsciiString anEntry;
182 //Find label of father
185 ASSERT(!CORBA::is_nil(theFatherObject));
186 CORBA::String_var fatherid = theFatherObject->GetID();
187 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
190 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
191 Standard_Integer imax = 0;
192 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
193 if (it.Value().Tag() > imax)
194 imax = it.Value().Tag();
197 TDF_Label NewLab = Lab.FindChild(imax);
199 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
200 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
202 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
207 //============================================================================
208 /*! Function : NewObjectToTag
211 //============================================================================
212 SALOMEDS::SObject_ptr
213 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
216 //Find label of father
219 ASSERT(!CORBA::is_nil(theFatherObject));
220 CORBA::String_var fatherid = theFatherObject->GetID();
221 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
222 //Create or find label
223 TDF_Label NewLab = Lab.FindChild(atag,1);
225 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
226 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
228 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
233 //============================================================================
234 /*! Function : RemoveObject
237 //============================================================================
238 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
240 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
243 ASSERT(!CORBA::is_nil(anObject));
244 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
246 Handle(TDF_Reference) aReference;
247 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
248 Handle(SALOMEDS_TargetAttribute) aTarget;
249 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
250 aTarget->Remove(Lab);
253 Lab.ForgetAllAttributes();
256 //============================================================================
257 /*! Function : RemoveObjectWithChildren
260 //============================================================================
261 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
263 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
266 ASSERT(!CORBA::is_nil(anObject));
267 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
269 Handle(TDF_Reference) aReference;
270 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
271 Handle(SALOMEDS_TargetAttribute) aTarget;
272 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
273 aTarget->Remove(Lab);
276 TDF_ChildIterator it(Lab);
277 for(;it.More();it.Next()) {
278 TDF_Label aLabel = it.Value();
279 if (aLabel.FindAttribute(TDF_Reference::GetID(), aReference)) {
280 Handle(SALOMEDS_TargetAttribute) aTarget;
281 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
282 aTarget->Remove(aLabel);
286 Lab.ForgetAllAttributes(Standard_True);
289 //============================================================================
290 /*! Function : Translate_persistentID_to_IOR
293 //============================================================================
294 static void Translate_persistentID_to_IOR(TDF_Label Lab,
295 SALOMEDS::Driver_ptr driver,
297 CORBA::Boolean isMultiFile,
298 CORBA::Boolean isASCII)
300 TDF_ChildIterator itchild (Lab);
302 for (; itchild.More(); itchild.Next()) {
303 TDF_Label current = itchild.Value();
304 Handle(TDF_Attribute) Att;
305 if (current.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
307 Handle(SALOMEDS_LocalIDAttribute) anID;
308 if (current.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID))
309 if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
311 TCollection_ExtendedString res;
312 res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
313 TCollection_AsciiString ch(res);
315 CORBA::String_var persistent_string = CORBA::string_dup(ch.ToCString());
316 ASSERT(! CORBA::is_nil(driver));
317 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (current,orb);
318 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
320 CORBA::String_var ior_string = driver->LocalPersistentIDToIOR(so, persistent_string, isMultiFile, isASCII);
322 TCollection_ExtendedString value(strdup(ior_string ));
323 SALOMEDS_IORAttribute::Set (current,value,orb);
325 //TCollection_AsciiString anEntry;TDF_Tool::Entry (current,anEntry); //SRN: No use here
326 //delete persistent_string;
329 Translate_persistentID_to_IOR (current,driver,orb,isMultiFile, isASCII);
333 //============================================================================
334 /*! Function : LoadWith
337 //============================================================================
339 //============================================================================
340 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
341 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
344 ASSERT(!CORBA::is_nil(anSCO));
345 CORBA::String_var scoid = anSCO->GetID();
346 TDF_Tool::Label(_doc->GetData(),strdup(scoid),Lab);
347 Handle(TDF_Attribute) Att;
349 //Find the current Url of the study
350 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
351 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
352 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
354 TCollection_ExtendedString Res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
356 Handle(TDataStd_Comment) type;
357 TCollection_ExtendedString DataType;
358 if (Lab.FindAttribute(TDataStd_Comment::GetID(),type))
359 DataType = type->Get();
361 MESSAGE("No Data Type");
363 // associate the driver to the SComponent
364 ASSERT(!CORBA::is_nil(aDriver));
365 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
366 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
367 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
370 DefineComponentInstance (anSCO, aDriver);
372 TCollection_AsciiString aHDFPath(Res);
375 bool isASCII = false;
376 if (HDFascii::isASCII(aHDFPath.ToCString())) {
378 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString());
379 aHDFUrl = new char[strlen(aResultPath) + 19];
380 sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath);
383 aHDFUrl = strdup(aHDFPath.ToCString());
386 //Open the Study HDF file
387 HDFfile *hdf_file = new HDFfile(aHDFUrl);
389 char aMultifileState[2];
390 char ASCIIfileState[2];
392 CORBA::String_var scoid = anSCO->GetID();
393 hdf_file->OpenOnDisk(HDF_RDONLY);
394 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
395 hdf_group->OpenOnDisk();
396 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
397 hdf_sco_group->OpenOnDisk();
399 SALOMEDS::TMPFile_var aStreamFile;
400 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
401 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
402 hdf_dataset->OpenOnDisk();
403 int aStreamSize = hdf_dataset->GetSize();
404 unsigned char* aBuffer = new unsigned char[aStreamSize];
405 if(aBuffer == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
406 hdf_dataset->ReadFromDisk(aBuffer);
407 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
408 hdf_dataset->CloseOnDisk();
410 } else aStreamFile = new SALOMEDS::TMPFile(0);
412 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
413 multifile_hdf_dataset->OpenOnDisk();
414 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
416 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
417 ascii_hdf_dataset->OpenOnDisk();
418 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
420 // set path without file name from URL
421 int aFileNameSize = Res.Length();
422 char* aDir = new char[aFileNameSize];
423 memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
424 for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
425 if (aDir[aCounter] == '/') {
426 aDir[aCounter+1] = 0;
430 CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
431 aDriver->LoadASCII(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M'):
432 aDriver->Load(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M');
434 RemoveAttribute( anSCO, "AttributeIOR" );
436 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
437 aFilesToRemove->length(1);
438 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
439 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
442 MESSAGE("Can't load component");
443 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
444 // throw HDFexception("Unable to load component");
449 multifile_hdf_dataset->CloseOnDisk();
450 multifile_hdf_dataset = 0;
451 ascii_hdf_dataset->CloseOnDisk();
452 ascii_hdf_dataset = 0;
453 hdf_sco_group->CloseOnDisk();
455 hdf_group->CloseOnDisk();
457 hdf_file->CloseOnDisk();
461 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
462 aFilesToRemove->length(1);
463 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
464 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
468 catch (HDFexception) {
469 MESSAGE("No persistent file Name");
472 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
473 aFilesToRemove->length(1);
474 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
475 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
478 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
483 Translate_persistentID_to_IOR (Lab,aDriver,_orb, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
484 } catch (SALOME::SALOME_Exception) {
485 MESSAGE("Can't translate PersRef to IOR");
486 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
487 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
488 // throw HDFexception("Unable to load component data");
490 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
492 MESSAGE("No persistent file Name");
496 //============================================================================
500 //============================================================================
501 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
503 MESSAGE ( "This function is not yet implemented");
506 //============================================================================
507 /*! Function : AddAttribute
510 //============================================================================
512 void SALOMEDS_StudyBuilder_i::AddAttribute(SALOMEDS::SObject_ptr anObject,
513 SALOMEDS::AttributeType aType,
514 const char * AttributeValue )
517 ASSERT(!CORBA::is_nil(anObject));
518 CORBA::String_var anobid = anObject->GetID();
519 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
521 TCollection_ExtendedString Value(strdup(AttributeValue));
523 Standard_GUID ID = SALOMEDS_SObject_i::TypeToAttributeID(aType);
525 if (ID == TDataStd_Name::GetID()) TDataStd_Name::Set (Lab,Value);
526 else if (ID == TDataStd_Comment::GetID()) TDataStd_Comment::Set (Lab,Value);
527 else if (ID == SALOMEDS_IORAttribute::GetID()) SALOMEDS_IORAttribute::Set (Lab,Value);
528 else if (ID == SALOMEDS_PersRefAttribute::GetID()) SALOMEDS_PersRefAttribute::Set(Lab,Value);
531 //============================================================================
532 /*! Function : FindOrCreateAttribute
533 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
536 //============================================================================
538 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
539 const char* aTypeOfAttribute)
542 ASSERT(!CORBA::is_nil(anObject));
543 CORBA::String_var anobid = anObject->GetID();
544 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
546 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
547 Handle(TDataStd_Real) anAttr;
548 if (!Lab.FindAttribute(TDataStd_Real::GetID(), anAttr)) {
549 anAttr = new TDataStd_Real;
550 Lab.AddAttribute(anAttr);
552 SALOMEDS_AttributeReal_i* aRealAttr = new SALOMEDS_AttributeReal_i(anAttr, _orb);
553 SALOMEDS::AttributeReal_var aRA = aRealAttr->AttributeReal::_this();
556 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
557 Handle(TDataStd_Integer) anAttr;
558 if (!Lab.FindAttribute(TDataStd_Integer::GetID(), anAttr)) {
559 anAttr = new TDataStd_Integer;
560 Lab.AddAttribute(anAttr);
562 SALOMEDS_AttributeInteger_i* aIntAttr = new SALOMEDS_AttributeInteger_i(anAttr, _orb);
563 SALOMEDS::AttributeInteger_var aIA = aIntAttr->AttributeInteger::_this();
566 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
567 Handle(SALOMEDS_SequenceOfRealAttribute) anAttr;
568 if (!Lab.FindAttribute(SALOMEDS_SequenceOfRealAttribute::GetID(), anAttr)) {
569 anAttr = new SALOMEDS_SequenceOfRealAttribute;
570 Lab.AddAttribute(anAttr);
572 SALOMEDS_AttributeSequenceOfReal_i* aSeqRealAttr = new SALOMEDS_AttributeSequenceOfReal_i(anAttr, _orb);
573 SALOMEDS::AttributeSequenceOfReal_var aSRA = aSeqRealAttr->AttributeSequenceOfReal::_this();
576 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
577 Handle(SALOMEDS_SequenceOfIntegerAttribute) anAttr;
578 if (!Lab.FindAttribute(SALOMEDS_SequenceOfIntegerAttribute::GetID(), anAttr)) {
579 anAttr = new SALOMEDS_SequenceOfIntegerAttribute;
580 Lab.AddAttribute(anAttr);
582 SALOMEDS_AttributeSequenceOfInteger_i* aSeqIntegerAttr = new SALOMEDS_AttributeSequenceOfInteger_i(anAttr, _orb);
583 SALOMEDS::AttributeSequenceOfInteger_var aSIA = aSeqIntegerAttr->AttributeSequenceOfInteger::_this();
586 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
587 Handle(TDataStd_Name) anAttr;
588 if (!Lab.FindAttribute(TDataStd_Name::GetID(), anAttr)) {
589 anAttr = new TDataStd_Name;
590 Lab.AddAttribute(anAttr);
592 SALOMEDS_AttributeName_i* aNameAttr = new SALOMEDS_AttributeName_i(anAttr, _orb);
593 SALOMEDS::AttributeName_var aSNA = aNameAttr->AttributeName::_this();
596 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
597 Handle(TDataStd_Comment) anAttr;
598 if (!Lab.FindAttribute(TDataStd_Comment::GetID(), anAttr)) {
599 anAttr = new TDataStd_Comment;
600 Lab.AddAttribute(anAttr);
602 SALOMEDS_AttributeComment_i* aCommentAttr = new SALOMEDS_AttributeComment_i(anAttr, _orb);
603 SALOMEDS::AttributeComment_var aCA = aCommentAttr->AttributeComment::_this();
606 else if (strcmp(aTypeOfAttribute, "AttributeExternalFileDef") == 0 ) {
607 Handle(SALOMEDS_ExternalFileDef) anAttr;
608 if (!Lab.FindAttribute(SALOMEDS_ExternalFileDef::GetID(), anAttr)) {
609 anAttr = new SALOMEDS_ExternalFileDef;
610 Lab.AddAttribute(anAttr);
612 SALOMEDS_AttributeExternalFileDef_i* anExternalFileDefAttr = new SALOMEDS_AttributeExternalFileDef_i(anAttr, _orb);
613 SALOMEDS::AttributeExternalFileDef_var aCA = anExternalFileDefAttr->AttributeExternalFileDef::_this();
616 else if (strcmp(aTypeOfAttribute, "AttributeFileType") == 0 ) {
617 Handle(SALOMEDS_FileType) anAttr;
618 if (!Lab.FindAttribute(SALOMEDS_FileType::GetID(), anAttr)) {
619 anAttr = new SALOMEDS_FileType;
620 Lab.AddAttribute(anAttr);
622 SALOMEDS_AttributeFileType_i* anFileTypeAttr = new SALOMEDS_AttributeFileType_i(anAttr, _orb);
623 SALOMEDS::AttributeFileType_var aCA = anFileTypeAttr->AttributeFileType::_this();
626 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
627 Handle(SALOMEDS_IORAttribute) anAttr;
628 if (!Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) {
629 anAttr = new SALOMEDS_IORAttribute;
630 Lab.AddAttribute(anAttr);
632 SALOMEDS_AttributeIOR_i* aIORAttr = new SALOMEDS_AttributeIOR_i(anAttr, _orb);
633 SALOMEDS::AttributeIOR_var aIA = aIORAttr->AttributeIOR::_this();
636 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
637 Handle(SALOMEDS_PersRefAttribute) anAttr;
638 if (!Lab.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), anAttr)) {
639 anAttr = new SALOMEDS_PersRefAttribute;
640 Lab.AddAttribute(anAttr);
642 SALOMEDS_AttributePersistentRef_i* aPerRefAttr = new SALOMEDS_AttributePersistentRef_i(anAttr, _orb);
643 SALOMEDS::AttributePersistentRef_var aPRA = aPerRefAttr->AttributePersistentRef::_this();
646 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
647 Handle(SALOMEDS_DrawableAttribute) anAttr;
648 if (!Lab.FindAttribute(SALOMEDS_DrawableAttribute::GetID(), anAttr)) {
649 anAttr = new SALOMEDS_DrawableAttribute;
650 Lab.AddAttribute(anAttr);
652 SALOMEDS_AttributeDrawable_i* aDrawableAttr = new SALOMEDS_AttributeDrawable_i(anAttr, _orb);
653 SALOMEDS::AttributeDrawable_var aDrawA = aDrawableAttr->AttributeDrawable::_this();
654 return aDrawA._retn();
656 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
657 Handle(SALOMEDS_SelectableAttribute) anAttr;
658 if (!Lab.FindAttribute(SALOMEDS_SelectableAttribute::GetID(), anAttr)) {
659 anAttr = new SALOMEDS_SelectableAttribute;
660 Lab.AddAttribute(anAttr);
662 SALOMEDS_AttributeSelectable_i* aSelectableAttr = new SALOMEDS_AttributeSelectable_i(anAttr, _orb);
663 SALOMEDS::AttributeSelectable_var aSelA = aSelectableAttr->AttributeSelectable::_this();
664 return aSelA._retn();
666 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
667 Handle(SALOMEDS_ExpandableAttribute) anAttr;
668 if (!Lab.FindAttribute(SALOMEDS_ExpandableAttribute::GetID(), anAttr)) {
669 anAttr = new SALOMEDS_ExpandableAttribute;
670 Lab.AddAttribute(anAttr);
672 SALOMEDS_AttributeExpandable_i* aExpandableAttr = new SALOMEDS_AttributeExpandable_i(anAttr, _orb);
673 SALOMEDS::AttributeExpandable_var aExpA = aExpandableAttr->AttributeExpandable::_this();
674 return aExpA._retn();
676 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
677 Handle(SALOMEDS_OpenedAttribute) anAttr;
678 if (!Lab.FindAttribute(SALOMEDS_OpenedAttribute::GetID(), anAttr)) {
679 anAttr = new SALOMEDS_OpenedAttribute;
680 Lab.AddAttribute(anAttr);
682 SALOMEDS_AttributeOpened_i* aOpenedAttr = new SALOMEDS_AttributeOpened_i(anAttr, _orb);
683 SALOMEDS::AttributeOpened_var aOpenA = aOpenedAttr->AttributeOpened::_this();
684 return aOpenA._retn();
686 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
687 Handle(SALOMEDS_TextColorAttribute) anAttr;
688 if (!Lab.FindAttribute(SALOMEDS_TextColorAttribute::GetID(), anAttr)) {
689 anAttr = new SALOMEDS_TextColorAttribute;
690 Lab.AddAttribute(anAttr);
692 SALOMEDS_AttributeTextColor_i* aTextColorAttr = new SALOMEDS_AttributeTextColor_i(anAttr, _orb);
693 SALOMEDS::AttributeTextColor_var aTCA = aTextColorAttr->AttributeTextColor::_this();
696 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
697 Handle(SALOMEDS_TextHighlightColorAttribute) anAttr;
698 if (!Lab.FindAttribute(SALOMEDS_TextHighlightColorAttribute::GetID(), anAttr)) {
699 anAttr = new SALOMEDS_TextHighlightColorAttribute;
700 Lab.AddAttribute(anAttr);
702 SALOMEDS_AttributeTextHighlightColor_i* aTextHighlightColorAttr = new SALOMEDS_AttributeTextHighlightColor_i(anAttr, _orb);
703 SALOMEDS::AttributeTextHighlightColor_var aTHCA = aTextHighlightColorAttr->AttributeTextHighlightColor::_this();
704 return aTHCA._retn();
706 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
707 Handle(SALOMEDS_PixMapAttribute) anAttr;
708 if (!Lab.FindAttribute(SALOMEDS_PixMapAttribute::GetID(), anAttr)) {
709 anAttr = new SALOMEDS_PixMapAttribute;
710 Lab.AddAttribute(anAttr);
712 SALOMEDS_AttributePixMap_i* aPixMapAttr = new SALOMEDS_AttributePixMap_i(anAttr, _orb);
713 SALOMEDS::AttributePixMap_var aPMA = aPixMapAttr->AttributePixMap::_this();
716 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
717 Standard_GUID aTreeNodeGUID;
718 if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0)
719 aTreeNodeGUID = TDataStd_TreeNode::GetDefaultTreeID();
721 char* aGUIDString = new char[40];
722 sprintf(aGUIDString, &(aTypeOfAttribute[21]));
723 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
726 Handle(TDataStd_TreeNode) anAttr;
727 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr))
728 anAttr = TDataStd_TreeNode::Set(Lab, aTreeNodeGUID);
729 SALOMEDS_AttributeTreeNode_i* aTreeNodeAttr = new SALOMEDS_AttributeTreeNode_i(anAttr, _orb);
730 SALOMEDS::AttributeTreeNode_var aTNA = aTreeNodeAttr->AttributeTreeNode::_this();
733 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
734 Handle(TDataStd_UAttribute) anAttr;
735 if (!Lab.FindAttribute(SALOMEDS_AttributeUserID_i::DefaultID(), anAttr))
736 anAttr = TDataStd_UAttribute::Set(Lab, SALOMEDS_AttributeUserID_i::DefaultID());
737 SALOMEDS_AttributeUserID_i* aUAttr = new SALOMEDS_AttributeUserID_i(anAttr, _orb);
738 SALOMEDS::AttributeUserID_var aUA = aUAttr->AttributeUserID::_this();
741 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
742 Handle(SALOMEDS_LocalIDAttribute) anAttr;
743 if (!Lab.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttr)) {
744 anAttr = new SALOMEDS_LocalIDAttribute;
745 Lab.AddAttribute(anAttr);
747 SALOMEDS_AttributeLocalID_i* aLIDAttr = new SALOMEDS_AttributeLocalID_i(anAttr, _orb);
748 SALOMEDS::AttributeLocalID_var aLIDA = aLIDAttr->AttributeLocalID::_this();
749 return aLIDA._retn();
751 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
752 Handle(SALOMEDS_TargetAttribute) anAttr;
753 if (!Lab.FindAttribute(SALOMEDS_TargetAttribute::GetID(), anAttr)) {
754 anAttr = new SALOMEDS_TargetAttribute;
755 Lab.AddAttribute(anAttr);
757 SALOMEDS_AttributeTarget_i* aLIDAttr = new SALOMEDS_AttributeTarget_i(anAttr, _orb);
758 SALOMEDS::AttributeTarget_var aLIDA = aLIDAttr->AttributeTarget::_this();
759 return aLIDA._retn();
761 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
762 Handle(SALOMEDS_TableOfIntegerAttribute) anAttr;
763 if (!Lab.FindAttribute(SALOMEDS_TableOfIntegerAttribute::GetID(), anAttr)) {
764 anAttr = new SALOMEDS_TableOfIntegerAttribute;
765 Lab.AddAttribute(anAttr);
767 SALOMEDS_AttributeTableOfInteger_i* aTabIntegerAttr = new SALOMEDS_AttributeTableOfInteger_i(anAttr, _orb);
768 SALOMEDS::AttributeTableOfInteger_var aTIA = aTabIntegerAttr->AttributeTableOfInteger::_this();
771 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
772 Handle(SALOMEDS_TableOfRealAttribute) anAttr;
773 if (!Lab.FindAttribute(SALOMEDS_TableOfRealAttribute::GetID(), anAttr)) {
774 anAttr = new SALOMEDS_TableOfRealAttribute;
775 Lab.AddAttribute(anAttr);
777 SALOMEDS_AttributeTableOfReal_i* aTabRealAttr = new SALOMEDS_AttributeTableOfReal_i(anAttr, _orb);
778 SALOMEDS::AttributeTableOfReal_var aTRA = aTabRealAttr->AttributeTableOfReal::_this();
781 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
782 Handle(SALOMEDS_TableOfStringAttribute) anAttr;
783 if (!Lab.FindAttribute(SALOMEDS_TableOfStringAttribute::GetID(), anAttr)) {
784 anAttr = new SALOMEDS_TableOfStringAttribute;
785 Lab.AddAttribute(anAttr);
787 SALOMEDS_AttributeTableOfString_i* aTabStringAttr = new SALOMEDS_AttributeTableOfString_i(anAttr, _orb);
788 SALOMEDS::AttributeTableOfString_var aTRA = aTabStringAttr->AttributeTableOfString::_this();
791 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
792 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
793 if (!Lab.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
794 anAttr = new SALOMEDS_StudyPropertiesAttribute;
795 Lab.AddAttribute(anAttr);
796 anAttr->SetModified(0);
798 SALOMEDS_AttributeStudyProperties_i* aStPropAttr = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
799 SALOMEDS::AttributeStudyProperties_var aSPA = aStPropAttr->AttributeStudyProperties::_this();
802 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
803 Handle(SALOMEDS_PythonObjectAttribute) anAttr;
804 if (!Lab.FindAttribute(SALOMEDS_PythonObjectAttribute::GetID(), anAttr)) {
805 anAttr = new SALOMEDS_PythonObjectAttribute;
806 Lab.AddAttribute(anAttr);
808 SALOMEDS_AttributePythonObject_i* aPObjAttr = new SALOMEDS_AttributePythonObject_i(anAttr, _orb);
809 SALOMEDS::AttributePythonObject_var aPOA = aPObjAttr->AttributePythonObject::_this();
814 //============================================================================
815 /*! Function : FindAttribute
816 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
818 //============================================================================
820 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
821 SALOMEDS::GenericAttribute_out anAttribute,
822 const char* aTypeOfAttribute)
825 ASSERT(!CORBA::is_nil(anObject));
826 CORBA::String_var anobid = anObject->GetID();
827 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
828 Handle(TDF_Attribute) anAttr;
829 Standard_Boolean found = Lab.FindAttribute(SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute), anAttr);
831 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
832 SALOMEDS_AttributeReal_i* Attr= new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
833 anAttribute = Attr->AttributeReal::_this();
834 return Standard_True;
836 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
837 SALOMEDS_AttributeInteger_i* Attr= new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
838 anAttribute = Attr->AttributeInteger::_this();
839 return Standard_True;
841 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
842 SALOMEDS_AttributeSequenceOfReal_i* Attr= new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
843 anAttribute = Attr->AttributeSequenceOfReal::_this();
844 return Standard_True;
846 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
847 SALOMEDS_AttributeSequenceOfInteger_i* Attr= new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
848 anAttribute = Attr->AttributeSequenceOfInteger::_this();
849 return Standard_True;
851 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
852 SALOMEDS_AttributeName_i* Attr= new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
853 anAttribute = Attr->AttributeName::_this();
854 return Standard_True;
856 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
857 SALOMEDS_AttributeComment_i* Attr= new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
858 anAttribute = Attr->AttributeComment::_this();
859 return Standard_True;
861 else if (strcmp(aTypeOfAttribute, "AttributeExternalFileDef") == 0 ) {
862 SALOMEDS_AttributeExternalFileDef_i* Attr= new SALOMEDS_AttributeExternalFileDef_i(Handle(SALOMEDS_ExternalFileDef)::DownCast(anAttr), _orb);
863 anAttribute = Attr->AttributeExternalFileDef::_this();
864 return Standard_True;
866 else if (strcmp(aTypeOfAttribute, "AttributeFileType") == 0 ) {
867 SALOMEDS_AttributeFileType_i* Attr= new SALOMEDS_AttributeFileType_i(Handle(SALOMEDS_FileType)::DownCast(anAttr), _orb);
868 anAttribute = Attr->AttributeFileType::_this();
869 return Standard_True;
871 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
872 SALOMEDS_AttributeIOR_i* Attr= new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
873 anAttribute = Attr->AttributeIOR::_this();
874 return Standard_True;
876 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
877 SALOMEDS_AttributePersistentRef_i* Attr= new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
878 anAttribute = Attr->AttributePersistentRef::_this();
879 return Standard_True;
881 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
882 SALOMEDS_AttributeDrawable_i* Attr= new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
883 anAttribute = Attr->AttributeDrawable::_this();
884 return Standard_True;
886 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
887 SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
888 anAttribute = Attr->AttributeSelectable::_this();
889 return Standard_True;
891 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
892 SALOMEDS_AttributeExpandable_i* Attr= new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
893 anAttribute = Attr->AttributeExpandable::_this();
894 return Standard_True;
896 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
897 SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
898 anAttribute = Attr->AttributeOpened::_this();
899 return Standard_True;
901 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
902 SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
903 anAttribute = Attr->AttributeTextColor::_this();
904 return Standard_True;
906 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
907 SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
908 anAttribute = Attr->AttributeTextHighlightColor::_this();
909 return Standard_True;
911 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
912 SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
913 anAttribute = Attr->AttributePixMap::_this();
914 return Standard_True;
916 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
917 SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
918 anAttribute = Attr->AttributeTreeNode::_this();
919 return Standard_True;
921 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
922 SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
923 anAttribute = Attr->AttributeUserID::_this();
924 return Standard_True;
926 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
927 SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
928 anAttribute = Attr->AttributeLocalID::_this();
929 return Standard_True;
931 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
932 SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
933 anAttribute = Attr->AttributeTarget::_this();
934 return Standard_True;
936 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
937 SALOMEDS_AttributeTableOfInteger_i* Attr= new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
938 anAttribute = Attr->AttributeTableOfInteger::_this();
939 return Standard_True;
941 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
942 SALOMEDS_AttributeTableOfReal_i* Attr= new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
943 anAttribute = Attr->AttributeTableOfReal::_this();
944 return Standard_True;
946 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
947 SALOMEDS_AttributeTableOfString_i* Attr= new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
948 anAttribute = Attr->AttributeTableOfString::_this();
949 return Standard_True;
951 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
952 SALOMEDS_AttributeStudyProperties_i* Attr= new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
953 anAttribute = Attr->AttributeStudyProperties::_this();
954 return Standard_True;
956 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
957 SALOMEDS_AttributePythonObject_i* Attr= new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
958 anAttribute = Attr->AttributePythonObject::_this();
959 return Standard_True;
961 } else return Standard_False;
964 //============================================================================
965 /*! Function : RemoveAttribute
966 * Purpose : Remove attribute of given type assigned SObject
968 //============================================================================
970 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
971 const char* aTypeOfAttribute)
974 ASSERT(!CORBA::is_nil(anObject));
975 CORBA::String_var anobid = anObject->GetID();
976 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
977 Lab.ForgetAttribute (SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute));
980 //============================================================================
981 /*! Function : Addreference
984 //============================================================================
986 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
987 SALOMEDS::SObject_ptr theReferencedObject)
990 ASSERT(!CORBA::is_nil(me));
991 CORBA::String_var meid = me->GetID();
992 TDF_Tool::Label(_doc->GetData(),strdup(meid),Lab);
994 ASSERT(!CORBA::is_nil(theReferencedObject));
995 CORBA::String_var roid = theReferencedObject->GetID();
996 TDF_Tool::Label(_doc->GetData(),strdup(roid),RefLab);
997 TDF_Reference::Set(Lab,RefLab);
999 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
1001 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(me);
1005 //============================================================================
1006 /*! Function : AddDirectory
1007 * Purpose : adds a new directory with a path = thePath
1009 //============================================================================
1010 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
1012 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
1014 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
1015 TDF_ChildIterator anIterator(_doc->Main());
1016 Handle(TDataStd_Name) aName;
1018 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb);
1019 SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(so_servant->_this());
1020 SALOMEDS::Study_var aStudy = anObject->GetStudy();
1023 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
1027 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
1029 if(aPath.Value(1) != '/') { //Relative path
1031 aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
1034 TCollection_AsciiString aToken = aPath.Token("/", 1);
1035 if(aToken.Length() == 0) aFatherPath = "/";
1038 while(aToken.Length() != 0) {
1039 if(aPath.Token("/", i+1).Length() > 0) {
1041 aFatherPath += aToken;
1043 aToken = aPath.Token("/", ++i);
1046 anObject = SALOMEDS::SObject::_nil();
1048 anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
1051 if(anObject->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1053 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
1054 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
1055 if(aLabel.IsNull()) {
1056 MESSAGE("### NULL label");
1057 throw SALOMEDS::Study::StudyInvalidComponent();
1060 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
1062 //Set LocalID attribute to identify the directory object
1063 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID");
1064 SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr);
1065 if(aPersRef->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1067 aPersRef->SetValue(DIRECTORYID);
1071 //============================================================================
1072 /*! Function : SetGUID
1075 //============================================================================
1076 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1079 ASSERT(!CORBA::is_nil(anObject));
1080 CORBA::String_var anEntry = anObject->GetID();
1081 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1082 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
1085 //============================================================================
1086 /*! Function : IsGUID
1089 //============================================================================
1090 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1093 ASSERT(!CORBA::is_nil(anObject));
1094 CORBA::String_var anEntry = anObject->GetID();
1095 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1096 return aLabel.IsAttribute((char*)theGUID);
1100 //============================================================================
1101 /*! Function : NewCommand
1104 //============================================================================
1105 void SALOMEDS_StudyBuilder_i::NewCommand()
1107 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
1108 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1109 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1110 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1111 _doc->Main().AddAttribute(anAttr);
1113 anAttr->IsLockChanged(true);
1118 //============================================================================
1119 /*! Function : CommitCommand
1122 //============================================================================
1123 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
1125 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1126 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1127 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1128 _doc->Main().AddAttribute(anAttr);
1130 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
1131 INFOS("Locked document modification !!!");
1133 throw SALOMEDS::StudyBuilder::LockProtection();
1135 int aModif = anAttr->GetModified();
1136 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
1137 anAttr->SetModified(aModif+1);
1138 _doc->CommitCommand();
1142 //============================================================================
1143 /*! Function : HasOpenCommand
1146 //============================================================================
1147 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
1149 _doc->HasOpenCommand();
1152 //============================================================================
1153 /*! Function : AbortCommand
1156 //============================================================================
1157 void SALOMEDS_StudyBuilder_i::AbortCommand()
1159 _doc->AbortCommand();
1162 //============================================================================
1166 //============================================================================
1167 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
1169 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1170 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1171 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1172 _doc->Main().AddAttribute(anAttr);
1174 if (anAttr->IsLocked()) {
1175 INFOS("Locked document modification !!!");
1176 throw SALOMEDS::StudyBuilder::LockProtection();
1179 anAttr->SetModified(anAttr->GetModified()-1);
1183 //============================================================================
1187 //============================================================================
1188 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
1190 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1191 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1192 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1193 _doc->Main().AddAttribute(anAttr);
1196 if (anAttr->IsLocked()) {
1197 INFOS("Locked document modification !!!");
1198 throw SALOMEDS::StudyBuilder::LockProtection();
1201 anAttr->SetModified(anAttr->GetModified()+1);
1205 //============================================================================
1206 /*! Function : GetAvailableUndos
1209 //============================================================================
1210 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
1212 return _doc->GetAvailableUndos();
1215 //============================================================================
1216 /*! Function : GetAvailableRedos
1219 //============================================================================
1220 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
1222 return _doc->GetAvailableRedos();
1226 //============================================================================
1227 /*! Function : UndoLimit
1230 //============================================================================
1231 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
1233 return _doc->GetUndoLimit();
1236 //============================================================================
1237 /*! Function : UndoLimit
1240 //============================================================================
1241 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
1243 _doc->SetUndoLimit (n);
1246 //============================================================================
1247 /*! Function : SetOnAddSObject
1250 //============================================================================
1251 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
1253 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnAdd))?NULL:_callbackOnAdd._retn();
1254 _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
1258 //============================================================================
1259 /*! Function : SetOnNewSObject
1262 //============================================================================
1263 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
1265 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnRemove))?NULL:_callbackOnRemove._retn();
1266 _callbackOnRemove = SALOMEDS::Callback::_duplicate(theCallback);