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