Skip to main content

ifc_style/assignment/
layer.rs

1//! IFC2x3 `IfcPresentationStyleAssignment` wrapper projection.
2
3use ifc_model::EntityId;
4
5use crate::error::StyleResult;
6use crate::view::Record;
7use crate::{assignment::presentation_style_members, PresentationStyleMember};
8
9/// Borrowed projection of the IFC2x3 `IfcPresentationStyleAssignment` wrapper
10/// entity, which groups a list of presentation styles under one id.
11#[derive(Debug, Clone, Copy)]
12pub struct PresentationStyleAssignment<'m, 's> {
13    record: Record<'m, 's>,
14}
15
16impl<'m, 's> PresentationStyleAssignment<'m, 's> {
17    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
18        Self { record }
19    }
20
21    /// The entity id of this `IfcPresentationStyleAssignment`.
22    pub fn id(&self) -> EntityId {
23        self.record.id
24    }
25
26    /// The `Styles` select, with any `IfcNullStyle.NULL` members dropped.
27    pub fn styles(&self) -> StyleResult<Vec<EntityId>> {
28        Ok(self
29            .members()?
30            .into_iter()
31            .filter_map(|member| match member {
32                PresentationStyleMember::Style(id) => Some(id),
33                PresentationStyleMember::Null => None,
34            })
35            .collect())
36    }
37
38    /// The raw `Styles` select, one member per list entry, preserving
39    /// `IfcNullStyle.NULL` placeholders.
40    pub fn members(&self) -> StyleResult<Vec<PresentationStyleMember>> {
41        presentation_style_members(self.record, "Styles", 1)
42    }
43}