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