Files
IfcOpenShell/src/ifcparse/IfcSIPrefix.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 lines
7.5 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"
#include "InstanceData.h"
#ifdef HAS_SCHEMA_2x3
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc2x3.h"
#endif
#ifdef HAS_SCHEMA_4
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4.h"
#endif
#ifdef HAS_SCHEMA_4x1
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x1.h"
#endif
#ifdef HAS_SCHEMA_4x2
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc1
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_rc1.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc2
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_rc2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc3
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_rc3.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc4
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_rc4.h"
#endif
2022-07-17 21:13:46 +02:00
#ifdef HAS_SCHEMA_4x3
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3.h"
2022-07-17 21:13:46 +02:00
#endif
#ifdef HAS_SCHEMA_4x3_tc1
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_tc1.h"
#endif
2022-11-21 09:43:13 +01:00
#ifdef HAS_SCHEMA_4x3_add1
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_add1.h"
2022-11-21 09:43:13 +01:00
#endif
2023-10-18 09:46:29 +02:00
#ifdef HAS_SCHEMA_4x3_add2
2026-03-31 10:02:00 +02:00
#include "schemas/Ifc4x3_add2.h"
2023-10-18 09:46:29 +02:00
#endif
2017-12-20 16:38:55 +01:00
double IfcParse::IfcSIPrefixToValue(const std::string& prefix) {
if (prefix == "EXA") {
2023-09-17 12:30:17 +02:00
return 1.e18;
}
if (prefix == "PETA") {
2023-09-17 12:30:17 +02:00
return 1.e15;
}
if (prefix == "TERA") {
2023-09-17 12:30:17 +02:00
return 1.e12;
}
if (prefix == "GIGA") {
2023-09-17 12:30:17 +02:00
return 1.e9;
}
if (prefix == "MEGA") {
2023-09-17 12:30:17 +02:00
return 1.e6;
}
if (prefix == "KILO") {
2023-09-17 12:30:17 +02:00
return 1.e3;
}
if (prefix == "HECTO") {
2023-09-17 12:30:17 +02:00
return 1.e2;
}
if (prefix == "DECA") {
2023-09-17 12:30:17 +02:00
return 1.e1;
}
if (prefix == "DECI") {
2023-09-17 12:30:17 +02:00
return 1.e-1;
}
if (prefix == "CENTI") {
2023-09-17 12:30:17 +02:00
return 1.e-2;
}
if (prefix == "MILLI") {
2023-09-17 12:30:17 +02:00
return 1.e-3;
}
if (prefix == "MICRO") {
2023-09-17 12:30:17 +02:00
return 1.e-6;
}
if (prefix == "NANO") {
2023-09-17 12:30:17 +02:00
return 1.e-9;
}
if (prefix == "PICO") {
2023-09-17 12:30:17 +02:00
return 1.e-12;
}
if (prefix == "FEMTO") {
2023-09-17 12:30:17 +02:00
return 1.e-15;
}
if (prefix == "ATTO") {
2023-09-17 12:30:17 +02:00
return 1.e-18;
}
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(const typename Schema::IfcNamedUnit& named_unit) {
2023-09-17 12:30:17 +02:00
double scale = 1.;
typename Schema::IfcSIUnit si_unit;
2016-05-24 13:50:50 +02:00
if (auto conv_unit = named_unit.template as<typename Schema::IfcConversionBasedUnit>()) {
auto factor = conv_unit.ConversionFactor();
auto component = factor.UnitComponent();
if (si_unit = component.concrete().template as<typename Schema::IfcSIUnit>()) {
auto value = factor.ValueComponent();
scale = value.get_attribute_value(0);
2023-09-17 12:30:17 +02:00
}
} else {
si_unit = named_unit.template as<typename Schema::IfcSIUnit>();
2023-09-17 12:30:17 +02:00
}
if (si_unit) {
if (si_unit.Prefix()) {
scale *= IfcSIPrefixToValue(Schema::IfcSIPrefix::ToString(*si_unit.Prefix()));
2023-09-17 12:30:17 +02:00
}
} else {
scale = 0.;
}
2016-05-24 13:50:50 +02:00
2023-09-17 12:30:17 +02:00
return scale;
}
2017-12-20 16:38:55 +01:00
2020-07-23 10:49:45 +02:00
#if defined(_MSC_VER) && _MSC_VER < 1900
#ifdef HAS_SCHEMA_2x3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc2x3>(const Ifc2x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4>(const Ifc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x1>(const Ifc4x1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x2>(const Ifc4x2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc1>(const Ifc4x3_rc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc2>(const Ifc4x3_rc2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc3>(const Ifc4x3_rc3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc4
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc4>(const Ifc4x3_rc4::IfcNamedUnit& named_unit);
#endif
2022-07-17 21:13:46 +02:00
#ifdef HAS_SCHEMA_4x3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3>(const Ifc4x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_tc1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_tc1>(const Ifc4x3_tc1::IfcNamedUnit& named_unit);
2022-11-21 09:43:13 +01:00
#endif
#ifdef HAS_SCHEMA_4x3_add1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_add1>(const Ifc4x3_add1::IfcNamedUnit& named_unit);
2022-07-17 21:13:46 +02:00
#endif
2023-10-18 09:46:29 +02:00
#ifdef HAS_SCHEMA_4x3_add2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_add2>(const Ifc4x3_add2::IfcNamedUnit& named_unit);
2023-10-18 09:46:29 +02:00
#endif
2020-07-23 10:49:45 +02:00
#else
#ifdef HAS_SCHEMA_2x3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc2x3>(const typename Ifc2x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4>(const typename Ifc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x1>(const typename Ifc4x1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x2>(const typename Ifc4x2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc1>(const typename Ifc4x3_rc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc2>(const typename Ifc4x3_rc2::IfcNamedUnit& named_unit);
2020-07-14 12:17:13 +02:00
#endif
#ifdef HAS_SCHEMA_4x3_rc3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc3>(const typename Ifc4x3_rc3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc4
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_rc4>(const typename Ifc4x3_rc4::IfcNamedUnit& named_unit);
#endif
2022-07-17 21:13:46 +02:00
#ifdef HAS_SCHEMA_4x3
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3>(const typename Ifc4x3::IfcNamedUnit& named_unit);
2022-07-17 21:13:46 +02:00
#endif
#ifdef HAS_SCHEMA_4x3_tc1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_tc1>(const typename Ifc4x3_tc1::IfcNamedUnit& named_unit);
#endif
2022-11-21 09:43:13 +01:00
#ifdef HAS_SCHEMA_4x3_add1
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_add1>(const typename Ifc4x3_add1::IfcNamedUnit& named_unit);
2022-11-21 09:43:13 +01:00
#endif
2023-10-18 09:46:29 +02:00
#ifdef HAS_SCHEMA_4x3_add2
template double IFC_PARSE_API IfcParse::get_SI_equivalent<Ifc4x3_add2>(const typename Ifc4x3_add2::IfcNamedUnit& named_unit);
2023-10-18 09:46:29 +02:00
#endif
#endif