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