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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//! Staging authored quantity updates onto a transaction.
//!
//! # This module stages; it does not commit
//!
//! Every function here takes a `&mut Transaction` and adds edits to it. None
//! of them touch the model. That is deliberate: a takeoff run updates areas on
//! two hundred elements, and those either all land or none do. If each helper
//! committed, a failure halfway through would leave a file whose quantities
//! disagree with each other, which is worse than a file that was never
//! updated.
//!
//! The caller decides the boundary:
//!
//! ```
//! use ifc_model::{Model, Transaction};
//! use ifc_properties::{set_quantity_value, QuantityKind};
//!
//! # fn run(model: &mut Model, area: ifc_model::EntityId) -> Result<(), Box<dyn std::error::Error>> {
//! let mut tx = Transaction::new(model);
//! set_quantity_value(&mut tx, model, area, 12.5)?;
//! // ... stage the rest of the takeoff ...
//! tx.commit(model).map_err(|c| format!("{c:?}"))?;
//! # Ok(())
//! # }
//! ```
//!
//! # The value is written bare
//!
//! A quantity's value slot is typed by its declaration: `IfcQuantityArea`
//! declares `AreaValue : IfcAreaMeasure`, a defined type and not a SELECT.
//! The measure is therefore already stated by the schema, and ISO 10303-21
//! writes the simple value there (`12.5`); a typed parameter such as
//! `IFCAREAMEASURE(12.5)` belongs only in a SELECT slot, where the type is
//! otherwise ambiguous (#190). The readers accept both forms, because files
//! in the wild carry both. These helpers refuse when the target is not the
//! kind of quantity the caller thinks it is, rather than coerce it.
use ;
use cratePropertyError;
use cratebind;
use crateQuantityKind;
/// Stage a new value for an existing simple quantity.
///
/// The value is written into the slot the model's declared release gives
/// the quantity's value attribute (`release.rs` has the binding), as a bare
/// number: the schema fixes which measure each subtype carries, so no
/// wrapper is written. A value read in the typed form
/// (`IFCAREAMEASURE(12.5)`) is replaced by the bare one. This also repairs
/// a quantity read as [`Quantity::Unresolved`](crate::Quantity::Unresolved).
///
/// # Errors
///
/// Nothing is staged on an error:
/// [`PropertyError::MissingEntity`] if `id` is not in the model,
/// [`PropertyError::NotAQuantity`] if it is not a simple quantity,
/// [`PropertyError::MultipleSchemas`] or [`PropertyError::UnsupportedSchema`]
/// if the model binds no single release,
/// [`PropertyError::EntityNotInSchema`] if that release does not declare the
/// quantity's entity, [`PropertyError::MalformedEntitySlots`] if the record
/// does not have the release's attribute count, and
/// [`PropertyError::AuthoringInvalid`] for a value its measure cannot hold.
/// Stage a new `Name` for a quantity or property.
///
/// Slot 0 on both `IfcPhysicalQuantity` and `IfcProperty`.
///
/// # Errors
///
/// [`PropertyError::MissingEntity`] if `id` is not in the model.
/// Stage a new `Description`, or clear it with `None`.
///
/// Slot 1 on both `IfcPhysicalQuantity` and `IfcProperty`. `None` writes
/// `Value::Null`, which is STEP's `$` -- the attribute is genuinely unset,
/// not set to an empty string. The distinction survives a round trip and a
/// consumer can tell "no description" from "description is blank".
///
/// # Errors
///
/// [`PropertyError::MissingEntity`] if `id` is not in the model.
/// Stage a brand-new simple quantity in `model`'s release, returning the id
/// reserved for it.
///
/// The entity is created with its value written bare in the slot whose
/// declared measure its kind implies, and no unit, meaning "the project
/// default applies" -- which is what most authored quantities mean. Attach
/// it to a set with [`add_quantity_to_set`].
///
/// # Errors
///
/// As [`create_quantity_with`].
/// The optional attributes of an `IfcPhysicalSimpleQuantity`.
///
/// Separated from [`create_quantity`] so the common call stays short,
/// while `Description`, `Unit` and `Formula` remain reachable. They are
/// attributes of the entity, not decoration: the reader in this crate
/// resolves all three.
/// Stage a simple quantity with its optional attributes, in `model`'s
/// release.
///
/// # The record has the release's layout
///
/// Attributes are placed by name in the declared release's table. IFC4 and
/// IFC4X3 quantities have five attributes (`Name`, `Description`, `Unit`,
/// the value, `Formula`); IFC2X3 ones have four, with no `Formula`. A
/// model without `FILE_SCHEMA` binds IFC4. The value is written bare
/// (`IFCQUANTITYAREA('A',$,$,12.5,$)`), since its declared type is a
/// defined measure and not a SELECT.
///
/// # Errors
///
/// Nothing is staged on an error:
/// - [`PropertyError::MultipleSchemas`] or
/// [`PropertyError::UnsupportedSchema`]: the model binds no single release.
/// - [`PropertyError::EntityNotInSchema`]: the release does not declare the
/// kind, as `IfcQuantityNumber` outside IFC4X3.
/// - [`PropertyError::AuthoringNotInSchema`]: a `Formula` for an IFC2X3
/// model, which has none.
/// - [`PropertyError::AuthoringInvalid`]: a non-finite value, or a
/// fractional count where `IfcCountMeasure` is `INTEGER` (IFC4X3). In
/// IFC2X3 and IFC4 it is `NUMBER`, so a fractional count is written as a
/// real, and never truncated.
/// Stage adding a quantity to an existing `IfcElementQuantity`.
///
/// Reads the set's current contents and writes back the extended list, so
/// this is a read-modify-write against the model as it stands. Two calls
/// adding to the same set in one transaction would each be computed from the
/// same starting list and the second would win -- add both in one call
/// instead.
///
/// # Errors
///
/// [`PropertyError::MissingEntity`] if the set is absent, and
/// [`PropertyError::NotAQuantitySet`] if it is not an `IfcElementQuantity`.