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