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