Sketch: offer Break Offset Association for offsets of lines (#4899) (#4920)

* claim: #4899

* Sketch: offer Break Offset Association for offsets of lines (#4899)

Trim and Extend refuse an associated offset output and point to Break
Offset Association, but the right-click menu offered it only for
free-form offsets. Offer it whenever the curve is an offset output
(analytic, topology or free-form), using the sketch's shared lookup.
This commit is contained in:
raykholo
2026-10-23 13:44:04 +00:00
committed by GitHub
parent dad28abecf
commit ed6e123d54
+43 -1
View File
@@ -908,7 +908,7 @@ fn sketch_entity_items(app: &SolveApp) -> Vec<Item> {
if !lines.is_empty() {
v.push(cmd(app, "sketch.infinite", "Infinite Line").with(json!({ "curves": lines })));
}
if curves.len() == 1 && ss.sketch.freeform_offsets.iter().any(|offset| offset.output == curves[0]) {
if curves.len() == 1 && ss.sketch.offset_distance(&curves[0]).is_some() {
v.push(cmd(app, "sketch.offset.break", "Break Offset Association").with(json!({"curve":curves[0]})));
}
v.push(act("ui.fix", "Fix/Unfix", "c_fix").with(json!({ "entities": ents })));
@@ -1939,6 +1939,48 @@ pub fn finish_rename(app: &mut SolveApp, text: Option<&str>, commit: bool) -> bo
mod tests {
use super::*;
#[test]
fn line_offset_context_menu_breaks_association_and_allows_trim() {
use solidcraft_engine::{geom::Vec2, sketch::Shape};
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
let source = h.app.run("sketch.line", json!({"points":[[0,0],[20,0]],"connect":false,"infer":false})).unwrap()["curves"][0]
.as_str()
.unwrap()
.to_owned();
let output =
h.app.run("sketch.offset", json!({"curves":[source],"distance":2,"chain":false})).unwrap()["curves"][0].as_str().unwrap().to_owned();
h.app.run("sketch.line", json!({"points":[[10,-5],[10,5]],"connect":false,"infer":false})).unwrap();
let sid = h.app.session.active_sketch.unwrap();
let state = h.app.session.world_state();
let sk = &state.sketch(sid).unwrap().sketch;
let Shape::Line { a, b } = sk.shape(sk.curve_index(&output).unwrap()).unwrap() else { panic!("offset must be a line") };
let cut = Vec2::new(15.0, a.y);
assert!((a.dist(b) - 20.0).abs() < 1e-6);
assert!(h.app.run("sketch.trim", json!({"curve":output,"at":[cut.x,cut.y]})).is_err());
h.call("ui.view", json!({"view":"top"}));
h.app.cam.distance = 60.0;
h.settle();
h.step(&json!({"click":{"world":[cut.x,cut.y,0]},"button":"right"})).unwrap();
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: output.clone() }]);
let menu = items(&h.app, &Target::Viewport);
let item = menu.iter().find(|item| item.id == "sketch.offset.break").expect("offset line must offer Break Offset Association");
assert_eq!(item.label, "Break Offset Association");
assert!(item.enabled);
assert_eq!(item.params, Some(json!({"curve":output})));
h.step(&json!({"click":{"handle":"menu:sketch.offset.break"}})).unwrap();
assert!(h.app.session.world_state().sketch(sid).unwrap().sketch.offset_distance(&output).is_none());
h.app.run("sketch.trim", json!({"curve":output,"at":[cut.x,cut.y]})).unwrap();
let state = h.app.session.world_state();
let sk = &state.sketch(sid).unwrap().sketch;
let remaining = sk.shape(sk.curve_index(&output).unwrap()).unwrap();
assert!(matches!(remaining, Shape::Line { a, b } if (a.dist(b) - 10.0).abs() < 1e-6), "{remaining:?}");
assert!(remaining.dist(cut) > 1.0);
}
#[test]
fn solidworks_face_menu_runs_normal_to_selection_and_rejects_curved_faces() {
let mut h = crate::scenario::Harness::new();