diff --git a/crates/engine/src/cmd/drawing_tests.rs b/crates/engine/src/cmd/drawing_tests.rs index 2ae026793..cd1510e01 100644 --- a/crates/engine/src/cmd/drawing_tests.rs +++ b/crates/engine/src/cmd/drawing_tests.rs @@ -1805,3 +1805,59 @@ fn sheet_reviewer_coincident_lines_join_only_their_local_endpoints() { run(&mut s, "edit.redo", json!({})); assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after); } + +/// R14: read-only curve selection and solve reports share the exact sheet receiver. +#[test] +fn sheet_reviewer_chain_and_solve_are_paper_owned_read_only_queries() { + let (mut s, drawing, sketch, made) = sheet_editor(); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [15, 10], "p1": [55, 30]})); + let before = s.doc.clone(); + let model = s.model.state(); + let entry = s.active_sheet_sketch.clone(); + let history = (s.undo.len(), s.redo.len(), s.evaluations); + let inspected = run(&mut s, "drawing.sketch.inspect", json!({})); + + let chain = run(&mut s, "sketch.chain", json!({"sketch": made["sketch"], "curve": "l1"})); + let ids = chain["curves"].as_array().unwrap(); + assert_eq!(ids.len(), 4, "the rectangle is one sheet-local connected chain: {chain}"); + assert!(ids.iter().any(|id| id == "l1")); + let solved = run(&mut s, "sketch.solve", json!({"sketch": made["sketch"]})); + assert_eq!(solved["profiles"], 1, "the existing profile finder sees one paper rectangle: {solved}"); + assert_eq!(solved["dof"], inspected["dof"], "inspection and solve use the same paper sketch"); + assert!(!solved["status"].is_null(), "the actual solver status must be reported"); + + assert!(Arc::ptr_eq(&s.doc, &before), "neither read-only command publishes a drawing"); + assert!(Arc::ptr_eq(&s.model.state(), &model), "neither query evaluates the model"); + assert_eq!(s.active_sheet_sketch, entry); + assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), history); + assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.len(), 4); +} + +/// R14: no implicit switch to a similarly named model sketch or another sheet. +#[test] +fn sheet_reviewer_chain_and_solve_refuse_foreign_or_missing_targets_atomically() { + let (mut s, drawing, sketch, _) = sheet_editor(); + run(&mut s, "sketch.line", json!({"points": [[10, 10], [30, 20]], "ids": ["only_sheet_line"]})); + let before = s.doc.clone(); + let model = s.model.state(); + let entry = s.active_sheet_sketch.clone(); + let history = (s.undo.len(), s.redo.len(), s.evaluations); + for (command, params) in [ + ("sketch.chain", json!({"sketch": ids::encode(drawing), "curve": "only_sheet_line"})), + ("sketch.chain", json!({"sketch": "not-an-id", "curve": "only_sheet_line"})), + ("sketch.chain", json!({"curve": "no_such_curve"})), + ("sketch.solve", json!({"sketch": ids::encode(drawing)})), + ("sketch.solve", json!({"sketch": -1})), + ("sketch.solve", json!({"sketch": true})), + ] { + refused(&mut s, command, params.clone()); + assert!(Arc::ptr_eq(&s.doc, &before), "{command}: {params}"); + assert!(Arc::ptr_eq(&s.model.state(), &model), "{command}: {params}"); + assert_eq!(s.active_sheet_sketch, entry, "{command}: {params}"); + assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), history, "{command}: {params}"); + } + assert_eq!(run(&mut s, "sketch.chain", json!({"curve": "only_sheet_line"}))["curves"], json!(["only_sheet_line"])); + assert_eq!(run(&mut s, "sketch.solve", json!({}))["profiles"], 0); + assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.len(), 1); + assert!(Arc::ptr_eq(&s.doc, &before)); +} diff --git a/crates/engine/src/cmd/sketch.rs b/crates/engine/src/cmd/sketch.rs index 69790f728..7e60b2145 100644 --- a/crates/engine/src/cmd/sketch.rs +++ b/crates/engine/src/cmd/sketch.rs @@ -224,11 +224,11 @@ pub static COMMANDS: &[CommandSpec] = &[ CommandSpec::new("sketch.options", "Sketch Palette Options", sketch_options).icon("sketch").params( "sketch?: id|name (default active); any of show_profile, show_points, show_dimensions, show_constraints, show_projected, show_construction, grid, snap, slice, sketch_3d: bool. Returns them all", ), - CommandSpec::new("sketch.chain", "Chain", chain_cmd).icon("chain") + CommandSpec::new("sketch.chain", "Chain", chain_cmd).in_sketch_part().icon("chain") .enabled(in_sketch) .noundo() .params("curve: id: the curves joined to it end to end (what a double-click selects)"), - CommandSpec::new("sketch.solve", "Solve Sketch", solve_cmd).icon("compute") + CommandSpec::new("sketch.solve", "Solve Sketch", solve_cmd).in_sketch_part().icon("compute") .enabled(in_sketch) .noundo() .params("reports the solver status and degrees of freedom"), @@ -2844,14 +2844,25 @@ fn sketch_options(s: &mut Session, p: &Value) -> Result { fn chain_cmd(s: &mut Session, p: &Value) -> Result { let cmd = "sketch.chain"; - let id = sketch_store::target(s, p, cmd)?; - let sk = sketch_store::read(&s.doc, id)?; - let c = curve_ref(sk, p.get("curve"), cmd, "curve")?; - Ok(json!({"curves": ids_of(sk, &sk.chain(c))})) + let sk = sketch_store::read_for_command(s, p, cmd)?; + let c = curve_ref(&sk, p.get("curve"), cmd, "curve")?; + Ok(json!({"curves": ids_of(&sk, &sk.chain(c))})) } fn solve_cmd(s: &mut Session, p: &Value) -> Result { - let id = sketch_store::target(s, p, "sketch.solve")?; + let cmd = "sketch.solve"; + if s.open_drawing.is_some() { + let entry = sketch_store::sheet_target(s, p, cmd)?; + let solved = s.drawing(cmd)?.solve_sheet_sketch(&s.doc, entry.sketch)?; + let profiles = solidcraft_sketch::find_drawn_profiles(&solved.sketch).len(); + return Ok(json!({ + "status": solved.report.status, + "dof": solved.report.dof, + "failing": solved.report.failing, + "profiles": profiles, + })); + } + let id = sketch_store::target(s, p, cmd)?; let st = s.model.state(); let ss = st.sketch(id).ok_or_else(|| EngineError::Other("the sketch has not been evaluated".into()))?; Ok(json!({"status": ss.report.status, "dof": ss.report.dof, "failing": ss.report.failing, "profiles": ss.profiles.len()})) diff --git a/docs/drawing-sheet-sketches.md b/docs/drawing-sheet-sketches.md index 30b278296..61981ce62 100644 --- a/docs/drawing-sheet-sketches.md +++ b/docs/drawing-sheet-sketches.md @@ -460,3 +460,28 @@ local entities. Their executed results and the exact tested commit belong in the PR. This does **not** complete sheet sketch driving dimensions, model projection, sheet editor UI, all-tool parity, canonical model/sheet Cancel composition or the full repository CI gate. + +### W38a R14: read-only chain selection and solve reports + +The existing `sketch.chain` and `sketch.solve` commands now accept the active +sheet-sketch receiver, without adding command ids or changing model-sketch +behavior. Both use the same sketch-part gate as the geometry tools: with a +drawing open, an exact active drawing/sheet/sketch entry is required. Explicit +`sketch` inputs may only confirm that entry; an absent, invalid or foreign +owner is never resolved as a model feature. + +`sketch.chain` reads a solved paper sketch through the shared command store and +uses the original connected-curve selection algorithm. `sketch.solve` reads the +same drawing-owned record through its existing read-only solve boundary and +reports status, degrees of freedom, failed constraints and a bounded profile +count from the shared drawn-profile finder. Neither query publishes the solved +geometry, changes a source parameter, triggers model evaluation or creates a +drawing undo step. Invalid local curves and wrong owners fail without mutation. + +Existing engine regressions and two new sheet-specific cases distinguish the +model receiver from paper-owned queries, including profile counts, no-op +history, source-model state and cross-owner refusals. This only enables +**command-level inspection**. The native/browser pointer-driven Drawing +workspace, canvas selection, ownership-aware event routing and visual +acceptance remain with the agreed UI integration work; these two commands +alone do not make a sheet sketch editable through the GUI.