Skip to main content

ifc_resource/actor/
organization.rs

1//! `IfcOrganization` and `IfcOrganizationRelationship` — bounded IFC4
2//! organization projections.
3
4use ifc_model::EntityId;
5
6use crate::actor::role::ActorRole;
7use crate::error::ResourceResult;
8use crate::view::{Record, ResourceView};
9
10/// A borrowed, schema-resolved `IfcOrganization` projection.
11#[derive(Debug, Clone, Copy)]
12pub struct Organization<'m, 's> {
13    record: Record<'m, 's>,
14}
15
16impl<'m, 's> Organization<'m, 's> {
17    pub(crate) fn from_record(record: Record<'m, 's>) -> ResourceResult<Self> {
18        Ok(Self { record })
19    }
20
21    /// The entity id of the projected `IfcOrganization`.
22    #[must_use]
23    pub fn id(&self) -> EntityId {
24        self.record.id
25    }
26
27    /// The `Identification` attribute, when authored.
28    pub fn identification(&self) -> ResourceResult<Option<&'m str>> {
29        self.record.optional_text("Identification")
30    }
31
32    /// The `Name` attribute.
33    pub fn name(&self) -> ResourceResult<&'m str> {
34        self.record.required_text("Name")
35    }
36
37    /// The `Description` attribute, when authored.
38    pub fn description(&self) -> ResourceResult<Option<&'m str>> {
39        self.record.optional_text("Description")
40    }
41
42    /// The `Roles` attribute: entity references, when authored.
43    pub fn role_ids(&self) -> ResourceResult<Vec<EntityId>> {
44        self.record.refs("Roles", "IfcActorRole", 1, true, false)
45    }
46
47    /// The `Roles` attribute, resolved to projected `IfcActorRole` values.
48    pub fn roles(&self) -> ResourceResult<Vec<ActorRole<'m, 's>>> {
49        self.role_ids()?
50            .into_iter()
51            .map(|id| {
52                Record::new(self.record.model, self.record.schema, id, "IfcActorRole")
53                    .and_then(ActorRole::from_record)
54            })
55            .collect()
56    }
57
58    /// The `Addresses` attribute, when authored.
59    pub fn address_ids(&self) -> ResourceResult<Vec<EntityId>> {
60        self.record.refs("Addresses", "IfcAddress", 1, true, false)
61    }
62}
63
64/// Borrowed `IfcOrganizationRelationship` projection: a named relationship
65/// between one relating organization and one or more related organizations.
66#[derive(Debug, Clone, Copy)]
67pub struct OrganizationRelationship<'m, 's> {
68    record: Record<'m, 's>,
69}
70
71impl<'m, 's> OrganizationRelationship<'m, 's> {
72    pub(crate) fn from_record(record: Record<'m, 's>) -> ResourceResult<Self> {
73        Ok(Self { record })
74    }
75
76    /// The entity id of the projected `IfcOrganizationRelationship`.
77    #[must_use]
78    pub fn id(&self) -> EntityId {
79        self.record.id
80    }
81
82    /// The `Name` attribute, when authored.
83    pub fn name(&self) -> ResourceResult<Option<&'m str>> {
84        self.record.optional_text("Name")
85    }
86
87    /// The `Description` attribute, when authored.
88    pub fn description(&self) -> ResourceResult<Option<&'m str>> {
89        self.record.optional_text("Description")
90    }
91
92    /// The `RelatingOrganization` attribute.
93    pub fn relating_organization(&self) -> ResourceResult<EntityId> {
94        self.record
95            .required_ref("RelatingOrganization", "IfcOrganization")
96    }
97
98    /// The `RelatedOrganizations` attribute.
99    pub fn related_organizations(&self) -> ResourceResult<Vec<EntityId>> {
100        self.record
101            .refs("RelatedOrganizations", "IfcOrganization", 1, false, true)
102    }
103}
104
105impl<'m, 's> ResourceView<'m, 's> {
106    /// Projects an `IfcOrganizationRelationship` by entity id.
107    pub fn organization_relationship(
108        &self,
109        id: EntityId,
110    ) -> ResourceResult<OrganizationRelationship<'m, 's>> {
111        OrganizationRelationship::from_record(self.record(id, "IfcOrganizationRelationship")?)
112    }
113}