pub mod evaluate;
pub mod flat_pattern;
pub mod tree;
pub use evaluate::evaluate;
pub use tree::{Bend, Edge, Flat, Hole, HoleBend, HoleBendKind, SheetTree};
use std::cell::RefCell;
use std::collections::HashMap;
pub(crate) fn register_folded(tree: SheetTree, name: &str) -> Result<super::AddedSolid, String> {
use super::features::common::{collect_edge_names, collect_face_names};
let solid = evaluate(&tree, 1.0)?;
let face_names = collect_face_names(&solid);
let edge_names = collect_edge_names(&solid);
let handle = crate::register_solid_value(solid);
put_tree(handle, tree);
Ok(super::AddedSolid {
handle,
name: name.to_string(),
face_names,
edge_names,
..super::AddedSolid::default()
})
}
thread_local! {
static SHEET_TREES: RefCell<HashMap<u32, SheetTree>> = RefCell::new(HashMap::new());
}
pub fn put_tree(handle: u32, tree: SheetTree) {
SHEET_TREES.with(|trees| {
trees.borrow_mut().insert(handle, tree);
});
}
pub fn get_tree(handle: u32) -> Option<SheetTree> {
SHEET_TREES.with(|trees| trees.borrow().get(&handle).cloned())
}
pub fn remove_tree(handle: u32) {
SHEET_TREES.with(|trees| {
trees.borrow_mut().remove(&handle);
});
}
pub fn clear_trees() {
SHEET_TREES.with(|trees| trees.borrow_mut().clear());
}
pub fn is_sheet_metal_handle(handle: u32) -> bool {
SHEET_TREES.with(|trees| trees.borrow().contains_key(&handle))
}
pub fn flat_pattern_dxf(handle: u32) -> Result<String, String> {
let tree = get_tree(handle)
.ok_or_else(|| "flat pattern: handle is not a sheet-metal body".to_string())?;
Ok(flat_pattern::to_dxf(&flat_pattern::build(&tree)?))
}
pub fn flat_pattern_svg(handle: u32) -> Result<String, String> {
let tree = get_tree(handle)
.ok_or_else(|| "flat pattern: handle is not a sheet-metal body".to_string())?;
Ok(flat_pattern::to_svg(&flat_pattern::build(&tree)?))
}