Skip to main content

ifc_classification/assignment/
document.rs

1//! Borrowed `Ifcrelassociatesdocument` association projection.
2use 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!(DocumentAssignment, "IFCRELASSOCIATESDOCUMENT");
9impl<'m> DocumentAssignment<'m> {
10    /// The `GlobalId` of this `IfcRelAssociatesDocument`.
11    pub fn global_id(self) -> ClassificationResult<&'m str> {
12        required_text(
13            "IFCRELASSOCIATESDOCUMENT",
14            self.id(),
15            self.entity(),
16            self.text_slot("GlobalId")?,
17            "GlobalId",
18        )
19    }
20    /// Optional `Name` of the association relationship.
21    pub fn name(self) -> ClassificationResult<Option<&'m str>> {
22        optional_text(
23            "IFCRELASSOCIATESDOCUMENT",
24            self.id(),
25            self.entity(),
26            self.text_slot("Name")?,
27            "Name",
28        )
29    }
30    /// Optional `Description` of the association relationship.
31    pub fn description(self) -> ClassificationResult<Option<&'m str>> {
32        optional_text(
33            "IFCRELASSOCIATESDOCUMENT",
34            self.id(),
35            self.entity(),
36            self.text_slot("Description")?,
37            "Description",
38        )
39    }
40    /// Ids of the `RelatedObjects` the document applies to; non-empty per schema.
41    pub fn related_object_ids(self) -> ClassificationResult<Vec<EntityId>> {
42        required_refs(
43            "IFCRELASSOCIATESDOCUMENT",
44            self.id(),
45            self.entity(),
46            self.slot("RelatedObjects")?,
47            "RelatedObjects",
48        )
49    }
50    /// Id of the `RelatingDocument` (an `IfcDocumentInformation` or `IfcDocumentReference`).
51    pub fn relating_document_id(self) -> ClassificationResult<EntityId> {
52        required_ref(
53            "IFCRELASSOCIATESDOCUMENT",
54            self.id(),
55            self.entity(),
56            self.slot("RelatingDocument")?,
57            "RelatingDocument",
58        )
59    }
60}
61impl<'m> ClassificationView<'m> {
62    /// All `IfcRelAssociatesDocument` instances in the model.
63    pub fn document_assignments(self) -> impl Iterator<Item = DocumentAssignment<'m>> + 'm {
64        self.model()
65            .of_type("IFCRELASSOCIATESDOCUMENT")
66            .map(move |(id, e)| DocumentAssignment::from_known(id, e, self.release()))
67    }
68    /// Document assignments naming `object` among their `RelatedObjects`, with the relating document checked against `IfcDocumentSelect`; fails if `object` is unknown or a reference does not resolve.
69    pub fn document_assignments_for(
70        self,
71        object: EntityId,
72    ) -> ClassificationResult<Vec<DocumentAssignment<'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.document_assignments() {
78            let related = assignment.related_object_ids()?;
79            if related.contains(&object) {
80                let target = assignment.relating_document_id()?;
81                validate_assignment(
82                    self,
83                    assignment.id(),
84                    &related,
85                    target,
86                    AssociationSchema {
87                        relation: "IFCRELASSOCIATESDOCUMENT",
88                        target_attribute: "RelatingDocument",
89                    },
90                )?;
91                out.push(assignment);
92            }
93        }
94        Ok(out)
95    }
96}