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_AttributeName_i.hxx"
54 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
55 #include "SALOMEDS_AttributeSequenceOfReal_i.hxx"
56 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
57 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
58 #include "SALOMEDS_AttributeTableOfString_i.hxx"
59 #include "SALOMEDS_AttributeInteger_i.hxx"
60 #include "SALOMEDS_AttributeReal_i.hxx"
61 #include "SALOMEDS_AttributeDrawable_i.hxx"
62 #include "SALOMEDS_AttributeSelectable_i.hxx"
63 #include "SALOMEDS_AttributeExpandable_i.hxx"
64 #include "SALOMEDS_AttributeOpened_i.hxx"
65 #include "SALOMEDS_AttributeTextColor_i.hxx"
66 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
67 #include "SALOMEDS_AttributePixMap_i.hxx"
68 #include "SALOMEDS_AttributeTreeNode_i.hxx"
69 #include "SALOMEDS_AttributeTarget_i.hxx"
70 #include "SALOMEDS_AttributeLocalID_i.hxx"
71 #include "SALOMEDS_AttributeUserID_i.hxx"
72 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
73 #include "SALOMEDS_AttributePythonObject_i.hxx"
74 #include "SALOMEDS_Tool.hxx"
75 #include "Utils_CorbaException.hxx"
80 #define USE_CASE_LABEL_TAG 2
81 #define DIRECTORYID 16661
82 #define FILELOCALID 26662
84 //============================================================================
85 /*! Function : constructor
88 //============================================================================
89 SALOMEDS_StudyBuilder_i::SALOMEDS_StudyBuilder_i(const Handle(TDocStd_Document) doc,
90 CORBA::ORB_ptr orb) : _doc(doc)
92 _orb = CORBA::ORB::_duplicate(orb);
95 //============================================================================
96 /*! Function : destructor
99 //============================================================================
100 SALOMEDS_StudyBuilder_i::~SALOMEDS_StudyBuilder_i()
104 //============================================================================
105 /*! Function : NewComponent
106 * Purpose : Create a new component (Scomponent)
108 //============================================================================
109 SALOMEDS::SComponent_ptr
110 SALOMEDS_StudyBuilder_i::NewComponent(const char* DataType)
112 //Always create component under main label.
113 TDF_Label L = _doc->Main();
115 // YFR DEBUG : 13/02/2002 TDF_Label NL = L.NewChild();
117 Standard_Integer imax = 0;
118 for (TDF_ChildIterator it(L); it.More(); it.Next()) {
119 if (it.Value().Tag() > imax)
120 imax = it.Value().Tag();
123 TDF_Label NL = L.FindChild(imax);
125 // TDataStd_Comment::Set(NL,Standard_CString(DataType));
126 TDataStd_Comment::Set(NL,Standard_CString(strdup(DataType)));
128 SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (NL,_orb);
129 SALOMEDS::SComponent_var so;
130 so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this());
132 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
137 //============================================================================
138 /*! Function : DefineComponentInstance
139 * Purpose : Add IOR attribute of a Scomponent
141 //============================================================================
142 void SALOMEDS_StudyBuilder_i::DefineComponentInstance(SALOMEDS::SComponent_ptr aComponent,
143 CORBA::Object_ptr IOR)
147 ASSERT(!CORBA::is_nil(aComponent));
148 CORBA::String_var compid = aComponent->GetID();
149 TDF_Tool::Label(_doc->GetData(),strdup(compid),Lab);
152 ASSERT(!CORBA::is_nil(IOR));
153 CORBA::String_var iorstr = _orb->object_to_string(IOR);
154 SALOMEDS_IORAttribute::Set(Lab,strdup(iorstr),_orb);
158 //============================================================================
159 /*! Function : RemoveComponent
160 * Purpose : Delete a Scomponent
162 //============================================================================
164 SALOMEDS_StudyBuilder_i::RemoveComponent(SALOMEDS::SComponent_ptr aComponent)
166 ASSERT(!CORBA::is_nil(aComponent));
167 RemoveObject(aComponent);
170 //============================================================================
171 /*! Function : NewObject
172 * Purpose : Create a new SObject
174 //============================================================================
175 SALOMEDS::SObject_ptr
176 SALOMEDS_StudyBuilder_i::NewObject(SALOMEDS::SObject_ptr theFatherObject)
178 TCollection_AsciiString anEntry;
180 //Find label of father
183 ASSERT(!CORBA::is_nil(theFatherObject));
184 CORBA::String_var fatherid = theFatherObject->GetID();
185 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
188 //YFR DEBUG : 13/02/2002 TDF_Label NewLab = Lab.NewChild();
189 Standard_Integer imax = 0;
190 for (TDF_ChildIterator it(Lab); it.More(); it.Next()) {
191 if (it.Value().Tag() > imax)
192 imax = it.Value().Tag();
195 TDF_Label NewLab = Lab.FindChild(imax);
197 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
198 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
200 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
205 //============================================================================
206 /*! Function : NewObjectToTag
209 //============================================================================
210 SALOMEDS::SObject_ptr
211 SALOMEDS_StudyBuilder_i::NewObjectToTag(SALOMEDS::SObject_ptr theFatherObject,
214 //Find label of father
217 ASSERT(!CORBA::is_nil(theFatherObject));
218 CORBA::String_var fatherid = theFatherObject->GetID();
219 TDF_Tool::Label(_doc->GetData(),strdup(fatherid),Lab);
220 //Create or find label
221 TDF_Label NewLab = Lab.FindChild(atag,1);
223 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (NewLab,_orb);
224 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
226 if(!CORBA::is_nil(_callbackOnAdd)) _callbackOnAdd->OnAddSObject(so);
231 //============================================================================
232 /*! Function : RemoveObject
235 //============================================================================
236 void SALOMEDS_StudyBuilder_i::RemoveObject(SALOMEDS::SObject_ptr anObject)
238 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
241 ASSERT(!CORBA::is_nil(anObject));
242 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
244 Handle(TDF_Reference) aReference;
245 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
246 Handle(SALOMEDS_TargetAttribute) aTarget;
247 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
248 aTarget->Remove(Lab);
251 Lab.ForgetAllAttributes();
254 //============================================================================
255 /*! Function : RemoveObjectWithChildren
258 //============================================================================
259 void SALOMEDS_StudyBuilder_i::RemoveObjectWithChildren(SALOMEDS::SObject_ptr anObject)
261 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(anObject);
264 ASSERT(!CORBA::is_nil(anObject));
265 TDF_Tool::Label(_doc->GetData(),anObject->GetID(),Lab);
267 Handle(TDF_Reference) aReference;
268 if (Lab.FindAttribute(TDF_Reference::GetID(), aReference)) {
269 Handle(SALOMEDS_TargetAttribute) aTarget;
270 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
271 aTarget->Remove(Lab);
274 TDF_ChildIterator it(Lab);
275 for(;it.More();it.Next()) {
276 TDF_Label aLabel = it.Value();
277 if (aLabel.FindAttribute(TDF_Reference::GetID(), aReference)) {
278 Handle(SALOMEDS_TargetAttribute) aTarget;
279 if (aReference->Get().FindAttribute(SALOMEDS_TargetAttribute::GetID(),aTarget))
280 aTarget->Remove(aLabel);
284 Lab.ForgetAllAttributes(Standard_True);
287 //============================================================================
288 /*! Function : Translate_persistentID_to_IOR
291 //============================================================================
292 static void Translate_persistentID_to_IOR(TDF_Label Lab,
293 SALOMEDS::Driver_ptr driver,
295 CORBA::Boolean isMultiFile,
296 CORBA::Boolean isASCII)
298 TDF_ChildIterator itchild (Lab);
300 for (; itchild.More(); itchild.Next()) {
301 TDF_Label current = itchild.Value();
302 Handle(TDF_Attribute) Att;
303 if (current.FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
305 Handle(SALOMEDS_LocalIDAttribute) anID;
306 if (current.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anID))
307 if (anID->Get() == FILELOCALID) continue; //SRN: This attribute store a file name, skip it
309 TCollection_ExtendedString res;
310 res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
311 TCollection_AsciiString ch(res);
313 CORBA::String_var persistent_string = CORBA::string_dup(ch.ToCString());
314 ASSERT(! CORBA::is_nil(driver));
315 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (current,orb);
316 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
318 CORBA::String_var ior_string = driver->LocalPersistentIDToIOR(so, persistent_string, isMultiFile, isASCII);
320 TCollection_ExtendedString value(strdup(ior_string ));
321 SALOMEDS_IORAttribute::Set (current,value,orb);
323 //TCollection_AsciiString anEntry;TDF_Tool::Entry (current,anEntry); //SRN: No use here
324 //delete persistent_string;
327 Translate_persistentID_to_IOR (current,driver,orb,isMultiFile, isASCII);
331 //============================================================================
332 /*! Function : LoadWith
335 //============================================================================
337 //============================================================================
338 void SALOMEDS_StudyBuilder_i::LoadWith(SALOMEDS::SComponent_ptr anSCO,
339 SALOMEDS::Driver_ptr aDriver) throw(SALOME::SALOME_Exception)
342 ASSERT(!CORBA::is_nil(anSCO));
343 CORBA::String_var scoid = anSCO->GetID();
344 TDF_Tool::Label(_doc->GetData(),strdup(scoid),Lab);
345 Handle(TDF_Attribute) Att;
347 //Find the current Url of the study
348 if (_doc->Main().FindAttribute(SALOMEDS_PersRefAttribute::GetID(),Att)) {
349 int aLocked = anSCO->GetStudy()->GetProperties()->IsLocked();
350 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
352 TCollection_ExtendedString Res = Handle(TDataStd_Comment)::DownCast(Att)->Get();
354 Handle(TDataStd_Comment) type;
355 TCollection_ExtendedString DataType;
356 if (Lab.FindAttribute(TDataStd_Comment::GetID(),type))
357 DataType = type->Get();
359 MESSAGE("No Data Type");
361 // associate the driver to the SComponent
362 ASSERT(!CORBA::is_nil(aDriver));
363 // mpv 06.03.2003: SAL1927 - if component data if already loaded, it is not necessary to do it again
364 if (Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), Att)) {
365 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
368 DefineComponentInstance (anSCO, aDriver);
370 TCollection_AsciiString aHDFPath(Res);
373 bool isASCII = false;
374 if (HDFascii::isASCII(aHDFPath.ToCString())) {
376 char* aResultPath = HDFascii::ConvertFromASCIIToHDF(aHDFPath.ToCString());
377 aHDFUrl = new char[strlen(aResultPath) + 19];
378 sprintf(aHDFUrl, "%shdf_from_ascii.hdf", aResultPath);
381 aHDFUrl = strdup(aHDFPath.ToCString());
384 //Open the Study HDF file
385 HDFfile *hdf_file = new HDFfile(aHDFUrl);
387 char aMultifileState[2];
388 char ASCIIfileState[2];
390 CORBA::String_var scoid = anSCO->GetID();
391 hdf_file->OpenOnDisk(HDF_RDONLY);
392 HDFgroup *hdf_group = new HDFgroup("DATACOMPONENT",hdf_file);
393 hdf_group->OpenOnDisk();
394 HDFgroup *hdf_sco_group = new HDFgroup(scoid, hdf_group);
395 hdf_sco_group->OpenOnDisk();
397 SALOMEDS::TMPFile_var aStreamFile;
398 if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
399 HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
400 hdf_dataset->OpenOnDisk();
401 int aStreamSize = hdf_dataset->GetSize();
402 unsigned char* aBuffer = new unsigned char[aStreamSize];
403 if(aBuffer == NULL) throw HDFexception("Unable to open dataset FILE_STREAM");
404 hdf_dataset->ReadFromDisk(aBuffer);
405 aStreamFile = new SALOMEDS::TMPFile(aStreamSize, aStreamSize, aBuffer, 1);
406 hdf_dataset->CloseOnDisk();
408 } else aStreamFile = new SALOMEDS::TMPFile(0);
410 HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
411 multifile_hdf_dataset->OpenOnDisk();
412 multifile_hdf_dataset->ReadFromDisk(aMultifileState);
414 HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
415 ascii_hdf_dataset->OpenOnDisk();
416 ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
418 // set path without file name from URL
419 int aFileNameSize = Res.Length();
420 char* aDir = new char[aFileNameSize];
421 memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
422 for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
423 if (aDir[aCounter] == '/') {
424 aDir[aCounter+1] = 0;
428 CORBA::Boolean aResult = (ASCIIfileState[0]=='A')?
429 aDriver->LoadASCII(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M'):
430 aDriver->Load(anSCO, aStreamFile.in(), aDir, aMultifileState[0]=='M');
432 RemoveAttribute( anSCO, "AttributeIOR" );
434 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
435 aFilesToRemove->length(1);
436 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
437 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
440 MESSAGE("Can't load component");
441 THROW_SALOME_CORBA_EXCEPTION("Unable to load component data",SALOME::BAD_PARAM);
442 // throw HDFexception("Unable to load component");
447 multifile_hdf_dataset->CloseOnDisk();
448 multifile_hdf_dataset = 0;
449 ascii_hdf_dataset->CloseOnDisk();
450 ascii_hdf_dataset = 0;
451 hdf_sco_group->CloseOnDisk();
453 hdf_group->CloseOnDisk();
455 hdf_file->CloseOnDisk();
459 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
460 aFilesToRemove->length(1);
461 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
462 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
466 catch (HDFexception) {
467 MESSAGE("No persistent file Name");
470 SALOMEDS::ListOfFileNames_var aFilesToRemove = new SALOMEDS::ListOfFileNames;
471 aFilesToRemove->length(1);
472 aFilesToRemove[0] = strdup(&(aHDFUrl[strlen(SALOMEDS_Tool::GetDirFromPath(aHDFUrl))]));
473 SALOMEDS_Tool::RemoveTemporaryFiles(SALOMEDS_Tool::GetDirFromPath(aHDFUrl), aFilesToRemove, true);
476 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
481 Translate_persistentID_to_IOR (Lab,aDriver,_orb, aMultifileState[0]=='M', ASCIIfileState[0] == 'A');
482 } catch (SALOME::SALOME_Exception) {
483 MESSAGE("Can't translate PersRef to IOR");
484 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
485 THROW_SALOME_CORBA_EXCEPTION("Unable to convert component persistent data to the transient",SALOME::BAD_PARAM);
486 // throw HDFexception("Unable to load component data");
488 if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(true);
490 MESSAGE("No persistent file Name");
494 //============================================================================
498 //============================================================================
499 void SALOMEDS_StudyBuilder_i::Load(SALOMEDS::SObject_ptr sco)
501 MESSAGE ( "This function is not yet implemented");
504 //============================================================================
505 /*! Function : AddAttribute
508 //============================================================================
510 void SALOMEDS_StudyBuilder_i::AddAttribute(SALOMEDS::SObject_ptr anObject,
511 SALOMEDS::AttributeType aType,
512 const char * AttributeValue )
515 ASSERT(!CORBA::is_nil(anObject));
516 CORBA::String_var anobid = anObject->GetID();
517 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
519 TCollection_ExtendedString Value(strdup(AttributeValue));
521 Standard_GUID ID = SALOMEDS_SObject_i::TypeToAttributeID(aType);
523 if (ID == TDataStd_Name::GetID()) TDataStd_Name::Set (Lab,Value);
524 else if (ID == TDataStd_Comment::GetID()) TDataStd_Comment::Set (Lab,Value);
525 else if (ID == SALOMEDS_IORAttribute::GetID()) SALOMEDS_IORAttribute::Set (Lab,Value);
526 else if (ID == SALOMEDS_PersRefAttribute::GetID()) SALOMEDS_PersRefAttribute::Set(Lab,Value);
529 //============================================================================
530 /*! Function : FindOrCreateAttribute
531 * Purpose : Add attribute of given type to SObject, if there is attribute of such type, returns
534 //============================================================================
536 SALOMEDS::GenericAttribute_ptr SALOMEDS_StudyBuilder_i::FindOrCreateAttribute(SALOMEDS::SObject_ptr anObject,
537 const char* aTypeOfAttribute)
540 ASSERT(!CORBA::is_nil(anObject));
541 CORBA::String_var anobid = anObject->GetID();
542 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
544 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
545 Handle(TDataStd_Real) anAttr;
546 if (!Lab.FindAttribute(TDataStd_Real::GetID(), anAttr)) {
547 anAttr = new TDataStd_Real;
548 Lab.AddAttribute(anAttr);
550 SALOMEDS_AttributeReal_i* aRealAttr = new SALOMEDS_AttributeReal_i(anAttr, _orb);
551 SALOMEDS::AttributeReal_var aRA = aRealAttr->AttributeReal::_this();
554 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
555 Handle(TDataStd_Integer) anAttr;
556 if (!Lab.FindAttribute(TDataStd_Integer::GetID(), anAttr)) {
557 anAttr = new TDataStd_Integer;
558 Lab.AddAttribute(anAttr);
560 SALOMEDS_AttributeInteger_i* aIntAttr = new SALOMEDS_AttributeInteger_i(anAttr, _orb);
561 SALOMEDS::AttributeInteger_var aIA = aIntAttr->AttributeInteger::_this();
564 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
565 Handle(SALOMEDS_SequenceOfRealAttribute) anAttr;
566 if (!Lab.FindAttribute(SALOMEDS_SequenceOfRealAttribute::GetID(), anAttr)) {
567 anAttr = new SALOMEDS_SequenceOfRealAttribute;
568 Lab.AddAttribute(anAttr);
570 SALOMEDS_AttributeSequenceOfReal_i* aSeqRealAttr = new SALOMEDS_AttributeSequenceOfReal_i(anAttr, _orb);
571 SALOMEDS::AttributeSequenceOfReal_var aSRA = aSeqRealAttr->AttributeSequenceOfReal::_this();
574 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
575 Handle(SALOMEDS_SequenceOfIntegerAttribute) anAttr;
576 if (!Lab.FindAttribute(SALOMEDS_SequenceOfIntegerAttribute::GetID(), anAttr)) {
577 anAttr = new SALOMEDS_SequenceOfIntegerAttribute;
578 Lab.AddAttribute(anAttr);
580 SALOMEDS_AttributeSequenceOfInteger_i* aSeqIntegerAttr = new SALOMEDS_AttributeSequenceOfInteger_i(anAttr, _orb);
581 SALOMEDS::AttributeSequenceOfInteger_var aSIA = aSeqIntegerAttr->AttributeSequenceOfInteger::_this();
584 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
585 Handle(TDataStd_Name) anAttr;
586 if (!Lab.FindAttribute(TDataStd_Name::GetID(), anAttr)) {
587 anAttr = new TDataStd_Name;
588 Lab.AddAttribute(anAttr);
590 SALOMEDS_AttributeName_i* aNameAttr = new SALOMEDS_AttributeName_i(anAttr, _orb);
591 SALOMEDS::AttributeName_var aSNA = aNameAttr->AttributeName::_this();
594 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
595 Handle(TDataStd_Comment) anAttr;
596 if (!Lab.FindAttribute(TDataStd_Comment::GetID(), anAttr)) {
597 anAttr = new TDataStd_Comment;
598 Lab.AddAttribute(anAttr);
600 SALOMEDS_AttributeComment_i* aCommentAttr = new SALOMEDS_AttributeComment_i(anAttr, _orb);
601 SALOMEDS::AttributeComment_var aCA = aCommentAttr->AttributeComment::_this();
604 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
605 Handle(SALOMEDS_IORAttribute) anAttr;
606 if (!Lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anAttr)) {
607 anAttr = new SALOMEDS_IORAttribute;
608 Lab.AddAttribute(anAttr);
610 SALOMEDS_AttributeIOR_i* aIORAttr = new SALOMEDS_AttributeIOR_i(anAttr, _orb);
611 SALOMEDS::AttributeIOR_var aIA = aIORAttr->AttributeIOR::_this();
614 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
615 Handle(SALOMEDS_PersRefAttribute) anAttr;
616 if (!Lab.FindAttribute(SALOMEDS_PersRefAttribute::GetID(), anAttr)) {
617 anAttr = new SALOMEDS_PersRefAttribute;
618 Lab.AddAttribute(anAttr);
620 SALOMEDS_AttributePersistentRef_i* aPerRefAttr = new SALOMEDS_AttributePersistentRef_i(anAttr, _orb);
621 SALOMEDS::AttributePersistentRef_var aPRA = aPerRefAttr->AttributePersistentRef::_this();
624 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
625 Handle(SALOMEDS_DrawableAttribute) anAttr;
626 if (!Lab.FindAttribute(SALOMEDS_DrawableAttribute::GetID(), anAttr)) {
627 anAttr = new SALOMEDS_DrawableAttribute;
628 Lab.AddAttribute(anAttr);
630 SALOMEDS_AttributeDrawable_i* aDrawableAttr = new SALOMEDS_AttributeDrawable_i(anAttr, _orb);
631 SALOMEDS::AttributeDrawable_var aDrawA = aDrawableAttr->AttributeDrawable::_this();
632 return aDrawA._retn();
634 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
635 Handle(SALOMEDS_SelectableAttribute) anAttr;
636 if (!Lab.FindAttribute(SALOMEDS_SelectableAttribute::GetID(), anAttr)) {
637 anAttr = new SALOMEDS_SelectableAttribute;
638 Lab.AddAttribute(anAttr);
640 SALOMEDS_AttributeSelectable_i* aSelectableAttr = new SALOMEDS_AttributeSelectable_i(anAttr, _orb);
641 SALOMEDS::AttributeSelectable_var aSelA = aSelectableAttr->AttributeSelectable::_this();
642 return aSelA._retn();
644 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
645 Handle(SALOMEDS_ExpandableAttribute) anAttr;
646 if (!Lab.FindAttribute(SALOMEDS_ExpandableAttribute::GetID(), anAttr)) {
647 anAttr = new SALOMEDS_ExpandableAttribute;
648 Lab.AddAttribute(anAttr);
650 SALOMEDS_AttributeExpandable_i* aExpandableAttr = new SALOMEDS_AttributeExpandable_i(anAttr, _orb);
651 SALOMEDS::AttributeExpandable_var aExpA = aExpandableAttr->AttributeExpandable::_this();
652 return aExpA._retn();
654 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
655 Handle(SALOMEDS_OpenedAttribute) anAttr;
656 if (!Lab.FindAttribute(SALOMEDS_OpenedAttribute::GetID(), anAttr)) {
657 anAttr = new SALOMEDS_OpenedAttribute;
658 Lab.AddAttribute(anAttr);
660 SALOMEDS_AttributeOpened_i* aOpenedAttr = new SALOMEDS_AttributeOpened_i(anAttr, _orb);
661 SALOMEDS::AttributeOpened_var aOpenA = aOpenedAttr->AttributeOpened::_this();
662 return aOpenA._retn();
664 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
665 Handle(SALOMEDS_TextColorAttribute) anAttr;
666 if (!Lab.FindAttribute(SALOMEDS_TextColorAttribute::GetID(), anAttr)) {
667 anAttr = new SALOMEDS_TextColorAttribute;
668 Lab.AddAttribute(anAttr);
670 SALOMEDS_AttributeTextColor_i* aTextColorAttr = new SALOMEDS_AttributeTextColor_i(anAttr, _orb);
671 SALOMEDS::AttributeTextColor_var aTCA = aTextColorAttr->AttributeTextColor::_this();
674 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
675 Handle(SALOMEDS_TextHighlightColorAttribute) anAttr;
676 if (!Lab.FindAttribute(SALOMEDS_TextHighlightColorAttribute::GetID(), anAttr)) {
677 anAttr = new SALOMEDS_TextHighlightColorAttribute;
678 Lab.AddAttribute(anAttr);
680 SALOMEDS_AttributeTextHighlightColor_i* aTextHighlightColorAttr = new SALOMEDS_AttributeTextHighlightColor_i(anAttr, _orb);
681 SALOMEDS::AttributeTextHighlightColor_var aTHCA = aTextHighlightColorAttr->AttributeTextHighlightColor::_this();
682 return aTHCA._retn();
684 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
685 Handle(SALOMEDS_PixMapAttribute) anAttr;
686 if (!Lab.FindAttribute(SALOMEDS_PixMapAttribute::GetID(), anAttr)) {
687 anAttr = new SALOMEDS_PixMapAttribute;
688 Lab.AddAttribute(anAttr);
690 SALOMEDS_AttributePixMap_i* aPixMapAttr = new SALOMEDS_AttributePixMap_i(anAttr, _orb);
691 SALOMEDS::AttributePixMap_var aPMA = aPixMapAttr->AttributePixMap::_this();
694 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
695 Standard_GUID aTreeNodeGUID;
696 if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0)
697 aTreeNodeGUID = TDataStd_TreeNode::GetDefaultTreeID();
699 char* aGUIDString = new char[40];
700 sprintf(aGUIDString, &(aTypeOfAttribute[21]));
701 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
704 Handle(TDataStd_TreeNode) anAttr;
705 if (!Lab.FindAttribute(aTreeNodeGUID, anAttr))
706 anAttr = TDataStd_TreeNode::Set(Lab, aTreeNodeGUID);
707 SALOMEDS_AttributeTreeNode_i* aTreeNodeAttr = new SALOMEDS_AttributeTreeNode_i(anAttr, _orb);
708 SALOMEDS::AttributeTreeNode_var aTNA = aTreeNodeAttr->AttributeTreeNode::_this();
711 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
712 Handle(TDataStd_UAttribute) anAttr;
713 if (!Lab.FindAttribute(SALOMEDS_AttributeUserID_i::DefaultID(), anAttr))
714 anAttr = TDataStd_UAttribute::Set(Lab, SALOMEDS_AttributeUserID_i::DefaultID());
715 SALOMEDS_AttributeUserID_i* aUAttr = new SALOMEDS_AttributeUserID_i(anAttr, _orb);
716 SALOMEDS::AttributeUserID_var aUA = aUAttr->AttributeUserID::_this();
719 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
720 Handle(SALOMEDS_LocalIDAttribute) anAttr;
721 if (!Lab.FindAttribute(SALOMEDS_LocalIDAttribute::GetID(), anAttr)) {
722 anAttr = new SALOMEDS_LocalIDAttribute;
723 Lab.AddAttribute(anAttr);
725 SALOMEDS_AttributeLocalID_i* aLIDAttr = new SALOMEDS_AttributeLocalID_i(anAttr, _orb);
726 SALOMEDS::AttributeLocalID_var aLIDA = aLIDAttr->AttributeLocalID::_this();
727 return aLIDA._retn();
729 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
730 Handle(SALOMEDS_TargetAttribute) anAttr;
731 if (!Lab.FindAttribute(SALOMEDS_TargetAttribute::GetID(), anAttr)) {
732 anAttr = new SALOMEDS_TargetAttribute;
733 Lab.AddAttribute(anAttr);
735 SALOMEDS_AttributeTarget_i* aLIDAttr = new SALOMEDS_AttributeTarget_i(anAttr, _orb);
736 SALOMEDS::AttributeTarget_var aLIDA = aLIDAttr->AttributeTarget::_this();
737 return aLIDA._retn();
739 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
740 Handle(SALOMEDS_TableOfIntegerAttribute) anAttr;
741 if (!Lab.FindAttribute(SALOMEDS_TableOfIntegerAttribute::GetID(), anAttr)) {
742 anAttr = new SALOMEDS_TableOfIntegerAttribute;
743 Lab.AddAttribute(anAttr);
745 SALOMEDS_AttributeTableOfInteger_i* aTabIntegerAttr = new SALOMEDS_AttributeTableOfInteger_i(anAttr, _orb);
746 SALOMEDS::AttributeTableOfInteger_var aTIA = aTabIntegerAttr->AttributeTableOfInteger::_this();
749 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
750 Handle(SALOMEDS_TableOfRealAttribute) anAttr;
751 if (!Lab.FindAttribute(SALOMEDS_TableOfRealAttribute::GetID(), anAttr)) {
752 anAttr = new SALOMEDS_TableOfRealAttribute;
753 Lab.AddAttribute(anAttr);
755 SALOMEDS_AttributeTableOfReal_i* aTabRealAttr = new SALOMEDS_AttributeTableOfReal_i(anAttr, _orb);
756 SALOMEDS::AttributeTableOfReal_var aTRA = aTabRealAttr->AttributeTableOfReal::_this();
759 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
760 Handle(SALOMEDS_TableOfStringAttribute) anAttr;
761 if (!Lab.FindAttribute(SALOMEDS_TableOfStringAttribute::GetID(), anAttr)) {
762 anAttr = new SALOMEDS_TableOfStringAttribute;
763 Lab.AddAttribute(anAttr);
765 SALOMEDS_AttributeTableOfString_i* aTabStringAttr = new SALOMEDS_AttributeTableOfString_i(anAttr, _orb);
766 SALOMEDS::AttributeTableOfString_var aTRA = aTabStringAttr->AttributeTableOfString::_this();
769 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
770 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
771 if (!Lab.FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
772 anAttr = new SALOMEDS_StudyPropertiesAttribute;
773 Lab.AddAttribute(anAttr);
774 anAttr->SetModified(0);
776 SALOMEDS_AttributeStudyProperties_i* aStPropAttr = new SALOMEDS_AttributeStudyProperties_i(anAttr, _orb);
777 SALOMEDS::AttributeStudyProperties_var aSPA = aStPropAttr->AttributeStudyProperties::_this();
780 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
781 Handle(SALOMEDS_PythonObjectAttribute) anAttr;
782 if (!Lab.FindAttribute(SALOMEDS_PythonObjectAttribute::GetID(), anAttr)) {
783 anAttr = new SALOMEDS_PythonObjectAttribute;
784 Lab.AddAttribute(anAttr);
786 SALOMEDS_AttributePythonObject_i* aPObjAttr = new SALOMEDS_AttributePythonObject_i(anAttr, _orb);
787 SALOMEDS::AttributePythonObject_var aPOA = aPObjAttr->AttributePythonObject::_this();
792 //============================================================================
793 /*! Function : FindAttribute
794 * Purpose : Find attribute of given type assigned SObject, returns Standard_True if it is found
796 //============================================================================
798 CORBA::Boolean SALOMEDS_StudyBuilder_i::FindAttribute(SALOMEDS::SObject_ptr anObject,
799 SALOMEDS::GenericAttribute_out anAttribute,
800 const char* aTypeOfAttribute)
803 ASSERT(!CORBA::is_nil(anObject));
804 CORBA::String_var anobid = anObject->GetID();
805 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
806 Handle(TDF_Attribute) anAttr;
807 Standard_Boolean found = Lab.FindAttribute(SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute), anAttr);
809 if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 ) {
810 SALOMEDS_AttributeReal_i* Attr= new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
811 anAttribute = Attr->AttributeReal::_this();
812 return Standard_True;
814 else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 ) {
815 SALOMEDS_AttributeInteger_i* Attr= new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
816 anAttribute = Attr->AttributeInteger::_this();
817 return Standard_True;
819 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 ) {
820 SALOMEDS_AttributeSequenceOfReal_i* Attr= new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
821 anAttribute = Attr->AttributeSequenceOfReal::_this();
822 return Standard_True;
824 else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 ) {
825 SALOMEDS_AttributeSequenceOfInteger_i* Attr= new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
826 anAttribute = Attr->AttributeSequenceOfInteger::_this();
827 return Standard_True;
829 else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
830 SALOMEDS_AttributeName_i* Attr= new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
831 anAttribute = Attr->AttributeName::_this();
832 return Standard_True;
834 else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
835 SALOMEDS_AttributeComment_i* Attr= new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
836 anAttribute = Attr->AttributeComment::_this();
837 return Standard_True;
839 else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
840 SALOMEDS_AttributeIOR_i* Attr= new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
841 anAttribute = Attr->AttributeIOR::_this();
842 return Standard_True;
844 else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 ) {
845 SALOMEDS_AttributePersistentRef_i* Attr= new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
846 anAttribute = Attr->AttributePersistentRef::_this();
847 return Standard_True;
849 else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 ) {
850 SALOMEDS_AttributeDrawable_i* Attr= new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
851 anAttribute = Attr->AttributeDrawable::_this();
852 return Standard_True;
854 else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 ) {
855 SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
856 anAttribute = Attr->AttributeSelectable::_this();
857 return Standard_True;
859 else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 ) {
860 SALOMEDS_AttributeExpandable_i* Attr= new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
861 anAttribute = Attr->AttributeExpandable::_this();
862 return Standard_True;
864 else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 ) {
865 SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
866 anAttribute = Attr->AttributeOpened::_this();
867 return Standard_True;
869 else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 ) {
870 SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
871 anAttribute = Attr->AttributeTextColor::_this();
872 return Standard_True;
874 else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) {
875 SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
876 anAttribute = Attr->AttributeTextHighlightColor::_this();
877 return Standard_True;
879 else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 ) {
880 SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
881 anAttribute = Attr->AttributePixMap::_this();
882 return Standard_True;
884 else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 ) {
885 SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
886 anAttribute = Attr->AttributeTreeNode::_this();
887 return Standard_True;
889 else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 ) {
890 SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
891 anAttribute = Attr->AttributeUserID::_this();
892 return Standard_True;
894 else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 ) {
895 SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
896 anAttribute = Attr->AttributeLocalID::_this();
897 return Standard_True;
899 else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 ) {
900 SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
901 anAttribute = Attr->AttributeTarget::_this();
902 return Standard_True;
904 else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 ) {
905 SALOMEDS_AttributeTableOfInteger_i* Attr= new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
906 anAttribute = Attr->AttributeTableOfInteger::_this();
907 return Standard_True;
909 else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 ) {
910 SALOMEDS_AttributeTableOfReal_i* Attr= new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
911 anAttribute = Attr->AttributeTableOfReal::_this();
912 return Standard_True;
914 else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 ) {
915 SALOMEDS_AttributeTableOfString_i* Attr= new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
916 anAttribute = Attr->AttributeTableOfString::_this();
917 return Standard_True;
919 else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 ) {
920 SALOMEDS_AttributeStudyProperties_i* Attr= new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
921 anAttribute = Attr->AttributeStudyProperties::_this();
922 return Standard_True;
924 else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 ) {
925 SALOMEDS_AttributePythonObject_i* Attr= new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
926 anAttribute = Attr->AttributePythonObject::_this();
927 return Standard_True;
929 } else return Standard_False;
932 //============================================================================
933 /*! Function : RemoveAttribute
934 * Purpose : Remove attribute of given type assigned SObject
936 //============================================================================
938 void SALOMEDS_StudyBuilder_i::RemoveAttribute(SALOMEDS::SObject_ptr anObject,
939 const char* aTypeOfAttribute)
942 ASSERT(!CORBA::is_nil(anObject));
943 CORBA::String_var anobid = anObject->GetID();
944 TDF_Tool::Label(_doc->GetData(),strdup(anobid),Lab);
945 Lab.ForgetAttribute (SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute));
948 //============================================================================
949 /*! Function : Addreference
952 //============================================================================
954 SALOMEDS_StudyBuilder_i::Addreference(SALOMEDS::SObject_ptr me,
955 SALOMEDS::SObject_ptr theReferencedObject)
958 ASSERT(!CORBA::is_nil(me));
959 CORBA::String_var meid = me->GetID();
960 TDF_Tool::Label(_doc->GetData(),strdup(meid),Lab);
962 ASSERT(!CORBA::is_nil(theReferencedObject));
963 CORBA::String_var roid = theReferencedObject->GetID();
964 TDF_Tool::Label(_doc->GetData(),strdup(roid),RefLab);
965 TDF_Reference::Set(Lab,RefLab);
967 SALOMEDS_TargetAttribute::Set(RefLab)->Append(Lab);
969 if(!CORBA::is_nil(_callbackOnRemove)) _callbackOnRemove->OnRemoveSObject(me);
973 //============================================================================
974 /*! Function : AddDirectory
975 * Purpose : adds a new directory with a path = thePath
977 //============================================================================
978 void SALOMEDS_StudyBuilder_i::AddDirectory(const char* thePath)
980 if(thePath == NULL || strlen(thePath) == 0) throw SALOMEDS::Study::StudyInvalidDirectory();
982 TCollection_AsciiString aPath(CORBA::string_dup(thePath)), aContext(""), aFatherPath;
983 TDF_ChildIterator anIterator(_doc->Main());
984 Handle(TDataStd_Name) aName;
986 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i (_doc->Main(), _orb);
987 SALOMEDS::SObject_var anObject = SALOMEDS::SObject::_narrow(so_servant->_this());
988 SALOMEDS::Study_var aStudy = anObject->GetStudy();
991 anObject = aStudy->FindObjectByPath(thePath); //Check if the directory already exists
995 if(!anObject->_is_nil()) throw SALOMEDS::Study::StudyNameAlreadyUsed();
997 if(aPath.Value(1) != '/') { //Relative path
999 aPath = TCollection_AsciiString(aStudy->GetContext()) + aPath;
1002 TCollection_AsciiString aToken = aPath.Token("/", 1);
1003 if(aToken.Length() == 0) aFatherPath = "/";
1006 while(aToken.Length() != 0) {
1007 if(aPath.Token("/", i+1).Length() > 0) {
1009 aFatherPath += aToken;
1011 aToken = aPath.Token("/", ++i);
1014 anObject = SALOMEDS::SObject::_nil();
1016 anObject = aStudy->FindObjectByPath(aFatherPath.ToCString()); //Check if the father directory exists
1019 if(anObject->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1021 SALOMEDS::SObject_var aNewObject = NewObject(anObject);
1022 TDF_Tool::Label(_doc->GetData(), aNewObject->GetID(), aLabel);
1023 if(aLabel.IsNull()) {
1024 MESSAGE("### NULL label");
1025 throw SALOMEDS::Study::StudyInvalidComponent();
1028 TDataStd_Name::Set(aLabel, aPath.Token("/", i-1));
1030 //Set LocalID attribute to identify the directory object
1031 SALOMEDS::GenericAttribute_var anAttr = FindOrCreateAttribute(aNewObject, "AttributeLocalID");
1032 SALOMEDS::AttributeLocalID_var aPersRef = SALOMEDS::AttributeLocalID::_narrow(anAttr);
1033 if(aPersRef->_is_nil()) throw SALOMEDS::Study::StudyInvalidDirectory();
1035 aPersRef->SetValue(DIRECTORYID);
1039 //============================================================================
1040 /*! Function : SetGUID
1043 //============================================================================
1044 void SALOMEDS_StudyBuilder_i::SetGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1047 ASSERT(!CORBA::is_nil(anObject));
1048 CORBA::String_var anEntry = anObject->GetID();
1049 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1050 TDataStd_UAttribute::Set(aLabel, (char*)theGUID);
1053 //============================================================================
1054 /*! Function : IsGUID
1057 //============================================================================
1058 bool SALOMEDS_StudyBuilder_i::IsGUID(SALOMEDS::SObject_ptr anObject, const char* theGUID)
1061 ASSERT(!CORBA::is_nil(anObject));
1062 CORBA::String_var anEntry = anObject->GetID();
1063 TDF_Tool::Label(_doc->GetData(), strdup(anEntry), aLabel);
1064 return aLabel.IsAttribute((char*)theGUID);
1068 //============================================================================
1069 /*! Function : NewCommand
1072 //============================================================================
1073 void SALOMEDS_StudyBuilder_i::NewCommand()
1075 // mpv: for SAL2114 - unset "lock changed" flag at the operation start
1076 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1077 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1078 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1079 _doc->Main().AddAttribute(anAttr);
1081 anAttr->IsLockChanged(true);
1086 //============================================================================
1087 /*! Function : CommitCommand
1090 //============================================================================
1091 void SALOMEDS_StudyBuilder_i::CommitCommand() throw (SALOMEDS::StudyBuilder::LockProtection)
1093 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1094 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1095 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1096 _doc->Main().AddAttribute(anAttr);
1098 if (anAttr->IsLocked() && !anAttr->IsLockChanged(true)) {
1099 INFOS("Locked document modification !!!");
1101 throw SALOMEDS::StudyBuilder::LockProtection();
1103 int aModif = anAttr->GetModified();
1104 if (aModif < 0) aModif = 1000; // if user make undo and then - new transaction "modify" will never be zero
1105 anAttr->SetModified(aModif+1);
1106 _doc->CommitCommand();
1110 //============================================================================
1111 /*! Function : HasOpenCommand
1114 //============================================================================
1115 CORBA::Boolean SALOMEDS_StudyBuilder_i::HasOpenCommand()
1117 _doc->HasOpenCommand();
1120 //============================================================================
1121 /*! Function : AbortCommand
1124 //============================================================================
1125 void SALOMEDS_StudyBuilder_i::AbortCommand()
1127 _doc->AbortCommand();
1130 //============================================================================
1134 //============================================================================
1135 void SALOMEDS_StudyBuilder_i::Undo() throw (SALOMEDS::StudyBuilder::LockProtection)
1137 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1138 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1139 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1140 _doc->Main().AddAttribute(anAttr);
1142 if (anAttr->IsLocked()) {
1143 INFOS("Locked document modification !!!");
1144 throw SALOMEDS::StudyBuilder::LockProtection();
1147 anAttr->SetModified(anAttr->GetModified()-1);
1151 //============================================================================
1155 //============================================================================
1156 void SALOMEDS_StudyBuilder_i::Redo() throw (SALOMEDS::StudyBuilder::LockProtection)
1158 Handle(SALOMEDS_StudyPropertiesAttribute) anAttr;
1159 if (!_doc->Main().FindAttribute(SALOMEDS_StudyPropertiesAttribute::GetID(), anAttr)) {
1160 anAttr = new SALOMEDS_StudyPropertiesAttribute;
1161 _doc->Main().AddAttribute(anAttr);
1164 if (anAttr->IsLocked()) {
1165 INFOS("Locked document modification !!!");
1166 throw SALOMEDS::StudyBuilder::LockProtection();
1169 anAttr->SetModified(anAttr->GetModified()+1);
1173 //============================================================================
1174 /*! Function : GetAvailableUndos
1177 //============================================================================
1178 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableUndos()
1180 return _doc->GetAvailableUndos();
1183 //============================================================================
1184 /*! Function : GetAvailableRedos
1187 //============================================================================
1188 CORBA::Boolean SALOMEDS_StudyBuilder_i::GetAvailableRedos()
1190 return _doc->GetAvailableRedos();
1194 //============================================================================
1195 /*! Function : UndoLimit
1198 //============================================================================
1199 CORBA::Long SALOMEDS_StudyBuilder_i::UndoLimit()
1201 return _doc->GetUndoLimit();
1204 //============================================================================
1205 /*! Function : UndoLimit
1208 //============================================================================
1209 void SALOMEDS_StudyBuilder_i::UndoLimit(CORBA::Long n)
1211 _doc->SetUndoLimit (n);
1214 //============================================================================
1215 /*! Function : SetOnAddSObject
1218 //============================================================================
1219 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnAddSObject(SALOMEDS::Callback_ptr theCallback)
1221 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnAdd))?NULL:_callbackOnAdd._retn();
1222 _callbackOnAdd = SALOMEDS::Callback::_duplicate(theCallback);
1226 //============================================================================
1227 /*! Function : SetOnNewSObject
1230 //============================================================================
1231 SALOMEDS::Callback_ptr SALOMEDS_StudyBuilder_i::SetOnRemoveSObject(SALOMEDS::Callback_ptr theCallback)
1233 SALOMEDS::Callback_ptr aRet = (CORBA::is_nil(_callbackOnRemove))?NULL:_callbackOnRemove._retn();
1234 _callbackOnRemove = SALOMEDS::Callback::_duplicate(theCallback);