@@ -0,0 +1,23 @@
|
||||
{
|
||||
"en": {
|
||||
"ui.perforate_margin_default": "from the diameter",
|
||||
"ui.perforate_pitch": "Pitch",
|
||||
"ui.perforate_square": "Square",
|
||||
"ui.perforate_staggered": "Staggered (60°)",
|
||||
"ui.perforate_title": "PERFORATE"
|
||||
},
|
||||
"ja": {
|
||||
"ui.perforate_margin_default": "直径と同じ",
|
||||
"ui.perforate_pitch": "ピッチ",
|
||||
"ui.perforate_square": "正方配列",
|
||||
"ui.perforate_staggered": "千鳥配列(60°)",
|
||||
"ui.perforate_title": "パーフォレーション"
|
||||
},
|
||||
"zh": {
|
||||
"ui.perforate_margin_default": "与直径相同",
|
||||
"ui.perforate_pitch": "孔距",
|
||||
"ui.perforate_square": "正方形排列",
|
||||
"ui.perforate_staggered": "交错排列(60°)",
|
||||
"ui.perforate_title": "穿孔"
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,12 @@ use solidcraft_engine::geom::{Vec2, Vec3};
|
||||
|
||||
use crate::SolveApp;
|
||||
use crate::dialogs::{Dialog, Kind, edge_sel, face_sel, form_row, profile_indices};
|
||||
use crate::selection::{AXES, BODIES, CURVES, EDGES, PLANAR_FACES, PROFILES, SelInput, SelectionExt as _, items, point_value as pt};
|
||||
use crate::selection::{AXES, BODIES, CURVES, EDGES, FACES, PLANAR_FACES, PROFILES, SelInput, SelectionExt as _, items, point_value as pt};
|
||||
use crate::theme::Tokens;
|
||||
|
||||
const PERFORATION_PATTERNS: [&str; 2] = ["staggered", "square"];
|
||||
const PERFORATION_LABELS: [&str; 2] = ["ui.perforate_staggered", "ui.perforate_square"];
|
||||
|
||||
const FOLD_POSITIONS: [&str; 4] = ["centerline", "start", "end", "mould"];
|
||||
const FOLD_POSITION_LABELS: [&str; 4] = ["Centerline", "Start of Bend", "End of Bend", "Outside Mould Line"];
|
||||
const FLANGE_TYPES: [&str; 3] = ["Base", "Edge", "Contour"];
|
||||
@@ -53,6 +56,13 @@ const FLANGE_RELIEF_LABELS: [&str; 5] = ["Rule", "Notch", "Round", "Rectangular"
|
||||
crate::dialog_descriptor::dialog_descriptors! {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Sm {
|
||||
Perforate("sheet.perforate", "ui.perforate_title", [("Body (last if none)", BODIES | FACES, false)],
|
||||
FeatureKind::SheetPerforate { diameter, pitch, margin, pattern, .. }) {
|
||||
diameter: String = "3 mm".into() => diameter.to_string(),
|
||||
pitch: String = "6 mm".into() => pitch.to_string(),
|
||||
margin: String = String::new() => margin.as_deref().map(str::to_string).unwrap_or_default(),
|
||||
pattern: usize = 0 => pattern.as_deref().and_then(|p| PERFORATION_PATTERNS.iter().position(|x| *x == p)).unwrap_or(0),
|
||||
} => json!({"diameter": diameter, "pitch": pitch, "pattern": PERFORATION_PATTERNS.get(*pattern).copied().unwrap_or("staggered")});
|
||||
Hem("sheet.hem", "HEM", [("Edges", EDGES, true)],
|
||||
FeatureKind::SheetHem { length, gap, flip, .. }) {
|
||||
length: String = "5 mm".into() => length.to_string(),
|
||||
@@ -320,6 +330,12 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Sm, inputs: &mut [Sel
|
||||
crate::ui_kit::options(ui, "sheet_options", &mut [("Flip", flip)]);
|
||||
}
|
||||
}
|
||||
Sm::Perforate { diameter, pitch, margin, pattern } => {
|
||||
enter |= expr_row(ui, "ui.diameter", diameter);
|
||||
enter |= expr_row(ui, "ui.perforate_pitch", pitch);
|
||||
enter |= hint_row(ui, "Margin", margin, crate::i18n::tr_label("ui.perforate_margin_default"));
|
||||
choice_row(ui, "Pattern", "sm_perforate_pattern", pattern, &PERFORATION_LABELS);
|
||||
}
|
||||
Sm::Hem { length, gap, flip } => {
|
||||
form_row(ui, "Type", |ui| {
|
||||
ui.label(crate::i18n::tr_label("Flat"));
|
||||
@@ -719,6 +735,16 @@ pub fn commands(app: &SolveApp, k: &Sm, inputs: &[SelInput], extra: &Map<String,
|
||||
put(&mut p, &[("radius", radius)]);
|
||||
("sheet.path_flange", p)
|
||||
}
|
||||
Sm::Perforate { margin, .. } => {
|
||||
let mut p = json!({});
|
||||
put(&mut p, &[("margin", margin)]);
|
||||
match items(inputs, 0).first() {
|
||||
Some(Sel::Body { name }) => p["body"] = json!(name),
|
||||
Some(Sel::Face { body, .. }) => p["body"] = json!(body),
|
||||
_ => {}
|
||||
}
|
||||
("sheet.perforate", p)
|
||||
}
|
||||
Sm::Unfold { refold } => {
|
||||
let mut p = json!({});
|
||||
if let Some(Sel::Body { name }) = items(inputs, 0).first() {
|
||||
@@ -870,6 +896,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
}
|
||||
return Some((Kind::Sheet(k), ins, extra));
|
||||
}
|
||||
FeatureKind::SheetPerforate { body, .. } => (Sm::simple_restore(kind)?, body.iter().map(|n| Sel::Body { name: n.to_string() }).collect()),
|
||||
FeatureKind::SheetUnfold { body, refold } => {
|
||||
(Sm::Unfold { refold: *refold }, body.iter().map(|n| Sel::Body { name: n.to_string() }).collect())
|
||||
}
|
||||
@@ -888,6 +915,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
let id = match &k {
|
||||
Sm::Flange { .. } => "sheet.flange",
|
||||
Sm::Hem { .. } => "sheet.hem",
|
||||
Sm::Perforate { .. } => "sheet.perforate",
|
||||
Sm::Unfold { refold: false } => "sheet.unfold",
|
||||
Sm::Unfold { .. } => "sheet.refold",
|
||||
_ => "sheet.convert",
|
||||
|
||||
@@ -1222,3 +1222,72 @@ fn inch_sheet_rule_edit_preserves_stored_lengths_and_dimensionless_k_factor() {
|
||||
assert_eq!(changed["thickness"], json!("0.125 in"));
|
||||
assert_eq!(changed["k_factor"], unchanged["k_factor"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn perforate_toolbar_opens_without_running_empty_parameters() {
|
||||
for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] {
|
||||
let mut app = plate(mode);
|
||||
app.run("sheet.flange", json!({"sketch": "Base"})).unwrap();
|
||||
let features = app.session.doc.features.len();
|
||||
app.start("sheet.perforate");
|
||||
let dialog = app.dialog.as_ref().expect("Perforate opens a dialog");
|
||||
assert!(dialog.previews());
|
||||
assert_eq!(app.session.doc.features.len(), features);
|
||||
assert!(!app.status.as_ref().is_some_and(|(_, _, error)| *error));
|
||||
let commands = apply_commands(&app, dialog).unwrap();
|
||||
assert_eq!(commands[0].0, "sheet.perforate");
|
||||
assert_eq!(commands[0].1["diameter"], "3 mm");
|
||||
assert_eq!(commands[0].1["pitch"], "6 mm");
|
||||
assert_eq!(commands[0].1["pattern"], "staggered");
|
||||
assert!(commands[0].1.get("margin").is_none());
|
||||
let mut dialog = dialog.clone();
|
||||
let ctx = crate::fonts::test_context();
|
||||
let output = crate::test_support::frame(&ctx, egui::RawInput::default(), |ui| {
|
||||
if let Kind::Sheet(k) = &mut dialog.kind {
|
||||
rows(&mut app, ui, k, &mut dialog.inputs);
|
||||
}
|
||||
});
|
||||
let texts: Vec<_> = crate::test_support::text_shapes(&output).map(|text| text.galley.text()).collect();
|
||||
for label in ["Diameter", "Pitch", "Margin", "Pattern", "Staggered (60°)", "3 mm", "6 mm", "from the diameter"] {
|
||||
assert!(texts.contains(&label), "missing field or default: {label}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn perforate_ok_targets_the_picked_sheet_and_updates_flat_data() {
|
||||
for face in [false, true] {
|
||||
let mut app = plate(crate::shell::LayoutMode::Docked);
|
||||
app.run("sheet.flange", json!({"sketch": "Base"})).unwrap();
|
||||
let body = app.session.model.state().sheets[0].body.clone();
|
||||
app.session.selection =
|
||||
vec![if face { face_sel(&app.session, Vec3::new(50.0, 30.0, 2.5)).unwrap() } else { Sel::Body { name: body.clone() } }];
|
||||
app.start("sheet.perforate");
|
||||
let dialog = app.dialog.as_ref().expect("Perforate opens a dialog");
|
||||
let commands = apply_commands(&app, dialog).unwrap();
|
||||
assert_eq!(commands[0].1["body"], body);
|
||||
run_all(&mut app, commands);
|
||||
let flat = app.session.execute("sheet.flat_pattern", &json!({"body": body})).unwrap();
|
||||
let field = &flat["perforations"][0];
|
||||
assert_eq!(field["diameter"], 3.0);
|
||||
assert_eq!(field["pitch"], 6.0);
|
||||
assert_eq!(field["margin"], 3.0);
|
||||
assert!(field["count"].as_u64().unwrap() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn perforate_edit_restores_dimensions_pattern_and_target() {
|
||||
let mut app = plate(crate::shell::LayoutMode::Docked);
|
||||
app.run("sheet.flange", json!({"sketch": "Base"})).unwrap();
|
||||
let body = app.session.model.state().sheets[0].body.clone();
|
||||
app.run("sheet.perforate", json!({"body": body, "diameter": "4 mm", "pitch": "9 mm", "margin": "5 mm", "pattern": "square"})).unwrap();
|
||||
let feature = app.session.doc.features.last().unwrap();
|
||||
let dialog = edit_dialog(&app, feature.id, None).expect("Perforate can be edited");
|
||||
let commands = apply_commands(&app, &dialog).unwrap();
|
||||
assert_eq!(commands[0].0, "timeline.redefine");
|
||||
let params = &commands[0].1["params"];
|
||||
for (key, value) in [("body", body.as_str()), ("diameter", "4 mm"), ("pitch", "9 mm"), ("margin", "5 mm"), ("pattern", "square")] {
|
||||
assert_eq!(params[key], value, "{key} is restored");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user