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            0,
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            1,
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("IFCLIBRARYREFERENCE", self.id(), self.entity(), 2, "Name")
29    }
30    /// The `Description` of the referenced library item, when authored.
31    pub fn description(self) -> ClassificationResult<Option<&'m str>> {
32        optional_text(
33            "IFCLIBRARYREFERENCE",
34            self.id(),
35            self.entity(),
36            3,
37            "Description",
38        )
39    }
40    /// The `Language` of the referenced library item, when authored.
41    pub fn language(self) -> ClassificationResult<Option<&'m str>> {
42        optional_text(
43            "IFCLIBRARYREFERENCE",
44            self.id(),
45            self.entity(),
46            4,
47            "Language",
48        )
49    }
50    /// Id of the `ReferencedLibrary` (an `IfcLibraryInformation`), when authored.
51    pub fn referenced_library_id(self) -> ClassificationResult<Option<ifc_model::EntityId>> {
52        optional_ref(
53            "IFCLIBRARYREFERENCE",
54            self.id(),
55            self.entity(),
56            5,
57            "ReferencedLibrary",
58        )
59    }
60    /// Checks the `IfcExternalReference.WR1` rule: at least one of `Location`, `Identification`, or `Name` must be stated.
61    pub fn validate(self) -> ClassificationResult<()> {
62        if self.location()?.is_some() || self.identification()?.is_some() || self.name()?.is_some()
63        {
64            Ok(())
65        } else {
66            Err(ClassificationError::InvalidValue {
67                entity: "IFCLIBRARYREFERENCE",
68                id: self.id(),
69                attribute: "WR1",
70                value: "Location, Identification, and Name are all unstated".into(),
71            })
72        }
73    }
74}
75impl<'m> ClassificationView<'m> {
76    /// All `IfcLibraryReference` instances in the model.
77    pub fn library_references(self) -> impl Iterator<Item = LibraryReference<'m>> + 'm {
78        self.model()
79            .of_type("IFCLIBRARYREFERENCE")
80            .map(|(id, e)| LibraryReference::from_known(id, e))
81    }
82}