use ifc_model::EntityId;
use ifc_schema::SchemaVersion;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SystemAnomaly {
Dangling {
relation: EntityId,
missing: EntityId,
},
ZoneMemberNotSpatial {
relation: EntityId,
zone: EntityId,
member: EntityId,
type_name: String,
},
ContainedTwice {
element: EntityId,
first: EntityId,
second: EntityId,
},
PortAttachedTwice {
port: EntityId,
kept: EntityId,
rejected: EntityId,
},
NotAPort {
relation: EntityId,
entity: EntityId,
type_name: String,
},
NotASystem {
relation: EntityId,
group: EntityId,
type_name: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SchemaResolutionError {
MissingSchema,
MultipleSchemas {
schemas: usize,
},
UnsupportedSchema {
schema: String,
},
}
impl std::fmt::Display for SchemaResolutionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingSchema => write!(f, "FILE_SCHEMA declares no schema"),
Self::MultipleSchemas { schemas } => {
write!(
f,
"FILE_SCHEMA declares {schemas} schemas, expected exactly one"
)
}
Self::UnsupportedSchema { schema } => {
write!(
f,
"schema {schema:?} is not resolved by this ifc-systems read"
)
}
}
}
}
impl std::error::Error for SchemaResolutionError {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct NotInSchema {
pub entity: EntityId,
pub schema: SchemaVersion,
}
impl std::fmt::Display for NotInSchema {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"attribute not declared for entity {:?} under {:?}",
self.entity, self.schema
)
}
}
impl std::error::Error for NotInSchema {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SchemaGap {
Schema(SchemaResolutionError),
NotInSchema(NotInSchema),
}
impl From<SchemaResolutionError> for SchemaGap {
fn from(error: SchemaResolutionError) -> Self {
Self::Schema(error)
}
}
impl From<NotInSchema> for SchemaGap {
fn from(error: NotInSchema) -> Self {
Self::NotInSchema(error)
}
}
impl std::fmt::Display for SchemaGap {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Schema(error) => write!(f, "{error}"),
Self::NotInSchema(error) => write!(f, "{error}"),
}
}
}
impl std::error::Error for SchemaGap {}