-
-
Notifications
You must be signed in to change notification settings - Fork 901
Expand file tree
/
Copy pathsi_prefix.cpp
More file actions
216 lines (205 loc) · 7.64 KB
/
si_prefix.cpp
File metadata and controls
216 lines (205 loc) · 7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#include "si_prefix.h"
#include "instance_data.h"
#ifdef HAS_SCHEMA_2x3
#include "schemas/Ifc2x3.h"
#endif
#ifdef HAS_SCHEMA_4
#include "schemas/Ifc4.h"
#endif
#ifdef HAS_SCHEMA_4x1
#include "schemas/Ifc4x1.h"
#endif
#ifdef HAS_SCHEMA_4x2
#include "schemas/Ifc4x2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc1
#include "schemas/Ifc4x3_rc1.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc2
#include "schemas/Ifc4x3_rc2.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc3
#include "schemas/Ifc4x3_rc3.h"
#endif
#ifdef HAS_SCHEMA_4x3_rc4
#include "schemas/Ifc4x3_rc4.h"
#endif
#ifdef HAS_SCHEMA_4x3
#include "schemas/Ifc4x3.h"
#endif
#ifdef HAS_SCHEMA_4x3_tc1
#include "schemas/Ifc4x3_tc1.h"
#endif
#ifdef HAS_SCHEMA_4x3_add1
#include "schemas/Ifc4x3_add1.h"
#endif
#ifdef HAS_SCHEMA_4x3_add2
#include "schemas/Ifc4x3_add2.h"
#endif
double ifcopenshell::si_prefix_to_value(const std::string& prefix) {
if (prefix == "EXA") {
return 1.e18;
}
if (prefix == "PETA") {
return 1.e15;
}
if (prefix == "TERA") {
return 1.e12;
}
if (prefix == "GIGA") {
return 1.e9;
}
if (prefix == "MEGA") {
return 1.e6;
}
if (prefix == "KILO") {
return 1.e3;
}
if (prefix == "HECTO") {
return 1.e2;
}
if (prefix == "DECA") {
return 1.e1;
}
if (prefix == "DECI") {
return 1.e-1;
}
if (prefix == "CENTI") {
return 1.e-2;
}
if (prefix == "MILLI") {
return 1.e-3;
}
if (prefix == "MICRO") {
return 1.e-6;
}
if (prefix == "NANO") {
return 1.e-9;
}
if (prefix == "PICO") {
return 1.e-12;
}
if (prefix == "FEMTO") {
return 1.e-15;
}
if (prefix == "ATTO") {
return 1.e-18;
}
return 1.;
}
template <typename Schema>
double ifcopenshell::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;
}
#if defined(_MSC_VER) && _MSC_VER < 1900
#ifdef HAS_SCHEMA_2x3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc2x3>(const Ifc2x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4>(const Ifc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x1>(const Ifc4x1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x2>(const Ifc4x2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc1>(const Ifc4x3_rc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc2>(const Ifc4x3_rc2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc3>(const Ifc4x3_rc3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc4
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc4>(const Ifc4x3_rc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3>(const Ifc4x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_tc1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_tc1>(const Ifc4x3_tc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_add1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_add1>(const Ifc4x3_add1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_add2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_add2>(const Ifc4x3_add2::IfcNamedUnit& named_unit);
#endif
#else
#ifdef HAS_SCHEMA_2x3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc2x3>(const typename Ifc2x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4>(const typename Ifc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x1>(const typename Ifc4x1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x2>(const typename Ifc4x2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc1>(const typename Ifc4x3_rc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc2>(const typename Ifc4x3_rc2::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc3>(const typename Ifc4x3_rc3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_rc4
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_rc4>(const typename Ifc4x3_rc4::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3>(const typename Ifc4x3::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_tc1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_tc1>(const typename Ifc4x3_tc1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_add1
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_add1>(const typename Ifc4x3_add1::IfcNamedUnit& named_unit);
#endif
#ifdef HAS_SCHEMA_4x3_add2
template double IFC_PARSE_API ifcopenshell::get_SI_equivalent<Ifc4x3_add2>(const typename Ifc4x3_add2::IfcNamedUnit& named_unit);
#endif
#endif