0023024: Update headers of OCCT files
[occt.git] / src / RWHeaderSection / RWHeaderSection_ReadWriteModule.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
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.
7//
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.
10//
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.
17
7fd59977 18#include <RWHeaderSection_ReadWriteModule.ixx>
19#include <Interface_ReaderLib.hxx>
20#include <StepData_WriterLib.hxx>
21#include <HeaderSection_Protocol.hxx>
22#include <Interface_Macros.hxx>
23#include <Interface_ParamType.hxx>
24
25
26#include <HeaderSection_FileName.hxx>
27#include <HeaderSection_FileDescription.hxx>
28#include <HeaderSection_FileSchema.hxx>
29
30#include <StepData_UndefinedEntity.hxx>
31
32
33#include <RWHeaderSection_RWFileName.hxx>
34#include <RWHeaderSection_RWFileDescription.hxx>
35#include <RWHeaderSection_RWFileSchema.hxx>
36
b311480e 37// -- General Declarations (Recognize, StepType) ---
7fd59977 38
39static TCollection_AsciiString PasReco(""); // neutralise StartEntity de SW
40static TCollection_AsciiString Reco_FileName ("FILE_NAME");
41static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
42static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");
43
44 // -- Definition of the libraries --
45
46RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
47{
48 Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
49 StepData_WriterLib::SetGlobal(this,protocol);
50 Interface_ReaderLib::SetGlobal(this,protocol);
51}
52
53 // --- Case Recognition ---
54
55Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
56 (const TCollection_AsciiString& key) const
57{
58 if (key.IsEqual(Reco_FileName)) return 1;
59 if (key.IsEqual(Reco_FileDescription)) return 2;
60 if (key.IsEqual(Reco_FileSchema)) return 3;
61return 0;
62}
63
64 // --- External Mapping Case Recognition ---
65
66Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
67 (const TColStd_SequenceOfAsciiString& types) const
68{
69
70 Standard_Integer NbComp = types.Length();
71#ifdef DEB
72 if (NbComp < 2) {
73 cout << "Plex Instance illegal " << endl;
74 }
75#endif
76 return 0;
77}
78
79
80 // --- External Mapping Recognition ---
81
82Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
83 (const Standard_Integer CN) const
84{
85 return Standard_False;
86}
87
88
89
90const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
91 (const Standard_Integer CN) const
92{
93 switch (CN) {
94 case 1 : return Reco_FileName;
95 case 2 : return Reco_FileDescription;
96 case 3 : return Reco_FileSchema;
97 default : return PasReco;
98 }
99}
100
101 // -- Reading of a file --
102
103void RWHeaderSection_ReadWriteModule::ReadStep
104 (const Standard_Integer CN,
105 const Handle(StepData_StepReaderData)& data,
106 const Standard_Integer num,
107 Handle(Interface_Check)& ach,
108 const Handle(Standard_Transient)&ent) const
109{
110 if (CN == 0) return;
111 switch (CN) {
112 case 1 :
113 {
114 DeclareAndCast(HeaderSection_FileName, anent, ent);
115 RWHeaderSection_RWFileName tool;
116 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
117 else tool.ReadStep (data,num,ach,anent);
118 }
119
120 break;
121 case 2 :
122 {
123 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
124 RWHeaderSection_RWFileDescription tool;
125 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
126 else tool.ReadStep (data,num,ach,anent);
127 }
128
129 break;
130 case 3 :
131 {
132 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
133 RWHeaderSection_RWFileSchema tool;
134 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
135 else tool.ReadStep (data,num,ach,anent);
136 }
137
138 break;
139 case 4 :
140 {
141 DeclareAndCast(StepData_UndefinedEntity,und,ent);
142 if (und.IsNull()) ach->AddFail
143 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
144 else und->ReadRecord(data,num,ach);
145 }
146
147 break;
148 default : ach->AddFail("Type Mismatch when reading - Entity");
149 }
150
151return;}
152
153 // -- Writing of a file --
154
155void RWHeaderSection_ReadWriteModule::WriteStep
156 (const Standard_Integer CN,
157 StepData_StepWriter& SW,
158 const Handle(Standard_Transient)&ent) const
159{
160 if (CN == 0) return;
161 switch (CN) {
162 case 1 :
163 {
164 DeclareAndCast(HeaderSection_FileName, anent, ent);
165 RWHeaderSection_RWFileName tool;
166 if (anent.IsNull()) return;
167 else tool.WriteStep (SW,anent);
168 }
169
170 break;
171 case 2 :
172 {
173 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
174 RWHeaderSection_RWFileDescription tool;
175 if (anent.IsNull()) return;
176 else tool.WriteStep (SW,anent);
177 }
178
179 break;
180 case 3 :
181 {
182 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
183 RWHeaderSection_RWFileSchema tool;
184 if (anent.IsNull()) return;
185 else tool.WriteStep (SW,anent);
186 }
187
188 break;
189 case 4 :
190 {
191 DeclareAndCast(StepData_UndefinedEntity,und,ent);
192 if (und.IsNull()) break;
193// Parentheses gerees par StepWriter lui-meme
194// car en recevant le type PasReco, StepWriter ne l'affiche pas,
195// mais il gere les parentheses comme si de rien n etait
196 if (und->IsComplex()) SW.StartComplex();
197 und->WriteParams(SW);
198 if (und->IsComplex()) SW.EndComplex();
199 }
200
201 break;
202 default : return;
203 }
204}
205