1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
2 // File : SALOMEDSImpl_SObject.cxx
3 // Author : Sergey RUIN
8 #include "SALOMEDSImpl_SObject.hxx"
9 #include "SALOMEDSImpl_Attributes.hxx"
10 #include "SALOMEDSImpl_SComponent.hxx"
11 #include "SALOMEDSImpl_Study.hxx"
15 #include <TDF_AttributeIterator.hxx>
18 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_SObject, MMgt_TShared )
19 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_SObject, MMgt_TShared )
21 //============================================================================
22 /*! Function : constructor
25 //============================================================================
26 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const TDF_Label& theLabel)
34 //============================================================================
35 /*! Function : Desctructor
38 //============================================================================
39 SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject()
42 //============================================================================
46 //============================================================================
47 TCollection_AsciiString SALOMEDSImpl_SObject::GetID()
49 TCollection_AsciiString anEntry;
50 TDF_Tool::Entry (_lab,anEntry);
54 //============================================================================
55 /*! Function : GetFatherComponent
58 //============================================================================
59 Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SObject::GetFatherComponent()
62 while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) {
66 if(LF.IsRoot()) return NULL;
68 return GetStudy()->GetSComponent(LF);
71 //============================================================================
72 /*! Function : GetFather
75 //============================================================================
76 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_SObject::GetFather()
78 return GetStudy()->GetSObject(_lab.Father());
82 //============================================================================
83 /*! Function : GetStudy
86 //============================================================================
87 Handle(SALOMEDSImpl_Study) SALOMEDSImpl_SObject::GetStudy()
89 return SALOMEDSImpl_Study::GetStudy(_lab);
92 //============================================================================
93 /*! Function : FindAttribute
94 * Purpose : Find attribute of given type on this SObject
96 //============================================================================
97 bool SALOMEDSImpl_SObject::FindAttribute(Handle(TDF_Attribute)& theAttribute,
98 const TCollection_AsciiString& theTypeOfAttribute)
100 if(_lab.IsNull()) return Standard_False;
101 Standard_GUID aGUID = GetGUID(theTypeOfAttribute);
102 if (_lab.FindAttribute(aGUID, theAttribute)) return Standard_True;
103 return Standard_False;
108 //============================================================================
109 /*! Function : GetAllAttributes
110 * Purpose : Returns list of all attributes for this sobject
112 //============================================================================
113 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_SObject::GetAllAttributes()
115 Standard_Integer NumAttr = _lab.NbAttributes();
116 Handle(TColStd_HSequenceOfTransient) SeqOfAttr = new TColStd_HSequenceOfTransient();
117 Handle(SALOMEDSImpl_GenericAttribute) anAttr;
119 for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) {
120 anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(iter.Value());
121 if(!anAttr.IsNull() && anAttr->Type() != "AttributeReference")
122 SeqOfAttr->Append(anAttr);
129 //============================================================================
130 /*! Function : ReferencedObject
133 //============================================================================
134 bool SALOMEDSImpl_SObject::ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObject)
136 Handle(SALOMEDSImpl_AttributeReference) Ref;
137 if (!_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),Ref))
140 theObject = GetStudy()->GetSObject(Ref->Get());
144 //============================================================================
145 /*! Function : FindSubObject
148 //============================================================================
149 bool SALOMEDSImpl_SObject::FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject)& theObject)
151 TDF_Label L = _lab.FindChild(theTag, false);
152 if (L.IsNull()) return false;
154 theObject = GetStudy()->GetSObject(L);
160 //============================================================================
161 /*! Function : GetName
164 //============================================================================
165 TCollection_AsciiString SALOMEDSImpl_SObject::GetName()
167 TCollection_AsciiString aStr = "";
168 Handle(SALOMEDSImpl_AttributeName) aName;
169 if (_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) {
170 aStr = aName->Value();
175 //============================================================================
176 /*! Function : GetComment
179 //============================================================================
180 TCollection_AsciiString SALOMEDSImpl_SObject::GetComment()
182 TCollection_AsciiString aStr = "";
183 Handle(SALOMEDSImpl_AttributeComment) aComment;
184 if (_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComment)) {
185 aStr = aComment->Value();
190 //============================================================================
191 /*! Function : GetIOR
194 //============================================================================
195 TCollection_AsciiString SALOMEDSImpl_SObject::GetIOR()
197 TCollection_AsciiString aStr = "";
198 Handle(SALOMEDSImpl_AttributeIOR) anIOR;
199 if (_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anIOR)) {
200 aStr = anIOR->Value();
206 Standard_GUID SALOMEDSImpl_SObject::GetGUID(const TCollection_AsciiString& theType)
208 __AttributeTypeToGUIDForSObject
210 if (strncmp(theType.ToCString(), "AttributeTreeNodeGUID",21) == 0) {
211 const char* aCType = theType.ToCString();
212 char* aGUIDString = new char[40];
213 sprintf(aGUIDString, &(aCType[21]));
214 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
218 return Standard_GUID();