ifc_classification/assignment/
library.rs1use crate::assignment::{validate_assignment, AssociationSchema};
3use crate::view::{
4 borrowed_entity, optional_text, required_ref, required_refs, required_text, ClassificationView,
5};
6use crate::ClassificationResult;
7use ifc_model::EntityId;
8borrowed_entity!(LibraryAssignment, "IFCRELASSOCIATESLIBRARY");
9impl<'m> LibraryAssignment<'m> {
10 pub fn global_id(self) -> ClassificationResult<&'m str> {
12 required_text(
13 "IFCRELASSOCIATESLIBRARY",
14 self.id(),
15 self.entity(),
16 self.text_slot("GlobalId")?,
17 "GlobalId",
18 )
19 }
20 pub fn name(self) -> ClassificationResult<Option<&'m str>> {
22 optional_text(
23 "IFCRELASSOCIATESLIBRARY",
24 self.id(),
25 self.entity(),
26 self.text_slot("Name")?,
27 "Name",
28 )
29 }
30 pub fn description(self) -> ClassificationResult<Option<&'m str>> {
32 optional_text(
33 "IFCRELASSOCIATESLIBRARY",
34 self.id(),
35 self.entity(),
36 self.text_slot("Description")?,
37 "Description",
38 )
39 }
40 pub fn related_object_ids(self) -> ClassificationResult<Vec<EntityId>> {
42 required_refs(
43 "IFCRELASSOCIATESLIBRARY",
44 self.id(),
45 self.entity(),
46 self.slot("RelatedObjects")?,
47 "RelatedObjects",
48 )
49 }
50 pub fn relating_library_id(self) -> ClassificationResult<EntityId> {
52 required_ref(
53 "IFCRELASSOCIATESLIBRARY",
54 self.id(),
55 self.entity(),
56 self.slot("RelatingLibrary")?,
57 "RelatingLibrary",
58 )
59 }
60}
61impl<'m> ClassificationView<'m> {
62 pub fn library_assignments(self) -> impl Iterator<Item = LibraryAssignment<'m>> + 'm {
64 self.model()
65 .of_type("IFCRELASSOCIATESLIBRARY")
66 .map(move |(id, e)| LibraryAssignment::from_known(id, e, self.release()))
67 }
68 pub fn library_assignments_for(
70 self,
71 object: EntityId,
72 ) -> ClassificationResult<Vec<LibraryAssignment<'m>>> {
73 if self.model().get(object).is_none() {
74 return Err(crate::ClassificationError::UnknownEntity { id: object });
75 }
76 let mut out = Vec::new();
77 for assignment in self.library_assignments() {
78 let related = assignment.related_object_ids()?;
79 if related.contains(&object) {
80 let target = assignment.relating_library_id()?;
81 validate_assignment(
82 self,
83 assignment.id(),
84 &related,
85 target,
86 AssociationSchema {
87 relation: "IFCRELASSOCIATESLIBRARY",
88 target_attribute: "RelatingLibrary",
89 },
90 )?;
91 out.push(assignment);
92 }
93 }
94 Ok(out)
95 }
96}