From 0f77199449613ac4b1bec759f894df098ac39b41 Mon Sep 17 00:00:00 2001 From: dudedagger42 <76926918+dudedagger42@users.noreply.github.com> Date: Mon, 26 Oct 2026 02:32:31 +0000 Subject: [PATCH] Pipe: an Operation row, so a pipe can join, cut or intersect (#2820) (#5169) * Pipe: an Operation row, so a pipe can join, cut or intersect (#2820) The engine's solid.pipe takes an operation, but the Pipe window had no way to choose one, so a pipe always made a new body. The window now has the same Operation row as Loft and the primitives, and editing a pipe keeps its operation. Co-Authored-By: Claude Opus 5.5 * Fit the Pipe operation row to main: sketch-qualified pick, length_input pattern Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: bherbruck --- crates/ui-egui/src/dialogs.rs | 8 +++--- crates/ui-egui/src/dialogs_all_tests.rs | 2 +- crates/ui-egui/src/dialogs_dense.rs | 3 ++- crates/ui-egui/src/length_input.rs | 2 +- crates/ui-egui/src/preselect_tests.rs | 34 +++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index d34d1a274..44083c3b5 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -127,10 +127,11 @@ crate::dialog_descriptor::dialog_descriptors! { margin: String = "2 mm".into() => margin.to_string(), } => json!({"margin": margin}); Pipe("solid.pipe", "PIPE", [("Path", CURVES, true)], - FeatureKind::Pipe { diameter, wall, .. }) { + FeatureKind::Pipe { diameter, wall, operation, .. }) { diameter: String = "5 mm".into() => diameter.to_string(), wall: String = String::new() => wall.as_deref().map(str::to_string).unwrap_or_default(), - } => json!({"diameter": diameter}); + operation: usize = 0 => op_index(operation), + } => json!({"diameter": diameter, "operation": OPS.get(*operation).copied().unwrap_or("new")}); Emboss("solid.emboss", "EMBOSS", [("Profiles", PROFILES, true), ("Target Face (optional)", FACES, false)], FeatureKind::Emboss { depth, deboss, .. }) { depth: String = "1 mm".into() => depth.to_string(), @@ -5349,13 +5350,12 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option) -> Option { + FeatureKind::Pipe { path_sketch, path, targets, .. } => { let mut d = start("solid.pipe")?; d.kind = Kind::simple_restore(&f.kind)?; if let Some(inp) = d.inputs.first_mut() { inp.items = path.iter().map(|id| crate::selection::curve_pick(id, path_sketch.0, s.active_sketch)).collect(); } - d.extra.insert("operation".into(), json!(OPS.get(op_index(operation)).copied().unwrap_or("new"))); if !targets.is_empty() { d.extra.insert("targets".into(), json!(targets)); } diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 20f60f046..6c4b5ab62 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -327,7 +327,7 @@ form_case!(boundary_fill, "solid.boundary_fill", ["Cells", "Operation"]); form_case!(align, "solid.align", ["From Snap", "To Snap"]); form_case!(remove, "solid.remove", []); form_case!(path_pattern, "solid.pattern.path", ["Type", "Object Type", "Quantity", "Spacing"]); -form_case!(pipe, "solid.pipe", ["Diameter", "Wall"]); +form_case!(pipe, "solid.pipe", ["Diameter", "Wall", "Operation"]); form_case!(stock, "solid.bounding_solid", ["Margin"]); form_case!(frame_member, "frame.member", ["All Lines", "Anchor", "Angle", "Mirror", "Name"]); form_case!(thread, "solid.thread", ["Profile", "Size", "Pitch", "Designation"]); diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index 31e4aae62..3e72f8e9c 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -741,9 +741,10 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo enter |= quantity_row(ui, &app.session.doc, "Quantity", count); enter |= expr_row(ui, "Spacing", spacing); } - Kind::Pipe { diameter, wall } => { + Kind::Pipe { diameter, wall, operation } => { enter |= expr_row(ui, "Diameter", diameter); enter |= hint_row(ui, "Wall", wall, tr("solid")); + choice_row(ui, "Operation", "pp_op", operation, &OP_LABELS); } Kind::Stock { margin } => { enter |= expr_row(ui, "Margin", margin); diff --git a/crates/ui-egui/src/length_input.rs b/crates/ui-egui/src/length_input.rs index 68f286d8e..0b671068b 100644 --- a/crates/ui-egui/src/length_input.rs +++ b/crates/ui-egui/src/length_input.rs @@ -100,7 +100,7 @@ pub(crate) fn fields<'a>(doc: &Document, kind: &'a mut crate::dialogs::Kind) -> D::Thread { length, .. } | D::Emboss { depth: length, .. } => vec![length], D::Rib { thickness, depth, .. } => vec![thickness, depth], D::PathPattern { spacing, .. } => vec![spacing], - D::Pipe { diameter, wall } => vec![diameter, wall], + D::Pipe { diameter, wall, .. } => vec![diameter, wall], D::Stock { margin } => vec![margin], D::Move { x, y, z, .. } => vec![x, y, z], D::Hole { diameter, depth, cb_diameter, cb_depth, cs_diameter, .. } => vec![diameter, depth, cb_diameter, cb_depth, cs_diameter], diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rs index 8009ed041..697dd736c 100644 --- a/crates/ui-egui/src/preselect_tests.rs +++ b/crates/ui-egui/src/preselect_tests.rs @@ -2493,3 +2493,37 @@ fn a_loft_from_a_profile_to_a_sketch_point_is_a_pyramid() { let v = solidcraft_engine::doc::kernel::measure(&st.bodies[0].body).unwrap().volume; assert!((v - 4000.0).abs() < 4.0, "{v}"); } + +/// #2820: the Pipe window has an Operation row, so a pipe can cut; editing a cutting pipe keeps +/// its operation. +#[test] +fn a_pipe_cuts_from_its_window_and_keeps_the_cut_when_edited() { + let mut app = app_with(json!([ + {"command": "solid.box", "params": {"corner": [-30, -30, -5], "length": 60, "width": 60, "height": 10}}, + {"command": "sketch.create", "params": {"plane": "XY", "name": "Path"}}, + {"command": "sketch.circle.center", "params": {"center": [0, 0], "radius": 20, "id": "c"}}, + {"command": "sketch.finish", "params": {}}, + ])); + let mut d = start(&mut app, vec![Sel::SketchCurve { id: "c".into(), sketch: None }], "solid.pipe"); + let Kind::Pipe { operation, .. } = &mut d.kind else { panic!("{:?}", d.kind) }; + assert_eq!(*operation, 0, "a pipe makes a new body unless told otherwise"); + *operation = 2; + let cmds = apply_commands(&app, &d).unwrap(); + assert_eq!(cmds[0].1["operation"], "cut", "{:?}", cmds[0].1); + let volume = |app: &SolveApp| { + let st = app.session.world_state(); + assert_eq!(st.bodies.len(), 1, "one body: {:?}", st.bodies.iter().map(|b| &b.name).collect::>()); + solidcraft_engine::doc::kernel::measure(&st.bodies[0].body).unwrap().volume + }; + let before = volume(&app); + for (cmd, p) in cmds { + app.run(&cmd, p).unwrap(); + } + assert!(volume(&app) < before - 1.0, "the pipe cut a groove into the box"); + let pipe = app.session.doc.features.last().unwrap().id; + let d = crate::dialogs::for_feature(&app, pipe, None).unwrap(); + assert!(matches!(d.kind, Kind::Pipe { operation: 2, .. }), "{:?}", d.kind); + let (edit, p) = apply_commands(&app, &d).unwrap().remove(0); + assert_eq!(edit, "timeline.redefine"); + assert_eq!(p["params"]["operation"], "cut", "{p}"); +}