use ifc_model::EntityId;
#[derive(Debug, Clone, PartialEq)]
pub enum PropertyAnomaly {
TypeAttachedByRelationship {
relationship: EntityId,
type_object: EntityId,
},
MissingDefinition {
relationship: EntityId,
definition: EntityId,
},
MissingObject {
relationship: EntityId,
object: EntityId,
},
QuantityUnitMismatch {
quantity: EntityId,
unit: EntityId,
expected: &'static str,
found: String,
},
NegativeQuantity {
quantity: EntityId,
value: f64,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum PropertyError {
MissingEntity {
id: EntityId,
},
NotAQuantity {
id: EntityId,
type_name: String,
},
NotAQuantitySet {
id: EntityId,
type_name: String,
},
AuthoringInvalid {
entity: &'static str,
attribute: &'static str,
value: String,
},
}
impl std::fmt::Display for PropertyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingEntity { id } => write!(f, "#{} is not in the model", id.0),
Self::NotAQuantity { id, type_name } => {
write!(f, "#{} is a {type_name}, not a simple quantity", id.0)
}
Self::NotAQuantitySet { id, type_name } => {
write!(f, "#{} is a {type_name}, not an IfcElementQuantity", id.0)
}
Self::AuthoringInvalid {
entity,
attribute,
value,
} => write!(
f,
"{entity}.{attribute} rejected the authored value: {value}"
),
}
}
}
pub type PropertyResult<T> = Result<T, PropertyError>;
impl std::error::Error for PropertyError {}