Skip to main content

ifc_material/constituent/
set.rs

1//! Source-order-preserving projection of the `IfcMaterialConstituentSet` SET.
2
3use ifc_model::EntityId;
4
5use crate::view::{borrowed_entity, optional_refs, optional_text, MaterialView};
6use crate::MaterialResult;
7
8borrowed_entity!(MaterialConstituentSet, "IFCMATERIALCONSTITUENTSET");
9
10impl<'m> MaterialConstituentSet<'m> {
11    /// `IfcMaterialConstituentSet.Name`, if given.
12    pub fn name(self) -> MaterialResult<Option<&'m str>> {
13        optional_text(
14            "IFCMATERIALCONSTITUENTSET",
15            self.id(),
16            self.entity(),
17            0,
18            "Name",
19        )
20    }
21
22    /// `IfcMaterialConstituentSet.Description`, if given.
23    pub fn description(self) -> MaterialResult<Option<&'m str>> {
24        optional_text(
25            "IFCMATERIALCONSTITUENTSET",
26            self.id(),
27            self.entity(),
28            1,
29            "Description",
30        )
31    }
32
33    /// `IfcMaterialConstituentSet.MaterialConstituents`, if the set has any
34    /// members. `None` when the optional attribute slot is absent, distinct
35    /// from an authored-but-empty list (which `optional_refs` rejects).
36    pub fn constituent_ids(self) -> MaterialResult<Option<Vec<EntityId>>> {
37        optional_refs(
38            "IFCMATERIALCONSTITUENTSET",
39            self.id(),
40            self.entity(),
41            2,
42            "MaterialConstituents",
43            1,
44        )
45    }
46}
47
48impl<'m> MaterialView<'m> {
49    /// Iterates every `IfcMaterialConstituentSet` instance in the model.
50    pub fn constituent_sets(self) -> impl Iterator<Item = MaterialConstituentSet<'m>> + 'm {
51        self.model()
52            .of_type("IFCMATERIALCONSTITUENTSET")
53            .map(|(id, entity)| MaterialConstituentSet::from_known(id, entity))
54    }
55}