Skip to main content

ifc_classification/classification/
reference.rs

1//! Borrowed `IfcClassificationReference` projection.
2use crate::view::{borrowed_entity, optional_ref, optional_text, ClassificationView};
3use crate::{ClassificationError, ClassificationResult};
4borrowed_entity!(ClassificationReference, "IFCCLASSIFICATIONREFERENCE");
5impl<'m> ClassificationReference<'m> {
6    /// The `Location` (e.g. a URI) of the referenced classification item, when authored.
7    pub fn location(self) -> ClassificationResult<Option<&'m str>> {
8        optional_text(
9            "IFCCLASSIFICATIONREFERENCE",
10            self.id(),
11            self.entity(),
12            self.text_slot("Location")?,
13            "Location",
14        )
15    }
16    /// The `Identification` code of the referenced classification item, when authored.
17    pub fn identification(self) -> ClassificationResult<Option<&'m str>> {
18        optional_text(
19            "IFCCLASSIFICATIONREFERENCE",
20            self.id(),
21            self.entity(),
22            self.text_slot("Identification")?,
23            "Identification",
24        )
25    }
26    /// The `Name` of the referenced classification item, when authored.
27    pub fn name(self) -> ClassificationResult<Option<&'m str>> {
28        optional_text(
29            "IFCCLASSIFICATIONREFERENCE",
30            self.id(),
31            self.entity(),
32            self.text_slot("Name")?,
33            "Name",
34        )
35    }
36    /// Id of the `ReferencedSource` — the parent `IfcClassification` or `IfcClassificationReference` in the hierarchy — when authored.
37    pub fn referenced_source_id(self) -> ClassificationResult<Option<ifc_model::EntityId>> {
38        optional_ref(
39            "IFCCLASSIFICATIONREFERENCE",
40            self.id(),
41            self.entity(),
42            self.slot("ReferencedSource")?,
43            "ReferencedSource",
44        )
45    }
46    /// The `Description` of the referenced classification item, when authored.
47    pub fn description(self) -> ClassificationResult<Option<&'m str>> {
48        optional_text(
49            "IFCCLASSIFICATIONREFERENCE",
50            self.id(),
51            self.entity(),
52            self.text_slot("Description")?,
53            "Description",
54        )
55    }
56    /// The `Sort` order of the referenced classification item, when authored.
57    pub fn sort(self) -> ClassificationResult<Option<&'m str>> {
58        optional_text(
59            "IFCCLASSIFICATIONREFERENCE",
60            self.id(),
61            self.entity(),
62            self.text_slot("Sort")?,
63            "Sort",
64        )
65    }
66    /// Checks the `IfcExternalReference.WR1` rule: at least one of `Location`, `Identification`, or `Name` must be stated.
67    pub fn validate(self) -> ClassificationResult<()> {
68        if self.location()?.is_some() || self.identification()?.is_some() || self.name()?.is_some()
69        {
70            Ok(())
71        } else {
72            Err(ClassificationError::InvalidValue {
73                entity: "IFCCLASSIFICATIONREFERENCE",
74                id: self.id(),
75                attribute: "WR1",
76                value: "Location, Identification, and Name are all unstated".into(),
77            })
78        }
79    }
80}
81impl<'m> ClassificationView<'m> {
82    /// All `IfcClassificationReference` instances in the model.
83    pub fn references(self) -> impl Iterator<Item = ClassificationReference<'m>> + 'm {
84        self.model()
85            .of_type("IFCCLASSIFICATIONREFERENCE")
86            .map(move |(id, e)| ClassificationReference::from_known(id, e, self.release()))
87    }
88}