ifc_template_catalog/definition/property.rs
1//! Property-template value forms.
2
3use super::LocalizedText;
4
5/// IFC value type and optional publication unit category.
6#[derive(Debug, Clone, PartialEq, Eq, bincode::Encode, bincode::Decode)]
7pub struct PropertyDataType {
8 /// IFC value type; `None` preserves malformed official entries with an empty `DataType`.
9 pub type_name: Option<String>,
10 /// Publication unit category (e.g. `LENGTHUNIT`), absent when unspecified.
11 pub unit_type: Option<String>,
12}
13
14impl PropertyDataType {
15 /// Build a data type with a known `type_name` and no declared unit category.
16 pub fn new(type_name: impl Into<String>) -> Self {
17 Self {
18 type_name: Some(type_name.into()),
19 unit_type: None,
20 }
21 }
22}
23
24/// One documented value from a PSD `ConstantList`.
25#[derive(Debug, Clone, PartialEq, Eq, bincode::Encode, bincode::Decode)]
26pub struct EnumerationConstant {
27 /// Constant's `Name` as declared by the `ConstantList` entry.
28 pub name: String,
29 /// Constant's `Definition` prose, absent when the publication omitted it.
30 pub definition: Option<String>,
31 /// Localized alternates for `name` in other publication languages.
32 pub name_aliases: Vec<LocalizedText>,
33 /// Localized alternates for `definition` in other publication languages.
34 pub definition_aliases: Vec<LocalizedText>,
35}
36
37/// External property template.
38#[derive(Debug, Clone, PartialEq, Eq, bincode::Encode, bincode::Decode)]
39pub struct PropertyTemplate {
40 /// `Name` as declared by the publication.
41 pub name: String,
42 /// Publication `GlobalId`, absent when the source did not assign one.
43 pub guid: Option<String>,
44 /// `Definition` prose, absent when the publication omitted it.
45 pub definition: Option<String>,
46 /// Localized alternates for `name` in other publication languages.
47 pub name_aliases: Vec<LocalizedText>,
48 /// Localized alternates for `definition` in other publication languages.
49 pub definition_aliases: Vec<LocalizedText>,
50 /// Value form, corresponding to an `IfcSimplePropertyTemplateTypeEnum` case.
51 pub kind: PropertyKind,
52}
53
54/// PSD property value form, mirroring `IfcSimplePropertyTemplateTypeEnum`
55/// plus the `IfcComplexPropertyTemplate` case.
56#[derive(Debug, Clone, PartialEq, Eq, bincode::Encode, bincode::Decode)]
57#[non_exhaustive]
58pub enum PropertyKind {
59 /// `P_SINGLEVALUE`: one scalar value of `data_type`.
60 SingleValue {
61 /// Value type and unit category for the scalar.
62 data_type: PropertyDataType,
63 },
64 /// `P_BOUNDEDVALUE`: an upper/lower/set-point triple of `data_type`.
65 BoundedValue {
66 /// Value type and unit category shared by the bound values.
67 data_type: PropertyDataType,
68 },
69 /// `P_ENUMERATEDVALUE`: a selection from a fixed list of lexical values
70 /// or documented constants.
71 EnumeratedValue {
72 /// Name of the referenced `IfcPropertyEnumeration`, absent when inline.
73 enumeration_name: Option<String>,
74 /// Value type and unit category of the enumeration members, absent
75 /// when the publication left it implicit.
76 data_type: Option<PropertyDataType>,
77 /// Lexical values from `EnumList`, in publication order.
78 values: Vec<String>,
79 /// Documented constants from `ConstantList`, kept distinct from lexical values.
80 constants: Vec<EnumerationConstant>,
81 },
82 /// `P_LISTVALUE`: an ordered list of values of `data_type`.
83 ListValue {
84 /// Value type and unit category shared by every list element.
85 data_type: PropertyDataType,
86 },
87 /// `P_REFERENCEVALUE`: a reference to another entity of `reference_type`.
88 ReferenceValue {
89 /// IFC entity type the reference must resolve to.
90 reference_type: String,
91 },
92 /// `P_TABLEVALUE`: a lookup table pairing `defining_type` keys with
93 /// `defined_type` values, optionally constrained by `expression`.
94 TableValue {
95 /// Value type of the table's defining (key) column.
96 defining_type: PropertyDataType,
97 /// Value type of the table's defined (value) column.
98 defined_type: PropertyDataType,
99 /// Optional formula constraining defined values from defining values.
100 expression: Option<String>,
101 },
102 /// An `IfcComplexPropertyTemplate`: a named grouping of nested property templates.
103 Complex {
104 /// `UsageName` distinguishing this grouping's role.
105 usage_name: String,
106 /// Nested property templates that make up this grouping.
107 properties: Vec<PropertyTemplate>,
108 },
109}