973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
973c2be1 |
5 | // This library is free software; you can redistribute it and / or modify it |
6 | // under the terms of the GNU Lesser General Public 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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <StepData_DescrReadWrite.ixx> |
15 | #include <StepData_EDescr.hxx> |
16 | #include <StepData_ECDescr.hxx> |
17 | #include <StepData_ESDescr.hxx> |
18 | #include <StepData_Simple.hxx> |
19 | #include <StepData_Plex.hxx> |
20 | #include <StepData_FieldListN.hxx> |
21 | #include <TColStd_HSequenceOfAsciiString.hxx> |
22 | #include <Interface_Macros.hxx> |
23 | |
24 | static TCollection_AsciiString nocp("?"); |
25 | |
26 | |
27 | StepData_DescrReadWrite::StepData_DescrReadWrite |
28 | (const Handle(StepData_Protocol)& proto) |
29 | : theproto (proto) { } |
30 | |
31 | Standard_Integer StepData_DescrReadWrite::CaseStep |
32 | (const TCollection_AsciiString& atype) const |
33 | { |
34 | Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False); |
35 | if (descr.IsNull()) return 0; |
36 | return theproto->DescrNumber (descr); |
37 | } |
38 | |
39 | Standard_Integer StepData_DescrReadWrite::CaseStep |
40 | (const TColStd_SequenceOfAsciiString& types) const |
41 | { |
42 | Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False); |
43 | if (descr.IsNull()) return 0; |
44 | return theproto->DescrNumber (descr); |
45 | } |
46 | |
47 | |
48 | Standard_Boolean StepData_DescrReadWrite::IsComplex |
49 | (const Standard_Integer CN) const |
50 | { |
51 | Handle(StepData_EDescr) descr = theproto->Descr (CN); |
52 | if (descr.IsNull()) return Standard_False; |
53 | return descr->IsComplex(); |
54 | } |
55 | |
56 | const TCollection_AsciiString& StepData_DescrReadWrite::StepType |
57 | (const Standard_Integer CN) const |
58 | { |
59 | Handle(StepData_ESDescr) descr = Handle(StepData_ESDescr)::DownCast |
60 | (theproto->Descr (CN)); |
61 | if (descr.IsNull()) return nocp; |
62 | return descr->StepType(); |
63 | } |
64 | |
65 | Standard_Boolean StepData_DescrReadWrite::ComplexType |
66 | (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const |
67 | { |
68 | Handle(StepData_ECDescr) descr = Handle(StepData_ECDescr)::DownCast |
69 | (theproto->Descr (CN)); |
70 | if (descr.IsNull()) return Standard_False; |
71 | Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList(); |
72 | if (list.IsNull()) return Standard_False; |
73 | Standard_Integer i, nb = list->Length(); |
74 | for (i = 1; i <= nb; i ++) types.Append (list->Value(i)); |
75 | return Standard_True; |
76 | } |
77 | |
78 | |
79 | void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN, |
80 | const Handle(StepData_StepReaderData)& data, |
81 | const Standard_Integer num, |
82 | Handle(Interface_Check)& ach, |
83 | const Handle(Standard_Transient)&ent) const |
84 | { |
85 | if (CN == 0) return; |
86 | DeclareAndCast(StepData_Simple,sent,ent); |
87 | if (!sent.IsNull()) { |
88 | Handle(StepData_ESDescr) sdescr = sent->ESDescr(); |
89 | StepData_FieldListN& fl = sent->CFields(); |
90 | data->ReadList (num,ach,sdescr,fl); |
91 | return; |
92 | } |
93 | |
94 | DeclareAndCast(StepData_Plex,cent,ent); |
95 | Standard_Integer i, nb=0; |
96 | if (!cent.IsNull()) nb = cent->NbMembers(); |
97 | Standard_Integer n0 = num; |
98 | for (i = 1; i <= nb; i ++) { |
99 | Handle(StepData_Simple) si = cent->Member(i); |
100 | Handle(StepData_ESDescr) sdescr = si->ESDescr(); |
101 | StepData_FieldListN& fl = si->CFields(); |
102 | data->ReadList (n0,ach,sdescr,fl); |
103 | if (i < nb) n0 = data->NextForComplex(n0); |
104 | } |
105 | } |
106 | |
107 | |
108 | void StepData_DescrReadWrite::WriteStep |
109 | (const Standard_Integer CN, |
110 | StepData_StepWriter& SW, |
111 | const Handle(Standard_Transient)&ent) const |
112 | { |
113 | if (CN == 0) return; |
114 | |
115 | DeclareAndCast(StepData_Simple,sent,ent); |
116 | if (!sent.IsNull()) { |
117 | Handle(StepData_ESDescr) sdescr = sent->ESDescr(); |
118 | const StepData_FieldListN& fl = sent->Fields(); |
119 | SW.SendList (fl,sdescr); |
120 | return; |
121 | } |
122 | |
123 | DeclareAndCast(StepData_Plex,cent,ent); |
124 | Standard_Integer i, nb=0; |
125 | if (!cent.IsNull()) nb = cent->NbMembers(); |
126 | for (i = 1; i <= nb; i ++) { |
127 | Handle(StepData_Simple) si = cent->Member(i); |
128 | Handle(StepData_ESDescr) sdescr = si->ESDescr(); |
129 | const StepData_FieldListN& fl = si->Fields(); |
130 | SW.StartEntity (sdescr->TypeName()); |
131 | SW.SendList (fl,sdescr); |
132 | } |
133 | } |