| 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
| 2 | // |
| 3 | // This file is part of Open CASCADE Technology software library. |
| 4 | // |
| 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. |
| 10 | // |
| 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 12 | // commercial license or contractual agreement. |
| 13 | |
| 14 | |
| 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> |
| 34 | |
| 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"); |
| 40 | |
| 41 | // -- Definition of the libraries -- |
| 42 | |
| 43 | RWHeaderSection_ReadWriteModule::RWHeaderSection_ReadWriteModule () |
| 44 | { |
| 45 | Handle(HeaderSection_Protocol) protocol = new HeaderSection_Protocol; |
| 46 | StepData_WriterLib::SetGlobal(this,protocol); |
| 47 | Interface_ReaderLib::SetGlobal(this,protocol); |
| 48 | } |
| 49 | |
| 50 | // --- Case Recognition --- |
| 51 | |
| 52 | Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep |
| 53 | (const TCollection_AsciiString& key) const |
| 54 | { |
| 55 | if (key.IsEqual(Reco_FileName)) return 1; |
| 56 | if (key.IsEqual(Reco_FileDescription)) return 2; |
| 57 | if (key.IsEqual(Reco_FileSchema)) return 3; |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | // --- External Mapping Case Recognition --- |
| 62 | #ifdef OCCT_DEBUG |
| 63 | Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString& types) const |
| 64 | { |
| 65 | Standard_Integer NbComp = types.Length(); |
| 66 | if (NbComp < 2) { |
| 67 | cout << "Plex Instance illegal " << endl; |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | #else |
| 72 | Standard_Integer RWHeaderSection_ReadWriteModule::CaseStep (const TColStd_SequenceOfAsciiString&) const |
| 73 | { return 0; } |
| 74 | #endif |
| 75 | |
| 76 | // --- External Mapping Recognition --- |
| 77 | |
| 78 | Standard_Boolean RWHeaderSection_ReadWriteModule::IsComplex |
| 79 | (const Standard_Integer /*CN*/) const |
| 80 | { |
| 81 | return Standard_False; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | const TCollection_AsciiString& RWHeaderSection_ReadWriteModule::StepType |
| 87 | (const Standard_Integer CN) const |
| 88 | { |
| 89 | switch (CN) { |
| 90 | case 1 : return Reco_FileName; |
| 91 | case 2 : return Reco_FileDescription; |
| 92 | case 3 : return Reco_FileSchema; |
| 93 | default : return PasReco; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // -- Reading of a file -- |
| 98 | |
| 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 |
| 105 | { |
| 106 | if (CN == 0) return; |
| 107 | switch (CN) { |
| 108 | case 1 : |
| 109 | { |
| 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); |
| 114 | } |
| 115 | |
| 116 | break; |
| 117 | case 2 : |
| 118 | { |
| 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); |
| 123 | } |
| 124 | |
| 125 | break; |
| 126 | case 3 : |
| 127 | { |
| 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); |
| 132 | } |
| 133 | |
| 134 | break; |
| 135 | case 4 : |
| 136 | { |
| 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); |
| 141 | } |
| 142 | |
| 143 | break; |
| 144 | default : ach->AddFail("Type Mismatch when reading - Entity"); |
| 145 | } |
| 146 | |
| 147 | return;} |
| 148 | |
| 149 | // -- Writing of a file -- |
| 150 | |
| 151 | void RWHeaderSection_ReadWriteModule::WriteStep |
| 152 | (const Standard_Integer CN, |
| 153 | StepData_StepWriter& SW, |
| 154 | const Handle(Standard_Transient)&ent) const |
| 155 | { |
| 156 | if (CN == 0) return; |
| 157 | switch (CN) { |
| 158 | case 1 : |
| 159 | { |
| 160 | DeclareAndCast(HeaderSection_FileName, anent, ent); |
| 161 | RWHeaderSection_RWFileName tool; |
| 162 | if (anent.IsNull()) return; |
| 163 | else tool.WriteStep (SW,anent); |
| 164 | } |
| 165 | |
| 166 | break; |
| 167 | case 2 : |
| 168 | { |
| 169 | DeclareAndCast(HeaderSection_FileDescription, anent, ent); |
| 170 | RWHeaderSection_RWFileDescription tool; |
| 171 | if (anent.IsNull()) return; |
| 172 | else tool.WriteStep (SW,anent); |
| 173 | } |
| 174 | |
| 175 | break; |
| 176 | case 3 : |
| 177 | { |
| 178 | DeclareAndCast(HeaderSection_FileSchema, anent, ent); |
| 179 | RWHeaderSection_RWFileSchema tool; |
| 180 | if (anent.IsNull()) return; |
| 181 | else tool.WriteStep (SW,anent); |
| 182 | } |
| 183 | |
| 184 | break; |
| 185 | case 4 : |
| 186 | { |
| 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(); |
| 195 | } |
| 196 | |
| 197 | break; |
| 198 | default : return; |
| 199 | } |
| 200 | } |
| 201 | |