Skip to main content

ifc_material/material/
properties.rs

1//! `IfcMaterialProperties` and its direct material/property links.
2
3use ifc_model::EntityId;
4
5use crate::view::{borrowed_entity, optional_text, required_ref, required_refs, MaterialView};
6use crate::MaterialResult;
7
8borrowed_entity!(MaterialProperties, "IFCMATERIALPROPERTIES");
9
10impl<'m> MaterialProperties<'m> {
11    /// `IfcMaterialProperties.Name`, if given.
12    pub fn name(self) -> MaterialResult<Option<&'m str>> {
13        optional_text("IFCMATERIALPROPERTIES", self.id(), self.entity(), 0, "Name")
14    }
15
16    /// `IfcMaterialProperties.Description`, if given.
17    pub fn description(self) -> MaterialResult<Option<&'m str>> {
18        optional_text(
19            "IFCMATERIALPROPERTIES",
20            self.id(),
21            self.entity(),
22            1,
23            "Description",
24        )
25    }
26
27    /// `IfcMaterialProperties.Properties`, the ids of the property set's
28    /// `IfcProperty` members. Required and must be non-empty.
29    pub fn property_ids(self) -> MaterialResult<Vec<EntityId>> {
30        required_refs(
31            "IFCMATERIALPROPERTIES",
32            self.id(),
33            self.entity(),
34            2,
35            "Properties",
36            1,
37        )
38    }
39
40    /// `IfcMaterialProperties.Material`, the id of the `IfcMaterialDefinition`
41    /// these properties describe. Required.
42    pub fn material_id(self) -> MaterialResult<EntityId> {
43        required_ref(
44            "IFCMATERIALPROPERTIES",
45            self.id(),
46            self.entity(),
47            3,
48            "Material",
49        )
50    }
51}
52
53impl<'m> MaterialView<'m> {
54    /// Iterates every `IfcMaterialProperties` instance in the model.
55    pub fn material_properties(self) -> impl Iterator<Item = MaterialProperties<'m>> + 'm {
56        self.model()
57            .of_type("IFCMATERIALPROPERTIES")
58            .map(|(id, entity)| MaterialProperties::from_known(id, entity))
59    }
60
61    /// Iterates every `IfcMaterialProperties` whose `Material` attribute
62    /// resolves to `material`, surfacing malformed records as errors rather
63    /// than skipping them.
64    pub fn properties_for(
65        self,
66        material: EntityId,
67    ) -> impl Iterator<Item = MaterialResult<MaterialProperties<'m>>> + 'm {
68        self.material_properties()
69            .filter_map(move |properties| match properties.material_id() {
70                Ok(id) if id == material => Some(Ok(properties)),
71                Ok(_) => None,
72                Err(error) => Some(Err(error)),
73            })
74    }
75}