* claim: #8390 * Sketch modify: pick a whole profile or chain for the shared Entities input (#8390) - Click inside a closed profile selects its whole boundary (and its holes); double-click a curve selects its whole chain, for Mirror, Move/Copy, Scale and the patterns. Single curves and points keep working as before. - The mirror line may itself be among the entities: the command leaves the line in place and mirrors the rest, instead of rejecting it. * Mirror: the shared line case is valid, not an error (#8390) Update the half-filled-window test: a mirror line that is also among the entities is now accepted (the command leaves it in place and mirrors the rest), matching the engine. --------- Co-authored-by: Dane Doubell <2853036+danedoubell@users.noreply.github.com>
This commit is contained in:
@@ -36,7 +36,7 @@ use solidcraft_engine::sketch::PatternAlignment;
|
||||
|
||||
use crate::SolveApp;
|
||||
use crate::dialogs::{CHAMFER_TYPES, Dialog, Kind};
|
||||
use crate::selection::{AXES, CURVES, SKETCH_POINTS, SelInput};
|
||||
use crate::selection::{AXES, CURVES, PROFILES, SKETCH_POINTS, SelInput};
|
||||
use crate::tool_modifiers::{Audit, Scope, ToolModifiers};
|
||||
use crate::ui_kit;
|
||||
use crate::viewport::{Hit, Proj};
|
||||
@@ -185,21 +185,25 @@ impl Mod {
|
||||
|
||||
fn inputs(k: &Mod) -> Vec<SelInput> {
|
||||
match k {
|
||||
Mod::Scale { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS, true), SelInput::new("Base point", SKETCH_POINTS, false)],
|
||||
Mod::Scale { .. } => {
|
||||
vec![SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true), SelInput::new("Base point", SKETCH_POINTS, false)]
|
||||
}
|
||||
Mod::Offset { .. } => vec![SelInput::new("Curves", CURVES, true)],
|
||||
// AXES is the mask that takes a straight sketch curve (`selection::SelInput::accepts`).
|
||||
Mod::Mirror => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS, true), SelInput::new("Mirror line", AXES, false)],
|
||||
Mod::Move { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS, true), SelInput::new("Center", SKETCH_POINTS, false)],
|
||||
Mod::Transform { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS, true)],
|
||||
Mod::Mirror => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true), SelInput::new("Mirror line", AXES, false)],
|
||||
Mod::Move { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true), SelInput::new("Center", SKETCH_POINTS, false)],
|
||||
Mod::Transform { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true)],
|
||||
// The direction is optional: `sketch.pattern.rectangular` documents sketch x as its
|
||||
// default, the way the engine reads it.
|
||||
Mod::PatternRect { .. } => vec![
|
||||
SelInput::new("Entities", CURVES | SKETCH_POINTS, true),
|
||||
SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true),
|
||||
SelInput::new("Direction", AXES, false),
|
||||
SelInput::new("Direction 2", AXES, false),
|
||||
],
|
||||
// The centre is required: `sketch.pattern.circular` has no default for it.
|
||||
Mod::PatternCirc { .. } => vec![SelInput::new("Entities", CURVES | SKETCH_POINTS, true), SelInput::new("Center", SKETCH_POINTS, false)],
|
||||
Mod::PatternCirc { .. } => {
|
||||
vec![SelInput::new("Entities", CURVES | SKETCH_POINTS | PROFILES, true), SelInput::new("Center", SKETCH_POINTS, false)]
|
||||
}
|
||||
// A fillet rounds any number of corners to one radius (`points`). Each chamfer command
|
||||
// cuts one corner: its point, or its two lines. Two lines name the corner between them
|
||||
// where more lines meet at its point (#1824), for both.
|
||||
@@ -308,7 +312,7 @@ pub(crate) fn selected_equation(app: &SolveApp) -> Option<String> {
|
||||
pub fn candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) -> Option<Sel> {
|
||||
let active = session.active_sketch?;
|
||||
match hit {
|
||||
Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } if *sketch != active => None,
|
||||
Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } | Hit::Profile { sketch, .. } if *sketch != active => None,
|
||||
Hit::SketchCurve { id, .. } if matches!(d.kind, Kind::SketchModify(Mod::Corner { .. })) => {
|
||||
let state = session.world_state();
|
||||
let sk = &state.sketch(active)?.sketch;
|
||||
@@ -395,6 +399,50 @@ pub fn double_click_pattern(app: &mut SolveApp, pos: Pos2) -> bool {
|
||||
id.is_some_and(|id| edit_pattern(app, &id))
|
||||
}
|
||||
|
||||
/// Double-click a sketch curve to add its whole connected chain to the shared Entities input of
|
||||
/// Mirror, Move/Copy, Scale and the two patterns, as a profile click adds a whole closed region
|
||||
/// (#8390). The single-curve pick of the double-click's two clicks cancels itself out (each click
|
||||
/// toggles the same curve), so the chain toggle lands on the state before the double-click.
|
||||
pub fn double_click_entities(app: &mut SolveApp) -> bool {
|
||||
let Some(Hit::SketchCurve { sketch, id, .. }) = app.viewport.hover.clone() else {
|
||||
return false;
|
||||
};
|
||||
if app.session.active_sketch != Some(sketch) {
|
||||
return false;
|
||||
}
|
||||
let Some(dialog) = app.dialog.as_mut() else {
|
||||
return false;
|
||||
};
|
||||
// Only the commands whose first input is the shared Entities list take a chain here; Offset
|
||||
// has its own Chain option, and the corner tools take one corner at a time.
|
||||
let entities = matches!(
|
||||
&dialog.kind,
|
||||
Kind::SketchModify(
|
||||
Mod::Scale { .. } | Mod::Mirror | Mod::Move { .. } | Mod::Transform { .. } | Mod::PatternRect { .. } | Mod::PatternCirc { .. }
|
||||
)
|
||||
);
|
||||
if !entities || dialog.active != 0 {
|
||||
return false;
|
||||
}
|
||||
let Ok(v) = app.session.execute("sketch.chain", &json!({ "curve": id })) else {
|
||||
return false;
|
||||
};
|
||||
let items: Vec<Sel> = v["curves"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|c| c.as_str())
|
||||
.map(|id| Sel::SketchCurve { id: id.to_string(), sketch: None })
|
||||
.collect();
|
||||
if items.is_empty() {
|
||||
return false;
|
||||
}
|
||||
if let Some(input) = dialog.inputs.get_mut(0) {
|
||||
input.toggle(items);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Place a circular pattern centre in empty sketch space without creating a document point.
|
||||
pub fn pick_position(d: &mut Dialog, session: &solidcraft_engine::Session, point: Vec3) -> bool {
|
||||
if !matches!(d.kind, Kind::SketchModify(Mod::PatternCirc { .. })) || d.active != 1 {
|
||||
@@ -668,15 +716,26 @@ pub(crate) fn point_id<'a>(session: &solidcraft_engine::Session, sel: &'a Sel) -
|
||||
}
|
||||
}
|
||||
|
||||
/// The curves and lone points picked in input `i`, as the engine's `entities` list.
|
||||
/// The curves and lone points picked in input `i`, as the engine's `entities` list. A profile
|
||||
/// pick expands to every curve of its boundary and its holes (#8390).
|
||||
fn entity_ids(session: &solidcraft_engine::Session, inputs: &[SelInput], i: usize) -> Vec<String> {
|
||||
items(inputs, i)
|
||||
.iter()
|
||||
.filter_map(|x| match x {
|
||||
Sel::SketchCurve { id, .. } => Some(id.clone()),
|
||||
_ => point_id(session, x).map(str::to_string),
|
||||
})
|
||||
.collect()
|
||||
let mut out = Vec::new();
|
||||
for x in items(inputs, i) {
|
||||
match x {
|
||||
Sel::SketchCurve { id, .. } => out.push(id.clone()),
|
||||
Sel::Profile { sketch, index } => {
|
||||
if let Some(ids) = session.world_state().sketch(*sketch).and_then(|ss| ss.profiles.get(*index)).map(|p| p.curve_ids()) {
|
||||
out.extend(ids);
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if let Some(id) = point_id(session, x) {
|
||||
out.push(id.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Sketch curve ids picked in input `i`.
|
||||
@@ -889,9 +948,8 @@ pub fn commands(app: &SolveApp, k: &Mod, inputs: &[SelInput], extra: &Map<String
|
||||
Some(_) => return Err("The mirror line must be a straight curve of this sketch or an origin axis in its plane".into()),
|
||||
None => return Err("Select the mirror line".into()),
|
||||
};
|
||||
if line.as_str().is_some_and(|line| entities.iter().any(|entity| entity == line)) {
|
||||
return Err("The mirror line cannot also be mirrored".into());
|
||||
}
|
||||
// The mirror line may itself be among the entities (a chain or profile the user
|
||||
// picked in one action): the command leaves the line in place and mirrors the rest.
|
||||
("sketch.mirror", json!({"entities": entities, "line": line}))
|
||||
}
|
||||
Mod::Move { x, y, angle, copy } => {
|
||||
|
||||
@@ -232,12 +232,12 @@ fn a_half_filled_window_is_an_error_instead_of_a_command() {
|
||||
origin_axis[0].items = vec![Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
|
||||
origin_axis[1].items = vec![Sel::Axis { name: "Z".into() }];
|
||||
assert!(commands(&h.app, &Mod::Mirror, &origin_axis, &serde_json::Map::new()).is_err());
|
||||
// The line itself must not be in the entities: the old click flow could not express that
|
||||
// either, and the engine silently dropped it.
|
||||
// The mirror line may itself be among the entities (a chain or profile picked in one action):
|
||||
// the command leaves the line in place and mirrors the rest.
|
||||
let mut line_in_both = mirror_inputs();
|
||||
line_in_both[0].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
line_in_both[1].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
assert!(commands(&h.app, &Mod::Mirror, &line_in_both, &serde_json::Map::new()).is_err());
|
||||
assert_eq!(commands(&h.app, &Mod::Mirror, &line_in_both, &serde_json::Map::new()).unwrap()[0].1, json!({"entities": [ids[0]], "line": ids[0]}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -4536,6 +4536,11 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
.collect();
|
||||
let _ = app.run("select.set", json!({ "items": items, "add": add }));
|
||||
}
|
||||
// Double-click a curve while a Mirror/Move/Copy/Scale/pattern Entities input is open:
|
||||
// add the whole connected chain to that input (#8390).
|
||||
if resp.double_clicked() && !held && !dim_edit && app.tool.is_none() && app.dialog.is_some() {
|
||||
let _ = crate::sketch_modify_ui::double_click_entities(app);
|
||||
}
|
||||
// Double-click an edge: select the edges that continue it smoothly (the loop).
|
||||
if resp.double_clicked()
|
||||
&& !held
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
[
|
||||
{"note": "#8390: one click inside a closed profile selects its whole boundary for the shared Entities input; a double-click selects a curve's chain."},
|
||||
{"queued": "engine.execute", "params": {"command": "sketch.create", "params": {"plane": "XY"}}},
|
||||
{"queued": "engine.execute", "params": {"command": "sketch.rectangle.two_point", "params": {"p0": [0, 0], "p1": [40, 30]}}},
|
||||
{"queued": "engine.execute", "params": {"command": "sketch.line", "params": {"points": [[-10, -40], [-10, 40]]}}},
|
||||
{"expect": {"errors": 0, "sketch_curves": {"own": 5}}},
|
||||
|
||||
{"note": "Open Mirror; a single click inside the rectangle selects the whole profile."},
|
||||
{"start": "sketch.mirror"},
|
||||
{"expect": {"dialog": "SketchModify(Mirror"}},
|
||||
{"click": {"sketch": [20, 15]}},
|
||||
{"expect": {"dialog": "SketchModify(Mirror", "errors": 0}},
|
||||
|
||||
{"note": "Pick the line as the mirror line and OK: all four rectangle sides reflect (4 -> 8, plus the line)."},
|
||||
{"click": {"handle": "dialog:Mirror line"}},
|
||||
{"click": {"sketch": [-10, 0]}},
|
||||
{"click": {"handle": "dialog:OK"}},
|
||||
{"expect": {"dialog": null, "errors": 0, "sketch_curves": {"own": 9}}}
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{"note": "A mirror line that is itself among the entities (a chain or profile picked in one action) is not rejected: the command leaves the line in place and mirrors the rest."},
|
||||
{"queued": "engine.execute", "params": {"command": "sketch.create", "params": {"plane": "XY"}}},
|
||||
{"queued": "engine.execute", "params": {"command": "sketch.rectangle.two_point", "params": {"p0": [0, 0], "p1": [40, 30]}}},
|
||||
{"expect": {"errors": 0, "sketch_curves": {"own": 4}}},
|
||||
|
||||
{"note": "One click inside the rectangle selects the whole profile (including its left edge)."},
|
||||
{"start": "sketch.mirror"},
|
||||
{"click": {"sketch": [20, 15]}},
|
||||
{"expect": {"dialog": "SketchModify(Mirror"}},
|
||||
|
||||
{"note": "Pick the rectangle's own left edge as the mirror line and OK: the left edge stays put and the other three sides reflect (4 -> 7)."},
|
||||
{"click": {"handle": "dialog:Mirror line"}},
|
||||
{"click": {"sketch": [0, 15]}},
|
||||
{"click": {"handle": "dialog:OK"}},
|
||||
{"expect": {"dialog": null, "errors": 0, "sketch_curves": {"own": 7}}}
|
||||
]
|
||||
Reference in New Issue
Block a user