Drawing: reuse bounded 2D sketch tools on sheets (#7082)
This commit is contained in:
1 parent
d3b7cfcf6f
commit
80e5bb3470
6 files changed
+516
-39
No files matched your search
@@ -2056,3 +2056,366 @@ fn sheet_reviewer_driving_dimension_rejects_invalid_inputs_without_publication()
|
||||
assert!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.constraints.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
/// W38a R17: the existing 2D edit commands are paper-owned transactions, not model edits.
|
||||
#[test]
|
||||
fn sheet_batch_move_scale_break_trim_and_drag_publish_only_the_selected_drawing() {
|
||||
for command in ["sketch.move", "sketch.scale", "sketch.break", "sketch.trim", "sketch.drag"] {
|
||||
let (mut s, drawing, sketch, made) = sheet_editor();
|
||||
let line = run(
|
||||
&mut s,
|
||||
"sketch.line",
|
||||
json!({
|
||||
"points": [[15, 20], [55, 20]], "connect": false, "infer": false
|
||||
}),
|
||||
)["curves"][0]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let params = match command {
|
||||
"sketch.move" => json!({"entities": [line], "translate": [8, 3]}),
|
||||
"sketch.scale" => json!({"entities": [line], "base": [0, 0], "factor": 1.5}),
|
||||
"sketch.break" => json!({"curve": line, "points": [[35, 20]]}),
|
||||
"sketch.trim" => json!({"curve": line, "at": [35, 20]}),
|
||||
"sketch.drag" => json!({"entity": line, "from": [35, 20], "to": [42, 26]}),
|
||||
_ => {
|
||||
assert!(command.is_empty(), "unexpected 2D test command: {command}");
|
||||
Value::Null
|
||||
}
|
||||
};
|
||||
let before = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
|
||||
let source = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let history = s.undo.len();
|
||||
let evals = s.evaluations;
|
||||
let result = run(&mut s, command, params);
|
||||
assert!(result["sketch"].is_object(), "{command}: {result}");
|
||||
let after = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
|
||||
assert_ne!(after, before, "{command} must modify the selected sheet");
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (history + 1, Some(drawing)), "{command}");
|
||||
assert_eq!((&s.doc.features, &s.doc.params), (&source.features, &source.params), "{command}");
|
||||
assert!(Arc::ptr_eq(&model, &s.model.state()), "{command}");
|
||||
assert_eq!(s.evaluations, evals, "{command}");
|
||||
assert_eq!(s.active_sheet_sketch.as_ref().unwrap().sketch, sketch, "{command}");
|
||||
assert_eq!(run(&mut s, "drawing.sketch.inspect", json!({}))["sketch"], made["sketch"]);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, before, "{command}");
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after, "{command}");
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, after, "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// One modify command that looks at the other curves must not borrow a model sketch.
|
||||
#[test]
|
||||
fn sheet_batch_extend_and_path_trim_keep_paper_geometry_without_model_pruning() {
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
s.doc_mut().new_model_param("10 mm", "mm");
|
||||
run(&mut s, "sketch.line", json!({"points": [[30, 5], [30, 45]], "connect": false, "infer": false}));
|
||||
let extending = run(&mut s, "sketch.line", json!({"points": [[5, 25], [15, 25]], "connect": false, "infer": false}))["curves"][0]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let snapshot = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let before_steps = s.undo.len();
|
||||
let extended = run(&mut s, "sketch.extend", json!({"curve": extending, "at": [15, 25]}));
|
||||
assert!(extended["sketch"].is_object());
|
||||
let updated = &s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch;
|
||||
let end = updated.point(updated.resolve_point(&format!("{extending}.end")).unwrap()).unwrap();
|
||||
assert!((end.x - 30.0).abs() < 1e-6 && (end.y - 25.0).abs() < 1e-6, "{end:?}");
|
||||
assert_eq!((&s.doc.params, &s.doc.features), (&snapshot.params, &snapshot.features));
|
||||
assert!(Arc::ptr_eq(&model, &s.model.state()));
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (before_steps + 1, Some(drawing)));
|
||||
|
||||
let before_trim = s.doc.clone();
|
||||
let history = s.undo.len();
|
||||
let trimmed = run(&mut s, "sketch.trim.path", json!({"points": [[20, 15], [40, 15]]}));
|
||||
assert!(trimmed["trimmed"].as_array().is_some_and(|a| !a.is_empty()), "{trimmed}");
|
||||
assert_eq!((&s.doc.params, &s.doc.features), (&snapshot.params, &snapshot.features));
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (history + 1, Some(drawing)));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(
|
||||
s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch,
|
||||
before_trim.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch
|
||||
);
|
||||
}
|
||||
|
||||
/// Existing fillet/chamfer geometry must use an authored sheet expression, never a model param.
|
||||
#[test]
|
||||
fn sheet_batch_fillet_chamfer_and_rounded_rectangle_are_drawing_local() {
|
||||
for command in
|
||||
["sketch.fillet", "sketch.chamfer.equal_distance", "sketch.chamfer.two_distance", "sketch.chamfer.distance_angle", "sketch.rectangle.rounded"]
|
||||
{
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
s.doc_mut().set_param("Inset", "1", Some("in"), None).unwrap();
|
||||
let before = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let evals = s.evaluations;
|
||||
let result = if command == "sketch.rectangle.rounded" {
|
||||
run(&mut s, command, json!({"p0": [20, 20], "p1": [90, 60], "radius": "Inset / 5"}))
|
||||
} else {
|
||||
let sides = run(&mut s, "sketch.rectangle.two_point", json!({"p0": [20, 20], "p1": [90, 60]}))["curves"].as_array().unwrap().clone();
|
||||
let mut request = json!({"a": sides[0], "b": sides[1]});
|
||||
match command {
|
||||
"sketch.fillet" => request["radius"] = json!("Inset / 5"),
|
||||
"sketch.chamfer.equal_distance" => request["distance"] = json!(4),
|
||||
"sketch.chamfer.two_distance" => {
|
||||
request["distance"] = json!(3);
|
||||
request["distance2"] = json!(4);
|
||||
}
|
||||
"sketch.chamfer.distance_angle" => {
|
||||
request["distance"] = json!(4);
|
||||
request["angle"] = json!(45);
|
||||
}
|
||||
_ => assert!(command.is_empty(), "unexpected corner test command: {command}"),
|
||||
};
|
||||
run(&mut s, command, request)
|
||||
};
|
||||
assert!(result["curves"].is_array(), "{command}: {result}");
|
||||
let saved = &s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch;
|
||||
assert!(saved.curves.len() >= 5, "{command}");
|
||||
if command == "sketch.fillet" || command == "sketch.rectangle.rounded" {
|
||||
assert_eq!(result["param"], Value::Null, "{command}: no model parameter");
|
||||
assert_eq!(result["expression"], "Inset / 5", "{command}");
|
||||
assert!(saved.constraints.iter().any(|c| c.param.as_deref() == Some("Inset / 5")), "{command}");
|
||||
}
|
||||
assert_eq!((&s.doc.features, &s.doc.params), (&before.features, &before.params), "{command}");
|
||||
assert!(Arc::ptr_eq(&s.model.state(), &model), "{command}");
|
||||
assert_eq!(s.evaluations, evals, "{command}");
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, *saved, "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A compound creator must stage its creator and dimensions atomically under the same sheet.
|
||||
#[test]
|
||||
fn sheet_batch_dimensioned_creation_respects_paper_units_and_owner() {
|
||||
let (mut s, drawing, sketch, made) = sheet_editor();
|
||||
s.doc_mut().set_param("Inset", "1", Some("in"), None).unwrap();
|
||||
let source = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let history = s.undo.len();
|
||||
let evals = s.evaluations;
|
||||
let out = run(
|
||||
&mut s,
|
||||
"sketch.draw.dimensioned",
|
||||
json!({
|
||||
"command": "sketch.line", "params": {"points": [[10, 15], [50, 15]], "connect": false},
|
||||
"dimensions": {"length": "Inset + 5"}
|
||||
}),
|
||||
);
|
||||
assert_eq!(out["dimensions"]["length"]["param"], Value::Null);
|
||||
assert_eq!(out["dimensions"]["length"]["expression"], "Inset + 5");
|
||||
assert_eq!(out["dimensions"]["length"]["unit"], "mm");
|
||||
let record = &s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch;
|
||||
assert!(record.constraints.iter().any(|c| c.param.as_deref() == Some("Inset + 5")));
|
||||
let dimension = record.constraints.iter().find(|c| c.param.as_deref() == Some("Inset + 5")).unwrap();
|
||||
assert!((solidcraft_sketch::measure_dimension(record, &dimension.kind).unwrap() - 30.4).abs() < 1e-5);
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (history + 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, evals);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.is_empty());
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.len() == 1);
|
||||
|
||||
let pristine = s.doc.clone();
|
||||
let original_history = (s.undo.len(), s.redo.len(), s.evaluations);
|
||||
for request in [
|
||||
json!({"command":"sketch.line","params":{"points":[[0,0],[10,0]]},"dimensions":{"length":"Missing + 2"}}),
|
||||
json!({"command":"sketch.line","params":{"sketch":made["drawing"],"points":[[0,0],[10,0]]},"dimensions":{"length":25}}),
|
||||
json!({"command":"sketch.line","params":{"points":[[0,0],[10,0]]},"dimensions":{"length":"1".repeat(4097)}}),
|
||||
json!({"command":"sketch.rectangle.rounded","params":{"p0":[10,10],"p1":[50,30],"radius":30},"dimensions":{"width":40}}),
|
||||
] {
|
||||
refused(&mut s, "sketch.draw.dimensioned", request.clone());
|
||||
assert!(Arc::ptr_eq(&s.doc, &pristine), "{request}");
|
||||
assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), original_history, "{request}");
|
||||
assert!(Arc::ptr_eq(&s.model.state(), &model));
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrong target and unadmitted record families never borrow active model geometry.
|
||||
#[test]
|
||||
fn sheet_batch_modify_refuses_foreign_owner_and_unpersisted_families_atomically() {
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
let line = run(&mut s, "sketch.line", json!({"points": [[10,10],[50,10]], "connect": false}))["curves"][0].clone();
|
||||
let source = 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.move", json!({"sketch":ids::encode(drawing),"entities":[line],"translate":[5,5]})),
|
||||
("sketch.scale", json!({"sketch":ids::encode(drawing),"entities":[line],"factor":2})),
|
||||
("sketch.break", json!({"sketch":ids::encode(drawing),"curve":line,"points":[[30,10]]})),
|
||||
("sketch.trim", json!({"sketch":ids::encode(drawing),"curve":line,"at":[30,10]})),
|
||||
("sketch.drag", json!({"sketch":ids::encode(drawing),"entity":line,"from":[30,10],"to":[40,20]})),
|
||||
("sketch.drag", json!({"entity":line,"from":[30,10],"to":[40,20],"live":true})),
|
||||
("sketch.drag", json!({"entity":line,"from":[30,10],"to":[40,20],"live":"frame"})),
|
||||
("sketch.fillet", json!({"sketch":ids::encode(drawing),"a":line,"b":line,"radius":5})),
|
||||
("sketch.mirror", json!({"sketch":ids::encode(drawing),"entities":[line],"line":line})),
|
||||
] {
|
||||
refused(&mut s, command, params.clone());
|
||||
assert!(Arc::ptr_eq(&s.doc, &source), "{command}: {params}");
|
||||
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}");
|
||||
}
|
||||
// Association families require a bounded sheet-record contract before they can be enabled.
|
||||
for command in ["sketch.offset", "sketch.pattern.circular", "sketch.pattern.rectangular"] {
|
||||
assert!(find_command(command).unwrap().allowed(&s).is_err(), "{command} must stay disabled on sheets");
|
||||
}
|
||||
assert!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).is_some());
|
||||
}
|
||||
|
||||
/// R17 2D creator coverage: only existing curve constructors and the paper receiver.
|
||||
#[test]
|
||||
fn sheet_batch_new_2d_creators_preserve_paper_records_and_history() {
|
||||
for (command, params) in [
|
||||
("sketch.line.midpoint", json!({"mid": [40, 40], "end": [60, 40]})),
|
||||
("sketch.slot.center_point", json!({"center": [60, 50], "end": [80, 50], "width": 8})),
|
||||
("sketch.slot.arc_three_point", json!({"start": [80, 50], "through": [70, 65], "end": [60, 50], "width": 8})),
|
||||
("sketch.slot.arc_center", json!({"center": [60, 50], "start": [80, 50], "end": [60, 70], "width": 8})),
|
||||
("sketch.ellipse", json!({"center": [80, 50], "major": [100, 50], "minor_radius": 10})),
|
||||
("sketch.spline.fit_point", json!({"points": [[40,40],[50,60],[70,55],[85,40]],"connect":false})),
|
||||
("sketch.spline.control_point", json!({"points": [[40,40],[50,60],[70,55],[85,40]],"connect":false})),
|
||||
("sketch.spline.control_point_5", json!({"points": [[40,40],[50,60],[55,65],[70,65],[80,55],[85,40]],"connect":false})),
|
||||
("sketch.conic", json!({"start":[40,40],"end":[90,40],"apex":[65,65],"rho":0.5,"connect":false})),
|
||||
] {
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
let source = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let steps = s.undo.len();
|
||||
let evals = s.evaluations;
|
||||
let result = run(&mut s, command, params.clone());
|
||||
assert!(result["curves"].as_array().is_some_and(|curves| !curves.is_empty()), "{command}: {result}");
|
||||
let record = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
|
||||
assert!(!record.curves.is_empty(), "{command}");
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (steps + 1, Some(drawing)), "{command}");
|
||||
assert_eq!((&s.doc.features, &s.doc.params), (&source.features, &source.params), "{command}");
|
||||
assert!(Arc::ptr_eq(&model, &s.model.state()), "{command}");
|
||||
assert_eq!(s.evaluations, evals, "{command}");
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, record, "{command}");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.curves.is_empty(), "{command}");
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert_eq!(s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, record, "{command}");
|
||||
}
|
||||
}
|
||||
|
||||
/// G1 blends and local line types operate within the same sheet and solver.
|
||||
#[test]
|
||||
fn sheet_batch_blend_tangent_arc_centerlines_and_infinite_are_local() {
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
let a = run(&mut s, "sketch.line", json!({"points":[[30,50],[60,50]],"connect":false,"infer":false}))["curves"][0].as_str().unwrap().to_string();
|
||||
let b =
|
||||
run(&mut s, "sketch.line", json!({"points":[[100,70],[120,70]],"connect":false,"infer":false}))["curves"][0].as_str().unwrap().to_string();
|
||||
let source = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let evaluations = s.evaluations;
|
||||
let blended = run(&mut s, "sketch.blend_curve", json!({"a":format!("{a}.end"),"b":format!("{b}.start"),"continuity":"g1"}));
|
||||
assert!(blended["curves"].as_array().is_some_and(|v| !v.is_empty()), "{blended}");
|
||||
let tangent = run(&mut s, "sketch.arc.tangent", json!({"start":format!("{b}.end"),"end":[135,85],"curve":b}));
|
||||
assert!(tangent["curves"].as_array().is_some_and(|v| !v.is_empty()), "{tangent}");
|
||||
let mid = run(&mut s, "sketch.centerline", json!({"curves":[a],"value":true}));
|
||||
assert_eq!(mid["changed"], 1);
|
||||
let infinite = run(&mut s, "sketch.infinite", json!({"curves":[a],"value":true}));
|
||||
assert_eq!(infinite["changed"], 1);
|
||||
let stored = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
|
||||
let ci = stored.curve_index(&a).unwrap();
|
||||
assert!(stored.curves[ci].infinite && stored.curves[ci].construction);
|
||||
assert_eq!((&s.doc.features, &s.doc.params), (&source.features, &source.params));
|
||||
assert!(Arc::ptr_eq(&s.model.state(), &model));
|
||||
assert_eq!(s.evaluations, evaluations);
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, stored);
|
||||
let before = s.doc.clone();
|
||||
let undo = (s.undo.len(), s.redo.len(), s.evaluations);
|
||||
refused(&mut s, "sketch.blend_curve", json!({"a":format!("{a}.end"),"b":format!("{b}.start"),"continuity":"g4"}));
|
||||
assert!(Arc::ptr_eq(&s.doc, &before));
|
||||
assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), undo);
|
||||
}
|
||||
|
||||
/// A tangent circle with a radius expression belongs to the sheet, not model parameters.
|
||||
#[test]
|
||||
fn sheet_batch_tangent_circle_read_only_source_and_reference_refusal() {
|
||||
let (mut s, drawing, sketch, _) = sheet_editor();
|
||||
s.doc_mut().set_param("Inset", "1", Some("in"), None).unwrap();
|
||||
let h = run(&mut s, "sketch.line", json!({"points":[[20,30],[100,30]],"connect":false,"infer":false}))["curves"][0].clone();
|
||||
let v = run(&mut s, "sketch.line", json!({"points":[[30,20],[30,100]],"connect":false,"infer":false}))["curves"][0].clone();
|
||||
run(&mut s, "sketch.constraint.fix", json!({"entities":[h,v]}));
|
||||
let source = s.doc.clone();
|
||||
let model = s.model.state();
|
||||
let history = s.undo.len();
|
||||
let evals = s.evaluations;
|
||||
let r = run(&mut s, "sketch.circle.two_tangent", json!({"curves":[h,v], "radius":"Inset / 5","near":[40,40]}));
|
||||
assert!(r["curves"].as_array().is_some_and(|x| x.len() == 1), "{r}");
|
||||
assert_eq!((s.undo.len(), s.undo.last().unwrap().part), (history + 1, Some(drawing)));
|
||||
let sheet = s.doc.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch.clone();
|
||||
assert!(sheet.constraints.iter().any(|c| c.param.as_deref() == Some("Inset / 5")));
|
||||
assert_eq!((&s.doc.features, &s.doc.params), (&source.features, &source.params));
|
||||
assert!(Arc::ptr_eq(&s.model.state(), &model));
|
||||
assert_eq!(s.evaluations, evals);
|
||||
let reopened = solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap();
|
||||
assert_eq!(reopened.drawing(drawing).unwrap().sheet_sketch(sketch).unwrap().sketch, sheet);
|
||||
let before = s.doc.clone();
|
||||
let undo = (s.undo.len(), s.redo.len(), s.evaluations);
|
||||
refused(&mut s, "sketch.circle.two_tangent", json!({"curves":[h,v],"radius":"Missing + 1","near":[40,40]}));
|
||||
assert!(Arc::ptr_eq(&s.doc, &before));
|
||||
assert_eq!((s.undo.len(), s.redo.len(), s.evaluations), undo);
|
||||
}
|
||||
|
||||
/// The known 2D families are enabled for sheets, while text links and patterns remain
|
||||
/// blocked by the current bounded stored-record contract.
|
||||
#[test]
|
||||
fn sheet_batch_command_capability_matrix_refuses_unsafe_record_families() {
|
||||
let (s, _, _, _) = sheet_editor();
|
||||
for id in [
|
||||
"sketch.line.midpoint",
|
||||
"sketch.arc.tangent",
|
||||
"sketch.circle.two_tangent",
|
||||
"sketch.circle.three_tangent",
|
||||
"sketch.slot.center_point",
|
||||
"sketch.slot.arc_three_point",
|
||||
"sketch.slot.arc_center",
|
||||
"sketch.ellipse",
|
||||
"sketch.spline.fit_point",
|
||||
"sketch.spline.control_point",
|
||||
"sketch.spline.control_point_5",
|
||||
"sketch.conic",
|
||||
"sketch.blend_curve",
|
||||
"sketch.centerline",
|
||||
"sketch.infinite",
|
||||
"sketch.rectangle.rounded",
|
||||
"sketch.draw.dimensioned",
|
||||
"sketch.fillet",
|
||||
"sketch.chamfer.equal_distance",
|
||||
"sketch.chamfer.distance_angle",
|
||||
"sketch.chamfer.two_distance",
|
||||
"sketch.trim",
|
||||
"sketch.trim.path",
|
||||
"sketch.extend",
|
||||
"sketch.break",
|
||||
"sketch.scale",
|
||||
"sketch.move",
|
||||
"sketch.mirror",
|
||||
"sketch.drag",
|
||||
] {
|
||||
assert!(find_command(id).unwrap().allowed(&s).is_ok(), "{id} should accept an active drawing-owned sketch");
|
||||
}
|
||||
for id in [
|
||||
"sketch.text",
|
||||
"sketch.edit_text",
|
||||
"sketch.offset",
|
||||
"sketch.pattern.circular",
|
||||
"sketch.pattern.rectangular",
|
||||
"sketch.drag_end",
|
||||
"sketch.create",
|
||||
"sketch.edit",
|
||||
] {
|
||||
assert!(find_command(id).unwrap().allowed(&s).is_err(), "{id} is not admitted on a sheet");
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.enabled(in_sketch)
|
||||
.params(concat!("points: [[x,y] | \"l1.end\" | {at, ref}…] (x and y each a number or an expression over the design's parameters, \"W / 2\": such a point is fixed where it comes to and follows the parameters; likewise wherever a point argument also takes a point id), closed?: bool, construction?: bool, ids?: [..], infer?: bool (add horizontal/vertical)", connect_doc!(), created_doc!())),
|
||||
CommandSpec::new("sketch.draw.dimensioned", "Draw Dimensioned Sketch Geometry", draw_dimensioned).icon("dimension")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("command: sketch creation command, params: object, dimensions: object of role to numeric or expression value; creates geometry and all driving dimensions atomically in one undo step", created_doc!())),
|
||||
CommandSpec::new("sketch.rectangle.two_point", "2-Point Rectangle", rect_two_point)
|
||||
.in_sketch_part()
|
||||
@@ -63,7 +63,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("sketch.rectangle.rounded", "Rounded Rectangle", rect_rounded)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("rect_rounded")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("p0, p1: opposite corners [x,y]; radius: expr (the corner radius, less than half the shorter side); construction?. A 2-point rectangle whose four corners are filleted alike: one radius dimension (`param`), the other arcs equal to it. Returns sides {bottom, right, top, left} (line ids) and arcs (the corner arcs: bottom-left, bottom-right, top-right, top-left)", connect_doc!(), created_doc!())),
|
||||
CommandSpec::new("sketch.rectangle.center", "Center Rectangle", rect_center)
|
||||
.in_sketch_part()
|
||||
@@ -212,7 +212,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.enabled(in_sketch)
|
||||
.params("entities: [curve, point or constraint ids]"),
|
||||
CommandSpec::new("sketch.move_point", "Drag Sketch Point", move_point).in_sketch_part().icon("sketch_move").enabled(in_sketch).params("point: ref, to: [x,y]"),
|
||||
CommandSpec::new("sketch.drag", "Drag Sketch Geometry", drag).icon("sketch_move").enabled(in_sketch).live(drag_live).params(
|
||||
CommandSpec::new("sketch.drag", "Drag Sketch Geometry", drag).in_sketch_part().icon("sketch_move").enabled(in_sketch).live(drag_live).params(
|
||||
"entity: point or curve, from: [x,y] where it was grabbed, to: [x,y], live?: bool: points and the material point grabbed on a line move toward `to` within the design constraints. When exact placement is impossible, bounded feasible steps minimize cursor distance. Splines slide by to - from; a circle or arc grabbed on its edge takes the radius to `to`. `with?`: [point or curve ids] moves the rest of a selection with the entity as one translation (circles keep their radii). Long moves retain the solution branch; arcs cannot sweep through their starts. Returns `reached`: progress projected onto the requested move (0..1), `at`: the grabbed position for the next frame, and `retry`: budget-limited progress can continue in another frame. `live: true` shares a work budget across held-solve decomposition and cursor correction; ordinary recovery and the final model evaluation retain their existing limits, not a wall-clock deadline. Later features stay stale until `sketch.drag_end`; `dof` stays from before the drag",
|
||||
),
|
||||
CommandSpec::new("sketch.drag_end", "End Sketch Drag", drag_end).icon("sketch_move").enabled(in_sketch).doc_only().params(
|
||||
@@ -1095,6 +1095,9 @@ fn rect_rounded(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
o.insert("arcs".into(), arcs);
|
||||
o.insert("param".into(), rounded.get("param").cloned().unwrap_or(Value::Null));
|
||||
if let Some(expression) = rounded.get("expression").filter(|_| s.open_drawing.is_some()) {
|
||||
o.insert("expression".into(), expression.clone());
|
||||
}
|
||||
if let Some(info) = rounded.get("sketch") {
|
||||
o.insert("sketch".into(), info.clone());
|
||||
}
|
||||
@@ -2745,6 +2748,36 @@ fn drag_frame(s: &mut Session, p: &Value, live: bool) -> Result<(Value, Option<c
|
||||
None | Some(Value::Null) => to,
|
||||
Some(v) => vec2(v).ok_or_else(|| bad(cmd, "`from` must be a point [x, y]"))?,
|
||||
};
|
||||
if s.open_drawing.is_some() {
|
||||
// The drawing editor publishes a complete gesture once. Live frames remain
|
||||
// model-only until the common UI gesture host owns a sheet transaction.
|
||||
if live || p.get("live").is_some_and(|v| !v.is_null() && v != &Value::Bool(false)) {
|
||||
return Err(bad(cmd, "live sheet drag needs the Drawing pointer gesture host; use a completed non-live sketch.drag edit"));
|
||||
}
|
||||
let entry = sketch_store::sheet_target(s, p, cmd)?;
|
||||
let (moved, report) = edit(s, p, cmd, false, |sk, _| {
|
||||
let id = p.get("entity").and_then(Value::as_str).ok_or_else(|| bad(cmd, "entity must be a sketch point or curve"))?;
|
||||
let entity = ent(sk, id).ok_or_else(|| bad(cmd, format!("unknown sketch entity `{id}`")))?;
|
||||
let companions = match p.get("with") {
|
||||
None | Some(Value::Null) => Vec::new(),
|
||||
Some(Value::Array(ids)) if ids.len() <= sk.points.len() + sk.curves.len() => ids
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let name = v.as_str().ok_or_else(|| bad(cmd, "with must list sketch point or curve ids"))?;
|
||||
ent(sk, name).ok_or_else(|| bad(cmd, format!("unknown sketch entity `{name}`")))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?,
|
||||
_ => return Err(bad(cmd, "with must be a bounded list of sketch point or curve ids")),
|
||||
};
|
||||
let (out, _) = drag_entity(sk, entity, &companions, from, to, false, None);
|
||||
Ok(out)
|
||||
})?;
|
||||
let owner = s.drawing(cmd)?;
|
||||
let sketch = &owner.sheet_sketch(entry.sketch).ok_or_else(|| bad(cmd, "the edited sheet sketch no longer exists"))?.sketch;
|
||||
let at = moved.at(sketch, from);
|
||||
let result = json!({"sketch": report, "reached": moved.reached, "at": [at.x, at.y], "retry": moved.retry});
|
||||
return Ok((result, None));
|
||||
}
|
||||
let id = sketch_store::target(s, p, cmd)?;
|
||||
// The sketch's report as last evaluated: a live frame keeps its degrees of freedom.
|
||||
let state = s.model.result(id).map(|r| r.state.clone());
|
||||
|
||||
@@ -30,65 +30,65 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("sketch.line.midpoint", "Midpoint Line", midpoint_line)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("line_mid")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("mid: [x,y] or point ref, end: [x,y]; construction?", created_doc!())),
|
||||
CommandSpec::new("sketch.arc.tangent", "Tangent Arc", arc_tangent).at("SKETCH", "CREATE").icon("arc_tangent").enabled(in_sketch).params(concat!(
|
||||
CommandSpec::new("sketch.arc.tangent", "Tangent Arc", arc_tangent).at("SKETCH", "CREATE").icon("arc_tangent").in_sketch_part().enabled(in_sketch).params(concat!(
|
||||
"start: end point of a line or arc (\"l1.end\"), end: [x,y]; curve?: the curve to be tangent to (default: the one ending at start)",
|
||||
created_doc!()
|
||||
)),
|
||||
CommandSpec::new("sketch.circle.two_tangent", "2-Tangent Circle", circle_tan_tan)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("circle_tt")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("curves: [two lines/circles/arcs], radius | diameter: expr, near: [x,y] (which of the solutions)", created_doc!())),
|
||||
CommandSpec::new("sketch.circle.three_tangent", "3-Tangent Circle", circle_three_tan)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("circle_ttt")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("curves: [three lines/circles/arcs], near: [x,y] (which of the solutions)", created_doc!())),
|
||||
CommandSpec::new("sketch.slot.center_point", "Center Point Slot", slot_center_point)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("slot_center")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("center: slot centre, end: one arc centre, width", created_doc!())),
|
||||
CommandSpec::new("sketch.slot.arc_three_point", "Three Point Arc Slot", arc_slot_three)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("arc_slot")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("start, through, end: points on the centre arc, width", created_doc!())),
|
||||
CommandSpec::new("sketch.slot.arc_center", "Center Point Arc Slot", arc_slot_center)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("arc_slot_center")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("center, start: centre arc start, end: direction of the centre arc end (counter-clockwise), width", created_doc!())),
|
||||
CommandSpec::new("sketch.ellipse", "Ellipse", ellipse).at("SKETCH", "CREATE").icon("ellipse").enabled(in_sketch).params(concat!(
|
||||
CommandSpec::new("sketch.ellipse", "Ellipse", ellipse).at("SKETCH", "CREATE").icon("ellipse").in_sketch_part().enabled(in_sketch).params(concat!(
|
||||
"center, major: end of the major axis [x,y], minor: a point the ellipse passes through on the minor side [x,y] | minor_radius",
|
||||
created_doc!()
|
||||
)),
|
||||
CommandSpec::new("sketch.spline.fit_point", "Fit Point Spline", spline_fit)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("spline")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("points: [[x,y] or point refs…] (2…500): the spline passes through them, periodic?: boolean (default false); periodic cubic fit closes smoothly through at least 3 distinct samples", created_doc!())),
|
||||
CommandSpec::new("sketch.spline.control_point", "Control Point Spline", spline_cv3)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("spline_cv")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("points: control points (2…500), cubic", created_doc!())),
|
||||
CommandSpec::new("sketch.spline.control_point_5", "Control Point Spline (Degree 5)", spline_cv5)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("spline_cv")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("points: control points (2…500), degree 5", created_doc!())),
|
||||
CommandSpec::new("sketch.conic", "Conic Curve", conic)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("conic")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("start, end, apex: [x,y] or point refs; rho?: 0…1 (default 0.5: parabola)", created_doc!())),
|
||||
CommandSpec::new("sketch.blend_curve", "Blend Curve", blend)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("blend")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!(
|
||||
"a, b: end points of two curves (\"l1.end\", \"a2.start\"), continuity?: g1|g2|g3|g4 (default g1: a tangent spline; g2…g4 match the reference curves' curvature, curvature rate and 4th derivative as well, as one Bézier of degree 5, 7 or 9)",
|
||||
created_doc!()
|
||||
@@ -96,10 +96,10 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("sketch.centerline", "Centerline", centerline)
|
||||
.at("SKETCH", "CREATE")
|
||||
.icon("centerline")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params("curves: [line ids], value?: bool (default toggles): centerline line type (not in profiles; an axis)"),
|
||||
CommandSpec::new("sketch.infinite", "Infinite Line", infinite_line).icon("infinite")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params("curves: [line ids], value?: bool (default toggles): infinite line type (#1359): construction geometry drawn across the whole view through the line's two points; off, a normal line"),
|
||||
CommandSpec::new("sketch.text", "Text", text).at("SKETCH", "CREATE").icon("sketch_text").enabled(in_sketch).params(concat!(
|
||||
"text: string (\\n breaks lines), at: baseline start [x,y], height?: capital height mm (default 5), angle?: deg; at's x and y, height and angle each take a number or an expression over the design's parameters as a string (\"plate_width / 2\", \"label_size\"): the text keeps the expression, follows the parameters, and returns it in `exprs`; an expression naming no parameter is the number it comes to, a bare number in one is in the design's units, \
|
||||
@@ -498,6 +498,9 @@ fn joint_derivatives(sk: &Sketch, ci: usize, pi: usize, order: usize, leaving: b
|
||||
fn blend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.blend_curve";
|
||||
let order = blend_order(p, cmd)?;
|
||||
if s.open_drawing.is_some() && order > 2 {
|
||||
return Err(bad(cmd, "sheet sketches support G1/G2 blends; higher-order splines need their own bounded record contract"));
|
||||
}
|
||||
let (out, info) = edit(s, p, cmd, false, |sk, doc| {
|
||||
let pa = req_parg(sk, doc, p, "a", cmd)?.idx().ok_or_else(|| bad(cmd, "`a` must be the end point of a curve"))?;
|
||||
let pb = req_parg(sk, doc, p, "b", cmd)?.idx().ok_or_else(|| bad(cmd, "`b` must be the end point of a curve"))?;
|
||||
@@ -877,6 +880,7 @@ fn tangent_curves(sk: &Sketch, p: &Value, cmd: &str, n: usize) -> Result<Vec<usi
|
||||
/// A circle tangent to `curves`, solved from a start near `near`.
|
||||
fn tangent_circle(s: &mut Session, p: &Value, cmd: &str, n: usize, radius: Option<String>) -> Result<Value> {
|
||||
let near = req_vec2(cmd, p, "near")?;
|
||||
let on_sheet = s.open_drawing.is_some();
|
||||
let (out, info) = edit(s, p, cmd, true, |sk, doc| {
|
||||
let cs = tangent_curves(sk, p, cmd, n)?;
|
||||
let r0 = match &radius {
|
||||
@@ -899,7 +903,7 @@ fn tangent_circle(s: &mut Session, p: &Value, cmd: &str, n: usize, radius: Optio
|
||||
cons.push(add_c(sk, ConstraintKind::Tangent { a: *k, b: c })?);
|
||||
}
|
||||
if let Some(e) = &radius {
|
||||
let pname = doc.new_model_param(e, "mm");
|
||||
let pname = if on_sheet { e.to_string() } else { doc.new_model_param(e, "mm") };
|
||||
let k = sk.add_constraint(ConstraintKind::Radius { c, value: r0 }, Some(pname))?;
|
||||
cons.push(k);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::{
|
||||
|
||||
pub(super) fn draw(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.draw.dimensioned";
|
||||
let on_sheet = s.open_drawing.is_some();
|
||||
let create = str_(p, "command").ok_or_else(|| bad(cmd, "`command` must name a supported sketch creator"))?;
|
||||
let roles: &[&str] = match create {
|
||||
"sketch.line" => &["length", "angle"],
|
||||
@@ -23,6 +24,10 @@ pub(super) fn draw(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
let mut params = p.get("params").filter(|v| v.is_object()).cloned().ok_or_else(|| bad(cmd, "`params` must be an object"))?;
|
||||
let dimensions = p.get("dimensions").and_then(Value::as_object).ok_or_else(|| bad(cmd, "`dimensions` must be an object"))?;
|
||||
if on_sheet {
|
||||
// Never let a compound tool select another sheet or a model sketch.
|
||||
super::super::sketch_store::sheet_target(s, ¶ms, cmd)?;
|
||||
}
|
||||
if dimensions.len() > roles.len() || dimensions.keys().any(|key| !roles.contains(&key.as_str())) {
|
||||
return Err(bad(cmd, "unsupported dimension role for this creator"));
|
||||
}
|
||||
@@ -106,7 +111,10 @@ pub(super) fn draw(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
// A typed size the sketch already has (a rectangle drawn onto another's side, the same
|
||||
// height) is placed as a driven (reference) dimension rather than refused.
|
||||
let mut dimension = json!({"entities": entities, "type": ty, "value": value, "if_redundant": "driven"});
|
||||
let mut dimension = json!({"entities": entities, "type": ty, "value": value});
|
||||
if !on_sheet {
|
||||
dimension["if_redundant"] = json!("driven");
|
||||
}
|
||||
if let Some(sketch) = params.get("sketch") {
|
||||
dimension["sketch"] = sketch.clone();
|
||||
}
|
||||
|
||||
@@ -23,22 +23,22 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("sketch.fillet", "Fillet", fillet)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_fillet")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("point: corner shared by two curves (\"l1.end\") | points: [corners] (all rounded alike: one radius, the rest equal) | a, b: two lines or arcs meeting at a corner; radius: expr. A corner that dimensions or constraints measure to stays as a virtual sharp corner on both curves' extensions (`virtual_corners`; the moved ones in `moved_to_virtual_corner`)", created_doc!())),
|
||||
CommandSpec::new("sketch.chamfer.equal_distance", "Equal Distance Chamfer", chamfer_equal)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_chamfer")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("point | a, b: a corner of two lines; distance", created_doc!())),
|
||||
CommandSpec::new("sketch.chamfer.distance_angle", "Distance and Angle Chamfer", chamfer_dist_angle)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_chamfer_angle")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("point | a, b: a corner of two lines; distance: along a, angle: deg from a", created_doc!())),
|
||||
CommandSpec::new("sketch.chamfer.two_distance", "Two Distance Chamfer", chamfer_two)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_chamfer_two_distances")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("point | a, b: a corner of two lines; distance: along a, distance2: along b", created_doc!())),
|
||||
CommandSpec::new("sketch.offset", "Offset", offset)
|
||||
.at("SKETCH", "MODIFY")
|
||||
@@ -58,11 +58,11 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("trim")
|
||||
.key("T")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("curve: id, at: [x,y] (the piece to remove: between the nearest intersections around it)", created_doc!())),
|
||||
CommandSpec::new("sketch.trim.path", "Trim Along Path", trim_path)
|
||||
.icon("trim")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!(
|
||||
"points: [[x,y]…] (2…2000 positions: a path drawn across the sketch). Every piece the path crosses is removed as `sketch.trim` removes the piece at that crossing, in the order the path crosses them; a piece crossed again after it is gone is not trimmed twice; projected geometry, infinite lines, offset outputs and pieces trim refuses are passed over (why in `skipped`). dry_run?: bool (report without changing the design). One undo step → trimmed: [each trim's result], removed: [[[x,y]…]] (each removed piece as a polyline)",
|
||||
created_doc!()
|
||||
@@ -70,27 +70,27 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("sketch.extend", "Extend", extend)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("extend")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params("curve: id, at: [x,y] near the end to extend (to the nearest curve)"),
|
||||
CommandSpec::new("sketch.break", "Break", break_cmd)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_break")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("curve: id, at: [x,y] (split at intersections) | points: [[x,y]…] (1…1000 positions projected onto the curve; duplicates are merged)", created_doc!())),
|
||||
CommandSpec::new("sketch.scale", "Sketch Scale", scale)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_scale")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params("entities: [curve/point ids], base: [x,y] or point ref, factor: number"),
|
||||
CommandSpec::new("sketch.move", "Move/Copy Sketch Entities", move_copy)
|
||||
.at("SKETCH", "MODIFY")
|
||||
.icon("sketch_move")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("entities: [ids], translate?: [dx,dy], angle?: deg, center?: [x,y], copy?: bool; picking a text outline or linked point transforms its whole text source once, and copies remain editable text", created_doc!())),
|
||||
CommandSpec::new("sketch.mirror", "Mirror", mirror)
|
||||
.at("SKETCH", "PATTERN")
|
||||
.icon("sketch_mirror")
|
||||
.enabled(in_sketch)
|
||||
.in_sketch_part().enabled(in_sketch)
|
||||
.params(concat!("entities: [curve/point ids], line: mirror line id (symmetry constraints are added)", created_doc!())),
|
||||
CommandSpec::new("sketch.pattern.circular", "Circular Pattern", pattern_circular)
|
||||
.at("SKETCH", "PATTERN")
|
||||
@@ -365,10 +365,13 @@ fn refuse_offset_ends(sk: &Sketch, ci: usize, what: &str, cmd: &str) -> Result<(
|
||||
fn trim(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.trim";
|
||||
let at = req_vec2(cmd, p, "at")?;
|
||||
let model_edit = s.open_drawing.is_none();
|
||||
let (out, info) = edit(s, p, cmd, false, |sk, doc| {
|
||||
let ci = curve_arg(sk, p, cmd)?;
|
||||
let (out, _) = remove_piece(sk, ci, at, cmd)?;
|
||||
doc.prune_model_params();
|
||||
if model_edit {
|
||||
doc.prune_model_params();
|
||||
}
|
||||
Ok(out)
|
||||
})?;
|
||||
Ok(json!({"result": out, "sketch": info}))
|
||||
@@ -523,6 +526,7 @@ fn trim_path(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
out["dry_run"] = json!(true);
|
||||
return Ok(out);
|
||||
}
|
||||
let model_edit = s.open_drawing.is_none();
|
||||
let ((trimmed, removed, skipped), info) = edit(s, p, cmd, false, |sk, doc| {
|
||||
let mut trimmed: Vec<Value> = Vec::new();
|
||||
let mut removed: Vec<Value> = Vec::new();
|
||||
@@ -550,7 +554,9 @@ fn trim_path(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if trimmed.is_empty() {
|
||||
return Err(bad(cmd, skipped.first().cloned().unwrap_or_else(|| "the path crosses no curve that can be trimmed".into())));
|
||||
}
|
||||
doc.prune_model_params();
|
||||
if model_edit {
|
||||
doc.prune_model_params();
|
||||
}
|
||||
Ok((trimmed, removed, skipped))
|
||||
})?;
|
||||
Ok(json!({"trimmed": trimmed, "removed": removed, "skipped": skipped, "sketch": info}))
|
||||
@@ -559,6 +565,7 @@ fn trim_path(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn break_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.break";
|
||||
let points = if p.get("points").is_some() { Some(vec2_list(cmd, p, "points", 1000)?) } else { None };
|
||||
let model_edit = s.open_drawing.is_none();
|
||||
let (out, info) = edit(s, p, cmd, false, |sk, doc| {
|
||||
let ci = curve_arg(sk, p, cmd)?;
|
||||
if sk.curves.get(ci).is_some_and(|c| c.kind.is_freeform()) {
|
||||
@@ -568,7 +575,9 @@ fn break_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let at = req_vec2(cmd, p, "at")?;
|
||||
super::sketch_freeform::trim_or_break(sk, ci, at, false, cmd)?
|
||||
};
|
||||
doc.prune_model_params();
|
||||
if model_edit {
|
||||
doc.prune_model_params();
|
||||
}
|
||||
return Ok(r["curves"].as_array().map(|a| a.iter().filter_map(|x| x.as_str().map(str::to_string)).collect()).unwrap_or_default());
|
||||
}
|
||||
let sh = sk.shape(ci).ok_or_else(|| bad(cmd, "curve"))?;
|
||||
@@ -602,10 +611,15 @@ fn break_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
fn extend(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let cmd = "sketch.extend";
|
||||
let at = req_vec2(cmd, p, "at")?;
|
||||
let on_sheet = s.open_drawing.is_some();
|
||||
let (out, info) = edit(s, p, cmd, true, |sk, doc| {
|
||||
let rep = solve_current(sk, doc)?;
|
||||
if !rep.keeps_orientation() {
|
||||
return Err(bad(cmd, rep.failure(|_| "solve the existing sketch constraints before extending".into())));
|
||||
// The sheet receiver has already solved the exact paper-owned sketch.
|
||||
// Model-only parameter evaluation would discard sheet expressions.
|
||||
if !on_sheet {
|
||||
let rep = solve_current(sk, doc)?;
|
||||
if !rep.keeps_orientation() {
|
||||
return Err(bad(cmd, rep.failure(|_| "solve the existing sketch constraints before extending".into())));
|
||||
}
|
||||
}
|
||||
let ci = curve_arg(sk, p, cmd)?;
|
||||
refuse_offset_ends(sk, ci, "extend", cmd)?;
|
||||
@@ -957,12 +971,14 @@ fn fillet(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Some(_) => return Err(bad(cmd, "`points` must list 1…500 corners")),
|
||||
None => vec![p.clone()],
|
||||
};
|
||||
let on_sheet = s.open_drawing.is_some();
|
||||
let (out, info) = edit(s, p, cmd, false, |sk, doc| {
|
||||
let r = doc.eval(&r_expr, solidcraft_doc::expr::Kind::Length).map_err(|e| bad(cmd, format!("radius: {e}")))?;
|
||||
if !(r > 1e-9 && r < 1e8) {
|
||||
return Err(bad(cmd, "radius must be positive"));
|
||||
}
|
||||
let pname = doc.new_model_param(&r_expr, "mm");
|
||||
// A sheet owns its radius expression, not a new source-model parameter.
|
||||
let pname = if on_sheet { r_expr.to_string() } else { doc.new_model_param(&r_expr, "mm") };
|
||||
let (mut arcs, mut cons, mut kept) = (Vec::new(), Vec::new(), Vec::new());
|
||||
for q in &corners {
|
||||
let (arc, mut c, k) = fillet_corner(sk, q, r, cmd)?;
|
||||
@@ -978,7 +994,13 @@ fn fillet(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok((ids_of(sk, &arcs), cons, pname, kept_json(kept)))
|
||||
})?;
|
||||
let (vc, moved) = out.3;
|
||||
Ok(json!({"curves": out.0, "constraints": out.1, "param": out.2, "virtual_corners": vc, "moved_to_virtual_corner": moved, "sketch": info}))
|
||||
let param = if on_sheet { Value::Null } else { json!(out.2) };
|
||||
let mut result =
|
||||
json!({"curves": out.0, "constraints": out.1, "param": param, "virtual_corners": vc, "moved_to_virtual_corner": moved, "sketch": info});
|
||||
if on_sheet {
|
||||
result["expression"] = json!(r_expr);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// The virtual corners kept and the constraints moved to them, for a response.
|
||||
|
||||
@@ -536,3 +536,50 @@ display, stored source expressions with changed-source read-only resolution,
|
||||
saving/reopening, drawing-local undo/redo, and atomic invalid/foreign
|
||||
refusals. This is a command/store increment; it does **not** claim an
|
||||
interactive desktop/browser sheet editor or full repository CI.
|
||||
|
||||
|
||||
### W38a R17: shared 2D command coverage on a paper-owned sketch
|
||||
|
||||
The same Drawing receiver now admits the remaining **bounded, self-contained 2D
|
||||
geometry commands** that can already be represented by the stored sheet
|
||||
`Sketch` payload. These are not new geometry implementations or command ids:
|
||||
|
||||
- Creation: midpoint line, tangent arc, two- and three-tangent circles,
|
||||
center-point and arc slots, ellipse, cubic fit/control splines, degree-five
|
||||
control spline, conic, G1/G2 blend, and rounded rectangle.
|
||||
- Editing: fillet, three chamfers, trim, path trim, extend, break,
|
||||
scale, move/copy, mirror, centerline, infinite line and a completed
|
||||
non-live `sketch.drag` command.
|
||||
- Compound `sketch.draw.dimensioned` creates its supported geometry and paper
|
||||
driving dimensions together in **one** drawing edit; it never uses model
|
||||
parameters or the model-only automatic reference-dimension fallback.
|
||||
|
||||
All of these retain the original shared sketcher, solver and constraint builders.
|
||||
Every edit uses the exact active drawing, sheet and sketch and is published
|
||||
only through `Session::edit_drawing`; the original model remains read-only.
|
||||
The model-only parameter-pruning calls after trim and break have been gated to
|
||||
model sketches. Fillet and tangent-circle radius expressions belong to the
|
||||
sheet constraint itself, are evaluated with the paper-mm default and can refer
|
||||
to existing source parameters without creating model parameters.
|
||||
|
||||
The bounded sheet format currently accepts splines only through degree five.
|
||||
Consequently G3/G4 blend requests are refused rather than stored in a format
|
||||
that cannot validate. Text links, arbitrary projected/reference links,
|
||||
pattern records, offset associations and 3D wires are still explicitly
|
||||
unavailable: admitting them requires their own bounded ownership/validation,
|
||||
resolution and persistence paths. They must not be silently discarded.
|
||||
|
||||
The non-live drag command represents **one completed gesture per call**.
|
||||
Intermediate `live: true` sheet frames and `sketch.drag_end` are not enabled:
|
||||
a reliable single-undo pointer gesture and the native/browser hit-test
|
||||
provider must be integrated by the established UI owner. This code does not
|
||||
add a parallel sheet canvas, navigation handler, command registration or
|
||||
a second solver.
|
||||
|
||||
The existing model command implementations and parameter semantics remain
|
||||
unchanged; `sketch.fillet` adds an `expression` output only in the sheet
|
||||
case. Model-only APIs and replies do not gain sheet-specific fields.
|
||||
W19 view-attached annotation dimensions, W38b view sketches, W38c
|
||||
projection, W38d saved fills and W38e images retain their separate owners.
|
||||
This slice does **not** certify complete W38a, native/browser editing,
|
||||
canonical model+sheet Cancel composition, K/store imports or full CI.
|
||||
Reference in new issue
Block a user