Skip to main content

ifc_resource/author/
draft.rs

1//! Authoring input types for the bounded IFC4 resource slice.
2
3use ifc_model::EntityId;
4
5use crate::ResourceKind;
6
7/// Staged fields for authoring a concrete `IfcConstructionResource`
8/// occurrence before it is committed through `ResourceEditor`.
9#[derive(Debug, Clone)]
10#[non_exhaustive]
11pub struct ResourceDraft<'a> {
12    pub(crate) kind: ResourceKind,
13    pub(crate) global_id: &'a str,
14    pub(crate) name: Option<&'a str>,
15    pub(crate) identification: Option<&'a str>,
16    pub(crate) long_description: Option<&'a str>,
17    pub(crate) object_type: Option<&'a str>,
18    pub(crate) usage: Option<EntityId>,
19    pub(crate) base_costs: Vec<EntityId>,
20    pub(crate) base_quantity: Option<EntityId>,
21    pub(crate) predefined_type: Option<&'a str>,
22}
23
24impl<'a> ResourceDraft<'a> {
25    /// Starts a draft for the given resource subtype and `GlobalId`.
26    #[must_use]
27    pub fn new(kind: ResourceKind, global_id: &'a str) -> Self {
28        Self {
29            kind,
30            global_id,
31            name: None,
32            identification: None,
33            long_description: None,
34            object_type: None,
35            usage: None,
36            base_costs: Vec::new(),
37            base_quantity: None,
38            predefined_type: None,
39        }
40    }
41
42    /// Sets the `Name` attribute.
43    #[must_use]
44    pub fn name(mut self, value: &'a str) -> Self {
45        self.name = Some(value);
46        self
47    }
48
49    /// Sets the `Identification` attribute.
50    #[must_use]
51    pub fn identification(mut self, value: &'a str) -> Self {
52        self.identification = Some(value);
53        self
54    }
55
56    /// Sets the `LongDescription` attribute.
57    #[must_use]
58    pub fn long_description(mut self, value: &'a str) -> Self {
59        self.long_description = Some(value);
60        self
61    }
62
63    /// Sets the `ObjectType` attribute; required when `predefined_type` is
64    /// `USERDEFINED`.
65    #[must_use]
66    pub fn object_type(mut self, value: &'a str) -> Self {
67        self.object_type = Some(value);
68        self
69    }
70
71    /// Sets the `Usage` attribute: a reference to an authored
72    /// `IfcResourceTime`.
73    #[must_use]
74    pub fn usage(mut self, value: EntityId) -> Self {
75        self.usage = Some(value);
76        self
77    }
78
79    /// Sets the `BaseCosts` attribute: applied-value references.
80    #[must_use]
81    pub fn base_costs(mut self, values: Vec<EntityId>) -> Self {
82        self.base_costs = values;
83        self
84    }
85
86    /// Sets the `BaseQuantity` attribute: a physical-quantity reference.
87    #[must_use]
88    pub fn base_quantity(mut self, value: EntityId) -> Self {
89        self.base_quantity = Some(value);
90        self
91    }
92
93    /// Sets the `PredefinedType` enumeration.
94    #[must_use]
95    pub fn predefined_type(mut self, value: &'a str) -> Self {
96        self.predefined_type = Some(value);
97        self
98    }
99}
100
101/// Staged fields for authoring an `IfcResourceTime` before it is committed
102/// through `ResourceEditor`.
103#[derive(Debug, Clone, Default)]
104#[non_exhaustive]
105pub struct ResourceTimeDraft<'a> {
106    pub(crate) name: Option<&'a str>,
107    pub(crate) schedule_work: Option<&'a str>,
108    pub(crate) schedule_usage: Option<f64>,
109    pub(crate) schedule_start: Option<&'a str>,
110    pub(crate) schedule_finish: Option<&'a str>,
111    pub(crate) is_over_allocated: Option<bool>,
112    pub(crate) status_time: Option<&'a str>,
113    pub(crate) actual_work: Option<&'a str>,
114    pub(crate) actual_usage: Option<f64>,
115    pub(crate) actual_start: Option<&'a str>,
116    pub(crate) actual_finish: Option<&'a str>,
117    pub(crate) remaining_work: Option<&'a str>,
118    pub(crate) remaining_usage: Option<f64>,
119    pub(crate) completion: Option<f64>,
120}
121
122impl<'a> ResourceTimeDraft<'a> {
123    /// Starts an empty draft with every attribute unset.
124    #[must_use]
125    pub fn new() -> Self {
126        Self::default()
127    }
128
129    /// Sets the `Name` attribute.
130    #[must_use]
131    pub fn name(mut self, value: &'a str) -> Self {
132        self.name = Some(value);
133        self
134    }
135
136    /// Sets the `ScheduleWork` duration.
137    #[must_use]
138    pub fn schedule_work(mut self, value: &'a str) -> Self {
139        self.schedule_work = Some(value);
140        self
141    }
142
143    /// Sets the `ScheduleUsage` ratio.
144    #[must_use]
145    pub fn schedule_usage(mut self, value: f64) -> Self {
146        self.schedule_usage = Some(value);
147        self
148    }
149
150    /// Sets the `ScheduleStart` date-time.
151    #[must_use]
152    pub fn schedule_start(mut self, value: &'a str) -> Self {
153        self.schedule_start = Some(value);
154        self
155    }
156
157    /// Sets the `ScheduleFinish` date-time.
158    #[must_use]
159    pub fn schedule_finish(mut self, value: &'a str) -> Self {
160        self.schedule_finish = Some(value);
161        self
162    }
163
164    /// Sets the `IsOverAllocated` flag.
165    #[must_use]
166    pub fn is_over_allocated(mut self, value: bool) -> Self {
167        self.is_over_allocated = Some(value);
168        self
169    }
170
171    /// Sets the `StatusTime` date-time.
172    #[must_use]
173    pub fn status_time(mut self, value: &'a str) -> Self {
174        self.status_time = Some(value);
175        self
176    }
177
178    /// Sets the `ActualWork` duration.
179    #[must_use]
180    pub fn actual_work(mut self, value: &'a str) -> Self {
181        self.actual_work = Some(value);
182        self
183    }
184
185    /// Sets the `ActualUsage` ratio.
186    #[must_use]
187    pub fn actual_usage(mut self, value: f64) -> Self {
188        self.actual_usage = Some(value);
189        self
190    }
191
192    /// Sets the `ActualStart` date-time.
193    #[must_use]
194    pub fn actual_start(mut self, value: &'a str) -> Self {
195        self.actual_start = Some(value);
196        self
197    }
198
199    /// Sets the `ActualFinish` date-time.
200    #[must_use]
201    pub fn actual_finish(mut self, value: &'a str) -> Self {
202        self.actual_finish = Some(value);
203        self
204    }
205
206    /// Sets the `RemainingWork` duration.
207    #[must_use]
208    pub fn remaining_work(mut self, value: &'a str) -> Self {
209        self.remaining_work = Some(value);
210        self
211    }
212
213    /// Sets the `RemainingUsage` ratio.
214    #[must_use]
215    pub fn remaining_usage(mut self, value: f64) -> Self {
216        self.remaining_usage = Some(value);
217        self
218    }
219
220    /// Sets the `Completion` percentage.
221    #[must_use]
222    pub fn completion(mut self, value: f64) -> Self {
223        self.completion = Some(value);
224        self
225    }
226}
227
228/// Staged fields for authoring an `IfcRelAssignsToResource` relation before
229/// it is committed through `ResourceEditor`.
230#[derive(Debug, Clone)]
231#[non_exhaustive]
232pub struct AllocationDraft<'a> {
233    pub(crate) global_id: &'a str,
234    pub(crate) name: Option<&'a str>,
235    pub(crate) description: Option<&'a str>,
236    pub(crate) resource: EntityId,
237    pub(crate) related_objects: Vec<EntityId>,
238    pub(crate) related_objects_type: Option<&'a str>,
239}
240
241impl<'a> AllocationDraft<'a> {
242    /// Starts a draft assigning `related_objects` to `resource`.
243    #[must_use]
244    pub fn new(global_id: &'a str, resource: EntityId, related_objects: Vec<EntityId>) -> Self {
245        Self {
246            global_id,
247            name: None,
248            description: None,
249            resource,
250            related_objects,
251            related_objects_type: None,
252        }
253    }
254
255    /// Sets the `Name` attribute.
256    #[must_use]
257    pub fn name(mut self, value: &'a str) -> Self {
258        self.name = Some(value);
259        self
260    }
261
262    /// Sets the `Description` attribute.
263    #[must_use]
264    pub fn description(mut self, value: &'a str) -> Self {
265        self.description = Some(value);
266        self
267    }
268
269    /// Sets the `RelatedObjectsType` enumeration.
270    #[must_use]
271    pub fn related_objects_type(mut self, value: &'a str) -> Self {
272        self.related_objects_type = Some(value);
273        self
274    }
275}
276
277/// Staged fields for authoring an `IfcRelNests` relation that nests
278/// resources under a parent before it is committed through
279/// `ResourceEditor`.
280#[derive(Debug, Clone)]
281#[non_exhaustive]
282pub struct NestingDraft<'a> {
283    pub(crate) global_id: &'a str,
284    pub(crate) name: Option<&'a str>,
285    pub(crate) description: Option<&'a str>,
286    pub(crate) parent: EntityId,
287    pub(crate) children: Vec<EntityId>,
288}
289
290impl<'a> NestingDraft<'a> {
291    /// Starts a draft nesting `children` under `parent`.
292    #[must_use]
293    pub fn new(global_id: &'a str, parent: EntityId, children: Vec<EntityId>) -> Self {
294        Self {
295            global_id,
296            name: None,
297            description: None,
298            parent,
299            children,
300        }
301    }
302
303    /// Sets the `Name` attribute.
304    #[must_use]
305    pub fn name(mut self, value: &'a str) -> Self {
306        self.name = Some(value);
307        self
308    }
309
310    /// Sets the `Description` attribute.
311    #[must_use]
312    pub fn description(mut self, value: &'a str) -> Self {
313        self.description = Some(value);
314        self
315    }
316}