Skip to main content

ifc_material/material/
relationships.rs

1//! Material lists, classifications, and resource-level relationships.
2
3use ifc_model::EntityId;
4
5use crate::view::{borrowed_entity, optional_text, required_ref, required_refs, MaterialView};
6use crate::MaterialResult;
7
8borrowed_entity!(
9    MaterialClassificationRelationship,
10    "IFCMATERIALCLASSIFICATIONRELATIONSHIP"
11);
12borrowed_entity!(MaterialList, "IFCMATERIALLIST");
13borrowed_entity!(MaterialRelationship, "IFCMATERIALRELATIONSHIP");
14
15impl MaterialClassificationRelationship<'_> {
16    /// `IfcMaterialClassificationRelationship.MaterialClassifications`.
17    /// Required and must be non-empty.
18    pub fn classification_ids(self) -> MaterialResult<Vec<EntityId>> {
19        required_refs(
20            "IFCMATERIALCLASSIFICATIONRELATIONSHIP",
21            self.id(),
22            self.entity(),
23            0,
24            "MaterialClassifications",
25            1,
26        )
27    }
28
29    /// `IfcMaterialClassificationRelationship.ClassifiedMaterial`. Required.
30    pub fn material_id(self) -> MaterialResult<EntityId> {
31        required_ref(
32            "IFCMATERIALCLASSIFICATIONRELATIONSHIP",
33            self.id(),
34            self.entity(),
35            1,
36            "ClassifiedMaterial",
37        )
38    }
39}
40
41impl MaterialList<'_> {
42    /// `IfcMaterialList.Materials`, the ids of the constituent
43    /// `IfcMaterial` entities. Required and must be non-empty.
44    pub fn material_ids(self) -> MaterialResult<Vec<EntityId>> {
45        required_refs(
46            "IFCMATERIALLIST",
47            self.id(),
48            self.entity(),
49            0,
50            "Materials",
51            1,
52        )
53    }
54}
55
56impl<'m> MaterialRelationship<'m> {
57    /// `IfcMaterialRelationship.Name`, if given.
58    pub fn name(self) -> MaterialResult<Option<&'m str>> {
59        optional_text(
60            "IFCMATERIALRELATIONSHIP",
61            self.id(),
62            self.entity(),
63            0,
64            "Name",
65        )
66    }
67
68    /// `IfcMaterialRelationship.Description`, if given.
69    pub fn description(self) -> MaterialResult<Option<&'m str>> {
70        optional_text(
71            "IFCMATERIALRELATIONSHIP",
72            self.id(),
73            self.entity(),
74            1,
75            "Description",
76        )
77    }
78
79    /// `IfcMaterialRelationship.RelatingMaterial`. Required.
80    pub fn relating_material_id(self) -> MaterialResult<EntityId> {
81        required_ref(
82            "IFCMATERIALRELATIONSHIP",
83            self.id(),
84            self.entity(),
85            2,
86            "RelatingMaterial",
87        )
88    }
89
90    /// `IfcMaterialRelationship.RelatedMaterials`. Required and must be
91    /// non-empty.
92    pub fn related_material_ids(self) -> MaterialResult<Vec<EntityId>> {
93        required_refs(
94            "IFCMATERIALRELATIONSHIP",
95            self.id(),
96            self.entity(),
97            3,
98            "RelatedMaterials",
99            1,
100        )
101    }
102
103    /// `IfcMaterialRelationship.Expression`, if given.
104    pub fn expression(self) -> MaterialResult<Option<&'m str>> {
105        optional_text(
106            "IFCMATERIALRELATIONSHIP",
107            self.id(),
108            self.entity(),
109            4,
110            "Expression",
111        )
112    }
113}
114
115impl<'m> MaterialView<'m> {
116    /// Iterates every `IfcMaterialClassificationRelationship` in the model.
117    pub fn classification_relationships(
118        self,
119    ) -> impl Iterator<Item = MaterialClassificationRelationship<'m>> + 'm {
120        self.model()
121            .of_type("IFCMATERIALCLASSIFICATIONRELATIONSHIP")
122            .map(|(id, entity)| MaterialClassificationRelationship::from_known(id, entity))
123    }
124
125    /// Iterates every `IfcMaterialList` instance in the model.
126    pub fn material_lists(self) -> impl Iterator<Item = MaterialList<'m>> + 'm {
127        self.model()
128            .of_type("IFCMATERIALLIST")
129            .map(|(id, entity)| MaterialList::from_known(id, entity))
130    }
131
132    /// Iterates every `IfcMaterialRelationship` instance in the model.
133    pub fn material_relationships(self) -> impl Iterator<Item = MaterialRelationship<'m>> + 'm {
134        self.model()
135            .of_type("IFCMATERIALRELATIONSHIP")
136            .map(|(id, entity)| MaterialRelationship::from_known(id, entity))
137    }
138}