1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <RWHeaderSection_ReadWriteModule.ixx>
19 #include <Interface_ReaderLib.hxx>
20 #include <StepData_WriterLib.hxx>
21 #include <HeaderSection_Protocol.hxx>
22 #include <Interface_Macros.hxx>
23 #include <Interface_ParamType.hxx>
26 #include <HeaderSection_FileName.hxx>
27 #include <HeaderSection_FileDescription.hxx>
28 #include <HeaderSection_FileSchema.hxx>
30 #include <StepData_UndefinedEntity.hxx>
33 #include <RWHeaderSection_RWFileName.hxx>
34 #include <RWHeaderSection_RWFileDescription.hxx>
35 #include <RWHeaderSection_RWFileSchema.hxx>
37 // -- General Declarations (Recognize, StepType) ---
39 static TCollection_AsciiString PasReco(""); // neutralise StartEntity de SW
40 static TCollection_AsciiString Reco_FileName ("FILE_NAME");
41 static TCollection_AsciiString Reco_FileDescription ("FILE_DESCRIPTION");
42 static TCollection_AsciiString Reco_FileSchema ("FILE_SCHEMA");
44 // -- Definition of the libraries --
46 RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule ()
48 Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol;
49 StepData_WriterLib::SetGlobal(this,protocol);
50 Interface_ReaderLib::SetGlobal(this,protocol);
53 // --- Case Recognition ---
55 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep
56 (const TCollection_AsciiString& key) const
58 if (key.IsEqual(Reco_FileName)) return 1;
59 if (key.IsEqual(Reco_FileDescription)) return 2;
60 if (key.IsEqual(Reco_FileSchema)) return 3;
64 // --- External Mapping Case Recognition ---
66 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const
68 Standard_Integer NbComp = types.Length();
70 cout << "Plex Instance illegal " << endl;
75 Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const
79 // --- External Mapping Recognition ---
81 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
82 (const Standard_Integer /*CN*/) const
84 return Standard_False;
89 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
90 (const Standard_Integer CN) const
93 case 1 : return Reco_FileName;
94 case 2 : return Reco_FileDescription;
95 case 3 : return Reco_FileSchema;
96 default : return PasReco;
100 // -- Reading of a file --
102 void RWHeaderSection_ReadWriteModule::ReadStep
103 (const Standard_Integer CN,
104 const Handle(StepData_StepReaderData)& data,
105 const Standard_Integer num,
106 Handle(Interface_Check)& ach,
107 const Handle(Standard_Transient)&ent) const
113 DeclareAndCast(HeaderSection_FileName, anent, ent);
114 RWHeaderSection_RWFileName tool;
115 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
116 else tool.ReadStep (data,num,ach,anent);
122 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
123 RWHeaderSection_RWFileDescription tool;
124 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
125 else tool.ReadStep (data,num,ach,anent);
131 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
132 RWHeaderSection_RWFileSchema tool;
133 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
134 else tool.ReadStep (data,num,ach,anent);
140 DeclareAndCast(StepData_UndefinedEntity,und,ent);
141 if (und.IsNull()) ach->AddFail
142 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
143 else und->ReadRecord(data,num,ach);
147 default : ach->AddFail("Type Mismatch when reading - Entity");
152 // -- Writing of a file --
154 void RWHeaderSection_ReadWriteModule::WriteStep
155 (const Standard_Integer CN,
156 StepData_StepWriter& SW,
157 const Handle(Standard_Transient)&ent) const
163 DeclareAndCast(HeaderSection_FileName, anent, ent);
164 RWHeaderSection_RWFileName tool;
165 if (anent.IsNull()) return;
166 else tool.WriteStep (SW,anent);
172 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
173 RWHeaderSection_RWFileDescription tool;
174 if (anent.IsNull()) return;
175 else tool.WriteStep (SW,anent);
181 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
182 RWHeaderSection_RWFileSchema tool;
183 if (anent.IsNull()) return;
184 else tool.WriteStep (SW,anent);
190 DeclareAndCast(StepData_UndefinedEntity,und,ent);
191 if (und.IsNull()) break;
192 // Parentheses gerees par StepWriter lui-meme
193 // car en recevant le type PasReco, StepWriter ne l'affiche pas,
194 // mais il gere les parentheses comme si de rien n etait
195 if (und->IsComplex()) SW.StartComplex();
196 und->WriteParams(SW);
197 if (und->IsComplex()) SW.EndComplex();