brep_kernel/feature_pipeline/sheet_metal/
mod.rs1pub mod evaluate;
11pub mod flat_pattern;
12pub mod tree;
13
14pub use evaluate::evaluate;
15pub use tree::{Bend, Edge, Flat, Hole, HoleBend, HoleBendKind, SheetTree};
16
17use std::cell::RefCell;
18use std::collections::HashMap;
19
20pub(crate) fn register_folded(tree: SheetTree, name: &str) -> Result<super::AddedSolid, String> {
23 use super::features::common::{collect_edge_names, collect_face_names};
24 let solid = evaluate(&tree, 1.0)?;
25 let face_names = collect_face_names(&solid);
26 let edge_names = collect_edge_names(&solid);
27 let handle = crate::register_solid_value(solid);
28 put_tree(handle, tree);
29 Ok(super::AddedSolid {
30 handle,
31 name: name.to_string(),
32 face_names,
33 edge_names,
34 ..super::AddedSolid::default()
35 })
36}
37
38thread_local! {
39 static SHEET_TREES: RefCell<HashMap<u32, SheetTree>> = RefCell::new(HashMap::new());
42}
43
44pub fn put_tree(handle: u32, tree: SheetTree) {
46 SHEET_TREES.with(|trees| {
47 trees.borrow_mut().insert(handle, tree);
48 });
49}
50
51pub fn get_tree(handle: u32) -> Option<SheetTree> {
53 SHEET_TREES.with(|trees| trees.borrow().get(&handle).cloned())
54}
55
56pub fn remove_tree(handle: u32) {
58 SHEET_TREES.with(|trees| {
59 trees.borrow_mut().remove(&handle);
60 });
61}
62
63pub fn clear_trees() {
66 SHEET_TREES.with(|trees| trees.borrow_mut().clear());
67}
68
69pub fn is_sheet_metal_handle(handle: u32) -> bool {
73 SHEET_TREES.with(|trees| trees.borrow().contains_key(&handle))
74}
75
76pub fn flat_pattern_dxf(handle: u32) -> Result<String, String> {
80 let tree = get_tree(handle)
81 .ok_or_else(|| "flat pattern: handle is not a sheet-metal body".to_string())?;
82 Ok(flat_pattern::to_dxf(&flat_pattern::build(&tree)?))
83}
84
85pub fn flat_pattern_svg(handle: u32) -> Result<String, String> {
88 let tree = get_tree(handle)
89 .ok_or_else(|| "flat pattern: handle is not a sheet-metal body".to_string())?;
90 Ok(flat_pattern::to_svg(&flat_pattern::build(&tree)?))
91}