Skip to main content

ifc_constraint/
types.rs

1//! Typed IFC4 constraint enumerations and metric value projection.
2
3use ifc_model::{EntityId, Value};
4
5macro_rules! string_enum {
6    ($(#[$meta:meta])* $name:ident { $($variant:ident => $token:literal),+ $(,)? }) => {
7        $(#[$meta])*
8        #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9        pub enum $name {
10            $(#[doc = concat!("IFC token `", $token, "`.")]
11            $variant),+
12        }
13        impl $name {
14            pub(crate) fn parse(value: &str) -> Option<Self> {
15                $(if value.eq_ignore_ascii_case($token) { return Some(Self::$variant); })+
16                None
17            }
18            pub(crate) const fn token(self) -> &'static str {
19                match self { $(Self::$variant => $token),+ }
20            }
21        }
22    };
23}
24
25string_enum!(
26    /// Severity/handling grade of an IFC constraint.
27    ConstraintGrade {
28        Hard => "HARD",
29        Soft => "SOFT",
30        Advisory => "ADVISORY",
31        UserDefined => "USERDEFINED",
32        NotDefined => "NOTDEFINED",
33    }
34);
35
36string_enum!(
37    /// Comparison operator carried by `IfcMetric`.
38    Benchmark {
39        GreaterThan => "GREATERTHAN",
40        GreaterThanOrEqualTo => "GREATERTHANOREQUALTO",
41        LessThan => "LESSTHAN",
42        LessThanOrEqualTo => "LESSTHANOREQUALTO",
43        EqualTo => "EQUALTO",
44        NotEqualTo => "NOTEQUALTO",
45        Includes => "INCLUDES",
46        NotIncludes => "NOTINCLUDES",
47        IncludedIn => "INCLUDEDIN",
48        NotIncludedIn => "NOTINCLUDEDIN",
49    }
50);
51
52string_enum!(
53    /// Logical aggregation operator carried by `IfcObjective`.
54    LogicalOperator {
55        LogicalAnd => "LOGICALAND",
56        LogicalOr => "LOGICALOR",
57        LogicalXor => "LOGICALXOR",
58        LogicalNotAnd => "LOGICALNOTAND",
59        LogicalNotOr => "LOGICALNOTOR",
60    }
61);
62
63string_enum!(
64    /// Purpose qualifier carried by `IfcObjective`.
65    ObjectiveQualifier {
66        CodeCompliance => "CODECOMPLIANCE",
67        CodeWaiver => "CODEWAIVER",
68        DesignIntent => "DESIGNINTENT",
69        External => "EXTERNAL",
70        HealthAndSafety => "HEALTHANDSAFETY",
71        MergeConflict => "MERGECONFLICT",
72        ModelView => "MODELVIEW",
73        Parameter => "PARAMETER",
74        Requirement => "REQUIREMENT",
75        Specification => "SPECIFICATION",
76        TriggerCondition => "TRIGGERCONDITION",
77        UserDefined => "USERDEFINED",
78        NotDefined => "NOTDEFINED",
79    }
80);
81
82/// Preserved `IfcMetricValueSelect` without evaluating its meaning.
83#[derive(Debug, Clone, Copy, PartialEq)]
84pub enum MetricValue<'m> {
85    /// Entity-valued member such as `IfcTable` or `IfcAppliedValue`.
86    Entity(EntityId),
87    /// Explicitly typed scalar/select member and its untouched payload.
88    Typed {
89        /// Declared IFC type name.
90        type_name: &'m str,
91        /// Untouched wrapped value.
92        value: &'m Value,
93    },
94}
95
96/// Authoring form of a preserved `IfcMetricValueSelect`.
97#[derive(Debug, Clone, Copy)]
98pub enum MetricValueDraft<'a> {
99    /// Existing or earlier-staged entity-valued member.
100    Entity(EntityId),
101    /// Explicit IFC type name and payload to wrap.
102    Typed {
103        /// Type admitted by `IfcMetricValueSelect`.
104        type_name: &'a str,
105        /// Structural payload preserved verbatim.
106        value: &'a Value,
107    },
108}