1 parent
bd17eeef0c
commit
987f0be21e
27 files changed
+435
-28
No files matched your search
@@ -83,7 +83,7 @@ pub fn dof_text(dof: usize, ok: bool) -> String {
|
||||
}
|
||||
|
||||
/// The line type new curves get in the sketch being edited (0 normal, 1 construction,
|
||||
/// 2 centerline); a new sketch starts normal.
|
||||
/// 2 centerline, 3 infinite); a new sketch starts normal.
|
||||
pub fn mode(app: &SolveApp) -> u8 {
|
||||
let (m, sk) = MODE.with(Cell::get);
|
||||
if sk.is_some() && sk == app.session.active_sketch { m } else { 0 }
|
||||
@@ -95,6 +95,7 @@ pub fn set_mode(app: &mut SolveApp, m: u8) {
|
||||
let hint = match m {
|
||||
1 => "Construction mode: new curves are construction geometry (X or the palette's Normal to leave)",
|
||||
2 => "Centerline mode: new lines are centerlines",
|
||||
3 => "Infinite mode: new lines are infinite construction lines",
|
||||
_ => "Normal mode",
|
||||
};
|
||||
app.set_status(hint, false);
|
||||
@@ -124,7 +125,7 @@ pub fn apply_mode(app: &mut SolveApp, id: &str, result: &Value) {
|
||||
if curves.is_empty() {
|
||||
return;
|
||||
}
|
||||
let lines: Vec<String> = if m == 2 {
|
||||
let lines: Vec<String> = if m == 2 || m == 3 {
|
||||
let st = app.session.model.state();
|
||||
let Some(ss) = app.session.active_sketch.and_then(|s| st.sketch(s)) else { return };
|
||||
curves
|
||||
@@ -144,7 +145,8 @@ pub fn apply_mode(app: &mut SolveApp, id: &str, result: &Value) {
|
||||
// Part of the drawing's own undo step.
|
||||
let depth = app.session.undo.len();
|
||||
if !lines.is_empty() {
|
||||
let _ = app.session.execute("sketch.centerline", &json!({ "curves": lines, "value": true }));
|
||||
let line_type = if m == 3 { "sketch.infinite" } else { "sketch.centerline" };
|
||||
let _ = app.session.execute(line_type, &json!({ "curves": lines, "value": true }));
|
||||
}
|
||||
if !rest.is_empty() {
|
||||
let _ = app.session.execute("sketch.construction", &json!({ "curves": rest, "value": true }));
|
||||
@@ -158,9 +160,10 @@ fn selected_curves(app: &SolveApp) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// The line types among the selected curves of the active sketch, indexed like the palette's
|
||||
/// buttons (0 normal, 1 construction, 2 centerline); a mixed selection marks each of its types.
|
||||
fn selected_linetypes(app: &SolveApp) -> [bool; 3] {
|
||||
let mut types = [false; 3];
|
||||
/// buttons (0 normal, 1 construction, 2 centerline, 3 infinite); a mixed selection marks each of
|
||||
/// its types.
|
||||
fn selected_linetypes(app: &SolveApp) -> [bool; 4] {
|
||||
let mut types = [false; 4];
|
||||
let curves = selected_curves(app);
|
||||
if curves.is_empty() {
|
||||
return types;
|
||||
@@ -168,7 +171,9 @@ fn selected_linetypes(app: &SolveApp) -> [bool; 3] {
|
||||
let st = app.session.world_state();
|
||||
let Some(ss) = app.session.active_sketch.and_then(|s| st.sketch(s)) else { return types };
|
||||
for c in curves.iter().filter_map(|id| ss.sketch.curve_index(id).and_then(|i| ss.sketch.curves.get(i))) {
|
||||
let k = if c.centerline {
|
||||
let k = if c.infinite {
|
||||
3
|
||||
} else if c.centerline {
|
||||
2
|
||||
} else if c.construction {
|
||||
1
|
||||
@@ -182,7 +187,8 @@ fn selected_linetypes(app: &SolveApp) -> [bool; 3] {
|
||||
types
|
||||
}
|
||||
|
||||
/// Set the line type of the selected curves: 0 normal, 1 construction, 2 centerline (lines).
|
||||
/// Set the line type of the selected curves: 0 normal, 1 construction, 2 centerline, 3 infinite
|
||||
/// (the last two for lines).
|
||||
pub fn set_linetype(app: &mut SolveApp, kind: u8) {
|
||||
let curves = selected_curves(app);
|
||||
if curves.is_empty() {
|
||||
@@ -210,7 +216,14 @@ pub fn set_linetype(app: &mut SolveApp, kind: u8) {
|
||||
}
|
||||
app.run("sketch.construction", json!({ "curves": curves, "value": false }))
|
||||
}
|
||||
1 => app.run("sketch.construction", json!({ "curves": curves, "value": true })),
|
||||
1 => {
|
||||
if !lines.is_empty() {
|
||||
let _ = app.run("sketch.infinite", json!({ "curves": lines, "value": false }));
|
||||
}
|
||||
app.run("sketch.construction", json!({ "curves": curves, "value": true }))
|
||||
}
|
||||
3 if lines.is_empty() => Err("an infinite line must be a line".to_string()),
|
||||
3 => app.run("sketch.infinite", json!({ "curves": lines, "value": true })),
|
||||
_ if lines.is_empty() => Err("a centerline must be a line".to_string()),
|
||||
_ => app.run("sketch.centerline", json!({ "curves": lines, "value": true })),
|
||||
};
|
||||
@@ -430,7 +443,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
// Centerline need a round dot and a clear gap to read apart. 30 by
|
||||
// 20 px left too little square room for either.
|
||||
let btn_w = 36.0;
|
||||
let group_w = 3.0 * btn_w + 2.0 * ui.spacing().item_spacing.x;
|
||||
let group_w = 4.0 * btn_w + 3.0 * ui.spacing().item_spacing.x;
|
||||
crate::frame::right_aligned(ui, width, group_w, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
// With a selection: its line type, and a click converts it;
|
||||
@@ -442,10 +455,14 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
// construction orange. Normal's icon never changes with the
|
||||
// accent colour. It stays neutral in every case.
|
||||
let current = mode(app);
|
||||
for (i, (label, icon, tip)) in
|
||||
[("—", "normal", "Normal"), ("- -", "construction", "Construction"), ("-·-", "centerline", "Centerline")]
|
||||
.iter()
|
||||
.enumerate()
|
||||
for (i, (label, icon, tip)) in [
|
||||
("—", "normal", "Normal"),
|
||||
("- -", "construction", "Construction"),
|
||||
("-·-", "centerline", "Centerline"),
|
||||
("↔", "infinite", "Infinite"),
|
||||
]
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let on = if has_curves { selected_types.get(i).copied().unwrap_or(false) } else { current == i as u8 };
|
||||
let tr_tip = app.tr_label(tip);
|
||||
|
||||
Reference in new issue
Block a user