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_SObject_i.cxx
25 // Author : Yves FRICAUD
29 #include "utilities.h"
30 #include "SALOMEDS_SObject_i.hxx"
32 #include "SALOMEDS_SComponent_i.hxx"
33 #include "SALOMEDS_GenericAttribute_i.hxx"
34 #include "SALOMEDS_IORAttribute.hxx"
35 #include <TDF_AttributeIterator.hxx>
38 //============================================================================
39 /*! Function : constructor
42 //============================================================================
43 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const TDF_Label lab, CORBA::ORB_ptr orb)
46 _orb = CORBA::ORB::_duplicate(orb);
50 _liste_ba_type.resize(0);
54 //============================================================================
55 /*! Function : destructor
58 //============================================================================
59 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
61 CORBA::string_free(_value);
62 CORBA::string_free(_type);
63 CORBA::string_free(_name);
67 //============================================================================
71 //============================================================================
72 char* SALOMEDS_SObject_i::GetID()
74 TCollection_AsciiString anEntry;
75 TDF_Tool::Entry (_lab,anEntry);
76 return CORBA::string_dup(anEntry.ToCString());
79 //============================================================================
83 //============================================================================
84 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
87 while (!SALOMEDS_SComponent_i::IsA(LF) && !LF.IsRoot()) {
90 SALOMEDS_SComponent_i * so_servant = new SALOMEDS_SComponent_i (LF,_orb);
91 SALOMEDS::SComponent_var so;
92 so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this());
96 //============================================================================
100 //============================================================================
101 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
103 TDF_Label LF = _lab.Father();
105 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (LF,_orb);
106 SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this());
110 //============================================================================
114 //============================================================================
115 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
117 TDF_Label Root = _lab.Root();
118 Handle(SALOMEDS_IORAttribute) Att;
120 if (Root.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
121 TCollection_AsciiString ch(Att->Get());
122 IOR = CORBA::string_dup(ch.ToCString());
123 CORBA::Object_var obj = _orb->string_to_object(IOR);
124 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
125 ASSERT(!CORBA::is_nil(Study));
126 return SALOMEDS::Study::_duplicate(Study); //return Study = abort...
128 MESSAGE("Problem GetStudy");
129 return SALOMEDS::Study::_nil();
132 //============================================================================
133 /*! Function : FindAttribute
134 * Purpose : Find attribute of given type on this SObject
136 //============================================================================
137 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
138 const char* aTypeOfAttribute)
140 Handle(TDF_Attribute) anAttr;
141 if (_lab.FindAttribute(SALOMEDS_GenericAttribute_i::GetGUID(aTypeOfAttribute), anAttr)) {
142 anAttribute = SALOMEDS::GenericAttribute::_duplicate(SALOMEDS_GenericAttribute_i::CreateAttribute(_orb, anAttr));
143 return Standard_True;
145 return Standard_False;
148 //============================================================================
149 /*! Function : GetAllAttributes
150 * Purpose : Returns list of all attributes for this sobject
152 //============================================================================
154 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
156 Standard_Integer NumAttr = _lab.NbAttributes();
157 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
158 //SeqOfAttr->length(NumAttr);
160 Standard_Integer i = 0;
161 for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) {
162 Handle(TDF_Attribute) anAttr = iter.Value();
163 SALOMEDS::GenericAttribute_var anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(_orb, anAttr);
164 if (!CORBA::is_nil(anAttribute)) {
165 SeqOfAttr->length(++i);
166 SeqOfAttr[i - 1] = anAttribute;
170 return SeqOfAttr._retn();
174 //============================================================================
175 /*! Function : ReferencedObject
178 //============================================================================
179 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
181 Handle(TDF_Reference) Ref;
182 if (!_lab.FindAttribute(TDF_Reference::GetID(),Ref))
185 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (Ref->Get(),_orb);
186 obj = SALOMEDS::SObject::_narrow(so_servant->_this());
190 //============================================================================
194 //============================================================================
195 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(long atag, SALOMEDS::SObject_out obj)
197 TDF_Label L = _lab.FindChild(atag,false);
198 if (L.IsNull()) return false;
200 SALOMEDS_SObject_i * so_servant = new SALOMEDS_SObject_i (L,_orb);
201 obj = SALOMEDS::SObject::_narrow(so_servant->_this());
206 //============================================================================
210 //============================================================================
211 char* SALOMEDS_SObject_i::Name()
213 return CORBA::string_dup(_name);
216 //============================================================================
220 //============================================================================
221 void SALOMEDS_SObject_i::Name(const char* name)
223 _name = CORBA::string_dup(name);
226 //============================================================================
230 //============================================================================
231 CORBA::Short SALOMEDS_SObject_i::Tag()
236 //============================================================================
240 //============================================================================
241 CORBA::Short SALOMEDS_SObject_i::Depth()
246 //============================================================================
250 //============================================================================
251 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
253 CORBA::Object_ptr obj = CORBA::Object::_nil();
255 Handle(SALOMEDS_IORAttribute) Att;
256 if (_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)) {
257 TCollection_AsciiString ch(Att->Get());
258 char* IOR = CORBA::string_dup(ch.ToCString());
259 obj = _orb->string_to_object(IOR);
265 //============================================================================
269 //============================================================================
270 char* SALOMEDS_SObject_i::GetName() {
271 CORBA::String_var aStr = CORBA::string_dup( "" );
272 Handle(TDataStd_Name) aName;
273 if (_lab.FindAttribute(TDataStd_Name::GetID(), aName)) {
274 aStr = CORBA::string_dup(TCollection_AsciiString(aName->Get()).ToCString());
279 //============================================================================
283 //============================================================================
284 char* SALOMEDS_SObject_i::GetComment() {
285 CORBA::String_var aStr = CORBA::string_dup( "" );
286 Handle(TDataStd_Comment) aComment;
287 if (_lab.FindAttribute(TDataStd_Comment::GetID(), aComment)) {
288 aStr = CORBA::string_dup(TCollection_AsciiString(aComment->Get()).ToCString());
293 //============================================================================
297 //============================================================================
298 char* SALOMEDS_SObject_i::GetIOR() {
299 CORBA::String_var aStr = CORBA::string_dup( "" );
300 Handle(SALOMEDS_IORAttribute) anIOR;
301 if (_lab.FindAttribute(SALOMEDS_IORAttribute::GetID(), anIOR)) {
302 aStr = CORBA::string_dup(TCollection_AsciiString(anIOR->Get()).ToCString());