@@ -1815,6 +1815,10 @@ pub struct SketchPoints {
|
||||
/// Drill the other way: away from the side the holes would go into by themselves.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub flip: bool,
|
||||
/// A Single hole snapped to this one point (#2110): drilled at the point as it moves, along
|
||||
/// the hole's `direction` (into the face it was placed on) rather than across the sketch.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub single: bool,
|
||||
}
|
||||
|
||||
/// A component: a node of the design tree that owns sketches, features and bodies. The root
|
||||
|
||||
+23
-7
@@ -1281,7 +1281,7 @@ impl Model {
|
||||
// the face along the hole's axis and never slides sideways to the face's nearest
|
||||
// point when the face no longer reaches it.
|
||||
let hole_axis = match &f.kind {
|
||||
FeatureKind::Hole { direction, points: None, .. } => direction.normalized(),
|
||||
FeatureKind::Hole { direction, points: None | Some(crate::SketchPoints { single: true, .. }), .. } => direction.normalized(),
|
||||
_ => None,
|
||||
};
|
||||
let fst = face_point_state(doc, &state, &f.kind, f.component);
|
||||
@@ -2673,7 +2673,7 @@ fn sketch_hole_dir(st: &ModelState, spots: &[Vec3], n: Vec3) -> Vec3 {
|
||||
fn hole_spots(vals: &BTreeMap<String, Value>, st: &ModelState, f: &Feature) -> Result<(Vec<Vec3>, Vec3)> {
|
||||
let FeatureKind::Hole { position, at, direction, points, .. } = &f.kind else { return Err(DocError::Invalid("not a hole".into())) };
|
||||
let (spots, dir) = match points {
|
||||
Some(sp) => {
|
||||
Some(sp) if !sp.single => {
|
||||
let ss =
|
||||
st.sketch(sp.sketch.0).ok_or_else(|| DocError::Unknown(format!("sketch {} (it must come earlier in the timeline)", sp.sketch)))?;
|
||||
let mut v = Vec::new();
|
||||
@@ -2685,9 +2685,9 @@ fn hole_spots(vals: &BTreeMap<String, Value>, st: &ModelState, f: &Feature) -> R
|
||||
let dir = if sp.flip { -dir } else { dir };
|
||||
(v, dir)
|
||||
}
|
||||
None => {
|
||||
_ => {
|
||||
let dir = direction.normalized().ok_or_else(|| DocError::Invalid("hole direction".into()))?;
|
||||
let at = hole_on_surface(st, hole_position(vals, position, at)?, dir);
|
||||
let at = hole_on_surface(st, single_hole_position(vals, st, position, at, points)?, dir);
|
||||
let dir = hole_dir_into_face(st, at, dir);
|
||||
return Ok((vec![hole_on_surface(st, at, dir)], dir));
|
||||
}
|
||||
@@ -2724,7 +2724,7 @@ fn hole_depth_to(st: &ModelState, at: &Vec3, dir: Vec3, to: &Option<Vec3>, depth
|
||||
fn hole_spots_raw(vals: &BTreeMap<String, Value>, st: &ModelState, f: &Feature) -> Result<(Vec<Vec3>, Vec3)> {
|
||||
let FeatureKind::Hole { position, at, direction, points, .. } = &f.kind else { return Err(DocError::Invalid("not a hole".into())) };
|
||||
match points {
|
||||
Some(sp) => {
|
||||
Some(sp) if !sp.single => {
|
||||
let ss = st.sketch(sp.sketch.0).ok_or_else(|| DocError::Unknown(format!("sketch {}", sp.sketch)))?;
|
||||
let v: Vec<Vec3> =
|
||||
sp.ids.iter().filter_map(|id| ss.sketch.points.iter().find(|p| &p.id == id)).map(|p| ss.plane.to_world(p.pos)).take(10_000).collect();
|
||||
@@ -2732,14 +2732,30 @@ fn hole_spots_raw(vals: &BTreeMap<String, Value>, st: &ModelState, f: &Feature)
|
||||
let dir = if sp.flip { -dir } else { dir };
|
||||
Ok((v, dir))
|
||||
}
|
||||
None => {
|
||||
_ => {
|
||||
let dir = direction.normalized().ok_or_else(|| DocError::Invalid("hole direction".into()))?;
|
||||
let p = hole_position(vals, position, at)?;
|
||||
let p = single_hole_position(vals, st, position, at, points)?;
|
||||
Ok((vec![p], hole_dir_into_face(st, hole_on_surface(st, p, dir), dir)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a hole placed by position is drilled: at its sketch point where the sketch has it now,
|
||||
/// for a Single hole snapped to one (#2110), else as [`hole_position`].
|
||||
fn single_hole_position(
|
||||
vals: &BTreeMap<String, Value>,
|
||||
st: &ModelState,
|
||||
position: &crate::FacePick,
|
||||
at: &Option<crate::PointExpr>,
|
||||
points: &Option<crate::SketchPoints>,
|
||||
) -> Result<Vec3> {
|
||||
let Some(sp) = points else { return hole_position(vals, position, at) };
|
||||
let ss = st.sketch(sp.sketch.0).ok_or_else(|| DocError::Unknown(format!("sketch {} (it must come earlier in the timeline)", sp.sketch)))?;
|
||||
let id = sp.ids.first().ok_or_else(|| DocError::Invalid("a Single hole needs its sketch point".into()))?;
|
||||
let p = ss.sketch.points.iter().find(|p| &p.id == id).ok_or_else(|| DocError::Unknown(format!("sketch point `{id}`")))?;
|
||||
Ok(ss.plane.to_world(p.pos))
|
||||
}
|
||||
|
||||
/// Where a hole placed by position is drilled: its `at` expressions evaluated, so it follows the
|
||||
/// parameters (#1678), else the point it was given.
|
||||
fn hole_position(vals: &BTreeMap<String, Value>, position: &crate::FacePick, at: &Option<crate::PointExpr>) -> Result<Vec3> {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
//! A Single hole picked at a sketch point keeps that point (`points` with `single: true`) and is
|
||||
//! drilled where the point is after the sketch changes, along its own direction into the face
|
||||
//! (#2110). Older designs need no transformation: a Single hole without it stays at the position
|
||||
//! it was placed at, as before; 0.15.x asks for an update instead of opening one that has it.
|
||||
@@ -56,7 +56,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.at("SOLID", "CREATE")
|
||||
.icon("hole")
|
||||
.key("H")
|
||||
.params("position: [x,y,z] on a face (numbers, or length expressions the hole follows) | sketch + points: [sketch point ids] (one hole each, perpendicular to the sketch, into the material on whichever side of the sketch plane it is) | sketch alone (every sketch point: standalone points and circle centres); flip?: bool (sketch points: drill to the other side); direction?: [x,y,z] (default: into the face, against its outward normal; one that leaves the face is mirrored into it; ignored with sketch points); diameter | thread (a tapped hole: the tap drill, major − pitch) | clearance: \"M6\" with fit?: close|normal|loose (ISO 273); depth? (default through all) | to?: [x,y,z] (To Object: drill to that face or point); type?: simple|drilled|counterbore|countersink; tip_angle?; cb_diameter?, cb_depth?; cs_diameter?, cs_angle?; thread?: \"M6\" (cosmetic)"),
|
||||
.params("position: [x,y,z] on a face (numbers, or length expressions the hole follows) | sketch + points: [sketch point ids] (one hole each, perpendicular to the sketch, into the material on whichever side of the sketch plane it is) | sketch alone (every sketch point: standalone points and circle centres); flip?: bool (sketch points: drill to the other side); single?: bool (with one sketch point: a Single hole that follows the point, drilled into the face there); direction?: [x,y,z] (default: into the face, against its outward normal; one that leaves the face is mirrored into it; ignored with sketch points unless single); diameter | thread (a tapped hole: the tap drill, major − pitch) | clearance: \"M6\" with fit?: close|normal|loose (ISO 273); depth? (default through all) | to?: [x,y,z] (To Object: drill to that face or point); type?: simple|drilled|counterbore|countersink; tip_angle?; cb_diameter?, cb_depth?; cs_diameter?, cs_angle?; thread?: \"M6\" (cosmetic)"),
|
||||
CommandSpec::new("solid.pipe", "Pipe", pipe)
|
||||
.at("SOLID", "CREATE")
|
||||
.icon("pipe")
|
||||
@@ -1685,7 +1685,13 @@ fn hole(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let first =
|
||||
ids.first().and_then(|id| ss.sketch.points.iter().find(|q| &q.id == id)).map(|q| ss.plane.to_world(q.pos)).unwrap_or_default();
|
||||
let flip = p.get("flip").and_then(Value::as_bool).unwrap_or(false);
|
||||
Some((solidcraft_doc::SketchPoints { sketch: SketchId(sketch), ids, flip }, first, -n))
|
||||
// A Single hole at one sketch point (#2110): it follows the point, drilled into the
|
||||
// face there rather than across the sketch.
|
||||
let single = p.get("single").and_then(Value::as_bool).unwrap_or(false);
|
||||
if single && (ids.len() != 1 || flip) {
|
||||
return Err(bad(cmd, "a `single` hole takes one sketch point and no `flip`"));
|
||||
}
|
||||
Some((solidcraft_doc::SketchPoints { sketch: SketchId(sketch), ids, flip, single }, first, -n))
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
@@ -1727,7 +1733,7 @@ fn hole(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
(None, None) => return Err(bad(cmd, "`position` must be [x, y, z], numbers or length expressions (or give `sketch` and `points`)")),
|
||||
};
|
||||
let direction = match (p.get("direction").and_then(vec3), &points) {
|
||||
(None, Some((_, _, d))) => *d,
|
||||
(None, Some((sp, _, d))) if !sp.single => *d,
|
||||
(d, _) => match d {
|
||||
Some(d) => d.normalized().ok_or_else(|| bad(cmd, "`direction` must be non-zero"))?,
|
||||
None => {
|
||||
@@ -2158,6 +2164,10 @@ mod prism_local_tests;
|
||||
#[path = "revolve_convention_tests.rs"]
|
||||
mod revolve_convention_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "single_hole_tests.rs"]
|
||||
mod single_hole_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sweep_options_tests.rs"]
|
||||
mod sweep_options_tests;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
//! A Single hole at a sketch point follows the point when the sketch changes (#2110), drilled
|
||||
//! into the face it was placed on, and keeps doing so after the design is saved and reopened.
|
||||
|
||||
use std::f64::consts::PI;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
use solidcraft_geom::Vec3;
|
||||
|
||||
use crate::Session;
|
||||
|
||||
fn run(s: &mut Session, id: &str, p: Value) -> Value {
|
||||
match s.execute(id, &p) {
|
||||
Ok(v) => v,
|
||||
Err(e) => panic!("{id} {p}: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
fn volume(s: &mut Session) -> f64 {
|
||||
run(s, "inspect.measure", json!({}))["total"]["volume_mm3"].as_f64().unwrap_or(f64::NAN)
|
||||
}
|
||||
|
||||
fn solid_at(s: &Session, p: Vec3) -> bool {
|
||||
s.model.state().bodies.iter().any(|b| b.body.contains(p))
|
||||
}
|
||||
|
||||
/// The circle `c1`'s centre: its point id and where it is in the world.
|
||||
fn centre(s: &Session) -> (String, Vec3) {
|
||||
let st = s.model.state();
|
||||
let ss = st.sketches.first().unwrap();
|
||||
ss.sketch
|
||||
.curves
|
||||
.iter()
|
||||
.find_map(|c| match c.kind {
|
||||
solidcraft_sketch::CurveKind::Circle { c, .. } => Some((ss.sketch.points[c].id.clone(), ss.plane.to_world(ss.sketch.points[c].pos))),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// The bore (5 mm across, 10 mm deep, down from the top face) is about `at`: empty on its axis
|
||||
/// and up to 2.4 mm from it, solid 2.6 mm from it in every direction.
|
||||
fn bore_at(s: &Session, at: Vec3) {
|
||||
for k in 0..8 {
|
||||
let a = PI / 4.0 * f64::from(k);
|
||||
let p = |r: f64| at + Vec3::new(a.cos(), a.sin(), 0.0) * r - Vec3::new(0.0, 0.0, 5.0);
|
||||
assert!(!solid_at(s, p(0.0)) && !solid_at(s, p(2.4)), "the bore about {at:?} is empty {a} rad from +x");
|
||||
assert!(solid_at(s, p(2.6)), "the wall about {at:?} is solid {a} rad from +x");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_hole_follows_its_sketch_point() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 20, "corner": [0, 0, 0]}));
|
||||
run(&mut s, "sketch.create", json!({"plane": {"face": [20, 15, 20]}, "name": "S"}));
|
||||
run(&mut s, "sketch.circle.center", json!({"center": [12, 9], "radius": 4, "id": "c1"}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
let (id, before) = centre(&s);
|
||||
assert!((before.z - 20.0).abs() < 1e-9, "the centre is on the top face: {before:?}");
|
||||
let block = volume(&mut s);
|
||||
run(&mut s, "solid.hole", json!({"sketch": "S", "points": [id], "single": true, "diameter": 5, "depth": 10, "name": "H"}));
|
||||
let bore = PI * 2.5 * 2.5 * 10.0;
|
||||
assert!((block - volume(&mut s) - bore).abs() < 1e-3 * bore, "one 5 x 10 bore: {} of {bore}", block - volume(&mut s));
|
||||
bore_at(&s, before);
|
||||
|
||||
// Move the centre 8 mm along the sketch's first axis: the hole goes with it.
|
||||
run(&mut s, "sketch.edit", json!({"sketch": "S"}));
|
||||
run(&mut s, "sketch.move_point", json!({"point": "c1.center", "to": [20, 9]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
let (_, after) = centre(&s);
|
||||
assert!((after.dist(before) - 8.0).abs() < 1e-6, "the centre moved 8 mm: {before:?} -> {after:?}");
|
||||
bore_at(&s, after);
|
||||
assert!(solid_at(&s, before - Vec3::new(0.0, 0.0, 5.0)), "the old spot is filled again");
|
||||
|
||||
// Saved and reopened, the hole is still a Single one at the point.
|
||||
let mut t = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
|
||||
t.refresh();
|
||||
bore_at(&t, after);
|
||||
let f = t.doc.find_feature("H").unwrap();
|
||||
assert!(matches!(&f.kind, solidcraft_doc::FeatureKind::Hole { points: Some(sp), .. } if sp.single && sp.ids == [id.clone()]), "{:?}", f.kind);
|
||||
assert!((block - volume(&mut t) - bore).abs() < 1e-3 * bore);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_hole_takes_one_point_and_no_flip() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 20, "corner": [0, 0, 0]}));
|
||||
run(&mut s, "sketch.create", json!({"plane": {"face": [20, 15, 20]}, "name": "S"}));
|
||||
run(&mut s, "sketch.circle.center", json!({"center": [12, 9], "radius": 4, "id": "c1"}));
|
||||
run(&mut s, "sketch.circle.center", json!({"center": [28, 9], "radius": 4, "id": "c2"}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
let (id, _) = centre(&s);
|
||||
run(&mut s, "solid.hole", json!({"sketch": "S", "points": [id.clone()], "single": true, "diameter": 5}));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
for p in
|
||||
[json!({"sketch": "S", "single": true, "diameter": 5}), json!({"sketch": "S", "points": [id], "single": true, "flip": true, "diameter": 5})]
|
||||
{
|
||||
assert!(s.execute("solid.hole", &p).is_err(), "{p}");
|
||||
}
|
||||
}
|
||||
@@ -1036,6 +1036,22 @@ fn default_profiles(s: &Session) -> Vec<Sel> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The sketch point (its sketch and id) a Single hole's face place `x` sits on: the one it was
|
||||
/// opened at, else a point a shown sketch shows exactly there (where a pick snapped to it).
|
||||
fn single_hole_point(app: &SolveApp, d: &Dialog, x: &Sel) -> Option<(u64, String)> {
|
||||
let Sel::Face { point, .. } = x else { return None };
|
||||
if let Some(k) = d.extra.get("single_point").filter(|k| k["point"] == pt3(*point)) {
|
||||
return Some((k["sketch"].as_u64()?, k["id"].as_str()?.to_string()));
|
||||
}
|
||||
let st = app.session.world_state();
|
||||
crate::viewport::visible_sketches(app).into_iter().find_map(|sid| {
|
||||
let ss = st.sketch(sid)?;
|
||||
let shown = SnapPoints::of(&ss.sketch);
|
||||
let p = ss.sketch.points.iter().find(|p| shown.takes(p) && ss.plane.to_world(p.pos).dist(*point) < 1e-9)?;
|
||||
Some((sid, p.id.clone()))
|
||||
})
|
||||
}
|
||||
|
||||
/// Does an input take face places that snap to sketch points on the face (the Single hole's)?
|
||||
pub(crate) fn snaps_to_points(accept: Accept) -> bool {
|
||||
accept & selection::POINTS != 0 && accept & PLANAR_FACES != 0
|
||||
@@ -4236,7 +4252,12 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
}
|
||||
taken.extend(crate::viewport::grouped_selection(s, x));
|
||||
let kept = d.extra.get("position_exprs").filter(|k| face_point(x).is_some_and(|p| p == k["point"])).map(|k| k["at"].clone());
|
||||
places.extend(face_point(x).map(|p| json!({ "position": kept.unwrap_or(p) })));
|
||||
// A place snapped to a sketch point keeps the point, so the hole follows it (#2110).
|
||||
let snapped = if kept.is_none() { single_hole_point(app, d, x) } else { None };
|
||||
places.extend(face_point(x).map(|p| match snapped {
|
||||
Some((sk, id)) => json!({"sketch": sk, "points": [id], "single": true}),
|
||||
None => json!({ "position": kept.unwrap_or(p) }),
|
||||
}));
|
||||
}
|
||||
}
|
||||
let mut out = Vec::new();
|
||||
@@ -4849,7 +4870,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
*dia = diameter.to_string();
|
||||
opts.all = depth.is_none();
|
||||
opts.angled = matches!(hole, HoleKind::Drilled { .. });
|
||||
opts.multiple = points.is_some();
|
||||
opts.multiple = points.as_ref().is_some_and(|sp| !sp.single);
|
||||
if let Some(th) = thread {
|
||||
opts.tapped = true;
|
||||
opts.thread = th.clone();
|
||||
@@ -4876,6 +4897,20 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
}
|
||||
d.kind = k;
|
||||
match points {
|
||||
Some(sp) if sp.single => {
|
||||
// A Single hole at a sketch point: picked on its face where the point is now.
|
||||
let id = sp.ids.first().cloned().unwrap_or_default();
|
||||
let st = s.world_state();
|
||||
let at = st
|
||||
.sketch(sp.sketch.0)
|
||||
.and_then(|ss| ss.sketch.points.iter().find(|p| p.id == id).map(|p| ss.plane.to_world(p.pos)))
|
||||
.unwrap_or(position.0);
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
inp.items = vec![face_sel(s, at).unwrap_or(Sel::Face { body: String::new(), index: 0, point: at })];
|
||||
}
|
||||
d.extra.insert("direction".into(), pt3(direction.0));
|
||||
d.extra.insert("single_point".into(), json!({"point": pt3(at), "sketch": sp.sketch.0, "id": id}));
|
||||
}
|
||||
Some(sp) => {
|
||||
d.inputs = vec![SelInput::new("Points", selection::POINTS, true)];
|
||||
if let Some(inp) = d.inputs.first_mut() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Hole placement on the canvas. A Single hole picked on or near a sketch point on the face (a
|
||||
//! circle's centre) goes to that point, as a Multiple pick of the same point does (#657); a pick
|
||||
//! circle's centre) goes to that point, as a Multiple pick of the same point does (#657), and
|
||||
//! follows it when the sketch changes (#2110); a pick
|
||||
//! away from sketch points, or near one off the face under the cursor, stays where it was clicked.
|
||||
//! Only points the sketch shows are snapped to (not lettering's outline points), and Select Other
|
||||
//! looks the face up once for every point near the cursor.
|
||||
@@ -118,7 +119,7 @@ fn a_single_hole_picked_near_a_circle_centre_goes_to_the_centre() {
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (id, position, at_points) = hole(&h);
|
||||
assert!(!at_points, "a Single hole is placed on its face");
|
||||
assert!(at_points, "a Single hole snapped to the centre keeps the point");
|
||||
assert!(position.dist(centre) < 1e-9, "the hole is at the circle centre {centre:?}, not at {position:?}");
|
||||
assert!(h.app.session.model.result(id).is_some_and(|r| r.error.is_none() && r.warning.is_none()));
|
||||
// The bore (5 mm across, 10 mm deep) is round about the centre: empty on its axis and up to
|
||||
@@ -144,10 +145,69 @@ fn a_single_hole_picked_near_a_circle_centre_goes_to_the_centre() {
|
||||
assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (again, position, at_points) = hole(&h);
|
||||
assert_eq!(again, id, "the same feature");
|
||||
assert!(!at_points && position.dist(centre) < 1e-9, "{position:?}");
|
||||
assert!(at_points && position.dist(centre) < 1e-9, "{position:?}");
|
||||
bore(&h);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_hole_at_a_circle_centre_follows_the_circle() {
|
||||
let (mut h, centre) = block_with_circle();
|
||||
let click = near(&mut h, centre);
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
h.step(&json!({"click": click})).unwrap();
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (id, _, _) = hole(&h);
|
||||
let sketch = h.app.session.world_state().sketches.first().unwrap().feature;
|
||||
let circle = h
|
||||
.app
|
||||
.session
|
||||
.world_state()
|
||||
.sketches
|
||||
.first()
|
||||
.unwrap()
|
||||
.sketch
|
||||
.curves
|
||||
.iter()
|
||||
.find(|c| matches!(c.kind, CurveKind::Circle { .. }))
|
||||
.unwrap()
|
||||
.id
|
||||
.clone();
|
||||
// The circle's centre moves 8 mm along the sketch's first axis: the hole goes with it.
|
||||
h.app.run("sketch.edit", json!({ "sketch": sketch })).unwrap();
|
||||
h.app.run("sketch.move_point", json!({"point": format!("{circle}.center"), "to": [20, 9]})).unwrap();
|
||||
h.app.run("sketch.finish", json!({})).unwrap();
|
||||
h.settle();
|
||||
let st = h.app.session.world_state();
|
||||
let ss = st.sketches.first().unwrap();
|
||||
let moved = ss
|
||||
.sketch
|
||||
.curves
|
||||
.iter()
|
||||
.find_map(|c| match c.kind {
|
||||
CurveKind::Circle { c, .. } => Some(ss.plane.to_world(ss.sketch.points[c].pos)),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
assert!((moved.dist(centre) - 8.0).abs() < 1e-6, "the centre moved 8 mm: {centre:?} -> {moved:?}");
|
||||
assert!(h.app.session.model.result(id).is_some_and(|r| r.error.is_none() && r.warning.is_none()));
|
||||
let down = Vec3::new(0.0, 0.0, 5.0);
|
||||
assert!(!solid_at(&h, moved - down), "the hole is at the moved centre {moved:?}");
|
||||
assert!(solid_at(&h, centre - down), "the old centre {centre:?} is solid again");
|
||||
// Edit Feature shows it as Single, picked where the centre is now, and OK keeps it there.
|
||||
h.step(&json!({"call": "ui.editFeature", "params": {"feature": id}})).unwrap();
|
||||
h.frames(4);
|
||||
let d = h.app.dialog.as_ref().expect("the hole dialog");
|
||||
assert!(matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple), "{:?}", d.kind);
|
||||
let places = face_places(&h);
|
||||
assert!(matches!(places.as_slice(), [(_, p)] if p.dist(moved) < 1e-6), "{places:?}");
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "OK closed the dialog: {:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (again, _, at_points) = hole(&h);
|
||||
assert!(again == id && at_points, "the same feature, still at the point");
|
||||
assert!(!solid_at(&h, moved - down));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_single_hole_picked_away_from_sketch_points_stays_where_it_was_clicked() {
|
||||
let (mut h, centre) = block_with_circle();
|
||||
|
||||
@@ -276,7 +276,7 @@ pub fn projection(app: &SolveApp, rect: Rect) -> Proj {
|
||||
}
|
||||
|
||||
/// Sketches drawn in the viewport: the active one, and finished ones not yet used by a feature.
|
||||
fn visible_sketches(app: &SolveApp) -> Vec<u64> {
|
||||
pub(crate) fn visible_sketches(app: &SolveApp) -> Vec<u64> {
|
||||
let st = app.session.world_state();
|
||||
st.sketches.iter().filter(|s| solidcraft_engine::view::sketch_drawn(&app.session, s.feature, app.ui.show_sketches)).map(|s| s.feature).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user