* claim: #4414 * feat: persist right and left thread handedness (#4414) * fix(thread): verify handedness with referenced holes and complete locales * test: verify handedness with merged tapped thread catalogues * test: retain tapped thread depth when changing handedness (#4414) * test: restrict Unix symlink coverage to Unix targets * test: inspect hole thread depth inside edit command parameters (#4414) * test(doc): initialize cylinder radius in handedness fixture
This commit is contained in:
committed by
GitHub
parent
da16362626
commit
47285ccb88
@@ -10,7 +10,9 @@ use serde_json::{Value, json};
|
||||
use solidcraft_engine::Sel;
|
||||
use solidcraft_engine::Session;
|
||||
use solidcraft_engine::doc::expr::Kind as ValueKind;
|
||||
use solidcraft_engine::doc::{AxisRef, Direction, FeatureKind, FilletStyle, HoleKind, Operation, PatternKind, PlaneRef, ProfileSel, ThinSide};
|
||||
use solidcraft_engine::doc::{
|
||||
AxisRef, Direction, FeatureKind, FilletStyle, HoleKind, Operation, PatternKind, PlaneRef, ProfileSel, ThinSide, ThreadHandedness,
|
||||
};
|
||||
use solidcraft_engine::geom::{Aabb3, Vec3};
|
||||
|
||||
use crate::SolveApp;
|
||||
@@ -237,6 +239,7 @@ crate::dialog_descriptor::dialog_descriptors! {
|
||||
Thread {
|
||||
designation: String,
|
||||
length: String,
|
||||
handedness: ThreadHandedness,
|
||||
/// The last automatic size; a different value is a manual override. Keep automatic
|
||||
/// features automatic when applying, even though their resolved size is visible.
|
||||
suggested: Option<String>,
|
||||
@@ -411,6 +414,7 @@ pub struct HoleOpts {
|
||||
/// Use the full useful cylindrical wall, independently of the drill extents.
|
||||
pub thread_full_depth: bool,
|
||||
pub thread_depth: String,
|
||||
pub handedness: ThreadHandedness,
|
||||
}
|
||||
|
||||
impl Default for HoleOpts {
|
||||
@@ -426,6 +430,7 @@ impl Default for HoleOpts {
|
||||
refs: Default::default(),
|
||||
thread_full_depth: true,
|
||||
thread_depth: "10 mm".into(),
|
||||
handedness: ThreadHandedness::Right,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -826,7 +831,13 @@ impl Dialog {
|
||||
vec![SelInput::new("Body to split", BODIES, false), SelInput::new("Splitting tool", PLANES | FACES | AXES, false)],
|
||||
),
|
||||
"solid.thread" => Dialog::new(
|
||||
Kind::Thread { designation: String::new(), length: String::new(), suggested: None, of: Vec::new() },
|
||||
Kind::Thread {
|
||||
designation: String::new(),
|
||||
length: String::new(),
|
||||
handedness: ThreadHandedness::Right,
|
||||
suggested: None,
|
||||
of: Vec::new(),
|
||||
},
|
||||
vec![SelInput::new("Cylindrical face", FACES, false)],
|
||||
),
|
||||
"material.assign" => Dialog::new(Kind::Material { index: 1, editor: Default::default() }, vec![SelInput::new("Bodies", BODIES, true)]),
|
||||
@@ -4140,13 +4151,16 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
need(0, "faces")?;
|
||||
("solid.offset_face", json!({"faces": face_points(0)}))
|
||||
}
|
||||
Kind::Thread { designation, length, suggested, .. } => {
|
||||
Kind::Thread { designation, length, suggested, handedness, .. } => {
|
||||
need(0, "a cylindrical face")?;
|
||||
let mut p = json!({"face": face_points(0).into_iter().next().unwrap_or(Value::Null)});
|
||||
if !designation.trim().is_empty() && suggested.as_deref() != Some(designation.as_str()) {
|
||||
p["designation"] = json!(designation.trim());
|
||||
}
|
||||
put(&mut p, &[("length", length)]);
|
||||
if !handedness.is_right() {
|
||||
p["handedness"] = json!(handedness);
|
||||
}
|
||||
("solid.thread", p)
|
||||
}
|
||||
Kind::Material { index, editor } => {
|
||||
@@ -4268,6 +4282,9 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
|
||||
if !opts.thread_full_depth {
|
||||
params["thread_depth"] = json!(opts.thread_depth.trim());
|
||||
}
|
||||
if !opts.handedness.is_right() {
|
||||
params["handedness"] = json!(opts.handedness);
|
||||
}
|
||||
}
|
||||
match *kind {
|
||||
1 => {
|
||||
@@ -5171,7 +5188,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
d.extra.insert("pull".into(), pt3(pull.0));
|
||||
d
|
||||
}
|
||||
FeatureKind::Hole { position, at, direction, diameter, depth, hole, points, thread, thread_depth, to, references } => {
|
||||
FeatureKind::Hole { position, at, direction, diameter, depth, hole, points, thread, thread_depth, handedness, to, references } => {
|
||||
let mut d = start("solid.hole")?;
|
||||
let mut k = hole_defaults(s);
|
||||
if let Kind::Hole { diameter: dia, depth: dep, kind, cb_diameter, cb_depth, cs_diameter, cs_angle, opts } = &mut k {
|
||||
@@ -5179,6 +5196,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
opts.all = depth.is_none();
|
||||
opts.angled = matches!(hole, HoleKind::Drilled { .. });
|
||||
opts.multiple = points.as_ref().is_some_and(|sp| !sp.single);
|
||||
opts.handedness = *handedness;
|
||||
if let Some(th) = thread {
|
||||
opts.tapped = true;
|
||||
opts.thread = th.clone();
|
||||
@@ -5656,7 +5674,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
}
|
||||
d
|
||||
}
|
||||
FeatureKind::Thread { face, designation, length, modeled } => {
|
||||
FeatureKind::Thread { face, designation, length, modeled, handedness } => {
|
||||
let mut d = start("solid.thread")?;
|
||||
if *modeled {
|
||||
d.extra.insert("modeled".into(), json!(true));
|
||||
@@ -5664,6 +5682,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
|
||||
d.kind = Kind::Thread {
|
||||
designation: designation.clone().unwrap_or_default(),
|
||||
length: length.as_deref().map(str::to_string).unwrap_or_default(),
|
||||
handedness: *handedness,
|
||||
suggested: None,
|
||||
of: Vec::new(),
|
||||
};
|
||||
|
||||
@@ -525,6 +525,7 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
if opts.tapped {
|
||||
enter |= crate::dialogs_thread::hole_rows(ui, &app.session.doc, &mut opts.thread, &mut opts.custom_thread);
|
||||
ui_kit::checkbox_grid(ui, &mut [("Full thread depth", &mut opts.thread_full_depth)], 1);
|
||||
crate::dialogs_thread::handedness_row(ui, &mut opts.handedness, "hole_handedness");
|
||||
}
|
||||
// Through all, the tip lies past the part.
|
||||
if !opts.all {
|
||||
@@ -755,12 +756,13 @@ fn additional_rows(app: &mut SolveApp, d: &mut Dialog, ui: &mut egui::Ui) -> boo
|
||||
Kind::OffsetFaces { distance } => {
|
||||
enter |= expr_row(ui, "Distance", distance);
|
||||
}
|
||||
Kind::Thread { designation, length, suggested, of } => {
|
||||
Kind::Thread { designation, length, suggested, of, handedness } => {
|
||||
let mut full = length.trim().is_empty();
|
||||
let was_full = full;
|
||||
let mut modeled = d.extra.get("modeled").and_then(Value::as_bool).unwrap_or(false);
|
||||
let before = modeled;
|
||||
let (submitted, reset) = crate::dialogs_thread::rows(ui, designation, suggested, &mut modeled, &mut full);
|
||||
crate::dialogs_thread::handedness_row(ui, handedness, "thread_handedness");
|
||||
if modeled != before {
|
||||
d.extra.insert("modeled".into(), json!(modeled));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
//! Tapped-hole catalogues and metric Thread choices share document sizing data.
|
||||
//! Browsing choices does not edit the model or freeze an automatic Thread feature.
|
||||
|
||||
use solidcraft_engine::doc::{Document, TappedThreadFamily, metric_thread_sizes, parse_metric_thread, parse_tapped_thread, tapped_thread_sizes};
|
||||
use solidcraft_engine::doc::{
|
||||
Document, TappedThreadFamily, ThreadHandedness, metric_thread_sizes, parse_metric_thread, parse_tapped_thread, tapped_thread_sizes,
|
||||
};
|
||||
|
||||
use crate::dialogs::{combo, form_row};
|
||||
use crate::i18n::tr;
|
||||
@@ -146,6 +148,14 @@ pub(crate) fn hole_rows(ui: &mut egui::Ui, doc: &Document, designation: &mut Str
|
||||
enter || (response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)))
|
||||
}
|
||||
|
||||
pub(crate) fn handedness_row(ui: &mut egui::Ui, handedness: &mut ThreadHandedness, id: &str) {
|
||||
let mut selected = usize::from(*handedness == ThreadHandedness::Left);
|
||||
form_row(ui, "thread.direction", |ui| {
|
||||
combo(ui, id, &["thread.right_hand", "thread.left_hand"], &mut selected);
|
||||
});
|
||||
*handedness = if selected == 1 { ThreadHandedness::Left } else { ThreadHandedness::Right };
|
||||
}
|
||||
|
||||
/// Returns (Enter pressed, automatic sizing requested).
|
||||
pub(crate) fn rows(ui: &mut egui::Ui, designation: &mut String, suggested: &mut Option<String>, modeled: &mut bool, full: &mut bool) -> (bool, bool) {
|
||||
form_row(ui, "Profile", |ui| {
|
||||
|
||||
@@ -1248,6 +1248,58 @@ fn thread_size_suggestion_can_be_cleared_and_edited_in_the_dialog() {
|
||||
assert_eq!(apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap()[0].1["designation"], "M8");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_handedness_choices_create_edit_and_restore_the_saved_direction() {
|
||||
use solidcraft_engine::doc::{FeatureKind, ThreadHandedness};
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.cylinder", json!({"radius":3,"height":6})).unwrap();
|
||||
h.app.session.selection = vec![thread_face(&h.app, "Body1")];
|
||||
h.step(&json!({"start":"solid.thread"})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(matches!(&h.app.dialog.as_ref().unwrap().kind, crate::dialogs::Kind::Thread { handedness: ThreadHandedness::Right, .. }));
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction"}})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction:thread.left_hand"}})).unwrap();
|
||||
let command = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(command[0].1["handedness"], "left");
|
||||
h.step(&json!({"widget":"OK"})).unwrap();
|
||||
let id = h.app.session.doc.features.last().unwrap().id;
|
||||
h.call("ui.editFeature", json!({"feature":id}));
|
||||
h.frames(2);
|
||||
assert!(matches!(&h.app.dialog.as_ref().unwrap().kind, crate::dialogs::Kind::Thread { handedness: ThreadHandedness::Left, .. }));
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction"}})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction:thread.right_hand"}})).unwrap();
|
||||
h.step(&json!({"widget":"OK"})).unwrap();
|
||||
assert!(matches!(&h.app.session.doc.feature(id).unwrap().kind, FeatureKind::Thread { handedness: ThreadHandedness::Right, .. }));
|
||||
assert_eq!(h.app.session.model.state().threads[0].handedness, ThreadHandedness::Right);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thread_handedness_tapped_hole_edit_retains_and_changes_direction() {
|
||||
use solidcraft_engine::doc::{FeatureKind, ThreadHandedness};
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.box", json!({"length":20,"width":20,"height":10})).unwrap();
|
||||
let id =
|
||||
h.app.run("solid.hole", json!({"position":[10,10,10],"thread":"M6","depth":6,"thread_depth":"3 mm","handedness":"left"})).unwrap()["feature"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
h.call("ui.editFeature", json!({"feature":id}));
|
||||
h.frames(2);
|
||||
assert!(
|
||||
matches!(&h.app.dialog.as_ref().unwrap().kind, crate::dialogs::Kind::Hole { opts, .. } if opts.handedness == ThreadHandedness::Left && !opts.thread_full_depth && opts.thread_depth == "3 mm")
|
||||
);
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction"}})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:thread.direction:thread.right_hand"}})).unwrap();
|
||||
let command = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
|
||||
assert_eq!(command[0].0, "timeline.redefine");
|
||||
assert_eq!(command[0].1["command"], "solid.hole");
|
||||
assert_eq!(command[0].1["params"]["thread_depth"], "3 mm", "editing direction must retain the independent thread depth");
|
||||
h.step(&json!({"widget":"OK"})).unwrap();
|
||||
assert!(matches!(&h.app.session.doc.feature(id).unwrap().kind, FeatureKind::Hole { handedness: ThreadHandedness::Right, .. }));
|
||||
let state = h.app.session.model.state();
|
||||
assert_eq!(state.threads[0].handedness, ThreadHandedness::Right);
|
||||
assert!((state.threads[0].end - state.threads[0].start - 3.0).abs() < 1e-8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modeled_thread_survives_timeline_double_click_and_ok() {
|
||||
for (analytic_pick, change_length) in [(false, false), (false, true), (true, false), (true, true)] {
|
||||
|
||||
Reference in New Issue
Block a user