Files
IfcOpenShell/src/ifcparse/si_prefix.h
T

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

58 lines
2.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/>. *
* *
********************************************************************************/
#ifndef IFCSIPREFIX
#define IFCSIPREFIX
#include "ifc_parse_api.h"
#include <string>
2026-03-31 15:32:36 +02:00
namespace ifcopenshell {
IFC_PARSE_API double si_prefix_to_value(const std::string& prefix);
2017-12-18 15:25:09 +01:00
2023-09-17 12:30:17 +02:00
template <typename Schema>
2026-05-06 21:17:25 +02:00
double get_SI_equivalent(const typename Schema::IfcNamedUnit& named_unit) {
double scale = 1.;
typename Schema::IfcSIUnit si_unit;
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);
}
} else {
si_unit = named_unit.template as<typename Schema::IfcSIUnit>();
}
if (si_unit) {
if (si_unit.Prefix()) {
scale *= si_prefix_to_value(Schema::IfcSIPrefix::ToString(*si_unit.Prefix()));
}
} else {
scale = 0.;
}
return scale;
}
2026-03-31 15:32:36 +02:00
} // namespace ifcopenshell
#endif