ifc_resource/inventory/definition.rs
1//! `IfcInventory` — bounded asset-inventory metadata projection.
2//!
3//! IFC2X3 declares `InventoryType` (required), `Jurisdiction`,
4//! `ResponsiblePersons` and `LastUpdateDate` as required, the last an
5//! `IfcCalendarDate` entity rather than IFC4's `IfcDate` text. The shared
6//! accessors read the IFC2X3 slots by their own names and refuse an unset
7//! required one; the calendar date has its own accessor.
8
9use ifc_model::EntityId;
10
11use crate::error::ResourceResult;
12use crate::view::Record;
13
14/// A borrowed, schema-resolved `IfcInventory` projection.
15///
16/// `IfcInventory` is an `IfcGroup`: its members are resolved separately
17/// through `IfcRelAssignsToGroup` (see `items.rs`), never carried on this
18/// projection directly.
19#[derive(Debug, Clone, Copy)]
20pub struct Inventory<'m, 's> {
21 record: Record<'m, 's>,
22}
23
24impl<'m, 's> Inventory<'m, 's> {
25 pub(crate) fn from_record(record: Record<'m, 's>) -> ResourceResult<Self> {
26 Ok(Self { record })
27 }
28
29 /// The entity id of the projected `IfcInventory`.
30 #[must_use]
31 pub fn id(&self) -> EntityId {
32 self.record.id
33 }
34
35 /// The `Name` attribute, when authored.
36 pub fn name(&self) -> ResourceResult<Option<&'m str>> {
37 self.record.optional_text("Name")
38 }
39
40 /// The `Description` attribute, when authored.
41 pub fn description(&self) -> ResourceResult<Option<&'m str>> {
42 self.record.optional_text("Description")
43 }
44
45 /// The `PredefinedType` enumeration, when authored.
46 ///
47 /// Under IFC2X3 this reads the required `InventoryType`, declared with
48 /// the same `IfcInventoryTypeEnum`; an unset value there is refused.
49 pub fn predefined_type(&self) -> ResourceResult<Option<&'m str>> {
50 if self.record.is_ifc2x3() {
51 return self.record.required_enum("InventoryType").map(Some);
52 }
53 self.record.optional_enum("PredefinedType")
54 }
55
56 /// `IfcActorSelect`: an `IfcPerson`, `IfcOrganization`, or
57 /// `IfcPersonAndOrganization`. Required under IFC2X3, so an unset value
58 /// there is refused.
59 pub fn jurisdiction(&self) -> ResourceResult<Option<EntityId>> {
60 const MEMBERS: &[&str] = &["IfcPerson", "IfcOrganization", "IfcPersonAndOrganization"];
61 if self.record.is_ifc2x3() {
62 return self
63 .record
64 .required_ref_select("Jurisdiction", "IfcActorSelect", MEMBERS)
65 .map(Some);
66 }
67 self.record
68 .optional_ref_select("Jurisdiction", "IfcActorSelect", MEMBERS)
69 }
70
71 /// The `ResponsiblePersons` attribute, when authored. Required
72 /// (`SET [1:?]`) under IFC2X3, so an unset value there is refused.
73 pub fn responsible_person_ids(&self) -> ResourceResult<Vec<EntityId>> {
74 let optional = !self.record.is_ifc2x3();
75 self.record
76 .refs("ResponsiblePersons", "IfcPerson", 1, optional, true)
77 }
78
79 /// The `LastUpdateDate` attribute (`IfcDate` text), when authored.
80 ///
81 /// IFC2X3 declares it as an `IfcCalendarDate` entity, so this refuses
82 /// with [`ResourceError::NotInSchema`](crate::ResourceError::NotInSchema) there; read it with
83 /// [`Inventory::last_update_calendar_date`].
84 pub fn last_update_date(&self) -> ResourceResult<Option<&'m str>> {
85 if self.record.is_ifc2x3() {
86 return Err(self.record.not_in_schema("LastUpdateDate"));
87 }
88 self.record.optional_text("LastUpdateDate")
89 }
90
91 /// IFC2X3 `IfcInventory.LastUpdateDate`: the required `IfcCalendarDate`
92 /// reference. [`ResourceError::NotInSchema`](crate::ResourceError::NotInSchema) under IFC4 and IFC4X3,
93 /// where the attribute is `IfcDate` text read by
94 /// [`Inventory::last_update_date`].
95 pub fn last_update_calendar_date(&self) -> ResourceResult<EntityId> {
96 if !self.record.is_ifc2x3() {
97 return Err(self.record.not_in_schema("LastUpdateDate"));
98 }
99 self.record
100 .required_ref("LastUpdateDate", "IfcCalendarDate")
101 }
102
103 /// The `CurrentValue` attribute, when authored.
104 pub fn current_value(&self) -> ResourceResult<Option<EntityId>> {
105 self.record.optional_ref("CurrentValue", "IfcCostValue")
106 }
107
108 /// The `OriginalValue` attribute, when authored.
109 pub fn original_value(&self) -> ResourceResult<Option<EntityId>> {
110 self.record.optional_ref("OriginalValue", "IfcCostValue")
111 }
112}