1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_Check.hxx>
16 #include <Interface_Macros.hxx>
17 #include <Standard_Transient.hxx>
18 #include <Standard_Type.hxx>
19 #include <StepData_DescrReadWrite.hxx>
20 #include <StepData_ECDescr.hxx>
21 #include <StepData_EDescr.hxx>
22 #include <StepData_ESDescr.hxx>
23 #include <StepData_FieldListN.hxx>
24 #include <StepData_Plex.hxx>
25 #include <StepData_Protocol.hxx>
26 #include <StepData_Simple.hxx>
27 #include <StepData_StepReaderData.hxx>
28 #include <StepData_StepWriter.hxx>
29 #include <TCollection_AsciiString.hxx>
30 #include <TColStd_HSequenceOfAsciiString.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(StepData_DescrReadWrite,StepData_ReadWriteModule)
34 static TCollection_AsciiString nocp("?");
37 StepData_DescrReadWrite::StepData_DescrReadWrite
38 (const Handle(StepData_Protocol)& proto)
39 : theproto (proto) { }
41 Standard_Integer StepData_DescrReadWrite::CaseStep
42 (const TCollection_AsciiString& atype) const
44 Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False);
45 if (descr.IsNull()) return 0;
46 return theproto->DescrNumber (descr);
49 Standard_Integer StepData_DescrReadWrite::CaseStep
50 (const TColStd_SequenceOfAsciiString& types) const
52 Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False);
53 if (descr.IsNull()) return 0;
54 return theproto->DescrNumber (descr);
58 Standard_Boolean StepData_DescrReadWrite::IsComplex
59 (const Standard_Integer CN) const
61 Handle(StepData_EDescr) descr = theproto->Descr (CN);
62 if (descr.IsNull()) return Standard_False;
63 return descr->IsComplex();
66 const TCollection_AsciiString& StepData_DescrReadWrite::StepType
67 (const Standard_Integer CN) const
69 Handle(StepData_ESDescr) descr = Handle(StepData_ESDescr)::DownCast
70 (theproto->Descr (CN));
71 if (descr.IsNull()) return nocp;
72 return descr->StepType();
75 Standard_Boolean StepData_DescrReadWrite::ComplexType
76 (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const
78 Handle(StepData_ECDescr) descr = Handle(StepData_ECDescr)::DownCast
79 (theproto->Descr (CN));
80 if (descr.IsNull()) return Standard_False;
81 Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList();
82 if (list.IsNull()) return Standard_False;
83 Standard_Integer i, nb = list->Length();
84 for (i = 1; i <= nb; i ++) types.Append (list->Value(i));
89 void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN,
90 const Handle(StepData_StepReaderData)& data,
91 const Standard_Integer num,
92 Handle(Interface_Check)& ach,
93 const Handle(Standard_Transient)&ent) const
96 DeclareAndCast(StepData_Simple,sent,ent);
98 Handle(StepData_ESDescr) sdescr = sent->ESDescr();
99 StepData_FieldListN& fl = sent->CFields();
100 data->ReadList (num,ach,sdescr,fl);
104 DeclareAndCast(StepData_Plex,cent,ent);
105 Standard_Integer i, nb=0;
106 if (!cent.IsNull()) nb = cent->NbMembers();
107 Standard_Integer n0 = num;
108 for (i = 1; i <= nb; i ++) {
109 Handle(StepData_Simple) si = cent->Member(i);
110 Handle(StepData_ESDescr) sdescr = si->ESDescr();
111 StepData_FieldListN& fl = si->CFields();
112 data->ReadList (n0,ach,sdescr,fl);
113 if (i < nb) n0 = data->NextForComplex(n0);
118 void StepData_DescrReadWrite::WriteStep
119 (const Standard_Integer CN,
120 StepData_StepWriter& SW,
121 const Handle(Standard_Transient)&ent) const
125 DeclareAndCast(StepData_Simple,sent,ent);
126 if (!sent.IsNull()) {
127 Handle(StepData_ESDescr) sdescr = sent->ESDescr();
128 const StepData_FieldListN& fl = sent->Fields();
129 SW.SendList (fl,sdescr);
133 DeclareAndCast(StepData_Plex,cent,ent);
134 Standard_Integer i, nb=0;
135 if (!cent.IsNull()) nb = cent->NbMembers();
136 for (i = 1; i <= nb; i ++) {
137 Handle(StepData_Simple) si = cent->Member(i);
138 Handle(StepData_ESDescr) sdescr = si->ESDescr();
139 const StepData_FieldListN& fl = si->Fields();
140 SW.StartEntity (sdescr->TypeName());
141 SW.SendList (fl,sdescr);