1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
21 // File : SALOMEDSImpl_SObject.cxx
22 // Author : Sergey RUIN
27 #include "SALOMEDSImpl_SObject.hxx"
28 #include "SALOMEDSImpl_Attributes.hxx"
29 #include "SALOMEDSImpl_SComponent.hxx"
30 #include "SALOMEDSImpl_Study.hxx"
34 #include <TDF_AttributeIterator.hxx>
37 IMPLEMENT_STANDARD_HANDLE( SALOMEDSImpl_SObject, MMgt_TShared )
38 IMPLEMENT_STANDARD_RTTIEXT( SALOMEDSImpl_SObject, MMgt_TShared )
40 //============================================================================
41 /*! Function : constructor
44 //============================================================================
45 SALOMEDSImpl_SObject::SALOMEDSImpl_SObject(const TDF_Label& theLabel)
53 //============================================================================
54 /*! Function : Desctructor
57 //============================================================================
58 SALOMEDSImpl_SObject::~SALOMEDSImpl_SObject()
61 //============================================================================
65 //============================================================================
66 TCollection_AsciiString SALOMEDSImpl_SObject::GetID()
68 TCollection_AsciiString anEntry;
69 TDF_Tool::Entry (_lab,anEntry);
73 //============================================================================
74 /*! Function : GetFatherComponent
77 //============================================================================
78 Handle(SALOMEDSImpl_SComponent) SALOMEDSImpl_SObject::GetFatherComponent()
81 while (!SALOMEDSImpl_SComponent::IsA(LF) && !LF.IsRoot()) {
85 if(LF.IsRoot()) return NULL;
87 return GetStudy()->GetSComponent(LF);
90 //============================================================================
91 /*! Function : GetFather
94 //============================================================================
95 Handle(SALOMEDSImpl_SObject) SALOMEDSImpl_SObject::GetFather()
97 return GetStudy()->GetSObject(_lab.Father());
101 //============================================================================
102 /*! Function : GetStudy
105 //============================================================================
106 Handle(SALOMEDSImpl_Study) SALOMEDSImpl_SObject::GetStudy()
108 return SALOMEDSImpl_Study::GetStudy(_lab);
111 //============================================================================
112 /*! Function : FindAttribute
113 * Purpose : Find attribute of given type on this SObject
115 //============================================================================
116 bool SALOMEDSImpl_SObject::FindAttribute(Handle(TDF_Attribute)& theAttribute,
117 const TCollection_AsciiString& theTypeOfAttribute)
119 if(_lab.IsNull()) return Standard_False;
120 Standard_GUID aGUID = GetGUID(theTypeOfAttribute);
121 if (_lab.FindAttribute(aGUID, theAttribute)) return Standard_True;
122 return Standard_False;
127 //============================================================================
128 /*! Function : GetAllAttributes
129 * Purpose : Returns list of all attributes for this sobject
131 //============================================================================
132 Handle(TColStd_HSequenceOfTransient) SALOMEDSImpl_SObject::GetAllAttributes()
134 Standard_Integer NumAttr = _lab.NbAttributes();
135 Handle(TColStd_HSequenceOfTransient) SeqOfAttr = new TColStd_HSequenceOfTransient();
136 Handle(SALOMEDSImpl_GenericAttribute) anAttr;
138 for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) {
139 anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(iter.Value());
140 if(!anAttr.IsNull() && anAttr->Type() != "AttributeReference")
141 SeqOfAttr->Append(anAttr);
148 //============================================================================
149 /*! Function : ReferencedObject
152 //============================================================================
153 bool SALOMEDSImpl_SObject::ReferencedObject(Handle(SALOMEDSImpl_SObject)& theObject)
155 Handle(SALOMEDSImpl_AttributeReference) Ref;
156 if (!_lab.FindAttribute(SALOMEDSImpl_AttributeReference::GetID(),Ref))
159 theObject = GetStudy()->GetSObject(Ref->Get());
163 //============================================================================
164 /*! Function : FindSubObject
167 //============================================================================
168 bool SALOMEDSImpl_SObject::FindSubObject(int theTag, Handle(SALOMEDSImpl_SObject)& theObject)
170 TDF_Label L = _lab.FindChild(theTag, false);
171 if (L.IsNull()) return false;
173 theObject = GetStudy()->GetSObject(L);
179 //============================================================================
180 /*! Function : GetName
183 //============================================================================
184 TCollection_AsciiString SALOMEDSImpl_SObject::GetName()
186 TCollection_AsciiString aStr = "";
187 Handle(SALOMEDSImpl_AttributeName) aName;
188 if (_lab.FindAttribute(SALOMEDSImpl_AttributeName::GetID(), aName)) {
189 aStr = aName->Value();
194 //============================================================================
195 /*! Function : GetComment
198 //============================================================================
199 TCollection_AsciiString SALOMEDSImpl_SObject::GetComment()
201 TCollection_AsciiString aStr = "";
202 Handle(SALOMEDSImpl_AttributeComment) aComment;
203 if (_lab.FindAttribute(SALOMEDSImpl_AttributeComment::GetID(), aComment)) {
204 aStr = aComment->Value();
209 //============================================================================
210 /*! Function : GetIOR
213 //============================================================================
214 TCollection_AsciiString SALOMEDSImpl_SObject::GetIOR()
216 TCollection_AsciiString aStr = "";
217 Handle(SALOMEDSImpl_AttributeIOR) anIOR;
218 if (_lab.FindAttribute(SALOMEDSImpl_AttributeIOR::GetID(), anIOR)) {
219 aStr = anIOR->Value();
225 Standard_GUID SALOMEDSImpl_SObject::GetGUID(const TCollection_AsciiString& theType)
227 __AttributeTypeToGUIDForSObject
229 if (strncmp(theType.ToCString(), "AttributeTreeNodeGUID",21) == 0) {
230 const char* aCType = theType.ToCString();
231 char* aGUIDString = new char[40];
232 sprintf(aGUIDString, &(aCType[21]));
233 Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
237 return Standard_GUID();