use crate::model::*;
use microcad_lang_base::SrcRef;
#[derive(Default)]
pub struct ModelBuilder {
root: ModelInner,
pub properties: Properties,
pub children: Models,
}
impl ModelBuilder {
pub fn new(element: Element, src_ref: SrcRef) -> Self {
Self {
root: ModelInner::new(element, src_ref),
..Default::default()
}
}
pub fn add_children(mut self, mut children: Models) -> Self {
self.children.append(&mut children);
self
}
pub fn attributes(mut self, attributes: Attributes) -> Self {
self.root.attributes = attributes;
self
}
pub fn properties(mut self, properties: Properties) -> Self {
self.properties = properties;
self
}
pub fn build(mut self) -> Model {
if let Element::Workpiece(workpiece) = &mut self.root.element.value {
workpiece.add_properties(self.properties);
}
let model = Model::new(self.root.into());
model.append_children(self.children);
model.deduce_output_type();
model
}
}
impl std::fmt::Display for ModelBuilder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.properties)
}
}