use std::{fmt, sync::Arc};
use ifc_geometry::GeometryError;
use ifc_model::EntityId;
use ifc_properties::{ExactPropertyError, ExactUnitError};
use super::RefusedWindowOperation;
use crate::operation::ReadError;
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum WindowOperationError {
Property(ExactPropertyError),
Unit(ExactUnitError),
Placement(GeometryError),
NotAWindow {
entity: EntityId,
type_name: Arc<str>,
},
UnsupportedTypeObject {
type_object: EntityId,
type_name: Arc<str>,
},
MalformedAttribute {
entity: EntityId,
attribute: &'static str,
},
MissingPartitioningType {
window: EntityId,
},
ConflictingPartitioningType {
occurrence: Arc<str>,
type_object: EntityId,
type_value: Arc<str>,
},
RefusedPartitioning {
partitioning: Arc<str>,
reason: RefusedWindowOperation,
},
RefusedPanelOperation {
set: EntityId,
operation: Arc<str>,
reason: RefusedWindowOperation,
},
MissingOverallWidth {
window: EntityId,
},
MissingOverallHeight {
window: EntityId,
},
NoPanelProperties {
window: EntityId,
},
PanelCount {
expected: usize,
found: usize,
},
PanelMismatch {
set: EntityId,
attribute: &'static str,
found: Arc<str>,
},
NoLiningProperties {
window: EntityId,
},
LiningCount {
found: usize,
},
MissingSplit {
set: EntityId,
attribute: &'static str,
},
InvalidSplit {
set: EntityId,
attribute: &'static str,
value: f64,
},
NonRigidPlacement {
window: EntityId,
},
NoPlanHandedness {
window: EntityId,
},
}
impl fmt::Display for WindowOperationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "window operation cannot be derived exactly: {self:?}")
}
}
impl std::error::Error for WindowOperationError {}
impl From<ExactPropertyError> for WindowOperationError {
fn from(error: ExactPropertyError) -> Self {
Self::Property(error)
}
}
impl From<ExactUnitError> for WindowOperationError {
fn from(error: ExactUnitError) -> Self {
Self::Unit(error)
}
}
impl WindowOperationError {
pub(super) fn read(error: ReadError) -> Self {
match error {
ReadError::Malformed { entity, attribute } => {
Self::MalformedAttribute { entity, attribute }
}
ReadError::Unit(error) => Self::Unit(error),
ReadError::Placement(error) => Self::Placement(error),
}
}
}