0026595: Lost some comments in OCCT-code after cdl elimination
[occt.git] / src / StepData / StepData_DescrReadWrite.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_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>
31
32 static TCollection_AsciiString nocp("?");
33
34
35     StepData_DescrReadWrite::StepData_DescrReadWrite
36   (const Handle(StepData_Protocol)& proto)
37     : theproto (proto)    {  }
38
39     Standard_Integer  StepData_DescrReadWrite::CaseStep
40   (const TCollection_AsciiString& atype) const
41 {
42   Handle(StepData_ESDescr) descr = theproto->ESDescr (atype.ToCString(),Standard_False);
43   if (descr.IsNull()) return 0;
44   return theproto->DescrNumber (descr);
45 }
46
47     Standard_Integer  StepData_DescrReadWrite::CaseStep
48   (const TColStd_SequenceOfAsciiString& types) const
49 {
50   Handle(StepData_ECDescr) descr = theproto->ECDescr (types,Standard_False);
51   if (descr.IsNull()) return 0;
52   return theproto->DescrNumber (descr);
53 }
54
55
56     Standard_Boolean  StepData_DescrReadWrite::IsComplex
57   (const Standard_Integer CN) const
58 {
59   Handle(StepData_EDescr)  descr = theproto->Descr (CN);
60   if (descr.IsNull()) return Standard_False;
61   return descr->IsComplex();
62 }
63
64     const TCollection_AsciiString& StepData_DescrReadWrite::StepType
65   (const Standard_Integer CN) const
66 {
67   Handle(StepData_ESDescr)  descr = Handle(StepData_ESDescr)::DownCast
68     (theproto->Descr (CN));
69   if (descr.IsNull()) return nocp;
70   return descr->StepType();
71 }
72
73     Standard_Boolean StepData_DescrReadWrite::ComplexType
74   (const Standard_Integer CN, TColStd_SequenceOfAsciiString& types) const
75 {
76   Handle(StepData_ECDescr)  descr = Handle(StepData_ECDescr)::DownCast
77     (theproto->Descr (CN));
78   if (descr.IsNull()) return Standard_False;
79   Handle(TColStd_HSequenceOfAsciiString) list = descr->TypeList();
80   if (list.IsNull()) return Standard_False;
81   Standard_Integer i, nb = list->Length();
82   for (i = 1; i <= nb; i ++)  types.Append (list->Value(i));
83   return Standard_True;
84 }
85
86
87 void StepData_DescrReadWrite::ReadStep(const Standard_Integer CN,
88                                        const Handle(StepData_StepReaderData)& data,
89                                        const Standard_Integer num,
90                                        Handle(Interface_Check)& ach,
91                                        const Handle(Standard_Transient)&ent) const
92 {
93   if (CN == 0) return;
94   DeclareAndCast(StepData_Simple,sent,ent);
95   if (!sent.IsNull()) {
96     Handle(StepData_ESDescr) sdescr = sent->ESDescr();
97     StepData_FieldListN& fl = sent->CFields();
98     data->ReadList (num,ach,sdescr,fl);
99     return;
100   }
101
102   DeclareAndCast(StepData_Plex,cent,ent);
103   Standard_Integer i, nb=0;
104   if (!cent.IsNull()) nb = cent->NbMembers();
105   Standard_Integer n0 = num;
106   for (i = 1; i <= nb; i ++) {
107     Handle(StepData_Simple) si = cent->Member(i);
108     Handle(StepData_ESDescr) sdescr = si->ESDescr();
109     StepData_FieldListN& fl = si->CFields();
110     data->ReadList (n0,ach,sdescr,fl);
111     if (i < nb) n0 = data->NextForComplex(n0);
112   }
113 }
114
115
116     void StepData_DescrReadWrite::WriteStep
117   (const Standard_Integer CN,
118    StepData_StepWriter& SW,
119    const Handle(Standard_Transient)&ent) const
120 {
121   if (CN == 0) return;
122
123   DeclareAndCast(StepData_Simple,sent,ent);
124   if (!sent.IsNull()) {
125     Handle(StepData_ESDescr) sdescr = sent->ESDescr();
126     const StepData_FieldListN& fl = sent->Fields();
127     SW.SendList (fl,sdescr);
128     return;
129   }
130
131   DeclareAndCast(StepData_Plex,cent,ent);
132   Standard_Integer i, nb=0;
133   if (!cent.IsNull()) nb = cent->NbMembers();
134   for (i = 1; i <= nb; i ++) {
135     Handle(StepData_Simple) si = cent->Member(i);
136     Handle(StepData_ESDescr) sdescr = si->ESDescr();
137       const StepData_FieldListN& fl = si->Fields();
138       SW.StartEntity (sdescr->TypeName());
139       SW.SendList (fl,sdescr);
140   }
141 }