Skip to main content

ifc_validate/property_set/
template.rs

1//! The members a catalog template declares, in neutral terms (#537).
2//!
3//! `ifc-validate` links no catalog (ADR 0017), so the facade copies what it
4//! needs from a catalog's set templates into these types. Names are the
5//! catalog's spelling; value types are IFC defined-type names such as
6//! `IfcBoolean`.
7
8/// One catalog set template: what kind of set it is and which members it
9/// declares.
10#[derive(Debug, Clone, PartialEq, Eq)]
11#[non_exhaustive]
12pub struct CatalogSet {
13    /// Whether the set holds properties or quantities.
14    pub kind: CatalogSetKind,
15    /// The declared members, in catalog order.
16    pub members: Vec<CatalogMember>,
17}
18
19impl CatalogSet {
20    /// A property set declaring `members`.
21    #[must_use]
22    pub fn property(members: Vec<CatalogMember>) -> Self {
23        Self {
24            kind: CatalogSetKind::Property,
25            members,
26        }
27    }
28
29    /// A quantity set declaring `members`.
30    #[must_use]
31    pub fn quantity(members: Vec<CatalogMember>) -> Self {
32        Self {
33            kind: CatalogSetKind::Quantity,
34            members,
35        }
36    }
37}
38
39/// Whether a catalog set is an `IfcPropertySet` or an `IfcElementQuantity`.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41#[non_exhaustive]
42pub enum CatalogSetKind {
43    /// An `IfcPropertySet`.
44    Property,
45    /// An `IfcElementQuantity`.
46    Quantity,
47}
48
49/// One declared property or quantity.
50#[derive(Debug, Clone, PartialEq, Eq)]
51#[non_exhaustive]
52pub struct CatalogMember {
53    /// The member's `Name`.
54    pub name: String,
55    /// The entity form and value types it declares.
56    pub form: CatalogMemberForm,
57}
58
59impl CatalogMember {
60    /// A member named `name` of `form`.
61    #[must_use]
62    pub fn new(name: impl Into<String>, form: CatalogMemberForm) -> Self {
63        Self {
64            name: name.into(),
65            form,
66        }
67    }
68}
69
70/// The entity form of a declared member, with the value types it declares.
71///
72/// A `None` value type means the catalog leaves it open: not checked.
73#[derive(Debug, Clone, PartialEq, Eq)]
74#[non_exhaustive]
75pub enum CatalogMemberForm {
76    /// An `IfcPropertySingleValue`.
77    SingleValue {
78        /// The `NominalValue` type.
79        data_type: Option<String>,
80    },
81    /// An `IfcPropertyEnumeratedValue`.
82    EnumeratedValue {
83        /// The type of the `EnumerationValues` members.
84        data_type: Option<String>,
85    },
86    /// An `IfcPropertyBoundedValue`.
87    BoundedValue {
88        /// The type of the bound and set-point values.
89        data_type: Option<String>,
90    },
91    /// An `IfcPropertyListValue`.
92    ListValue {
93        /// The type of the `ListValues` members.
94        data_type: Option<String>,
95    },
96    /// An `IfcPropertyTableValue`.
97    TableValue {
98        /// The type of the `DefiningValues` members.
99        defining_type: Option<String>,
100        /// The type of the `DefinedValues` members.
101        defined_type: Option<String>,
102    },
103    /// An `IfcPropertyReferenceValue`.
104    ReferenceValue {
105        /// The entity type the reference must resolve to.
106        reference_type: String,
107    },
108    /// An `IfcComplexProperty` grouping further properties.
109    Complex {
110        /// The declared nested members.
111        members: Vec<CatalogMember>,
112    },
113    /// A simple quantity of the given kind.
114    Quantity(CatalogQuantityKind),
115}
116
117impl CatalogMemberForm {
118    /// The IFC entity this form is written as.
119    #[must_use]
120    pub fn entity_name(&self) -> &'static str {
121        match self {
122            Self::SingleValue { .. } => "IfcPropertySingleValue",
123            Self::EnumeratedValue { .. } => "IfcPropertyEnumeratedValue",
124            Self::BoundedValue { .. } => "IfcPropertyBoundedValue",
125            Self::ListValue { .. } => "IfcPropertyListValue",
126            Self::TableValue { .. } => "IfcPropertyTableValue",
127            Self::ReferenceValue { .. } => "IfcPropertyReferenceValue",
128            Self::Complex { .. } => "IfcComplexProperty",
129            Self::Quantity(kind) => kind.entity_name(),
130        }
131    }
132}
133
134/// The family of a simple quantity.
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
136#[non_exhaustive]
137pub enum CatalogQuantityKind {
138    /// `IfcQuantityLength`.
139    Length,
140    /// `IfcQuantityArea`.
141    Area,
142    /// `IfcQuantityVolume`.
143    Volume,
144    /// `IfcQuantityWeight`.
145    Weight,
146    /// `IfcQuantityTime`.
147    Time,
148    /// `IfcQuantityCount`.
149    Count,
150    /// `IfcQuantityNumber`.
151    Number,
152}
153
154impl CatalogQuantityKind {
155    /// The IFC entity of this kind.
156    #[must_use]
157    pub fn entity_name(self) -> &'static str {
158        match self {
159            Self::Length => "IfcQuantityLength",
160            Self::Area => "IfcQuantityArea",
161            Self::Volume => "IfcQuantityVolume",
162            Self::Weight => "IfcQuantityWeight",
163            Self::Time => "IfcQuantityTime",
164            Self::Count => "IfcQuantityCount",
165            Self::Number => "IfcQuantityNumber",
166        }
167    }
168}