0027532: Errors on reading stp-file
[occt.git] / src / StepData / StepData_Plex.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_Check.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_InterfaceMismatch.hxx>
18 #include <Standard_Type.hxx>
19 #include <StepData_ECDescr.hxx>
20 #include <StepData_Field.hxx>
21 #include <StepData_Plex.hxx>
22 #include <StepData_Simple.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 IMPLEMENT_STANDARD_RTTIEXT(StepData_Plex,StepData_Described)
26
27 static StepData_Field bid;
28
29     StepData_Plex::StepData_Plex  (const Handle(StepData_ECDescr)& descr)
30     : StepData_Described (descr)    {  }
31
32     void  StepData_Plex::Add (const Handle(StepData_Simple)& member)
33       {  themembers.Append (member);  }
34
35     Handle(StepData_ECDescr)  StepData_Plex::ECDescr () const
36       {  return Handle(StepData_ECDescr)::DownCast(Description());  }
37
38
39     Standard_Boolean  StepData_Plex::IsComplex () const
40       {  return Standard_True;  }
41
42     Standard_Boolean  StepData_Plex::Matches (const Standard_CString steptype) const
43 {
44   Standard_Integer i, nb = NbMembers();
45   for (i = 1; i <= nb; i ++) {
46     if (Member(i)->Matches (steptype)) return Standard_True;
47   }
48   return Standard_False;
49 }
50
51     Handle(StepData_Simple)  StepData_Plex::As  (const Standard_CString steptype) const
52 {
53   Handle(StepData_Simple) ent;
54   Standard_Integer i, nb = NbMembers();
55   for (i = 1; i <= nb; i ++) {
56     ent = Member(i);
57     if (ent->Matches(steptype)) return ent;
58   }
59   ent.Nullify();
60   return ent;
61 }
62
63     Standard_Boolean  StepData_Plex::HasField (const Standard_CString name) const
64 {
65   Standard_Integer i, nb = NbMembers();
66   for (i = 1; i <= nb; i ++) {
67     if (Member(i)->HasField (name)) return Standard_True;
68   }
69   return Standard_False;
70 }
71
72     const StepData_Field&  StepData_Plex::Field (const Standard_CString name) const
73 {
74   Handle(StepData_Simple) ent;
75   Standard_Integer i, nb = NbMembers();
76   for (i = 1; i <= nb; i ++) {
77     ent = Member(i);
78     if (ent->HasField (name)) return ent->Field (name);
79   }
80   Interface_InterfaceMismatch::Raise("StepData_Plex : Field");
81   return bid;  // pour faire plaisir au compilo
82 }
83
84
85     StepData_Field&  StepData_Plex::CField (const Standard_CString name)
86 {
87   Handle(StepData_Simple) ent;
88   Standard_Integer i, nb = NbMembers();
89   for (i = 1; i <= nb; i ++) {
90     ent = Member(i);
91     if (ent->HasField (name)) return ent->CField (name);
92   }
93   Interface_InterfaceMismatch::Raise("StepData_Plex : Field");
94   return bid;  // pour faire plaisir au compilo
95 }
96
97
98     Standard_Integer  StepData_Plex::NbMembers () const
99       {  return themembers.Length();  }
100
101     Handle(StepData_Simple)  StepData_Plex::Member (const Standard_Integer num) const
102       {  return Handle(StepData_Simple)::DownCast (themembers.Value(num));  }
103
104     Handle(TColStd_HSequenceOfAsciiString)  StepData_Plex::TypeList () const
105 {
106   Handle(TColStd_HSequenceOfAsciiString) tl = new TColStd_HSequenceOfAsciiString();
107   Standard_Integer i, nb = NbMembers();
108   for (i = 1; i <= nb; i ++) {
109     TCollection_AsciiString nam (Member(i)->StepType());
110     tl->Append (nam);
111   }
112   return tl;
113 }
114
115
116 void StepData_Plex::Check(Handle(Interface_Check)& ach) const
117 {
118   Standard_Integer i, nb = NbMembers();
119   for (i = 1; i <= nb; i ++) {
120     Handle(StepData_Simple) si = Member(i);
121     si->Check(ach);
122   }
123 }
124
125
126     void  StepData_Plex::Shared (Interface_EntityIterator& list) const
127 {
128   Standard_Integer i, nb = NbMembers();
129   for (i = 1; i <= nb; i ++) {
130     Handle(StepData_Simple) si = Member(i);
131     si->Shared (list);
132   }
133 }