use ifc_model::{Entity, EntityId, Model, Value};
pub mod slot {
pub const GLOBAL_ID: usize = 0;
pub const NAME: usize = 2;
pub const DESCRIPTION: usize = 3;
pub const IDENTIFICATION: usize = 5;
pub const CREATION_DATE: usize = 6;
pub const PURPOSE: usize = 8;
pub const DURATION: usize = 9;
pub const TOTAL_FLOAT: usize = 10;
pub const START_TIME: usize = 11;
pub const FINISH_TIME: usize = 12;
pub const PREDEFINED_TYPE: usize = 13;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WorkControlKind {
Plan,
Schedule,
}
impl WorkControlKind {
fn from_type(name: &str) -> Option<Self> {
if name.eq_ignore_ascii_case("IFCWORKPLAN") {
Some(Self::Plan)
} else if name.eq_ignore_ascii_case("IFCWORKSCHEDULE") {
Some(Self::Schedule)
} else {
None
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct WorkControl<'m> {
id: EntityId,
entity: &'m Entity,
kind: WorkControlKind,
}
impl<'m> WorkControl<'m> {
#[must_use]
pub fn new(id: EntityId, entity: &'m Entity) -> Option<Self> {
let kind = WorkControlKind::from_type(&entity.type_name)?;
Some(Self { id, entity, kind })
}
#[must_use]
pub fn id(&self) -> EntityId {
self.id
}
#[must_use]
pub fn kind(&self) -> WorkControlKind {
self.kind
}
#[must_use]
pub fn global_id(&self) -> Option<&'m str> {
self.entity.text(slot::GLOBAL_ID)
}
#[must_use]
pub fn name(&self) -> Option<&'m str> {
self.entity.text(slot::NAME)
}
#[must_use]
pub fn description(&self) -> Option<&'m str> {
self.entity.text(slot::DESCRIPTION)
}
#[must_use]
pub fn identification(&self) -> Option<&'m str> {
self.entity.text(slot::IDENTIFICATION)
}
#[must_use]
pub fn purpose(&self) -> Option<&'m str> {
self.entity.text(slot::PURPOSE)
}
#[must_use]
pub fn creation_date(&self) -> Option<&'m str> {
self.entity.text(slot::CREATION_DATE)
}
#[must_use]
pub fn start_time(&self) -> Option<&'m str> {
self.entity.text(slot::START_TIME)
}
#[must_use]
pub fn finish_time(&self) -> Option<&'m str> {
self.entity.text(slot::FINISH_TIME)
}
#[must_use]
pub fn duration(&self) -> Option<&'m str> {
self.entity.text(slot::DURATION)
}
#[must_use]
pub fn total_float(&self) -> Option<&'m str> {
self.entity.text(slot::TOTAL_FLOAT)
}
#[must_use]
pub fn predefined_type(&self) -> Option<&'m str> {
match self.entity.attribute(slot::PREDEFINED_TYPE)? {
Value::Enum(token) => Some(token),
_ => None,
}
}
}
#[must_use]
pub fn work_plans(model: &Model) -> Vec<WorkControl<'_>> {
model
.of_type("IFCWORKPLAN")
.filter_map(|(id, entity)| WorkControl::new(id, entity))
.collect()
}
#[must_use]
pub fn work_schedules(model: &Model) -> Vec<WorkControl<'_>> {
model
.of_type("IFCWORKSCHEDULE")
.filter_map(|(id, entity)| WorkControl::new(id, entity))
.collect()
}