Skip to main content

ifc_resource/actor/
mod.rs

1//! Actor capability: `IfcPerson`, `IfcOrganization`, `IfcPersonAndOrganization`,
2//! `IfcActorRole`.
3//!
4//! ## Internal split
5//!
6//! - `person.rs`: people and identities.
7//! - `organization.rs`: organizations/relationships.
8//! - `role.rs`: actor roles.
9
10mod organization;
11mod person;
12mod role;
13
14pub use organization::{Organization, OrganizationRelationship};
15pub use person::Person;
16pub use role::ActorRole;
17
18use ifc_model::EntityId;
19
20use crate::error::ResourceResult;
21use crate::view::{Record, ResourceView};
22
23/// Borrowed `IfcPersonAndOrganization` projection.
24#[derive(Debug, Clone, Copy)]
25pub struct PersonAndOrganization<'m, 's> {
26    record: Record<'m, 's>,
27}
28
29impl<'m, 's> PersonAndOrganization<'m, 's> {
30    pub(crate) fn from_record(record: Record<'m, 's>) -> ResourceResult<Self> {
31        Ok(Self { record })
32    }
33
34    /// The entity id of the projected `IfcPersonAndOrganization`.
35    #[must_use]
36    pub fn id(&self) -> EntityId {
37        self.record.id
38    }
39
40    /// The `ThePerson` attribute.
41    pub fn person(&self) -> ResourceResult<EntityId> {
42        self.record.required_ref("ThePerson", "IfcPerson")
43    }
44
45    /// The `TheOrganization` attribute.
46    pub fn organization(&self) -> ResourceResult<EntityId> {
47        self.record
48            .required_ref("TheOrganization", "IfcOrganization")
49    }
50
51    /// The `Roles` attribute, when authored.
52    pub fn role_ids(&self) -> ResourceResult<Vec<EntityId>> {
53        self.record.refs("Roles", "IfcActorRole", 1, true, false)
54    }
55}
56
57impl<'m, 's> ResourceView<'m, 's> {
58    /// Projects an `IfcPerson` by entity id.
59    pub fn person(&self, id: EntityId) -> ResourceResult<Person<'m, 's>> {
60        Person::from_record(self.record(id, "IfcPerson")?)
61    }
62
63    /// Projects an `IfcOrganization` by entity id.
64    pub fn organization(&self, id: EntityId) -> ResourceResult<Organization<'m, 's>> {
65        Organization::from_record(self.record(id, "IfcOrganization")?)
66    }
67
68    /// Projects an `IfcActorRole` by entity id.
69    pub fn actor_role(&self, id: EntityId) -> ResourceResult<ActorRole<'m, 's>> {
70        ActorRole::from_record(self.record(id, "IfcActorRole")?)
71    }
72
73    /// Projects an `IfcPersonAndOrganization` by entity id.
74    pub fn person_and_organization(
75        &self,
76        id: EntityId,
77    ) -> ResourceResult<PersonAndOrganization<'m, 's>> {
78        PersonAndOrganization::from_record(self.record(id, "IfcPersonAndOrganization")?)
79    }
80}