1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
22 #include <HeaderSection_FileName.hxx>
23 #include <HeaderSection_FileDescription.hxx>
24 #include <HeaderSection_FileSchema.hxx>
26 #include <StepData_UndefinedEntity.hxx>
29 #include <RWHeaderSection_RWFileName.hxx>
30 #include <RWHeaderSection_RWFileDescription.hxx>
31 #include <RWHeaderSection_RWFileSchema.hxx>
33 // -- General Declarations (Recognize, StepType) ---
35 static TCollection_AsciiString PasReco(""); // neutralise StartEntity de SW
36 static TCollection_AsciiString Reco_FileName ("FILE_NAME");
37 static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
38 static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");
40 // -- Definition of the libraries --
42 RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
44 Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
45 StepData_WriterLib::SetGlobal(this,protocol);
46 Interface_ReaderLib::SetGlobal(this,protocol);
49 // --- Case Recognition ---
51 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
52 (const TCollection_AsciiString& key) const
54 if (key.IsEqual(Reco_FileName)) return 1;
55 if (key.IsEqual(Reco_FileDescription)) return 2;
56 if (key.IsEqual(Reco_FileSchema)) return 3;
60 // --- External Mapping Case Recognition ---
62 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const
64 Standard_Integer NbComp = types.Length();
66 cout << "Plex Instance illegal " << endl;
71 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const
75 // --- External Mapping Recognition ---
77 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
78 (const Standard_Integer /*CN*/) const
80 return Standard_False;
85 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
86 (const Standard_Integer CN) const
89 case 1 : return Reco_FileName;
90 case 2 : return Reco_FileDescription;
91 case 3 : return Reco_FileSchema;
92 default : return PasReco;
96 // -- Reading of a file --
98 void 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
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);
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);
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);
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);
143 default : ach->AddFail("Type Mismatch when reading - Entity");
148 // -- Writing of a file --
150 void RWHeaderSection_ReadWriteModule::WriteStep
151 (const Standard_Integer CN,
152 StepData_StepWriter& SW,
153 const Handle(Standard_Transient)&ent) const
159 DeclareAndCast(HeaderSection_FileName, anent, ent);
160 RWHeaderSection_RWFileName tool;
161 if (anent.IsNull()) return;
162 else tool.WriteStep (SW,anent);
168 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
169 RWHeaderSection_RWFileDescription tool;
170 if (anent.IsNull()) return;
171 else tool.WriteStep (SW,anent);
177 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
178 RWHeaderSection_RWFileSchema tool;
179 if (anent.IsNull()) return;
180 else tool.WriteStep (SW,anent);
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();