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 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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
35 IMPLEMENT_STANDARD_RTTIEXT(RWHeaderSection_ReadWriteModule,StepData_ReadWriteModule)
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");
43 // -- Definition of the libraries --
45 RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
47 Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
48 StepData_WriterLib::SetGlobal(this,protocol);
49 Interface_ReaderLib::SetGlobal(this,protocol);
52 // --- Case Recognition ---
54 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
55 (const TCollection_AsciiString& key) const
57 if (key.IsEqual(Reco_FileName)) return 1;
58 if (key.IsEqual(Reco_FileDescription)) return 2;
59 if (key.IsEqual(Reco_FileSchema)) return 3;
63 // --- External Mapping Case Recognition ---
65 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const
67 Standard_Integer NbComp = types.Length();
69 cout << "Plex Instance illegal " << endl;
74 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const
78 // --- External Mapping Recognition ---
80 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
81 (const Standard_Integer /*CN*/) const
83 return Standard_False;
88 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
89 (const Standard_Integer CN) const
92 case 1 : return Reco_FileName;
93 case 2 : return Reco_FileDescription;
94 case 3 : return Reco_FileSchema;
95 default : return PasReco;
99 // -- Reading of a file --
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
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);
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);
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);
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);
146 default : ach->AddFail("Type Mismatch when reading - Entity");
151 // -- Writing of a file --
153 void RWHeaderSection_ReadWriteModule::WriteStep
154 (const Standard_Integer CN,
155 StepData_StepWriter& SW,
156 const Handle(Standard_Transient)&ent) const
162 DeclareAndCast(HeaderSection_FileName, anent, ent);
163 RWHeaderSection_RWFileName tool;
164 if (anent.IsNull()) return;
165 else tool.WriteStep (SW,anent);
171 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
172 RWHeaderSection_RWFileDescription tool;
173 if (anent.IsNull()) return;
174 else tool.WriteStep (SW,anent);
180 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
181 RWHeaderSection_RWFileSchema tool;
182 if (anent.IsNull()) return;
183 else tool.WriteStep (SW,anent);
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();