1use ifc_model::{EntityId, Model, Transaction, Value};
21
22use crate::PropertyResult;
23
24use super::owned::{stage_ifc4, stage_owned, Rooted};
25use super::predefined::{invalid, measure, ratio, require_guid, Measure};
26
27#[derive(Debug, Clone, Copy, Default)]
29#[non_exhaustive]
30pub struct DoorLiningDraft<'a> {
31 pub name: Option<&'a str>,
33 pub description: Option<&'a str>,
35 pub lining_depth: Option<f64>,
37 pub lining_thickness: Option<f64>,
39 pub threshold_depth: Option<f64>,
41 pub threshold_thickness: Option<f64>,
43 pub transom_thickness: Option<f64>,
45 pub transom_offset: Option<f64>,
47 pub lining_offset: Option<f64>,
49 pub threshold_offset: Option<f64>,
51 pub casing_thickness: Option<f64>,
53 pub casing_depth: Option<f64>,
55 pub shape_aspect_style: Option<EntityId>,
57 pub lining_to_panel_offset_x: Option<f64>,
59 pub lining_to_panel_offset_y: Option<f64>,
61}
62
63impl<'a> DoorLiningDraft<'a> {
64 #[must_use]
66 pub fn new() -> Self {
67 Self::default()
68 }
69
70 #[must_use]
74 pub fn name(mut self, value: &'a str) -> Self {
75 self.name = Some(value);
76 self
77 }
78
79 #[must_use]
83 pub fn description(mut self, value: &'a str) -> Self {
84 self.description = Some(value);
85 self
86 }
87
88 #[must_use]
92 pub fn lining_depth(mut self, value: f64) -> Self {
93 self.lining_depth = Some(value);
94 self
95 }
96
97 #[must_use]
101 pub fn lining_thickness(mut self, value: f64) -> Self {
102 self.lining_thickness = Some(value);
103 self
104 }
105
106 #[must_use]
110 pub fn threshold_depth(mut self, value: f64) -> Self {
111 self.threshold_depth = Some(value);
112 self
113 }
114
115 #[must_use]
119 pub fn threshold_thickness(mut self, value: f64) -> Self {
120 self.threshold_thickness = Some(value);
121 self
122 }
123
124 #[must_use]
128 pub fn transom_thickness(mut self, value: f64) -> Self {
129 self.transom_thickness = Some(value);
130 self
131 }
132
133 #[must_use]
137 pub fn transom_offset(mut self, value: f64) -> Self {
138 self.transom_offset = Some(value);
139 self
140 }
141
142 #[must_use]
146 pub fn lining_offset(mut self, value: f64) -> Self {
147 self.lining_offset = Some(value);
148 self
149 }
150
151 #[must_use]
155 pub fn threshold_offset(mut self, value: f64) -> Self {
156 self.threshold_offset = Some(value);
157 self
158 }
159
160 #[must_use]
164 pub fn casing_thickness(mut self, value: f64) -> Self {
165 self.casing_thickness = Some(value);
166 self
167 }
168
169 #[must_use]
173 pub fn casing_depth(mut self, value: f64) -> Self {
174 self.casing_depth = Some(value);
175 self
176 }
177
178 #[must_use]
182 pub fn shape_aspect_style(mut self, value: EntityId) -> Self {
183 self.shape_aspect_style = Some(value);
184 self
185 }
186
187 #[must_use]
191 pub fn lining_to_panel_offset_x(mut self, value: f64) -> Self {
192 self.lining_to_panel_offset_x = Some(value);
193 self
194 }
195
196 #[must_use]
200 pub fn lining_to_panel_offset_y(mut self, value: f64) -> Self {
201 self.lining_to_panel_offset_y = Some(value);
202 self
203 }
204}
205
206pub fn add_door_lining_properties(
223 tx: &mut Transaction,
224 global_id: &str,
225 draft: DoorLiningDraft<'_>,
226) -> PropertyResult<EntityId> {
227 stage_ifc4(tx, door_lining(global_id, draft)?)
228}
229
230pub fn add_door_lining_properties_with_owner_history(
245 tx: &mut Transaction,
246 model: &Model,
247 global_id: &str,
248 draft: DoorLiningDraft<'_>,
249 owner_history: EntityId,
250) -> PropertyResult<EntityId> {
251 stage_owned(tx, model, door_lining(global_id, draft)?, owner_history)
252}
253
254fn door_lining<'a>(global_id: &'a str, draft: DoorLiningDraft<'a>) -> PropertyResult<Rooted<'a>> {
255 const ENTITY: &str = "IFCDOORLININGPROPERTIES";
256 if draft.lining_depth.is_some() && draft.lining_thickness.is_none() {
257 return Err(invalid(
258 ENTITY,
259 "LiningThickness",
260 "WR31: a lining depth needs its thickness",
261 ));
262 }
263 if draft.threshold_depth.is_some() && draft.threshold_thickness.is_none() {
264 return Err(invalid(
265 ENTITY,
266 "ThresholdThickness",
267 "WR32: a threshold depth needs its thickness",
268 ));
269 }
270 if draft.transom_offset.is_some() != draft.transom_thickness.is_some() {
271 return Err(invalid(
272 ENTITY,
273 "TransomOffset",
274 "WR33: transom offset and thickness are all or nothing",
275 ));
276 }
277 if draft.casing_depth.is_some() != draft.casing_thickness.is_some() {
278 return Err(invalid(
279 ENTITY,
280 "CasingDepth",
281 "WR34: casing depth and thickness are all or nothing",
282 ));
283 }
284 require_guid(ENTITY, global_id)?;
285 let m = |attribute, value, kind| measure(ENTITY, attribute, value, kind);
286 let values = vec![
287 (
288 "LiningDepth",
289 m("LiningDepth", draft.lining_depth, Measure::Positive)?,
290 ),
291 (
292 "LiningThickness",
293 m(
294 "LiningThickness",
295 draft.lining_thickness,
296 Measure::NonNegative,
297 )?,
298 ),
299 (
300 "ThresholdDepth",
301 m("ThresholdDepth", draft.threshold_depth, Measure::Positive)?,
302 ),
303 (
304 "ThresholdThickness",
305 m(
306 "ThresholdThickness",
307 draft.threshold_thickness,
308 Measure::NonNegative,
309 )?,
310 ),
311 (
312 "TransomThickness",
313 m(
314 "TransomThickness",
315 draft.transom_thickness,
316 Measure::NonNegative,
317 )?,
318 ),
319 (
320 "TransomOffset",
321 m("TransomOffset", draft.transom_offset, Measure::Length)?,
322 ),
323 (
324 "LiningOffset",
325 m("LiningOffset", draft.lining_offset, Measure::Length)?,
326 ),
327 (
328 "ThresholdOffset",
329 m("ThresholdOffset", draft.threshold_offset, Measure::Length)?,
330 ),
331 (
332 "CasingThickness",
333 m("CasingThickness", draft.casing_thickness, Measure::Positive)?,
334 ),
335 (
336 "CasingDepth",
337 m("CasingDepth", draft.casing_depth, Measure::Positive)?,
338 ),
339 (
340 "ShapeAspectStyle",
341 draft.shape_aspect_style.map_or(Value::Null, Value::Ref),
342 ),
343 (
344 "LiningToPanelOffsetX",
345 m(
346 "LiningToPanelOffsetX",
347 draft.lining_to_panel_offset_x,
348 Measure::Length,
349 )?,
350 ),
351 (
352 "LiningToPanelOffsetY",
353 m(
354 "LiningToPanelOffsetY",
355 draft.lining_to_panel_offset_y,
356 Measure::Length,
357 )?,
358 ),
359 ];
360 Ok(Rooted {
361 entity: ENTITY,
362 global_id,
363 name: draft.name,
364 description: draft.description,
365 values,
366 })
367}
368
369#[derive(Debug, Clone, Copy, Default)]
371#[non_exhaustive]
372pub struct WindowLiningDraft<'a> {
373 pub name: Option<&'a str>,
375 pub description: Option<&'a str>,
377 pub lining_depth: Option<f64>,
379 pub lining_thickness: Option<f64>,
381 pub transom_thickness: Option<f64>,
383 pub mullion_thickness: Option<f64>,
385 pub first_transom_offset: Option<f64>,
387 pub second_transom_offset: Option<f64>,
389 pub first_mullion_offset: Option<f64>,
391 pub second_mullion_offset: Option<f64>,
393 pub shape_aspect_style: Option<EntityId>,
395 pub lining_offset: Option<f64>,
397 pub lining_to_panel_offset_x: Option<f64>,
399 pub lining_to_panel_offset_y: Option<f64>,
401}
402
403impl<'a> WindowLiningDraft<'a> {
404 #[must_use]
406 pub fn new() -> Self {
407 Self::default()
408 }
409
410 #[must_use]
414 pub fn name(mut self, value: &'a str) -> Self {
415 self.name = Some(value);
416 self
417 }
418
419 #[must_use]
423 pub fn description(mut self, value: &'a str) -> Self {
424 self.description = Some(value);
425 self
426 }
427
428 #[must_use]
432 pub fn lining_depth(mut self, value: f64) -> Self {
433 self.lining_depth = Some(value);
434 self
435 }
436
437 #[must_use]
441 pub fn lining_thickness(mut self, value: f64) -> Self {
442 self.lining_thickness = Some(value);
443 self
444 }
445
446 #[must_use]
450 pub fn transom_thickness(mut self, value: f64) -> Self {
451 self.transom_thickness = Some(value);
452 self
453 }
454
455 #[must_use]
459 pub fn mullion_thickness(mut self, value: f64) -> Self {
460 self.mullion_thickness = Some(value);
461 self
462 }
463
464 #[must_use]
468 pub fn first_transom_offset(mut self, value: f64) -> Self {
469 self.first_transom_offset = Some(value);
470 self
471 }
472
473 #[must_use]
477 pub fn second_transom_offset(mut self, value: f64) -> Self {
478 self.second_transom_offset = Some(value);
479 self
480 }
481
482 #[must_use]
486 pub fn first_mullion_offset(mut self, value: f64) -> Self {
487 self.first_mullion_offset = Some(value);
488 self
489 }
490
491 #[must_use]
495 pub fn second_mullion_offset(mut self, value: f64) -> Self {
496 self.second_mullion_offset = Some(value);
497 self
498 }
499
500 #[must_use]
504 pub fn shape_aspect_style(mut self, value: EntityId) -> Self {
505 self.shape_aspect_style = Some(value);
506 self
507 }
508
509 #[must_use]
513 pub fn lining_offset(mut self, value: f64) -> Self {
514 self.lining_offset = Some(value);
515 self
516 }
517
518 #[must_use]
522 pub fn lining_to_panel_offset_x(mut self, value: f64) -> Self {
523 self.lining_to_panel_offset_x = Some(value);
524 self
525 }
526
527 #[must_use]
531 pub fn lining_to_panel_offset_y(mut self, value: f64) -> Self {
532 self.lining_to_panel_offset_y = Some(value);
533 self
534 }
535}
536
537pub fn add_window_lining_properties(
555 tx: &mut Transaction,
556 global_id: &str,
557 draft: WindowLiningDraft<'_>,
558) -> PropertyResult<EntityId> {
559 stage_ifc4(tx, window_lining(global_id, draft)?)
560}
561
562pub fn add_window_lining_properties_with_owner_history(
573 tx: &mut Transaction,
574 model: &Model,
575 global_id: &str,
576 draft: WindowLiningDraft<'_>,
577 owner_history: EntityId,
578) -> PropertyResult<EntityId> {
579 stage_owned(tx, model, window_lining(global_id, draft)?, owner_history)
580}
581
582fn window_lining<'a>(
583 global_id: &'a str,
584 draft: WindowLiningDraft<'a>,
585) -> PropertyResult<Rooted<'a>> {
586 const ENTITY: &str = "IFCWINDOWLININGPROPERTIES";
587 if draft.lining_depth.is_some() && draft.lining_thickness.is_none() {
588 return Err(invalid(
589 ENTITY,
590 "LiningThickness",
591 "WR31: a lining depth needs its thickness",
592 ));
593 }
594 if draft.second_transom_offset.is_some() && draft.first_transom_offset.is_none() {
595 return Err(invalid(
596 ENTITY,
597 "SecondTransomOffset",
598 "WR32: a second transom offset needs the first",
599 ));
600 }
601 if draft.second_mullion_offset.is_some() && draft.first_mullion_offset.is_none() {
602 return Err(invalid(
603 ENTITY,
604 "SecondMullionOffset",
605 "WR33: a second mullion offset needs the first",
606 ));
607 }
608 require_guid(ENTITY, global_id)?;
609 let m = |attribute, value, kind| measure(ENTITY, attribute, value, kind);
610 let r = |attribute, value| ratio(ENTITY, attribute, value);
611 let values = vec![
612 (
613 "LiningDepth",
614 m("LiningDepth", draft.lining_depth, Measure::Positive)?,
615 ),
616 (
617 "LiningThickness",
618 m(
619 "LiningThickness",
620 draft.lining_thickness,
621 Measure::NonNegative,
622 )?,
623 ),
624 (
625 "TransomThickness",
626 m(
627 "TransomThickness",
628 draft.transom_thickness,
629 Measure::NonNegative,
630 )?,
631 ),
632 (
633 "MullionThickness",
634 m(
635 "MullionThickness",
636 draft.mullion_thickness,
637 Measure::NonNegative,
638 )?,
639 ),
640 (
641 "FirstTransomOffset",
642 r("FirstTransomOffset", draft.first_transom_offset)?,
643 ),
644 (
645 "SecondTransomOffset",
646 r("SecondTransomOffset", draft.second_transom_offset)?,
647 ),
648 (
649 "FirstMullionOffset",
650 r("FirstMullionOffset", draft.first_mullion_offset)?,
651 ),
652 (
653 "SecondMullionOffset",
654 r("SecondMullionOffset", draft.second_mullion_offset)?,
655 ),
656 (
657 "ShapeAspectStyle",
658 draft.shape_aspect_style.map_or(Value::Null, Value::Ref),
659 ),
660 (
661 "LiningOffset",
662 m("LiningOffset", draft.lining_offset, Measure::Length)?,
663 ),
664 (
665 "LiningToPanelOffsetX",
666 m(
667 "LiningToPanelOffsetX",
668 draft.lining_to_panel_offset_x,
669 Measure::Length,
670 )?,
671 ),
672 (
673 "LiningToPanelOffsetY",
674 m(
675 "LiningToPanelOffsetY",
676 draft.lining_to_panel_offset_y,
677 Measure::Length,
678 )?,
679 ),
680 ];
681 Ok(Rooted {
682 entity: ENTITY,
683 global_id,
684 name: draft.name,
685 description: draft.description,
686 values,
687 })
688}