* Dialog curve picks keep their sketch (#3726) * Format Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Format Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Adapt context-menu test to Sel::SketchCurve's sketch field Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Path Flange picks keep their sketch too Path Flange (#4096) landed after this PR and still looked its path up in the newest sketch with those ids. --------- Co-authored-by: bherbruck <brennen.herbruck@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
48 files changed
+442
-320
No files matched your search
@@ -88,7 +88,7 @@ fn apply(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Sel::Occurrence { path } => {
|
||||
selected_occurrences.push(s.occurrence_placement(path)?.occurrence.to_string());
|
||||
}
|
||||
Sel::SketchCurve { id } | Sel::SketchPoint { id } | Sel::SketchConstraint { id } => entities.push(id.clone()),
|
||||
Sel::SketchCurve { id, .. } | Sel::SketchPoint { id } | Sel::SketchConstraint { id } => entities.push(id.clone()),
|
||||
Sel::Feature { id } => {
|
||||
if s.doc.feature(*id).is_none() {
|
||||
return Err(bad(cmd, format!("no feature {id}")));
|
||||
|
||||
@@ -342,7 +342,7 @@ fn describe(s: &Session, sel: &Sel) -> Option<Item> {
|
||||
let v = m.measure().volume;
|
||||
plain(Geo::Tris(tris), None, json!({"type": "body", "name": name, "closed": closed, "volume_mm3": closed.then_some(v)}))
|
||||
}
|
||||
Sel::SketchCurve { id } => sketch_curve(sketch_of(s, &st, None, |sk| sk.curve_index(id).is_some())?, id),
|
||||
Sel::SketchCurve { id, sketch } => sketch_curve(sketch_of(s, &st, *sketch, |sk| sk.curve_index(id).is_some())?, id),
|
||||
Sel::ExternalSketchCurve { sketch, id } => sketch_curve(sketch_of(s, &st, Some(*sketch), |_| true)?, id),
|
||||
Sel::SketchPoint { id } | Sel::ExternalSketchPoint { id, .. } => {
|
||||
let given = match sel {
|
||||
|
||||
@@ -78,7 +78,7 @@ fn chosen(s: &Session, p: &Value) -> Vec<String> {
|
||||
s.selection
|
||||
.iter()
|
||||
.filter_map(|sel| match sel {
|
||||
Sel::SketchCurve { id } | Sel::SketchPoint { id } => Some(id.clone()),
|
||||
Sel::SketchCurve { id, .. } | Sel::SketchPoint { id } => Some(id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
@@ -321,8 +321,11 @@ fn paste(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
// The pasted geometry is selected, ready to move.
|
||||
if s.active_sketch == Some(target) {
|
||||
s.selection =
|
||||
curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).chain(lone.iter().map(|id| Sel::SketchPoint { id: id.clone() })).collect();
|
||||
s.selection = curves
|
||||
.iter()
|
||||
.map(|id| Sel::SketchCurve { id: id.clone(), sketch: None })
|
||||
.chain(lone.iter().map(|id| Sel::SketchPoint { id: id.clone() }))
|
||||
.collect();
|
||||
}
|
||||
Ok(json!({"curves": curves, "points": lone, "constraints": constraints, "translate": [t.x, t.y], "sketch": info}))
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ fn copy_paste_keeps_internal_constraints_and_dimensions_and_drops_outside_ones()
|
||||
.and_then(|d| d.param.clone())
|
||||
.unwrap();
|
||||
// The paste is selected.
|
||||
let sel: Vec<_> = s.selection.iter().filter_map(|x| if let Sel::SketchCurve { id } = x { Some(id.clone()) } else { None }).collect();
|
||||
let sel: Vec<_> = s.selection.iter().filter_map(|x| if let Sel::SketchCurve { id, .. } = x { Some(id.clone()) } else { None }).collect();
|
||||
assert_eq!(sel, pasted);
|
||||
// The pasted rectangle is free to move (the original is held by the origin): dragging it moves it.
|
||||
run(&mut s, "sketch.drag", json!({"entity": pasted[0], "from": [p0[0].x, p0[0].y], "to": [p0[0].x + 5.0, p0[0].y + 5.0]}));
|
||||
@@ -138,8 +138,10 @@ fn every_kind_of_sketch_geometry_pastes() {
|
||||
all.push(point_id.clone());
|
||||
all.push(text_curve);
|
||||
// Copy from the selection, as Ctrl+C does.
|
||||
s.selection =
|
||||
all.iter().map(|id| if *id == point_id { Sel::SketchPoint { id: id.clone() } } else { Sel::SketchCurve { id: id.clone() } }).collect();
|
||||
s.selection = all
|
||||
.iter()
|
||||
.map(|id| if *id == point_id { Sel::SketchPoint { id: id.clone() } } else { Sel::SketchCurve { id: id.clone(), sketch: None } })
|
||||
.collect();
|
||||
run(&mut s, "sketch.copy", json!({}));
|
||||
let out = run(&mut s, "sketch.paste", json!({"translate": [0, 100]}));
|
||||
let sk = sketch(&s, sid);
|
||||
|
||||
@@ -114,9 +114,12 @@ pub enum Sel {
|
||||
Feature {
|
||||
id: u64,
|
||||
},
|
||||
/// A sketch curve or point (by id) of the active sketch.
|
||||
/// A sketch curve or point (by id) of the active sketch. A curve picked into a dialog also
|
||||
/// names its `sketch`: curve ids repeat from one sketch to the next (#3726).
|
||||
SketchCurve {
|
||||
id: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
sketch: Option<u64>,
|
||||
},
|
||||
SketchPoint {
|
||||
id: String,
|
||||
|
||||
@@ -1836,7 +1836,7 @@ fn a_huge_selection_is_counted_not_dropped_silently() {
|
||||
Sel::Edge { body: "Nope".into(), index: 7, point: solidcraft_engine::geom::Vec3::new(0.0, 0.0, 0.0) },
|
||||
Sel::Feature { id: u64::MAX },
|
||||
Sel::Plane { name: "XY".into() },
|
||||
Sel::SketchCurve { id: "c1".into() },
|
||||
Sel::SketchCurve { id: "c1".into(), sketch: None },
|
||||
];
|
||||
let described = context::describe(&mut session, &odd);
|
||||
assert_eq!(described.items.len(), 5);
|
||||
|
||||
@@ -34,7 +34,7 @@ fn a_loop_of_sketch_curves_is_the_loop_patch() {
|
||||
h.frames(3);
|
||||
assert!(h.widget("Cross curves").is_some() && h.widget("Continuity").is_some() && h.widget("Operation").is_some());
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = ["s1", "s2", "s3", "s4"].iter().map(|id| Sel::SketchCurve { id: (*id).into() }).collect();
|
||||
d.inputs[0].items = ["s1", "s2", "s3", "s4"].iter().map(|id| Sel::SketchCurve { id: (*id).into(), sketch: None }).collect();
|
||||
ok(&mut h);
|
||||
let f = h.app.session.doc.features.last().unwrap();
|
||||
let FeatureKind::SurfaceBoundary { curves, orders, .. } = &f.kind else { panic!("{:?}", f.kind) };
|
||||
@@ -68,7 +68,7 @@ fn edges_and_curves_make_a_network_and_come_back_in_an_edit() {
|
||||
h.step(&json!({"call":"ui.start","params":{"command":"surface.boundary"}})).unwrap();
|
||||
h.frames(3);
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![rim.clone(), Sel::SketchCurve { id: top.clone() }];
|
||||
d.inputs[0].items = vec![rim.clone(), Sel::SketchCurve { id: top.clone(), sketch: None }];
|
||||
let Kind::Surface(Surf::Boundary { continuity, join }) = &mut d.kind else { panic!("{:?}", d.kind) };
|
||||
*continuity = 2;
|
||||
*join = true;
|
||||
@@ -114,8 +114,8 @@ fn curves_that_meet_are_one_chain() {
|
||||
let sketch = h.app.session.doc.find_feature("Net").unwrap().id;
|
||||
let k = Surf::Boundary { continuity: 0, join: false };
|
||||
let (_, mut inputs) = crate::dialogs_surface::start(&h.app, "surface.boundary").unwrap();
|
||||
inputs[0].items = ["a2", "b", "a1"].iter().map(|id| Sel::SketchCurve { id: (*id).into() }).collect();
|
||||
inputs[1].items = ["c", "d"].iter().map(|id| Sel::SketchCurve { id: (*id).into() }).collect();
|
||||
inputs[0].items = ["a2", "b", "a1"].iter().map(|id| Sel::SketchCurve { id: (*id).into(), sketch: None }).collect();
|
||||
inputs[1].items = ["c", "d"].iter().map(|id| Sel::SketchCurve { id: (*id).into(), sketch: None }).collect();
|
||||
let cmds = crate::dialogs_surface::commands(&h.app, &k, &inputs, &Map::new()).unwrap();
|
||||
let (id, p) = &cmds[0];
|
||||
assert_eq!(id, "surface.boundary");
|
||||
|
||||
@@ -48,8 +48,11 @@ pub fn anchor(app: &SolveApp, d: &Dialog) -> Option<(Vec3, Option<Vec3>)> {
|
||||
Sel::Face { body, index, point } => (*point, crate::dialogs::planar_face(&app.session, body, *index).map(|(_, n)| n)),
|
||||
Sel::Edge { body, index, point } => (*point, st.body(body).and_then(|b| edge_bisector(&b.mesh(), *index, *point))),
|
||||
Sel::Vertex { point, .. } => (*point, None),
|
||||
Sel::SketchCurve { id } => {
|
||||
let ss = st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(id).is_some())?;
|
||||
Sel::SketchCurve { id, sketch } => {
|
||||
let ss = match sketch {
|
||||
Some(k) => st.sketch(*k)?,
|
||||
None => st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(id).is_some())?,
|
||||
};
|
||||
let pts = ss.sketch.polyline(ss.sketch.curve_index(id)?);
|
||||
let (mid, tangent) = poly_mid(&pts)?;
|
||||
// An offset's drag arrow: the in-plane direction the distance grows along. The
|
||||
|
||||
@@ -902,7 +902,7 @@ fn sketch_entity_items(app: &SolveApp) -> Vec<Item> {
|
||||
let mut picked: Vec<String> = Vec::new();
|
||||
for s in &app.session.selection {
|
||||
match s {
|
||||
Sel::SketchCurve { id } => {
|
||||
Sel::SketchCurve { id, .. } => {
|
||||
picked.push(id.clone());
|
||||
curves.push(id.clone());
|
||||
match ss.sketch.curve_index(id).and_then(|i| ss.sketch.curves.get(i)).map(|c| &c.kind) {
|
||||
@@ -1563,7 +1563,7 @@ pub(crate) fn commit_rename(app: &mut SolveApp, r: &Rename) {
|
||||
fn context_target_selected(selection: &[Sel], target: &Sel) -> bool {
|
||||
selection.iter().any(|selected| {
|
||||
crate::selection::same_item(selected, target)
|
||||
|| matches!((selected, target), (Sel::SketchCurve { id: a }, Sel::SketchMidpoint { id: b }) if a == b)
|
||||
|| matches!((selected, target), (Sel::SketchCurve { id: a, .. }, Sel::SketchMidpoint { id: b }) if a == b)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2091,7 +2091,7 @@ mod tests {
|
||||
// A non-dimension constraint, and a plain curve, get no toggle item.
|
||||
h.app.session.selection = vec![Sel::SketchConstraint { id: horiz }];
|
||||
assert!(!items(&h.app, &Target::Viewport).iter().any(|i| i.id == "sketch.toggle_driven"), "a horizontal constraint is not a dimension");
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: l }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: l, sketch: None }];
|
||||
assert!(!items(&h.app, &Target::Viewport).iter().any(|i| i.id == "sketch.toggle_driven"));
|
||||
}
|
||||
|
||||
@@ -2167,7 +2167,7 @@ mod tests {
|
||||
h.app.cam.distance = 60.0;
|
||||
h.settle();
|
||||
h.step(&json!({"click":{"world":[cut.x,cut.y,0]},"button":"right"})).unwrap();
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: output.clone() }]);
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: output.clone(), sketch: None }]);
|
||||
let menu = items(&h.app, &Target::Viewport);
|
||||
let item = menu.iter().find(|item| item.id == "sketch.offset.break").expect("offset line must offer Break Offset Association");
|
||||
assert_eq!(item.label, "Break Offset Association");
|
||||
|
||||
@@ -1227,7 +1227,7 @@ impl Dialog {
|
||||
return snap.place_at(s.world_state().sketch(*sketch)?.plane.to_world(*at));
|
||||
}
|
||||
// The snap looked the face under the cursor up already, planar or not.
|
||||
inp.accepts(h, |body, face| snap.and_then(|f| f.planar(body, face)).unwrap_or_else(|| planar_face(s, body, face).is_some()))
|
||||
inp.accepts(h, s.active_sketch, |body, face| snap.and_then(|f| f.planar(body, face)).unwrap_or_else(|| planar_face(s, body, face).is_some()))
|
||||
}
|
||||
|
||||
/// With automatic To Object enabled and profiles picked, a face or vertex off their plane,
|
||||
@@ -2046,7 +2046,7 @@ fn placement_row(d: &mut Dialog, ui: &mut egui::Ui, session: &Session) {
|
||||
|
||||
fn selection_label(s: &Session, item: &Sel) -> String {
|
||||
match item {
|
||||
Sel::SketchCurve { id } => id.clone(),
|
||||
Sel::SketchCurve { id, .. } => id.clone(),
|
||||
Sel::SketchPoint { id } => crate::sketch_modify_ui::point_id(s, item).unwrap_or(id).to_string(),
|
||||
Sel::Plane { name } | Sel::Axis { name } | Sel::Body { name } => name.clone(),
|
||||
Sel::Face { body, index, .. } => format!("{body} · face {index}"),
|
||||
@@ -2461,7 +2461,7 @@ fn auto_operation(app: &SolveApp, d: &mut Dialog) {
|
||||
fn picked_side(app: &SolveApp, d: &Dialog, first: &Sel) -> Option<usize> {
|
||||
let normal = match first {
|
||||
Sel::Profile { sketch, .. } => crate::canvas::profile_plane(app, *sketch)?.normal(),
|
||||
Sel::SketchCurve { id } => app.session.world_state().sketches.iter().rev().find(|ss| ss.sketch.curve_index(id).is_some())?.plane.normal(),
|
||||
Sel::SketchCurve { .. } => app.session.world_state().sketch(picks_sketch(app, std::slice::from_ref(first), None)?)?.plane.normal(),
|
||||
Sel::Face { .. } => return Some(0),
|
||||
_ => return None,
|
||||
};
|
||||
@@ -3437,7 +3437,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
let has_all = |id: u64| curves.iter().all(|c| st.sketch(id).is_some_and(|ss| ss.sketch.curve_index(c).is_some()));
|
||||
let sketch = match sketch.or(edited.map(u64::from)) {
|
||||
Some(id) if has_all(id) => id,
|
||||
_ => curves_sketch(app, &curves, None).ok_or("the curves must be in one sketch")?,
|
||||
_ => picks_sketch(app, sels(d, 0), None).ok_or("the curves must be in one sketch")?,
|
||||
};
|
||||
let mut wall_params = json!({"sketch": sketch, "thin": true, "curves": curves, "thickness": wall, "side": WALL_SIDES.get(*wall_side).copied().unwrap_or("center")});
|
||||
if *wall_side == 3 {
|
||||
@@ -3502,7 +3502,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
need(0, "profiles")?;
|
||||
let axis = match sels(d, 1).first() {
|
||||
Some(Sel::Axis { name }) => json!(name),
|
||||
Some(Sel::SketchCurve { id }) => json!(id),
|
||||
Some(Sel::SketchCurve { id, .. }) => json!(id),
|
||||
_ => stored_axis.clone().ok_or("select an axis")?,
|
||||
};
|
||||
let (sketch, idx) = profiles();
|
||||
@@ -3682,7 +3682,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
need(1, "the path")?;
|
||||
let (sketch, idx) = profiles();
|
||||
let path: Vec<String> = sels(d, 1).curve_ids();
|
||||
let path_sketch = curves_sketch(app, &path, sketch.as_u64()).ok_or("the path curves must be in one sketch")?;
|
||||
let path_sketch = picks_sketch(app, sels(d, 1), sketch.as_u64()).ok_or("the path curves must be in one sketch")?;
|
||||
let mut p = json!({"sketch": sketch, "profiles": idx, "path_sketch": path_sketch, "path": path, "operation": OPS.get(*operation).copied().unwrap_or("new")});
|
||||
crate::dialogs_sweep::params(app, opts, sels(d, 2).first(), [sels(d, 3), sels(d, 4)], &mut p)?;
|
||||
("solid.sweep", p)
|
||||
@@ -3726,7 +3726,8 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
Kind::PathPlane { t, sketch } => {
|
||||
need(0, "a path")?;
|
||||
let path = match sels(d, 0).first() {
|
||||
Some(Sel::SketchCurve { id }) => {
|
||||
Some(Sel::SketchCurve { id, sketch: Some(named) }) => json!({"sketch": named, "curve": id}),
|
||||
Some(Sel::SketchCurve { id, .. }) => {
|
||||
let st = app.session.world_state();
|
||||
let matches: Vec<u64> = st
|
||||
.sketches
|
||||
@@ -3762,7 +3763,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
Kind::Rib { web, thickness, depth, flip, normal } => {
|
||||
need(0, "open sketch curves")?;
|
||||
let curves = sels(d, 0).curve_ids();
|
||||
let sketch = curves_sketch(app, &curves, None).ok_or("the curves must be in one sketch")?;
|
||||
let sketch = picks_sketch(app, sels(d, 0), None).ok_or("the curves must be in one sketch")?;
|
||||
let mut p = json!({"sketch": sketch, "curves": curves, "thickness": thickness, "flip": flip});
|
||||
if *normal {
|
||||
p["direction"] = json!("normal");
|
||||
@@ -3827,7 +3828,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
need(0, "objects")?;
|
||||
need(1, "the path")?;
|
||||
let path = sels(d, 1).curve_ids();
|
||||
let sketch = curves_sketch(app, &path, None).ok_or("the path curves must be in one sketch")?;
|
||||
let sketch = picks_sketch(app, sels(d, 1), None).ok_or("the path curves must be in one sketch")?;
|
||||
let mut p = json!({"path_sketch": sketch, "path": path, "count": count, "spacing": spacing});
|
||||
pattern_objects(s, sels(d, 0), &mut p);
|
||||
("solid.pattern.path", p)
|
||||
@@ -3835,7 +3836,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
Kind::Pipe { wall, .. } => {
|
||||
need(0, "the path")?;
|
||||
let path = sels(d, 0).curve_ids();
|
||||
let sketch = curves_sketch(app, &path, None).ok_or("the path curves must be in one sketch")?;
|
||||
let sketch = picks_sketch(app, sels(d, 0), None).ok_or("the path curves must be in one sketch")?;
|
||||
let mut p = json!({"path_sketch": sketch, "path": path});
|
||||
put(&mut p, &[("wall", wall)]);
|
||||
("solid.pipe", p)
|
||||
@@ -3859,8 +3860,8 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
None => json!({"body": body, "tool": {"body": b, "point": pt(*point)}}),
|
||||
},
|
||||
// A straight sketch line, in the sketch it was picked in (#1552).
|
||||
Some(Sel::SketchCurve { id }) => {
|
||||
let picked = d.extra.get("tool_sketch").and_then(Value::as_u64);
|
||||
Some(Sel::SketchCurve { id, sketch: named }) => {
|
||||
let picked = named.or_else(|| d.extra.get("tool_sketch").and_then(Value::as_u64));
|
||||
let st = s.world_state();
|
||||
let holding: Vec<u64> = st.sketches.iter().filter(|ss| ss.sketch.curve_index(id).is_some()).map(|ss| ss.feature).collect();
|
||||
let sketch = match picked {
|
||||
@@ -4197,6 +4198,21 @@ fn source_features(s: &Session, bodies: &[String]) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// The sketch holding all these curve ids (the active sketch first, never `not`).
|
||||
/// The sketch the curve picks `sels` are in: the one they name (a curve of the sketch being edited
|
||||
/// names none), else the one [`curves_sketch`] finds for their ids. Curve ids repeat from one sketch
|
||||
/// to the next, so a named sketch wins (#3726); picks in different sketches, or only in `not`, have
|
||||
/// none.
|
||||
pub(crate) fn picks_sketch(app: &SolveApp, sels: &[Sel], not: Option<u64>) -> Option<u64> {
|
||||
let named: Vec<Option<u64>> = sels.iter().filter_map(|x| if let Sel::SketchCurve { sketch, .. } = x { Some(*sketch) } else { None }).collect();
|
||||
if named.iter().all(Option::is_none) {
|
||||
return curves_sketch(app, &sels.curve_ids(), not);
|
||||
}
|
||||
// A curve of the sketch being edited names none: it is in the active sketch.
|
||||
let active = app.session.active_sketch;
|
||||
let first = named.iter().find_map(|k| k.or(active))?;
|
||||
named.iter().all(|k| k.or(active) == Some(first)).then_some(first).filter(|k| Some(*k) != not)
|
||||
}
|
||||
|
||||
pub(crate) fn curves_sketch(app: &SolveApp, ids: &[String], not: Option<u64>) -> Option<u64> {
|
||||
let st = app.session.world_state();
|
||||
let has =
|
||||
@@ -4221,9 +4237,9 @@ pub fn axis_of(app: &SolveApp, sel: &Sel) -> Option<(Vec3, Vec3)> {
|
||||
// A construction axis.
|
||||
n => solidcraft_engine::view::construction_axes(&app.session).into_iter().find(|(_, an, _, _)| an == n).map(|(_, _, o, d)| (o, d)),
|
||||
},
|
||||
Sel::SketchCurve { id } => {
|
||||
Sel::SketchCurve { id, .. } => {
|
||||
let st = app.session.world_state();
|
||||
let sid = curves_sketch(app, std::slice::from_ref(id), None)?;
|
||||
let sid = picks_sketch(app, std::slice::from_ref(sel), None)?;
|
||||
let ss = st.sketch(sid)?;
|
||||
let (pa, pb) = if let Some(i) = ss.sketch.curve_index(id) {
|
||||
let c = ss.sketch.curves.get(i)?;
|
||||
@@ -4475,7 +4491,8 @@ fn construct_ref(app: &SolveApp, sel: &Sel) -> Result<Value, String> {
|
||||
Some((sketch, point)) => json!({"sketch": sketch, "point": point}),
|
||||
None => return Err("pick the point in the viewport".into()),
|
||||
},
|
||||
Sel::SketchCurve { id } => {
|
||||
Sel::SketchCurve { id, sketch: Some(sketch) } => json!({"sketch": sketch, "curve": id}),
|
||||
Sel::SketchCurve { id, .. } => {
|
||||
let st = app.session.world_state();
|
||||
let sketches: Vec<u64> = st
|
||||
.sketches
|
||||
@@ -4618,7 +4635,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
if let Some(thin) = thin {
|
||||
set_thin(&mut d.inputs, true);
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
inp.items = thin.curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inp.items = thin.curves.iter().map(|id| crate::selection::curve_pick(id, sketch.0, s.active_sketch)).collect();
|
||||
}
|
||||
} else {
|
||||
let items = st.sketch(sketch.0).map(|ss| profile_indices(ss, profiles)).unwrap_or_default();
|
||||
@@ -4662,7 +4679,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
let ax = match axis {
|
||||
AxisRef::World { axis } => Some(Sel::Axis { name: axis.to_ascii_uppercase() }),
|
||||
AxisRef::SketchAxis { axis } => Some(Sel::Axis { name: axis.to_ascii_lowercase() }),
|
||||
AxisRef::SketchLine { curve } => Some(Sel::SketchCurve { id: curve.clone() }),
|
||||
AxisRef::SketchLine { curve } => Some(crate::selection::curve_pick(curve, sketch.0, s.active_sketch)),
|
||||
AxisRef::Construction { name } => Some(Sel::Axis { name: name.to_string() }),
|
||||
_ => None,
|
||||
};
|
||||
@@ -5115,7 +5132,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
FeatureKind::Loft { sections, operation, targets, rails, rail_fit } => {
|
||||
let mut d = start("solid.loft")?;
|
||||
d.kind = Kind::Loft { operation: op_index(operation), rail_fit: crate::dialogs_sweep::rail_fit_index(*rail_fit) };
|
||||
for (inp, items) in d.inputs.iter_mut().skip(1).zip(crate::dialogs_sweep::rail_sels(rails)) {
|
||||
for (inp, items) in d.inputs.iter_mut().skip(1).zip(crate::dialogs_sweep::rail_sels(rails, s.active_sketch)) {
|
||||
inp.items = items;
|
||||
}
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
@@ -5132,14 +5149,14 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
}
|
||||
d
|
||||
}
|
||||
FeatureKind::Sweep { sketch, profiles, path, operation, targets, orientation, twist, scale, rails, rail_fit, .. } => {
|
||||
FeatureKind::Sweep { sketch, profiles, path_sketch, path, operation, targets, orientation, twist, scale, rails, rail_fit, .. } => {
|
||||
let mut d = start("solid.sweep")?;
|
||||
let (opts, direction) = crate::dialogs_sweep::SweepOpts::of(orientation, twist, scale, *rail_fit, &feature_frame(s, f.component));
|
||||
d.kind = Kind::Sweep { operation: op_index(operation), opts };
|
||||
if let Some(inp) = d.inputs.get_mut(2) {
|
||||
inp.items = direction.into_iter().collect();
|
||||
}
|
||||
for (inp, items) in d.inputs.iter_mut().skip(3).zip(crate::dialogs_sweep::rail_sels(rails)) {
|
||||
for (inp, items) in d.inputs.iter_mut().skip(3).zip(crate::dialogs_sweep::rail_sels(rails, s.active_sketch)) {
|
||||
inp.items = items;
|
||||
}
|
||||
let items = st.sketch(sketch.0).map(|ss| profile_indices(ss, profiles)).unwrap_or_default();
|
||||
@@ -5147,7 +5164,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
inp.items = items.into_iter().map(|index| Sel::Profile { sketch: sketch.0, index }).collect();
|
||||
}
|
||||
if let Some(inp) = d.inputs.get_mut(1) {
|
||||
inp.items = path.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inp.items = path.iter().map(|id| crate::selection::curve_pick(id, path_sketch.0, s.active_sketch)).collect();
|
||||
}
|
||||
if !targets.is_empty() {
|
||||
d.extra.insert("targets".into(), json!(targets));
|
||||
@@ -5175,7 +5192,9 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
FeatureKind::ConstructionPlane { plane: PlaneRef::AlongPath { path, t } } => {
|
||||
let mut d = start("construct.plane.along_path")?;
|
||||
let (item, sketch) = match path.as_ref() {
|
||||
solidcraft_engine::doc::construct::GeoRef::SketchCurve { sketch, curve } => (Sel::SketchCurve { id: curve.clone() }, Some(*sketch)),
|
||||
solidcraft_engine::doc::construct::GeoRef::SketchCurve { sketch, curve } => {
|
||||
(crate::selection::curve_pick(curve, *sketch, s.active_sketch), Some(*sketch))
|
||||
}
|
||||
solidcraft_engine::doc::construct::GeoRef::Edge { at, name } => {
|
||||
// Preserve the saved named reference until a replacement is picked.
|
||||
d.extra.insert("path".into(), json!({"type":"edge","at":pt3(*at),"name":name}));
|
||||
@@ -5225,7 +5244,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
if let (Some(k), Some(id)) = (sketch, line) {
|
||||
d.extra.insert("tool_sketch".into(), json!(k.0));
|
||||
if let Some(inp) = d.inputs.get_mut(1) {
|
||||
inp.items = vec![Sel::SketchCurve { id: id.clone() }];
|
||||
inp.items = vec![crate::selection::curve_pick(id, k.0, s.active_sketch)];
|
||||
}
|
||||
} else if let Some(inp) = d.inputs.get_mut(1) {
|
||||
inp.items = match tool {
|
||||
@@ -5283,11 +5302,11 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
}
|
||||
d
|
||||
}
|
||||
FeatureKind::Pipe { path, operation, targets, .. } => {
|
||||
FeatureKind::Pipe { path_sketch, path, operation, targets, .. } => {
|
||||
let mut d = start("solid.pipe")?;
|
||||
d.kind = Kind::simple_restore(&f.kind)?;
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
inp.items = path.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inp.items = path.iter().map(|id| crate::selection::curve_pick(id, path_sketch.0, s.active_sketch)).collect();
|
||||
}
|
||||
d.extra.insert("operation".into(), json!(OPS.get(op_index(operation)).copied().unwrap_or("new")));
|
||||
if !targets.is_empty() {
|
||||
@@ -5312,7 +5331,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
}
|
||||
d
|
||||
}
|
||||
FeatureKind::Rib { curves, thickness, depth, flip, web, normal, .. } => {
|
||||
FeatureKind::Rib { sketch, curves, thickness, depth, flip, web, normal, .. } => {
|
||||
let mut d = start(if *web { "solid.web" } else { "solid.rib" })?;
|
||||
d.kind = Kind::Rib {
|
||||
web: *web,
|
||||
@@ -5322,7 +5341,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
normal: *normal,
|
||||
};
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
inp.items = curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inp.items = curves.iter().map(|id| crate::selection::curve_pick(id, sketch.0, s.active_sketch)).collect();
|
||||
}
|
||||
d
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ fn representative(h: &Harness, command: &str) -> Dialog {
|
||||
} else if input.accept & crate::selection::SKETCH_LINES != 0 {
|
||||
vec![Sel::ExternalSketchCurve { sketch: s.world_state().sketches.last().unwrap().feature, id: path.clone() }]
|
||||
} else if input.accept & CURVES != 0 || command == "sheet.fold" && index == 0 {
|
||||
vec![Sel::SketchCurve { id: path.clone() }]
|
||||
vec![Sel::SketchCurve { id: path.clone(), sketch: None }]
|
||||
} else if input.accept & AXES != 0 {
|
||||
// The Revolve fixture's profile is in XY; its preview needs an axis in that plane.
|
||||
let axis = if command == "solid.revolve" { "Y" } else { "Z" };
|
||||
|
||||
@@ -119,14 +119,14 @@ pub fn commands(app: &SolveApp, m: &Member, inputs: &[SelInput], extra: &Map<Str
|
||||
let mut known = None;
|
||||
for pick in picks {
|
||||
match pick {
|
||||
Sel::ExternalSketchCurve { sketch, id } => {
|
||||
Sel::ExternalSketchCurve { sketch, id } | Sel::SketchCurve { id, sketch: Some(sketch) } => {
|
||||
if known.is_some_and(|k| k != *sketch) {
|
||||
return Err("the lines must be in one sketch".into());
|
||||
}
|
||||
known = Some(*sketch);
|
||||
lines.push(id.clone());
|
||||
}
|
||||
Sel::SketchCurve { id } => lines.push(id.clone()),
|
||||
Sel::SketchCurve { id, sketch: None } => lines.push(id.clone()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ fn body_names(app: &SolveApp) -> Vec<String> {
|
||||
|
||||
/// The dialog started with the given lines picked.
|
||||
fn dialog_on(app: &mut SolveApp, lines: &[String]) -> Dialog {
|
||||
app.session.selection = lines.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
app.session.selection = lines.iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
app.start("frame.member");
|
||||
app.dialog.clone().unwrap()
|
||||
}
|
||||
|
||||
@@ -523,38 +523,24 @@ fn path_chain(app: &SolveApp, inputs: &mut [SelInput]) {
|
||||
let edge = inputs.first().and_then(|i| i.items.edge_points().first().copied());
|
||||
let Some(input) = inputs.get_mut(1) else { return };
|
||||
let st = app.session.world_state();
|
||||
let mut chained: Vec<Sel> = Vec::new();
|
||||
for sel in &input.items {
|
||||
let Sel::SketchCurve { id } = sel else { continue };
|
||||
let ids = st
|
||||
.sketches
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|ss| {
|
||||
let ci = ss.sketch.curve_index(id)?;
|
||||
Some(
|
||||
ss.sketch
|
||||
.chain(ci)
|
||||
.into_iter()
|
||||
.filter_map(|c| ss.sketch.curves.get(c))
|
||||
.filter(|c| !c.construction)
|
||||
.map(|c| c.id.clone())
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| vec![id.clone()]);
|
||||
for id in ids {
|
||||
let sel = Sel::SketchCurve { id };
|
||||
if !chained.contains(&sel) {
|
||||
chained.push(sel);
|
||||
// The path is in the sketch its picks name (#3726).
|
||||
let Some(ss) = crate::dialogs::picks_sketch(app, &input.items, None).and_then(|k| st.sketch(k)) else { return };
|
||||
let mut ids: Vec<String> = Vec::new();
|
||||
for id in input.items.curve_ids() {
|
||||
let chain = match ss.sketch.curve_index(&id) {
|
||||
Some(ci) => {
|
||||
ss.sketch.chain(ci).into_iter().filter_map(|c| ss.sketch.curves.get(c)).filter(|c| !c.construction).map(|c| c.id.clone()).collect()
|
||||
}
|
||||
None => vec![id],
|
||||
};
|
||||
for id in chain {
|
||||
if !ids.contains(&id) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
// In order along the path, so the flanges read from the edge out.
|
||||
let ids: Vec<String> = chained.iter().filter_map(|sel| if let Sel::SketchCurve { id } = sel { Some(id.clone()) } else { None }).collect();
|
||||
if let Some(ss) = ids.first().and_then(|first| st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(first).is_some()))
|
||||
&& let Ok(mut order) = ss.chain_order(&ids)
|
||||
{
|
||||
if let Ok(mut order) = ss.chain_order(&ids) {
|
||||
// From the end nearer the picked edge.
|
||||
let near = |id: Option<&String>| {
|
||||
let segs = id.and_then(|id| ss.sketch.curve_index(id)).map(|ci| ss.sketch.segs(ci)).unwrap_or_default();
|
||||
@@ -564,8 +550,9 @@ fn path_chain(app: &SolveApp, inputs: &mut [SelInput]) {
|
||||
if near(order.last()) < near(order.first()) {
|
||||
order.reverse();
|
||||
}
|
||||
chained = order.into_iter().map(|id| Sel::SketchCurve { id }).collect();
|
||||
ids = order;
|
||||
}
|
||||
let chained: Vec<Sel> = ids.iter().map(|id| crate::selection::curve_pick(id, ss.feature, app.session.active_sketch)).collect();
|
||||
if chained != input.items {
|
||||
input.items = chained;
|
||||
}
|
||||
@@ -574,14 +561,14 @@ fn path_chain(app: &SolveApp, inputs: &mut [SelInput]) {
|
||||
/// The lengths of the path's lines, in the order picked (mm).
|
||||
fn path_lengths(app: &SolveApp, inputs: &[SelInput]) -> Vec<f64> {
|
||||
let st = app.session.world_state();
|
||||
items(inputs, 1)
|
||||
let picks = items(inputs, 1);
|
||||
let Some(ss) = crate::dialogs::picks_sketch(app, picks, None).and_then(|k| st.sketch(k)) else { return Vec::new() };
|
||||
picks
|
||||
.curve_ids()
|
||||
.iter()
|
||||
.filter_map(|sel| match sel {
|
||||
Sel::SketchCurve { id } => st.sketches.iter().rev().find_map(|ss| {
|
||||
let ci = ss.sketch.curve_index(id)?;
|
||||
Some(ss.sketch.segs(ci).iter().map(|s| s.start().dist(s.end())).sum())
|
||||
}),
|
||||
_ => None,
|
||||
.filter_map(|id| {
|
||||
let ci = ss.sketch.curve_index(id)?;
|
||||
Some(ss.sketch.segs(ci).iter().map(|s| s.start().dist(s.end())).sum())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -662,12 +649,9 @@ pub fn commands(app: &SolveApp, k: &Sm, inputs: &[SelInput], extra: &Map<String,
|
||||
2 => {
|
||||
let ids: Vec<String> = items(inputs, 0).curve_ids();
|
||||
let st = s.world_state();
|
||||
let sketch = st
|
||||
.sketches
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|ss| ids.iter().all(|id| ss.sketch.curve_index(id).is_some()))
|
||||
.map(|ss| ss.feature)
|
||||
let sketch = items(inputs, 0)
|
||||
.named_sketch()
|
||||
.or_else(|| st.sketches.iter().rev().find(|ss| ids.iter().all(|id| ss.sketch.curve_index(id).is_some())).map(|ss| ss.feature))
|
||||
.ok_or("pick lines of one sketch")?;
|
||||
json!({"type": "contour", "sketch": sketch, "curves": ids, "distance": distance, "reverse": reverse})
|
||||
}
|
||||
@@ -696,14 +680,10 @@ pub fn commands(app: &SolveApp, k: &Sm, inputs: &[SelInput], extra: &Map<String,
|
||||
Sm::Fold { radius, .. } => {
|
||||
let mut p = json!({});
|
||||
match items(inputs, 0).first() {
|
||||
Some(Sel::SketchCurve { id }) => {
|
||||
Some(Sel::SketchCurve { id, sketch: named }) => {
|
||||
let st = s.world_state();
|
||||
let sketch = st
|
||||
.sketches
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|ss| ss.sketch.curve_index(id).is_some())
|
||||
.map(|ss| ss.feature)
|
||||
let sketch = named
|
||||
.or_else(|| st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(id).is_some()).map(|ss| ss.feature))
|
||||
.ok_or("the line's sketch is gone")?;
|
||||
p["sketch"] = json!(sketch);
|
||||
p["curve"] = json!(id);
|
||||
@@ -720,17 +700,12 @@ pub fn commands(app: &SolveApp, k: &Sm, inputs: &[SelInput], extra: &Map<String,
|
||||
}
|
||||
Sm::Path { radius } => {
|
||||
let edge = edge_points(inputs).into_iter().next().ok_or("select the sheet edge first")?;
|
||||
let curves: Vec<String> = items(inputs, 1)
|
||||
.iter()
|
||||
.filter_map(|sel| match sel {
|
||||
Sel::SketchCurve { id } => Some(id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let first = curves.first().ok_or("select the path (sketch lines across the edge)")?;
|
||||
let st = s.world_state();
|
||||
let sketch =
|
||||
st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(first).is_some()).map(|ss| ss.feature).ok_or("the path's sketch is gone")?;
|
||||
let picks = items(inputs, 1);
|
||||
let curves = picks.curve_ids();
|
||||
if curves.is_empty() {
|
||||
return Err("select the path (sketch lines across the edge)".into());
|
||||
}
|
||||
let sketch = crate::dialogs::picks_sketch(app, picks, None).ok_or("the path's sketch is gone")?;
|
||||
let mut p = json!({"edge": edge, "sketch": sketch, "curves": curves});
|
||||
put(&mut p, &[("radius", radius)]);
|
||||
("sheet.path_flange", p)
|
||||
@@ -802,7 +777,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
}
|
||||
(f, ps.into_iter().map(|index| Sel::Profile { sketch: sketch.0, index }).collect())
|
||||
}
|
||||
FeatureKind::SheetContour { curves, distance, rule, flip, reverse, .. } => {
|
||||
FeatureKind::SheetContour { sketch, curves, distance, rule, flip, reverse, .. } => {
|
||||
let mut f = new_flange(app, 2);
|
||||
if let Sm::Flange { flip: fl, rule: r, distance: d, reverse: rv, .. } = &mut f {
|
||||
*fl = *flip;
|
||||
@@ -810,7 +785,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
*d = distance.to_string();
|
||||
*rv = *reverse;
|
||||
}
|
||||
(f, curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect())
|
||||
(f, curves.iter().map(|id| crate::selection::curve_pick(id, sketch.0, app.session.active_sketch)).collect())
|
||||
}
|
||||
FeatureKind::SheetFlange { edges, height, angle, radius, position, flip, body, corner_relief_shape, corner_relief, height_from } => {
|
||||
if let Some(b) = body {
|
||||
@@ -860,7 +835,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
}
|
||||
(Sm::simple_restore(kind)?, edges.iter().filter_map(|p| edge_sel(s, p.0)).collect())
|
||||
}
|
||||
FeatureKind::SheetFold { curve, a, b, fixed, body, .. } => {
|
||||
FeatureKind::SheetFold { sketch, curve, a, b, fixed, body, .. } => {
|
||||
if let Some(bd) = body {
|
||||
extra.insert("body".into(), json!(bd));
|
||||
}
|
||||
@@ -869,7 +844,10 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
match curve {
|
||||
Some(c) => {
|
||||
if let Some(i) = ins.first_mut() {
|
||||
i.items = vec![Sel::SketchCurve { id: c.clone() }];
|
||||
i.items = vec![match sketch {
|
||||
Some(k) => crate::selection::curve_pick(c, k.0, app.session.active_sketch),
|
||||
None => Sel::SketchCurve { id: c.clone(), sketch: None },
|
||||
}];
|
||||
}
|
||||
}
|
||||
// A fold given by two points keeps them.
|
||||
@@ -882,7 +860,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
}
|
||||
return Some((Kind::Sheet(k), ins, extra));
|
||||
}
|
||||
FeatureKind::SheetPath { edge, curves, body, .. } => {
|
||||
FeatureKind::SheetPath { edge, sketch, curves, body, .. } => {
|
||||
if let Some(bd) = body {
|
||||
extra.insert("body".into(), json!(bd));
|
||||
}
|
||||
@@ -892,7 +870,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind) -> Option<(Kind, Vec<SelI
|
||||
i.items = edge_sel(s, edge.0).into_iter().collect();
|
||||
}
|
||||
if let Some(i) = ins.get_mut(1) {
|
||||
i.items = curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
i.items = curves.iter().map(|id| crate::selection::curve_pick(id, sketch.0, app.session.active_sketch)).collect();
|
||||
}
|
||||
return Some((Kind::Sheet(k), ins, extra));
|
||||
}
|
||||
|
||||
@@ -858,6 +858,12 @@ fn path_flange_dialog_follows_the_path() {
|
||||
app.run("sketch.create", json!({"plane": {"origin": [0, 0, 15], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}, "name": "Path"})).unwrap();
|
||||
app.run("sketch.line", json!({"points": [[0, 0], [a, -a], [a + 30.0, -a]], "ids": ["p1", "p2"]})).unwrap();
|
||||
app.run("sketch.finish", json!({})).unwrap();
|
||||
let path = app.session.world_state().sketches.last().map(|ss| ss.feature);
|
||||
// A newer sketch with the same line ids: the picks name the path's sketch (#3726).
|
||||
app.run("sketch.create", json!({"plane": {"origin": [0, 0, 60], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}, "name": "Other"})).unwrap();
|
||||
app.run("sketch.line", json!({"points": [[50, 50], [60, 50], [60, 60]], "ids": ["p1", "p2"]})).unwrap();
|
||||
app.run("sketch.finish", json!({})).unwrap();
|
||||
let pick = |id: &str| Sel::SketchCurve { id: id.into(), sketch: path };
|
||||
let features = app.session.doc.features.len();
|
||||
app.start("sheet.path_flange");
|
||||
let mut d = app.dialog.clone().unwrap();
|
||||
@@ -865,16 +871,17 @@ fn path_flange_dialog_follows_the_path() {
|
||||
d.inputs[0].items = vec![edge_sel(&app.session, Vec3::new(1.25, 0.0, 15.0)).expect("the wall's end edge")];
|
||||
assert!(apply_commands(&app, &d).is_err(), "no path picked yet");
|
||||
// One line picked takes the whole path, and the dialog shows the flanges it makes.
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "p2".into() }];
|
||||
d.inputs[1].items = vec![pick("p2")];
|
||||
path_chain(&app, &mut d.inputs);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "p1".into() }, Sel::SketchCurve { id: "p2".into() }], "in order along the path");
|
||||
assert_eq!(d.inputs[1].items, vec![pick("p1"), pick("p2")], "in order along the path");
|
||||
let lengths = path_lengths(&app, &d.inputs);
|
||||
assert!(lengths.len() == 2 && lengths.iter().all(|l| (l - 30.0).abs() < 1e-6), "{lengths:?}");
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "p1".into() }, Sel::SketchCurve { id: "p2".into() }];
|
||||
d.inputs[1].items = vec![pick("p1"), pick("p2")];
|
||||
let c = apply_commands(&app, &d).unwrap();
|
||||
assert_eq!(c.len(), 1);
|
||||
assert_eq!(c[0].0, "sheet.path_flange");
|
||||
assert_eq!(c[0].1["curves"], json!(["p1", "p2"]));
|
||||
assert_eq!(c[0].1["sketch"], json!(path));
|
||||
run_all(&mut app, c);
|
||||
assert!(app.session.model.results.iter().all(|r| r.error.is_none()), "{:?}", app.session.model.results);
|
||||
assert_eq!(app.session.doc.features.len(), features + 1, "one feature");
|
||||
@@ -883,6 +890,7 @@ fn path_flange_dialog_follows_the_path() {
|
||||
let e = edit_dialog(&app, f.id, None).unwrap();
|
||||
assert!(matches!(&e.kind, Kind::Sheet(Sm::Path { .. })));
|
||||
assert_eq!((e.inputs[0].items.len(), e.inputs[1].items.len()), (1, 2));
|
||||
assert_eq!(e.inputs[1].items, vec![pick("p1"), pick("p2")], "the path's own sketch");
|
||||
assert!(apply_commands(&app, &e).is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ fn picked(h: &Harness, command: &str) -> Dialog {
|
||||
d.inputs[0].items = vec![if matches!(k, Mod::Corner { .. }) {
|
||||
Sel::SketchPoint { id: sk.points.iter().find(|p| p.id != "origin").unwrap().id.clone() }
|
||||
} else {
|
||||
Sel::SketchCurve { id: sk.curves[0].id.clone() }
|
||||
Sel::SketchCurve { id: sk.curves[0].id.clone(), sketch: None }
|
||||
}];
|
||||
if matches!(k, Mod::Mirror) {
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: sk.curves[3].id.clone() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: sk.curves[3].id.clone(), sketch: None }];
|
||||
}
|
||||
if matches!(k, Mod::PatternCirc { .. }) {
|
||||
d.inputs[1].items = vec![Sel::SketchPoint { id: "origin".into() }];
|
||||
@@ -133,11 +133,11 @@ fn picked_list_removes_one_item_and_field_still_activates_input() {
|
||||
let mut h = fixture();
|
||||
let mut d = picked(&h, "sketch.scale");
|
||||
let second = h.app.session.doc.sketch(1).unwrap().curves[1].id.clone();
|
||||
d.inputs[0].items.push(Sel::SketchCurve { id: second.clone() });
|
||||
d.inputs[0].items.push(Sel::SketchCurve { id: second.clone(), sketch: None });
|
||||
h.app.dialog = Some(d);
|
||||
h.frames(4);
|
||||
h.step(&json!({"click":{"handle":"dialog:list:Entities:0:remove"}})).unwrap();
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![Sel::SketchCurve { id: second }]);
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[0].items, vec![Sel::SketchCurve { id: second, sketch: None }]);
|
||||
h.step(&json!({"click":{"handle":"dialog:Base point"}})).unwrap();
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().active, 1);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ fn panel_dimension_preserves_expression_and_command_and_ok_closes() {
|
||||
fn text_and_text_move_cards_preserve_parameters_and_cancel_live_edits() {
|
||||
let mut h = fixture();
|
||||
let out = h.app.run("sketch.text", json!({"text":"II","at":[50,20],"height":8})).unwrap();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: out["curves"][0].as_str().unwrap().into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: out["curves"][0].as_str().unwrap().into(), sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
h.frames(4);
|
||||
card(&h);
|
||||
@@ -175,7 +175,7 @@ fn text_and_text_move_cards_preserve_parameters_and_cancel_live_edits() {
|
||||
h.step(&json!({"text":"Changed"})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:cancel"}})).unwrap();
|
||||
assert_eq!(h.app.session.doc.to_json(), before);
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: out["curves"][0].as_str().unwrap().into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: out["curves"][0].as_str().unwrap().into(), sketch: None }];
|
||||
h.app.start("sketch.move");
|
||||
h.frames(4);
|
||||
card(&h);
|
||||
|
||||
@@ -345,7 +345,7 @@ fn sheet_picks(app: &SolveApp, picks: &[Sel]) -> Result<Value, String> {
|
||||
let curves: Vec<String> = picks.curve_ids();
|
||||
let sketch = match profiles.first() {
|
||||
Some((sk, _)) => *sk,
|
||||
None => crate::dialogs::curves_sketch(app, &curves, None).ok_or("the curves must be in one sketch")?,
|
||||
None => crate::dialogs::picks_sketch(app, picks, None).ok_or("the curves must be in one sketch")?,
|
||||
};
|
||||
if profiles.iter().any(|(sk, _)| *sk != sketch) {
|
||||
return Err("the profiles and curves must be in one sketch".into());
|
||||
@@ -367,7 +367,7 @@ fn sheet_sels(app: &SolveApp, sketch: u64, profiles: Option<&ProfileSel>, curves
|
||||
(Some(sel), Some(ss)) => crate::dialogs::profile_indices(ss, sel).into_iter().map(|index| Sel::Profile { sketch, index }).collect(),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
sels.extend(curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }));
|
||||
sels.extend(curves.iter().map(|id| crate::selection::curve_pick(id, sketch, app.session.active_sketch)));
|
||||
sels
|
||||
}
|
||||
|
||||
@@ -400,8 +400,8 @@ fn chains(app: &SolveApp, picks: &[Sel]) -> Result<Vec<Chain>, String> {
|
||||
let mut parts: Vec<(Chain, [Vec3; 2])> = Vec::with_capacity(picks.len());
|
||||
for x in picks {
|
||||
match x {
|
||||
Sel::SketchCurve { id } => {
|
||||
let sketch = crate::dialogs::curves_sketch(app, std::slice::from_ref(id), None).ok_or("a picked curve is no longer in a sketch")?;
|
||||
Sel::SketchCurve { id, .. } => {
|
||||
let sketch = crate::dialogs::picks_sketch(app, std::slice::from_ref(x), None).ok_or("a picked curve is no longer in a sketch")?;
|
||||
let ss = st.sketch(sketch).ok_or("a picked curve's sketch has not been solved")?;
|
||||
let ends = if let Some(ci) = ss.sketch.curve_index(id) {
|
||||
let segs = ss.sketch.segs(ci);
|
||||
@@ -492,7 +492,7 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
let mut p = sheet_picks(app, items(inputs, 0))?;
|
||||
p["axis"] = match items(inputs, 1).first() {
|
||||
Some(Sel::Axis { name }) => json!(name),
|
||||
Some(Sel::SketchCurve { id }) => json!(id),
|
||||
Some(Sel::SketchCurve { id, .. }) => json!(id),
|
||||
_ => axis.clone().ok_or("select an axis")?,
|
||||
};
|
||||
p["angle"] = json!(angle);
|
||||
@@ -506,8 +506,9 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
need(1, "the path")?;
|
||||
let mut p = sheet_picks(app, items(inputs, 0))?;
|
||||
let path: Vec<String> = items(inputs, 1).curve_ids();
|
||||
p["path_sketch"] =
|
||||
json!(crate::dialogs::curves_sketch(app, &path, p["sketch"].as_u64()).ok_or("the path curves must be in one other sketch")?);
|
||||
p["path_sketch"] = json!(
|
||||
crate::dialogs::picks_sketch(app, items(inputs, 1), p["sketch"].as_u64()).ok_or("the path curves must be in one other sketch")?
|
||||
);
|
||||
p["path"] = json!(path);
|
||||
crate::dialogs_sweep::params(app, opts, items(inputs, 2).first(), [items(inputs, 3), items(inputs, 4)], &mut p)?;
|
||||
("surface.sweep", p)
|
||||
@@ -515,10 +516,9 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
Surf::Loft { rail_fit } => {
|
||||
need(0, "the sections, one sketch each")?;
|
||||
// One section per sketch, in the order the sketches were first picked.
|
||||
let st = app.session.world_state();
|
||||
let sketch_of = |x: &Sel| match x {
|
||||
Sel::Profile { sketch, .. } => Some(*sketch),
|
||||
Sel::SketchCurve { id } => st.sketches.iter().rev().find(|ss| ss.sketch.curve_index(id).is_some()).map(|ss| ss.feature),
|
||||
Sel::SketchCurve { .. } => crate::dialogs::picks_sketch(app, std::slice::from_ref(x), None),
|
||||
_ => None,
|
||||
};
|
||||
let mut order: Vec<u64> = Vec::new();
|
||||
@@ -569,7 +569,7 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
let sketch_ids: Vec<String> = picks.curve_ids();
|
||||
// Two to four sketch curves of one sketch and nothing across: the loop patch.
|
||||
let looped = across.is_empty() && !*join && sketch_ids.len() == picks.len() && (2..=4).contains(&picks.len());
|
||||
match looped.then(|| crate::dialogs::curves_sketch(app, &sketch_ids, None)).flatten() {
|
||||
match looped.then(|| crate::dialogs::picks_sketch(app, picks, None)).flatten() {
|
||||
Some(sk) => {
|
||||
let mut p = json!({"sketch": sk, "curves": sketch_ids});
|
||||
// Orders that differ from side to side (kept from the feature) stand as they are.
|
||||
@@ -725,7 +725,7 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
need(1, "the trimming tool")?;
|
||||
let picks = items(inputs, 1);
|
||||
let curves: Vec<String> =
|
||||
picks.iter().filter_map(|x| if let Sel::SketchCurve { id } = x { Some(id.clone()) } else { None }).collect();
|
||||
picks.iter().filter_map(|x| if let Sel::SketchCurve { id, .. } = x { Some(id.clone()) } else { None }).collect();
|
||||
if curves.is_empty() {
|
||||
let [one] = picks else { return Err("pick one plane or face as the tool, or sketch curves".into()) };
|
||||
let (key, t) = tool(app, Some(one))?;
|
||||
@@ -734,7 +734,7 @@ pub fn commands(app: &SolveApp, k: &Surf, inputs: &[SelInput], extra: &Map<Strin
|
||||
if curves.len() != picks.len() {
|
||||
return Err("trim by sketch curves, or by one plane or face".into());
|
||||
}
|
||||
let sketch = crate::dialogs::curves_sketch(app, &curves, None).ok_or("the curves must be in one sketch")?;
|
||||
let sketch = crate::dialogs::picks_sketch(app, picks, None).ok_or("the curves must be in one sketch")?;
|
||||
let mut c = json!({"sketch": sketch, "curves": curves});
|
||||
if let Some(d) = direction {
|
||||
c["direction"] = pt(*d);
|
||||
@@ -809,7 +809,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
let (pick, stored) = match axis {
|
||||
AxisRef::World { axis } => (Some(Sel::Axis { name: axis.to_ascii_uppercase() }), None),
|
||||
AxisRef::SketchAxis { axis } => (Some(Sel::Axis { name: axis.to_ascii_lowercase() }), None),
|
||||
AxisRef::SketchLine { curve } => (Some(Sel::SketchCurve { id: curve.clone() }), None),
|
||||
AxisRef::SketchLine { curve } => (Some(crate::selection::curve_pick(curve, sketch.0, s.active_sketch)), None),
|
||||
AxisRef::Construction { name } => (Some(Sel::Axis { name: name.to_string() }), None),
|
||||
AxisRef::Line { origin, dir } => (
|
||||
None,
|
||||
@@ -830,14 +830,14 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
}
|
||||
return Some((Kind::Surface(k), ins, extra));
|
||||
}
|
||||
FeatureKind::SurfaceSweep { sketch, profiles, curves, path, orientation, twist, scale, rails, rail_fit, .. } => {
|
||||
FeatureKind::SurfaceSweep { sketch, profiles, curves, path_sketch, path, orientation, twist, scale, rails, rail_fit, .. } => {
|
||||
let (opts, direction) = crate::dialogs_sweep::SweepOpts::of(orientation, twist, scale, *rail_fit, frame);
|
||||
let [rail, rail2] = crate::dialogs_sweep::rail_sels(rails);
|
||||
let [rail, rail2] = crate::dialogs_sweep::rail_sels(rails, s.active_sketch);
|
||||
(
|
||||
Surf::Sweep(opts),
|
||||
vec![
|
||||
sheet_sels(app, sketch.0, profiles.as_ref(), curves),
|
||||
path.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect(),
|
||||
path.iter().map(|id| crate::selection::curve_pick(id, path_sketch.0, s.active_sketch)).collect(),
|
||||
direction.into_iter().collect(),
|
||||
rail,
|
||||
rail2,
|
||||
@@ -860,7 +860,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
}
|
||||
return Some((Kind::Surface(k), ins, extra));
|
||||
}
|
||||
FeatureKind::SurfaceBoundary { curves, orders, crown, samples, .. } => {
|
||||
FeatureKind::SurfaceBoundary { sketch, curves, orders, crown, samples, .. } => {
|
||||
let first = orders.first().copied().unwrap_or(solidcraft_engine::doc::kernel::Continuity::G1);
|
||||
let index = PATCH_CONTINUITY.iter().position(|(_, w)| *w == first.as_str());
|
||||
// What the dialog does not show is kept as it was: a crown, the stations, and orders
|
||||
@@ -878,7 +878,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
let k = Surf::Boundary { continuity: index.unwrap_or(1), join: false };
|
||||
let mut ins = inputs(&k);
|
||||
if let Some(inp) = ins.first_mut() {
|
||||
inp.items = curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inp.items = curves.iter().map(|id| crate::selection::curve_pick(id, sketch.0, s.active_sketch)).collect();
|
||||
}
|
||||
return Some((Kind::Surface(k), ins, extra));
|
||||
}
|
||||
@@ -890,7 +890,14 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
let sels = |list: &[solidcraft_engine::doc::NetworkCurve]| -> Vec<Sel> {
|
||||
list.iter()
|
||||
.flat_map(|c| {
|
||||
let mut out: Vec<Sel> = c.curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
let mut out: Vec<Sel> = c
|
||||
.curves
|
||||
.iter()
|
||||
.map(|id| match c.sketch {
|
||||
Some(k) => crate::selection::curve_pick(id, k.0, s.active_sketch),
|
||||
None => Sel::SketchCurve { id: id.clone(), sketch: None },
|
||||
})
|
||||
.collect();
|
||||
out.extend(c.edges.iter().filter_map(edge));
|
||||
out
|
||||
})
|
||||
@@ -901,7 +908,7 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
(Surf::Boundary { continuity: index, join: *operation == solidcraft_engine::doc::Operation::Join }, vec![sels(u), sels(v)])
|
||||
}
|
||||
FeatureKind::SurfaceLoft { sections, rails, rail_fit, .. } => {
|
||||
let [rail, rail2] = crate::dialogs_sweep::rail_sels(rails);
|
||||
let [rail, rail2] = crate::dialogs_sweep::rail_sels(rails, s.active_sketch);
|
||||
let picked = sections.iter().flat_map(|sec| sheet_sels(app, sec.sketch.0, sec.profiles.as_ref(), &sec.curves)).collect();
|
||||
(Surf::Loft { rail_fit: crate::dialogs_sweep::rail_fit_index(*rail_fit) }, vec![picked, rail, rail2])
|
||||
}
|
||||
@@ -1027,10 +1034,17 @@ pub fn for_feature(app: &SolveApp, kind: &FeatureKind, frame: &Mat) -> Option<(K
|
||||
(None, Some(c)) if c.curves.is_empty() => {
|
||||
let st = s.world_state();
|
||||
st.sketch(c.sketch.0)
|
||||
.map(|ss| ss.sketch.curves.iter().filter(|k| !k.construction).map(|k| Sel::SketchCurve { id: k.id.clone() }).collect())
|
||||
.map(|ss| {
|
||||
ss.sketch
|
||||
.curves
|
||||
.iter()
|
||||
.filter(|k| !k.construction)
|
||||
.map(|k| crate::selection::curve_pick(&k.id, c.sketch.0, s.active_sketch))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
(None, Some(c)) => c.curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect(),
|
||||
(None, Some(c)) => c.curves.iter().map(|id| crate::selection::curve_pick(id, c.sketch.0, s.active_sketch)).collect(),
|
||||
(None, None) => tool_sel(app, plane, tool.as_ref()).into_iter().collect(),
|
||||
};
|
||||
(
|
||||
|
||||
@@ -93,9 +93,10 @@ pub fn rail_inputs() -> [SelInput; 2] {
|
||||
[SelInput::new("Rail", CURVES, true), SelInput::new("Second Rail", CURVES, true)]
|
||||
}
|
||||
|
||||
/// A feature's stored rails as the rail inputs' selections.
|
||||
pub fn rail_sels(rails: &[SweepRail]) -> [Vec<Sel>; 2] {
|
||||
let sels = |i: usize| rails.get(i).map(|r| r.curves.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect()).unwrap_or_default();
|
||||
/// A feature's stored rails as the rail inputs' selections (`active`: the sketch being edited).
|
||||
pub fn rail_sels(rails: &[SweepRail], active: Option<u64>) -> [Vec<Sel>; 2] {
|
||||
let sels =
|
||||
|i: usize| rails.get(i).map(|r| r.curves.iter().map(|id| crate::selection::curve_pick(id, r.sketch.0, active)).collect()).unwrap_or_default();
|
||||
[sels(0), sels(1)]
|
||||
}
|
||||
|
||||
@@ -137,7 +138,7 @@ pub fn rail_params(app: &SolveApp, fit: usize, rails: [&[Sel]; 2], p: &mut Value
|
||||
if curves.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let sketch = crate::dialogs::curves_sketch(app, &curves, None).ok_or("each rail's curves must be in one sketch")?;
|
||||
let sketch = crate::dialogs::picks_sketch(app, sels, None).ok_or("each rail's curves must be in one sketch")?;
|
||||
given.push(json!({"sketch": sketch, "curves": curves}));
|
||||
}
|
||||
if given.is_empty() {
|
||||
|
||||
@@ -34,7 +34,7 @@ fn sketch_selection(app: &SolveApp) -> Vec<String> {
|
||||
.selection
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
Sel::SketchCurve { id } | Sel::SketchPoint { id } => Some(id.clone()),
|
||||
Sel::SketchCurve { id, .. } | Sel::SketchPoint { id } => Some(id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -128,7 +128,7 @@ fn ctrl_c_ctrl_v_pastes_the_sketch_selection_at_the_cursor_selected_in_one_undo_
|
||||
assert!(start(&h, &rect[0]).dist(Vec2::ZERO) < 1e-9);
|
||||
// Selected, ready to move.
|
||||
let selected: Vec<String> =
|
||||
h.app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id } = s { Some(id.clone()) } else { None }).collect();
|
||||
h.app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id, .. } = s { Some(id.clone()) } else { None }).collect();
|
||||
assert_eq!(selected, pasted);
|
||||
// One undo step.
|
||||
assert_eq!(h.app.session.undo.len(), undo + 1);
|
||||
|
||||
@@ -1216,7 +1216,7 @@ impl SolveApp {
|
||||
| "sketch.constraint.tangent"
|
||||
| "sketch.constraint.concentric"
|
||||
| "sketch.constraint.collinear"
|
||||
) && let [solidcraft_engine::Sel::SketchCurve { id: a }, solidcraft_engine::Sel::SketchCurve { id: b }] =
|
||||
) && let [solidcraft_engine::Sel::SketchCurve { id: a, .. }, solidcraft_engine::Sel::SketchCurve { id: b, .. }] =
|
||||
self.session.selection.as_slice()
|
||||
&& a != b
|
||||
{
|
||||
@@ -1233,7 +1233,7 @@ impl SolveApp {
|
||||
.selection
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
solidcraft_engine::Sel::SketchCurve { id } | solidcraft_engine::Sel::SketchPoint { id } => Some(id.clone()),
|
||||
solidcraft_engine::Sel::SketchCurve { id, .. } | solidcraft_engine::Sel::SketchPoint { id } => Some(id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.take(2)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use crate::dialogs::Kind;
|
||||
use crate::dialogs_surface::Surf;
|
||||
use crate::scenario::Harness;
|
||||
use crate::viewport::Hit;
|
||||
use serde_json::json;
|
||||
use solidcraft_engine::Sel;
|
||||
use solidcraft_engine::doc::{FeatureKind, RailFit, SketchId, SweepRail};
|
||||
@@ -37,7 +38,7 @@ fn a_rail_picked_in_the_loft_dialog_is_kept_through_an_edit() {
|
||||
assert!(h.widget("Rail").is_some() && h.widget("Rail Fit").is_some());
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch: base, index: 0 }, Sel::Profile { sketch: top, index: 0 }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "out".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "out".into(), sketch: None }];
|
||||
let Kind::Loft { rail_fit, .. } = &mut d.kind else { panic!("{:?}", d.kind) };
|
||||
*rail_fit = 1;
|
||||
ok(&mut h);
|
||||
@@ -52,7 +53,7 @@ fn a_rail_picked_in_the_loft_dialog_is_kept_through_an_edit() {
|
||||
h.step(&json!({"call":"ui.editFeature","params":{"feature":name}})).unwrap();
|
||||
h.frames(8);
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "out".into() }]);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "out".into(), sketch: Some(rail_sketch) }]);
|
||||
assert!(matches!(d.kind, Kind::Loft { rail_fit: 1, .. }), "{:?}", d.kind);
|
||||
ok(&mut h);
|
||||
assert_eq!(rails(&h), (stored, fit));
|
||||
@@ -67,7 +68,7 @@ fn a_rail_picked_in_the_surface_loft_dialog_is_kept_through_an_edit() {
|
||||
assert!(h.widget("Rail").is_some() && h.widget("Rail Fit").is_some());
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch: base, index: 0 }, Sel::Profile { sketch: top, index: 0 }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "out".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "out".into(), sketch: None }];
|
||||
ok(&mut h);
|
||||
let name = h.app.session.doc.features.last().unwrap().name.clone();
|
||||
let rails = |h: &Harness| match &h.app.session.doc.find_feature(&name).unwrap().kind {
|
||||
@@ -79,7 +80,50 @@ fn a_rail_picked_in_the_surface_loft_dialog_is_kept_through_an_edit() {
|
||||
h.frames(8);
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert!(matches!(d.kind, Kind::Surface(Surf::Loft { rail_fit: 0 })), "{:?}", d.kind);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "out".into() }]);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "out".into(), sketch: Some(rail_sketch) }]);
|
||||
ok(&mut h);
|
||||
assert_eq!(rails(&h).0.len(), 1);
|
||||
}
|
||||
|
||||
/// Curve ids repeat from one sketch to the next (#3726). Rails `out` in two sketches each reach
|
||||
/// the loft from their own sketch, not both from the newest one with an `out`; and two sketches'
|
||||
/// lines `l` both stay in Surface Loft's sections, the second pick not taking the first back out.
|
||||
#[test]
|
||||
fn curves_that_share_an_id_are_picked_from_their_own_sketches() {
|
||||
let mut h = Harness::new();
|
||||
let (base, top, right) = setup(&mut h);
|
||||
h.app.run("sketch.create", json!({"plane": "XZ", "name": "L"})).unwrap();
|
||||
h.app.run("sketch.arc.three_point", json!({"start": [-10, 0], "end": [-10, -40], "through": [-15, -20], "id": "out"})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
let left = h.app.session.doc.find_feature("L").unwrap().id;
|
||||
let hit = |sketch: u64, id: &str| Hit::SketchCurve { sketch, id: id.into(), straight: false };
|
||||
h.step(&json!({"call":"ui.start","params":{"command":"solid.loft"}})).unwrap();
|
||||
h.frames(3);
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch: base, index: 0 }, Sel::Profile { sketch: top, index: 0 }];
|
||||
for (input, sketch) in [(1, right), (2, left)] {
|
||||
d.active = input;
|
||||
let pick = d.candidate_on(&h.app.session, &hit(sketch, "out"), None).unwrap();
|
||||
d.pick(&h.app.session, pick);
|
||||
}
|
||||
let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(commands[0].1["rails"], json!([{"sketch": right, "curves": ["out"]}, {"sketch": left, "curves": ["out"]}]));
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
|
||||
for (name, z) in [("Low", 0), ("High", 40)] {
|
||||
h.app.run("sketch.create", json!({"name": name, "plane": {"origin": [0, 0, z], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}})).unwrap();
|
||||
h.app.run("sketch.line", json!({"points": [[-10, 0], [10, 0]], "ids": ["l"]})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
}
|
||||
let (low, high) = (h.app.session.doc.find_feature("Low").unwrap().id, h.app.session.doc.find_feature("High").unwrap().id);
|
||||
h.step(&json!({"call":"ui.start","params":{"command":"surface.loft"}})).unwrap();
|
||||
h.frames(3);
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
for sketch in [low, high] {
|
||||
let pick = d.candidate_on(&h.app.session, &hit(sketch, "l"), None).unwrap();
|
||||
d.pick(&h.app.session, pick);
|
||||
}
|
||||
assert_eq!(d.inputs[0].items.len(), 2, "{:?}", d.inputs[0].items);
|
||||
let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(commands[0].1["sections"], json!([{"sketch": low, "curves": ["l"]}, {"sketch": high, "curves": ["l"]}]));
|
||||
}
|
||||
@@ -47,7 +47,7 @@ fn measure_dialog_shows_the_obtuse_corner_of_selected_lines() {
|
||||
h.app.home.open = false;
|
||||
h.app.run("sketch.create", json!({"plane": "XY"})).unwrap();
|
||||
h.app.run("sketch.line", json!({"points": [[40, 0], [0, 0], [-24, 32]]})).unwrap();
|
||||
h.app.session.selection = ["l1", "l2"].into_iter().map(|id| Sel::SketchCurve { id: id.into() }).collect();
|
||||
h.app.session.selection = ["l1", "l2"].into_iter().map(|id| Sel::SketchCurve { id: id.into(), sketch: None }).collect();
|
||||
h.app.start("inspect.measure");
|
||||
for layout in ["floating", "compact"] {
|
||||
h.call("ui.set", json!({"layout": layout}));
|
||||
@@ -67,7 +67,7 @@ fn measurement_axis_distances_follow_the_upstream_centre_min_and_max_choices() {
|
||||
let mut items = Vec::new();
|
||||
for (center, radius) in [([0, 0], 3), ([30, 40], 5)] {
|
||||
let made = h.app.run("sketch.circle.center", json!({"center":center,"radius":radius})).unwrap();
|
||||
items.push(Sel::SketchCurve { id: made["curves"][0].as_str().unwrap().into() });
|
||||
items.push(Sel::SketchCurve { id: made["curves"][0].as_str().unwrap().into(), sketch: None });
|
||||
}
|
||||
h.app.session.selection = items;
|
||||
h.app.start("inspect.measure");
|
||||
|
||||
@@ -810,9 +810,9 @@ fn line_and_profile_then_revolve_routes_each() {
|
||||
{"command": "sketch.line", "params": {"points": [[0, 0], [0, 30]], "ids": ["axis"]}},
|
||||
]));
|
||||
let sk = app.session.active_sketch.unwrap();
|
||||
let d = start(&mut app, vec![Sel::SketchCurve { id: "axis".into() }, Sel::Profile { sketch: sk, index: 0 }], "solid.revolve");
|
||||
let d = start(&mut app, vec![Sel::SketchCurve { id: "axis".into(), sketch: None }, Sel::Profile { sketch: sk, index: 0 }], "solid.revolve");
|
||||
assert_eq!(d.inputs[0].items, vec![Sel::Profile { sketch: sk, index: 0 }]);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "axis".into() }]);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "axis".into(), sketch: None }]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1646,7 +1646,7 @@ fn surface_extrude_dialog_takes_profiles_and_curves() {
|
||||
]));
|
||||
let sk = app.session.doc.features.last().unwrap().id;
|
||||
let mut d = start(&mut app, vec![], "surface.extrude");
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch: sk, index: 0 }, Sel::SketchCurve { id: "free".into() }];
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch: sk, index: 0 }, Sel::SketchCurve { id: "free".into(), sketch: None }];
|
||||
let (id, p) = apply_commands(&app, &d).unwrap().remove(0);
|
||||
assert_eq!(id, "surface.extrude");
|
||||
assert_eq!(p["curves"], json!(["free"]), "{p}");
|
||||
@@ -1698,7 +1698,7 @@ fn surface_revolve_dialog_takes_curves_and_an_axis() {
|
||||
{"command": "sketch.finish", "params": {}}
|
||||
]));
|
||||
let mut d = start(&mut app, vec![], "surface.revolve");
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "side".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "side".into(), sketch: None }];
|
||||
assert!(apply_commands(&app, &d).is_err(), "no axis yet");
|
||||
d.inputs[1].items = vec![Sel::Axis { name: "y".into() }];
|
||||
if let Kind::Surface(crate::dialogs_surface::Surf::Revolve { angle, .. }) = &mut d.kind {
|
||||
@@ -1712,7 +1712,8 @@ fn surface_revolve_dialog_takes_curves_and_an_axis() {
|
||||
assert!((area - want).abs() < want * 2e-3, "{area} vs {want}");
|
||||
let fid = app.session.doc.features.last().unwrap().id;
|
||||
let back = crate::dialogs::for_feature(&app, fid, None).unwrap();
|
||||
assert_eq!(back.inputs[0].items, vec![Sel::SketchCurve { id: "side".into() }]);
|
||||
// Editing brings the curves back from the sketch the feature is built on.
|
||||
assert_eq!(back.inputs[0].items, vec![Sel::SketchCurve { id: "side".into(), sketch: Some(1) }]);
|
||||
assert_eq!(back.inputs[1].items, vec![Sel::Axis { name: "y".into() }]);
|
||||
}
|
||||
|
||||
@@ -1729,9 +1730,9 @@ fn surface_sweep_dialog_takes_curves_and_a_path() {
|
||||
{"command": "sketch.finish", "params": {}}
|
||||
]));
|
||||
let mut d = start(&mut app, vec![], "surface.sweep");
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l".into(), sketch: None }];
|
||||
assert!(apply_commands(&app, &d).is_err(), "no path yet");
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into(), sketch: None }];
|
||||
let (id, p) = apply_commands(&app, &d).unwrap().remove(0);
|
||||
assert_eq!((id.as_str(), &p["path"], &p["curves"]), ("surface.sweep", &json!(["up"]), &json!(["l"])), "{p}");
|
||||
assert_ne!(p["path_sketch"], p["sketch"], "{p}");
|
||||
@@ -1740,8 +1741,8 @@ fn surface_sweep_dialog_takes_curves_and_a_path() {
|
||||
assert!((area - 50.0).abs() < 1e-6, "{area}");
|
||||
let fid = app.session.doc.features.last().unwrap().id;
|
||||
let back = crate::dialogs::for_feature(&app, fid, None).unwrap();
|
||||
assert_eq!(back.inputs[0].items, vec![Sel::SketchCurve { id: "l".into() }]);
|
||||
assert_eq!(back.inputs[1].items, vec![Sel::SketchCurve { id: "up".into() }]);
|
||||
assert_eq!(back.inputs[0].items, vec![Sel::SketchCurve { id: "l".into(), sketch: Some(1) }]);
|
||||
assert_eq!(back.inputs[1].items, vec![Sel::SketchCurve { id: "up".into(), sketch: Some(2) }]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1758,9 +1759,9 @@ fn surface_loft_dialog_makes_a_section_per_sketch() {
|
||||
{"command": "sketch.finish", "params": {}}
|
||||
]));
|
||||
let mut d = start(&mut app, vec![], "surface.loft");
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "a".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "a".into(), sketch: None }];
|
||||
assert!(apply_commands(&app, &d).is_err(), "one section");
|
||||
d.inputs[0].items.push(Sel::SketchCurve { id: "b".into() });
|
||||
d.inputs[0].items.push(Sel::SketchCurve { id: "b".into(), sketch: None });
|
||||
let (id, p) = apply_commands(&app, &d).unwrap().remove(0);
|
||||
assert_eq!(id, "surface.loft");
|
||||
assert_eq!(p["sections"].as_array().map(Vec::len), Some(2), "{p}");
|
||||
@@ -1770,7 +1771,10 @@ fn surface_loft_dialog_makes_a_section_per_sketch() {
|
||||
assert!((area - 50.0).abs() < 1e-6, "{area}");
|
||||
let fid = app.session.doc.features.last().unwrap().id;
|
||||
let back = crate::dialogs::for_feature(&app, fid, None).unwrap();
|
||||
assert_eq!(back.inputs[0].items, vec![Sel::SketchCurve { id: "a".into() }, Sel::SketchCurve { id: "b".into() }]);
|
||||
assert_eq!(
|
||||
back.inputs[0].items,
|
||||
vec![Sel::SketchCurve { id: "a".into(), sketch: Some(2) }, Sel::SketchCurve { id: "b".into(), sketch: Some(3) }]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1833,7 +1837,7 @@ fn trim_dialog_takes_curves_several_keep_points_and_another_surface() {
|
||||
let mut d = start(&mut app, vec![], "surface.trim");
|
||||
assert_eq!(d.inputs.len(), 5);
|
||||
d.inputs[0].items = vec![Sel::Body { name: "Floor".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "c1".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "c1".into(), sketch: None }];
|
||||
// Two places on the one face both count (a face pick would toggle the face off).
|
||||
d.inputs[2].toggle(vec![face("Floor", [1.0, 5.0, 0.0])]);
|
||||
d.inputs[2].toggle(vec![face("Floor", [-5.0, 5.0, 0.0])]);
|
||||
|
||||
@@ -243,7 +243,7 @@ pub fn label(app: &SolveApp, sel: &Sel) -> String {
|
||||
format!("MID · {}", app.session.active_sketch.map(|s| in_sketch(s, &|sk| curve_label(sk, id))).unwrap_or_else(|| id.clone()))
|
||||
}
|
||||
Sel::SketchPoint { id } => app.session.active_sketch.map(|s| in_sketch(s, &|sk| point_label(sk, id))).unwrap_or_else(|| id.clone()),
|
||||
Sel::SketchCurve { id } => app.session.active_sketch.map(|s| in_sketch(s, &|sk| curve_label(sk, id))).unwrap_or_else(|| id.clone()),
|
||||
Sel::SketchCurve { id, .. } => app.session.active_sketch.map(|s| in_sketch(s, &|sk| curve_label(sk, id))).unwrap_or_else(|| id.clone()),
|
||||
Sel::ExternalSketchPoint { sketch, id } => format!("{} · {}", in_sketch(*sketch, &|sk| point_label(sk, id)), sketch_name(app, *sketch)),
|
||||
Sel::ExternalSketchCurve { sketch, id } => format!("{} · {}", in_sketch(*sketch, &|sk| curve_label(sk, id)), sketch_name(app, *sketch)),
|
||||
Sel::SketchConstraint { id } => format!("Constraint {id}"),
|
||||
@@ -275,7 +275,7 @@ fn icon(app: &SolveApp, sel: &Sel) -> &'static str {
|
||||
};
|
||||
match sel {
|
||||
Sel::SketchPoint { .. } | Sel::SketchMidpoint { .. } | Sel::ExternalSketchPoint { .. } | Sel::Vertex { .. } => "point",
|
||||
Sel::SketchCurve { id } => curve(app.session.active_sketch, id),
|
||||
Sel::SketchCurve { id, .. } => curve(app.session.active_sketch, id),
|
||||
Sel::ExternalSketchCurve { sketch, id } => curve(Some(*sketch), id),
|
||||
Sel::SketchConstraint { .. } => "dimension",
|
||||
Sel::Edge { .. } => "fillet",
|
||||
|
||||
@@ -25,7 +25,7 @@ fn labels(h: &Harness) -> Vec<String> {
|
||||
}
|
||||
|
||||
fn curves(h: &Harness) -> Vec<String> {
|
||||
h.app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id } = s { Some(id.clone()) } else { None }).collect()
|
||||
h.app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id, .. } = s { Some(id.clone()) } else { None }).collect()
|
||||
}
|
||||
|
||||
/// Two lines of the sketch's own apart from each other (`l1` on x 0–15, `l2` on x 25–40, at
|
||||
@@ -49,7 +49,7 @@ fn two_lines_apart() -> (Harness, Value, Value) {
|
||||
fn row_of(h: &Harness, id: &str) -> usize {
|
||||
let rows = crate::select_other::describe(&h.app)["rows"].clone();
|
||||
let sels: Vec<Sel> = rows.as_array().into_iter().flatten().filter_map(|r| serde_json::from_value(r["sel"].clone()).ok()).collect();
|
||||
sels.iter().position(|s| matches!(s, Sel::SketchCurve { id: x } if x == id)).unwrap_or_else(|| panic!("no row for {id}: {rows}"))
|
||||
sels.iter().position(|s| matches!(s, Sel::SketchCurve { id: x, .. } if x == id)).unwrap_or_else(|| panic!("no row for {id}: {rows}"))
|
||||
}
|
||||
|
||||
fn sorted(mut v: Vec<String>) -> Vec<String> {
|
||||
|
||||
@@ -92,8 +92,9 @@ impl SelInput {
|
||||
self
|
||||
}
|
||||
|
||||
/// The selection a hit stands for, if this input accepts it.
|
||||
pub fn accepts(&self, h: &Hit, planar: impl Fn(&str, usize) -> bool) -> Option<Sel> {
|
||||
/// The selection a hit stands for, if this input accepts it. A curve of another sketch than
|
||||
/// the `active` one names its sketch: curve ids repeat from one sketch to the next (#3726).
|
||||
pub fn accepts(&self, h: &Hit, active: Option<u64>, planar: impl Fn(&str, usize) -> bool) -> Option<Sel> {
|
||||
let a = self.accept;
|
||||
match h {
|
||||
Hit::Profile { sketch, index } if a & PROFILES != 0 => Some(Sel::Profile { sketch: *sketch, index: *index }),
|
||||
@@ -104,9 +105,9 @@ impl SelInput {
|
||||
Hit::Face { body, .. } if a & BODIES != 0 => Some(Sel::Body { name: body.clone() }),
|
||||
Hit::Plane { name, .. } if a & PLANES != 0 => Some(Sel::Plane { name: name.clone() }),
|
||||
Hit::Axis { name } if a & AXES != 0 => Some(Sel::Axis { name: name.clone() }),
|
||||
Hit::SketchCurve { id, straight: true, .. } if a & AXES != 0 => Some(Sel::SketchCurve { id: id.clone() }),
|
||||
Hit::SketchCurve { sketch, id, straight: true, .. } if a & AXES != 0 => Some(curve_pick(id, *sketch, active)),
|
||||
Hit::SketchCurve { sketch, id, .. } if a & SKETCH_LINES != 0 => Some(Sel::ExternalSketchCurve { sketch: *sketch, id: id.clone() }),
|
||||
Hit::SketchCurve { id, .. } if a & CURVES != 0 => Some(Sel::SketchCurve { id: id.clone() }),
|
||||
Hit::SketchCurve { sketch, id, .. } if a & CURVES != 0 => Some(curve_pick(id, *sketch, active)),
|
||||
Hit::SketchPoint { sketch, id, .. } if a & EXTERNAL_POINTS != 0 => Some(Sel::ExternalSketchPoint { sketch: *sketch, id: id.clone() }),
|
||||
Hit::SketchPoint { id, .. } if a & SKETCH_POINTS != 0 => Some(Sel::SketchPoint { id: id.clone() }),
|
||||
Hit::SketchPoint { sketch, id, .. } if a & POINTS != 0 => Some(Sel::SketchPoint { id: format!("{sketch}:{id}") }),
|
||||
@@ -144,10 +145,18 @@ impl SelInput {
|
||||
}
|
||||
}
|
||||
|
||||
/// A sketch curve as a dialog's pick. A curve of another sketch than the `active` one names its
|
||||
/// sketch: curve ids repeat from one sketch to the next (#3726).
|
||||
pub(crate) fn curve_pick(id: &str, sketch: u64, active: Option<u64>) -> Sel {
|
||||
Sel::SketchCurve { id: id.to_string(), sketch: (active != Some(sketch)).then_some(sketch) }
|
||||
}
|
||||
|
||||
/// Projections preserve pick order and repetitions; callers own any deduplication or frames.
|
||||
pub(crate) trait SelectionExt {
|
||||
fn body_names(&self) -> Vec<String>;
|
||||
fn curve_ids(&self) -> Vec<String>;
|
||||
/// The sketch every curve pick names, when they all name the same one (#3726).
|
||||
fn named_sketch(&self) -> Option<u64>;
|
||||
fn profiles(&self) -> Vec<(u64, usize)>;
|
||||
fn edge_points(&self) -> Vec<Vec3>;
|
||||
fn face_points(&self) -> Vec<Vec3>;
|
||||
@@ -158,7 +167,12 @@ impl SelectionExt for [Sel] {
|
||||
self.iter().filter_map(|x| if let Sel::Body { name } = x { Some(name.clone()) } else { None }).collect()
|
||||
}
|
||||
fn curve_ids(&self) -> Vec<String> {
|
||||
self.iter().filter_map(|x| if let Sel::SketchCurve { id } = x { Some(id.clone()) } else { None }).collect()
|
||||
self.iter().filter_map(|x| if let Sel::SketchCurve { id, .. } = x { Some(id.clone()) } else { None }).collect()
|
||||
}
|
||||
fn named_sketch(&self) -> Option<u64> {
|
||||
let mut named = self.iter().filter_map(|x| if let Sel::SketchCurve { sketch, .. } = x { Some(*sketch) } else { None });
|
||||
let first = named.next()??;
|
||||
named.all(|k| k == Some(first)).then_some(first)
|
||||
}
|
||||
fn profiles(&self) -> Vec<(u64, usize)> {
|
||||
self.iter().filter_map(|x| if let Sel::Profile { sketch, index } = x { Some((*sketch, *index)) } else { None }).collect()
|
||||
@@ -337,10 +351,10 @@ mod tests {
|
||||
inp.toggle(vec![e(2), e(3)]);
|
||||
assert_eq!(inp.items, vec![e(1)]);
|
||||
let face = Hit::Face { body: "B".into(), index: 0, point: Vec3::ZERO };
|
||||
assert!(inp.accepts(&face, |_, _| true).is_none());
|
||||
assert!(inp.accepts(&face, None, |_, _| true).is_none());
|
||||
let planes = SelInput::new("Plane", PLANES | PLANAR_FACES, false);
|
||||
assert!(planes.accepts(&face, |_, _| true).is_some());
|
||||
assert!(planes.accepts(&face, |_, _| false).is_none());
|
||||
assert!(planes.accepts(&face, None, |_, _| true).is_some());
|
||||
assert!(planes.accepts(&face, None, |_, _| false).is_none());
|
||||
let mut one = SelInput::new("Plane", PLANES, false);
|
||||
one.toggle(vec![Sel::Plane { name: "XY".into() }]);
|
||||
one.toggle(vec![Sel::Plane { name: "YZ".into() }]);
|
||||
|
||||
@@ -62,7 +62,9 @@ fn dialog_curves(h: &crate::scenario::Harness) -> Vec<String> {
|
||||
.dialog
|
||||
.as_ref()
|
||||
.and_then(|d| d.inputs.first())
|
||||
.map(|i| i.items.iter().filter_map(|x| if let solidcraft_engine::Sel::SketchCurve { id } = x { Some(id.clone()) } else { None }).collect())
|
||||
.map(|i| {
|
||||
i.items.iter().filter_map(|x| if let solidcraft_engine::Sel::SketchCurve { id, .. } = x { Some(id.clone()) } else { None }).collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -150,7 +152,7 @@ fn derived_offset_context_action_releases_geometry_and_undo_restores() {
|
||||
h.app.run("sketch.ellipse", json!({"center":[0,0],"major":[10,0],"minor_radius":5})).unwrap();
|
||||
let out = h.app.run("sketch.offset", json!({"curves":["e1"],"distance":-1,"chain":false})).unwrap();
|
||||
let id = out["curves"][0].as_str().unwrap().to_string();
|
||||
h.app.session.selection = vec![solidcraft_engine::Sel::SketchCurve { id: id.clone() }];
|
||||
h.app.session.selection = vec![solidcraft_engine::Sel::SketchCurve { id: id.clone(), sketch: None }];
|
||||
let items = crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport);
|
||||
let item = items.iter().find(|item| item.id == "sketch.offset.break").unwrap();
|
||||
assert_eq!(item.params, Some(json!({"curve":id})));
|
||||
|
||||
@@ -78,7 +78,7 @@ fn pixel_circle_fit_exact_half_chord_hover_click_and_model_invariance() {
|
||||
h.app.viewport.hover
|
||||
);
|
||||
h.step(&json!({"click":{"world":[world.x,world.y,world.z]}})).unwrap();
|
||||
assert!(h.app.session.selection.iter().any(|s| matches!(s, solidcraft_engine::Sel::SketchCurve{id} if id == "c1")));
|
||||
assert!(h.app.session.selection.iter().any(|s| matches!(s, solidcraft_engine::Sel::SketchCurve{id, ..} if id == "c1")));
|
||||
h.app.session.selection.clear();
|
||||
}
|
||||
assert_eq!(h.app.session.doc.to_json(), baseline, "display and selection must not alter stored geometry, constraints or expressions");
|
||||
@@ -216,7 +216,7 @@ fn pixel_curve_second_nested_rotated_occurrence_uses_its_world_plane() {
|
||||
assert!(dense_circle_error(&path, &ss.plane, &proj, 1.0, h.app.viewport.pixels_per_point()) <= 1.0);
|
||||
let world = ss.plane.to_world(Vec2::new(0.8090169943749475, 0.5877852522924731));
|
||||
h.step(&json!({"click":{"world":[world.x,world.y,world.z]}})).unwrap();
|
||||
assert!(h.app.session.selection.iter().any(|s| matches!(s, solidcraft_engine::Sel::SketchCurve{id} if id == "c1")));
|
||||
assert!(h.app.session.selection.iter().any(|s| matches!(s, solidcraft_engine::Sel::SketchCurve{id, ..} if id == "c1")));
|
||||
assert_eq!(h.app.session.doc.to_json(), baseline);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ fn dragging_a_selected_line_moves_the_whole_selection() {
|
||||
let mut selected: Vec<usize> = lines.iter().flat_map(|l| before.curves[before.curve_index(l).unwrap()].kind.point_ids()).collect();
|
||||
selected.sort_unstable();
|
||||
selected.dedup();
|
||||
h.app.session.selection = lines.iter().map(|l| Sel::SketchCurve { id: (*l).into() }).collect();
|
||||
h.app.session.selection = lines.iter().map(|l| Sel::SketchCurve { id: (*l).into(), sketch: None }).collect();
|
||||
h.app.session.selection.extend(selected.iter().map(|&p| Sel::SketchPoint { id: before.points[p].id.clone() }));
|
||||
h.call("ui.view", json!({"view": "top"}));
|
||||
h.app.cam.distance = 150.0;
|
||||
@@ -357,7 +357,7 @@ fn a_window_selected_circle_still_takes_its_radius_from_a_drag_on_its_edge() {
|
||||
run(&mut h, "sketch.create", json!({"plane": "XY"}));
|
||||
run(&mut h, "sketch.circle.center", json!({"center": [20, 20], "radius": 10, "id": "c1"}));
|
||||
// A window around the circle picks it and its centre: not a group to move.
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "c1".into() }, Sel::SketchPoint { id: "c1.center".into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "c1".into(), sketch: None }, Sel::SketchPoint { id: "c1.center".into() }];
|
||||
h.call("ui.view", json!({"view": "top"}));
|
||||
h.app.cam.distance = 150.0;
|
||||
h.frames(3);
|
||||
|
||||
@@ -140,7 +140,7 @@ fn sketch_dialog_box_selection_adds_replaces_and_preserves_reference() {
|
||||
h.app.dialog.as_ref().unwrap().inputs[0]
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|s| if let Sel::SketchCurve { id } = s { Some(id.clone()) } else { None })
|
||||
.filter_map(|s| if let Sel::SketchCurve { id, .. } = s { Some(id.clone()) } else { None })
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(sources(&h), vec!["l1", "l2"]);
|
||||
@@ -148,7 +148,7 @@ fn sketch_dialog_box_selection_adds_replaces_and_preserves_reference() {
|
||||
assert_eq!(sources(&h), vec!["l1", "l2", "l4"]);
|
||||
step(&mut h, json!({"drag":[{"sketch":[-32,8]},{"sketch":[-13,12]}]}));
|
||||
assert_eq!(sources(&h), vec!["l1"]);
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items, vec![Sel::SketchCurve { id: "l3".into() }]);
|
||||
assert_eq!(h.app.dialog.as_ref().unwrap().inputs[1].items, vec![Sel::SketchCurve { id: "l3".into(), sketch: None }]);
|
||||
step(&mut h, json!({"key":"Escape"}));
|
||||
step(&mut h, json!({"start":"sketch.offset"}));
|
||||
step(&mut h, json!({"drag":[{"sketch":[-32,8]},{"sketch":[-13,27]}]}));
|
||||
@@ -170,12 +170,12 @@ fn sketch_modify_inputs_refuse_other_sketches_without_changing_hole_points() {
|
||||
}
|
||||
let input = crate::selection::SelInput::new("Hole points", crate::selection::POINTS, true);
|
||||
assert_eq!(
|
||||
input.accepts(&Hit::SketchPoint { sketch: 2, id: "p1".into(), at: solidcraft_engine::geom::Vec2::ZERO }, |_, _| false),
|
||||
input.accepts(&Hit::SketchPoint { sketch: 2, id: "p1".into(), at: solidcraft_engine::geom::Vec2::ZERO }, None, |_, _| false),
|
||||
Some(Sel::SketchPoint { id: "2:p1".into() })
|
||||
);
|
||||
h.app.start("sketch.pattern.circular");
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l1".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchPoint { id: "2:p1".into() }];
|
||||
assert!(crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).is_err());
|
||||
}
|
||||
@@ -194,12 +194,12 @@ fn sketch_preselected_points_toggle_once_and_empty_shift_box_keeps_reference() {
|
||||
d.pick(&h.app.session, selected);
|
||||
assert!(d.inputs[0].items.is_empty(), "clicking a preselection removes it instead of duplicating it");
|
||||
d.active = 1;
|
||||
let reference = Sel::SketchCurve { id: "l3".into() };
|
||||
let reference = Sel::SketchCurve { id: "l3".into(), sketch: None };
|
||||
d.pick(&h.app.session, reference.clone());
|
||||
d.take_box(&h.app.session, Vec::new(), true);
|
||||
assert_eq!(d.inputs[1].items, vec![reference]);
|
||||
d.take_box(&h.app.session, vec![Sel::SketchCurve { id: "l1".into() }, Sel::SketchCurve { id: "l2".into() }], true);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "l1".into() }], "a box replaces a single reference with one item");
|
||||
d.take_box(&h.app.session, vec![Sel::SketchCurve { id: "l1".into(), sketch: None }, Sel::SketchCurve { id: "l2".into(), sketch: None }], true);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "l1".into(), sketch: None }], "a box replaces a single reference with one item");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -254,7 +254,7 @@ fn sketch_modify_keeps_custom_point_ids_that_contain_colons() {
|
||||
h.app.run("sketch.point", json!({"point":[-40,0],"id":"2:centre"})).unwrap();
|
||||
h.app.start("sketch.pattern.circular");
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l1".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchPoint { id: "2:centre".into() }];
|
||||
let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(commands[0].1["center"], "2:centre");
|
||||
|
||||
@@ -239,7 +239,7 @@ pub fn candidate(d: &Dialog, session: &solidcraft_engine::Session, hit: &Hit) ->
|
||||
let active = session.active_sketch?;
|
||||
match hit {
|
||||
Hit::SketchCurve { sketch, .. } | Hit::SketchPoint { sketch, .. } if *sketch != active => None,
|
||||
_ => d.active_input()?.accepts(hit, |_, _| false),
|
||||
_ => d.active_input()?.accepts(hit, Some(active), |_, _| false),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,11 +271,14 @@ pub fn edit_pattern(app: &mut SolveApp, id: &str) -> bool {
|
||||
};
|
||||
let mut dialog = Dialog::new(Kind::SketchModify(kind.clone()), inputs(&kind));
|
||||
if let Some(input) = dialog.inputs.first_mut() {
|
||||
input.items = pattern
|
||||
.entities
|
||||
.iter()
|
||||
.map(|id| if sk.curve_index(id).is_some() { Sel::SketchCurve { id: id.clone() } } else { Sel::SketchPoint { id: id.clone() } })
|
||||
.collect();
|
||||
input.items =
|
||||
pattern
|
||||
.entities
|
||||
.iter()
|
||||
.map(|id| {
|
||||
if sk.curve_index(id).is_some() { Sel::SketchCurve { id: id.clone(), sketch: None } } else { Sel::SketchPoint { id: id.clone() } }
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
match &pattern.kind {
|
||||
SketchPatternKind::Circular { center, .. } => {
|
||||
@@ -290,7 +293,7 @@ pub fn edit_pattern(app: &mut SolveApp, id: &str) -> bool {
|
||||
if let Some(id) = id
|
||||
&& let Some(input) = dialog.inputs.get_mut(index)
|
||||
{
|
||||
input.items = vec![Sel::SketchCurve { id: id.clone() }];
|
||||
input.items = vec![Sel::SketchCurve { id: id.clone(), sketch: None }];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -556,7 +559,7 @@ fn entity_ids(session: &solidcraft_engine::Session, inputs: &[SelInput], i: usiz
|
||||
items(inputs, i)
|
||||
.iter()
|
||||
.filter_map(|x| match x {
|
||||
Sel::SketchCurve { id } => Some(id.clone()),
|
||||
Sel::SketchCurve { id, .. } => Some(id.clone()),
|
||||
_ => point_id(session, x).map(str::to_string),
|
||||
})
|
||||
.collect()
|
||||
@@ -564,7 +567,7 @@ fn entity_ids(session: &solidcraft_engine::Session, inputs: &[SelInput], i: usiz
|
||||
|
||||
/// Sketch curve ids picked in input `i`.
|
||||
fn curve_ids(inputs: &[SelInput], i: usize) -> Vec<String> {
|
||||
items(inputs, i).iter().filter_map(|x| if let Sel::SketchCurve { id } = x { Some(id.clone()) } else { None }).collect()
|
||||
items(inputs, i).iter().filter_map(|x| if let Sel::SketchCurve { id, .. } = x { Some(id.clone()) } else { None }).collect()
|
||||
}
|
||||
|
||||
/// A typed scale factor as the command wants it: the field evaluated against the document's
|
||||
@@ -638,7 +641,7 @@ fn line_ids(inputs: &[SelInput], i: usize) -> Vec<String> {
|
||||
items(inputs, i)
|
||||
.iter()
|
||||
.filter_map(|x| match x {
|
||||
Sel::SketchCurve { id } => Some(id.clone()),
|
||||
Sel::SketchCurve { id, .. } => Some(id.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
@@ -744,7 +747,7 @@ pub fn commands(app: &SolveApp, k: &Mod, inputs: &[SelInput], extra: &Map<String
|
||||
// The AXES mask also takes an origin axis, which is not a curve of this sketch and
|
||||
// cannot be a mirror line.
|
||||
let line = match items(inputs, 1).first() {
|
||||
Some(Sel::SketchCurve { id }) => id.clone(),
|
||||
Some(Sel::SketchCurve { id, .. }) => id.clone(),
|
||||
Some(_) => return Err("The mirror line must be a straight curve of this sketch, not an origin axis".into()),
|
||||
None => return Err("Select the mirror line".into()),
|
||||
};
|
||||
@@ -796,7 +799,7 @@ pub fn commands(app: &SolveApp, k: &Mod, inputs: &[SelInput], extra: &Map<String
|
||||
let d = sketch_dir(app, sel).ok_or("The direction must be an axis or a straight sketch curve that lies in the sketch plane")?;
|
||||
p[vector_key] = json!([d.x, d.y]);
|
||||
p[line_key] = match sel {
|
||||
Sel::SketchCurve { id } => json!(id),
|
||||
Sel::SketchCurve { id, .. } => json!(id),
|
||||
_ => Value::Null,
|
||||
};
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ fn existing_patterns_reopen_from_menu_and_badge_and_edit_without_changing_surviv
|
||||
};
|
||||
let out = h.app.run(cmd, p).unwrap();
|
||||
let before = h.app.session.doc.to_json();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l2".into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l2".into(), sketch: None }];
|
||||
h.settle();
|
||||
let menu = crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport);
|
||||
let item = menu.iter().find(|item| item.id == "ui.editSketchPattern").expect("a copy offers Edit Sketch Pattern");
|
||||
@@ -93,7 +93,7 @@ fn the_typed_factor_reaches_the_command_unchanged() {
|
||||
let h = rectangle();
|
||||
let ids = curve_ids(&h);
|
||||
let mut inputs = vec![SelInput::new("Entities", crate::selection::CURVES, true), SelInput::new("Base point", crate::selection::POINTS, false)];
|
||||
inputs[0].items = ids.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inputs[0].items = ids.iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
let k = Mod::Scale { factor: "2.5".into() };
|
||||
let out = commands(&h.app, &k, &inputs, &serde_json::Map::new()).unwrap();
|
||||
assert_eq!(out.len(), 1);
|
||||
@@ -110,7 +110,7 @@ fn an_expression_in_the_factor_field_is_evaluated() {
|
||||
h.app.run("parameters.add", json!({"name": "growth", "expression": "3", "unit": ""})).unwrap();
|
||||
let ids = curve_ids(&h);
|
||||
let mut inputs = vec![SelInput::new("Entities", crate::selection::CURVES, true)];
|
||||
inputs[0].items = ids.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
inputs[0].items = ids.iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
let out = commands(&h.app, &Mod::Scale { factor: "growth * 2".into() }, &inputs, &serde_json::Map::new()).unwrap();
|
||||
assert_eq!(out[0].1["factor"], json!(6.0));
|
||||
}
|
||||
@@ -121,7 +121,7 @@ fn a_picked_base_point_loses_the_sketch_prefix_that_picking_adds() {
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
let ids = curve_ids(&h);
|
||||
let mut inputs = vec![SelInput::new("Entities", crate::selection::CURVES, true), SelInput::new("Base point", crate::selection::POINTS, false)];
|
||||
inputs[0].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
inputs[0].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
let point = {
|
||||
let st = h.app.session.model.state();
|
||||
st.sketch(sid).unwrap().sketch.points.first().unwrap().id.clone()
|
||||
@@ -138,7 +138,7 @@ fn an_empty_selection_or_a_bad_factor_is_an_error_the_window_shows() {
|
||||
let empty = vec![SelInput::new("Entities", crate::selection::CURVES, true)];
|
||||
assert!(commands(&h.app, &Mod::Scale { factor: "2".into() }, &empty, &serde_json::Map::new()).is_err());
|
||||
let mut filled = empty.clone();
|
||||
filled[0].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
filled[0].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
for bad in ["0", "-2", "", "nonsense"] {
|
||||
let r = commands(&h.app, &Mod::Scale { factor: bad.into() }, &filled, &serde_json::Map::new());
|
||||
assert!(r.is_err(), "factor `{bad}` should not reach the command: {r:?}");
|
||||
@@ -156,7 +156,7 @@ fn the_window_scales_the_picked_geometry_and_leaves_the_rest_alone() {
|
||||
h.step(&json!({"start": "sketch.scale"})).unwrap();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = rect.iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
d.inputs[0].items = rect.iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
d.kind = Kind::SketchModify(Mod::Scale { factor: "2".into() });
|
||||
}
|
||||
// A frame with the picks in place: the canvas value box takes focus on the frame after a
|
||||
@@ -209,8 +209,8 @@ fn the_two_picks_become_the_command() {
|
||||
let ids = curve_ids(&h);
|
||||
let (line, circle) = (ids[0].clone(), ids[1].clone());
|
||||
let mut inputs = mirror_inputs();
|
||||
inputs[0].items = vec![Sel::SketchCurve { id: circle.clone() }];
|
||||
inputs[1].items = vec![Sel::SketchCurve { id: line.clone() }];
|
||||
inputs[0].items = vec![Sel::SketchCurve { id: circle.clone(), sketch: None }];
|
||||
inputs[1].items = vec![Sel::SketchCurve { id: line.clone(), sketch: None }];
|
||||
let out = commands(&h.app, &Mod::Mirror, &inputs, &serde_json::Map::new()).unwrap();
|
||||
assert_eq!(out.len(), 1);
|
||||
assert_eq!(out[0].0, "sketch.mirror");
|
||||
@@ -222,21 +222,21 @@ fn a_half_filled_window_is_an_error_instead_of_a_command() {
|
||||
let h = line_and_circle();
|
||||
let ids = curve_ids(&h);
|
||||
let mut only_entities = mirror_inputs();
|
||||
only_entities[0].items = vec![Sel::SketchCurve { id: ids[1].clone() }];
|
||||
only_entities[0].items = vec![Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
|
||||
assert!(commands(&h.app, &Mod::Mirror, &only_entities, &serde_json::Map::new()).is_err());
|
||||
let mut only_line = mirror_inputs();
|
||||
only_line[1].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
only_line[1].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
assert!(commands(&h.app, &Mod::Mirror, &only_line, &serde_json::Map::new()).is_err());
|
||||
// The AXES mask also takes an origin axis, which is no curve of this sketch.
|
||||
let mut origin_axis = mirror_inputs();
|
||||
origin_axis[0].items = vec![Sel::SketchCurve { id: ids[1].clone() }];
|
||||
origin_axis[0].items = vec![Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
|
||||
origin_axis[1].items = vec![Sel::Axis { name: "Y".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.
|
||||
let mut line_in_both = mirror_inputs();
|
||||
line_in_both[0].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
line_in_both[1].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -248,8 +248,8 @@ fn the_window_reflects_the_picked_circle_across_the_line() {
|
||||
h.step(&json!({"start": "sketch.mirror"})).unwrap();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: ids[1].clone() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: ids[0].clone() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: ids[1].clone(), sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }];
|
||||
}
|
||||
// A frame with the picks in place: the dialog reads them when it next draws.
|
||||
h.frames(2);
|
||||
@@ -269,7 +269,7 @@ fn the_window_reflects_the_picked_circle_across_the_line() {
|
||||
|
||||
fn move_inputs(h: &Harness) -> Vec<SelInput> {
|
||||
let mut v = vec![SelInput::new("Entities", CURVES | POINTS, true), SelInput::new("Center", POINTS, false)];
|
||||
v[0].items = curve_ids(h).iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
v[0].items = curve_ids(h).iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
v
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ fn the_context_menu_item_fills_the_window_from_the_selection() {
|
||||
h.app.run("select.set", json!({"items": [{"type": "sketch_curve", "id": ids[0]}]})).unwrap();
|
||||
h.step(&json!({"start": "sketch.move"})).unwrap();
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert_eq!(d.inputs[0].items, vec![Sel::SketchCurve { id: ids[0].clone() }]);
|
||||
assert_eq!(d.inputs[0].items, vec![Sel::SketchCurve { id: ids[0].clone(), sketch: None }]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -349,7 +349,7 @@ fn the_window_moves_the_rectangle_and_the_copy_row_leaves_the_original_behind()
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
h.step(&json!({"start": "sketch.move"})).unwrap();
|
||||
// Read the ids before the dialog is borrowed mutably: `curve_ids` borrows the harness.
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = picks;
|
||||
@@ -383,7 +383,7 @@ fn a_plain_move_takes_the_geometry_with_it() {
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
h.step(&json!({"start": "sketch.move"})).unwrap();
|
||||
// Read the ids before the dialog is borrowed mutably: `curve_ids` borrows the harness.
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = picks;
|
||||
@@ -413,8 +413,8 @@ fn escape_leaves_the_sketch_exactly_as_it_was() {
|
||||
h.step(&json!({"start": "sketch.mirror"})).unwrap();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: before[1].clone() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: before[0].clone() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: before[1].clone(), sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: before[0].clone(), sketch: None }];
|
||||
}
|
||||
h.frames(2);
|
||||
h.step(&json!({"key": "Escape"})).unwrap();
|
||||
@@ -430,7 +430,7 @@ fn the_x_distance_gets_a_drag_arrow_along_the_sketch_x_axis() {
|
||||
let mut h = rectangle();
|
||||
h.step(&json!({"start": "sketch.move"})).unwrap();
|
||||
// Read the ids before the dialog is borrowed mutably: `curve_ids` borrows the harness.
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone() }).collect();
|
||||
let picks: Vec<Sel> = curve_ids(&h).iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }).collect();
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = picks;
|
||||
@@ -472,7 +472,7 @@ fn two_sided_offset_shows_a_dimension_for_each_distance() {
|
||||
let (mut h, id) = open("sketch.offset");
|
||||
{
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
}
|
||||
h.frames(2);
|
||||
assert!(crate::scenario::handle_at("arrow").is_some(), "Distance has its dimension");
|
||||
@@ -504,7 +504,7 @@ fn rectangular_pattern_window_opens_instead_of_a_click_tool() {
|
||||
fn rectangular_sections_flip_and_center_independently_and_restore_even_counts_when_editing() {
|
||||
use solidcraft_engine::sketch::PatternAlignment;
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
rect(&mut h, "4", "20", "2", "10");
|
||||
h.settle();
|
||||
let first = crate::scenario::handle_at("dialog:Spacing").unwrap();
|
||||
@@ -549,7 +549,7 @@ fn rectangular_sections_flip_and_center_independently_and_restore_even_counts_wh
|
||||
#[test]
|
||||
fn typed_counts_and_spacings_reach_the_command_with_the_second_direction() {
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
rect(&mut h, "5", "20", "2", "15 mm");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
let cmds = apply_commands(&h.app, &d).unwrap();
|
||||
@@ -566,7 +566,7 @@ fn typed_counts_and_spacings_reach_the_command_with_the_second_direction() {
|
||||
#[test]
|
||||
fn a_picked_axis_becomes_an_in_plane_direction() {
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[1].items = vec![Sel::Axis { name: "Y".into() }];
|
||||
rect(&mut h, "3", "10", "1", "10");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
@@ -580,9 +580,9 @@ fn two_picked_lines_are_sent_as_live_references_and_restored_in_the_editor() {
|
||||
h.app.run("sketch.line", json!({"points":[[0,-20],[10,-20]],"ids":["dir1"]})).unwrap();
|
||||
h.app.run("sketch.line", json!({"points":[[0,-40],[6,-32]],"ids":["dir2"]})).unwrap();
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "dir1".into() }];
|
||||
d.inputs[2].items = vec![Sel::SketchCurve { id: "dir2".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "dir1".into(), sketch: None }];
|
||||
d.inputs[2].items = vec![Sel::SketchCurve { id: "dir2".into(), sketch: None }];
|
||||
rect(&mut h, "3", "20", "2", "10");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
let cmds = apply_commands(&h.app, &d).unwrap();
|
||||
@@ -591,8 +591,8 @@ fn two_picked_lines_are_sent_as_live_references_and_restored_in_the_editor() {
|
||||
let out = h.app.run(&cmds[0].0, cmds[0].1.clone()).unwrap();
|
||||
assert!(crate::sketch_modify_ui::edit_pattern(&mut h.app, out["pattern"].as_str().unwrap()));
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "dir1".into() }]);
|
||||
assert_eq!(d.inputs[2].items, vec![Sel::SketchCurve { id: "dir2".into() }]);
|
||||
assert_eq!(d.inputs[1].items, vec![Sel::SketchCurve { id: "dir1".into(), sketch: None }]);
|
||||
assert_eq!(d.inputs[2].items, vec![Sel::SketchCurve { id: "dir2".into(), sketch: None }]);
|
||||
let reopened = apply_commands(&h.app, d).unwrap();
|
||||
assert_eq!(reopened[0].1["direction2"], "dir2");
|
||||
}
|
||||
@@ -616,7 +616,7 @@ fn sketch_pattern_tools_are_promoted_together_and_open_from_the_toolbar() {
|
||||
#[test]
|
||||
fn an_axis_perpendicular_to_the_sketch_is_reported_not_silently_replaced() {
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[1].items = vec![Sel::Axis { name: "Z".into() }];
|
||||
rect(&mut h, "3", "10", "1", "10");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
@@ -631,7 +631,7 @@ fn an_axis_perpendicular_to_the_sketch_is_reported_not_silently_replaced() {
|
||||
fn a_count_expression_is_evaluated_rather_than_sent_as_a_string() {
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.run("parameters.add", json!({"name": "n", "expression": "4", "unit": ""})).unwrap();
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
rect(&mut h, "n", "10", "1", "10");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
let cmds = apply_commands(&h.app, &d).unwrap();
|
||||
@@ -644,7 +644,7 @@ fn bad_counts_and_an_empty_selection_are_refused_before_the_command_runs() {
|
||||
rect(&mut h, "5", "20", "1", "20");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
assert!(apply_commands(&h.app, &d).unwrap_err().contains("Select"));
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
for bad in ["0", "2.5", "501", "wat"] {
|
||||
rect(&mut h, bad, "20", "1", "20");
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
@@ -661,7 +661,7 @@ fn bad_counts_and_an_empty_selection_are_refused_before_the_command_runs() {
|
||||
#[test]
|
||||
fn the_spacing_gets_a_canvas_arrow_along_the_pattern_direction() {
|
||||
let (mut h, id) = open("sketch.pattern.rectangular");
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id }];
|
||||
h.app.dialog.as_mut().unwrap().inputs[0].items = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
let d = h.app.dialog.clone().unwrap();
|
||||
let (_, dir) = crate::canvas::anchor(&h.app, &d).expect("an anchor on the picked curve");
|
||||
assert_eq!(dir, Some(solidcraft_engine::geom::Vec3::X));
|
||||
@@ -690,7 +690,7 @@ fn open_circ() -> (crate::scenario::Harness, String) {
|
||||
};
|
||||
h.step(&json!({"start": "sketch.pattern.circular"})).unwrap();
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: curve }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: curve, sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchPoint { id: format!("{sid}:{centre}") }];
|
||||
(h, centre)
|
||||
}
|
||||
@@ -807,7 +807,7 @@ fn circular_quantity_keeps_its_expression_when_reopened_and_follows_parameter_ch
|
||||
h.app.run("sketch.circle.center", json!({"center":[20,0],"radius":2,"id":"seed"})).unwrap();
|
||||
h.app.start("sketch.pattern.circular");
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "seed".into() }];
|
||||
d.inputs[0].items = vec![Sel::SketchCurve { id: "seed".into(), sketch: None }];
|
||||
d.inputs[1].items = vec![Sel::SketchPoint { id: "origin".into() }];
|
||||
if let Kind::SketchModify(Mod::PatternCirc { count, .. }) = &mut d.kind {
|
||||
*count = "HoleAmount".into();
|
||||
|
||||
@@ -145,7 +145,7 @@ pub fn apply_mode(app: &mut SolveApp, id: &str, result: &Value) {
|
||||
|
||||
/// Selected curves of the active sketch.
|
||||
fn selected_curves(app: &SolveApp) -> Vec<String> {
|
||||
app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id } = s { Some(id.clone()) } else { None }).collect()
|
||||
app.session.selection.iter().filter_map(|s| if let Sel::SketchCurve { id, .. } = s { Some(id.clone()) } else { None }).collect()
|
||||
}
|
||||
|
||||
/// The line types among the selected curves of the active sketch, indexed like the palette's
|
||||
@@ -738,7 +738,7 @@ mod tests {
|
||||
h.app.run("sketch.centerline", json!({"curves":[center],"value":true})).unwrap();
|
||||
// Which of Normal, Construction, Centerline and Infinite the palette shows pressed.
|
||||
let pressed = |h: &mut crate::scenario::Harness, ids: &[&String]| {
|
||||
h.app.session.selection = ids.iter().map(|id| Sel::SketchCurve { id: (*id).clone() }).collect();
|
||||
h.app.session.selection = ids.iter().map(|id| Sel::SketchCurve { id: (*id).clone(), sketch: None }).collect();
|
||||
h.settle();
|
||||
let tree = h.output.accesskit_update.as_ref().unwrap();
|
||||
["normal", "construction", "centerline", "infinite"]
|
||||
|
||||
@@ -34,7 +34,13 @@ pub(crate) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, sketch: u64, depth: us
|
||||
.entities
|
||||
.iter()
|
||||
.chain(pattern.instances.iter().flat_map(|i| &i.curves))
|
||||
.map(|id| if sk.curve_index(id).is_some() { Sel::SketchCurve { id: id.clone() } } else { Sel::SketchPoint { id: id.clone() } })
|
||||
.map(|id| {
|
||||
if sk.curve_index(id).is_some() {
|
||||
Sel::SketchCurve { id: id.clone(), sketch: None }
|
||||
} else {
|
||||
Sel::SketchPoint { id: id.clone() }
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
@@ -139,7 +139,7 @@ fn a_second_escape_stays_in_the_sketch() {
|
||||
press(&mut h, "Escape");
|
||||
assert_eq!(h.app.session.active_sketch, sketch, "a second Escape stays in the sketch");
|
||||
h.app.run("sketch.line", json!({"points":[[0,0],[10,0]]})).unwrap();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }];
|
||||
pause(&mut h);
|
||||
press(&mut h, "Escape");
|
||||
assert!(h.app.session.selection.is_empty(), "Escape still clears a selection");
|
||||
@@ -184,7 +184,7 @@ fn move_key_keeps_sketch_mode_behavior_and_honors_a_sketch_move_binding() {
|
||||
h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
|
||||
h.app.run("sketch.line", json!({"points":[[0,0],[10,0]]})).unwrap();
|
||||
let sketch = h.app.session.active_sketch;
|
||||
let selection = vec![Sel::SketchCurve { id: "l1".into() }];
|
||||
let selection = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }];
|
||||
h.app.session.selection = selection.clone();
|
||||
|
||||
press(&mut h, "M");
|
||||
|
||||
@@ -83,7 +83,7 @@ pub(crate) fn entity_for_selection(app: &SolveApp, selection: &Sel) -> Option<St
|
||||
let state = app.session.world_state();
|
||||
let ss = state.sketch(sid)?;
|
||||
let ids = match selection {
|
||||
Sel::SketchCurve { id } => vec![id.clone()],
|
||||
Sel::SketchCurve { id, .. } => vec![id.clone()],
|
||||
Sel::Profile { sketch, index } if *sketch == sid => ss.profiles.get(*index)?.curve_ids(),
|
||||
// A point of a letter's outline stands for its text (a double-click often lands on one).
|
||||
Sel::SketchPoint { id } => {
|
||||
@@ -197,7 +197,11 @@ pub(crate) fn selected_link(app: &SolveApp) -> Option<String> {
|
||||
pub(crate) fn highlighted(app: &SolveApp) -> Vec<Sel> {
|
||||
let Some(Kind::Text(tx)) = app.dialog.as_ref().map(|dialog| &dialog.kind) else { return Vec::new() };
|
||||
let Ok(sk) = app.session.doc.sketch(tx.sketch) else { return Vec::new() };
|
||||
sk.curves.iter().filter(|curve| curve.link.as_deref() == Some(tx.link.as_str())).map(|curve| Sel::SketchCurve { id: curve.id.clone() }).collect()
|
||||
sk.curves
|
||||
.iter()
|
||||
.filter(|curve| curve.link.as_deref() == Some(tx.link.as_str()))
|
||||
.map(|curve| Sel::SketchCurve { id: curve.id.clone(), sketch: None })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A value shown in a field: rounded so binary noise does not show, with its unit.
|
||||
@@ -248,7 +252,7 @@ fn dialog(tx: Box<Tx>) -> Dialog {
|
||||
|
||||
fn inputs_for(tx: &Tx) -> Vec<SelInput> {
|
||||
let mut path = SelInput::new("Path", crate::selection::CURVES, false);
|
||||
path.items.extend(tx.style.path.iter().map(|id| Sel::SketchCurve { id: id.clone() }));
|
||||
path.items.extend(tx.style.path.iter().map(|id| Sel::SketchCurve { id: id.clone(), sketch: None }));
|
||||
vec![path]
|
||||
}
|
||||
|
||||
@@ -256,7 +260,7 @@ fn inputs_for(tx: &Tx) -> Vec<SelInput> {
|
||||
pub(crate) fn sync_path(d: &mut Dialog) {
|
||||
let Kind::Text(k) = &mut d.kind else { return };
|
||||
let picked = d.inputs.first().and_then(|i| i.items.first()).and_then(|sel| match sel {
|
||||
Sel::SketchCurve { id } => Some(id.clone()),
|
||||
Sel::SketchCurve { id, .. } => Some(id.clone()),
|
||||
_ => None,
|
||||
});
|
||||
if picked != k.style.path {
|
||||
@@ -711,7 +715,7 @@ mod tests {
|
||||
assert_eq!(tx(&h.app).link, link);
|
||||
let sk = h.app.session.doc.sketch(sid).unwrap();
|
||||
for curve in sk.curves.iter().filter(|curve| curve.link.as_deref() == Some(&link)) {
|
||||
assert!(h.app.highlighted().contains(&Sel::SketchCurve { id: curve.id.clone() }));
|
||||
assert!(h.app.highlighted().contains(&Sel::SketchCurve { id: curve.id.clone(), sketch: None }));
|
||||
}
|
||||
h.step(&json!({"widget":"Cancel"})).unwrap();
|
||||
assert!(highlighted(&h.app).is_empty());
|
||||
@@ -733,7 +737,7 @@ mod tests {
|
||||
let before = outline(&h);
|
||||
assert!(before.len() > 4 && before.iter().all(|(_, l)| l.as_deref() == Some(link.as_str())));
|
||||
let profiles = h.app.session.world_state().sketch(sid).unwrap().profiles.len();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: before[0].0.clone() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: before[0].0.clone(), sketch: None }];
|
||||
let undo = h.app.session.undo.len();
|
||||
let item = crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport)
|
||||
.into_iter()
|
||||
@@ -871,7 +875,7 @@ mod tests {
|
||||
h.app.session.doc.sketch(sid).unwrap().link(&link).unwrap().source,
|
||||
LinkSource::Text { text: "O".into(), at, height, angle, font: None, style: TextStyle::default(), exprs: Default::default() }
|
||||
);
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: h.app.session.doc.sketch(sid).unwrap().curves[0].id.clone() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: h.app.session.doc.sketch(sid).unwrap().curves[0].id.clone(), sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
h.frames(3);
|
||||
let undo = h.app.session.undo.len();
|
||||
@@ -899,7 +903,7 @@ mod tests {
|
||||
let reopen = |h: &mut Harness| {
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
let id = h.app.session.doc.sketch(sid).unwrap().curves[0].id.clone();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
h.frames(3);
|
||||
};
|
||||
@@ -988,10 +992,10 @@ mod tests {
|
||||
fn text_editor_rejects_mixed_sources_and_leaves_with_document_or_command() {
|
||||
let (mut h, _, curve) = setup();
|
||||
let other = h.app.run("sketch.text", json!({"text":"O","at":[30,0],"height":10})).unwrap();
|
||||
h.app.session.selection.push(Sel::SketchCurve { id: other["curves"][0].as_str().unwrap().into() });
|
||||
h.app.session.selection.push(Sel::SketchCurve { id: other["curves"][0].as_str().unwrap().into(), sketch: None });
|
||||
assert!(selected_entity(&h.app).is_none());
|
||||
assert!(!crate::context_menu::items(&h.app, &crate::context_menu::Target::Viewport).iter().any(|item| item.id == "sketch.edit_text"));
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve, sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
assert!(editing(&h.app));
|
||||
h.app.start("sketch.line");
|
||||
@@ -1057,7 +1061,7 @@ mod tests {
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
let sk = h.app.session.doc.sketch(sid).unwrap();
|
||||
let id = sk.curves[sk.link_curves(link)[0]].id.clone();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id, sketch: None }];
|
||||
h.frames(3);
|
||||
}
|
||||
|
||||
@@ -1420,7 +1424,7 @@ mod tests {
|
||||
assert_eq!(h.app.session.undo.len(), undo + 1);
|
||||
// Reopened, the dialog shows them.
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: h.app.session.doc.sketch(sid).unwrap().curves[0].id.clone() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: h.app.session.doc.sketch(sid).unwrap().curves[0].id.clone(), sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
h.frames(3);
|
||||
assert_eq!(tx(&h.app).style, live);
|
||||
@@ -1462,7 +1466,7 @@ mod tests {
|
||||
h.app.cam.distance = 120.0;
|
||||
h.frames(3);
|
||||
let sid = h.app.session.active_sketch.unwrap();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve, sketch: None }];
|
||||
h.app.start("sketch.edit_text");
|
||||
h.frames(3);
|
||||
assert_eq!(style_of(&h, &link).path, None, "the selected text is not its own path");
|
||||
|
||||
@@ -392,7 +392,7 @@ mod tests {
|
||||
let result = h.app.run("sketch.text", json!({"text":"II","at":[0,0],"height":10})).unwrap();
|
||||
h.call("ui.view", json!({"view":"top"}));
|
||||
h.app.cam.distance = 60.0;
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: result["curves"][0].as_str().unwrap().into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: result["curves"][0].as_str().unwrap().into(), sketch: None }];
|
||||
h.frames(3);
|
||||
(h, result["link"].as_str().unwrap().into())
|
||||
}
|
||||
@@ -466,7 +466,7 @@ mod tests {
|
||||
h.call("ui.view", json!({"view":"top"}));
|
||||
// Keep the rotated resize target clear of the floating ribbon too.
|
||||
h.app.cam.distance = 90.0;
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: result["curves"][0].as_str().unwrap().into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: result["curves"][0].as_str().unwrap().into(), sketch: None }];
|
||||
h.frames(3);
|
||||
let height_expr = |h: &Harness| {
|
||||
let sk = h.app.session.doc.sketch(h.app.session.active_sketch.unwrap()).unwrap();
|
||||
|
||||
@@ -72,7 +72,7 @@ pub(crate) fn highlighted(app: &SolveApp) -> Vec<Sel> {
|
||||
let Some(sk) = app.session.active_sketch.and_then(|sid| app.session.doc.sketch(sid).ok()) else {
|
||||
return vec![];
|
||||
};
|
||||
sk.curves.iter().filter(|c| c.link.as_deref() == Some(link)).map(|c| Sel::SketchCurve { id: c.id.clone() }).collect()
|
||||
sk.curves.iter().filter(|c| c.link.as_deref() == Some(link)).map(|c| Sel::SketchCurve { id: c.id.clone(), sketch: None }).collect()
|
||||
}
|
||||
|
||||
/// Esc restores the document and both history stacks to the start of this gesture.
|
||||
@@ -133,7 +133,7 @@ mod tests {
|
||||
h.app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(h.app.session.doc.to_json(), before);
|
||||
let curve = h.app.session.doc.sketch(1).unwrap().curves[0].id.clone();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve, sketch: None }];
|
||||
h.app.start("sketch.move");
|
||||
h.frames(3);
|
||||
replace(&mut h, "dialog:Distance X", "17");
|
||||
|
||||
@@ -947,7 +947,7 @@ pub fn on_click(app: &mut SolveApp, tool: &mut Tool, proj: &Proj, pos: Pos2) {
|
||||
if cmd == "sketch.edit_text" {
|
||||
let selection = hits.first().and_then(|hit| match hit {
|
||||
Hit::SketchCurve { sketch, id, .. } if Some(*sketch) == active_sketch(app) => {
|
||||
Some(solidcraft_engine::Sel::SketchCurve { id: id.clone() })
|
||||
Some(solidcraft_engine::Sel::SketchCurve { id: id.clone(), sketch: None })
|
||||
}
|
||||
Hit::Profile { sketch, index } => Some(solidcraft_engine::Sel::Profile { sketch: *sketch, index: *index }),
|
||||
_ => None,
|
||||
|
||||
@@ -29,7 +29,7 @@ fn a_new_sweep_takes_its_options_from_the_dialog() {
|
||||
assert!(h.widget("Twist").is_some() && h.widget("End Scale").is_some() && h.widget("Orientation").is_some());
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch, index: 0 }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into(), sketch: None }];
|
||||
d.inputs[2].items = vec![Sel::Axis { name: "X".into() }];
|
||||
let Kind::Sweep { opts, .. } = &mut d.kind else { panic!("{:?}", d.kind) };
|
||||
opts.orientation = 2;
|
||||
@@ -53,7 +53,7 @@ fn a_plain_sweep_from_the_dialog_stores_no_options() {
|
||||
h.frames(3);
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch, index: 0 }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into(), sketch: None }];
|
||||
h.step(&json!({"widget":"OK"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "{:?}", h.app.session.log);
|
||||
let f = h.app.session.doc.features.last().unwrap();
|
||||
@@ -117,8 +117,8 @@ fn a_rail_picked_in_the_dialog_is_kept_through_an_edit() {
|
||||
assert!(h.widget("Rail Fit").is_some());
|
||||
let d = h.app.dialog.as_mut().unwrap();
|
||||
d.inputs[0].items = vec![Sel::Profile { sketch, index: 0 }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into() }];
|
||||
d.inputs[3].items = vec![Sel::SketchCurve { id: "out".into() }];
|
||||
d.inputs[1].items = vec![Sel::SketchCurve { id: "up".into(), sketch: None }];
|
||||
d.inputs[3].items = vec![Sel::SketchCurve { id: "out".into(), sketch: None }];
|
||||
let Kind::Sweep { opts, .. } = &mut d.kind else { panic!("{:?}", d.kind) };
|
||||
opts.rail_fit = 1;
|
||||
h.frames(2);
|
||||
@@ -135,7 +135,7 @@ fn a_rail_picked_in_the_dialog_is_kept_through_an_edit() {
|
||||
h.step(&json!({"call":"ui.editFeature","params":{"feature":name}})).unwrap();
|
||||
h.frames(8);
|
||||
let d = h.app.dialog.as_ref().unwrap();
|
||||
assert_eq!(d.inputs[3].items, vec![Sel::SketchCurve { id: "out".into() }]);
|
||||
assert_eq!(d.inputs[3].items, vec![Sel::SketchCurve { id: "out".into(), sketch: Some(rail_sketch) }]);
|
||||
h.step(&json!({"widget":"OK"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "{:?}", h.app.session.log);
|
||||
assert_eq!(rails(&h), (stored, fit));
|
||||
|
||||
@@ -87,7 +87,7 @@ fn three_selected_lines_take_the_construction_line_as_the_symmetry_line() {
|
||||
let h = between_two_lines();
|
||||
let state = h.app.session.world_state();
|
||||
let sk = &state.sketch(h.app.session.active_sketch.unwrap()).unwrap().sketch;
|
||||
let sel = |ids: [&str; 3]| ids.map(|id| SketchCurve { id: id.into() });
|
||||
let sel = |ids: [&str; 3]| ids.map(|id| SketchCurve { id: id.into(), sketch: None });
|
||||
for ids in [["mid", "left", "right"], ["right", "mid", "left"]] {
|
||||
let params = crate::tools::constraint_preselection("sketch.constraint.symmetry", &sel(ids), Some(sk)).unwrap();
|
||||
assert_eq!(params["line"], "mid", "{ids:?}");
|
||||
|
||||
@@ -63,7 +63,7 @@ pub(crate) fn selected_text(text: &str, at: [i32; 2]) -> (Harness, String, Strin
|
||||
let result = h.app.run("sketch.text", json!({"text":text,"at":at,"height":10})).unwrap();
|
||||
let link = result["link"].as_str().unwrap().to_owned();
|
||||
let curve = result["curves"][0].as_str().unwrap().to_owned();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve.clone() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: curve.clone(), sketch: None }];
|
||||
(h, link, curve)
|
||||
}
|
||||
|
||||
|
||||
@@ -546,7 +546,7 @@ pub(crate) fn constraint_preselection(
|
||||
let ids: Vec<&str> = selection
|
||||
.iter()
|
||||
.map(|s| match s {
|
||||
SketchCurve { id } => Some(id.as_str()),
|
||||
SketchCurve { id, .. } => Some(id.as_str()),
|
||||
SketchPoint { id } if !curves_only => Some(id.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
@@ -559,12 +559,12 @@ pub(crate) fn constraint_preselection(
|
||||
("sketch.constraint.polygon", _) => selected_ids(true, 3).map(|ids| json!({"lines":ids})),
|
||||
// Three or more curves: all of them equal, in pick order (#4985). Two keep the `a, b` form.
|
||||
("sketch.constraint.equal", _) if selection.len() >= 3 => selected_ids(true, 3).map(|ids| json!({"curves":ids})),
|
||||
("sketch.constraint.curvature", [SketchCurve { id: a }, SketchCurve { id: b }]) if a != b => Some(json!({"a":a,"b":b})),
|
||||
("sketch.constraint.horizontal_vertical", [SketchCurve { id }]) => Some(json!({"line":id})),
|
||||
("sketch.constraint.curvature", [SketchCurve { id: a, .. }, SketchCurve { id: b, .. }]) if a != b => Some(json!({"a":a,"b":b})),
|
||||
("sketch.constraint.horizontal_vertical", [SketchCurve { id, .. }]) => Some(json!({"line":id})),
|
||||
("sketch.constraint.horizontal_vertical", _) => crate::selection::alignment_points(selection).map(|points| json!({"points": points})),
|
||||
("sketch.constraint.coincident", [a, b]) => {
|
||||
let entity = |s: &solidcraft_engine::Sel| match s {
|
||||
SketchPoint { id } | SketchCurve { id } => Some(id.clone()),
|
||||
SketchPoint { id } | SketchCurve { id, .. } => Some(id.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let (a, b) = (entity(a)?, entity(b)?);
|
||||
@@ -572,14 +572,14 @@ pub(crate) fn constraint_preselection(
|
||||
}
|
||||
(
|
||||
"sketch.constraint.midpoint",
|
||||
[SketchPoint { id: point }, SketchCurve { id: line }] | [SketchCurve { id: line }, SketchPoint { id: point }],
|
||||
[SketchPoint { id: point }, SketchCurve { id: line, .. }] | [SketchCurve { id: line, .. }, SketchPoint { id: point }],
|
||||
) => Some(json!({"point":point,"line":line})),
|
||||
("sketch.constraint.midpoint", [SketchCurve { id: a }, SketchCurve { id: b }]) if a != b => Some(json!({"a":a,"b":b})),
|
||||
("sketch.constraint.midpoint", [SketchCurve { id: a, .. }, SketchCurve { id: b, .. }]) if a != b => Some(json!({"a":a,"b":b})),
|
||||
("sketch.constraint.symmetry", [a, b, c]) => {
|
||||
let picks = [a, b, c]
|
||||
.into_iter()
|
||||
.map(|entity| match entity {
|
||||
SketchPoint { id } | SketchCurve { id } => Some(json!(id)),
|
||||
SketchPoint { id } | SketchCurve { id, .. } => Some(json!(id)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()?;
|
||||
|
||||
@@ -2084,8 +2084,8 @@ fn bounds_of(app: &SolveApp, items: impl Iterator<Item = Sel>) -> Option<solidcr
|
||||
}
|
||||
}
|
||||
}
|
||||
Sel::SketchCurve { id } => {
|
||||
for ss in &st.sketches {
|
||||
Sel::SketchCurve { id, sketch } => {
|
||||
for ss in st.sketches.iter().filter(|ss| sketch.is_none_or(|k| ss.feature == k)) {
|
||||
if let Some(i) = ss.sketch.curve_index(id) {
|
||||
for q in ss.sketch.polyline(i) {
|
||||
b.add(ss.plane.to_world(q));
|
||||
@@ -2200,7 +2200,7 @@ pub fn hit_sel(h: &Hit) -> Option<Sel> {
|
||||
Some(match h {
|
||||
Hit::SketchMidpoint { id, .. } => Sel::SketchMidpoint { id: id.clone() },
|
||||
Hit::SketchPoint { id, .. } => Sel::SketchPoint { id: id.clone() },
|
||||
Hit::SketchCurve { id, .. } => Sel::SketchCurve { id: id.clone() },
|
||||
Hit::SketchCurve { id, .. } => Sel::SketchCurve { id: id.clone(), sketch: None },
|
||||
Hit::Vertex { body, point } => Sel::Vertex { body: body.clone(), point: *point },
|
||||
Hit::Edge { body, index, mid } => Sel::Edge { body: body.clone(), index: *index, point: *mid },
|
||||
Hit::Profile { sketch, index } => Sel::Profile { sketch: *sketch, index: *index },
|
||||
@@ -2779,7 +2779,18 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {
|
||||
}
|
||||
}
|
||||
Sel::Profile { sketch, index } => profile_fill(&mut feedback, app, *sketch, *index, t.sel_profile, t.sel_profile_edge),
|
||||
Sel::ExternalSketchCurve { sketch, id } => {
|
||||
// A 3D sketch curve, in the sketch it names, or whichever sketch has it.
|
||||
Sel::SketchCurve { id, sketch } if st.sketches.iter().any(|ss| ss.sketch.wire_index(id).is_some()) => {
|
||||
for ss in st.sketches.iter().filter(|ss| sketch.is_none_or(|k| ss.feature == k)) {
|
||||
if let Some(w) = ss.sketch.wire_index(id).and_then(|i| ss.sketch.wires.get(i)) {
|
||||
for q in w.pts.windows(2) {
|
||||
feedback.line(q[0].to_f32(), q[1].to_f32(), c4(t.sel_edge), 3.5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// A curve picked into a dialog from another sketch than the active one names it.
|
||||
Sel::ExternalSketchCurve { sketch, id } | Sel::SketchCurve { id, sketch: Some(sketch) } => {
|
||||
if let Some(ss) = st.sketch(*sketch)
|
||||
&& let Some(ci) = ss.sketch.curve_index(id)
|
||||
{
|
||||
@@ -2796,17 +2807,7 @@ pub(crate) fn build_highlight(app: &SolveApp) -> GpuScene {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A 3D sketch curve, in whichever sketch has it.
|
||||
Sel::SketchCurve { id } if st.sketches.iter().any(|ss| ss.sketch.wire_index(id).is_some()) => {
|
||||
for ss in st.sketches.iter() {
|
||||
if let Some(w) = ss.sketch.wire_index(id).and_then(|i| ss.sketch.wires.get(i)) {
|
||||
for q in w.pts.windows(2) {
|
||||
feedback.line(q[0].to_f32(), q[1].to_f32(), c4(t.sel_edge), 3.5, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Sel::SketchCurve { id } => {
|
||||
Sel::SketchCurve { id, .. } => {
|
||||
if let Some(ss) = app.session.active_sketch.and_then(|sid| st.sketch(sid))
|
||||
&& let Some(ci) = ss.sketch.curve_index(id)
|
||||
{
|
||||
@@ -3471,8 +3472,13 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
&& app.session.active_sketch == Some(sketch)
|
||||
&& let Ok(v) = app.session.execute("sketch.chain", &json!({ "curve": id }))
|
||||
{
|
||||
let items: Vec<Sel> =
|
||||
v["curves"].as_array().into_iter().flatten().filter_map(|c| c.as_str()).map(|id| Sel::SketchCurve { id: id.into() }).collect();
|
||||
let items: Vec<Sel> = v["curves"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|c| c.as_str())
|
||||
.map(|id| Sel::SketchCurve { id: id.into(), sketch: None })
|
||||
.collect();
|
||||
let _ = app.run("select.set", json!({ "items": items, "add": add }));
|
||||
}
|
||||
// Double-click an edge: select the edges that continue it smoothly (the loop).
|
||||
@@ -4106,7 +4112,7 @@ pub(crate) fn select(app: &mut SolveApp, sel: Option<Sel>, add: bool, toggle: bo
|
||||
fn dragged_with(app: &SolveApp, id: &str) -> Vec<String> {
|
||||
fn geometry(s: &Sel) -> Option<&str> {
|
||||
match s {
|
||||
Sel::SketchPoint { id } | Sel::SketchCurve { id } => Some(id.as_str()),
|
||||
Sel::SketchPoint { id } | Sel::SketchCurve { id, .. } => Some(id.as_str()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -4256,7 +4262,7 @@ fn box_select(app: &mut SolveApp, proj: &Proj, bx: BoxSel, add: bool) {
|
||||
&& parts.iter().all(|part| bx.takes(part))
|
||||
};
|
||||
if takes {
|
||||
out.push(Sel::SketchCurve { id: c.id.clone() });
|
||||
out.push(Sel::SketchCurve { id: c.id.clone(), sketch: None });
|
||||
}
|
||||
}
|
||||
let visible = solidcraft_engine::view::SketchPointVisibility::new(&ss.sketch);
|
||||
@@ -4999,8 +5005,8 @@ mod tests {
|
||||
let hits = pick_all(&app, &proj, proj.to_screen(at).unwrap());
|
||||
let hit = hits.iter().find(|h| matches!(h, Hit::SketchCurve { id: picked, .. } if picked == &id)).unwrap();
|
||||
let axis = crate::selection::SelInput::new("Axis", crate::selection::AXES, false);
|
||||
assert_eq!(axis.accepts(hit, |_, _| false).is_some(), straight, "{hit:?}");
|
||||
let selected = Sel::SketchCurve { id };
|
||||
assert_eq!(axis.accepts(hit, None, |_, _| false).is_some(), straight, "{hit:?}");
|
||||
let selected = Sel::SketchCurve { id, sketch: None };
|
||||
assert_eq!(crate::dialogs::axis_of(&app, &selected).is_some(), straight);
|
||||
}
|
||||
}
|
||||
@@ -5013,7 +5019,7 @@ mod tests {
|
||||
let id = s.execute("sketch.line3d", &json!({"points":[[10,20,30],[30,20,30]]})).unwrap()["curves"][0].as_str().unwrap().to_string();
|
||||
s.execute("sketch.finish", &json!({})).unwrap();
|
||||
let mut app = SolveApp::new(s, crate::Services::default());
|
||||
let selected = Sel::SketchCurve { id };
|
||||
let selected = Sel::SketchCurve { id, sketch: None };
|
||||
let (origin, dir) = crate::dialogs::axis_of(&app, &selected).unwrap();
|
||||
assert!(origin.dist(Vec3::new(10., 20., 30.)) < 1e-9);
|
||||
assert!(dir.dist(Vec3::X) < 1e-9);
|
||||
|
||||
@@ -17,7 +17,7 @@ fn select_lines(h: &mut Harness) {
|
||||
{"click":{"sketch":[17.5,31.25]},"shift":true}
|
||||
]))
|
||||
.unwrap();
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: "l1".into() }, Sel::SketchCurve { id: "l2".into() }]);
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: "l1".into(), sketch: None }, Sel::SketchCurve { id: "l2".into(), sketch: None }]);
|
||||
}
|
||||
|
||||
fn assert_line_geometry(h: &Harness, command: &str) {
|
||||
@@ -122,7 +122,7 @@ fn selected_circles_all_become_equal() {
|
||||
sk.radius(sk.curve_index(id).unwrap()).unwrap()
|
||||
};
|
||||
let r1 = radius(&h, "c1");
|
||||
h.app.session.selection = ["c4", "c3", "c2", "c1"].iter().map(|id| Sel::SketchCurve { id: (*id).into() }).collect();
|
||||
h.app.session.selection = ["c4", "c3", "c2", "c1"].iter().map(|id| Sel::SketchCurve { id: (*id).into(), sketch: None }).collect();
|
||||
let undo = h.app.session.undo.len();
|
||||
h.run(&json!([{"start":"sketch.constraint.equal"}])).unwrap();
|
||||
assert!(!h.app.status.as_ref().is_some_and(|(_, _, error)| *error), "{:?}", h.app.status);
|
||||
@@ -140,8 +140,12 @@ fn selected_circles_all_become_equal() {
|
||||
fn ambiguous_selection_preserves_tool_first_workflow() {
|
||||
for selection in [
|
||||
vec![],
|
||||
vec![Sel::SketchCurve { id: "l1".into() }],
|
||||
vec![Sel::SketchCurve { id: "l1".into() }, Sel::SketchCurve { id: "l2".into() }, Sel::SketchPoint { id: "origin".into() }],
|
||||
vec![Sel::SketchCurve { id: "l1".into(), sketch: None }],
|
||||
vec![
|
||||
Sel::SketchCurve { id: "l1".into(), sketch: None },
|
||||
Sel::SketchCurve { id: "l2".into(), sketch: None },
|
||||
Sel::SketchPoint { id: "origin".into() },
|
||||
],
|
||||
] {
|
||||
let mut h = lines();
|
||||
h.app.session.selection = selection;
|
||||
@@ -258,7 +262,7 @@ fn remaining_constraints_preserve_mixed_selections_and_rejected_geometry() {
|
||||
let mut h = lines();
|
||||
let before = h.app.session.doc.to_json();
|
||||
let undo = h.app.session.undo.len();
|
||||
let mixed = vec![Sel::SketchCurve { id: "l1".into() }, Sel::Body { name: "missing".into() }];
|
||||
let mixed = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }, Sel::Body { name: "missing".into() }];
|
||||
h.app.session.selection = mixed.clone();
|
||||
h.step(&json!({"start":format!("sketch.constraint.{command}")})).unwrap();
|
||||
assert!(h.app.tool.is_some());
|
||||
@@ -267,7 +271,7 @@ fn remaining_constraints_preserve_mixed_selections_and_rejected_geometry() {
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
let mut h = lines();
|
||||
let selection = vec![Sel::SketchCurve { id: "l1".into() }, Sel::SketchCurve { id: "missing".into() }];
|
||||
let selection = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }, Sel::SketchCurve { id: "missing".into(), sketch: None }];
|
||||
h.app.session.selection = selection.clone();
|
||||
let before = h.app.session.doc.to_json();
|
||||
let undo = h.app.session.undo.len();
|
||||
|
||||
@@ -54,8 +54,12 @@ fn horizontal_vertical_leaves_ambiguous_preselection_to_pick_tool() {
|
||||
use solidcraft_engine::Sel;
|
||||
for selection in [
|
||||
vec![Sel::SketchPoint { id: "origin".into() }],
|
||||
vec![Sel::SketchPoint { id: "origin".into() }, Sel::SketchCurve { id: "c1".into() }],
|
||||
vec![Sel::SketchPoint { id: "origin".into() }, Sel::SketchPoint { id: "c1.center".into() }, Sel::SketchCurve { id: "c1".into() }],
|
||||
vec![Sel::SketchPoint { id: "origin".into() }, Sel::SketchCurve { id: "c1".into(), sketch: None }],
|
||||
vec![
|
||||
Sel::SketchPoint { id: "origin".into() },
|
||||
Sel::SketchPoint { id: "c1.center".into() },
|
||||
Sel::SketchCurve { id: "c1".into(), sketch: None },
|
||||
],
|
||||
] {
|
||||
let mut h = Harness::new();
|
||||
h.app.session.execute("sketch.create", &json!({"plane":"XY"})).unwrap();
|
||||
@@ -429,7 +433,7 @@ fn context_menu_alignment_requires_exactly_two_points_and_preserves_conflicts()
|
||||
h.app.run("sketch.circle.center", json!({"center":[20,30],"radius":3})).unwrap();
|
||||
let origin = Sel::SketchPoint { id: "origin".into() };
|
||||
let center = Sel::SketchPoint { id: "c1.center".into() };
|
||||
let curve = Sel::SketchCurve { id: "c1".into() };
|
||||
let curve = Sel::SketchCurve { id: "c1".into(), sketch: None };
|
||||
for selection in [vec![], vec![origin.clone()], vec![origin.clone(), curve.clone()], vec![origin.clone(), center.clone(), curve]] {
|
||||
h.app.session.selection = selection;
|
||||
assert!(
|
||||
@@ -571,7 +575,7 @@ fn idle_midpoints_are_selectable_without_modifying_the_sketch() {
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
// Ordinary edge and endpoint picks still work away from MID.
|
||||
h.step(&json!({"click":{"sketch":[20,12.5]}})).unwrap();
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: "l1".into() }]);
|
||||
assert_eq!(h.app.session.selection, vec![Sel::SketchCurve { id: "l1".into(), sketch: None }]);
|
||||
h.step(&json!({"click":{"sketch":[10,10]}})).unwrap();
|
||||
assert!(matches!(h.app.session.selection.as_slice(), [Sel::SketchPoint { .. }]));
|
||||
h.app.ui.pick_off.push("sketch_points".into());
|
||||
|
||||
@@ -93,7 +93,7 @@ fn axis_and_plane_preselection_projects_as_one_command() {
|
||||
#[test]
|
||||
fn mixed_local_and_external_selection_keeps_ordinary_project_picking() {
|
||||
let (mut h, source) = setup();
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into() }, Sel::ExternalSketchCurve { sketch: source, id: "l1".into() }];
|
||||
h.app.session.selection = vec![Sel::SketchCurve { id: "l1".into(), sketch: None }, Sel::ExternalSketchCurve { sketch: source, id: "l1".into() }];
|
||||
let before = h.app.session.doc.to_json();
|
||||
let selection = h.app.session.selection.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
|
||||
Reference in new issue
Block a user