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
67 (const TColStd_SequenceOfAsciiString& types) const
70 Standard_Integer NbComp = types.Length();
73 cout << "Plex Instance illegal " << endl;
80 // --- External Mapping Recognition ---
82 Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex
83 (const Standard_Integer CN) const
85 return Standard_False;
90 const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType
91 (const Standard_Integer CN) const
94 case 1 : return Reco_FileName;
95 case 2 : return Reco_FileDescription;
96 case 3 : return Reco_FileSchema;
97 default : return PasReco;
101 // -- Reading of a file --
103 void RWHeaderSection_ReadWriteModule::ReadStep
104 (const Standard_Integer CN,
105 const Handle(StepData_StepReaderData)& data,
106 const Standard_Integer num,
107 Handle(Interface_Check)& ach,
108 const Handle(Standard_Transient)&ent) const
114 DeclareAndCast(HeaderSection_FileName, anent, ent);
115 RWHeaderSection_RWFileName tool;
116 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileName");
117 else tool.ReadStep (data,num,ach,anent);
123 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
124 RWHeaderSection_RWFileDescription tool;
125 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileDescription");
126 else tool.ReadStep (data,num,ach,anent);
132 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
133 RWHeaderSection_RWFileSchema tool;
134 if (anent.IsNull()) ach->AddFail("Type Mismatch on FileSchema");
135 else tool.ReadStep (data,num,ach,anent);
141 DeclareAndCast(StepData_UndefinedEntity,und,ent);
142 if (und.IsNull()) ach->AddFail
143 ("# Entity neither Recognized nor set as UndefinedEntity from StepData #");
144 else und->ReadRecord(data,num,ach);
148 default : ach->AddFail("Type Mismatch when reading - Entity");
153 // -- Writing of a file --
155 void RWHeaderSection_ReadWriteModule::WriteStep
156 (const Standard_Integer CN,
157 StepData_StepWriter& SW,
158 const Handle(Standard_Transient)&ent) const
164 DeclareAndCast(HeaderSection_FileName, anent, ent);
165 RWHeaderSection_RWFileName tool;
166 if (anent.IsNull()) return;
167 else tool.WriteStep (SW,anent);
173 DeclareAndCast(HeaderSection_FileDescription, anent, ent);
174 RWHeaderSection_RWFileDescription tool;
175 if (anent.IsNull()) return;
176 else tool.WriteStep (SW,anent);
182 DeclareAndCast(HeaderSection_FileSchema, anent, ent);
183 RWHeaderSection_RWFileSchema tool;
184 if (anent.IsNull()) return;
185 else tool.WriteStep (SW,anent);
191 DeclareAndCast(StepData_UndefinedEntity,und,ent);
192 if (und.IsNull()) break;
193 // Parentheses gerees par StepWriter lui-meme
194 // car en recevant le type PasReco, StepWriter ne l'affiche pas,
195 // mais il gere les parentheses comme si de rien n etait
196 if (und->IsComplex()) SW.StartComplex();
197 und->WriteParams(SW);
198 if (und->IsComplex()) SW.EndComplex();