Skip to main content

ifc_geometry/error/
about.rs

1//! What a [`GeometryError`] is about: its entity and whether it is unsupported.
2
3use ifc_model::EntityId;
4
5use super::GeometryError;
6
7impl GeometryError {
8    /// The entity this error is about, when there is one.
9    ///
10    /// Lets a caller collect failures per element rather than aborting a whole
11    /// file for one bad wall.
12    pub fn entity(&self) -> Option<EntityId> {
13        match self {
14            Self::MissingEntity { referrer, .. } => Some(*referrer),
15            Self::MissingAttribute { entity, .. }
16            | Self::WrongValueKind { entity, .. }
17            | Self::WrongEntityType { entity, .. }
18            | Self::Unsupported { entity, .. }
19            | Self::CyclicChain { entity, .. }
20            | Self::ChainTooDeep { entity, .. }
21            | Self::AggregateTooLarge { entity, .. }
22            | Self::Degenerate { entity, .. } => Some(*entity),
23            Self::GridAxesParallel { intersection, .. }
24            | Self::GridAxesDoNotIntersect { intersection, .. }
25            | Self::GridAxesInDifferentGrids { intersection, .. } => Some(*intersection),
26            Self::GridAxisWithoutGrid { axis } => Some(*axis),
27            Self::PlacementRelToConflict { placement, .. } => Some(*placement),
28            #[cfg(feature = "compile")]
29            Self::CompilationRefused { entity, .. } => Some(*entity),
30            #[cfg(feature = "compile")]
31            Self::NotASolid { entity, .. } => Some(*entity),
32            #[cfg(feature = "compile")]
33            Self::CachedPlacementMismatch { placement, .. } => Some(*placement),
34            #[cfg(feature = "compile")]
35            Self::SeamSideUnsupported { placement, .. } => Some(*placement),
36            #[cfg(feature = "compile")]
37            Self::CurvePathUnsupported { placement, .. } => Some(*placement),
38            #[cfg(feature = "compile")]
39            Self::PathPieceLengthUnstated { placement, .. }
40            | Self::CurvePathOpenEndUnsupported { placement, .. }
41            | Self::PathPointOffCurve { placement, .. }
42            | Self::PathPointAmbiguous { placement, .. }
43            | Self::CurvePathBoundUnsupported { placement, .. }
44            | Self::PathJointDistancesUnsupported { placement, .. }
45            | Self::PlacementSeamWindowRefused { placement, .. } => Some(*placement),
46            #[cfg(feature = "compile")]
47            Self::StationSeamWindowRefused {
48                product, stations, ..
49            } => Some(stations.first().copied().unwrap_or(*product)),
50            #[cfg(feature = "compile")]
51            Self::RunSeamWindowRefused { product, runs, .. } => {
52                Some(runs.first().copied().unwrap_or(*product))
53            }
54            // The opening is what failed; `host` stays readable on the variant.
55            Self::OpeningNotSubtracted { opening, .. } => Some(*opening),
56            Self::LayerNotSplit { product, .. } => Some(*product),
57            Self::LengthUnitUndeclared {
58                project,
59                assignment,
60            } => assignment.or(*project),
61            Self::AngleUnitUndeclared { entity } => Some(*entity),
62            Self::UnitUnreadable { unit, .. } => Some(*unit),
63            Self::UnitsAmbiguous { second, .. } => Some(*second),
64            Self::UnitRecordDamaged { entity, .. } => Some(*entity),
65            Self::Units(_)
66            | Self::UnitsIncomplete { .. }
67            | Self::InvalidAuthoredValue { .. }
68            | Self::AuthoringSchemaUnbound { .. }
69            | Self::AuthoringEntityNotInSchema { .. } => None,
70        }
71    }
72
73    /// Is this "valid IFC we do not handle yet" rather than a broken file?
74    ///
75    /// Callers building a viewer usually want to skip and count these, while
76    /// treating genuine corruption differently.
77    pub fn is_unsupported(&self) -> bool {
78        match self {
79            Self::Unsupported { .. } => true,
80            // Valid IFC this evaluator cannot read; one with seam sides can.
81            #[cfg(feature = "compile")]
82            Self::SeamSideUnsupported { .. } => true,
83            // Valid IFC this evaluator cannot read; one with curve paths can.
84            #[cfg(feature = "compile")]
85            Self::CurvePathUnsupported { .. } => true,
86            // Valid IFC whose path needs an execution provider, or an
87            // evaluator with open ends, piece bounds or certified joints
88            // (#427, #436). A trim point off its curve, or one it passes
89            // through twice, is the file failing to name one place.
90            #[cfg(feature = "compile")]
91            Self::PathPieceLengthUnstated { .. }
92            | Self::CurvePathOpenEndUnsupported { .. }
93            | Self::CurvePathBoundUnsupported { .. }
94            | Self::PathJointDistancesUnsupported { .. } => true,
95            // A seam the kernel cannot certify is valid IFC it cannot read;
96            // two seams within precision, or a seam on its edge, is the
97            // file's precision failing to name one place.
98            #[cfg(feature = "compile")]
99            Self::StationSeamWindowRefused { refusal, .. }
100            | Self::PlacementSeamWindowRefused { refusal, .. }
101            | Self::RunSeamWindowRefused { refusal, .. } => matches!(
102                refusal,
103                crate::compile::SeamWindowRefusal::UncertifiedLength
104                    | crate::compile::SeamWindowRefusal::CertificationBudgetExceeded
105            ),
106            // A net refusal is as supported as the reason behind it.
107            Self::OpeningNotSubtracted { cause, .. } | Self::LayerNotSplit { cause, .. } => {
108                cause.is_unsupported()
109            }
110            _ => false,
111        }
112    }
113}