Skip to main content

ifc_schedule/authoring/
builders.rs

1//! Constructors and setters for the schedule drafts.
2//!
3//! The drafts are `#[non_exhaustive]` so they can grow a field when a
4//! release needs one (#214) without breaking callers: build one with `new`
5//! and the setters, each named after the field it sets, as
6//! `ifc-resource`'s drafts are built.
7
8use ifc_model::EntityId;
9
10use super::procedure::ProcedureDraft;
11use super::timing::TaskTimeDraft;
12use super::{
13    DateTimeValue, EventDraft, EventTimeDraft, RecurrenceDraft, TaskDraft, WorkControlDraft,
14};
15
16impl<'a> TaskDraft<'a> {
17    /// Starts a draft for an `IfcTask` with its `GlobalId` and every optional
18    /// attribute unset, `IsMilestone` false.
19    #[must_use]
20    pub fn new(global_id: &'a str) -> Self {
21        Self {
22            global_id,
23            ..Self::default()
24        }
25    }
26
27    /// Sets `IfcRoot.Name`.
28    #[must_use]
29    pub fn name(mut self, value: &'a str) -> Self {
30        self.name = Some(value);
31        self
32    }
33
34    /// Sets `IfcRoot.Description`.
35    #[must_use]
36    pub fn description(mut self, value: &'a str) -> Self {
37        self.description = Some(value);
38        self
39    }
40
41    /// Sets `IfcProcess.Identification` (IFC2X3 `TaskId`).
42    #[must_use]
43    pub fn identification(mut self, value: &'a str) -> Self {
44        self.identification = Some(value);
45        self
46    }
47
48    /// Sets `IfcProcess.LongDescription`.
49    #[must_use]
50    pub fn long_description(mut self, value: &'a str) -> Self {
51        self.long_description = Some(value);
52        self
53    }
54
55    /// Sets `IfcTask.Status`.
56    #[must_use]
57    pub fn status(mut self, value: &'a str) -> Self {
58        self.status = Some(value);
59        self
60    }
61
62    /// Sets `IfcTask.WorkMethod`.
63    #[must_use]
64    pub fn work_method(mut self, value: &'a str) -> Self {
65        self.work_method = Some(value);
66        self
67    }
68
69    /// Sets `IfcTask.IsMilestone`.
70    #[must_use]
71    pub fn is_milestone(mut self, value: bool) -> Self {
72        self.is_milestone = value;
73        self
74    }
75
76    /// Sets `IfcTask.Priority`, an integer in `0..=100`.
77    #[must_use]
78    pub fn priority(mut self, value: i64) -> Self {
79        self.priority = Some(value);
80        self
81    }
82
83    /// Sets `IfcTask.TaskTime`, an `IfcTaskTime` reference.
84    #[must_use]
85    pub fn task_time(mut self, value: EntityId) -> Self {
86        self.task_time = Some(value);
87        self
88    }
89
90    /// Sets `IfcTask.PredefinedType`.
91    #[must_use]
92    pub fn predefined_type(mut self, value: &'a str) -> Self {
93        self.predefined_type = Some(value);
94        self
95    }
96}
97
98impl<'a> WorkControlDraft<'a> {
99    /// Starts a draft for an `IfcWorkPlan` or `IfcWorkSchedule` with its
100    /// required `GlobalId`, `CreationDate` and `StartTime`; each date is
101    /// ISO 8601 text (`&str`, IFC4 and IFC4X3) or an IFC2X3 record form.
102    #[must_use]
103    pub fn new(
104        global_id: &'a str,
105        creation_date: impl Into<DateTimeValue<'a>>,
106        start_time: impl Into<DateTimeValue<'a>>,
107    ) -> Self {
108        Self {
109            global_id,
110            creation_date: creation_date.into(),
111            start_time: start_time.into(),
112            ..Self::default()
113        }
114    }
115
116    /// Sets `IfcRoot.Name`.
117    #[must_use]
118    pub fn name(mut self, value: &'a str) -> Self {
119        self.name = Some(value);
120        self
121    }
122
123    /// Sets `IfcRoot.Description`.
124    #[must_use]
125    pub fn description(mut self, value: &'a str) -> Self {
126        self.description = Some(value);
127        self
128    }
129
130    /// Sets `IfcWorkControl.Identification` (IFC2X3 `Identifier`).
131    #[must_use]
132    pub fn identification(mut self, value: &'a str) -> Self {
133        self.identification = Some(value);
134        self
135    }
136
137    /// Sets `IfcWorkControl.Purpose`.
138    #[must_use]
139    pub fn purpose(mut self, value: &'a str) -> Self {
140        self.purpose = Some(value);
141        self
142    }
143
144    /// Sets `IfcWorkControl.Duration`, an ISO 8601 duration.
145    #[must_use]
146    pub fn duration(mut self, value: &'a str) -> Self {
147        self.duration = Some(value);
148        self
149    }
150
151    /// Sets `IfcWorkControl.TotalFloat`, an ISO 8601 duration.
152    #[must_use]
153    pub fn total_float(mut self, value: &'a str) -> Self {
154        self.total_float = Some(value);
155        self
156    }
157
158    /// Sets `IfcWorkControl.FinishTime`.
159    #[must_use]
160    pub fn finish_time(mut self, value: impl Into<DateTimeValue<'a>>) -> Self {
161        self.finish_time = Some(value.into());
162        self
163    }
164
165    /// Sets `PredefinedType`.
166    #[must_use]
167    pub fn predefined_type(mut self, value: &'a str) -> Self {
168        self.predefined_type = Some(value);
169        self
170    }
171}
172
173impl<'a> EventDraft<'a> {
174    /// Starts a draft for an `IfcEvent` with its `GlobalId` and every optional
175    /// attribute unset.
176    #[must_use]
177    pub fn new(global_id: &'a str) -> Self {
178        Self {
179            global_id,
180            ..Self::default()
181        }
182    }
183
184    /// Sets `IfcRoot.Name`.
185    #[must_use]
186    pub fn name(mut self, value: &'a str) -> Self {
187        self.name = Some(value);
188        self
189    }
190
191    /// Sets `IfcObject.ObjectType`.
192    #[must_use]
193    pub fn object_type(mut self, value: &'a str) -> Self {
194        self.object_type = Some(value);
195        self
196    }
197
198    /// Sets `IfcProcess.Identification`.
199    #[must_use]
200    pub fn identification(mut self, value: &'a str) -> Self {
201        self.identification = Some(value);
202        self
203    }
204
205    /// Sets `IfcProcess.LongDescription`.
206    #[must_use]
207    pub fn long_description(mut self, value: &'a str) -> Self {
208        self.long_description = Some(value);
209        self
210    }
211
212    /// Sets `IfcEvent.PredefinedType`.
213    #[must_use]
214    pub fn predefined_type(mut self, value: &'a str) -> Self {
215        self.predefined_type = Some(value);
216        self
217    }
218
219    /// Sets `IfcEvent.EventTriggerType`.
220    #[must_use]
221    pub fn trigger_type(mut self, value: &'a str) -> Self {
222        self.trigger_type = Some(value);
223        self
224    }
225
226    /// Sets `IfcEvent.UserDefinedEventTriggerType`.
227    #[must_use]
228    pub fn user_defined_trigger_type(mut self, value: &'a str) -> Self {
229        self.user_defined_trigger_type = Some(value);
230        self
231    }
232
233    /// Sets `IfcEvent.EventOccurenceTime`, an `IfcEventTime` reference.
234    #[must_use]
235    pub fn occurence_time(mut self, value: EntityId) -> Self {
236        self.occurence_time = Some(value);
237        self
238    }
239}
240
241impl<'a> EventTimeDraft<'a> {
242    /// Starts a draft for an `IfcEventTime` with every attribute unset.
243    #[must_use]
244    pub fn new() -> Self {
245        Self::default()
246    }
247
248    /// Sets `IfcSchedulingTime.Name`.
249    #[must_use]
250    pub fn name(mut self, value: &'a str) -> Self {
251        self.name = Some(value);
252        self
253    }
254
255    /// Sets `IfcEventTime.ActualDate`.
256    #[must_use]
257    pub fn actual(mut self, value: &'a str) -> Self {
258        self.actual = Some(value);
259        self
260    }
261
262    /// Sets `IfcEventTime.EarlyDate`.
263    #[must_use]
264    pub fn early(mut self, value: &'a str) -> Self {
265        self.early = Some(value);
266        self
267    }
268
269    /// Sets `IfcEventTime.LateDate`.
270    #[must_use]
271    pub fn late(mut self, value: &'a str) -> Self {
272        self.late = Some(value);
273        self
274    }
275
276    /// Sets `IfcEventTime.ScheduleDate`.
277    #[must_use]
278    pub fn schedule(mut self, value: &'a str) -> Self {
279        self.schedule = Some(value);
280        self
281    }
282}
283
284impl<'a> RecurrenceDraft<'a> {
285    /// Starts a draft for an `IfcRecurrencePattern` with its required
286    /// `RecurrenceType` and every component unset.
287    #[must_use]
288    pub fn new(recurrence_type: &'a str) -> Self {
289        Self {
290            recurrence_type,
291            ..Self::default()
292        }
293    }
294
295    /// Sets `DayComponent`, days of the month in `1..=31`.
296    #[must_use]
297    pub fn days(mut self, value: Vec<i64>) -> Self {
298        self.days = value;
299        self
300    }
301
302    /// Sets `WeekdayComponent`, 1 = Monday through 7 = Sunday.
303    #[must_use]
304    pub fn weekdays(mut self, value: Vec<i64>) -> Self {
305        self.weekdays = value;
306        self
307    }
308
309    /// Sets `MonthComponent`, 1 = January through 12 = December.
310    #[must_use]
311    pub fn months(mut self, value: Vec<i64>) -> Self {
312        self.months = value;
313        self
314    }
315
316    /// Sets `Position`.
317    #[must_use]
318    pub fn position(mut self, value: i64) -> Self {
319        self.position = Some(value);
320        self
321    }
322
323    /// Sets `Interval`, a positive count.
324    #[must_use]
325    pub fn interval(mut self, value: i64) -> Self {
326        self.interval = Some(value);
327        self
328    }
329
330    /// Sets `Occurrences`, a positive count.
331    #[must_use]
332    pub fn occurrences(mut self, value: i64) -> Self {
333        self.occurrences = Some(value);
334        self
335    }
336
337    /// Sets `TimePeriods`, the `IfcTimePeriod` records the pattern's
338    /// occurrences span, in authored order (#233).
339    #[must_use]
340    pub fn time_periods(mut self, value: Vec<EntityId>) -> Self {
341        self.time_periods = value;
342        self
343    }
344}
345
346impl<'a> ProcedureDraft<'a> {
347    /// Starts a draft for an `IfcProcedure` with its `GlobalId` and every optional
348    /// attribute unset.
349    #[must_use]
350    pub fn new(global_id: &'a str) -> Self {
351        Self {
352            global_id,
353            ..Self::default()
354        }
355    }
356
357    /// Sets `Name`, required by `HasName`.
358    #[must_use]
359    pub fn name(mut self, value: &'a str) -> Self {
360        self.name = Some(value);
361        self
362    }
363
364    /// Sets `Description`.
365    #[must_use]
366    pub fn description(mut self, value: &'a str) -> Self {
367        self.description = Some(value);
368        self
369    }
370
371    /// Sets `ObjectType`.
372    #[must_use]
373    pub fn object_type(mut self, value: &'a str) -> Self {
374        self.object_type = Some(value);
375        self
376    }
377
378    /// Sets `Identification` (IFC2X3 `ProcedureID`).
379    #[must_use]
380    pub fn identification(mut self, value: &'a str) -> Self {
381        self.identification = Some(value);
382        self
383    }
384
385    /// Sets `LongDescription`.
386    #[must_use]
387    pub fn long_description(mut self, value: &'a str) -> Self {
388        self.long_description = Some(value);
389        self
390    }
391
392    /// Sets `PredefinedType` (IFC2X3 `ProcedureType`).
393    #[must_use]
394    pub fn predefined_type(mut self, value: &'a str) -> Self {
395        self.predefined_type = Some(value);
396        self
397    }
398
399    /// Sets IFC2X3 `UserDefinedProcedureType`.
400    #[must_use]
401    pub fn user_defined_procedure_type(mut self, value: &'a str) -> Self {
402        self.user_defined_procedure_type = Some(value);
403        self
404    }
405}
406
407impl<'a> TaskTimeDraft<'a> {
408    /// Starts a draft for an `IfcTaskTime` with every attribute unset.
409    #[must_use]
410    pub fn new() -> Self {
411        Self::default()
412    }
413
414    /// Sets `Name`.
415    #[must_use]
416    pub fn name(mut self, value: &'a str) -> Self {
417        self.name = Some(value);
418        self
419    }
420
421    /// Sets `DurationType`.
422    #[must_use]
423    pub fn duration_type(mut self, value: &'a str) -> Self {
424        self.duration_type = Some(value);
425        self
426    }
427
428    /// Sets `ScheduleDuration`, an ISO 8601 duration.
429    #[must_use]
430    pub fn schedule_duration(mut self, value: &'a str) -> Self {
431        self.schedule_duration = Some(value);
432        self
433    }
434
435    /// Sets `ScheduleStart`.
436    #[must_use]
437    pub fn schedule_start(mut self, value: &'a str) -> Self {
438        self.schedule_start = Some(value);
439        self
440    }
441
442    /// Sets `ScheduleFinish`.
443    #[must_use]
444    pub fn schedule_finish(mut self, value: &'a str) -> Self {
445        self.schedule_finish = Some(value);
446        self
447    }
448
449    /// Sets `ActualStart`.
450    #[must_use]
451    pub fn actual_start(mut self, value: &'a str) -> Self {
452        self.actual_start = Some(value);
453        self
454    }
455
456    /// Sets `ActualFinish`.
457    #[must_use]
458    pub fn actual_finish(mut self, value: &'a str) -> Self {
459        self.actual_finish = Some(value);
460        self
461    }
462
463    /// Sets `IsCritical`.
464    #[must_use]
465    pub fn is_critical(mut self, value: bool) -> Self {
466        self.is_critical = Some(value);
467        self
468    }
469
470    /// Sets `Completion`, a percentage in `0..=100`.
471    #[must_use]
472    pub fn completion(mut self, value: f64) -> Self {
473        self.completion = Some(value);
474        self
475    }
476}