Drawing: qualify fix and symmetry sheet constraints (#7082)

This commit is contained in:
lillith committed 2026-10-28 07:37:45 +01:00
1 parent 24ad198407
commit 0e897e670b
3 files changed
+116

No files matched your search

+94
View File
@@ -1472,3 +1472,97 @@ fn sheet_reviewer_constraints_refuse_cross_owner_targets_atomically() {
assert_eq!(s.doc.drawing(d).unwrap().sheet_sketch(sk).unwrap().sketch.curves.len(), 1);
}
}
// W38a R10: qualify existing fix/unfix and symmetry through the shared sheet store.
#[test]
fn sheet_reviewer_fix_and_symmetry_keep_model_and_drawing_history_separate() {
use solidcraft_sketch::ConstraintKind;
let (mut s, drawing, sketch, _) = sheet_editor();
run(&mut s, "sketch.point", json!({"point":[30,40],"id":"held"}));
let original_source = s.doc.clone();
let model = s.model.state();
let (undo, evaluated) = (s.undo.len(), s.evaluations);
let before = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
let fixed = run(&mut s, "sketch.constraint.fix", json!({"entity":"held","fixed":true}));
assert_eq!(fixed["result"]["fixed"], true);
assert_eq!(fixed["result"]["changed"], 1);
let after = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
let index = after.resolve_point("held").unwrap();
assert!(after.constraints.iter().any(|c| matches!(c.kind, ConstraintKind::Fix { p } if p == index)));
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (undo + 1, Some(drawing)));
assert_eq!((&s.doc.features, &s.doc.params), (&original_source.features, &original_source.params));
assert!(Arc::ptr_eq(&s.model.state(), &model));
assert_eq!(s.evaluations, evaluated);
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, before);
run(&mut s, "edit.redo", json!({}));
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after);
let saved = s.doc.to_json();
let reopened = solidcraft_doc::Document::from_json(&saved).unwrap();
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after);
let released = run(&mut s, "sketch.constraint.fix", json!({"entity":"held","fixed":false}));
assert_eq!(released["result"]["fixed"], false);
assert_eq!(released["result"]["changed"], 1);
let unfixed = &s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch;
assert!(!unfixed.constraints.iter().any(|c| matches!(c.kind, ConstraintKind::Fix { p } if p == index)));
let (mut s, drawing, sketch, _) = sheet_editor();
run(&mut s, "sketch.line", json!({"points":[[50,0],[50,100]],"ids":["axis"]}));
run(&mut s, "sketch.point", json!({"point":[30,40],"id":"a"}));
run(&mut s, "sketch.point", json!({"point":[75,43],"id":"b"}));
let source = s.doc.clone();
let model = s.model.state();
let (undo, evaluated) = (s.undo.len(), s.evaluations);
let before = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
let result = run(&mut s, "sketch.constraint.symmetry", json!({"a":"a","b":"b","line":"axis"}));
assert_eq!(result["constraints"].as_array().unwrap().len(), 1);
let after = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
let pa = after.point(after.resolve_point("a").unwrap()).unwrap();
let pb = after.point(after.resolve_point("b").unwrap()).unwrap();
let axis = after.curve_index("axis").unwrap();
let solidcraft_sketch::CurveKind::Line { a, b } = after.curves[axis].kind else { panic!("missing symmetry axis") };
let p0 = after.point(a).unwrap();
let direction = after.point(b).unwrap() - p0;
let length = direction.len();
assert!(length > 1.0);
assert!((((pa + pb) * 0.5 - p0).cross(direction) / length).abs() < 1e-4);
assert!(((pb - pa).dot(direction) / length).abs() < 1e-4);
assert!(after.constraints.iter().any(|c| matches!(c.kind, ConstraintKind::Symmetric { .. })));
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (undo + 1, Some(drawing)));
assert_eq!((&s.doc.features, &s.doc.params), (&source.features, &source.params));
assert!(Arc::ptr_eq(&s.model.state(), &model));
assert_eq!(s.evaluations, evaluated);
run(&mut s, "edit.undo", json!({}));
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, before);
run(&mut s, "edit.redo", json!({}));
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after);
let saved = s.doc.to_json();
let reopened = solidcraft_doc::Document::from_json(&saved).unwrap();
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after);
}
#[test]
fn sheet_reviewer_fix_and_symmetry_refuse_foreign_targets_atomically() {
let (mut s, drawing, sketch, _) = sheet_editor();
run(&mut s, "sketch.line", json!({"points":[[50,0],[50,100]],"ids":["axis"]}));
run(&mut s, "sketch.point", json!({"point":[30,40],"id":"a"}));
run(&mut s, "sketch.point", json!({"point":[75,43],"id":"b"}));
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, args) in [
("sketch.constraint.fix", json!({"sketch":-1,"entity":"a","fixed":true})),
("sketch.constraint.symmetry", json!({"sketch":-1,"a":"a","b":"b","line":"axis"})),
("sketch.constraint.fix", json!({"entity":"foreign","fixed":true})),
("sketch.constraint.symmetry", json!({"a":"a","b":"b","line":"foreign"})),
] {
refused(&mut s, command, args);
assert!(Arc::ptr_eq(&s.doc, &before), "{command}");
assert!(Arc::ptr_eq(&s.model.state(), &model), "{command}");
assert_eq!(s.active_sheet_sketch, entry, "{command}");
assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), history, "{command}");
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.len(), 1);
}
}
+2
View File
@@ -171,6 +171,7 @@ pub static COMMANDS: &[CommandSpec] = &[
.enabled(in_sketch)
.params("a, b: lines or sketch axes (x / y: the sketch's own axes, unless a curve has that id; an axis becomes a linked construction line on it, reported in created)"),
CommandSpec::new("sketch.constraint.fix", "Fix/UnFix", c_fix)
.in_sketch_part()
.at("SKETCH", "CONSTRAINTS")
.icon("c_fix")
.enabled(in_sketch)
@@ -194,6 +195,7 @@ pub static COMMANDS: &[CommandSpec] = &[
.enabled(in_sketch)
.params("a, b: lines or sketch axes (x / y: the sketch's own axes, unless a curve has that id; an axis becomes a linked construction line on it, reported in created)"),
CommandSpec::new("sketch.constraint.symmetry", "Symmetry", c_symmetry)
.in_sketch_part()
.at("SKETCH", "CONSTRAINTS")
.icon("c_symmetry")
.enabled(in_sketch)
+20
View File
@@ -375,3 +375,23 @@ drawing-only undo/redo and file reopening, and atomic refusal of a model
target. This does not qualify other constraint commands, interactive
snap/picking, drawing-owned dimensions, the native/browser editor or the
full workspace CI suite.
### R10: fixing sheet geometry and point/axis symmetry
The existing sketch.constraint.fix and sketch.constraint.symmetry commands
now use the same exact sheet target, shared sketch implementation and solver as
the admitted constraints above. Fix/unfix changes only the selected sheet
sketch's point constraints or curve fixed state. Symmetry uses the sketcher's
existing point/axis and curve mirroring logic; it does not construct a second
geometry engine or a model feature.
Both commands publish only through Session::edit_drawing, with one drawing
undo step per changed command. Incorrect sketch ids, unknown local entities or
an absent editing boundary fail without changing the source design or drawing
history. Analytic point/line symmetry and fix/unfix, undo/redo, isolation and
JSON save/reopen cases live in the existing engine Drawing tests.
This is not shared annotation dimension support, pointer-driven UI integration,
canonical sketch.cancel composition or full native/browser acceptance.
Those remain separate dependencies and deliverables.