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