0030380: Exception while reading Step-file
[occt.git] / src / StepData / StepData_Field.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <Interface_HArray1OfHAsciiString.hxx>
16 #include <Interface_Macros.hxx>
17 #include <Standard_Transient.hxx>
18 #include <StepData_Field.hxx>
19 #include <StepData_SelectInt.hxx>
20 #include <StepData_SelectMember.hxx>
21 #include <StepData_SelectNamed.hxx>
22 #include <StepData_SelectReal.hxx>
23 #include <TCollection_HAsciiString.hxx>
24 #include <TColStd_HArray1OfInteger.hxx>
25 #include <TColStd_HArray1OfReal.hxx>
26 #include <TColStd_HArray1OfTransient.hxx>
27 #include <TColStd_HArray2OfInteger.hxx>
28 #include <TColStd_HArray2OfReal.hxx>
29 #include <TColStd_HArray2OfTransient.hxx>
30
31 //  Le kind code le type de donnee, le mode d acces (direct ou via Select),
32 //  l arite (simple, liste, carre)
33 //  Valeurs pour Kind : 0 = Clear/Undefined
34 //  KindInteger KindBoolean KindLogical KindEnum KindReal KindString KindEntity
35 //  + KindSelect qui s y substitue et peut s y combiner
36 //  + KindList et KindList2  qui peuvent s y combiner
37 //  (sur masque KindArity et decalage ShiftArity)
38 #define KindInteger 1
39 #define KindBoolean 2
40 #define KindLogical 3
41 #define KindEnum    4
42 #define KindReal    5
43 #define KindString  6
44 #define KindEntity  7
45 #define KindAny     8
46 #define KindDerived 9
47
48 #define KindType    15
49 #define KindSelect  16
50 #define KindArity   192
51 #define KindList    64
52 #define KindList2   128
53 #define ShiftArity  6
54
55 static Standard_Integer TrueKind (const Standard_Integer kind)
56 {  return (kind & KindType);  }
57
58
59     StepData_Field::StepData_Field ()    {  Clear();  }
60
61     StepData_Field::StepData_Field
62   (const StepData_Field& other, const Standard_Boolean copy)
63 {
64   if (copy)  {  CopyFrom(other);  return;  }
65   thekind = other.Kind(Standard_False);  theint = other.Int();
66   thereal = other.Real();  theany = other.Transient();
67 }
68
69     void  StepData_Field::CopyFrom (const StepData_Field& other)
70 {
71   thekind = other.Kind(Standard_False);  theint = other.Int();
72   thereal = other.Real();  theany = other.Transient();
73   if (thekind == KindString || thekind == KindEnum) {
74     DeclareAndCast(TCollection_HAsciiString,str,theany);
75     if (!str.IsNull()) theany = new TCollection_HAsciiString (str->ToCString());
76     return;
77   }
78   if (thekind == KindSelect) {
79 //  Differents cas
80     DeclareAndCast(StepData_SelectReal,sr,theany);
81     if (!sr.IsNull()) {
82       Standard_Real val = sr->Real();
83       sr = new StepData_SelectReal;  sr->SetReal(val);
84       theany = sr;  return;
85     }
86     DeclareAndCast(StepData_SelectInt,si,theany);
87     if (!si.IsNull()) {
88       Standard_Integer ival = si->Int(), ik = si->Kind();
89       si = new StepData_SelectInt;  si->SetKind(ik);  si->SetInt(ival);
90       theany = si;  return;
91     }
92     DeclareAndCast(StepData_SelectNamed,sn,theany);
93     if (!sn.IsNull()) {
94       Handle(StepData_SelectNamed) sn2 = new StepData_SelectNamed;
95       if (sn->HasName()) sn2->SetName(sn2->Name());
96       sn2->CField().CopyFrom(*this);
97       theany = sn2;  return;
98     }
99   }
100 //    Les listes ...
101   if ((thekind & KindArity) == KindList)  {
102     Standard_Integer i, low, up;
103     DeclareAndCast(TColStd_HArray1OfInteger,hi,theany);
104     if (!hi.IsNull()) {
105       low = hi->Lower();  up = hi->Upper();
106       Handle(TColStd_HArray1OfInteger) hi2 = new TColStd_HArray1OfInteger (low,up);
107       for (i = low; i <= up; i ++) hi2->SetValue (i,hi->Value(i));
108       return;
109     }
110     DeclareAndCast(TColStd_HArray1OfReal,hr,theany);
111     if (!hr.IsNull()) {
112       low = hr->Lower();  up = hr->Upper();
113       Handle(TColStd_HArray1OfReal) hr2 = new TColStd_HArray1OfReal (low,up);
114       for (i = low; i <= up; i ++) hr2->SetValue (i,hr->Value(i));
115       return;
116     }
117     DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
118     if (!hs.IsNull()) {
119       low = hs->Lower();  up = hs->Upper();
120       Handle(Interface_HArray1OfHAsciiString) hs2 = new Interface_HArray1OfHAsciiString (low,up);
121       for (i = low; i <= up; i ++) hs2->SetValue (i,new TCollection_HAsciiString(hs->Value(i)));
122       return;
123     }
124     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
125     if (!ht.IsNull()) {
126       low = ht->Lower();  up = ht->Upper();
127       Handle(TColStd_HArray1OfTransient) ht2 = new TColStd_HArray1OfTransient (low,up);
128 //  faudrait reprendre les cas SelectMember ...
129       for (i = low; i <= up; i ++) ht2->SetValue (i,ht->Value(i));
130       return;
131     }
132   }
133 //    Reste la liste 2 ...
134 //  if ((thekind & KindArity) == KindList2) {
135 //    DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
136 //  }
137 }
138
139
140     void  StepData_Field::Clear (const Standard_Integer kind)
141 {
142   thekind = kind;
143   theint = 0; thereal = 0.;  theany.Nullify();
144 }
145
146     void  StepData_Field::SetDerived ()
147       {  Clear(KindDerived);  }
148
149     void  StepData_Field::SetInt (const Standard_Integer val)
150 {
151   if (thekind == KindSelect) {
152     DeclareAndCast(StepData_SelectMember,sm,theany);
153     if (!sm.IsNull())  {  sm->SetInteger(val);  return;  }
154   }
155   if (thekind == KindInteger || thekind == KindBoolean ||
156       thekind == KindLogical || thekind == KindEnum)  theint = val;
157 //  else ?
158 }
159
160     void  StepData_Field::SetInteger (const Standard_Integer val)
161 {
162   if (thekind == KindSelect) {
163     DeclareAndCast(StepData_SelectMember,sm,theany);
164     if (!sm.IsNull())  {  sm->SetInteger(val);  return;  }
165   }
166   Clear(KindInteger);
167   theint = val;
168 }
169
170     void  StepData_Field::SetBoolean (const Standard_Boolean val)
171 {
172   if (thekind == KindSelect) {
173     DeclareAndCast(StepData_SelectMember,sm,theany);
174     if (!sm.IsNull())  {  sm->SetBoolean(val);  return;  }
175   }
176   Clear(KindBoolean);
177   theint = (val ? 1 : 0);
178 }
179
180     void  StepData_Field::SetLogical (const StepData_Logical val)
181 {
182   if (thekind == KindSelect) {
183     DeclareAndCast(StepData_SelectMember,sm,theany);
184     if (!sm.IsNull())  {  sm->SetLogical(val);  return;  }
185   }
186   Clear(KindLogical);
187   if (val == StepData_LFalse)   theint = 0;
188   if (val == StepData_LTrue)    theint = 1;
189   if (val == StepData_LUnknown) theint = 2;
190 }
191
192     void  StepData_Field::SetReal (const Standard_Real val)
193 {
194   if (thekind == KindSelect) {
195     DeclareAndCast(StepData_SelectMember,sm,theany);
196     if (!sm.IsNull())  {  sm->SetReal(val);  return;  }
197   }
198   Clear(KindReal);
199   thereal = val;
200 }
201
202     void  StepData_Field::SetString (const Standard_CString val)
203 {
204   if (thekind == KindSelect) {
205     DeclareAndCast(StepData_SelectMember,sm,theany);
206     if (!sm.IsNull())  {  sm->SetString (val);  return;  }
207   }
208   if (thekind != KindEnum) Clear(KindString);
209   theany = new TCollection_HAsciiString(val);
210 }
211
212     void  StepData_Field::SetEnum
213   (const Standard_Integer val, const Standard_CString text)
214 {
215   Clear(KindEnum);
216   SetInt(val);
217   if (text && text[0] != '\0') SetString(text);
218 }
219
220     void  StepData_Field::SetSelectMember
221   (const Handle(StepData_SelectMember)& val)
222 {
223   if (val.IsNull()) return;
224   Clear (KindSelect);
225   theany = val;
226 }
227
228     void  StepData_Field::SetEntity (const Handle(Standard_Transient)& val)
229       {  Clear(KindEntity);  theany = val;  }
230
231     void  StepData_Field::SetEntity ()
232       {  Handle(Standard_Transient) nulent;  SetEntity(nulent);  }
233
234     void  StepData_Field::SetList
235   (const Standard_Integer size, const Standard_Integer first)
236 {
237 //  ATTENTION, on ne traite pas l agrandissement ...
238
239   theint = size;  thereal = 0.0;  theany.Nullify();  // ?? agrandissement ??
240   switch (thekind) {
241   case KindInteger :
242   case KindBoolean :
243   case KindLogical : theany = new TColStd_HArray1OfInteger(first,first+size-1);
244                      break;
245   case KindReal    : theany = new TColStd_HArray1OfReal (first,first+size-1);
246                      break;
247   case KindEnum    :
248   case KindString  : theany = new Interface_HArray1OfHAsciiString (first,first+size-1);
249                      break;
250 //  default : en particulier si "non specifie" (any)
251   default          : theany = new TColStd_HArray1OfTransient(first,first+size-1);
252   }
253   if (thekind == 0) thekind = KindAny;
254   thekind |= KindList;
255 }
256
257     void  StepData_Field::SetList2
258   (const Standard_Integer siz1, const Standard_Integer siz2,
259    const Standard_Integer f1,   const Standard_Integer f2)
260 {
261 //  ATTENTION, on ne traite pas l agrandissement ...
262
263   theint = siz1;  thereal = Standard_Real(siz2);  theany.Nullify();
264   Standard_Integer kind = thekind;
265   if (thekind == KindSelect) {
266     DeclareAndCast(StepData_SelectMember,sm,theany);
267     if (!sm.IsNull())  kind = sm->Kind();
268   }
269   switch (kind) {
270   case KindInteger :
271   case KindBoolean :
272   case KindLogical : theany = new TColStd_HArray2OfInteger(f1,f1+siz1-1,f2,f2+siz2-1);
273                      break;
274   case KindReal    : theany = new TColStd_HArray2OfReal (f1,f1+siz1-1,f2,f2+siz2-1);
275                      break;
276   case KindEnum    :
277   case KindString  : theany = new TColStd_HArray2OfTransient (f1,f1+siz1-1,f2,f2+siz2-1);
278                      break;
279 //  default : en particulier si "non specifie" (any)
280   default          : theany = new TColStd_HArray2OfTransient(f1,f1+siz1-1,f2,f2+siz2-1);
281   }
282   if (thekind == 0) thekind = KindAny;
283   thekind |= KindList2;
284 }
285
286
287     void  StepData_Field::Set (const Handle(Standard_Transient)& val)
288 {
289   Standard_Integer kind = thekind;
290   Clear();  theany = val;
291   if (val.IsNull())  return;
292   if (val->IsKind(STANDARD_TYPE(TCollection_HAsciiString)))
293     {  thekind = KindString;  return;  }
294   DeclareAndCast(StepData_SelectMember,sm,val);
295   if (!sm.IsNull())  {  thekind = KindSelect;  return;  }
296   DeclareAndCast(TColStd_HArray1OfInteger,hi,val);
297   if (!hi.IsNull())
298     {  if (kind == 0) kind = KindInteger;
299        thekind = kind        | KindList;  theint = hi->Length();  return;  }
300   DeclareAndCast(TColStd_HArray1OfReal,hr,val);
301   if (!hr.IsNull())
302     {  thekind = KindReal    | KindList;  theint = hr->Length();  return;  }
303   DeclareAndCast(Interface_HArray1OfHAsciiString,hs,val);
304   if (!hs.IsNull())
305     {  thekind = KindString  | KindList;  theint = hs->Length();  return;  }
306   DeclareAndCast(TColStd_HArray1OfTransient,ht,val);
307   if (!ht.IsNull())
308     {  if (kind == 0) kind = KindAny;
309        thekind = kind        | KindList;  theint = ht->Length();  return;  }
310   DeclareAndCast(TColStd_HArray2OfInteger,hi2,val);
311   if (!hi2.IsNull())
312     {  if (kind == 0) kind = KindInteger;
313        thekind = kind        | KindList2;  theint = hi2->ColLength();
314        thereal = Standard_Real(hi2->RowLength());  return;  }
315   DeclareAndCast(TColStd_HArray2OfReal,hr2,val);
316   if (!hr2.IsNull())
317     {  thekind = KindInteger | KindList2;  theint = hr2->ColLength();
318        thereal = Standard_Real(hi2->RowLength());  return;  }
319   DeclareAndCast(TColStd_HArray2OfTransient,ht2,val);
320   if (!ht2.IsNull())
321     {  if (kind == 0) kind = KindAny;
322        thekind = kind        | KindList2;  theint = ht2->ColLength();
323        thereal = Standard_Real(hi2->RowLength());  return;  }
324 }
325
326
327     void  StepData_Field::ClearItem (const Standard_Integer num)
328 {
329   DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
330   if (!ht.IsNull()) ht->ChangeValue(num).Nullify();
331   DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
332   if (!hs.IsNull()) hs->ChangeValue(num).Nullify();
333 }
334
335     void  StepData_Field::SetInt
336   (const Standard_Integer num, const Standard_Integer val, const Standard_Integer kind)
337 {
338   DeclareAndCast(TColStd_HArray1OfInteger,hi,theany);
339   if (!hi.IsNull())  {  hi->SetValue(num,val);  return;  }
340 //   Si deja commence sur autre chose, changer et mettre des select
341   DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
342   if (ht.IsNull()) return;  // yena erreur, ou alors OfReal
343   thekind = KindAny | KindList;
344   DeclareAndCast(StepData_SelectMember,sm,ht->Value(num));
345   if (sm.IsNull())  {  sm = new StepData_SelectInt;  ht->SetValue(num,sm);  }
346   sm->SetKind(kind);  sm->SetInt (val);
347 }
348
349     void  StepData_Field::SetInteger
350   (const Standard_Integer num, const Standard_Integer val)
351       {  SetInt (num,val,KindInteger);  }
352
353     void  StepData_Field::SetBoolean
354   (const Standard_Integer num, const Standard_Boolean val)
355       {  SetInt (num, (val ? 1 : 0),KindBoolean);  }
356
357     void  StepData_Field::SetLogical
358   (const Standard_Integer num, const StepData_Logical val)
359 {
360   if (val == StepData_LFalse)   SetInt (num, 0,KindLogical);
361   if (val == StepData_LTrue)    SetInt (num, 1,KindLogical);
362   if (val == StepData_LUnknown) SetInt (num, 2,KindLogical);
363 }
364
365     void  StepData_Field::SetEnum
366   (const Standard_Integer num, const Standard_Integer val, const Standard_CString text)
367 {
368   DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
369   if (ht.IsNull()) { SetInteger (num,val); return; }
370   DeclareAndCast(StepData_SelectMember,sm,ht->Value(num));
371   thekind = KindAny | KindList;
372   if (sm.IsNull()) {  sm = new StepData_SelectNamed;  ht->SetValue(num,sm);  }
373   sm->SetEnum (val,text);
374 }
375
376     void  StepData_Field::SetReal
377   (const Standard_Integer num, const Standard_Real val)
378 {
379   DeclareAndCast(TColStd_HArray1OfReal,hr,theany);
380   if (!hr.IsNull())  {  hr->SetValue(num,val);  return;  }
381 //   Si deja commence sur autre chose, changer et mettre des select
382   DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
383   if (ht.IsNull()) return;  // yena erreur, ou alors OfInteger
384   thekind = KindAny | KindList;
385   DeclareAndCast(StepData_SelectMember,sm,ht->Value(num));
386   if (sm.IsNull())  {  sm = new StepData_SelectReal;  ht->SetValue(num,sm);  }
387   sm->SetReal (val);
388 }
389
390
391     void  StepData_Field::SetString
392   (const Standard_Integer num, const Standard_CString val)
393 {
394   DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
395   if (!hs.IsNull()) { hs->SetValue (num,new TCollection_HAsciiString(val)); return; }
396 //    et si OfInteger ou OfReal ?
397   DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
398   if ( ht.IsNull()) return;
399   thekind = KindAny | KindList;
400   ht->SetValue (num,new TCollection_HAsciiString(val));
401 }
402
403
404     void  StepData_Field::SetEntity
405   (const Standard_Integer num, const Handle(Standard_Transient)& val)
406 {
407   DeclareAndCast(TColStd_HArray1OfTransient,aHt,theany);
408   if (!aHt.IsNull()) { aHt->SetValue (num,val); return; }
409   DeclareAndCast(TColStd_HArray1OfInteger,hi,theany);
410   if (!hi.IsNull()) {
411     Standard_Integer low = hi->Lower(), up = hi->Upper();
412     Handle(TColStd_HArray1OfTransient) ht = new TColStd_HArray1OfTransient(low,up);
413     Handle(StepData_SelectMember) sm;
414     Standard_Integer kind = Kind();
415     for (Standard_Integer i = low; i <= up; i ++) {
416       if (i == num) ht->SetValue(i,val);
417       else {
418         sm = new StepData_SelectInt;
419         sm->SetKind(kind); sm->SetInt(hi->Value(i));
420         ht->SetValue(i,sm);
421       }
422     }
423     thekind = KindAny | KindList;
424     return;
425   }
426   DeclareAndCast(TColStd_HArray1OfReal,hr,theany);
427   if (!hr.IsNull()) {
428     Standard_Integer low = hr->Lower(), up = hr->Upper();
429     Handle(TColStd_HArray1OfTransient) ht = new TColStd_HArray1OfTransient(low,up);
430     Handle(StepData_SelectMember) sm;
431     for (Standard_Integer i = low; i <= up; i ++) {
432       if (i == num) ht->SetValue(i,val);
433       else {
434         sm = new StepData_SelectReal;
435         sm->SetReal(hr->Value(i));
436         ht->SetValue(i,sm);
437       }
438     }
439     thekind = KindAny | KindList;
440     return;
441   }
442   DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
443   if (!hs.IsNull()) {
444     Standard_Integer low = hs->Lower(), up = hs->Upper();
445     Handle(TColStd_HArray1OfTransient) ht = new TColStd_HArray1OfTransient(low,up);
446     for (Standard_Integer i = low; i <= up; i ++) {
447       if (i == num) ht->SetValue(i,val);
448       else ht->SetValue(i,hs->Value(i));
449     }
450     thekind = KindAny | KindList;
451     return;
452   }
453 }
454
455
456 //     QUERIES
457
458     Standard_Boolean  StepData_Field::IsSet
459   (const Standard_Integer n1, const Standard_Integer n2) const
460 {
461   if (thekind == 0) return Standard_False;
462   if (thekind == KindSelect) {
463     DeclareAndCast(StepData_SelectMember,sm,theany);
464     if (sm.IsNull()) return Standard_False;
465     return (sm->Kind() != 0);
466   }
467   if ((thekind & KindArity) == KindList) {
468     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
469     if (!ht.IsNull()) return (!ht->Value(n1).IsNull());
470     DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
471     if (!hs.IsNull()) return (!hs->Value(n1).IsNull());
472   }
473   if ((thekind & KindArity) == KindList2) {
474     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
475     if (!ht.IsNull()) return (!ht->Value(n1,n2).IsNull());
476   }
477   return Standard_True;
478 }
479
480
481     Standard_Integer  StepData_Field::ItemKind
482   (const Standard_Integer n1, const Standard_Integer n2) const
483 {
484   if ((thekind & KindArity) == 0) return Kind(Standard_True);
485   Standard_Integer kind = TrueKind(thekind);    // si Any, evaluer ...
486   if (kind != KindAny) return kind;
487 //  Sinon, chercher un Transient
488   Handle(Standard_Transient) item;
489   if ((thekind & KindArity) == KindList) {
490     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
491     if (!ht.IsNull()) return kind;
492     item = ht->Value(n1);
493   } else if ((thekind & KindArity) == KindList2) {
494     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
495     if (!ht.IsNull()) return kind;
496     item = ht->Value(n1,n2);
497   }
498   if (item.IsNull()) return 0;
499   if (item->IsKind(STANDARD_TYPE(TCollection_HAsciiString))) return KindString;
500   DeclareAndCast(StepData_SelectMember,sm,item);
501   if (sm.IsNull()) return KindEntity;
502   return sm->Kind();
503 }
504
505     Standard_Integer  StepData_Field::Kind (const Standard_Boolean type) const
506 {
507   if (!type) return thekind;
508   if (thekind == KindSelect) {
509     DeclareAndCast(StepData_SelectMember,sm,theany);
510     if (!sm.IsNull())  return TrueKind(sm->Kind());
511   }
512   return TrueKind (thekind);
513 }
514
515
516     Standard_Integer  StepData_Field::Arity () const
517       {  return (thekind & KindArity) >> ShiftArity;  }
518
519     Standard_Integer  StepData_Field::Length (const Standard_Integer index) const
520 {
521   if ((thekind & KindArity) == KindList)  return theint;
522   if ((thekind & KindArity) == KindList2) {
523     if (index == 2) return Standard_Integer (thereal);
524     else return theint;
525   }
526   return 0;
527 }
528
529     Standard_Integer  StepData_Field::Lower (const Standard_Integer index) const
530 {
531   if ((thekind & KindArity) == KindList)  {
532     DeclareAndCast(TColStd_HArray1OfInteger,hi,theany);
533     if (!hi.IsNull()) return hi->Lower();
534     DeclareAndCast(TColStd_HArray1OfReal,hr,theany);
535     if (!hr.IsNull()) return hr->Lower();
536     DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
537     if (!hs.IsNull()) return hs->Lower();
538     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
539     if (!ht.IsNull()) return ht->Lower();
540   }
541   if ((thekind & KindArity) == KindList2) {
542     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
543     if ( ht.IsNull()) return 0;
544     if (index == 1) return ht->LowerCol();
545     if (index == 2) return ht->LowerRow();
546   }
547   return 0;
548 }
549
550     Standard_Integer  StepData_Field::Int () const
551       {  return theint;  }
552
553     Standard_Integer  StepData_Field::Integer
554   (const Standard_Integer n1, const Standard_Integer n2) const
555 {
556   if ((thekind & KindArity) == 0) {
557     if (thekind == KindSelect) {
558       DeclareAndCast(StepData_SelectMember,sm,theany);
559       if (!sm.IsNull()) return sm->Int();
560     }
561     return theint;
562   }
563   if ((thekind & KindArity) == KindList) {
564     DeclareAndCast(TColStd_HArray1OfInteger,hi,theany);
565     if (!hi.IsNull()) return hi->Value(n1);
566     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
567     if (ht.IsNull()) return 0;
568     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1));
569     if (!sm.IsNull()) return sm->Int();
570   }
571   if ((thekind & KindArity) == KindList2) {
572     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
573     if (ht.IsNull()) return 0;
574     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1,n2));
575     if (!sm.IsNull()) return sm->Int();
576   }
577   return 0;
578 }
579
580     Standard_Boolean  StepData_Field::Boolean
581   (const Standard_Integer n1, const Standard_Integer n2) const
582       {  return (Integer(n1,n2) > 0);  }
583
584     StepData_Logical  StepData_Field::Logical
585   (const Standard_Integer n1, const Standard_Integer n2) const
586 {
587   Standard_Integer ival = Integer(n1,n2);
588   if (ival == 0) return StepData_LFalse;
589   if (ival == 1) return StepData_LTrue;
590   return StepData_LUnknown;
591 }
592
593     Standard_Real     StepData_Field::Real
594   (const Standard_Integer n1, const Standard_Integer n2) const
595 {
596   if ((thekind & KindArity) == 0) {
597     if (thekind == KindSelect) {
598       DeclareAndCast(StepData_SelectMember,sm,theany);
599       if (!sm.IsNull()) return sm->Real();
600     }
601     return thereal;
602   }
603   if ((thekind & KindArity) == KindList) {
604     DeclareAndCast(TColStd_HArray1OfReal,hr,theany);
605     if (!hr.IsNull()) return hr->Value(n1);
606     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
607     if (ht.IsNull()) return 0;
608     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1));
609     if (!sm.IsNull()) return sm->Real();
610   }
611   if ((thekind & KindArity) == KindList2) {
612     DeclareAndCast(TColStd_HArray2OfReal,hr,theany);
613     if (!hr.IsNull()) return hr->Value(n1,n2);
614     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
615     if (ht.IsNull()) return 0;
616     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1,n2));
617     if (!sm.IsNull()) return sm->Int();
618   }
619   return 0.0;
620 }
621
622     Standard_CString  StepData_Field::String
623   (const Standard_Integer n1, const Standard_Integer n2) const
624 {
625   if (thekind == KindString || thekind == KindEnum) {
626     DeclareAndCast(TCollection_HAsciiString,str,theany);
627     if (!str.IsNull()) return str->ToCString();
628     else return "";
629   }
630   if (thekind == KindSelect) {
631     DeclareAndCast(StepData_SelectMember,sm,theany);
632     if (!sm.IsNull()) return sm->String();
633   }
634   if ((thekind & KindArity) == KindList) {
635     DeclareAndCast(Interface_HArray1OfHAsciiString,hs,theany);
636     if (!hs.IsNull()) {
637       if (hs->Value(n1).IsNull()) return "";
638       else return hs->Value(n1)->ToCString();
639     }
640     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
641     if (ht.IsNull()) return "";
642     DeclareAndCast(TCollection_HAsciiString,str,ht->Value(n1));
643     if (!str.IsNull()) return str->ToCString();
644     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1));
645     if (!sm.IsNull()) return sm->String();
646   }
647   if ((thekind & KindArity) == KindList2) {
648     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
649     if (ht.IsNull()) return "";
650     DeclareAndCast(TCollection_HAsciiString,str,ht->Value(n1,n2));
651     if (!str.IsNull()) return str->ToCString();
652     DeclareAndCast(StepData_SelectMember,sm,ht->Value(n1,n2));
653     if (!sm.IsNull()) return sm->String();
654   }
655   return "";
656 }
657
658
659     Standard_Integer  StepData_Field::Enum
660   (const Standard_Integer n1, const Standard_Integer n2) const
661       {  return Integer(n1,n2);  }
662
663     Standard_CString  StepData_Field::EnumText
664   (const Standard_Integer n1, const Standard_Integer n2) const
665       {  return String (n1,n2);  }
666
667     Handle(Standard_Transient)  StepData_Field::Entity
668   (const Standard_Integer n1, const Standard_Integer n2) const
669 {
670   Handle(Standard_Transient) nulval;  // null handle
671   if ((thekind & KindArity) == 0) {
672     if (thekind == KindEntity) return theany;
673     return nulval;
674   }
675   if ((thekind & KindArity) == KindList) {
676     DeclareAndCast(TColStd_HArray1OfTransient,ht,theany);
677     if (ht.IsNull()) return nulval;
678     nulval = ht->Value(n1);
679     if (nulval.IsNull()) return nulval;
680     if (nulval->IsKind(STANDARD_TYPE(StepData_SelectMember)) ||
681         nulval->IsKind(STANDARD_TYPE(TCollection_HAsciiString)) )
682       nulval.Nullify();
683     return nulval;
684   }
685   if ((thekind & KindArity) == KindList2) {
686     DeclareAndCast(TColStd_HArray2OfTransient,ht,theany);
687     if (ht.IsNull()) return nulval;
688     nulval = ht->Value(n1,n2);
689     if (nulval.IsNull()) return nulval;
690     if (nulval->IsKind(STANDARD_TYPE(StepData_SelectMember))
691         || nulval->IsKind(STANDARD_TYPE(TCollection_HAsciiString)) )
692       nulval.Nullify();
693     return nulval;
694   }
695   return nulval;
696 }
697
698     Handle(Standard_Transient)  StepData_Field::Transient () const
699       {  return theany;  }