Files
IfcOpenShell/src/ifcparse/IfcSIPrefix.cpp
T

89 lines
4.3 KiB
C++
Raw Normal View History

/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
2017-12-20 16:38:55 +01:00
#include "IfcSIPrefix.h"
2017-12-20 16:38:55 +01:00
#include "../ifcparse/Ifc2x3.h"
#include "../ifcparse/Ifc4.h"
#include "../ifcparse/Ifc4x1.h"
#include "../ifcparse/Ifc4x2.h"
#include "../ifcparse/Ifc4x3_rc1.h"
2017-12-20 16:38:55 +01:00
double IfcParse::IfcSIPrefixToValue(const std::string& v) {
if ( v == "EXA" ) return 1.e18;
else if ( v == "PETA" ) return 1.e15;
else if ( v == "TERA" ) return 1.e12;
else if ( v == "GIGA" ) return 1.e9;
else if ( v == "MEGA" ) return 1.e6;
else if ( v == "KILO" ) return 1.e3;
else if ( v == "HECTO" ) return 1.e2;
else if ( v == "DECA" ) return 1.;
else if ( v == "DECI" ) return 1.e-1;
else if ( v == "CENTI" ) return 1.e-2;
else if ( v == "MILLI" ) return 1.e-3;
else if ( v == "MICRO" ) return 1.e-6;
else if ( v == "NANO" ) return 1.e-9;
else if ( v == "PICO" ) return 1.e-12;
else if ( v == "FEMTO" ) return 1.e-15;
else if ( v == "ATTO" ) return 1.e-18;
else return 1.;
2016-05-24 13:50:50 +02:00
}
2017-12-18 15:25:09 +01:00
template <typename Schema>
double IfcParse::get_SI_equivalent(typename Schema::IfcNamedUnit* named_unit) {
2016-05-24 13:50:50 +02:00
double scale = 1.;
2017-12-20 16:38:55 +01:00
typename Schema::IfcSIUnit* si_unit = 0;
2016-05-24 13:50:50 +02:00
2017-12-20 16:38:55 +01:00
if (named_unit->declaration().is(Schema::IfcConversionBasedUnit::Class())) {
typename Schema::IfcConversionBasedUnit* conv_unit = named_unit->template as<typename Schema::IfcConversionBasedUnit>();
2017-12-20 16:38:55 +01:00
typename Schema::IfcMeasureWithUnit* factor = conv_unit->ConversionFactor();
typename Schema::IfcUnit* component = factor->UnitComponent();
if (component->declaration().is(Schema::IfcSIUnit::Class())) {
si_unit = component->template as<typename Schema::IfcSIUnit>();
2017-12-20 16:38:55 +01:00
typename Schema::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-20 16:38:55 +01:00
} else if (named_unit->declaration().is(Schema::IfcSIUnit::Class())) {
si_unit = named_unit->template as<typename Schema::IfcSIUnit>();
2016-05-24 13:50:50 +02:00
}
if (si_unit) {
if (si_unit->hasPrefix()) {
2017-12-20 16:38:55 +01:00
scale *= IfcSIPrefixToValue(Schema::IfcSIPrefix::ToString(si_unit->Prefix()));
2016-05-24 13:50:50 +02:00
}
} else {
scale = 0.;
}
return scale;
}
2017-12-20 16:38:55 +01:00
2020-07-14 12:17:13 +02:00
#if _MSC_VER < 1900
template double IfcParse::get_SI_equivalent<Ifc2x3>(Ifc2x3::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4>(Ifc4::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x1>(Ifc4x1::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x2>(Ifc4x2::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x3_rc1>(Ifc4x3_rc1::IfcNamedUnit* named_unit);
#else
2017-12-20 16:38:55 +01:00
template double IfcParse::get_SI_equivalent<Ifc2x3>(typename Ifc2x3::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4>(typename Ifc4::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x1>(typename Ifc4x1::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x2>(typename Ifc4x2::IfcNamedUnit* named_unit);
template double IfcParse::get_SI_equivalent<Ifc4x3_rc1>(typename Ifc4x3_rc1::IfcNamedUnit* named_unit);
2020-07-14 12:17:13 +02:00
#endif