Skip to main content

ifc_classification/library/
reference.rs

1//! Borrowed `IfcLibraryReference` projection.
2use crate::view::{borrowed_entity, optional_ref, optional_text, ClassificationView};
3use crate::{ClassificationError, ClassificationResult};
4borrowed_entity!(LibraryReference, "IFCLIBRARYREFERENCE");
5impl<'m> LibraryReference<'m> {
6    /// The `Location` (e.g. a URI) of the referenced library item, when authored.
7    pub fn location(self) -> ClassificationResult<Option<&'m str>> {
8        optional_text(
9            "IFCLIBRARYREFERENCE",
10            self.id(),
11            self.entity(),
12            self.text_slot("Location")?,
13            "Location",
14        )
15    }
16    /// The `Identification` code of the referenced library item, when authored.
17    pub fn identification(self) -> ClassificationResult<Option<&'m str>> {
18        optional_text(
19            "IFCLIBRARYREFERENCE",
20            self.id(),
21            self.entity(),
22            self.text_slot("Identification")?,
23            "Identification",
24        )
25    }
26    /// The `Name` of the referenced library item, when authored.
27    pub fn name(self) -> ClassificationResult<Option<&'m str>> {
28        optional_text(
29            "IFCLIBRARYREFERENCE",
30            self.id(),
31            self.entity(),
32            self.text_slot("Name")?,
33            "Name",
34        )
35    }
36    /// The `Description` of the referenced library item, when authored.
37    pub fn description(self) -> ClassificationResult<Option<&'m str>> {
38        optional_text(
39            "IFCLIBRARYREFERENCE",
40            self.id(),
41            self.entity(),
42            self.text_slot("Description")?,
43            "Description",
44        )
45    }
46    /// The `Language` of the referenced library item, when authored.
47    pub fn language(self) -> ClassificationResult<Option<&'m str>> {
48        optional_text(
49            "IFCLIBRARYREFERENCE",
50            self.id(),
51            self.entity(),
52            self.text_slot("Language")?,
53            "Language",
54        )
55    }
56    /// Id of the `ReferencedLibrary` (an `IfcLibraryInformation`), when authored.
57    pub fn referenced_library_id(self) -> ClassificationResult<Option<ifc_model::EntityId>> {
58        optional_ref(
59            "IFCLIBRARYREFERENCE",
60            self.id(),
61            self.entity(),
62            self.slot("ReferencedLibrary")?,
63            "ReferencedLibrary",
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: "IFCLIBRARYREFERENCE",
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 `IfcLibraryReference` instances in the model.
83    pub fn library_references(self) -> impl Iterator<Item = LibraryReference<'m>> + 'm {
84        self.model()
85            .of_type("IFCLIBRARYREFERENCE")
86            .map(move |(id, e)| LibraryReference::from_known(id, e, self.release()))
87    }
88}