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 <Interface_Check.hxx>
16 #include <RWStepBasic_RWSiUnit.hxx>
17 #include <StepBasic_DimensionalExponents.hxx>
18 #include <StepBasic_SiUnit.hxx>
19 #include <StepData_StepReaderData.hxx>
20 #include <StepData_StepWriter.hxx>
21 #include <TCollection_AsciiString.hxx>
23 // --- Enum : SiPrefix ---
24 static TCollection_AsciiString spExa(".EXA.");
25 static TCollection_AsciiString spPico(".PICO.");
26 static TCollection_AsciiString spMega(".MEGA.");
27 static TCollection_AsciiString spFemto(".FEMTO.");
28 static TCollection_AsciiString spAtto(".ATTO.");
29 static TCollection_AsciiString spCenti(".CENTI.");
30 static TCollection_AsciiString spNano(".NANO.");
31 static TCollection_AsciiString spHecto(".HECTO.");
32 static TCollection_AsciiString spMicro(".MICRO.");
33 static TCollection_AsciiString spTera(".TERA.");
34 static TCollection_AsciiString spGiga(".GIGA.");
35 static TCollection_AsciiString spMilli(".MILLI.");
36 static TCollection_AsciiString spPeta(".PETA.");
37 static TCollection_AsciiString spDeci(".DECI.");
38 static TCollection_AsciiString spKilo(".KILO.");
39 static TCollection_AsciiString spDeca(".DECA.");
41 // --- Enum : SiUnitName ---
42 static TCollection_AsciiString sunHertz(".HERTZ.");
43 static TCollection_AsciiString sunDegreeCelsius(".DEGREE_CELSIUS.");
44 static TCollection_AsciiString sunSiemens(".SIEMENS.");
45 static TCollection_AsciiString sunSievert(".SIEVERT.");
46 static TCollection_AsciiString sunLux(".LUX.");
47 static TCollection_AsciiString sunWatt(".WATT.");
48 static TCollection_AsciiString sunOhm(".OHM.");
49 static TCollection_AsciiString sunSecond(".SECOND.");
50 static TCollection_AsciiString sunBecquerel(".BECQUEREL.");
51 static TCollection_AsciiString sunPascal(".PASCAL.");
52 static TCollection_AsciiString sunHenry(".HENRY.");
53 static TCollection_AsciiString sunTesla(".TESLA.");
54 static TCollection_AsciiString sunVolt(".VOLT.");
55 static TCollection_AsciiString sunJoule(".JOULE.");
56 static TCollection_AsciiString sunKelvin(".KELVIN.");
57 static TCollection_AsciiString sunAmpere(".AMPERE.");
58 static TCollection_AsciiString sunGram(".GRAM.");
59 static TCollection_AsciiString sunSteradian(".STERADIAN.");
60 static TCollection_AsciiString sunMole(".MOLE.");
61 static TCollection_AsciiString sunLumen(".LUMEN.");
62 static TCollection_AsciiString sunGray(".GRAY.");
63 static TCollection_AsciiString sunCandela(".CANDELA.");
64 static TCollection_AsciiString sunFarad(".FARAD.");
65 static TCollection_AsciiString sunRadian(".RADIAN.");
66 static TCollection_AsciiString sunNewton(".NEWTON.");
67 static TCollection_AsciiString sunMetre(".METRE.");
68 static TCollection_AsciiString sunWeber(".WEBER.");
69 static TCollection_AsciiString sunCoulomb(".COULOMB.");
71 RWStepBasic_RWSiUnit::RWStepBasic_RWSiUnit () {}
73 void RWStepBasic_RWSiUnit::ReadStep(const Handle(StepData_StepReaderData)& data,
74 const Standard_Integer num,
75 Handle(Interface_Check)& ach,
76 const Handle(StepBasic_SiUnit)& ent) const
78 // --- Number of Parameter Control ---
79 if (!data->CheckNbParams(num,3,ach,"si_unit")) return;
81 // --- inherited field : dimensions ---
82 // --- this field is redefined ---
83 //szv#4:S4163:12Mar99 `Standard_Boolean stat1 =` not needed
84 data->CheckDerived(num,1,"dimensions",ach,Standard_False);
86 // --- own field : prefix ---
87 StepBasic_SiPrefix aPrefix = StepBasic_spExa;
88 Standard_Boolean hasAprefix = Standard_False;
89 if (data->IsParamDefined(num,2)) {
90 if (data->ParamType(num,2) == Interface_ParamEnum) {
91 Standard_CString text = data->ParamCValue(num,2);
92 hasAprefix = DecodePrefix(aPrefix,text);
94 ach->AddFail("Enumeration si_prefix has not an allowed value");
96 else ach->AddFail("Parameter #2 (prefix) is not an enumeration");
99 // --- own field : name ---
100 StepBasic_SiUnitName aName = StepBasic_sunMetre;
101 if (data->ParamType(num,3) == Interface_ParamEnum) {
102 Standard_CString text = data->ParamCValue(num,3);
103 if(!DecodeName(aName,text))
104 ach->AddFail("Enumeration si_unit_name has not an allowed value");
107 ach->AddFail("Parameter #3 (name) is not an enumeration");
109 //--- Initialisation of the read entity ---
110 ent->Init(hasAprefix, aPrefix, aName);
114 void RWStepBasic_RWSiUnit::WriteStep (StepData_StepWriter& SW,
115 const Handle(StepBasic_SiUnit)& ent) const
118 // --- inherited field dimensions ---
121 // --- own field : prefix ---
122 Standard_Boolean hasAprefix = ent->HasPrefix();
124 SW.SendEnum(EncodePrefix(ent->Prefix()));
128 // --- own field : name ---
129 SW.SendEnum(EncodeName(ent->Name()));
132 Standard_Boolean RWStepBasic_RWSiUnit::DecodePrefix(StepBasic_SiPrefix& aPrefix,
133 const Standard_CString text) const
135 if (spExa.IsEqual(text)) aPrefix = StepBasic_spExa;
136 else if (spPico.IsEqual(text)) aPrefix = StepBasic_spPico;
137 else if (spMega.IsEqual(text)) aPrefix = StepBasic_spMega;
138 else if (spFemto.IsEqual(text)) aPrefix = StepBasic_spFemto;
139 else if (spAtto.IsEqual(text)) aPrefix = StepBasic_spAtto;
140 else if (spCenti.IsEqual(text)) aPrefix = StepBasic_spCenti;
141 else if (spNano.IsEqual(text)) aPrefix = StepBasic_spNano;
142 else if (spHecto.IsEqual(text)) aPrefix = StepBasic_spHecto;
143 else if (spMicro.IsEqual(text)) aPrefix = StepBasic_spMicro;
144 else if (spTera.IsEqual(text)) aPrefix = StepBasic_spTera;
145 else if (spGiga.IsEqual(text)) aPrefix = StepBasic_spGiga;
146 else if (spMilli.IsEqual(text)) aPrefix = StepBasic_spMilli;
147 else if (spPeta.IsEqual(text)) aPrefix = StepBasic_spPeta;
148 else if (spDeci.IsEqual(text)) aPrefix = StepBasic_spDeci;
149 else if (spKilo.IsEqual(text)) aPrefix = StepBasic_spKilo;
150 else if (spDeca.IsEqual(text)) aPrefix = StepBasic_spDeca;
151 else return Standard_False;
152 return Standard_True;
155 Standard_Boolean RWStepBasic_RWSiUnit::DecodeName(StepBasic_SiUnitName& aName,
156 const Standard_CString text) const
158 if (sunHertz.IsEqual(text)) aName = StepBasic_sunHertz;
159 else if (sunDegreeCelsius.IsEqual(text)) aName = StepBasic_sunDegreeCelsius;
160 else if (sunSiemens.IsEqual(text)) aName = StepBasic_sunSiemens;
161 else if (sunSievert.IsEqual(text)) aName = StepBasic_sunSievert;
162 else if (sunLux.IsEqual(text)) aName = StepBasic_sunLux;
163 else if (sunWatt.IsEqual(text)) aName = StepBasic_sunWatt;
164 else if (sunOhm.IsEqual(text)) aName = StepBasic_sunOhm;
165 else if (sunSecond.IsEqual(text)) aName = StepBasic_sunSecond;
166 else if (sunBecquerel.IsEqual(text)) aName = StepBasic_sunBecquerel;
167 else if (sunPascal.IsEqual(text)) aName = StepBasic_sunPascal;
168 else if (sunHenry.IsEqual(text)) aName = StepBasic_sunHenry;
169 else if (sunTesla.IsEqual(text)) aName = StepBasic_sunTesla;
170 else if (sunVolt.IsEqual(text)) aName = StepBasic_sunVolt;
171 else if (sunJoule.IsEqual(text)) aName = StepBasic_sunJoule;
172 else if (sunKelvin.IsEqual(text)) aName = StepBasic_sunKelvin;
173 else if (sunAmpere.IsEqual(text)) aName = StepBasic_sunAmpere;
174 else if (sunGram.IsEqual(text)) aName = StepBasic_sunGram;
175 else if (sunSteradian.IsEqual(text)) aName = StepBasic_sunSteradian;
176 else if (sunMole.IsEqual(text)) aName = StepBasic_sunMole;
177 else if (sunLumen.IsEqual(text)) aName = StepBasic_sunLumen;
178 else if (sunGray.IsEqual(text)) aName = StepBasic_sunGray;
179 else if (sunCandela.IsEqual(text)) aName = StepBasic_sunCandela;
180 else if (sunFarad.IsEqual(text)) aName = StepBasic_sunFarad;
181 else if (sunRadian.IsEqual(text)) aName = StepBasic_sunRadian;
182 else if (sunNewton.IsEqual(text)) aName = StepBasic_sunNewton;
183 else if (sunMetre.IsEqual(text)) aName = StepBasic_sunMetre;
184 else if (sunWeber.IsEqual(text)) aName = StepBasic_sunWeber;
185 else if (sunCoulomb.IsEqual(text)) aName = StepBasic_sunCoulomb;
186 else return Standard_False;
187 return Standard_True;
190 TCollection_AsciiString RWStepBasic_RWSiUnit::EncodePrefix(const StepBasic_SiPrefix aPrefix) const
193 case StepBasic_spExa : return spExa;
194 case StepBasic_spPico : return spPico;
195 case StepBasic_spMega : return spMega;
196 case StepBasic_spFemto: return spFemto;
197 case StepBasic_spAtto : return spAtto;
198 case StepBasic_spCenti: return spCenti;
199 case StepBasic_spNano : return spNano;
200 case StepBasic_spHecto: return spHecto;
201 case StepBasic_spMicro: return spMicro;
202 case StepBasic_spTera : return spTera;
203 case StepBasic_spGiga : return spGiga;
204 case StepBasic_spMilli: return spMilli;
205 case StepBasic_spPeta : return spPeta;
206 case StepBasic_spDeci : return spDeci;
207 case StepBasic_spKilo : return spKilo;
208 case StepBasic_spDeca : return spDeca;
210 return TCollection_AsciiString("");
213 TCollection_AsciiString RWStepBasic_RWSiUnit::EncodeName(const StepBasic_SiUnitName aName) const
216 case StepBasic_sunHertz : return sunHertz;
217 case StepBasic_sunDegreeCelsius : return sunDegreeCelsius;
218 case StepBasic_sunSiemens : return sunSiemens;
219 case StepBasic_sunSievert : return sunSievert;
220 case StepBasic_sunLux : return sunLux;
221 case StepBasic_sunWatt : return sunWatt;
222 case StepBasic_sunOhm : return sunOhm;
223 case StepBasic_sunSecond : return sunSecond;
224 case StepBasic_sunBecquerel : return sunBecquerel;
225 case StepBasic_sunPascal : return sunPascal;
226 case StepBasic_sunHenry : return sunHenry;
227 case StepBasic_sunTesla : return sunTesla;
228 case StepBasic_sunVolt : return sunVolt;
229 case StepBasic_sunJoule : return sunJoule;
230 case StepBasic_sunKelvin : return sunKelvin;
231 case StepBasic_sunAmpere : return sunAmpere;
232 case StepBasic_sunGram : return sunGram;
233 case StepBasic_sunSteradian : return sunSteradian;
234 case StepBasic_sunMole : return sunMole;
235 case StepBasic_sunLumen : return sunLumen;
236 case StepBasic_sunGray : return sunGray;
237 case StepBasic_sunCandela : return sunCandela;
238 case StepBasic_sunFarad : return sunFarad;
239 case StepBasic_sunRadian : return sunRadian;
240 case StepBasic_sunNewton : return sunNewton;
241 case StepBasic_sunMetre : return sunMetre;
242 case StepBasic_sunWeber : return sunWeber;
243 case StepBasic_sunCoulomb : return sunCoulomb;
245 return TCollection_AsciiString("");