Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/engine/src/cmd/sketch_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,10 @@ fn offset_ladder(
Ok((sides, sources))
}

/// What the offset reply says when a distance names a parameter that drives nothing (#12294).
const UNLINKED_OFFSET: &str =
"the offset is trimmed and not linked to its source, so its distance expression does not drive it: changing the parameter will not move it";

fn offset(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "sketch.offset";
let ids = string_list(cmd, p, "curves")?;
Expand Down Expand Up @@ -3240,7 +3244,14 @@ fn offset(s: &mut Session, p: &Value) -> Result<Value> {
[(_, only)] => only.association.clone(),
_ => None,
};
reply(cmd, OffsetResult { curves, constraints, sketch: info, sides: each, param, instances, param2, association, param_warnings: Vec::new() })
// A trimmed offset (a spline with another curve) is not linked to its source, so a distance
// that names a parameter drives nothing: say so instead of leaving `param` null unexplained (#12294).
let ignored = |expression: &str, param: &Option<String>| param.is_none() && !solidcraft_doc::expr::references(expression).is_empty();
let warning = (ignored(&expression, &param) || expression2.as_deref().is_some_and(|e| ignored(e, &param2))).then(|| UNLINKED_OFFSET.to_string());
reply(
cmd,
OffsetResult { curves, constraints, sketch: info, sides: each, param, instances, param2, association, warning, param_warnings: Vec::new() },
)
}

fn break_offset(s: &mut Session, p: &Value) -> Result<Value> {
Expand Down
24 changes: 24 additions & 0 deletions crates/engine/src/cmd/sketch_modify_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5736,3 +5736,27 @@ fn split_failures_name_the_public_command() {
assert!(!text.contains("invalid parameters for `split`"), "{text}");
assert!(!text.contains("sketch.modify"), "{text}");
}

/// #12294: a spline offset together with a line is trimmed and unlinked, so a distance that names a
/// parameter drives nothing. The reply says so; a linked offset of the same parameter does not.
#[test]
fn an_unlinked_offset_says_its_parameter_drives_nothing() {
let mut s = new_sketch();
run(&mut s, "parameters.add", json!({"name": "wall", "expression": "1 mm"}));
let sp = ids(&run(&mut s, "sketch.spline.fit_point", json!({"points": [[-20, 0], [-10, 15], [10, 15], [20, 0]]}))["curves"])[0].clone();
run(&mut s, "sketch.line", json!({"points": [[20, 0], [-20, 0]]}));
let r = run(&mut s, "sketch.offset", json!({"curves": [sp], "distance": "wall", "side": [0, 5], "param": "w_in"}));
assert!(r["param"].is_null(), "{r}");
let warning = r["warning"].as_str().unwrap_or_default();
assert!(warning.contains("not linked to its source"), "{r}");
// A rectangle's offset is linked: its parameter drives it and nothing is said.
let mut s = new_sketch();
run(&mut s, "parameters.add", json!({"name": "wall", "expression": "1 mm"}));
let lines: Vec<String> = [[[0, 0], [20, 0]], [[20, 0], [20, 10]], [[20, 10], [0, 10]], [[0, 10], [0, 0]]]
.iter()
.map(|p| ids(&run(&mut s, "sketch.line", json!({"points": p}))["curves"])[0].clone())
.collect();
let r = run(&mut s, "sketch.offset", json!({"curves": lines, "distance": "wall", "side": [10, 5]}));
assert!(r["param"].is_string(), "{r}");
assert!(r.get("warning").is_none(), "{r}");
}
4 changes: 4 additions & 0 deletions crates/engine/src/schema/sketch_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ pub struct OffsetResult {
/// or several instances each side of `sides` has its own.
#[serde(skip_serializing_if = "Option::is_none")]
pub association: Option<String>,
/// Set when a distance that names a parameter drives nothing, because the offset was trimmed
/// and so is not linked to its source (#12294).
#[serde(skip_serializing_if = "Option::is_none")]
pub warning: Option<String>,
/// In the warn parameter-check mode: what the call's parameters got wrong.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub param_warnings: Vec<String>,
Expand Down
Loading