#[derive(Debug, Clone, Copy)]
pub(crate) struct RelSlots {
pub type_name: &'static str,
pub relating: usize,
pub related: usize,
}
impl RelSlots {
pub(crate) fn relating_name(self) -> &'static str {
ifc4_name(self.type_name, self.relating)
}
pub(crate) fn related_name(self) -> &'static str {
ifc4_name(self.type_name, self.related)
}
}
fn ifc4_name(entity: &str, slot: usize) -> &'static str {
ifc_schema::ifc4x3().attribute_names(entity)[slot]
}
pub(crate) const AGGREGATES: RelSlots = RelSlots {
type_name: "IFCRELAGGREGATES",
relating: 4,
related: 5,
};
pub(crate) const CONTAINED_IN: RelSlots = RelSlots {
type_name: "IFCRELCONTAINEDINSPATIALSTRUCTURE",
relating: 5,
related: 4,
};
pub(crate) const REFERENCED_IN: RelSlots = RelSlots {
type_name: "IFCRELREFERENCEDINSPATIALSTRUCTURE",
relating: 5,
related: 4,
};
pub(crate) const NESTS: RelSlots = RelSlots {
type_name: "IFCRELNESTS",
relating: 4,
related: 5,
};
pub(crate) const SPACE_BOUNDARY: RelSlots = RelSlots {
type_name: "IFCRELSPACEBOUNDARY",
relating: 4,
related: 5,
};
pub(crate) const SPACE_BOUNDARY_1ST: RelSlots = RelSlots {
type_name: "IFCRELSPACEBOUNDARY1STLEVEL",
relating: 4,
related: 5,
};
pub(crate) const SPACE_BOUNDARY_2ND: RelSlots = RelSlots {
type_name: "IFCRELSPACEBOUNDARY2NDLEVEL",
relating: 4,
related: 5,
};
pub(crate) const SPACE_BOUNDARY_TYPES: [RelSlots; 3] =
[SPACE_BOUNDARY, SPACE_BOUNDARY_1ST, SPACE_BOUNDARY_2ND];
pub(crate) const COVERS_ELEMENTS: RelSlots = RelSlots {
type_name: "IFCRELCOVERSBLDGELEMENTS",
relating: 4,
related: 5,
};
pub(crate) const COVERS_SPACES: RelSlots = RelSlots {
type_name: "IFCRELCOVERSSPACES",
relating: 4,
related: 5,
};
pub(crate) const CONNECTS_ELEMENTS: RelSlots = RelSlots {
type_name: "IFCRELCONNECTSELEMENTS",
relating: 5,
related: 6,
};
pub(crate) const CONNECTS_PATH_ELEMENTS: RelSlots = RelSlots {
type_name: "IFCRELCONNECTSPATHELEMENTS",
relating: 5,
related: 6,
};
pub(crate) const CONNECTS_WITH_REALIZING: RelSlots = RelSlots {
type_name: "IFCRELCONNECTSWITHREALIZINGELEMENTS",
relating: 5,
related: 6,
};
pub(crate) const CONNECTS_ELEMENT_TYPES: [RelSlots; 3] = [
CONNECTS_ELEMENTS,
CONNECTS_PATH_ELEMENTS,
CONNECTS_WITH_REALIZING,
];
pub(crate) const INTERFERES_ELEMENTS: RelSlots = RelSlots {
type_name: "IFCRELINTERFERESELEMENTS",
relating: 4,
related: 5,
};
pub(crate) const ASSIGNS_TO_ACTOR: RelSlots = RelSlots {
type_name: "IFCRELASSIGNSTOACTOR",
relating: 6,
related: 4,
};
pub(crate) const ASSIGNS_TO_PROCESS: RelSlots = RelSlots {
type_name: "IFCRELASSIGNSTOPROCESS",
relating: 6,
related: 4,
};
pub(crate) const ASSIGNS_TO_PRODUCT: RelSlots = RelSlots {
type_name: "IFCRELASSIGNSTOPRODUCT",
relating: 6,
related: 4,
};
pub(crate) const ASSIGNS_TO_GROUP_BY_FACTOR: RelSlots = RelSlots {
type_name: "IFCRELASSIGNSTOGROUPBYFACTOR",
relating: 6,
related: 4,
};
pub(crate) const DECLARES: RelSlots = RelSlots {
type_name: "IFCRELDECLARES",
relating: 4,
related: 5,
};
pub(crate) const DEFINES_BY_OBJECT: RelSlots = RelSlots {
type_name: "IFCRELDEFINESBYOBJECT",
relating: 5,
related: 4,
};
pub(crate) const FLOW_CONTROL_ELEMENTS: RelSlots = RelSlots {
type_name: "IFCRELFLOWCONTROLELEMENTS",
relating: 5,
related: 4,
};
pub(crate) const SERVICES_BUILDINGS: RelSlots = RelSlots {
type_name: "IFCRELSERVICESBUILDINGS",
relating: 4,
related: 5,
};
pub(crate) const CONNECTS_WITH_ECCENTRICITY: RelSlots = RelSlots {
type_name: "IFCRELCONNECTSWITHECCENTRICITY",
relating: 4,
related: 5,
};
pub(crate) const VOIDS_ELEMENT: RelSlots = RelSlots {
type_name: "IFCRELVOIDSELEMENT",
relating: 4,
related: 5,
};
pub(crate) const FILLS_ELEMENT: RelSlots = RelSlots {
type_name: "IFCRELFILLSELEMENT",
relating: 4,
related: 5,
};
pub(crate) const PROJECTS_ELEMENT: RelSlots = RelSlots {
type_name: "IFCRELPROJECTSELEMENT",
relating: 4,
related: 5,
};
pub(crate) const ADHERES_TO_ELEMENT: RelSlots = RelSlots {
type_name: "IFCRELADHERESTOELEMENT",
relating: 4,
related: 5,
};
pub(crate) const POSITIONS: RelSlots = RelSlots {
type_name: "IFCRELPOSITIONS",
relating: 4,
related: 5,
};
pub(crate) const ASSIGNS_TO_RESOURCE: RelSlots = RelSlots {
type_name: "IFCRELASSIGNSTORESOURCE",
relating: 6,
related: 4,
};
pub(crate) const ASSOCIATES_PROFILE_DEF: RelSlots = RelSlots {
type_name: "IFCRELASSOCIATESPROFILEDEF",
relating: 5,
related: 4,
};
#[cfg(test)]
mod tests {
use super::*;
const WRITTEN: [RelSlots; 22] = [
AGGREGATES,
CONTAINED_IN,
COVERS_ELEMENTS,
COVERS_SPACES,
DECLARES,
DEFINES_BY_OBJECT,
SERVICES_BUILDINGS,
FLOW_CONTROL_ELEMENTS,
ASSIGNS_TO_ACTOR,
ASSIGNS_TO_PRODUCT,
ASSIGNS_TO_PROCESS,
ASSIGNS_TO_GROUP_BY_FACTOR,
ASSIGNS_TO_RESOURCE,
CONNECTS_ELEMENTS,
CONNECTS_WITH_REALIZING,
CONNECTS_PATH_ELEMENTS,
INTERFERES_ELEMENTS,
VOIDS_ELEMENT,
FILLS_ELEMENT,
PROJECTS_ELEMENT,
ADHERES_TO_ELEMENT,
POSITIONS,
];
#[test]
fn written_names_are_the_ifc4_names_at_the_reader_slots() {
let mut checked = 0;
for rel in WRITTEN.into_iter().chain([ASSOCIATES_PROFILE_DEF]) {
let ifc4 = ifc_schema::ifc4().attribute_names(rel.type_name);
let ifc4x3 = ifc_schema::ifc4x3().attribute_names(rel.type_name);
assert!(!ifc4x3.is_empty(), "{}", rel.type_name);
assert_eq!(rel.relating_name(), ifc4x3[rel.relating]);
assert_eq!(rel.related_name(), ifc4x3[rel.related]);
if !ifc4.is_empty() {
assert_eq!(rel.relating_name(), ifc4[rel.relating], "{}", rel.type_name);
assert_eq!(rel.related_name(), ifc4[rel.related], "{}", rel.type_name);
checked += 1;
}
}
assert_eq!(checked, 20);
}
}