ifc_material/material/
properties.rs1use 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 pub fn name(self) -> MaterialResult<Option<&'m str>> {
13 optional_text("IFCMATERIALPROPERTIES", self.id(), self.entity(), 0, "Name")
14 }
15
16 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 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 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 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 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}