2014-12-19 12:14:36 +00:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
2015-02-17 19:48:41 +00:00
|
|
|
#include "IfcSIPrefix.h"
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-02-17 19:48:41 +00:00
|
|
|
double IfcParse::IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix v) {
|
2014-12-19 12:14:36 +00:00
|
|
|
if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_EXA ) return 1.e18;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PETA ) return 1.e15;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_TERA ) return 1.e12;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_GIGA ) return 1.e9;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MEGA ) return 1.e6;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_KILO ) return 1.e3;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_HECTO ) return 1.e2;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECA ) return 1.;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECI ) return 1.e-1;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_CENTI ) return 1.e-2;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MILLI ) return 1.e-3;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MICRO ) return 1.e-6;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_NANO ) return 1.e-9;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PICO ) return 1.e-12;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_FEMTO ) return 1.e-15;
|
|
|
|
|
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_ATTO ) return 1.e-18;
|
2015-02-17 19:48:41 +00:00
|
|
|
else return 1.;
|
2016-05-24 13:50:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
|
|
|
|
|
double scale = 1.;
|
|
|
|
|
IfcSchema::IfcSIUnit* si_unit = 0;
|
|
|
|
|
|
2017-12-11 14:47:30 +01:00
|
|
|
if (named_unit->declaration().is(IfcSchema::Type::IfcConversionBasedUnit)) {
|
2016-05-24 13:50:50 +02:00
|
|
|
IfcSchema::IfcConversionBasedUnit* conv_unit = named_unit->as<IfcSchema::IfcConversionBasedUnit>();
|
|
|
|
|
IfcSchema::IfcMeasureWithUnit* factor = conv_unit->ConversionFactor();
|
|
|
|
|
IfcSchema::IfcUnit* component = factor->UnitComponent();
|
2017-12-11 14:47:30 +01:00
|
|
|
if (component->declaration().is(IfcSchema::Type::IfcSIUnit)) {
|
2016-05-24 13:50:50 +02:00
|
|
|
si_unit = component->as<IfcSchema::IfcSIUnit>();
|
|
|
|
|
IfcSchema::IfcValue* v = factor->ValueComponent();
|
2017-12-11 14:47:30 +01:00
|
|
|
scale = *v->data().getArgument(0);
|
2016-05-24 13:50:50 +02:00
|
|
|
}
|
2017-12-11 14:47:30 +01:00
|
|
|
} else if (named_unit->declaration().is(IfcSchema::Type::IfcSIUnit)) {
|
2016-05-24 13:50:50 +02:00
|
|
|
si_unit = named_unit->as<IfcSchema::IfcSIUnit>();
|
|
|
|
|
}
|
|
|
|
|
if (si_unit) {
|
|
|
|
|
if (si_unit->hasPrefix()) {
|
|
|
|
|
scale *= IfcSIPrefixToValue(si_unit->Prefix());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scale = 0.;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return scale;
|
2014-12-19 12:14:36 +00:00
|
|
|
}
|