1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <StepData_DescrReadWrite.ixx>
19 #include <StepData_EDescr.hxx>
20 #include <StepData_ECDescr.hxx>
21 #include <StepData_ESDescr.hxx>
22 #include <StepData_Simple.hxx>
23 #include <StepData_Plex.hxx>
24 #include <StepData_FieldListN.hxx>
25 #include <TColStd_HSequenceOfAsciiString.hxx>
26 #include <Interface_Macros.hxx>
28 static TCollection_AsciiString nocp("?");
31 StepData_DescrReadWrite::StepData_DescrReadWrite
32 (const Handle(StepData_Protocol)& proto)
33 : theproto (proto) { }
35 Standard_Integer StepData_DescrReadWrite::CaseStep
36 (const TCollection_AsciiString& atype) const
38 Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False);
39 if (descr.IsNull()) return 0;
40 return theproto->DescrNumber (descr);
43 Standard_Integer StepData_DescrReadWrite::CaseStep
44 (const TColStd_SequenceOfAsciiString& types) const
46 Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False);
47 if (descr.IsNull()) return 0;
48 return theproto->DescrNumber (descr);
52 Standard_Boolean StepData_DescrReadWrite::IsComplex
53 (const Standard_Integer CN) const
55 Handle(StepData_EDescr) descr = theproto->Descr (CN);
56 if (descr.IsNull()) return Standard_False;
57 return descr->IsComplex();
60 const TCollection_AsciiString& StepData_DescrReadWrite::StepType
61 (const Standard_Integer CN) const
63 Handle(StepData_ESDescr) descr = Handle(StepData_ESDescr)::DownCast
64 (theproto->Descr (CN));
65 if (descr.IsNull()) return nocp;
66 return descr->StepType();
69 Standard_Boolean StepData_DescrReadWrite::ComplexType
70 (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const
72 Handle(StepData_ECDescr) descr = Handle(StepData_ECDescr)::DownCast
73 (theproto->Descr (CN));
74 if (descr.IsNull()) return Standard_False;
75 Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList();
76 if (list.IsNull()) return Standard_False;
77 Standard_Integer i, nb = list->Length();
78 for (i = 1; i <= nb; i ++) types.Append (list->Value(i));
83 void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN,
84 const Handle(StepData_StepReaderData)& data,
85 const Standard_Integer num,
86 Handle(Interface_Check)& ach,
87 const Handle(Standard_Transient)&ent) const
90 DeclareAndCast(StepData_Simple,sent,ent);
92 Handle(StepData_ESDescr) sdescr = sent->ESDescr();
93 StepData_FieldListN& fl = sent->CFields();
94 data->ReadList (num,ach,sdescr,fl);
98 DeclareAndCast(StepData_Plex,cent,ent);
99 Standard_Integer i, nb=0;
100 if (!cent.IsNull()) nb = cent->NbMembers();
101 Standard_Integer n0 = num;
102 for (i = 1; i <= nb; i ++) {
103 Handle(StepData_Simple) si = cent->Member(i);
104 Handle(StepData_ESDescr) sdescr = si->ESDescr();
105 StepData_FieldListN& fl = si->CFields();
106 data->ReadList (n0,ach,sdescr,fl);
107 if (i < nb) n0 = data->NextForComplex(n0);
112 void StepData_DescrReadWrite::WriteStep
113 (const Standard_Integer CN,
114 StepData_StepWriter& SW,
115 const Handle(Standard_Transient)&ent) const
119 DeclareAndCast(StepData_Simple,sent,ent);
120 if (!sent.IsNull()) {
121 Handle(StepData_ESDescr) sdescr = sent->ESDescr();
122 const StepData_FieldListN& fl = sent->Fields();
123 SW.SendList (fl,sdescr);
127 DeclareAndCast(StepData_Plex,cent,ent);
128 Standard_Integer i, nb=0;
129 if (!cent.IsNull()) nb = cent->NbMembers();
130 for (i = 1; i <= nb; i ++) {
131 Handle(StepData_Simple) si = cent->Member(i);
132 Handle(StepData_ESDescr) sdescr = si->ESDescr();
133 const StepData_FieldListN& fl = si->Fields();
134 SW.StartEntity (sdescr->TypeName());
135 SW.SendList (fl,sdescr);