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