ifc_style/assignment/
styled_item.rs1use ifc_model::EntityId;
4use ifc_schema::SchemaVersion;
5
6use crate::error::{StyleError, StyleResult};
7use crate::view::Record;
8
9#[derive(Debug, Clone, Copy)]
12pub struct StyledItem<'m, 's> {
13 record: Record<'m, 's>,
14}
15
16impl<'m, 's> StyledItem<'m, 's> {
17 pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
18 Self { record }
19 }
20
21 pub fn id(&self) -> EntityId {
23 self.record.id
24 }
25
26 pub fn item(&self) -> StyleResult<Option<EntityId>> {
29 self.record.optional_ref("Item", "IfcRepresentationItem")
30 }
31
32 pub fn styles(&self) -> StyleResult<Vec<EntityId>> {
43 let (members, maximum): (&[&str], Option<usize>) = match self.record.schema.version() {
44 Some(SchemaVersion::Ifc2x3) => (&["IfcPresentationStyleAssignment"], Some(1)),
45 Some(SchemaVersion::Ifc4 | SchemaVersion::Ifc4x1 | SchemaVersion::Ifc4x2) => (
46 &["IfcPresentationStyle", "IfcPresentationStyleAssignment"],
47 None,
48 ),
49 Some(SchemaVersion::Ifc4x3) | None => (&["IfcPresentationStyle"], None),
50 Some(_) => {
51 return Err(StyleError::UnsupportedSchema {
52 schema: self.record.schema.name().to_owned(),
53 })
54 }
55 };
56 self.record
57 .required_refs_select("Styles", "IfcStyleAssignmentSelect", members, 1, maximum)
58 }
59
60 pub fn name(&self) -> StyleResult<Option<&'m str>> {
62 self.record.optional_text("Name")
63 }
64}