* claim: #8979 Co-authored-by: Cursor <cursoragent@cursor.com> * Sketch Trim: prefer free curves over projected edges (#8979). When Trim/Extend/Break is active, linked face edges yield to nearby drawn curves, and the refuse message names Break Link. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
a66a517c40
commit
d93b1cb282
3 files changed
+29
-3
No files matched your search
@@ -121,7 +121,13 @@ fn curve_arg(sk: &Sketch, p: &Value, cmd: &str) -> Result<usize> {
|
||||
fn curve_by_id(sk: &Sketch, id: &str, cmd: &str) -> Result<usize> {
|
||||
let c = sk.curve_index(id).ok_or_else(|| bad(cmd, format!("unknown curve `{id}`")))?;
|
||||
if sk.is_linked_curve(c) {
|
||||
return Err(bad(cmd, format!("`{id}` is projected geometry: break its link first")));
|
||||
let action = match cmd {
|
||||
"sketch.trim" => "Trim",
|
||||
"sketch.extend" => "Extend",
|
||||
"sketch.break" => "Break",
|
||||
_ => "edit",
|
||||
};
|
||||
return Err(bad(cmd, format!("`{id}` is projected from the model — use Break Link on it, then {action} again")));
|
||||
}
|
||||
if sk.freeform_offsets.iter().any(|offset| offset.output == id)
|
||||
|| sk.offsets.iter().filter_map(|offset| offset.topology.as_ref()).any(|topology| topology.roles.iter().any(|role| role.output == id))
|
||||
|
||||
@@ -259,6 +259,21 @@ fn break_link_makes_normal_geometry() {
|
||||
assert!(s.execute("sketch.break_link", &json!({"link": "j99"})).is_err());
|
||||
}
|
||||
|
||||
/// Trim refuses projected edges until Break Link; the message names that command (#8979).
|
||||
#[test]
|
||||
fn trim_refuses_projected_edges_until_break_link() {
|
||||
let mut s = Session::default();
|
||||
box_part(&mut s);
|
||||
let r = run(&mut s, "sketch.create", json!({"plane": {"face": [20, 15, 20]}}));
|
||||
let link = r["projected"].as_str().unwrap().to_string();
|
||||
let curve = linked_curves(&inspect(&mut s))[0]["id"].as_str().unwrap().to_string();
|
||||
let err = s.execute("sketch.trim", &json!({"curve": curve, "at": [20, 15]})).unwrap_err().to_string();
|
||||
assert!(err.contains("Break Link"), "{err}");
|
||||
assert!(err.contains("projected"), "{err}");
|
||||
run(&mut s, "sketch.break_link", json!({"link": link}));
|
||||
run(&mut s, "sketch.trim", json!({"curve": curve, "at": [20, 15]}));
|
||||
}
|
||||
|
||||
/// The sketch's curves as evaluated (after its links were refreshed): (id, construction).
|
||||
fn evaluated_curves(s: &Session, id: u64) -> Vec<(String, bool)> {
|
||||
s.model.state().sketch(id).unwrap().sketch.curves.iter().map(|c| (c.id.clone(), c.construction)).collect()
|
||||
|
||||
@@ -2446,19 +2446,24 @@ fn pick_hits(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool,
|
||||
let active = s.active_sketch == Some(sid);
|
||||
let bonus = if active { 2.0 } else { 0.0 };
|
||||
let tier = |own: bool| u8::from(!(active && own));
|
||||
// Trim / Extend / Break edit free curves; projected edges under the same click should
|
||||
// yield so a drawn rectangle on a face is not refused as projected geometry (#8979).
|
||||
let trim_prefers_free = app.tool.as_ref().is_some_and(|t| matches!(t.cmd, "sketch.trim" | "sketch.extend" | "sketch.break"));
|
||||
for (i, c) in ss.sketch.curves.iter().enumerate() {
|
||||
if !solidcraft_engine::view::sketch_curve_visible(&ss.sketch, i) {
|
||||
continue;
|
||||
}
|
||||
let straight = matches!(c.kind, CurveKind::Line { .. });
|
||||
let tier = tier(c.link.is_none() || ss.sketch.is_text_curve(i));
|
||||
let own = c.link.is_none() || ss.sketch.is_text_curve(i);
|
||||
let tier = tier(own);
|
||||
// Construction geometry lying on a regular curve yields to it (#6396); Select Other
|
||||
// still offers both.
|
||||
let helper = if c.construction || c.centerline { 0.5 } else { 0.0 };
|
||||
let linked_penalty = if trim_prefers_free && !own { 3.5 } else { 0.0 };
|
||||
for part in &crate::sketch_display::curve_sample(app, sid, i, &ss.plane, proj).parts {
|
||||
let pts: Vec<(Pos2, Vec3)> = part.iter().filter_map(|q| proj.to_screen(*q).map(|sp| (sp, *q))).collect();
|
||||
for w in pts.windows(2) {
|
||||
let dd = seg_dist(pos, w[0].0, w[1].0) - bonus + helper;
|
||||
let dd = seg_dist(pos, w[0].0, w[1].0) - bonus + helper + linked_penalty;
|
||||
if dd < 6.0 && bestc.wants((tier, dd)) {
|
||||
let point = ray_segment_closest(o, d, w[0].1, w[1].1);
|
||||
bestc.offer((tier, dd), Hit::SketchCurve { sketch: sid, id: c.id.clone(), straight, point });
|
||||
|
||||
Reference in new issue
Block a user