Placing a Single hole put it exactly where the click landed, with nothing to line it up by and no
way to move it but taking it out and picking again; the dialog was a list of size fields.
- Preferences › Design › Create Hole has two settings, both off by default, so a new installation
places holes as before:
- Snap to face and edge centres (`hole_snaps`): the planar face under the cursor offers its
middle and the centres of its round edges (a boss, a rounded corner, a hole already there) as
marks; a pick near one, or on or beside such an edge, takes that centre and the mark is named.
Sketch points on the face still come first; Alt or Ctrl held places it where clicked.
- Move holes by clicking or dragging (`hole_moves`): each placed hole has a handle that drags it
(snapping when snaps are on) and takes it out when clicked, and a pick elsewhere on its face
moves it there. Edit Feature shows the handle too, so a hole can be moved later (#1047).
- The Hole dialog draws a section of the hole as its options make it, with each size in a field
beside the dimension it sets; a hovered or focused field lights its dimension. The layout is a
new kit element, `ui_kit::figure_rows` (a caller-painted figure beside captioned fields).
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//! Constraint, assembly snap and dimension marker artwork.
|
||||
//! Constraint, assembly snap, hole placement and dimension marker artwork.
|
||||
use crate::dialogs_assembly::SnapKind;
|
||||
use crate::theme::Tokens;
|
||||
use egui::{Color32, Pos2, Stroke, vec2};
|
||||
@@ -57,6 +57,39 @@ pub(crate) fn snap(painter: &egui::Painter, c: Pos2, tip: Option<Pos2>, kind: Sn
|
||||
painter.galley(at, g, t.text);
|
||||
}
|
||||
}
|
||||
/// A place a hole can snap to, before the cursor reaches it: a small hollow mark of its kind
|
||||
/// (a square for a face's centre, a ring for a round edge's centre).
|
||||
pub(crate) fn snap_hint(painter: &egui::Painter, c: Pos2, kind: SnapKind, col: Color32) {
|
||||
let ic = Tokens::get().icons;
|
||||
for stroke in [Stroke::new(3.5, ic.marker_halo), Stroke::new(1.4, col)] {
|
||||
match kind {
|
||||
SnapKind::FaceCenter => {
|
||||
painter.rect_stroke(egui::Rect::from_center_size(c, vec2(8.0, 8.0)), 1.0, stroke, egui::StrokeKind::Middle);
|
||||
}
|
||||
SnapKind::CircleCenter => {
|
||||
painter.circle_stroke(c, 4.5, stroke);
|
||||
}
|
||||
SnapKind::EdgeMid | SnapKind::Vertex => {
|
||||
let r = 5.0;
|
||||
let diamond = vec![c + vec2(0.0, -r), c + vec2(r, 0.0), c + vec2(0.0, r), c + vec2(-r, 0.0)];
|
||||
painter.add(egui::Shape::convex_polygon(diamond, Color32::TRANSPARENT, stroke));
|
||||
}
|
||||
}
|
||||
}
|
||||
painter.circle_filled(c, 1.3, col);
|
||||
}
|
||||
|
||||
/// A placed hole's drag handle: a ring round the hole's centre with a cross through it, filled
|
||||
/// while it is hovered or dragged.
|
||||
pub(crate) fn hole_handle(painter: &egui::Painter, c: Pos2, col: Color32, hot: bool) {
|
||||
let ic = Tokens::get().icons;
|
||||
let r = 6.0;
|
||||
painter.circle_filled(c, r + 3.5, ic.marker_halo);
|
||||
painter.circle(c, r, if hot { col } else { col.gamma_multiply(0.35) }, Stroke::new(1.6, col));
|
||||
let ink = Stroke::new(1.3, if hot { ic.highlight } else { col });
|
||||
painter.line_segment([c - vec2(r + 3.0, 0.0), c + vec2(r + 3.0, 0.0)], ink);
|
||||
painter.line_segment([c - vec2(0.0, r + 3.0), c + vec2(0.0, r + 3.0)], ink);
|
||||
}
|
||||
pub(crate) fn glyph_icon(name: &str) -> Option<&'static str> {
|
||||
Some(match name {
|
||||
"Coincident" => "c_coincident",
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"2. Attach your screenshot: copy and paste it, or save and upload the PNG.": "2. Attach your screenshot: copy and paste it, or save and upload the PNG.",
|
||||
"2D": "2D",
|
||||
"3. Click Submit new issue on GitHub to send your report.": "3. Click Submit new issue on GitHub to send your report.",
|
||||
"A Single hole snaps to the middle of its face and to the centres of its round edges": "A Single hole snaps to the middle of its face and to the centres of its round edges",
|
||||
"A new configuration, a copy of the active one": "A new configuration, a copy of the active one",
|
||||
"A placed Single hole has a handle to drag it, and picking its face again moves the hole there instead of taking it out": "A placed Single hole has a handle to drag it, and picking its face again moves the hole there instead of taking it out",
|
||||
"ARRANGE": "ARRANGE",
|
||||
"About SolidCraft": "About SolidCraft",
|
||||
"Acceleration": "Acceleration",
|
||||
@@ -92,6 +94,7 @@
|
||||
"Choose Variable radius or Spline in Type.": "Choose Variable radius or Spline in Type.",
|
||||
"Choose a new plane. Sketch geometry and dimensions stay unchanged in its two-dimensional coordinates.": "Choose a new plane. Sketch geometry and dimensions stay unchanged in its two-dimensional coordinates.",
|
||||
"Choose…": "Choose…",
|
||||
"Circle center": "Circle center",
|
||||
"Circular": "Circular",
|
||||
"Circumference": "Circumference",
|
||||
"Close draft": "Close draft",
|
||||
@@ -126,6 +129,7 @@
|
||||
"Counterbore Ø": "Counterbore Ø",
|
||||
"Countersink angle": "Countersink angle",
|
||||
"Countersink Ø": "Countersink Ø",
|
||||
"Create Hole": "Create Hole",
|
||||
"Create Issue — review draft": "Create Issue — review draft",
|
||||
"Create Issue…": "Create Issue…",
|
||||
"Cross curves": "Cross curves",
|
||||
@@ -161,6 +165,7 @@
|
||||
"Don't ask again": "Don't ask again",
|
||||
"Double-click to rename": "Double-click to rename",
|
||||
"Double-clicking the middle button in the view: Home (the home view, framing what is shown), Fit (frame what is shown, keeping the orientation) or nothing": "Double-clicking the middle button in the view: Home (the home view, framing what is shown), Fit (frame what is shown, keeping the orientation) or nothing",
|
||||
"Drag to move the hole; click to remove it": "Drag to move the hole; click to remove it",
|
||||
"Drive Joint": "Drive Joint",
|
||||
"Duration": "Duration",
|
||||
"Edges": "Edges",
|
||||
@@ -194,6 +199,7 @@
|
||||
"Face": "Face",
|
||||
"Face Appearance": "Face Appearance",
|
||||
"Face attachment lost": "Face attachment lost",
|
||||
"Face center": "Face center",
|
||||
"Faces": "Faces",
|
||||
"Faces / edges / vertices": "Faces / edges / vertices",
|
||||
"Faces to split": "Faces to split",
|
||||
@@ -302,6 +308,7 @@
|
||||
"Move Type": "Move Type",
|
||||
"Move down": "Move down",
|
||||
"Move earlier": "Move earlier",
|
||||
"Move holes by clicking or dragging": "Move holes by clicking or dragging",
|
||||
"Move later": "Move later",
|
||||
"Move up": "Move up",
|
||||
"Name": "Name",
|
||||
@@ -466,6 +473,7 @@
|
||||
"Sketch plane has no body-face attachment.": "Sketch plane has no body-face attachment.",
|
||||
"Sketch points": "Sketch points",
|
||||
"Slot width": "Slot width",
|
||||
"Snap to face and edge centres": "Snap to face and edge centres",
|
||||
"SolidCraft closed before these designs were saved. Their last autosave can be opened.": "SolidCraft closed before these designs were saved. Their last autosave can be opened.",
|
||||
"Specialise": "Specialise",
|
||||
"Speed": "Speed",
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"2. Attach your screenshot: copy and paste it, or save and upload the PNG.": "2. スクリーンショットを添付します。コピーして貼り付けるか、PNGを保存してアップロードします。",
|
||||
"2D": "2D",
|
||||
"3. Click Submit new issue on GitHub to send your report.": "3. GitHubでSubmit new issueをクリックしてレポートを送信します。",
|
||||
"A Single hole snaps to the middle of its face and to the centres of its round edges": "単一の穴を面の中心と丸いエッジの中心にスナップします",
|
||||
"A new configuration, a copy of the active one": "アクティブな構成をコピーして新しい構成を作成",
|
||||
"A placed Single hole has a handle to drag it, and picking its face again moves the hole there instead of taking it out": "配置した単一の穴にドラッグ用のハンドルを付け、面をもう一度選ぶと穴を削除せずにそこへ移動します",
|
||||
"ARRANGE": "配置",
|
||||
"About SolidCraft": "SolidCraft について",
|
||||
"Acceleration": "加速度",
|
||||
@@ -92,6 +94,7 @@
|
||||
"Choose Variable radius or Spline in Type.": "タイプで Variable radius またはスプラインを選択してください。",
|
||||
"Choose a new plane. Sketch geometry and dimensions stay unchanged in its two-dimensional coordinates.": "新しい平面を選択してください。スケッチジオメトリと寸法は2次元座標系のまま維持されます。",
|
||||
"Choose…": "選択…",
|
||||
"Circle center": "円の中心",
|
||||
"Circular": "円形",
|
||||
"Circumference": "円周",
|
||||
"Close draft": "下書きを閉じる",
|
||||
@@ -126,6 +129,7 @@
|
||||
"Counterbore Ø": "座ぐり Ø",
|
||||
"Countersink angle": "皿穴角度",
|
||||
"Countersink Ø": "皿穴 Ø",
|
||||
"Create Hole": "穴を作成",
|
||||
"Create Issue — review draft": "Issueを作成 — 下書きの確認",
|
||||
"Create Issue…": "Issueを作成…",
|
||||
"Cross curves": "交差する曲線",
|
||||
@@ -161,6 +165,7 @@
|
||||
"Don't ask again": "今後確認しない",
|
||||
"Double-click to rename": "ダブルクリックで名前変更",
|
||||
"Double-clicking the middle button in the view: Home (the home view, framing what is shown), Fit (frame what is shown, keeping the orientation) or nothing": "ビュー上で中ボタンをダブルクリックした時の動作: ホーム(全体を収めたホームビュー)、全体表示(向きを維持して全体を収める)、または無効",
|
||||
"Drag to move the hole; click to remove it": "ドラッグで穴を移動、クリックで削除",
|
||||
"Drive Joint": "ジョイントを駆動",
|
||||
"Duration": "時間",
|
||||
"Edges": "エッジ",
|
||||
@@ -194,6 +199,7 @@
|
||||
"Face": "面",
|
||||
"Face Appearance": "面の外観",
|
||||
"Face attachment lost": "面アタッチメントが失われました",
|
||||
"Face center": "面の中心",
|
||||
"Faces": "面",
|
||||
"Faces / edges / vertices": "面 / エッジ / 頂点",
|
||||
"Faces to split": "分割する面",
|
||||
@@ -302,6 +308,7 @@
|
||||
"Move Type": "移動タイプ",
|
||||
"Move down": "下へ移動",
|
||||
"Move earlier": "前へ移動",
|
||||
"Move holes by clicking or dragging": "クリックやドラッグで穴を移動",
|
||||
"Move later": "後へ移動",
|
||||
"Move up": "上へ移動",
|
||||
"Name": "名前",
|
||||
@@ -466,6 +473,7 @@
|
||||
"Sketch plane has no body-face attachment.": "スケッチ平面にボディ面のアタッチメントがありません。",
|
||||
"Sketch points": "スケッチ点",
|
||||
"Slot width": "長穴の幅",
|
||||
"Snap to face and edge centres": "面とエッジの中心にスナップ",
|
||||
"SolidCraft closed before these designs were saved. Their last autosave can be opened.": "これらのデザインが保存される前にSolidCraftが終了しました。最後の自動保存ファイルを開くことができます。",
|
||||
"Specialise": "特殊操作",
|
||||
"Speed": "速度",
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"2. Attach your screenshot: copy and paste it, or save and upload the PNG.": "2. 附上截图:复制并粘贴,或保存为 PNG 后上传。",
|
||||
"2D": "2D",
|
||||
"3. Click Submit new issue on GitHub to send your report.": "3. 在 GitHub 上点击 Submit new issue 发送报告。",
|
||||
"A Single hole snaps to the middle of its face and to the centres of its round edges": "单个孔捕捉到其所在面的中心和圆形边的中心",
|
||||
"A new configuration, a copy of the active one": "新建配置,为当前配置的副本",
|
||||
"A placed Single hole has a handle to drag it, and picking its face again moves the hole there instead of taking it out": "已放置的单个孔带有可拖动的控点,再次选择该面会将孔移到该处而不是删除它",
|
||||
"ARRANGE": "排列",
|
||||
"About SolidCraft": "关于 SolidCraft",
|
||||
"Acceleration": "加速度",
|
||||
@@ -92,6 +94,7 @@
|
||||
"Choose Variable radius or Spline in Type.": "请在“类型”中选择 Variable radius 或样条曲线。",
|
||||
"Choose a new plane. Sketch geometry and dimensions stay unchanged in its two-dimensional coordinates.": "选择一个新平面。草图几何和尺寸在其二维坐标中保持不变。",
|
||||
"Choose…": "选择…",
|
||||
"Circle center": "圆心",
|
||||
"Circular": "圆周",
|
||||
"Circumference": "周长",
|
||||
"Close draft": "关闭草稿",
|
||||
@@ -126,6 +129,7 @@
|
||||
"Counterbore Ø": "柱形沉孔 Ø",
|
||||
"Countersink angle": "沉头角度",
|
||||
"Countersink Ø": "锥形沉孔 Ø",
|
||||
"Create Hole": "创建孔",
|
||||
"Create Issue — review draft": "创建 Issue——审阅草稿",
|
||||
"Create Issue…": "创建 Issue…",
|
||||
"Cross curves": "交叉曲线",
|
||||
@@ -161,6 +165,7 @@
|
||||
"Don't ask again": "不再询问",
|
||||
"Double-click to rename": "双击重命名",
|
||||
"Double-clicking the middle button in the view: Home (the home view, framing what is shown), Fit (frame what is shown, keeping the orientation) or nothing": "在视图中双击中键:主视图(主视图,框住所显示的内容)、适合窗口(框住所显示的内容,保持方向)或无动作",
|
||||
"Drag to move the hole; click to remove it": "拖动以移动孔,单击以删除",
|
||||
"Drive Joint": "驱动接头",
|
||||
"Duration": "时长",
|
||||
"Edges": "边",
|
||||
@@ -194,6 +199,7 @@
|
||||
"Face": "面",
|
||||
"Face Appearance": "面外观",
|
||||
"Face attachment lost": "面附着丢失",
|
||||
"Face center": "面中心",
|
||||
"Faces": "面",
|
||||
"Faces / edges / vertices": "面 / 边 / 顶点",
|
||||
"Faces to split": "要分割的面",
|
||||
@@ -302,6 +308,7 @@
|
||||
"Move Type": "移动类型",
|
||||
"Move down": "下移",
|
||||
"Move earlier": "向前移动",
|
||||
"Move holes by clicking or dragging": "通过单击或拖动移动孔",
|
||||
"Move later": "向后移动",
|
||||
"Move up": "上移",
|
||||
"Name": "名称",
|
||||
@@ -466,6 +473,7 @@
|
||||
"Sketch plane has no body-face attachment.": "草图平面没有实体面附着。",
|
||||
"Sketch points": "草图点",
|
||||
"Slot width": "槽宽",
|
||||
"Snap to face and edge centres": "捕捉到面和边的中心",
|
||||
"SolidCraft closed before these designs were saved. Their last autosave can be opened.": "SolidCraft 在这些设计保存前已关闭。可以打开它们的上次自动保存。",
|
||||
"Specialise": "专用操作",
|
||||
"Speed": "速度",
|
||||
|
||||
@@ -345,6 +345,8 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj
|
||||
draw(app, ui, painter, proj, &mut d, base, bs, dir);
|
||||
}
|
||||
app.dialog = Some(d);
|
||||
// A Single hole's handles, over the depth arrow's stem: a press on a hole moves it.
|
||||
crate::hole_place::show(app, ui, painter, proj);
|
||||
}
|
||||
|
||||
/// A round step for dragged values at this zoom (1, 2 or 5 times a power of ten).
|
||||
|
||||
@@ -1164,7 +1164,7 @@ fn glyph(painter: &egui::Painter, proj: &Proj, s: &SnapPt, col: Color32, half_he
|
||||
}
|
||||
|
||||
/// What a snap is called (the hover label).
|
||||
fn snap_name(k: SnapKind) -> &'static str {
|
||||
pub(crate) fn snap_name(k: SnapKind) -> &'static str {
|
||||
match k {
|
||||
SnapKind::FaceCenter => "Face center",
|
||||
SnapKind::CircleCenter => "Circle center",
|
||||
|
||||
@@ -495,7 +495,7 @@ pub(super) fn rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui:
|
||||
feature_pattern_alignment_row(ui, &mut d.extra, 0);
|
||||
}
|
||||
}
|
||||
Kind::Hole { diameter, depth, kind, cb_diameter, cb_depth, cs_diameter, cs_angle, opts } => {
|
||||
Kind::Hole { kind, opts, .. } => {
|
||||
form_row(ui, "Extents", |ui| {
|
||||
let cur = if to_object_on(&d.inputs) { 1 } else { usize::from(opts.all) * 2 };
|
||||
let mut ext = cur;
|
||||
@@ -524,30 +524,18 @@ 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);
|
||||
}
|
||||
if *kind == 0 {
|
||||
// Through all, the tip lies past the part.
|
||||
if *kind == 0 && !opts.all {
|
||||
form_row(ui, "Drill Point", |ui| {
|
||||
let mut tip = usize::from(opts.angled);
|
||||
combo(ui, "hole_tip", &["Flat", "Angle"], &mut tip);
|
||||
opts.angled = tip == 1;
|
||||
});
|
||||
}
|
||||
if !opts.all {
|
||||
enter |= expr_row(ui, "Depth", depth);
|
||||
}
|
||||
if *kind == 0 && opts.angled {
|
||||
enter |= expr_row(ui, "Tip Angle", &mut opts.tip_angle);
|
||||
}
|
||||
if !opts.tapped {
|
||||
enter |= expr_row(ui, "Diameter", diameter);
|
||||
}
|
||||
if *kind == 1 {
|
||||
enter |= expr_row(ui, "Counterbore Ø", cb_diameter);
|
||||
enter |= expr_row(ui, "Counterbore depth", cb_depth);
|
||||
}
|
||||
if *kind == 2 {
|
||||
enter |= expr_row(ui, "Countersink Ø", cs_diameter);
|
||||
enter |= expr_row(ui, "Countersink angle", cs_angle);
|
||||
}
|
||||
// The section through the hole, each size beside its dimension (#2171).
|
||||
let to_object = to_object_on(&d.inputs);
|
||||
let doc = &app.session.doc;
|
||||
enter |= crate::dialogs_hole::rows(ui, &mut d.kind, to_object, &|e, k| doc.eval(e, k).ok());
|
||||
}
|
||||
_ => enter |= additional_rows(app, d, ui),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
//! The Hole dialog's section (#2171): a cut through the hole as its options make it (simple,
|
||||
//! counterbore or countersink; to a depth, to an object or through all; a flat or an angled
|
||||
//! tip; tapped), with each size typed in a field beside the dimension it sets. The picture is
|
||||
//! schematic: its widths follow the diameters loosely, its heights line up with the fields.
|
||||
//! Hovering a field, or typing in it, lights its dimension.
|
||||
|
||||
use egui::{Color32, Pos2, Rect, Shape, Stroke, pos2, vec2};
|
||||
use solidcraft_engine::doc::expr::Kind as ValueKind;
|
||||
|
||||
use crate::dialogs::{HoleOpts, Kind};
|
||||
use crate::theme::Tokens;
|
||||
use crate::ui_kit::FigureSlot;
|
||||
|
||||
/// A size the section shows.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Dim {
|
||||
/// The counterbore's or the countersink's diameter, across the top.
|
||||
TopDiameter,
|
||||
CbDepth,
|
||||
CsAngle,
|
||||
Depth,
|
||||
Diameter,
|
||||
TipAngle,
|
||||
}
|
||||
|
||||
impl Dim {
|
||||
/// The field's name, as the rows had it (scenarios find `dialog:<name>`).
|
||||
pub(crate) fn label(self, kind: usize) -> &'static str {
|
||||
match self {
|
||||
Dim::TopDiameter if kind == 2 => "Countersink Ø",
|
||||
Dim::TopDiameter => "Counterbore Ø",
|
||||
Dim::CbDepth => "Counterbore depth",
|
||||
Dim::CsAngle => "Countersink angle",
|
||||
Dim::Depth => "Depth",
|
||||
Dim::Diameter => "Diameter",
|
||||
Dim::TipAngle => "Tip Angle",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The sizes a hole of type `kind` takes, top to bottom: a depth unless it goes through all or
|
||||
/// to an object, a diameter unless it is tapped (the thread sets it), a tip angle for an angled
|
||||
/// tip at the bottom of a blind simple hole.
|
||||
pub(crate) fn dims(kind: usize, opts: &HoleOpts, to_object: bool) -> Vec<Dim> {
|
||||
let mut v = match kind {
|
||||
1 => vec![Dim::TopDiameter, Dim::CbDepth],
|
||||
2 => vec![Dim::TopDiameter, Dim::CsAngle],
|
||||
_ => Vec::new(),
|
||||
};
|
||||
if !opts.all && !to_object {
|
||||
v.push(Dim::Depth);
|
||||
}
|
||||
if !opts.tapped {
|
||||
v.push(Dim::Diameter);
|
||||
}
|
||||
if kind == 0 && opts.angled && !opts.all {
|
||||
v.push(Dim::TipAngle);
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// What the picture is drawn from.
|
||||
struct Section {
|
||||
kind: usize,
|
||||
through: bool,
|
||||
to_object: bool,
|
||||
angled: bool,
|
||||
tapped: bool,
|
||||
/// The bore's diameter over the counterbore's or countersink's (1 for a simple hole).
|
||||
ratio: f32,
|
||||
/// Half the countersink's and the tip's angles (radians).
|
||||
cs_half: f32,
|
||||
tip_half: f32,
|
||||
}
|
||||
|
||||
/// The section and its sizes (`ui_kit::figure_rows`): the picture in the label column, the
|
||||
/// fields beside it. Returns whether Enter was accepted in a field.
|
||||
pub(crate) fn rows(ui: &mut egui::Ui, k: &mut Kind, to_object: bool, eval: &dyn Fn(&str, ValueKind) -> Option<f64>) -> bool {
|
||||
let Kind::Hole { diameter, depth, kind, cb_diameter, cb_depth, cs_diameter, cs_angle, opts } = k else { return false };
|
||||
let kind = *kind;
|
||||
let dims = dims(kind, opts, to_object);
|
||||
let len = |e: &str| eval(e, ValueKind::Length).filter(|v| v.is_finite() && *v > 0.0);
|
||||
let angle = |e: &str, lo: f64, hi: f64, or: f64| eval(e, ValueKind::Angle).filter(|v| v.is_finite()).map_or(or, |v| (v / 2.0).clamp(lo, hi));
|
||||
let top = if kind == 2 { cs_diameter.as_str() } else { cb_diameter.as_str() };
|
||||
let ratio = match (len(diameter.as_str()), len(top)) {
|
||||
(Some(d), Some(t)) if kind != 0 => (d / t).clamp(0.3, 0.8) as f32,
|
||||
_ if kind != 0 => 0.55,
|
||||
_ => 1.0,
|
||||
};
|
||||
let section = Section {
|
||||
kind,
|
||||
through: opts.all,
|
||||
to_object,
|
||||
angled: kind == 0 && opts.angled,
|
||||
tapped: opts.tapped,
|
||||
ratio,
|
||||
cs_half: angle(cs_angle.as_str(), 0.35, 1.3, std::f64::consts::FRAC_PI_4) as f32,
|
||||
tip_half: angle(opts.tip_angle.as_str(), 0.5, 1.3, 1.03) as f32,
|
||||
};
|
||||
// The fields in `dims`' order, each value taken once.
|
||||
let mut fields: Vec<(&str, &mut String)> = Vec::with_capacity(dims.len());
|
||||
match kind {
|
||||
1 => {
|
||||
fields.push((Dim::TopDiameter.label(kind), cb_diameter));
|
||||
fields.push((Dim::CbDepth.label(kind), cb_depth));
|
||||
}
|
||||
2 => {
|
||||
fields.push((Dim::TopDiameter.label(kind), cs_diameter));
|
||||
fields.push((Dim::CsAngle.label(kind), cs_angle));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if dims.contains(&Dim::Depth) {
|
||||
fields.push((Dim::Depth.label(kind), depth));
|
||||
}
|
||||
if dims.contains(&Dim::Diameter) {
|
||||
fields.push((Dim::Diameter.label(kind), diameter));
|
||||
}
|
||||
if dims.contains(&Dim::TipAngle) {
|
||||
fields.push((Dim::TipAngle.label(kind), &mut opts.tip_angle));
|
||||
}
|
||||
crate::ui_kit::figure_rows(ui, "hole section", &mut fields, |painter, pic, slots| {
|
||||
let slots: Vec<(Dim, Rect, bool)> = dims.iter().zip(slots).map(|(d, s): (&Dim, &FigureSlot)| (*d, s.rect, s.hot)).collect();
|
||||
paint(painter, pic, §ion, &slots);
|
||||
})
|
||||
}
|
||||
|
||||
/// A small filled arrowhead at `tip`, pointing away from `from`.
|
||||
fn head(p: &egui::Painter, tip: Pos2, from: Pos2, col: Color32) {
|
||||
let d = (tip - from).normalized();
|
||||
let n = vec2(-d.y, d.x);
|
||||
p.add(Shape::convex_polygon(vec![tip, tip - d * 6.0 + n * 2.5, tip - d * 6.0 - n * 2.5], col, Stroke::NONE));
|
||||
}
|
||||
|
||||
/// A dimension line from `a` to `b` with arrowheads at both ends.
|
||||
fn dimension(p: &egui::Painter, a: Pos2, b: Pos2, stroke: Stroke) {
|
||||
p.line_segment([a, b], stroke);
|
||||
head(p, a, b, stroke.color);
|
||||
head(p, b, a, stroke.color);
|
||||
}
|
||||
|
||||
/// An arc about `c` of radius `r` between the directions at `from` and `to` (radians, screen y
|
||||
/// down), with arrowheads at both ends; returns its middle.
|
||||
fn angle_arc(p: &egui::Painter, c: Pos2, r: f32, from: f32, to: f32, stroke: Stroke) -> Pos2 {
|
||||
let at = |a: f32| c + vec2(a.cos(), a.sin()) * r;
|
||||
let pts: Vec<Pos2> = (0..=16).map(|k| at(from + (to - from) * k as f32 / 16.0)).collect();
|
||||
p.add(Shape::line(pts.clone(), stroke));
|
||||
if let (Some(a), Some(a2), Some(b), Some(b2)) = (pts.first(), pts.get(2), pts.last(), pts.get(14)) {
|
||||
head(p, *a, *a2, stroke.color);
|
||||
head(p, *b, *b2, stroke.color);
|
||||
}
|
||||
at((from + to) / 2.0)
|
||||
}
|
||||
|
||||
/// Diagonal hatching across `r` (a cut through material).
|
||||
fn hatch(p: &egui::Painter, r: Rect, stroke: Stroke) {
|
||||
let step = 7.0;
|
||||
let mut x = r.left() - r.height();
|
||||
while x < r.right() {
|
||||
// The line x + s, bottom - s for s in 0..height, clipped to the rectangle.
|
||||
let (s0, s1) = ((r.left() - x).max(0.0), (r.right() - x).min(r.height()));
|
||||
if s1 > s0 {
|
||||
p.line_segment([pos2(x + s0, r.bottom() - s0), pos2(x + s1, r.bottom() - s1)], stroke);
|
||||
}
|
||||
x += step;
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the section into `pic`, its dimensions at the heights of the fields in `slots`, each
|
||||
/// with a leader to its field.
|
||||
fn paint(p: &egui::Painter, pic: Rect, s: &Section, slots: &[(Dim, Rect, bool)]) {
|
||||
let t = Tokens::get();
|
||||
let field = |d: Dim| slots.iter().find(|x| x.0 == d).map(|x| (x.1, x.2));
|
||||
let y_of = |d: Dim| field(d).map(|(r, _)| r.center().y);
|
||||
let ink = |d: Dim| {
|
||||
let hot = field(d).is_some_and(|(_, h)| h);
|
||||
if hot { Stroke::new(1.6, t.form_primary) } else { Stroke::new(1.0, t.form_dim) }
|
||||
};
|
||||
// A leader from a dimension's point to its field's left edge.
|
||||
let leader = |d: Dim, from: Pos2| {
|
||||
if let Some((r, _)) = field(d) {
|
||||
let to = pos2(r.left() - 3.0, r.center().y);
|
||||
let st = ink(d);
|
||||
p.line_segment([from, to], Stroke::new(st.width.min(1.2), st.color));
|
||||
p.circle_filled(from, 1.8, st.color);
|
||||
}
|
||||
};
|
||||
// Across: the axis, the widest half width, the material's sides; the vertical dimensions sit
|
||||
// right of the material, before the fields.
|
||||
let cx = pic.left() + 44.0;
|
||||
let wide = 24.0;
|
||||
let (left, right) = (pic.left() + 6.0, pic.left() + 76.0);
|
||||
let bottom = pic.bottom() - 3.0;
|
||||
let top_r = wide;
|
||||
let bore_r = if s.kind == 0 { wide * 0.55 } else { wide * s.ratio };
|
||||
// Down: the top face, the counterbore's floor or the countersink's end, the bore's bottom.
|
||||
let top = y_of(Dim::TopDiameter).map_or(pic.top() + 14.0, |y| y + 14.0);
|
||||
let step = match s.kind {
|
||||
1 => y_of(Dim::CbDepth).map_or(top + 16.0, |y| y + 9.0).max(top + 12.0),
|
||||
2 => top + ((top_r - bore_r) / s.cs_half.tan().max(0.2)).clamp(6.0, 28.0),
|
||||
_ => top,
|
||||
};
|
||||
let tip_h = if s.angled { (bore_r / s.tip_half.tan().max(0.2)).clamp(4.0, 16.0) } else { 0.0 };
|
||||
let shoulder = if s.through {
|
||||
bottom + 1.0
|
||||
} else {
|
||||
let mut y = step + 18.0;
|
||||
for d in [Dim::Depth, Dim::Diameter] {
|
||||
if let Some(v) = y_of(d) {
|
||||
y = y.max(v + 10.0);
|
||||
}
|
||||
}
|
||||
if let Some(v) = y_of(Dim::TipAngle) {
|
||||
y = y.max(v - tip_h - 2.0);
|
||||
}
|
||||
y.min(bottom - tip_h - 10.0).max(step + 8.0)
|
||||
};
|
||||
// The material, cut: hatched, with the hole's room cleared out of it.
|
||||
let block = Rect::from_min_max(pos2(left, top), pos2(right, bottom));
|
||||
p.rect_filled(block, 0.0, t.form_dim.gamma_multiply(0.16));
|
||||
hatch(p, block, Stroke::new(0.8, t.form_dim.gamma_multiply(0.45)));
|
||||
// The right half of the hole's outline, top to bottom (half widths), then mirrored.
|
||||
let mut half: Vec<(f32, f32)> = match s.kind {
|
||||
1 => vec![(top_r, top), (top_r, step), (bore_r, step), (bore_r, shoulder)],
|
||||
2 => vec![(top_r, top), (bore_r, step), (bore_r, shoulder)],
|
||||
_ => vec![(bore_r, top), (bore_r, shoulder)],
|
||||
};
|
||||
if s.through
|
||||
&& let Some(last) = half.last_mut()
|
||||
{
|
||||
last.1 = bottom + 1.0;
|
||||
}
|
||||
let clear = t.dialog_body;
|
||||
for w in half.windows(2) {
|
||||
let &[(a, ya), (b, yb)] = w else { continue };
|
||||
if yb > ya {
|
||||
p.add(Shape::convex_polygon(vec![pos2(cx - a, ya), pos2(cx + a, ya), pos2(cx + b, yb), pos2(cx - b, yb)], clear, Stroke::NONE));
|
||||
}
|
||||
}
|
||||
let apex = pos2(cx, shoulder + tip_h);
|
||||
if s.angled && !s.through {
|
||||
p.add(Shape::convex_polygon(vec![pos2(cx - bore_r, shoulder), pos2(cx + bore_r, shoulder), apex], clear, Stroke::NONE));
|
||||
}
|
||||
// A tapped hole's thread: thin lines at the thread's major diameter, in the material.
|
||||
if s.tapped {
|
||||
let r = bore_r * 1.22;
|
||||
let (y0, y1) = (half.iter().rev().nth(1).map_or(top, |x| x.1), if s.through { bottom } else { shoulder - 3.0 });
|
||||
for x in [cx - r, cx + r] {
|
||||
p.line_segment([pos2(x, y0 + 2.0), pos2(x, y1)], Stroke::new(1.0, t.form_ink));
|
||||
}
|
||||
}
|
||||
// Outlines: the block's top and sides, the hole's walls and bottom.
|
||||
let edge = Stroke::new(1.4, t.form_ink);
|
||||
let wall = |sign: f32| -> Vec<Pos2> { half.iter().map(|(w, y)| pos2(cx + sign * w, *y)).collect() };
|
||||
let opening = half.first().map_or(bore_r, |x| x.0);
|
||||
p.add(Shape::line(vec![pos2(left, bottom), pos2(left, top), pos2(cx - opening, top)], edge));
|
||||
p.add(Shape::line(vec![pos2(cx + opening, top), pos2(right, top), pos2(right, bottom)], edge));
|
||||
p.add(Shape::line(wall(-1.0), edge));
|
||||
p.add(Shape::line(wall(1.0), edge));
|
||||
if s.through {
|
||||
p.line_segment([pos2(left, bottom), pos2(cx - bore_r, bottom)], edge);
|
||||
p.line_segment([pos2(cx + bore_r, bottom), pos2(right, bottom)], edge);
|
||||
} else {
|
||||
p.line_segment([pos2(left, bottom), pos2(right, bottom)], edge);
|
||||
if s.angled {
|
||||
p.add(Shape::line(vec![pos2(cx - bore_r, shoulder), apex, pos2(cx + bore_r, shoulder)], edge));
|
||||
} else {
|
||||
p.line_segment([pos2(cx - bore_r, shoulder), pos2(cx + bore_r, shoulder)], edge);
|
||||
}
|
||||
}
|
||||
// To an object: the face it stops at, dashed across the bottom of the hole.
|
||||
if s.to_object {
|
||||
let y = shoulder + tip_h + 3.0;
|
||||
p.add(Shape::dashed_line(&[pos2(left - 2.0, y), pos2(right + 2.0, y)], Stroke::new(1.2, t.form_primary), 4.0, 3.0));
|
||||
}
|
||||
// The hole's axis.
|
||||
p.add(Shape::dashed_line(&[pos2(cx, top - 6.0), pos2(cx, (shoulder + tip_h + 6.0).min(pic.bottom()))], Stroke::new(0.8, t.form_dim), 6.0, 3.0));
|
||||
|
||||
// Dimensions, each lined up with its field.
|
||||
let thin = |d: Dim| {
|
||||
let st = ink(d);
|
||||
Stroke::new(0.8, st.color)
|
||||
};
|
||||
if let Some(y) = y_of(Dim::TopDiameter) {
|
||||
let (a, b) = (pos2(cx - top_r, y), pos2(cx + top_r, y));
|
||||
p.line_segment([pos2(a.x, top - 2.0), pos2(a.x, y - 3.0)], thin(Dim::TopDiameter));
|
||||
p.line_segment([pos2(b.x, top - 2.0), pos2(b.x, y - 3.0)], thin(Dim::TopDiameter));
|
||||
dimension(p, a, b, ink(Dim::TopDiameter));
|
||||
leader(Dim::TopDiameter, b);
|
||||
}
|
||||
// Depths stand right of the material: the counterbore's nearer, the hole's farther out.
|
||||
let mut x = right + 8.0;
|
||||
if let Some(y) = y_of(Dim::CbDepth) {
|
||||
p.line_segment([pos2(cx + top_r, step), pos2(x + 3.0, step)], thin(Dim::CbDepth));
|
||||
p.line_segment([pos2(right, top), pos2(x + 3.0, top)], thin(Dim::CbDepth));
|
||||
dimension(p, pos2(x, top), pos2(x, step), ink(Dim::CbDepth));
|
||||
leader(Dim::CbDepth, pos2(x, y.clamp(top + 2.0, step - 2.0)));
|
||||
x += 10.0;
|
||||
}
|
||||
if let Some(y) = y_of(Dim::Depth) {
|
||||
p.line_segment([pos2(cx + bore_r, shoulder), pos2(x + 3.0, shoulder)], thin(Dim::Depth));
|
||||
p.line_segment([pos2(right, top), pos2(x + 3.0, top)], thin(Dim::Depth));
|
||||
dimension(p, pos2(x, top), pos2(x, shoulder), ink(Dim::Depth));
|
||||
leader(Dim::Depth, pos2(x, y.clamp(top + 2.0, shoulder - 2.0)));
|
||||
}
|
||||
if let Some(y) = y_of(Dim::CsAngle) {
|
||||
// About the point where the countersink's sides meet, between them.
|
||||
let k = s.cs_half.tan().max(0.2);
|
||||
let meet = pos2(cx, top + top_r / k);
|
||||
let r = (meet.y - top) * 0.7;
|
||||
let up = -std::f32::consts::FRAC_PI_2;
|
||||
let mid = angle_arc(p, meet, r, up - s.cs_half, up + s.cs_half, ink(Dim::CsAngle));
|
||||
let end = meet + vec2((up + s.cs_half).cos(), (up + s.cs_half).sin()) * r;
|
||||
leader(Dim::CsAngle, if (end.y - y).abs() < (mid.y - y).abs() { end } else { mid });
|
||||
}
|
||||
if let Some(y) = y_of(Dim::Diameter) {
|
||||
let lo = if s.kind == 0 { top + 3.0 } else { step + 3.0 };
|
||||
let hi = if s.through { bottom - 3.0 } else { shoulder - 3.0 };
|
||||
let y = if hi > lo { y.clamp(lo, hi) } else { (lo + hi) / 2.0 };
|
||||
let (a, b) = (pos2(cx - bore_r, y), pos2(cx + bore_r, y));
|
||||
dimension(p, a, b, ink(Dim::Diameter));
|
||||
leader(Dim::Diameter, b);
|
||||
}
|
||||
if y_of(Dim::TipAngle).is_some() && s.angled && !s.through {
|
||||
// Most of the way along the tip's sides, so the arc spans them where they are clear.
|
||||
let r = (bore_r.hypot(tip_h) * 0.8).max(6.0);
|
||||
let up = -std::f32::consts::FRAC_PI_2;
|
||||
angle_arc(p, apex, r, up - s.tip_half, up + s.tip_half, ink(Dim::TipAngle));
|
||||
leader(Dim::TipAngle, apex + vec2((up + s.tip_half).cos(), (up + s.tip_half).sin()) * r);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn opts(all: bool, angled: bool) -> HoleOpts {
|
||||
HoleOpts { all, angled, ..HoleOpts::default() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_sizes_follow_the_options() {
|
||||
use Dim::*;
|
||||
assert_eq!(dims(0, &opts(false, true), false), vec![Depth, Diameter, TipAngle]);
|
||||
assert_eq!(dims(0, &opts(false, false), false), vec![Depth, Diameter]);
|
||||
assert_eq!(dims(0, &opts(true, true), false), vec![Diameter], "through all: no depth, no tip");
|
||||
assert_eq!(dims(0, &opts(false, true), true), vec![Diameter, TipAngle], "to an object: no depth");
|
||||
assert_eq!(dims(1, &opts(false, false), false), vec![TopDiameter, CbDepth, Depth, Diameter]);
|
||||
assert_eq!(dims(2, &opts(true, false), false), vec![TopDiameter, CsAngle, Diameter]);
|
||||
let tapped = HoleOpts { tapped: true, ..opts(false, true) };
|
||||
assert_eq!(dims(0, &tapped, false), vec![Depth, TipAngle], "tapped: the thread sets the diameter");
|
||||
assert_eq!(TopDiameter.label(1), "Counterbore Ø");
|
||||
assert_eq!(TopDiameter.label(2), "Countersink Ø");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,388 @@
|
||||
//! Placing a Single hole on the canvas (#2171, #1047). Both behaviours are Preferences › Design
|
||||
//! settings, off by default, so a hole goes where it is clicked and a second pick on its face
|
||||
//! takes it out, as it always did.
|
||||
//!
|
||||
//! Create Hole › Snap to face and edge centres (`hole_snaps`): the planar face under the cursor offers snap points, the
|
||||
//! middle of the face and the centres of its round edges (a boss standing on it, a rounded
|
||||
//! corner, a hole already in it). While the cursor is over the face they show as small marks; a
|
||||
//! pick within reach of one, or on one of those round edges, is taken at that point, and the mark
|
||||
//! it takes is named. Sketch points on the face (#657) still come first. Ctrl or Alt held: no snap.
|
||||
//!
|
||||
//! Create Hole › Move holes by clicking or dragging (`hole_moves`): every placed hole has a handle at its
|
||||
//! centre that drags it across the model (snapping as a pick would) and takes it out when
|
||||
//! clicked, and a pick elsewhere on a face that already has a hole moves the hole there.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
use egui::{Pos2, vec2};
|
||||
use solidcraft_engine::Sel;
|
||||
use solidcraft_engine::Session;
|
||||
use solidcraft_engine::doc::expr::Kind as ValueKind;
|
||||
use solidcraft_engine::geom::{Aabb3, Mesh, Vec3};
|
||||
|
||||
use crate::SolveApp;
|
||||
use crate::dialogs::{Dialog, Kind};
|
||||
use crate::dialogs_assembly::SnapKind;
|
||||
use crate::selection::same_item;
|
||||
use crate::theme::Tokens;
|
||||
use crate::viewport::{Hit, Proj};
|
||||
|
||||
/// How near (screen points) a pick must come to a snap point to take it.
|
||||
pub(crate) const POINT_REACH: f32 = 10.0;
|
||||
/// How near a pick must come to a round edge to take its centre.
|
||||
pub(crate) const RIM_REACH: f32 = 6.0;
|
||||
/// How far (screen points) from a hole's centre a press takes its handle.
|
||||
const HANDLE_REACH: f32 = 9.0;
|
||||
/// The most triangles of one face looked through for its snaps.
|
||||
const MAX_TRIANGLES: usize = 1 << 18;
|
||||
|
||||
/// A place a hole may snap to on a planar face.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) struct Snap {
|
||||
pub at: Vec3,
|
||||
pub kind: SnapKind,
|
||||
/// The round edges whose centre it is (a rim split into pieces makes one snap).
|
||||
pub rims: Vec<Vec<Vec3>>,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// The last face's snaps, with the mesh they were found on (held, so a new mesh at the same
|
||||
/// address can't pass for it).
|
||||
static CACHE: RefCell<Option<(Arc<Mesh>, usize, Arc<Vec<Snap>>)>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// The snaps of face `face` of mesh `m`: none unless the face is planar.
|
||||
pub(crate) fn face_snaps(m: &Arc<Mesh>, face: usize) -> Arc<Vec<Snap>> {
|
||||
let cached = CACHE.with(|c| c.borrow().as_ref().filter(|(mm, f, _)| Arc::ptr_eq(mm, m) && *f == face).map(|(_, _, s)| s.clone()));
|
||||
if let Some(snaps) = cached {
|
||||
return snaps;
|
||||
}
|
||||
let snaps = Arc::new(find_snaps(m, face));
|
||||
CACHE.with(|c| *c.borrow_mut() = Some((m.clone(), face, snaps.clone())));
|
||||
snaps
|
||||
}
|
||||
|
||||
/// The centres of the face's round edges that lie in its plane, and the middle of the face (the
|
||||
/// centre of its extent, when that is on the face and no round edge's centre is there already).
|
||||
fn find_snaps(m: &Mesh, face: usize) -> Vec<Snap> {
|
||||
let tris: Vec<[Vec3; 3]> =
|
||||
m.triangles.iter().zip(&m.tri_face).filter(|(_, f)| **f as usize == face).filter_map(|(t, _)| m.tri(t)).take(MAX_TRIANGLES).collect();
|
||||
let Some(&[a, _, _]) = tris.first() else { return Vec::new() };
|
||||
// The plane: the triangles' summed normals (counter-clockwise from outside), through a corner.
|
||||
let Some(n) = tris.iter().fold(Vec3::ZERO, |s, [p, q, r]| s + (*q - *p).cross(*r - *p)).normalized() else { return Vec::new() };
|
||||
let mut bounds = Aabb3::EMPTY;
|
||||
tris.iter().flatten().for_each(|p| bounds.add(*p));
|
||||
let tol = (bounds.diagonal() * 1e-6).max(1e-7);
|
||||
if tris.iter().flatten().any(|p| (*p - a).dot(n).abs() > tol * 10.0) {
|
||||
return Vec::new();
|
||||
}
|
||||
let same = |p: Vec3, q: Vec3| p.dist(q) <= tol * 100.0;
|
||||
let mut snaps: Vec<Snap> = Vec::new();
|
||||
for e in m.face_edges(face as u32) {
|
||||
let Some(pts) = m.edges.get(e) else { continue };
|
||||
let Some((c, axis)) = crate::dialogs_assembly::circle_of(pts) else { continue };
|
||||
// A circle or an arc in the face's plane (a seam or a slanted rim is no place for a hole).
|
||||
if (c - a).dot(n).abs() > tol * 100.0 || axis.dot(n).abs() < 1.0 - 1e-6 {
|
||||
continue;
|
||||
}
|
||||
match snaps.iter_mut().find(|s| same(s.at, c)) {
|
||||
Some(s) => s.rims.push(pts.clone()),
|
||||
None => snaps.push(Snap { at: c, kind: SnapKind::CircleCenter, rims: vec![pts.clone()] }),
|
||||
}
|
||||
}
|
||||
let c = bounds.center();
|
||||
let c = c - n * (c - a).dot(n);
|
||||
if on_face(c, n, &tris, tol) && !snaps.iter().any(|s| same(s.at, c)) {
|
||||
snaps.insert(0, Snap { at: c, kind: SnapKind::FaceCenter, rims: Vec::new() });
|
||||
}
|
||||
snaps
|
||||
}
|
||||
|
||||
/// Does `p` (in the plane of normal `n`) lie on one of the triangles?
|
||||
fn on_face(p: Vec3, n: Vec3, tris: &[[Vec3; 3]], tol: f64) -> bool {
|
||||
tris.iter().any(|[a, b, c]| [(a, b), (b, c), (c, a)].iter().all(|(u, v)| (**v - **u).cross(p - **u).dot(n) >= -tol * (**v - **u).len()))
|
||||
}
|
||||
|
||||
/// Is a Single hole being placed: the Hole dialog open on its face input?
|
||||
pub(crate) fn placing(app: &SolveApp) -> bool {
|
||||
app.dialog.as_ref().is_some_and(|d| {
|
||||
d.active == 0
|
||||
&& matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple)
|
||||
&& d.active_input().is_some_and(|i| crate::dialogs::snaps_to_points(i.accept))
|
||||
})
|
||||
}
|
||||
|
||||
/// Do picks snap while a Single hole is placed (the preference is on)?
|
||||
pub(crate) fn snapping(app: &SolveApp) -> bool {
|
||||
app.preferences.hole_snaps && placing(app)
|
||||
}
|
||||
|
||||
/// The distance on screen from `p` to the segment from `a` to `b`.
|
||||
fn to_segment(p: Pos2, a: Pos2, b: Pos2) -> f32 {
|
||||
let v = b - a;
|
||||
let t = if v.length_sq() > 0.0 { ((p - a).dot(v) / v.length_sq()).clamp(0.0, 1.0) } else { 0.0 };
|
||||
p.distance(a + v * t)
|
||||
}
|
||||
|
||||
/// The snap a pick at `pos` takes among `snaps`: the nearest snap point within [`POINT_REACH`],
|
||||
/// else the centre of the nearest round edge within [`RIM_REACH`].
|
||||
fn nearest(proj: &Proj, pos: Pos2, snaps: &[Snap]) -> Option<Snap> {
|
||||
let point = snaps
|
||||
.iter()
|
||||
.filter_map(|s| Some((proj.to_screen(s.at)?.distance(pos), s)))
|
||||
.filter(|(d, _)| *d <= POINT_REACH)
|
||||
.min_by(|a, b| a.0.total_cmp(&b.0));
|
||||
if let Some((_, s)) = point {
|
||||
return Some(s.clone());
|
||||
}
|
||||
snaps
|
||||
.iter()
|
||||
.filter_map(|s| {
|
||||
let d = s
|
||||
.rims
|
||||
.iter()
|
||||
.flat_map(|r| r.windows(2))
|
||||
.filter_map(|w| Some(to_segment(pos, proj.to_screen(*w.first()?)?, proj.to_screen(*w.get(1)?)?)))
|
||||
.fold(f32::INFINITY, f32::min);
|
||||
(d <= RIM_REACH).then_some((d, s))
|
||||
})
|
||||
.min_by(|a, b| a.0.total_cmp(&b.0))
|
||||
.map(|(_, s)| s.clone())
|
||||
}
|
||||
|
||||
/// A pick for a Single hole's face place: the nearest face under the cursor is taken at the snap
|
||||
/// within reach on it, or at the centre of a round edge the cursor is on (the edge lies between
|
||||
/// the face and a hole's or a boss's wall, so the face under the cursor may be the wall).
|
||||
pub(crate) fn snap_hits(app: &SolveApp, proj: &Proj, pos: Pos2, hits: &mut Vec<Hit>) {
|
||||
if !snapping(app) || crate::drag_snap::suppressed() {
|
||||
return;
|
||||
}
|
||||
let st = app.session.world_state();
|
||||
let face = hits.iter().position(|h| matches!(h, Hit::Face { .. }));
|
||||
let at_face = face.and_then(|i| match hits.get(i) {
|
||||
Some(Hit::Face { body, index, .. }) => {
|
||||
let m = st.body(body)?.mesh();
|
||||
nearest(proj, pos, &face_snaps(&m, *index)).map(|s| (body.clone(), *index, s.at))
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
let on_rim = || {
|
||||
hits.iter().find_map(|h| {
|
||||
let Hit::Edge { body, index, .. } = h else { return None };
|
||||
let m = st.body(body)?.mesh();
|
||||
let pts = m.edges.get(*index)?;
|
||||
m.edge_faces.get(*index)?.iter().find_map(|f| {
|
||||
let snaps = face_snaps(&m, *f as usize);
|
||||
snaps.iter().find(|s| s.rims.iter().any(|r| r == pts)).map(|s| (body.clone(), *f as usize, s.at))
|
||||
})
|
||||
})
|
||||
};
|
||||
let Some((body, index, point)) = at_face.or_else(on_rim) else { return };
|
||||
let hit = Hit::Face { body, index, point };
|
||||
match face {
|
||||
Some(i) => {
|
||||
if let Some(h) = hits.get_mut(i) {
|
||||
*h = hit;
|
||||
}
|
||||
}
|
||||
None => hits.push(hit),
|
||||
}
|
||||
}
|
||||
|
||||
/// The snap a face place sits on, if any.
|
||||
fn snap_under(app: &SolveApp, body: &str, index: usize, point: Vec3) -> (Arc<Vec<Snap>>, Option<Snap>) {
|
||||
let st = app.session.world_state();
|
||||
let Some(b) = st.body(body) else { return (Arc::new(Vec::new()), None) };
|
||||
let snaps = face_snaps(&b.mesh(), index);
|
||||
let on = snaps.iter().find(|s| s.at.dist(point) <= 1e-9 * (1.0 + s.at.len())).cloned();
|
||||
(snaps, on)
|
||||
}
|
||||
|
||||
/// The holes placed so far: the index of each one's face place, and where it is. A round face
|
||||
/// split at its seam is picked as both halves, the one picked first where the hole goes.
|
||||
fn places(s: &Session, d: &Dialog) -> Vec<(usize, Vec3)> {
|
||||
let Some(inp) = d.inputs.first() else { return Vec::new() };
|
||||
let mut taken: Vec<Sel> = Vec::new();
|
||||
let mut out = Vec::new();
|
||||
for (i, x) in inp.items.iter().enumerate() {
|
||||
let Sel::Face { point, .. } = x else { continue };
|
||||
if taken.iter().any(|t| same_item(t, x)) {
|
||||
continue;
|
||||
}
|
||||
taken.extend(crate::viewport::grouped_selection(s, x));
|
||||
out.push((i, *point));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Move the hole placed by item `i` of the face input to the face place `to`. The place (with the
|
||||
/// other half of a round face split at its seam) gives way to `to` (with its own). Not onto a face
|
||||
/// another hole holds: a face takes one Single hole, so that would lose the other one.
|
||||
pub(crate) fn move_place(d: &mut Dialog, s: &Session, i: usize, to: Sel) -> bool {
|
||||
let group = crate::viewport::grouped_selection(s, &to);
|
||||
let Some(inp) = d.inputs.first_mut() else { return false };
|
||||
let Some(old) = inp.items.get(i).cloned() else { return false };
|
||||
let own = crate::viewport::grouped_selection(s, &old);
|
||||
let mine = |x: &Sel| own.iter().any(|g| same_item(x, g));
|
||||
if inp.items.iter().any(|x| !mine(x) && group.iter().any(|g| same_item(x, g))) {
|
||||
return false;
|
||||
}
|
||||
let at = inp.items.iter().position(&mine).unwrap_or(i);
|
||||
inp.items.retain(|x| !mine(x));
|
||||
let at = at.min(inp.items.len());
|
||||
for (k, x) in group.into_iter().enumerate() {
|
||||
inp.items.insert(at + k, x);
|
||||
}
|
||||
d.error = None;
|
||||
true
|
||||
}
|
||||
|
||||
/// A Single hole's face place picked on a face that already has a hole moves that hole there
|
||||
/// (true), when holes move by clicking. A pick on the hole itself (within its radius) is left to
|
||||
/// take it out, as before.
|
||||
pub(crate) fn pick_moves(d: &mut Dialog, s: &Session, sel: &Sel) -> bool {
|
||||
let Kind::Hole { opts, diameter, .. } = &d.kind else { return false };
|
||||
let Sel::Face { point, .. } = sel else { return false };
|
||||
if opts.multiple || d.active != 0 {
|
||||
return false;
|
||||
}
|
||||
let radius = s.doc.eval(diameter, ValueKind::Length).ok().filter(|v| v.is_finite() && *v > 0.0).map_or(0.0, |v| v / 2.0);
|
||||
let group = crate::viewport::grouped_selection(s, sel);
|
||||
let Some(inp) = d.inputs.first() else { return false };
|
||||
let Some(i) = inp.items.iter().position(|x| group.iter().any(|g| same_item(x, g))) else { return false };
|
||||
let Some(Sel::Face { point: was, .. }) = inp.items.get(i) else { return false };
|
||||
if was.dist(*point) <= radius {
|
||||
return false;
|
||||
}
|
||||
move_place(d, s, i, sel.clone())
|
||||
}
|
||||
|
||||
/// The hovered face's snap marks, and the face places' handles when holes move by dragging.
|
||||
/// Called after the canvas draws the dialog's arrows, so a press on a hole's centre takes the
|
||||
/// hole, not the depth arrow.
|
||||
pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj) {
|
||||
let Some(d) = app.dialog.as_ref() else { return };
|
||||
if !matches!(&d.kind, Kind::Hole { opts, .. } if !opts.multiple) || app.applying.is_some() {
|
||||
return;
|
||||
}
|
||||
let t = Tokens::get();
|
||||
marks(app, painter, proj);
|
||||
if !app.preferences.hole_moves {
|
||||
return;
|
||||
}
|
||||
let places = places(&app.session, d);
|
||||
let mut moved: Option<(usize, Sel)> = None;
|
||||
let mut removed: Option<usize> = None;
|
||||
for (n, (i, at)) in places.into_iter().enumerate() {
|
||||
let Some(mut c) = proj.to_screen(at) else { continue };
|
||||
let id = egui::Id::new(("sc_hole_place", i));
|
||||
let r = ui.interact(egui::Rect::from_center_size(c, vec2(2.0 * HANDLE_REACH, 2.0 * HANDLE_REACH)), id, egui::Sense::click_and_drag());
|
||||
// A click on the hole takes it out, as a pick of a picked face does.
|
||||
if r.clicked() {
|
||||
removed = Some(i);
|
||||
}
|
||||
if r.dragged()
|
||||
&& let Some(p) = r.interact_pointer_pos()
|
||||
{
|
||||
// Where a click under the pointer would place a hole: on a face, snapped.
|
||||
let hits = crate::viewport::pick(app, proj, p);
|
||||
if let Some((_, to @ Sel::Face { .. })) = crate::viewport::candidate(app, &hits) {
|
||||
if let Sel::Face { point, .. } = &to
|
||||
&& let Some(q) = proj.to_screen(*point)
|
||||
{
|
||||
c = q;
|
||||
}
|
||||
moved = Some((i, to));
|
||||
}
|
||||
}
|
||||
let hot = r.hovered() || r.dragged();
|
||||
if hot {
|
||||
ui.ctx().set_cursor_icon(if r.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab });
|
||||
}
|
||||
crate::icons::markers::hole_handle(painter, c, if hot { t.accent } else { t.manipulator }, hot);
|
||||
crate::scenario::publish_handle(&format!("hole:{n}"), c);
|
||||
if !r.dragged() {
|
||||
r.on_hover_text(crate::i18n::tr_label("Drag to move the hole; click to remove it"));
|
||||
}
|
||||
}
|
||||
if let Some((i, to)) = moved
|
||||
&& let Some(d) = app.dialog.as_mut()
|
||||
{
|
||||
move_place(d, &app.session, i, to);
|
||||
}
|
||||
if let Some(i) = removed
|
||||
&& let Some(d) = app.dialog.as_mut()
|
||||
{
|
||||
remove_place(d, &app.session, i);
|
||||
}
|
||||
}
|
||||
|
||||
/// Take out the hole placed by item `i` of the face input (with the other half of a round face
|
||||
/// split at its seam).
|
||||
fn remove_place(d: &mut Dialog, s: &Session, i: usize) {
|
||||
let Some(inp) = d.inputs.first_mut() else { return };
|
||||
let Some(old) = inp.items.get(i).cloned() else { return };
|
||||
let own = crate::viewport::grouped_selection(s, &old);
|
||||
inp.items.retain(|x| !own.iter().any(|g| same_item(x, g)));
|
||||
d.error = None;
|
||||
}
|
||||
|
||||
/// The snap points of the face under the cursor while a Single hole is placed, and the one a
|
||||
/// pick there takes, named.
|
||||
fn marks(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {
|
||||
if !snapping(app) {
|
||||
return;
|
||||
}
|
||||
let Some(Hit::Face { body, index, point }) = &app.viewport.hover else { return };
|
||||
let t = Tokens::get();
|
||||
let (snaps, on) = snap_under(app, body, *index, *point);
|
||||
for s in snaps.iter() {
|
||||
let Some(c) = proj.to_screen(s.at) else { continue };
|
||||
if on.as_ref().is_some_and(|o| o.at == s.at) {
|
||||
let name = crate::i18n::tr_label(crate::dialogs_assembly::snap_name(s.kind));
|
||||
crate::icons::markers::snap(painter, c, None, s.kind, t.hover_profile_edge, Some(name));
|
||||
} else {
|
||||
crate::icons::markers::snap_hint(painter, c, s.kind, t.manipulator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use solidcraft_engine::geom::Vec3;
|
||||
|
||||
/// A square face (two triangles) at z = 5 with a round edge about (2, 3) on it.
|
||||
fn mesh() -> Mesh {
|
||||
let p = |x: f64, y: f64| Vec3::new(x, y, 5.0);
|
||||
let rim: Vec<Vec3> = (0..=16).map(|k| f64::from(k) * std::f64::consts::TAU / 16.0).map(|a| p(2.0 + a.cos(), 3.0 + a.sin())).collect();
|
||||
Mesh {
|
||||
positions: vec![p(0.0, 0.0), p(10.0, 0.0), p(10.0, 10.0), p(0.0, 10.0)],
|
||||
triangles: vec![[0, 1, 2], [0, 2, 3]],
|
||||
tri_face: vec![0, 0],
|
||||
edges: vec![vec![p(0.0, 0.0), p(10.0, 0.0)], rim],
|
||||
edge_faces: vec![vec![0], vec![0, 1]],
|
||||
..Mesh::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_planar_face_snaps_to_its_middle_and_its_round_edges_centres() {
|
||||
let snaps = find_snaps(&mesh(), 0);
|
||||
let at: Vec<(SnapKind, Vec3)> = snaps.iter().map(|s| (s.kind, s.at)).collect();
|
||||
assert_eq!(at.len(), 2, "{at:?}");
|
||||
assert!(at[0].0 == SnapKind::FaceCenter && at[0].1.dist(Vec3::new(5.0, 5.0, 5.0)) < 1e-9, "{at:?}");
|
||||
assert!(at[1].0 == SnapKind::CircleCenter && at[1].1.dist(Vec3::new(2.0, 3.0, 5.0)) < 1e-9, "{at:?}");
|
||||
assert!(find_snaps(&mesh(), 7).is_empty(), "no triangles, no snaps");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_curved_face_has_no_snaps() {
|
||||
let mut m = mesh();
|
||||
if let Some(p) = m.positions.get_mut(2) {
|
||||
p.z = 6.0;
|
||||
}
|
||||
assert!(find_snaps(&m, 0).is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
//! Placing a Single hole (#2171, #1047). With Snap to face and edge centres on (Preferences, off by
|
||||
//! default), a pick near the middle of a face or on a round edge snaps there, and Alt held places
|
||||
//! it where it was clicked. With Move holes by clicking or dragging on (also off by default), the
|
||||
//! handle drags a placed hole (also one being edited) and a second pick on its face moves it.
|
||||
//! Both off, picks behave as before. Either way the dialog shows the hole's sizes beside a
|
||||
//! section of it.
|
||||
|
||||
use serde_json::json;
|
||||
use solidcraft_engine::Sel;
|
||||
use solidcraft_engine::doc::FeatureKind;
|
||||
use solidcraft_engine::geom::Vec3;
|
||||
|
||||
use crate::dialogs::Kind;
|
||||
use crate::scenario::{Harness, handle_at, rect_of};
|
||||
use crate::viewport::Hit;
|
||||
|
||||
/// A 40 × 30 × 20 block seen from the top, with a 10 mm hole through it at (10, 10), and hole
|
||||
/// snaps and moves turned on as the Preferences dialog (or `ui.prefs`) turns them on.
|
||||
fn block() -> Harness {
|
||||
let mut h = block_as_installed();
|
||||
crate::prefs::set(&mut h.app, &json!({"hole_snaps": true, "hole_moves": true})).unwrap();
|
||||
assert!(h.app.preferences.hole_snaps && h.app.preferences.hole_moves);
|
||||
h
|
||||
}
|
||||
|
||||
/// The block with the preferences a new installation has.
|
||||
fn block_as_installed() -> Harness {
|
||||
let mut h = Harness::new();
|
||||
h.app.ui.show_origin = false;
|
||||
h.app.run("solid.box", json!({"length": 40, "width": 30, "height": 20})).unwrap();
|
||||
h.app.run("solid.hole", json!({"position": [10, 10, 20], "diameter": 10, "name": "Bore"})).unwrap();
|
||||
h.step(&json!({"call": "ui.view", "params": {"view": "top"}})).unwrap();
|
||||
h.settle();
|
||||
h
|
||||
}
|
||||
|
||||
/// Where a world point is on screen.
|
||||
fn screen(h: &mut Harness, p: Vec3) -> [f64; 2] {
|
||||
h.at(&json!({"world": [p.x, p.y, p.z]})).unwrap()
|
||||
}
|
||||
|
||||
/// `p` on screen, moved by `dx`, `dy` points.
|
||||
fn off(h: &mut Harness, p: Vec3, dx: f64, dy: f64) -> [f64; 2] {
|
||||
let c = screen(h, p);
|
||||
[c[0] + dx, c[1] + dy]
|
||||
}
|
||||
|
||||
/// The face places the open dialog holds.
|
||||
fn places(h: &Harness) -> Vec<Vec3> {
|
||||
h.app.dialog.as_ref().unwrap().inputs[0]
|
||||
.items
|
||||
.iter()
|
||||
.map(|x| match x {
|
||||
Sel::Face { point, .. } => *point,
|
||||
other => panic!("a face place, not {other:?}"),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The last feature's id and position, when it is a hole.
|
||||
fn last_hole(h: &Harness) -> (u64, Vec3) {
|
||||
let f = h.app.session.doc.features.last().unwrap();
|
||||
match &f.kind {
|
||||
FeatureKind::Hole { position, .. } => (f.id, position.0),
|
||||
other => panic!("the last feature is not a hole: {}", other.type_name()),
|
||||
}
|
||||
}
|
||||
|
||||
fn solid_at(h: &Harness, p: Vec3) -> bool {
|
||||
h.app.session.model.state().bodies.iter().any(|b| b.body.contains(p))
|
||||
}
|
||||
|
||||
const MIDDLE: Vec3 = Vec3::new(20.0, 15.0, 20.0);
|
||||
const BORE: Vec3 = Vec3::new(10.0, 10.0, 20.0);
|
||||
|
||||
#[test]
|
||||
fn a_pick_near_the_middle_of_a_face_goes_to_the_middle() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let at = off(&mut h, MIDDLE, 5.0, -4.0);
|
||||
h.step(&json!({"move": at})).unwrap();
|
||||
match &h.app.viewport.hover {
|
||||
Some(Hit::Face { point, .. }) => assert!(point.dist(MIDDLE) < 1e-9, "the face lights up at its middle: {point:?}"),
|
||||
other => panic!("the face lights up, not {other:?}"),
|
||||
}
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) < 1e-9), "{:?}", places(&h));
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (_, position) = last_hole(&h);
|
||||
assert!(position.dist(MIDDLE) < 1e-9, "{position:?}");
|
||||
assert!(!solid_at(&h, MIDDLE - Vec3::new(0.0, 0.0, 5.0)), "drilled at the middle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pick_away_from_snaps_or_with_alt_held_stays_where_it_was_clicked() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
// Well away from the middle and from the bore's rim.
|
||||
let away = Vec3::new(30.0, 8.0, 20.0);
|
||||
let at = screen(&mut h, away);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(away) < 1e-3 && p.dist(MIDDLE) > 1.0), "{:?}", places(&h));
|
||||
h.step(&json!({"key": "Escape"})).unwrap();
|
||||
// Alt held: no snap, even beside the middle.
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let at = off(&mut h, MIDDLE, 5.0, -4.0);
|
||||
h.step(&json!({"move": at, "alt": true})).unwrap();
|
||||
h.step(&json!({"click": at, "alt": true})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) > 0.1 && (p.z - 20.0).abs() < 1e-9), "{:?}", places(&h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pick_on_a_round_edge_goes_to_its_centre() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
// On the bore's rim, and a few points outside it on the top face.
|
||||
for (dx, label) in [(0.0, "on the rim"), (3.0, "beside the rim")] {
|
||||
let rim = off(&mut h, BORE + Vec3::new(5.0, 0.0, 0.0), dx, 0.0);
|
||||
let c = screen(&mut h, BORE);
|
||||
assert!((rim[0] - c[0]).abs() > 2.0 * f64::from(crate::hole_place::POINT_REACH), "the rim is out of the centre's reach");
|
||||
h.step(&json!({"click": rim})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(BORE) < 1e-6), "{label}: {:?}", places(&h));
|
||||
h.step(&json!({"key": "Escape"})).unwrap();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
}
|
||||
// A counterbore round the bore: drilled on its axis.
|
||||
let rim = screen(&mut h, BORE + Vec3::new(5.0, 0.0, 0.0));
|
||||
h.step(&json!({"click": rim})).unwrap();
|
||||
if let Some(Kind::Hole { kind, cb_diameter, cb_depth, diameter, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
|
||||
*kind = 1;
|
||||
*diameter = "12 mm".into();
|
||||
*cb_diameter = "16 mm".into();
|
||||
*cb_depth = "3 mm".into();
|
||||
}
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (id, position) = last_hole(&h);
|
||||
assert!(position.dist(BORE) < 1e-6, "{position:?}");
|
||||
assert!(h.app.session.model.result(id).is_some_and(|r| r.error.is_none()), "the counterbore cuts");
|
||||
assert!(!solid_at(&h, BORE + Vec3::new(7.5, 0.0, -1.5)) && solid_at(&h, BORE + Vec3::new(8.5, 0.0, -1.5)), "8 mm round the axis");
|
||||
assert!(!solid_at(&h, BORE + Vec3::new(5.5, 0.0, -8.0)) && solid_at(&h, BORE + Vec3::new(6.5, 0.0, -8.0)), "then 6 mm");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_handle_drags_a_placed_hole_and_snaps() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let start = Vec3::new(30.0, 8.0, 20.0);
|
||||
let at = screen(&mut h, start);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(handle_at("hole:0").is_some(), "the placed hole has a handle");
|
||||
// Dragged to beside the middle: it snaps there.
|
||||
let to = off(&mut h, MIDDLE, 4.0, 3.0);
|
||||
h.step(&json!({"drag": [{"handle": "hole:0"}, to]})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) < 1e-9), "{:?}", places(&h));
|
||||
// Then onto a free spot: it goes where it is let go.
|
||||
let free = Vec3::new(32.0, 24.0, 20.0);
|
||||
let to = screen(&mut h, free);
|
||||
h.step(&json!({"drag": [{"handle": "hole:0"}, to]})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(free) < 0.2), "{:?}", places(&h));
|
||||
// A drag is not a pick: still one hole, and nothing was box-selected.
|
||||
assert_eq!(places(&h).len(), 1);
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
let (_, position) = last_hole(&h);
|
||||
assert!(position.dist(free) < 0.2, "{position:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_pick_on_the_face_moves_the_hole_and_a_pick_on_it_takes_it_out() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let first = Vec3::new(30.0, 8.0, 20.0);
|
||||
let at = screen(&mut h, first);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
let second = Vec3::new(32.0, 24.0, 20.0);
|
||||
let at2 = screen(&mut h, second);
|
||||
h.step(&json!({"click": at2})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(second) < 0.2), "moved, not added: {:?}", places(&h));
|
||||
// On the hole itself (inside its 5 mm): taken out.
|
||||
h.step(&json!({"click": at2})).unwrap();
|
||||
assert!(places(&h).is_empty(), "{:?}", places(&h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editing_a_hole_drags_it_to_a_new_place() {
|
||||
// Moving a hole (#1047): Edit Feature, drag its handle, OK.
|
||||
let mut h = block();
|
||||
let (id, _) = last_hole(&h);
|
||||
h.step(&json!({"call": "ui.editFeature", "params": {"feature": id}})).unwrap();
|
||||
h.frames(4);
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(BORE) < 1e-6), "{:?}", places(&h));
|
||||
let to = off(&mut h, MIDDLE, -3.0, 4.0);
|
||||
h.step(&json!({"drag": [{"handle": "hole:0"}, to]})).unwrap();
|
||||
h.step(&json!({"key": "Enter"})).unwrap();
|
||||
assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|d| &d.error));
|
||||
let (again, position) = last_hole(&h);
|
||||
assert_eq!(again, id, "the same feature");
|
||||
assert!(position.dist(MIDDLE) < 1e-9, "{position:?}");
|
||||
let down = Vec3::new(0.0, 0.0, 10.0);
|
||||
assert!(solid_at(&h, BORE - down), "the old place is solid again");
|
||||
assert!(!solid_at(&h, MIDDLE - down), "the hole is at the middle now");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snaps_and_moves_are_off_by_default_and_picks_behave_as_before() {
|
||||
let mut h = block_as_installed();
|
||||
assert!(!h.app.preferences.hole_snaps && !h.app.preferences.hole_moves, "a new installation places holes as it always did");
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
// Beside the middle: no snap.
|
||||
let at = off(&mut h, MIDDLE, 5.0, -4.0);
|
||||
h.step(&json!({"move": at})).unwrap();
|
||||
match &h.app.viewport.hover {
|
||||
Some(Hit::Face { point, .. }) => assert!(point.dist(MIDDLE) > 0.1, "{point:?}"),
|
||||
other => panic!("the face lights up, not {other:?}"),
|
||||
}
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) > 0.1 && (p.z - 20.0).abs() < 1e-9), "{:?}", places(&h));
|
||||
h.frames(2);
|
||||
assert!(handle_at("hole:0").is_none(), "no drag handle");
|
||||
// A second pick on the face takes the hole out, as it always did.
|
||||
let elsewhere = screen(&mut h, Vec3::new(32.0, 24.0, 20.0));
|
||||
h.step(&json!({"click": elsewhere})).unwrap();
|
||||
assert!(places(&h).is_empty(), "{:?}", places(&h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_holes_is_its_own_setting() {
|
||||
// Moves on, snaps off: the handle drags a hole to where it is let go, and a second pick on
|
||||
// its face moves it; neither snaps.
|
||||
let mut h = block_as_installed();
|
||||
crate::prefs::set(&mut h.app, &json!({"hole_moves": true})).unwrap();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let start = screen(&mut h, Vec3::new(30.0, 8.0, 20.0));
|
||||
h.step(&json!({"click": start})).unwrap();
|
||||
h.frames(2);
|
||||
let to = off(&mut h, MIDDLE, 5.0, -4.0);
|
||||
h.step(&json!({"drag": [{"handle": "hole:0"}, to]})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) > 0.1 && p.dist(MIDDLE) < 2.0), "dragged, not snapped: {:?}", places(&h));
|
||||
let elsewhere = Vec3::new(32.0, 24.0, 20.0);
|
||||
let at = screen(&mut h, elsewhere);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(elsewhere) < 0.2), "moved, not taken out: {:?}", places(&h));
|
||||
// Snaps on, moves off: a pick snaps, and a second pick on the face takes the hole out.
|
||||
h.step(&json!({"key": "Escape"})).unwrap();
|
||||
crate::prefs::set(&mut h.app, &json!({"hole_snaps": true, "hole_moves": false})).unwrap();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
let at = off(&mut h, MIDDLE, 5.0, -4.0);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(matches!(places(&h).as_slice(), [p] if p.dist(MIDDLE) < 1e-9), "{:?}", places(&h));
|
||||
h.frames(2);
|
||||
assert!(handle_at("hole:0").is_none(), "no drag handle");
|
||||
let at = screen(&mut h, elsewhere);
|
||||
h.step(&json!({"click": at})).unwrap();
|
||||
assert!(places(&h).is_empty(), "{:?}", places(&h));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_dialog_shows_the_sizes_beside_a_section_of_the_hole() {
|
||||
let mut h = block();
|
||||
h.step(&json!({"start": "solid.hole"})).unwrap();
|
||||
h.frames(3);
|
||||
let section = rect_of("dialog:figure_picture:hole section").expect("the section is drawn");
|
||||
let at = |name: &str| handle_at(&format!("dialog:{name}")).unwrap_or_else(|| panic!("no field {name}"));
|
||||
// A drilled hole to a depth: depth, diameter and tip angle, top to bottom, right of it.
|
||||
let (depth, dia, tip) = (at("Depth"), at("Diameter"), at("Tip Angle"));
|
||||
assert!(depth.y < dia.y && dia.y < tip.y, "{depth:?} {dia:?} {tip:?}");
|
||||
assert!([depth, dia, tip].iter().all(|p| p.x > section.right() && p.y > section.top() && p.y < section.bottom()));
|
||||
// A counterbore: its diameter and depth come first.
|
||||
if let Some(Kind::Hole { kind, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
|
||||
*kind = 1;
|
||||
}
|
||||
h.frames(3);
|
||||
let (cb, cbd, depth, dia) = (at("Counterbore Ø"), at("Counterbore depth"), at("Depth"), at("Diameter"));
|
||||
assert!(cb.y < cbd.y && cbd.y < depth.y && depth.y < dia.y, "{cb:?} {cbd:?} {depth:?} {dia:?}");
|
||||
assert!(handle_at("dialog:Tip Angle").is_none(), "no tip on a counterbore");
|
||||
// Through all: no depth.
|
||||
if let Some(Kind::Hole { opts, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
|
||||
opts.all = true;
|
||||
}
|
||||
h.frames(3);
|
||||
assert!(handle_at("dialog:Depth").is_none());
|
||||
// The depth field still takes typing (scenarios click it by its name).
|
||||
if let Some(Kind::Hole { opts, kind, .. }) = h.app.dialog.as_mut().map(|d| &mut d.kind) {
|
||||
opts.all = false;
|
||||
*kind = 0;
|
||||
}
|
||||
h.frames(3);
|
||||
h.step(&json!({"click": {"handle": "dialog:Depth"}})).unwrap();
|
||||
h.step(&json!({"key": "A", "cmd": true})).unwrap();
|
||||
h.step(&json!({"text": "7 mm"})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(matches!(&h.app.dialog.as_ref().unwrap().kind, Kind::Hole { depth, .. } if depth == "7 mm"));
|
||||
}
|
||||
@@ -35,6 +35,7 @@ pub mod dialogs_appearance;
|
||||
pub mod dialogs_assembly;
|
||||
pub mod dialogs_coupling;
|
||||
pub mod dialogs_frame;
|
||||
mod dialogs_hole;
|
||||
pub mod dialogs_library;
|
||||
pub mod dialogs_motion;
|
||||
pub mod dialogs_move;
|
||||
@@ -63,6 +64,9 @@ pub mod gpu;
|
||||
pub mod help;
|
||||
#[cfg(test)]
|
||||
mod hole_direction_ui_tests;
|
||||
pub(crate) mod hole_place;
|
||||
#[cfg(test)]
|
||||
mod hole_place_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod hole_placement_ui_tests;
|
||||
pub mod home;
|
||||
|
||||
@@ -581,6 +581,13 @@ preference_settings! {
|
||||
/// Extrude: with a profile picked, a face, vertex or parallel plane picked off its plane
|
||||
/// switches the extent to To Object (off: picks only add profiles, as before).
|
||||
extrude_auto_to_object: bool = false, PAGE_DESIGN => check("Extrude to a picked target", "In Extrude, with a profile picked, picking a face, vertex or parallel plane off its plane switches the extent to To Object");
|
||||
/// Placing a Single hole snaps to the middle of the face and the centres of its round edges
|
||||
/// (`hole_place`). Off by default: a hole goes where it is clicked.
|
||||
hole_snaps: bool = false, PAGE_DESIGN => check("Snap to face and edge centres");
|
||||
/// A placed Single hole has a handle that drags it, and a pick elsewhere on a face that has a
|
||||
/// hole moves the hole there (`hole_place`). Off by default: a second pick on its face takes
|
||||
/// the hole out, and a hole is moved by taking it out and picking again.
|
||||
hole_moves: bool = false, PAGE_DESIGN => check("Move holes by clicking or dragging");
|
||||
/// What a middle-button double-click in the view does: `home`, `fit` or `off`.
|
||||
middle_double_click: String = "home".into(), PAGE_NAVIGATION;
|
||||
/// Colour vision mode (#778): `off`, `protan`, `deutan` or `tritan`.
|
||||
|
||||
@@ -53,4 +53,21 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
ui_kit::text(ui, app.tr("prefs.stand_up_note"), ui_kit::Text::Hint("stand_up"));
|
||||
setting::extrude_auto_to_object(app, ui);
|
||||
});
|
||||
// The Hole command's own settings, under its name.
|
||||
ui_kit::settings_section(ui, "create_hole", crate::i18n::tr_label("Create Hole"), |ui| {
|
||||
setting::hole_snaps(app, ui);
|
||||
ui_kit::text(
|
||||
ui,
|
||||
crate::i18n::tr_label("A Single hole snaps to the middle of its face and to the centres of its round edges"),
|
||||
ui_kit::Text::Hint("hole_snaps"),
|
||||
);
|
||||
setting::hole_moves(app, ui);
|
||||
ui_kit::text(
|
||||
ui,
|
||||
crate::i18n::tr_label(
|
||||
"A placed Single hole has a handle to drag it, and picking its face again moves the hole there instead of taking it out",
|
||||
),
|
||||
ui_kit::Text::Hint("hole_moves"),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1019,6 +1019,18 @@ const ELEMENTS: &[Element] = &[
|
||||
element!("caption", "dialog:caption:Gallery", None, |ui, _| {
|
||||
caption(ui, "Gallery", "Construction");
|
||||
}),
|
||||
element!("figure_rows", "dialog:figure:gallery", Some("dialog:Gallery"), |ui, s| {
|
||||
let Sample { value, second, .. } = s;
|
||||
figure_rows(ui, "gallery", &mut [("Gallery", value), ("Second", second)], |painter, rect, slots| {
|
||||
let t = Tokens::get();
|
||||
painter.rect_stroke(rect.shrink(t.space_4), t.control_radius, egui::Stroke::new(1.0, t.form_dim), egui::StrokeKind::Inside);
|
||||
for slot in slots {
|
||||
let ink = if slot.hot { t.form_primary } else { t.form_dim };
|
||||
let y = slot.rect.center().y;
|
||||
painter.line_segment([egui::pos2(rect.center().x, y), egui::pos2(slot.rect.left(), y)], egui::Stroke::new(1.0, ink));
|
||||
}
|
||||
});
|
||||
}),
|
||||
element!("section", "dialog:section:Advanced", Some("dialog:section:Advanced"), |ui, _| {
|
||||
section(ui, "gallery", "Advanced", false, |_| {});
|
||||
}),
|
||||
|
||||
@@ -142,6 +142,63 @@ pub(crate) fn caption(ui: &mut Ui, aligned_to: &str, text: &str) {
|
||||
scenario::publish_rect(&format!("dialog:caption:{aligned_to}"), text_rect);
|
||||
}
|
||||
|
||||
/// Where a [`figure_rows`] field went (in the order given): the field's rect, and whether it is
|
||||
/// hovered or has the keyboard (its part of the figure lights up).
|
||||
pub(crate) struct FigureSlot {
|
||||
pub rect: egui::Rect,
|
||||
pub hot: bool,
|
||||
}
|
||||
|
||||
/// A figure in the label column beside a stack of expression fields, each under its own caption,
|
||||
/// for a picture whose parts the fields size (the Hole dialog's section): the caller paints the
|
||||
/// figure where the fields went, with leaders to them. At least four rows tall; the fields keep
|
||||
/// their labels' handles and accessible names. Returns whether Enter was accepted in a field.
|
||||
/// Tokens: `control_height, form_label_width, font_small, form_dim, space_2/4, label gap`.
|
||||
pub(crate) fn figure_rows(
|
||||
ui: &mut Ui,
|
||||
id: &str,
|
||||
fields: &mut [(&str, &mut String)],
|
||||
paint: impl FnOnce(&egui::Painter, egui::Rect, &[FigureSlot]),
|
||||
) -> bool {
|
||||
let t = Tokens::get();
|
||||
let width = dimension(ui.available_width());
|
||||
let slot = t.font_small + t.space_2 + row_height();
|
||||
let stack = fields.len() as f32 * slot + fields.len().saturating_sub(1) as f32 * t.space_4;
|
||||
let height = stack.max(row_height() * 4.0);
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(width, height), egui::Sense::hover());
|
||||
let figure = egui::Rect::from_min_size(rect.min, vec2((t.form_label_width * 1.4).min(width * 0.45), height));
|
||||
let left = (figure.right() + label_gap(ui, width)).min(rect.right());
|
||||
let focused = ui.ctx().memory(|m| m.focused()).and_then(|f| ui.ctx().read_response(f)).map(|r| r.rect);
|
||||
let mut enter = false;
|
||||
let mut top = rect.top() + (height - stack) / 2.0;
|
||||
let mut slots = Vec::with_capacity(fields.len());
|
||||
for (label, value) in fields.iter_mut() {
|
||||
let caption = egui::Rect::from_min_max(egui::pos2(left, top), egui::pos2(rect.right(), top + t.font_small));
|
||||
paint_text(ui, caption, crate::i18n::tr_label(label), egui::FontId::proportional(t.font_small), t.form_dim, false);
|
||||
let field = egui::Rect::from_min_max(egui::pos2(left, caption.bottom() + t.space_2), egui::pos2(rect.right(), top + slot));
|
||||
enter |= ui
|
||||
.scope_builder(
|
||||
egui::UiBuilder::new()
|
||||
.id_salt((id, *label))
|
||||
.max_rect(field)
|
||||
.layout(egui::Layout::left_to_right(egui::Align::Center))
|
||||
.ui_stack_info(egui::UiStackInfo::default().with_tag_value(LABEL, label.to_string())),
|
||||
|ui| {
|
||||
ui.spacing_mut().text_edit_width = field.width();
|
||||
super::field(ui, value)
|
||||
},
|
||||
)
|
||||
.inner;
|
||||
let hot = ui.rect_contains_pointer(field) || focused.is_some_and(|f| field.contains_rect(f));
|
||||
slots.push(FigureSlot { rect: field, hot });
|
||||
top += slot + t.space_4;
|
||||
}
|
||||
paint(ui.painter(), figure, &slots);
|
||||
scenario::publish_rect(&format!("dialog:figure:{id}"), rect);
|
||||
scenario::publish_rect(&format!("dialog:figure_picture:{id}"), figure);
|
||||
enter
|
||||
}
|
||||
|
||||
/// Memory belongs to the enclosing dialog ID; animation is avoided so each row keeps its fixed height.
|
||||
/// Persisted disclosure with a rule and uppercase title. Tokens: `control_height, space_2, radius_sm, hover, dialog_rule, form_section_icon_size, form_gap_y, font_caption, font_section_tracking, text_dim`.
|
||||
pub(crate) fn section<R>(ui: &mut Ui, id: impl egui::AsIdSalt, title: &str, default_open: bool, add: impl FnOnce(&mut Ui) -> R) -> Option<R> {
|
||||
|
||||
@@ -1389,6 +1389,8 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit
|
||||
app.session.active_sketch.hash(&mut h);
|
||||
crate::sketch3d::drawing(app).hash(&mut h);
|
||||
app.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).hash(&mut h);
|
||||
crate::hole_place::snapping(app).hash(&mut h);
|
||||
crate::drag_snap::suppressed().hash(&mut h);
|
||||
app.session.visibility.hidden_bodies.hash(&mut h);
|
||||
app.session.visibility.hidden_occurrences.hash(&mut h);
|
||||
origin_point_shown(app).hash(&mut h);
|
||||
@@ -1428,7 +1430,10 @@ pub fn pick_all(app: &SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hit> {
|
||||
}
|
||||
|
||||
fn pick_with_sketch_points(app: &SolveApp, proj: &Proj, pos: Pos2, other_sketch_points: bool) -> Vec<Hit> {
|
||||
pick_hits(app, proj, pos, other_sketch_points, false)
|
||||
let mut hits = pick_hits(app, proj, pos, other_sketch_points, false);
|
||||
// A Single hole's face place snaps to the face's centre and its round edges' centres.
|
||||
crate::hole_place::snap_hits(app, proj, pos, &mut hits);
|
||||
hits
|
||||
}
|
||||
|
||||
/// The same thing picked twice (one row per target in [`pick_all`]).
|
||||
@@ -2039,7 +2044,12 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) {
|
||||
return;
|
||||
}
|
||||
let Some(mut d) = app.dialog.take() else { return };
|
||||
d.pick(&app.session, sel);
|
||||
// With holes moving by clicking (Preferences), a Single hole picked again on its face moves there.
|
||||
if app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel) {
|
||||
d.focus = true;
|
||||
} else {
|
||||
d.pick(&app.session, sel);
|
||||
}
|
||||
if let crate::dialogs::Kind::PathPlane { sketch, .. } = &mut d.kind {
|
||||
*sketch = match hit {
|
||||
Hit::SketchCurve { sketch, .. } => Some(*sketch),
|
||||
|
||||
@@ -103,6 +103,23 @@ offers the face where you clicked. The corners of text outlines don't count, nor
|
||||
points while the sketch hides projected geometry. The hole keeps that place on the face; to have
|
||||
holes follow later edits of the sketch, place them with **Multiple**.
|
||||
|
||||
Two settings under **Create Hole** in **Preferences › Design**, both off by default, change how
|
||||
a Single hole is placed:
|
||||
|
||||
- **Snap to face and edge centres**: the face itself offers snap points too: its middle, and the centre
|
||||
of each round edge on it (a boss standing on it, a rounded corner, a hole already in it). While
|
||||
the cursor is over the face they show as small marks; a pick near one, or on or beside one of
|
||||
those round edges, places the hole at that centre, and the mark it takes is named. Hold **Alt**
|
||||
or **Ctrl** to place the hole exactly where you click.
|
||||
- **Move holes by clicking or dragging**: each placed hole has a handle at its centre. Drag it
|
||||
to move the hole (it snaps when snapping is on), or click it to take the hole out. A pick
|
||||
elsewhere on a face that already has a hole moves the hole there instead of taking it out.
|
||||
**Edit Feature** shows the handle as well, so a hole can be moved later.
|
||||
|
||||
The Hole dialog draws a section through the hole as its options make it (type, extents, drill
|
||||
point, tapped) and puts each size in a field beside the dimension it sets; hovering a field, or
|
||||
typing in it, lights its dimension.
|
||||
|
||||
Fillets and chamfers handle straight edges between planar faces, whole smooth loops, runs of
|
||||
neighbouring edges with mitred or spherical corners, and closed chains of curved edges (a rolling
|
||||
ball). See the roadmap's known limitations for the rest.
|
||||
|
||||
@@ -236,7 +236,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
|
||||
| `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs |
|
||||
| `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) |
|
||||
| `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text |
|
||||
| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` |
|
||||
| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `length_decimals`, `angle_decimals`, `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres), `hole_moves` (default false: a placed Single hole has a drag handle (`hole:<n>`), and a pick on a face that has a hole moves it there), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark` and `stand_up_offer` |
|
||||
| `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits |
|
||||
| `ui.window` | `action`: minimize, maximize, restore, toggle, close | what the title bar's caption buttons do (on Windows and Linux the application bar is the title bar); close asks about unsaved designs first |
|
||||
| `ui.agent_cursor` | `show` (bool), `speed`: a number from 1 to 5 (times the normal speed) or `"instant"` (no animation: the command runs at once and the pointer jumps to where it acted), `follow_camera` (bool); all optional | the settings. While the cursor is shown, `engine.execute` first glides to the command's toolbar button and to each pick, then runs and replies; later requests wait their turn. It also follows the pointer input sent with `ui.move`, `ui.click`, `ui.drag` and `ui.scroll`, as each event reaches the app, and a press leaves a ripple. `"animate": false` on a call skips it |
|
||||
|
||||
@@ -84,6 +84,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
|
||||
| metrics: `row_height`, `table_row_height`, `header_height` | Shared control/header heights | `control_height`, `space_8`, `form_header_height` |
|
||||
| layout: `scope`, `row` | Form styling and aligned label/control columns | `form_label_width`, `form_gap_y`, `control_*`, `font_label`, `dialog_label`, `space_4/8` |
|
||||
| `caption` | Dim caption aligned beneath a control | `font_small`, `text_dim`, label-column tokens |
|
||||
| `figure_rows`, `FigureSlot` | A caller-painted figure in the label column beside a stack of captioned expression fields (the Hole dialog's section); the caller gets each field's rect and hover/focus state to draw leaders and light the part it sizes. Fields keep their `dialog:<label>` handles; the block publishes `dialog:figure:<id>` and its picture `dialog:figure_picture:<id>` | `control_height`, `form_label_width`, `font_small`, `form_dim`, `space_2/4`, label gap |
|
||||
| `section`, `section_count`, `divider` | Persisted small-caps disclosure with chevron, optional count badge and trailing hairline; full-width rule | `control_height`, `dialog_rule`, `font_caption`, tracking, spacing |
|
||||
| `list_row` | Picked item with a remove target | `control_height`, `font_label`, icon/spacing tokens |
|
||||
| `text`, `Text` | Hint, note, report, inline or cell text; see variants below | `font_small/label`, `text/dim/error`, `control_height`, `space_4` |
|
||||
|
||||
Reference in New Issue
Block a user