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 // -- General Declarations (Recognize, StepType) ---
36 static TCollection_AsciiString PasReco(""); // neutralise StartEntity de SW
37 static TCollection_AsciiString Reco_FileName ("FILE_NAME");
38 static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
39 static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");
41 // -- Definition of the libraries --
43 RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
45 Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
46 StepData_WriterLib::SetGlobal(this,protocol);
47 Interface_ReaderLib::SetGlobal(this,protocol);
50 // --- Case Recognition ---
52 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
53 (const TCollection_AsciiString& key) const
55 if (key.IsEqual(Reco_FileName)) return 1;
56 if (key.IsEqual(Reco_FileDescription)) return 2;
57 if (key.IsEqual(Reco_FileSchema)) return 3;
61 // --- External Mapping Case Recognition ---
63 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const
65 Standard_Integer NbComp = types.Length();
67 cout << "Plex Instance illegal " << endl;
72 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const
76 // --- External Mapping Recognition ---
78 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
79 (const Standard_Integer /*CN*/) const
81 return Standard_False;
86 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
87 (const Standard_Integer CN) const
90 case 1 : return Reco_FileName;
91 case 2 : return Reco_FileDescription;
92 case 3 : return Reco_FileSchema;
93 default : return PasReco;
97 // -- Reading of a file --
99 void RWHeaderSection_ReadWriteModule::ReadStep
100 (const Standard_Integer CN,
101 const Handle(StepData_StepReaderData)& data,
102 const Standard_Integer num,
103 Handle(Interface_Check)& ach,
104 const Handle(Standard_Transient)&ent) const
110 DeclareAndCast(HeaderSection_FileName, anent, ent);
111 RWHeaderSection_RWFileName tool;
112 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
113 else tool.ReadStep (data,num,ach,anent);
119 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
120 RWHeaderSection_RWFileDescription tool;
121 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
122 else tool.ReadStep (data,num,ach,anent);
128 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
129 RWHeaderSection_RWFileSchema tool;
130 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
131 else tool.ReadStep (data,num,ach,anent);
137 DeclareAndCast(StepData_UndefinedEntity,und,ent);
138 if (und.IsNull()) ach->AddFail
139 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
140 else und->ReadRecord(data,num,ach);
144 default : ach->AddFail("Type Mismatch when reading - Entity");
149 // -- Writing of a file --
151 void RWHeaderSection_ReadWriteModule::WriteStep
152 (const Standard_Integer CN,
153 StepData_StepWriter& SW,
154 const Handle(Standard_Transient)&ent) const
160 DeclareAndCast(HeaderSection_FileName, anent, ent);
161 RWHeaderSection_RWFileName tool;
162 if (anent.IsNull()) return;
163 else tool.WriteStep (SW,anent);
169 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
170 RWHeaderSection_RWFileDescription tool;
171 if (anent.IsNull()) return;
172 else tool.WriteStep (SW,anent);
178 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
179 RWHeaderSection_RWFileSchema tool;
180 if (anent.IsNull()) return;
181 else tool.WriteStep (SW,anent);
187 DeclareAndCast(StepData_UndefinedEntity,und,ent);
188 if (und.IsNull()) break;
189 // Parentheses gerees par StepWriter lui-meme
190 // car en recevant le type PasReco, StepWriter ne l'affiche pas,
191 // mais il gere les parentheses comme si de rien n etait
192 if (und->IsComplex()) SW.StartComplex();
193 und->WriteParams(SW);
194 if (und->IsComplex()) SW.EndComplex();