Salome HOME
NRI : Merge from V1_2.
[modules/yacs.git] / src / SALOMEDS / SALOMEDS_SObject_i.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEDS_SObject_i.cxx
25 //  Author : Yves FRICAUD
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "utilities.h"
31 #include "SALOMEDS_SObject_i.hxx"
32 //SALOMEDS Headers
33 #include "SALOMEDS_SComponent_i.hxx"
34 #include "SALOMEDS_IORAttribute.hxx"
35 #include "SALOMEDS_PersRefAttribute.hxx"
36 #include "SALOMEDS_SequenceOfRealAttribute.hxx"
37 #include "SALOMEDS_SequenceOfIntegerAttribute.hxx"
38 #include "SALOMEDS_TableOfRealAttribute.hxx"
39 #include "SALOMEDS_TableOfIntegerAttribute.hxx"
40 #include "SALOMEDS_IORAttribute.hxx"
41 #include "SALOMEDS_PersRefAttribute.hxx"
42 #include "SALOMEDS_StudyPropertiesAttribute.hxx"
43 #include "SALOMEDS_PythonObjectAttribute.hxx"
44 #include "SALOMEDS_AttributePersistentRef_i.hxx"
45 #include "SALOMEDS_AttributeIOR_i.hxx"
46 #include "SALOMEDS_AttributeComment_i.hxx"
47 #include "SALOMEDS_AttributeName_i.hxx"
48 #include "SALOMEDS_AttributeSequenceOfInteger_i.hxx"
49 #include "SALOMEDS_AttributeSequenceOfReal_i.hxx"
50 #include "SALOMEDS_AttributeInteger_i.hxx"
51 #include "SALOMEDS_AttributeReal_i.hxx"
52 #include "SALOMEDS_AttributeDrawable_i.hxx"
53 #include "SALOMEDS_AttributeSelectable_i.hxx"
54 #include "SALOMEDS_AttributeExpandable_i.hxx"
55 #include "SALOMEDS_AttributeOpened_i.hxx"
56 #include "SALOMEDS_AttributeTextColor_i.hxx"
57 #include "SALOMEDS_AttributeTextHighlightColor_i.hxx"
58 #include "SALOMEDS_AttributePixMap_i.hxx"
59 #include "SALOMEDS_AttributeTreeNode_i.hxx"
60 #include "SALOMEDS_AttributeLocalID_i.hxx"
61 #include "SALOMEDS_AttributeUserID_i.hxx"
62 #include "SALOMEDS_AttributeTarget_i.hxx"
63 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
64 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
65 #include "SALOMEDS_AttributeTableOfString_i.hxx"
66 #include "SALOMEDS_AttributeStudyProperties_i.hxx"
67 #include "SALOMEDS_AttributePythonObject_i.hxx"
68 #include <TDF_AttributeIterator.hxx>
69
70 //============================================================================
71 /*! Function : ReturnGUIDForAttribute
72  *  Purpose  : 
73  */
74 //============================================================================
75
76 Standard_GUID  
77 SALOMEDS_SObject_i::ReturnGUIDForAttribute(const char* aTypeOfAttribute)
78 {
79    Standard_GUID TypeID;
80   
81    if      (strcmp(aTypeOfAttribute, "AttributeReal") == 0 )               return TDataStd_Real::GetID();
82    else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 )            return TDataStd_Integer::GetID();
83    else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 )     return SALOMEDS_SequenceOfRealAttribute::GetID();
84    else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 )  return SALOMEDS_SequenceOfIntegerAttribute::GetID();
85    else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 )               return TDataStd_Name::GetID();
86    else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 )            return TDataStd_Comment::GetID();
87    else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 )                return SALOMEDS_IORAttribute::GetID();
88    else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 )      return SALOMEDS_PersRefAttribute::GetID();
89    else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 )           return SALOMEDS_DrawableAttribute::GetID();
90    else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 )         return SALOMEDS_SelectableAttribute::GetID();
91    else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 )         return SALOMEDS_ExpandableAttribute::GetID();
92    else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 )             return SALOMEDS_OpenedAttribute::GetID();
93    else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 )          return SALOMEDS_TextColorAttribute::GetID();
94    else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 ) return SALOMEDS_TextHighlightColorAttribute::GetID();
95    else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 )             return SALOMEDS_PixMapAttribute::GetID();
96    else if (strcmp(aTypeOfAttribute, "AttributeTreeNode") == 0 )           return TDataStd_TreeNode::GetDefaultTreeID();
97    else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 )            return SALOMEDS_LocalIDAttribute::GetID();
98    else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 )             return SALOMEDS_TargetAttribute::GetID();
99    else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 )     return SALOMEDS_TableOfIntegerAttribute::GetID();
100    else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 )        return SALOMEDS_TableOfRealAttribute::GetID();
101    else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 )      return SALOMEDS_TableOfStringAttribute::GetID();
102    else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 )    return SALOMEDS_StudyPropertiesAttribute::GetID();
103    else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 )       return SALOMEDS_PythonObjectAttribute::GetID();
104    else if (strcmp(aTypeOfAttribute, "AttributeUserID") == 0 )             return SALOMEDS_AttributeUserID_i::DefaultID();
105    else if (strncmp(aTypeOfAttribute,"AttributeTreeNodeGUID",21) == 0) {
106      char* aGUIDString = new char[40];
107      sprintf(aGUIDString, &(aTypeOfAttribute[21]));
108      Standard_GUID aGUID = Standard_GUID(aGUIDString); // create tree node GUID by name
109      delete(aGUIDString);
110      return aGUID;
111    }
112    else Standard_NoSuchObject::Raise("SALOMEDS_SObject_i::ReturnGUIDForAttribute");
113 }
114
115 //============================================================================
116 /*! Function : AttributeIDToType
117  *  Purpose  : 
118  */
119 //============================================================================
120 char* SALOMEDS_SObject_i::AttributeIDToType(Standard_GUID ID)
121 {
122   if      (ID == TDataStd_Name::GetID())                        return "AttributeName";
123   else if (ID == TDataStd_Comment::GetID())                     return "AttributeComment";
124   else if (ID == SALOMEDS_IORAttribute::GetID())                return "AttributeIOR"; 
125   else if (ID == SALOMEDS_PersRefAttribute::GetID())            return "AttributePersistentRef";
126   else if (ID == TDataStd_Real::GetID())                        return "AttributeReal";
127   else if (ID == TDataStd_Integer::GetID())                     return "AttributeInteger";
128   else if (ID == SALOMEDS_SequenceOfRealAttribute::GetID())     return "AttributeSequenceOfReal";
129   else if (ID == SALOMEDS_SequenceOfIntegerAttribute::GetID())  return "AttributeSequenceOfInteger";
130   else if (ID == SALOMEDS_DrawableAttribute::GetID())           return "AttributeDrawable";
131   else if (ID == SALOMEDS_SelectableAttribute::GetID())         return "AttributeSelectable";
132   else if (ID == SALOMEDS_ExpandableAttribute::GetID())         return "AttributeExpandable";
133   else if (ID == SALOMEDS_OpenedAttribute::GetID())             return "AttributeOpened";
134   else if (ID == SALOMEDS_TextColorAttribute::GetID())          return "AttributeTextColor";
135   else if (ID == SALOMEDS_TextHighlightColorAttribute::GetID()) return "AttributeTextHighlightColor";
136   else if (ID == SALOMEDS_PixMapAttribute::GetID())             return "AttributePixMap";
137   else if (ID == TDataStd_TreeNode::GetDefaultTreeID())         return "AttributeTreeNode";
138   else if (ID == SALOMEDS_LocalIDAttribute::GetID())            return "AttributeLocalID";
139   else if (ID == SALOMEDS_TargetAttribute::GetID())             return "AttributeTarget";
140   else if (ID == SALOMEDS_TableOfIntegerAttribute::GetID())     return "AttributeTableOfInteger";
141   else if (ID == SALOMEDS_TableOfRealAttribute::GetID())        return "AttributeTableOfReal";
142   else if (ID == SALOMEDS_TableOfStringAttribute::GetID())      return "AttributeTableOfString";
143   else if (ID == SALOMEDS_StudyPropertiesAttribute::GetID())    return "AttributeStudyProperties";
144   else if (ID == SALOMEDS_PythonObjectAttribute::GetID())       return "AttributePythonObject";
145   else if (ID == SALOMEDS_AttributeUserID_i::DefaultID())       return "AttributeUserID";
146   // 08.01.2003 mpv: this method must be called only for attributes with constant GUID
147   else Standard_NoSuchObject::Raise("SALOMEDS_SObject_i::AttributeIDToType");
148 }
149
150
151 //============================================================================
152 /*! Function : constructor
153  *  Purpose  : 
154  */
155 //============================================================================
156 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const TDF_Label lab, CORBA::ORB_ptr orb)
157   :_lab(lab)
158 {
159   _orb = CORBA::ORB::_duplicate(orb);
160   _value = NULL;
161   _type = NULL;
162   _name = NULL;
163   _liste_ba_type.resize(0);
164 }
165   
166
167 //============================================================================
168 /*! Function : destructor
169  *  Purpose  : 
170  */
171 //============================================================================
172 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
173 {
174   CORBA::string_free(_value);
175   CORBA::string_free(_type);
176   CORBA::string_free(_name);
177 }
178   
179   
180 //============================================================================
181 /*! Function :
182  *  Purpose  : 
183  */
184 //============================================================================
185 char* SALOMEDS_SObject_i::GetID()
186 {
187   TCollection_AsciiString anEntry;
188   TDF_Tool::Entry (_lab,anEntry);
189   return CORBA::string_dup(anEntry.ToCString());
190 }
191   
192 //============================================================================
193 /*! Function :
194  *  Purpose  : 
195  */
196 //============================================================================
197 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
198 {
199   TDF_Label LF = _lab;
200   while (!SALOMEDS_SComponent_i::IsA(LF) && !LF.IsRoot()) {
201     LF = LF.Father();
202   }
203   SALOMEDS_SComponent_i *  so_servant = new SALOMEDS_SComponent_i (LF,_orb);
204   SALOMEDS::SComponent_var so;
205   so= SALOMEDS::SComponent::_narrow(so_servant->SComponent::_this()); 
206   return so;
207 }
208   
209 //============================================================================
210 /*! Function :
211  *  Purpose  : 
212  */
213 //============================================================================
214 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
215 {
216   TDF_Label LF = _lab.Father();
217
218   SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (LF,_orb);
219   SALOMEDS::SObject_var so = SALOMEDS::SObject::_narrow(so_servant->_this()); 
220   return so;
221 }
222
223 //============================================================================
224 /*! Function :
225  *  Purpose  : 
226  */
227 //============================================================================
228 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
229 {
230   TDF_Label Root = _lab.Root();
231   Handle(SALOMEDS_IORAttribute) Att;
232   char* IOR;
233   if (Root.FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){
234     TCollection_AsciiString ch(Att->Get());
235     IOR = CORBA::string_dup(ch.ToCString());
236     CORBA::Object_var obj = _orb->string_to_object(IOR);
237     SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
238     ASSERT(!CORBA::is_nil(Study));
239     return SALOMEDS::Study::_duplicate(Study); //return Study = abort...
240   }
241   INFOS("Problem GetStudy");
242   return SALOMEDS::Study::_nil();
243 }
244
245 //============================================================================
246 /*! Function : FindAttribute
247  *  Purpose  : Find attribute of given type on this SObject
248  */
249 //============================================================================
250 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute, 
251                                                   const char* aTypeOfAttribute)
252 {
253   Handle(TDF_Attribute) anAttr;
254   Standard_Boolean found = _lab.FindAttribute(SALOMEDS_SObject_i::ReturnGUIDForAttribute(aTypeOfAttribute), anAttr);
255   if (found) {
256     if (strcmp(aTypeOfAttribute, "AttributeReal") == 0 )  {
257       SALOMEDS_AttributeReal_i* Attr = new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
258       anAttribute = Attr->AttributeReal::_this();
259       return Standard_True;
260     }
261     else if (strcmp(aTypeOfAttribute, "AttributeInteger") == 0 )  {
262       SALOMEDS_AttributeInteger_i* Attr = new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
263       anAttribute = Attr->AttributeInteger::_this();
264       return Standard_True;
265     }
266     else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfReal") == 0 )  {
267       SALOMEDS_AttributeSequenceOfReal_i* Attr = new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
268       anAttribute = Attr->AttributeSequenceOfReal::_this();
269       return Standard_True;
270     }
271     else if (strcmp(aTypeOfAttribute, "AttributeSequenceOfInteger") == 0 )  {
272       SALOMEDS_AttributeSequenceOfInteger_i* Attr = new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
273       anAttribute = Attr->AttributeSequenceOfInteger::_this();
274       return Standard_True;
275     }
276     else if (strcmp(aTypeOfAttribute, "AttributeName") == 0 ) {
277       SALOMEDS_AttributeName_i* Attr = new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
278       anAttribute = Attr->AttributeName::_this();
279       return Standard_True;
280     }
281     else if (strcmp(aTypeOfAttribute, "AttributeComment") == 0 ) {
282       SALOMEDS_AttributeComment_i* Attr = new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
283       anAttribute = Attr->AttributeComment::_this();
284       return Standard_True;
285     }
286     else if (strcmp(aTypeOfAttribute, "AttributeIOR") == 0 ) {
287       SALOMEDS_AttributeIOR_i* Attr = new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
288       anAttribute = Attr->AttributeIOR::_this();
289       return Standard_True;
290     }
291     else if (strcmp(aTypeOfAttribute, "AttributePersistentRef") == 0 )  {
292       SALOMEDS_AttributePersistentRef_i* Attr = new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
293       anAttribute = Attr->AttributePersistentRef::_this();
294       return Standard_True;
295     }
296     else if (strcmp(aTypeOfAttribute, "AttributeDrawable") == 0 )  {
297       SALOMEDS_AttributeDrawable_i* Attr = new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
298       anAttribute = Attr->AttributeDrawable::_this();
299       return Standard_True;
300     }
301     else if (strcmp(aTypeOfAttribute, "AttributeSelectable") == 0 )  {
302       SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
303       anAttribute = Attr->AttributeSelectable::_this();
304       return Standard_True;
305     }
306     else if (strcmp(aTypeOfAttribute, "AttributeExpandable") == 0 )  {
307       SALOMEDS_AttributeExpandable_i* Attr = new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
308       anAttribute = Attr->AttributeExpandable::_this();
309       return Standard_True;
310     }
311     else if (strcmp(aTypeOfAttribute, "AttributeOpened") == 0 )  {
312       SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
313       anAttribute = Attr->AttributeOpened::_this();
314       return Standard_True;
315     }
316     else if (strcmp(aTypeOfAttribute, "AttributeTextColor") == 0 )  {
317       SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
318       anAttribute = Attr->AttributeTextColor::_this();
319       return Standard_True;
320     }
321     else if (strcmp(aTypeOfAttribute, "AttributeTextHighlightColor") == 0 )  {
322       SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
323       anAttribute = Attr->AttributeTextHighlightColor::_this();
324       return Standard_True;
325     }
326     else if (strcmp(aTypeOfAttribute, "AttributePixMap") == 0 )  {
327       SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
328       anAttribute = Attr->AttributePixMap::_this();
329       return Standard_True;
330     }
331     else if (strncmp(aTypeOfAttribute, "AttributeTreeNode",17) == 0 )  {
332       SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
333       anAttribute = Attr->AttributeTreeNode::_this();
334       return Standard_True;
335     }
336     else if (strcmp(aTypeOfAttribute, "AttributeLocalID") == 0 )  {
337       SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
338       anAttribute = Attr->AttributeLocalID::_this();
339       return Standard_True;
340     }
341     else if (strncmp(aTypeOfAttribute, "AttributeUserID",15) == 0 )  {
342       SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
343       anAttribute = Attr->AttributeUserID::_this();
344       return Standard_True;
345     }
346     else if (strcmp(aTypeOfAttribute, "AttributeTarget") == 0 )  {
347       SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
348       anAttribute = Attr->AttributeTarget::_this();
349       return Standard_True;
350     }
351     else if (strcmp(aTypeOfAttribute, "AttributeTableOfInteger") == 0 )  {
352       SALOMEDS_AttributeTableOfInteger_i* Attr = new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
353       anAttribute = Attr->AttributeTableOfInteger::_this();
354       return Standard_True;
355     }
356     else if (strcmp(aTypeOfAttribute, "AttributeTableOfReal") == 0 )  {
357       SALOMEDS_AttributeTableOfReal_i* Attr = new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
358       anAttribute = Attr->AttributeTableOfReal::_this();
359       return Standard_True;
360     }
361     else if (strcmp(aTypeOfAttribute, "AttributeTableOfString") == 0 )  {
362       SALOMEDS_AttributeTableOfString_i* Attr = new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
363       anAttribute = Attr->AttributeTableOfString::_this();
364       return Standard_True;
365     }
366     else if (strcmp(aTypeOfAttribute, "AttributeStudyProperties") == 0 )  {
367       SALOMEDS_AttributeStudyProperties_i* Attr = new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
368       anAttribute = Attr->AttributeStudyProperties::_this();
369       return Standard_True;
370     }
371     else if (strcmp(aTypeOfAttribute, "AttributePythonObject") == 0 )  {
372       SALOMEDS_AttributePythonObject_i* Attr = new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
373       anAttribute = Attr->AttributePythonObject::_this();
374       return Standard_True;
375     }
376   } else return Standard_False;
377 }
378
379 //============================================================================
380 /*! Function : GetAllAttributes
381  *  Purpose  : Returns list of all attributes for this sobject
382  */
383 //============================================================================
384
385 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
386 {
387   Standard_Integer NumAttr = _lab.NbAttributes();
388   SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
389   SeqOfAttr->length(NumAttr);
390   if (NumAttr != 0) {
391     Standard_Integer i = 0;
392     for(TDF_AttributeIterator iter(_lab);iter.More();iter.Next()) {
393       Handle(TDF_Attribute) anAttr = iter.Value();
394       SALOMEDS::GenericAttribute_var anAttribute;
395       if (ReturnGUIDForAttribute("AttributeReal") == anAttr->ID()) {
396         SALOMEDS_AttributeReal_i* Attr= new SALOMEDS_AttributeReal_i(Handle(TDataStd_Real)::DownCast(anAttr), _orb);
397         anAttribute = Attr->AttributeReal::_this();
398       } 
399       else if (ReturnGUIDForAttribute("AttributeInteger") == anAttr->ID()) {
400         SALOMEDS_AttributeInteger_i* Attr= new SALOMEDS_AttributeInteger_i(Handle(TDataStd_Integer)::DownCast(anAttr), _orb);
401         anAttribute = Attr->AttributeInteger::_this();
402       } 
403       else if (ReturnGUIDForAttribute("AttributeSequenceOfReal") == anAttr->ID()) {
404         SALOMEDS_AttributeSequenceOfReal_i* Attr= new SALOMEDS_AttributeSequenceOfReal_i(Handle(SALOMEDS_SequenceOfRealAttribute)::DownCast(anAttr), _orb);
405         anAttribute = Attr->AttributeSequenceOfReal::_this();
406       } 
407       else if (ReturnGUIDForAttribute("AttributeSequenceOfInteger") == anAttr->ID()) {
408         SALOMEDS_AttributeSequenceOfInteger_i* Attr= new SALOMEDS_AttributeSequenceOfInteger_i(Handle(SALOMEDS_SequenceOfIntegerAttribute)::DownCast(anAttr), _orb);
409         anAttribute = Attr->AttributeSequenceOfInteger::_this();
410       } 
411       else if (ReturnGUIDForAttribute("AttributeName") == anAttr->ID()) {
412         SALOMEDS_AttributeName_i* Attr= new SALOMEDS_AttributeName_i(Handle(TDataStd_Name)::DownCast(anAttr), _orb);
413         anAttribute = Attr->AttributeName::_this();
414       } 
415       else if (ReturnGUIDForAttribute("AttributeComment") == anAttr->ID()) {
416         SALOMEDS_AttributeComment_i* Attr= new SALOMEDS_AttributeComment_i(Handle(TDataStd_Comment)::DownCast(anAttr), _orb);
417         anAttribute = Attr->AttributeComment::_this();
418       } 
419       else if (ReturnGUIDForAttribute("AttributeIOR") == anAttr->ID()) {
420         SALOMEDS_AttributeIOR_i* Attr= new SALOMEDS_AttributeIOR_i(Handle(SALOMEDS_IORAttribute)::DownCast(anAttr), _orb);
421         anAttribute = Attr->AttributeIOR::_this();
422       } 
423       else if (ReturnGUIDForAttribute("AttributePersistentRef") == anAttr->ID()) {
424         SALOMEDS_AttributePersistentRef_i* Attr= new SALOMEDS_AttributePersistentRef_i(Handle(SALOMEDS_PersRefAttribute)::DownCast(anAttr), _orb);
425         anAttribute = Attr->AttributePersistentRef::_this();
426       }
427       else if (ReturnGUIDForAttribute("AttributeDrawable") == anAttr->ID()) {
428         SALOMEDS_AttributeDrawable_i* Attr= new SALOMEDS_AttributeDrawable_i(Handle(SALOMEDS_DrawableAttribute)::DownCast(anAttr), _orb);
429         anAttribute = Attr->AttributeDrawable::_this();
430       } 
431       else if (ReturnGUIDForAttribute("AttributeSelectable") == anAttr->ID()) {
432         SALOMEDS_AttributeSelectable_i* Attr= new SALOMEDS_AttributeSelectable_i(Handle(SALOMEDS_SelectableAttribute)::DownCast(anAttr), _orb);
433         anAttribute = Attr->AttributeSelectable::_this();
434       } 
435       else if (ReturnGUIDForAttribute("AttributeExpandable") == anAttr->ID()) {
436         SALOMEDS_AttributeExpandable_i* Attr= new SALOMEDS_AttributeExpandable_i(Handle(SALOMEDS_ExpandableAttribute)::DownCast(anAttr), _orb);
437         anAttribute = Attr->AttributeExpandable::_this();
438       } 
439       else if (ReturnGUIDForAttribute("AttributeOpened") == anAttr->ID()) {
440         SALOMEDS_AttributeOpened_i* Attr= new SALOMEDS_AttributeOpened_i(Handle(SALOMEDS_OpenedAttribute)::DownCast(anAttr), _orb);
441         anAttribute = Attr->AttributeOpened::_this();
442       } 
443       else if (ReturnGUIDForAttribute("AttributeTextColor") == anAttr->ID()) {
444         SALOMEDS_AttributeTextColor_i* Attr= new SALOMEDS_AttributeTextColor_i(Handle(SALOMEDS_TextColorAttribute)::DownCast(anAttr), _orb);
445         anAttribute = Attr->AttributeTextColor::_this();
446       } 
447       else if (ReturnGUIDForAttribute("AttributeTextHighlightColor") == anAttr->ID()) {
448         SALOMEDS_AttributeTextHighlightColor_i* Attr= new SALOMEDS_AttributeTextHighlightColor_i(Handle(SALOMEDS_TextHighlightColorAttribute)::DownCast(anAttr), _orb);
449         anAttribute = Attr->AttributeTextHighlightColor::_this();
450       } 
451       else if (ReturnGUIDForAttribute("AttributePixMap") == anAttr->ID()) {
452         SALOMEDS_AttributePixMap_i* Attr= new SALOMEDS_AttributePixMap_i(Handle(SALOMEDS_PixMapAttribute)::DownCast(anAttr), _orb);
453         anAttribute = Attr->AttributePixMap::_this();
454       } 
455       else if (ReturnGUIDForAttribute("AttributeTreeNode") == anAttr->ID()) {
456         SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
457         anAttribute = Attr->AttributeTreeNode::_this();
458       } 
459       else if (ReturnGUIDForAttribute("AttributeLocalID") == anAttr->ID()) {
460         SALOMEDS_AttributeLocalID_i* Attr= new SALOMEDS_AttributeLocalID_i(Handle(SALOMEDS_LocalIDAttribute)::DownCast(anAttr), _orb);
461         anAttribute = Attr->AttributeLocalID::_this();
462       } 
463       else if (ReturnGUIDForAttribute("AttributeTarget") == anAttr->ID()) {
464         SALOMEDS_AttributeTarget_i* Attr= new SALOMEDS_AttributeTarget_i(Handle(SALOMEDS_TargetAttribute)::DownCast(anAttr), _orb);
465         anAttribute = Attr->AttributeTarget::_this();
466       } 
467       else if (ReturnGUIDForAttribute("AttributeTableOfInteger") == anAttr->ID()) {
468         SALOMEDS_AttributeTableOfInteger_i* Attr= new SALOMEDS_AttributeTableOfInteger_i(Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(anAttr), _orb);
469         anAttribute = Attr->AttributeTableOfInteger::_this();
470       } 
471       else if (ReturnGUIDForAttribute("AttributeTableOfReal") == anAttr->ID()) {
472         SALOMEDS_AttributeTableOfReal_i* Attr= new SALOMEDS_AttributeTableOfReal_i(Handle(SALOMEDS_TableOfRealAttribute)::DownCast(anAttr), _orb);
473         anAttribute = Attr->AttributeTableOfReal::_this();
474       } 
475       else if (ReturnGUIDForAttribute("AttributeTableOfString") == anAttr->ID()) {
476         SALOMEDS_AttributeTableOfString_i* Attr= new SALOMEDS_AttributeTableOfString_i(Handle(SALOMEDS_TableOfStringAttribute)::DownCast(anAttr), _orb);
477         anAttribute = Attr->AttributeTableOfString::_this();
478       } 
479       else if (ReturnGUIDForAttribute("AttributeStudyProperties") == anAttr->ID()) {
480         SALOMEDS_AttributeStudyProperties_i* Attr= new SALOMEDS_AttributeStudyProperties_i(Handle(SALOMEDS_StudyPropertiesAttribute)::DownCast(anAttr), _orb);
481         anAttribute = Attr->AttributeStudyProperties::_this();
482       } 
483       else if (ReturnGUIDForAttribute("AttributePythonObject") == anAttr->ID()) {
484         SALOMEDS_AttributePythonObject_i* Attr= new SALOMEDS_AttributePythonObject_i(Handle(SALOMEDS_PythonObjectAttribute)::DownCast(anAttr), _orb);
485         anAttribute = Attr->AttributePythonObject::_this();
486       } 
487       else if (!Handle(TDataStd_UAttribute)::DownCast(anAttr).IsNull()) {
488         SALOMEDS_AttributeUserID_i* Attr= new SALOMEDS_AttributeUserID_i(Handle(TDataStd_UAttribute)::DownCast(anAttr), _orb);
489         anAttribute = Attr->AttributeUserID::_this();
490       } 
491       else if (!Handle(TDataStd_TreeNode)::DownCast(anAttr).IsNull()) {
492         SALOMEDS_AttributeTreeNode_i* Attr= new SALOMEDS_AttributeTreeNode_i(Handle(TDataStd_TreeNode)::DownCast(anAttr), _orb);
493         anAttribute = Attr->AttributeTreeNode::_this();
494       } else {
495         // references attributes, for an example, never returns
496         continue;
497       }
498
499       SeqOfAttr[i] =  anAttribute;
500       i++;
501     }
502   }
503   return SeqOfAttr._retn();
504 }
505
506
507 //============================================================================
508 /*! Function : ReferencedObject
509  *  Purpose  : 
510  */
511 //============================================================================
512 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
513 {
514   Handle(TDF_Reference) Ref;
515   if (!_lab.FindAttribute(TDF_Reference::GetID(),Ref))
516     return false;
517   
518   SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (Ref->Get(),_orb);
519   obj  = SALOMEDS::SObject::_narrow(so_servant->_this()); 
520   return true;
521 }
522
523 //============================================================================
524 /*! Function :
525  *  Purpose  : 
526  */
527 //============================================================================
528 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(long atag, SALOMEDS::SObject_out obj)
529 {
530   TDF_Label L = _lab.FindChild(atag,false);
531   if (L.IsNull()) return false;
532   
533   SALOMEDS_SObject_i *  so_servant = new SALOMEDS_SObject_i (L,_orb);
534   obj  = SALOMEDS::SObject::_narrow(so_servant->_this()); 
535   return true;
536     
537 }  
538
539 //============================================================================
540 /*! Function :
541  *  Purpose  : 
542  */
543 //============================================================================
544 char* SALOMEDS_SObject_i::Name()
545 {
546   return CORBA::string_dup(_name);
547 }
548   
549 //============================================================================
550 /*! Function :
551  *  Purpose  : 
552  */
553 //============================================================================
554 void  SALOMEDS_SObject_i::Name(const char* name)
555 {
556   _name = CORBA::string_dup(name);
557 }
558   
559 //============================================================================
560 /*! Function :
561  *  Purpose  : 
562  */
563 //============================================================================
564 CORBA::Short SALOMEDS_SObject_i::Tag()
565 {
566   return _lab.Tag();
567 }