From 0332836238d33adcbf21f3ff50aaeae09b2c389a Mon Sep 17 00:00:00 2001 From: Francesco BV Date: Tue, 27 Oct 2026 22:31:35 +0100 Subject: [PATCH 1/2] INSERT: Verify and Preset attributes, ATTREQ and ATTDIA with the Edit Attributes dialog (F17) A typed or menu INSERT asks a Verify attribute's value twice and gives Preset (and constant) attributes their defaults without asking. ATTREQ 0 gives every attribute its default; ATTDIA 1 (the default) asks for the values in an Edit Attributes dialog, typed answers still working. Both are user settings, as DWG keeps them in its header only before R2000. Answers are counted per prompt, so two definitions with one tag no longer ask the second for ever. The JSON form never asks. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/cmd/blocks.rs | 66 +++-- crates/engine/src/guard.rs | 9 + crates/engine/src/lib.rs | 2 +- crates/engine/src/prompt.rs | 40 +++ crates/engine/src/session/interactive.rs | 6 + crates/engine/src/settings.rs | 8 + crates/engine/src/sysvars/table.rs | 10 +- crates/engine/tests/it/insert_attrib_entry.rs | 227 ++++++++++++++++++ crates/engine/tests/it/main.rs | 1 + crates/ui-egui/src/attentry.rs | 104 ++++++++ crates/ui-egui/src/dialogs.rs | 1 + crates/ui-egui/src/i18n/it.tsv | 4 + crates/ui-egui/src/i18n/uk.tsv | 4 + crates/ui-egui/src/lib.rs | 1 + .../ui-egui/tests/it/insert_attrib_dialog.rs | 132 ++++++++++ crates/ui-egui/tests/it/main.rs | 1 + docs/gaps.md | 5 +- docs/ui-parity.md | 4 +- 18 files changed, 603 insertions(+), 22 deletions(-) create mode 100644 crates/engine/tests/it/insert_attrib_entry.rs create mode 100644 crates/ui-egui/src/attentry.rs create mode 100644 crates/ui-egui/tests/it/insert_attrib_dialog.rs diff --git a/crates/engine/src/cmd/blocks.rs b/crates/engine/src/cmd/blocks.rs index ca4cfffecc..e7d2b5862d 100644 --- a/crates/engine/src/cmd/blocks.rs +++ b/crates/engine/src/cmd/blocks.rs @@ -15,7 +15,7 @@ use super::machines::{SelOutcome, SelectPhase, number}; use super::{CommandSpec, bad, bool_or, f64_or, find_command, ok, point_param, point_req, point_value, str_param, targets}; use super::has_doc; -use crate::{Accept, EngineError, Input, Interactive, Prompt, Result, Session, Step}; +use crate::{Accept, AttribAsk, AttribEntry, EngineError, Input, Interactive, Prompt, Result, Session, Step}; mod attedit; mod burst; @@ -588,7 +588,15 @@ struct InsertM { x_scale: Option, scale: Option, rotation: Option, - attdefs: Vec<(String, String, String)>, + /// The attributes to ask for, in order: not the constant or Preset ones (they take their + /// value without asking), none with ATTREQ 0 (every one takes its default). + attdefs: Vec, + /// How many of `attdefs` have their value. + asked: usize, + /// A Verify attribute's value waiting to be confirmed. + verifying: Option, + /// ATTDIA 1: the values are asked for in the Edit Attributes dialog. + dialog: bool, values: serde_json::Map, /// `*name`: insert the block's objects (one uniform scale factor, no attribute values). explode: bool, @@ -607,7 +615,7 @@ impl InsertM { InsStage::Attribs }; if self.stage == InsStage::Attribs - && self.values.len() >= self.attdefs.len() + && self.asked >= self.attdefs.len() && let (Some(n), Some(a), Some(sc), Some(r)) = (self.name.clone(), self.at, self.scale, self.rotation) { let h = insert_with(s, &n, a, sc, r, self.base, &self.values)?; @@ -625,20 +633,24 @@ impl InsertM { s.echo(format!("Block \"{name}\" not found.")); return Ok(()); }; - self.attdefs = if self.explode { + let ask = s.settings.attreq; + self.dialog = s.settings.attdia; + self.attdefs = if self.explode || !ask { Vec::new() } else { b.entities .iter() - .filter_map(|e| { - if let EntityKind::AttDef(a) = &e.kind { - (!a.constant).then(|| (a.tag.clone(), a.prompt.clone(), a.text.value.clone())) - } else { - None + .filter_map(|e| match &e.kind { + EntityKind::AttDef(a) if !a.constant && !a.modes.preset => { + Some(AttribAsk { tag: a.tag.clone(), prompt: a.prompt.clone(), default: a.text.value.clone(), verify: a.modes.verify }) } + _ => None, }) .collect() }; + self.asked = 0; + self.verifying = None; + self.values.clear(); s.doc_mut()?.header.set_str("INSNAME", &b.name); self.name = Some(b.name.clone()); self.stage = InsStage::Point; @@ -697,8 +709,11 @@ impl Interactive for InsertM { InsStage::YScale => Prompt::new("Enter Y scale factor", Accept::NUMBER).default("use X scale factor"), InsStage::Rotation => Prompt::new("Specify rotation angle", Accept::POINT_OR_NUMBER).default("0").base(at), InsStage::Attribs => { - let (_, prompt, default) = self.attdefs.get(self.values.len()).cloned().unwrap_or_default(); - Prompt::new(if prompt.is_empty() { "Enter attribute value".into() } else { prompt }, Accept::TEXT).default(default) + if let Some(v) = &self.verifying { + return Prompt::new("Verify attribute value", Accept::TEXT).default(v.clone()); + } + let a = self.attdefs.get(self.asked).cloned().unwrap_or_default(); + Prompt::new(if a.prompt.is_empty() { "Enter attribute value".into() } else { a.prompt }, Accept::TEXT).default(a.default) } } } @@ -816,12 +831,24 @@ impl Interactive for InsertM { return self.advance(s); } InsStage::Attribs => { - let (tag, _, default) = self.attdefs.get(self.values.len()).cloned().unwrap_or_default(); - let v = match i { - Input::Text(t) => t, - _ => default, + let a = self.attdefs.get(self.asked).cloned().unwrap_or_default(); + let v = match (i, self.verifying.take()) { + // Verify: Enter keeps the value given, a typed one replaces it. + (Input::Text(t), Some(_)) => t, + (_, Some(v)) => v, + (Input::Text(t), None) if a.verify => { + self.verifying = Some(t); + return Ok(Step::Continue); + } + (_, None) if a.verify => { + self.verifying = Some(a.default); + return Ok(Step::Continue); + } + (Input::Text(t), None) => t, + (_, None) => a.default, }; - self.values.insert(tag, Value::String(v)); + self.values.insert(a.tag, Value::String(v)); + self.asked += 1; return self.advance(s); } } @@ -843,6 +870,13 @@ impl Interactive for InsertM { let rot = self.rotation.unwrap_or(if self.stage == InsStage::Rotation { at.angle_to(c) } else { 0.0 }); vec![EntityKind::Insert(insert_entity(b, at, scale, rot, self.base))] } + fn attribute_entry(&self) -> Option { + // Only before the first answer: values typed at the command line go on there. + if !self.dialog || self.stage != InsStage::Attribs || self.asked > 0 || self.verifying.is_some() || self.attdefs.is_empty() { + return None; + } + Some(AttribEntry { block: self.name.clone().unwrap_or_default(), rows: self.attdefs.clone() }) + } } #[derive(Default)] diff --git a/crates/engine/src/guard.rs b/crates/engine/src/guard.rs index 8a64e2b74c..9e39233765 100644 --- a/crates/engine/src/guard.rs +++ b/crates/engine/src/guard.rs @@ -102,6 +102,15 @@ impl Interactive for Guarded { None }) } + fn attribute_entry(&self) -> Option { + if self.broken.get().is_some() { + return None; + } + catch_unwind(AssertUnwindSafe(|| self.inner.attribute_entry())).unwrap_or_else(|_| { + self.broken.set(Some("panic in prompt")); + None + }) + } } #[cfg(test)] diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index caeda8d7d5..480218474e 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -47,7 +47,7 @@ pub use cadcraft_geom as geom; pub use cadcraft_render as render; pub use cmd::hatch::{HatchPicks, PatternChoice, PickMode, pattern_choices}; pub use cmd::{CommandInfo, CommandSpec, command_specs, find_command}; -pub use prompt::{Accept, Drag, Input, Interactive, Picker, Prompt, Step}; +pub use prompt::{Accept, AttribAsk, AttribEntry, Drag, Input, Interactive, Picker, Prompt, Step}; mod doc_state; mod error; diff --git a/crates/engine/src/prompt.rs b/crates/engine/src/prompt.rs index c02551b80e..3d0ba8063d 100644 --- a/crates/engine/src/prompt.rs +++ b/crates/engine/src/prompt.rs @@ -243,6 +243,46 @@ pub trait Interactive: Send { fn editing_mtext(&self) -> Option { None } + /// The attribute values the command waits for, all at once, when the UI should ask for them + /// in the Edit Attributes dialog (INSERT with ATTDIA 1). Typed answers still work. + fn attribute_entry(&self) -> Option { + None + } +} + +/// See [`Interactive::attribute_entry`]: the block being inserted and the attributes asked for, +/// in order. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct AttribEntry { + pub block: String, + pub rows: Vec, +} + +/// One attribute an INSERT asks for: its tag, prompt and default value; Verify ones are asked +/// twice at the command line. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct AttribAsk { + pub tag: String, + pub prompt: String, + pub default: String, + pub verify: bool, +} + +impl AttribEntry { + /// The answers that give the attributes `values` (one per row, in order; a missing one is + /// the default) when typed in turn: a Verify attribute's value twice, as the dialog has + /// already shown it. + pub fn answers(&self, values: &[String]) -> Vec { + let mut out = Vec::with_capacity(self.rows.len().saturating_mul(2)); + for (i, r) in self.rows.iter().enumerate() { + let v = values.get(i).cloned().unwrap_or_else(|| r.default.clone()); + if r.verify { + out.push(v.clone()); + } + out.push(v); + } + out + } } /// See [`Interactive::drag`]. diff --git a/crates/engine/src/session/interactive.rs b/crates/engine/src/session/interactive.rs index e7cb074504..2cfbee9031 100644 --- a/crates/engine/src/session/interactive.rs +++ b/crates/engine/src/session/interactive.rs @@ -435,6 +435,12 @@ impl Session { self.running.as_ref().and_then(|r| r.machine.editing_mtext()) } + /// The attribute values the running command asks for in the Edit Attributes dialog + /// ([`Interactive::attribute_entry`]). + pub fn attribute_entry(&self) -> Option { + self.running.as_ref().and_then(|r| r.machine.attribute_entry()) + } + pub fn current_prompt(&self) -> Option { if let Some(p) = self.lisp_prompt() { return Some(p); diff --git a/crates/engine/src/settings.rs b/crates/engine/src/settings.rs index 32507162ff..adbc94fb51 100644 --- a/crates/engine/src/settings.rs +++ b/crates/engine/src/settings.rs @@ -127,6 +127,12 @@ pub struct Settings { pub polardist: f64, /// AUDITCTL: 1 creates an audit report (.adt) file when AUDIT is run (default: 0). pub auditctl: bool, + /// ATTREQ: INSERT asks for attribute values (on by default); off gives every attribute its + /// default value. A user setting, as in AutoCAD (not saved in the drawing). + pub attreq: bool, + /// ATTDIA: INSERT typed or from a menu asks for attribute values in the Edit Attributes + /// dialog (on by default, as in AutoCAD); off asks at the command line. + pub attdia: bool, } impl Default for Settings { @@ -191,6 +197,8 @@ impl Default for Settings { polarsnap: false, polardist: 0.0, auditctl: false, + attreq: true, + attdia: true, } } } diff --git a/crates/engine/src/sysvars/table.rs b/crates/engine/src/sysvars/table.rs index fa319d3f1e..72af5b9c09 100644 --- a/crates/engine/src/sysvars/table.rs +++ b/crates/engine/src/sysvars/table.rs @@ -81,8 +81,14 @@ const LINEWEIGHTS: [i64; 24] = [0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, /// On/off session settings: name, read, write. type Toggle = (&'static str, fn(&Settings) -> bool, fn(&mut Settings, bool)); -const SETTINGS: &[Toggle] = - &[("AUDITCTL", |s| s.auditctl, |s, v| s.auditctl = v), ("TRANSPARENCYDISPLAY", |s| s.transparency_display, |s, v| s.transparency_display = v)]; +const SETTINGS: &[Toggle] = &[ + // ATTDIA 1: INSERT typed or from a menu asks for attribute values in the Edit Attributes + // dialog; 0: at the command line. ATTREQ 0: INSERT gives every attribute its default. + ("ATTDIA", |s| s.attdia, |s, v| s.attdia = v), + ("ATTREQ", |s| s.attreq, |s, v| s.attreq = v), + ("AUDITCTL", |s| s.auditctl, |s, v| s.auditctl = v), + ("TRANSPARENCYDISPLAY", |s| s.transparency_display, |s, v| s.transparency_display = v), +]; fn header_var(name: &str) -> Option<&'static (&'static str, Kind, Def)> { HEADER.iter().find(|(n, _, _)| *n == name) diff --git a/crates/engine/tests/it/insert_attrib_entry.rs b/crates/engine/tests/it/insert_attrib_entry.rs new file mode 100644 index 0000000000..78e1253c1a --- /dev/null +++ b/crates/engine/tests/it/insert_attrib_entry.rs @@ -0,0 +1,227 @@ +//! INSERT and the attribute modes (gap F17): Verify attributes are asked twice, Preset ones take +//! their default without asking, ATTREQ 0 gives every attribute its default, and ATTDIA 1 asks +//! for the values all at once in the Edit Attributes dialog (`Session::attribute_entry`), typed +//! answers still working. The JSON form never asks. ATTREQ and ATTDIA are user settings, as in +//! AutoCAD (DWG keeps them in its header only before R2000). + +use std::sync::Arc; + +use cadcraft_engine::doc::{Attrib, AttribModes, Block, Entity, EntityKind, Handle, Text}; +use cadcraft_engine::geom::{Vec2, Vec3}; +use cadcraft_engine::{AttribAsk, Input, Session}; +use serde_json::json; + +fn def(tag: &str, prompt: &str, default: &str, y: f64, constant: bool, modes: AttribModes) -> Attrib { + Attrib { + tag: tag.into(), + text: Text { + insert: Vec3::new(0.0, y, 0.0), + align_pt: None, + height: 1.0, + value: default.into(), + rotation: 0.0, + width_factor: 1.0, + oblique: 0.0, + style: "Standard".into(), + halign: Default::default(), + valign: Default::default(), + }, + invisible: false, + constant, + prompt: prompt.into(), + props: Default::default(), + multiline: None, + modes, + } +} + +/// Block T with the definitions A (Verify), B (Preset), C (plain) and D (constant); ATTREQ and +/// ATTDIA as given (their defaults, 1, otherwise). +fn session(attreq: Option, attdia: Option) -> Session { + let mut d = cadcraft_engine::doc::Drawing::new_imperial(); + let mut b = Block::new("T"); + let none = AttribModes::default(); + for a in [ + def("A", "First", "1", 2.0, false, AttribModes { verify: true, ..none }), + def("B", "Second", "two", 4.0, false, AttribModes { preset: true, ..none }), + def("C", "Third", "3", 6.0, false, none), + def("D", "", "fixed", 8.0, true, none), + ] { + let h = d.new_handle(); + b.entities.push(Entity::new(h, EntityKind::AttDef(a))); + } + d.blocks.insert("T".into(), Arc::new(b)); + let mut s = Session::empty(); + s.open_drawing(d, "attribs", None); + if let Some(v) = attreq { + s.settings.attreq = v; + } + if let Some(v) = attdia { + s.settings.attdia = v; + } + s +} + +/// Start INSERT of T at 100,0 and answer the scale and rotation prompts. +fn insert_up_to_the_attributes(s: &mut Session) { + s.start("insert").unwrap(); + s.cmdline("T").unwrap(); + s.input(Input::Point(Vec2::new(100.0, 0.0))).unwrap(); + s.input(Input::Enter).unwrap(); // X scale 1 + s.input(Input::Enter).unwrap(); // Y scale = X + s.input(Input::Enter).unwrap(); // rotation 0 +} + +/// The attribute values of the last block reference, in order. +fn values(s: &Session) -> Vec<(String, String)> { + let d = s.doc().unwrap(); + let Some(EntityKind::Insert(i)) = d.model.iter().filter(|e| matches!(e.kind, EntityKind::Insert(_))).last().map(|e| e.kind.clone()) else { + panic!("no block reference") + }; + i.attribs.iter().map(|a| (a.tag.clone(), a.text.value.clone())).collect() +} + +fn pairs(v: &[(&str, &str)]) -> Vec<(String, String)> { + v.iter().map(|(t, v)| (t.to_string(), v.to_string())).collect() +} + +#[test] +fn typed_insert_asks_verify_twice_and_skips_preset_and_constant() { + let mut s = session(None, Some(false)); + insert_up_to_the_attributes(&mut s); + assert!(s.attribute_entry().is_none(), "ATTDIA 0: no dialog"); + assert_eq!(s.prompt_text(), "INSERT First <1>:", "A first"); + s.input(Input::Text("10".into())).unwrap(); + assert_eq!(s.prompt_text(), "INSERT Verify attribute value <10>:"); + s.input(Input::Text("11".into())).unwrap(); // the value typed at Verify replaces it + assert_eq!(s.prompt_text(), "INSERT Third <3>:", "B is Preset: not asked"); + s.input(Input::Enter).unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + assert_eq!(values(&s), pairs(&[("A", "11"), ("B", "two"), ("C", "3")])); + + // Enter at Verify keeps the value given; Enter at A takes its default, verified. + insert_up_to_the_attributes(&mut s); + s.input(Input::Enter).unwrap(); + assert_eq!(s.prompt_text(), "INSERT Verify attribute value <1>:"); + s.input(Input::Enter).unwrap(); + s.input(Input::Text("c".into())).unwrap(); + assert_eq!(values(&s), pairs(&[("A", "1"), ("B", "two"), ("C", "c")])); + + // A script answers in turn too. + s.script("-INSERT T 0,50 1 1 0\na\na\nc\n").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + assert_eq!(values(&s), pairs(&[("A", "a"), ("B", "two"), ("C", "c")])); +} + +#[test] +fn attreq_0_gives_every_attribute_its_default() { + let mut s = session(Some(false), None); + insert_up_to_the_attributes(&mut s); + assert!(s.running.is_none(), "no attribute prompt: {}", s.prompt_text()); + assert_eq!(values(&s), pairs(&[("A", "1"), ("B", "two"), ("C", "3")])); + // SETVAR changes it. + s.execute("setvar", &json!({ "name": "ATTREQ", "value": 1 })).unwrap(); + s.execute("setvar", &json!({ "name": "ATTDIA", "value": 0 })).unwrap(); + insert_up_to_the_attributes(&mut s); + assert_eq!(s.prompt_text(), "INSERT First <1>:"); +} + +#[test] +fn attdia_1_asks_for_every_value_at_once_and_typed_answers_still_work() { + // AutoCAD's default, ATTDIA 1, with no value in the drawing. + let mut s = session(None, None); + assert_eq!(s.execute("getvar", &json!({ "name": "ATTDIA" })).unwrap()["value"], 1); + assert_eq!(s.execute("getvar", &json!({ "name": "ATTREQ" })).unwrap()["value"], 1); + s.start("insert").unwrap(); + s.cmdline("T").unwrap(); + assert!(s.attribute_entry().is_none(), "not before the attribute prompts"); + s.input(Input::Point(Vec2::new(100.0, 0.0))).unwrap(); + s.input(Input::Enter).unwrap(); + s.input(Input::Enter).unwrap(); + s.input(Input::Enter).unwrap(); + let e = s.attribute_entry().expect("the dialog's rows"); + assert_eq!(e.block, "T"); + let ask = + |tag: &str, prompt: &str, default: &str, verify: bool| AttribAsk { tag: tag.into(), prompt: prompt.into(), default: default.into(), verify }; + assert_eq!(e.rows, vec![ask("A", "First", "1", true), ask("C", "Third", "3", false)]); + // The dialog's OK: the answers typed in turn, Verify ones twice. + let answers = e.answers(&["x".into(), String::new()]); + assert_eq!(answers, ["x", "x", ""]); + for a in answers { + s.input(Input::Text(a)).unwrap(); + } + assert!(s.running.is_none(), "{}", s.prompt_text()); + assert_eq!(values(&s), pairs(&[("A", "x"), ("B", "two"), ("C", "")])); + + // Typed instead: the dialog goes away after the first answer. + insert_up_to_the_attributes(&mut s); + assert!(s.attribute_entry().is_some()); + s.input(Input::Text("typed".into())).unwrap(); + assert!(s.attribute_entry().is_none()); + s.input(Input::Enter).unwrap(); + s.input(Input::Enter).unwrap(); + assert_eq!(values(&s), pairs(&[("A", "typed"), ("B", "two"), ("C", "3")])); + + // Cancel from the dialog inserts nothing. + let before = s.doc().unwrap().model.len(); + insert_up_to_the_attributes(&mut s); + s.cancel(); + assert!(s.running.is_none()); + assert_eq!(s.doc().unwrap().model.len(), before); +} + +#[test] +fn json_insert_never_asks_whatever_attreq_and_attdia_say() { + for (req, dia) in [(false, false), (true, true)] { + let mut s = session(Some(req), Some(dia)); + let r = s.execute("insert", &json!({ "name": "T", "at": [0, 0], "attribs": { "a": "given", "B": "preset given" } })).unwrap(); + assert!(r["handle"].is_string()); + assert!(s.running.is_none() && s.attribute_entry().is_none()); + assert_eq!(values(&s), pairs(&[("A", "given"), ("B", "preset given"), ("C", "3")])); + } +} + +#[test] +fn hostile_values_never_panic() { + let mut s = session(None, None); + insert_up_to_the_attributes(&mut s); + let e = s.attribute_entry().expect("asks"); + // Too few answers take the defaults, too many are ignored. + assert_eq!(e.answers(&[]), ["1", "1", "3"]); + assert_eq!(e.answers(&["p".into(), "q".into(), "r".into()]), ["p", "p", "q"]); + s.cancel(); + for bad in [json!(2), json!(-1), json!("x"), json!(null), json!(1.5)] { + assert!(s.execute("setvar", &json!({ "name": "ATTDIA", "value": bad })).is_err(), "{bad}"); + assert!(s.execute("setvar", &json!({ "name": "ATTREQ", "value": bad })).is_err(), "{bad}"); + } + assert!(s.settings.attdia && s.settings.attreq, "a refused value changes nothing"); + // An INSERT of a block with only Preset and constant attributes asks nothing. + let mut d = cadcraft_engine::doc::Drawing::new_imperial(); + let mut b = Block::new("P"); + let h: Handle = d.new_handle(); + b.entities.push(Entity::new(h, EntityKind::AttDef(def("P", "p", "v", 0.0, false, AttribModes { preset: true, ..AttribModes::default() })))); + d.blocks.insert("P".into(), Arc::new(b)); + let mut s = Session::empty(); + s.open_drawing(d, "preset", None); + s.script("-INSERT P 0,0 1 1 0\n").unwrap(); + assert!(s.running.is_none() && s.attribute_entry().is_none()); + assert_eq!(values(&s), pairs(&[("P", "v")])); +} + +#[test] +fn two_definitions_with_one_tag_are_both_asked_once() { + // INSERT counted its answers by tag: the second X was asked for ever. + let mut d = cadcraft_engine::doc::Drawing::new_imperial(); + let mut b = Block::new("DUP"); + for (prompt, y) in [("first", 0.0), ("second", 2.0)] { + let h = d.new_handle(); + b.entities.push(Entity::new(h, EntityKind::AttDef(def("X", prompt, "d", y, false, AttribModes::default())))); + } + d.blocks.insert("DUP".into(), Arc::new(b)); + let mut s = Session::empty(); + s.open_drawing(d, "dup", None); + s.settings.attdia = false; + s.script("-INSERT DUP 0,0 1 1 0\na\nb\n").unwrap(); + assert!(s.running.is_none(), "{}", s.prompt_text()); + assert_eq!(values(&s).len(), 2); +} diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index c4c4a1ce6b..bc8546879d 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -54,6 +54,7 @@ mod hatch_options; mod helix; mod inquiry_keywords; mod inquiry_z; +mod insert_attrib_entry; mod insert_prompts; mod isometric; mod join_close; diff --git a/crates/ui-egui/src/attentry.rs b/crates/ui-egui/src/attentry.rs new file mode 100644 index 0000000000..88b6554445 --- /dev/null +++ b/crates/ui-egui/src/attentry.rs @@ -0,0 +1,104 @@ +//! Edit Attributes: INSERT asks for its attribute values in one dialog when ATTDIA is 1 +//! ([`cadcraft_engine::Session::attribute_entry`]). OK answers INSERT's prompts in turn, Cancel +//! cancels the command; values typed at the command line still work, and the dialog goes away +//! after the first one. + +use egui::{RichText, vec2}; + +use crate::CadApp; +use crate::theme::Tokens; + +/// The values being edited, for the block they were made for. +#[derive(Clone, Default)] +struct State { + block: String, + values: Vec, + /// The first field has had the keyboard focus once. + focused: bool, +} + +fn state_id() -> egui::Id { + egui::Id::unique("attentry_state") +} + +enum Done { + No, + Ok, + Cancel, +} + +/// Show the dialog while INSERT waits for attribute values with ATTDIA 1. +pub fn show(app: &mut CadApp, ctx: &egui::Context) { + let Some(entry) = app.session.attribute_entry() else { + ctx.data_mut(|d| d.remove::(state_id())); + return; + }; + let t = Tokens::get(); + let mut st = ctx + .data_mut(|d| d.get_temp::(state_id())) + .filter(|s| s.block == entry.block && s.values.len() == entry.rows.len()) + .unwrap_or_else(|| State { block: entry.block.clone(), values: entry.rows.iter().map(|r| r.default.clone()).collect(), focused: false }); + let mut done = Done::No; + let st_focused = st.focused; + st.focused = true; + egui::Window::new(crate::tl!("Edit Attributes")) + .id(egui::Id::unique("Edit Attributes")) + .collapsible(false) + .resizable(false) + .anchor(egui::Align2::CENTER_CENTER, vec2(0.0, 0.0)) + .show(ctx, |ui| { + ui.horizontal(|ui| { + ui.label(crate::tl!("Block name:")); + ui.label(RichText::new(&entry.block).strong()); + }); + ui.separator(); + egui::ScrollArea::vertical().max_height(260.0).auto_shrink([false, true]).show(ui, |ui| { + egui::Grid::new("attentry_grid").num_columns(2).spacing(vec2(12.0, 6.0)).show(ui, |ui| { + for (i, (row, value)) in entry.rows.iter().zip(st.values.iter_mut()).enumerate() { + let shown = if row.prompt.is_empty() { row.tag.as_str() } else { row.prompt.as_str() }; + let label = ui.label(shown).on_hover_text(crate::tf!("Tag: {tag}", tag = row.tag)); + let field = egui::TextEdit::singleline(value).id(egui::Id::unique(("attentry_value", i))).desired_width(220.0); + let resp = ui.add(field).labelled_by(label.id); + if i == 0 && !st_focused { + resp.request_focus(); + } + // Enter in a field is OK, the dialog's default button. + if resp.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) { + done = Done::Ok; + } + ui.end_row(); + } + }); + }); + ui.separator(); + ui.horizontal(|ui| { + if ui.button(crate::tl!("OK")).clicked() { + done = Done::Ok; + } + if ui.button(crate::tl!("Cancel")).clicked() { + done = Done::Cancel; + } + ui.label(RichText::new(crate::tl!("Values typed at the command line work too")).small().color(t.text_dim)); + }); + }); + if ctx.input(|i| i.key_pressed(egui::Key::Escape)) { + done = Done::Cancel; + } + match done { + Done::No => { + ctx.data_mut(|d| d.insert_temp(state_id(), st)); + } + Done::Ok => { + ctx.data_mut(|d| d.remove::(state_id())); + for a in entry.answers(&st.values) { + if app.session.input(cadcraft_engine::Input::Text(a)).is_err() { + break; + } + } + } + Done::Cancel => { + ctx.data_mut(|d| d.remove::(state_id())); + app.session.cancel(); + } + } +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index acdddb5520..a0efd20fff 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -10,6 +10,7 @@ use crate::theme::Tokens; pub fn show(app: &mut CadApp, ctx: &egui::Context) { crate::mtext_editor::show(app, ctx); + crate::attentry::show(app, ctx); crate::quick::quick_properties(app, ctx); let Some(d) = app.ui.dialog.clone() else { return }; let mut open = true; diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 634249093c..428bbbccd0 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -1367,3 +1367,7 @@ menu Modify Edita Check for Updates… Verifica aggiornamenti… CADCraft is up to date. CADCraft è aggiornato. Could not check for updates. Impossibile verificare gli aggiornamenti. + Edit Attributes Modifica attributi + Block name: Nome blocco: + Tag: {tag} Etichetta: {tag} + Values typed at the command line work too Anche i valori digitati nella riga di comando vengono accettati diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index d71b3ccd7d..f9fb462170 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -1373,3 +1373,7 @@ Check for Updates… Перевірити оновлення… CADCraft is up to date. Встановлено найновішу версію CADCraft. Could not check for updates. Не вдалося перевірити оновлення. + Edit Attributes Редагування атрибутів + Block name: Ім’я блока: + Tag: {tag} Мітка: {tag} + Values typed at the command line work too Значення, введені в командному рядку, теж приймаються diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 017cf5a42a..773c1a6cdc 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -10,6 +10,7 @@ pub mod aliasdlg; pub mod animation; +pub mod attentry; pub mod autosave; pub mod bedit; pub mod canvas; diff --git a/crates/ui-egui/tests/it/insert_attrib_dialog.rs b/crates/ui-egui/tests/it/insert_attrib_dialog.rs new file mode 100644 index 0000000000..1e0783e66a --- /dev/null +++ b/crates/ui-egui/tests/it/insert_attrib_dialog.rs @@ -0,0 +1,132 @@ +//! Edit Attributes (ATTDIA 1): a typed INSERT asks for its attribute values in one dialog. OK +//! gives them to INSERT (a Verify one is not asked again), Enter in a field is OK, Cancel inserts +//! nothing, and with ATTDIA 0 or a JSON call there is no dialog. + +use cadcraft_engine::Input; +use cadcraft_engine::Session; +use cadcraft_engine::doc::EntityKind; +use cadcraft_engine::geom::Vec2; +use cadcraft_ui_egui::{CadApp, Services, dialogs}; +use egui::accesskit::Role; +use egui::{Key, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{Queryable, by}; +use serde_json::json; + +/// Block T with the definitions A ("Room", default "101") and B ("Floor", default "1"). +fn app() -> CadApp { + let mut app = CadApp::new(Session::new(), Services::default()); + let a = app.run("attdef", json!({ "tag": "A", "prompt": "Room", "default": "101", "at": [0, 2] })).unwrap(); + let b = app.run("attdef", json!({ "tag": "B", "prompt": "Floor", "default": "1", "at": [0, 4] })).unwrap(); + app.run("block", json!({ "name": "T", "base": [0, 0], "handles": [a["handle"], b["handle"]], "keep": "delete" })).unwrap(); + app +} + +/// INSERT of T typed, answered up to its attribute values. +fn insert(app: &mut CadApp) { + app.start("insert"); + app.cmdline("T"); + for i in [Input::Point(Vec2::new(50.0, 0.0)), Input::Enter, Input::Enter, Input::Enter] { + app.session.input(i).unwrap(); + } +} + +fn harness(app: CadApp) -> Harness<'static, CadApp> { + let mut h = Harness::builder().with_size(vec2(900.0, 700.0)).build_ui_state(|ui, app: &mut CadApp| dialogs::show(app, ui.ctx()), app); + h.run_steps(3); + h +} + +fn values(app: &CadApp) -> Option> { + let d = app.session.doc().unwrap(); + d.model.iter().find_map(|e| match &e.kind { + EntityKind::Insert(i) => Some(i.attribs.iter().map(|a| (a.tag.clone(), a.text.value.clone())).collect()), + _ => None, + }) +} + +fn field<'h>(h: &'h Harness<'static, CadApp>, shown: &'h str) -> egui_kittest::Node<'h> { + h.get(by().role(Role::TextInput).value(shown)) +} + +fn replace(h: &mut Harness<'static, CadApp>, shown: &str, with: &str) { + field(h, shown).focus(); + h.run_steps(2); + h.key_press_modifiers(egui::Modifiers::COMMAND, Key::A); + h.run_steps(1); + field(h, shown).type_text(with); + h.run_steps(2); +} + +#[test] +fn ok_gives_the_values_to_insert() { + let mut a = app(); + insert(&mut a); + let mut h = harness(a); + h.get_by_label("Edit Attributes"); + // The fields are named by their prompts. + assert_eq!(h.get_by_label("Room").value().as_deref(), Some("101")); + replace(&mut h, "1", "3"); + replace(&mut h, "101", "205"); + h.get_by_label("OK").click(); + h.run_steps(3); + let app = h.state(); + assert!(app.session.running.is_none(), "{}", app.session.prompt_text()); + assert_eq!(values(app), Some(vec![("A".into(), "205".into()), ("B".into(), "3".into())])); + assert!(h.query_by_label("Edit Attributes").is_none(), "closed"); +} + +#[test] +fn enter_in_a_field_is_ok_and_verify_is_not_asked_again() { + let mut a = app(); + a.run("battman", json!({ "name": "T", "action": "edit", "tag": "A", "default": "7" })).unwrap(); + // Make A a Verify attribute in the block definition. + let d = a.session.doc_mut().unwrap(); + let mut b = (**d.block("T").unwrap()).clone(); + for e in b.entities.iter().map(|e| e.handle).collect::>() { + b.entities.modify(e, |e| { + if let EntityKind::AttDef(ad) = &mut e.kind + && ad.tag == "A" + { + ad.modes.verify = true; + } + }); + } + d.blocks.insert("T".into(), std::sync::Arc::new(b)); + insert(&mut a); + let mut h = harness(a); + replace(&mut h, "7", "8"); + h.key_press(Key::Enter); + h.run_steps(3); + let app = h.state(); + assert!(app.session.running.is_none(), "{}", app.session.prompt_text()); + assert_eq!(values(app), Some(vec![("A".into(), "8".into()), ("B".into(), "1".into())])); +} + +#[test] +fn cancel_inserts_nothing() { + let mut a = app(); + insert(&mut a); + let mut h = harness(a); + h.get_by_label("Cancel").click(); + h.run_steps(3); + let app = h.state(); + assert!(app.session.running.is_none()); + assert_eq!(values(app), None); +} + +#[test] +fn no_dialog_with_attdia_0_or_from_json() { + let mut a = app(); + a.session.settings.attdia = false; + insert(&mut a); + let h = harness(a); + assert!(h.query_by_label("Edit Attributes").is_none()); + assert!(h.state().session.prompt_text().contains("Room"), "asked at the command line"); + + let mut a = app(); + a.run("insert", json!({ "name": "T", "at": [0, 0], "attribs": { "A": "x" } })).unwrap(); + let h = harness(a); + assert!(h.query_by_label("Edit Attributes").is_none()); + assert_eq!(values(h.state()), Some(vec![("A".into(), "x".into()), ("B".into(), "1".into())])); +} diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index c32012e1ab..2af1720434 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -13,6 +13,7 @@ mod drafting_spacing; mod file_tab_titles; mod gpu_viewport_stencil; mod hidden_command_line; +mod insert_attrib_dialog; mod instant_modals; mod lisp_files; mod measure_distance_snapping; diff --git a/docs/gaps.md b/docs/gaps.md index 9c0bf3630f..6e76a2bca6 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where CADCraft falls short of AutoCAD -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (Named Viewports dialog: U11 narrowed; MVIEW Restore and PURGE of multiline styles had landed: F15 and F21 corrected) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (INSERT follows the attribute modes, ATTREQ and ATTDIA: F17 narrowed) · **Target:** Autodesk AutoCAD 2027 Every known shortfall, one row each, ranked within each section by user impact. This is the work list: agents pick from here (top of a section first), and remove or update a row in the same PR @@ -39,7 +39,7 @@ do them first. | F13 | Hatch: 23 patterns (AutoCAD ~85; ours must stay original); the Hatch and Gradient and Hatch Edit dialogs have no Preview or Inherit Properties (HPDLGMODE 0 keeps HATCH on the command line); no MPolygon; HATCHEDIT and -HATCHEDIT add boundaries from picked points or closed objects and remove chosen loops, but a hatch copied with its boundary isn't linked to the copy; HPGAPTOL closes gaps between curve ends only | `doc/src/library.rs`, `cmd/hatch.rs`, `cmd/hatch/edit.rs` | Medium | 6–10 | | F15 | Viewports: a clipped viewport and its clip boundary move and scale separately. Polygonal, object and clipped viewports, VPCLIP, MVIEW ON/OFF/Lock/2/3/4 and the status-bar scale list landed (#453), MVIEW Restore in #633 | `cmd/layout/viewports.rs` | Low | 2–4 | | F16 | Groups: no group bounding box or single grip when a group is selected (GROUPDISPLAYMODE), copying a whole group does not make a new group, no Object Grouping dialog (GROUP, GROUPEDIT, UNGROUP, -GROUP, PICKSTYLE group selection and the DXF/DWG round trip landed, #417); PICKSTYLE's associative-hatch bit is stored but unused | `cmd/groups.rs` | Low | 2–4 | -| F17 | Attributes (ATTSYNC, global -ATTEDIT, BATTMAN editing and DATAEXTRACTION/EATTEXT landed, #433): no verify, preset or lock-position modes, and multiline attributes (read, drawn and saved since 2026-10-12) can't be created or switched in BATTMAN; data extraction covers block references and attribute values (CSV or a table) only — no wizard, nested blocks, other objects' properties, `.dxe` templates or spreadsheet output | `cmd/blocks/battman.rs`, `cmd/blocks/extract.rs` | Low | 4–6 | +| F17 | Attributes (ATTSYNC, global -ATTEDIT, BATTMAN editing and DATAEXTRACTION/EATTEXT landed, #433; INSERT asks Verify attributes twice, skips Preset ones and follows ATTREQ and ATTDIA, with the Edit Attributes dialog): ATTDEF can't set the Verify, Preset or Lock position modes, locked attributes still have grips, and multiline attributes (read, drawn and saved since 2026-10-12) can't be created or switched in BATTMAN; data extraction covers block references and attribute values (CSV or a table) only — no wizard, nested blocks, other objects' properties, `.dxe` templates or spreadsheet output | `cmd/blocks/battman.rs`, `cmd/blocks/extract.rs` | Low | 4–6 | | F19 | MATCHPROP Settings is a keyword prompt (no dialog) and has no material, shadow or centre-object settings; TEXTTOFRONT and HATCHTOBACK act on the current space only; OVERKILL doesn't compare polyline segments with other objects (picker and Settings, DRAWORDER Above/Under, TEXTTOFRONT, HATCHTOBACK, OVERKILL tolerance/ignore/overlap/end-to-end options landed, #439) | `props/matchprop.rs`, `draworder.rs`, `overkill.rs` | Low | 2–4 | | F20 | OPTIONS dialog done (#23): Display, Open and Save, Drafting, Selection, User Preferences and Profiles tabs, and the user profile (object snap modes, drafting toggles, Dynamic Input, PICKBOX, APERTURE, GRIPSIZE, CURSORSIZE, PICKFIRST, PICKADD, QPMODE, model and paper background, snap marker size, system cursor) survives restarts. Left: right-click customization, the autosave interval and default save version on Open and Save (the features themselves landed, #406, #421), AutoSnap magnet and tooltip toggles, colours of the other drawing-area elements, named profiles with import and export | `ui-egui/src/options/` | Low | 2–4 | | F21 | MLINE, REGION and HELIX are objects since #510, with gaps: MLEDIT tees trim square; UNION/SUBTRACT/INTERSECT only combine regions whose boundaries don't meet; regions are saved as closed polylines (no ACIS data) | `draw2/mline.rs`, `inquiry/regions.rs`, `dxf_region.rs` | Low | 6–10 | @@ -150,6 +150,7 @@ Detail: [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | INSERT asks a Verify attribute's value twice and gives a Preset one its default without asking; ATTREQ 0 gives every attribute its default; ATTDIA 1 (the default) asks for the values in the Edit Attributes dialog when INSERT is typed or picked, typed answers still working; both are user settings (SETVAR), not saved in the drawing, as DWG from R2000 has no place for them: F17 narrowed | | 2026-10-25 | minor | Named Viewports (View ▸ Viewports ▸ Named Viewports..., `vports.named`) lists the saved viewport configurations with a preview and the current one's name, and restores or deletes one; in a layout Restore places it as MVIEW Restore does: U11 narrowed. F15 and U11 no longer list MVIEW Restore (#633), and F21 no longer says PURGE skips multiline styles | | 2026-10-25 | minor | DIMTFILL limits: with DIMTFILL 1 (the drawing's background color) the written `*D` block and EXPLODE keep no background mask (a WIPEOUT over the text box would), and a true-color DIMTFILLCLR is written to DXF as the nearest ACI: F7 updated | | 2026-10-24 | minor | COMPAREEXPORT (typed, or Export on the comparison bar) opens the comparison as a new untitled drawing, `compare_ vs .dwg`: this drawing's objects in one group and the other drawing's differing objects in a second group, in the comparison colors (green, red, gray for objects in both), block contents and style colors included: F22 narrowed | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c06e8f242b..c91d85f7e8 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (distinct polyline midpoint grips) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-27 · **Change:** minor (attribute values when inserting: ATTREQ, ATTDIA and the Edit Attributes dialog) · **Target:** Autodesk AutoCAD 2027 for Mac (26.0) How CADCraft's interaction compares with AutoCAD's: point entry, object snaps, tracking, dynamic input, grips, selection, the command line, chrome and navigation. A drafter's speed in AutoCAD @@ -149,6 +149,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Clickable keywords in the prompt | yes | yes (`cmdline.rs:253-267`) | | UNDO with Mark, Back, BEgin, End, Auto, Control | yes | count only, whole-document snapshots capped at 2,000 (`lib.rs:477`, `edit.rs:56`) | | SETVAR for every system variable | ~1,000 sysvars | about 60 session/header variables by name (`sysvars.rs`) | +| Attribute values when inserting (ATTREQ, ATTDIA, Verify, Preset) | prompts or the Edit Attributes dialog | both: ATTDIA 1 opens Edit Attributes (OK, Enter, Cancel; typed answers still work), ATTDIA 0 asks at the command line, Verify attributes asked twice there, Preset ones and ATTREQ 0 take their defaults (`attentry.rs`); no Previous/Next pages (one scrolling list) | | Scripts (SCRIPT, `.scr`) | yes | script text via CLI/MCP/control; no `.scr` file command | | Floating/docked command window, transparency, lines of history | yes | floating overlay, history lines setting | @@ -203,6 +204,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Date | Change | Summary | |---|---|---| +| 2026-10-27 | minor | INSERT asks for attribute values as AutoCAD does: the Edit Attributes dialog with ATTDIA 1, the command line with 0 (Verify asked twice), none with ATTREQ 0 or for Preset attributes | | 2026-10-22 | minor | Polyline segment midpoint grips use rectangles, distinct from square vertex grips, with matching hover and pick bounds (#1950) | | 2026-10-13 | minor | Filled-region highlight boundaries are traversed in deterministic coordinate order, fixing dash-phase jumps on CPU hover/selection redraws and GPU highlight rebuilds; CPU dash-position, pixel and GPU mesh regressions | | 2026-10-14 | minor | Selection cycling (#1143): the list and badge of SELECTIONCYCLING, Shift+Space through overlapping objects (#1145) | From d3ec8efe19a345e0077ff8c58ed6789bb11e44f9 Mon Sep 17 00:00:00 2001 From: Francesco BV Date: Thu, 29 Oct 2026 10:37:59 +0100 Subject: [PATCH 2/2] INSERT: ATTDIA defaults to 0, the command line, as in AutoCAD AutoCAD's published system variable reference gives ATTDIA an initial value of 0: a typed INSERT asks for attribute values at the command line, which also keeps scripts and agents typing through the command line as before. ATTDIA 1 still opens the Edit Attributes dialog. The dialog tests set ATTDIA 1 themselves; a new check shows the default opens no dialog. Co-Authored-By: Claude Opus 5.5 (1M context) --- crates/engine/src/settings.rs | 4 ++-- crates/engine/src/sysvars/table.rs | 2 +- crates/engine/tests/it/insert_attrib_entry.rs | 18 ++++++++++-------- .../ui-egui/tests/it/insert_attrib_dialog.rs | 15 +++++++++++++-- docs/gaps.md | 2 +- docs/ui-parity.md | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/crates/engine/src/settings.rs b/crates/engine/src/settings.rs index adbc94fb51..54c44258a3 100644 --- a/crates/engine/src/settings.rs +++ b/crates/engine/src/settings.rs @@ -131,7 +131,7 @@ pub struct Settings { /// default value. A user setting, as in AutoCAD (not saved in the drawing). pub attreq: bool, /// ATTDIA: INSERT typed or from a menu asks for attribute values in the Edit Attributes - /// dialog (on by default, as in AutoCAD); off asks at the command line. + /// dialog; off (the default, as in AutoCAD) asks at the command line. pub attdia: bool, } @@ -198,7 +198,7 @@ impl Default for Settings { polardist: 0.0, auditctl: false, attreq: true, - attdia: true, + attdia: false, } } } diff --git a/crates/engine/src/sysvars/table.rs b/crates/engine/src/sysvars/table.rs index 72af5b9c09..43cf142777 100644 --- a/crates/engine/src/sysvars/table.rs +++ b/crates/engine/src/sysvars/table.rs @@ -83,7 +83,7 @@ const LINEWEIGHTS: [i64; 24] = [0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, type Toggle = (&'static str, fn(&Settings) -> bool, fn(&mut Settings, bool)); const SETTINGS: &[Toggle] = &[ // ATTDIA 1: INSERT typed or from a menu asks for attribute values in the Edit Attributes - // dialog; 0: at the command line. ATTREQ 0: INSERT gives every attribute its default. + // dialog; 0 (the default): at the command line. ATTREQ 0: INSERT gives every attribute its default. ("ATTDIA", |s| s.attdia, |s, v| s.attdia = v), ("ATTREQ", |s| s.attreq, |s, v| s.attreq = v), ("AUDITCTL", |s| s.auditctl, |s, v| s.auditctl = v), diff --git a/crates/engine/tests/it/insert_attrib_entry.rs b/crates/engine/tests/it/insert_attrib_entry.rs index 78e1253c1a..79d37e8596 100644 --- a/crates/engine/tests/it/insert_attrib_entry.rs +++ b/crates/engine/tests/it/insert_attrib_entry.rs @@ -1,7 +1,7 @@ //! INSERT and the attribute modes (gap F17): Verify attributes are asked twice, Preset ones take -//! their default without asking, ATTREQ 0 gives every attribute its default, and ATTDIA 1 asks -//! for the values all at once in the Edit Attributes dialog (`Session::attribute_entry`), typed -//! answers still working. The JSON form never asks. ATTREQ and ATTDIA are user settings, as in +//! their default without asking, ATTREQ 0 gives every attribute its default, ATTDIA 0 (the +//! default) asks at the command line and ATTDIA 1 asks for the values all at once in the Edit +//! Attributes dialog (`Session::attribute_entry`), typed answers still working. The JSON form never asks. ATTREQ and ATTDIA are user settings, as in //! AutoCAD (DWG keeps them in its header only before R2000). use std::sync::Arc; @@ -36,7 +36,7 @@ fn def(tag: &str, prompt: &str, default: &str, y: f64, constant: bool, modes: At } /// Block T with the definitions A (Verify), B (Preset), C (plain) and D (constant); ATTREQ and -/// ATTDIA as given (their defaults, 1, otherwise). +/// ATTDIA as given (their defaults, ATTREQ 1 and ATTDIA 0, otherwise). fn session(attreq: Option, attdia: Option) -> Session { let mut d = cadcraft_engine::doc::Drawing::new_imperial(); let mut b = Block::new("T"); @@ -87,7 +87,10 @@ fn pairs(v: &[(&str, &str)]) -> Vec<(String, String)> { #[test] fn typed_insert_asks_verify_twice_and_skips_preset_and_constant() { - let mut s = session(None, Some(false)); + // AutoCAD's default, ATTDIA 0, with no value in the drawing: the command line asks. + let mut s = session(None, None); + assert_eq!(s.execute("getvar", &json!({ "name": "ATTDIA" })).unwrap()["value"], 0); + assert_eq!(s.execute("getvar", &json!({ "name": "ATTREQ" })).unwrap()["value"], 1); insert_up_to_the_attributes(&mut s); assert!(s.attribute_entry().is_none(), "ATTDIA 0: no dialog"); assert_eq!(s.prompt_text(), "INSERT First <1>:", "A first"); @@ -128,10 +131,9 @@ fn attreq_0_gives_every_attribute_its_default() { #[test] fn attdia_1_asks_for_every_value_at_once_and_typed_answers_still_work() { - // AutoCAD's default, ATTDIA 1, with no value in the drawing. let mut s = session(None, None); + s.execute("setvar", &json!({ "name": "ATTDIA", "value": 1 })).unwrap(); assert_eq!(s.execute("getvar", &json!({ "name": "ATTDIA" })).unwrap()["value"], 1); - assert_eq!(s.execute("getvar", &json!({ "name": "ATTREQ" })).unwrap()["value"], 1); s.start("insert").unwrap(); s.cmdline("T").unwrap(); assert!(s.attribute_entry().is_none(), "not before the attribute prompts"); @@ -183,7 +185,7 @@ fn json_insert_never_asks_whatever_attreq_and_attdia_say() { #[test] fn hostile_values_never_panic() { - let mut s = session(None, None); + let mut s = session(None, Some(true)); insert_up_to_the_attributes(&mut s); let e = s.attribute_entry().expect("asks"); // Too few answers take the defaults, too many are ignored. diff --git a/crates/ui-egui/tests/it/insert_attrib_dialog.rs b/crates/ui-egui/tests/it/insert_attrib_dialog.rs index 1e0783e66a..f194fe969b 100644 --- a/crates/ui-egui/tests/it/insert_attrib_dialog.rs +++ b/crates/ui-egui/tests/it/insert_attrib_dialog.rs @@ -13,9 +13,11 @@ use egui_kittest::Harness; use egui_kittest::kittest::{Queryable, by}; use serde_json::json; -/// Block T with the definitions A ("Room", default "101") and B ("Floor", default "1"). +/// Block T with the definitions A ("Room", default "101") and B ("Floor", default "1"), and +/// ATTDIA 1 (the default is 0, the command line). fn app() -> CadApp { let mut app = CadApp::new(Session::new(), Services::default()); + app.run("setvar", json!({ "name": "ATTDIA", "value": 1 })).unwrap(); let a = app.run("attdef", json!({ "tag": "A", "prompt": "Room", "default": "101", "at": [0, 2] })).unwrap(); let b = app.run("attdef", json!({ "tag": "B", "prompt": "Floor", "default": "1", "at": [0, 4] })).unwrap(); app.run("block", json!({ "name": "T", "base": [0, 0], "handles": [a["handle"], b["handle"]], "keep": "delete" })).unwrap(); @@ -118,7 +120,16 @@ fn cancel_inserts_nothing() { #[test] fn no_dialog_with_attdia_0_or_from_json() { let mut a = app(); - a.session.settings.attdia = false; + a.run("setvar", json!({ "name": "ATTDIA", "value": 0 })).unwrap(); + insert(&mut a); + let h = harness(a); + assert!(h.query_by_label("Edit Attributes").is_none()); + assert!(h.state().session.prompt_text().contains("Room"), "asked at the command line"); + + // ATTDIA's default, 0, asks at the command line too. + let mut a = app(); + a.session.settings = Default::default(); + assert!(!a.session.settings.attdia); insert(&mut a); let h = harness(a); assert!(h.query_by_label("Edit Attributes").is_none()); diff --git a/docs/gaps.md b/docs/gaps.md index 6e76a2bca6..e5f820618d 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -150,7 +150,7 @@ Detail: [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| -| 2026-10-27 | minor | INSERT asks a Verify attribute's value twice and gives a Preset one its default without asking; ATTREQ 0 gives every attribute its default; ATTDIA 1 (the default) asks for the values in the Edit Attributes dialog when INSERT is typed or picked, typed answers still working; both are user settings (SETVAR), not saved in the drawing, as DWG from R2000 has no place for them: F17 narrowed | +| 2026-10-27 | minor | INSERT asks a Verify attribute's value twice and gives a Preset one its default without asking; ATTREQ 0 gives every attribute its default; ATTDIA 1 asks for the values in the Edit Attributes dialog when INSERT is typed or picked, typed answers still working, and 0 (the default) at the command line; both are user settings (SETVAR), not saved in the drawing, as DWG from R2000 has no place for them: F17 narrowed | | 2026-10-25 | minor | Named Viewports (View ▸ Viewports ▸ Named Viewports..., `vports.named`) lists the saved viewport configurations with a preview and the current one's name, and restores or deletes one; in a layout Restore places it as MVIEW Restore does: U11 narrowed. F15 and U11 no longer list MVIEW Restore (#633), and F21 no longer says PURGE skips multiline styles | | 2026-10-25 | minor | DIMTFILL limits: with DIMTFILL 1 (the drawing's background color) the written `*D` block and EXPLODE keep no background mask (a WIPEOUT over the text box would), and a true-color DIMTFILLCLR is written to DXF as the nearest ACI: F7 updated | | 2026-10-24 | minor | COMPAREEXPORT (typed, or Export on the comparison bar) opens the comparison as a new untitled drawing, `compare_ vs .dwg`: this drawing's objects in one group and the other drawing's differing objects in a second group, in the comparison colors (green, red, gray for objects in both), block contents and style colors included: F22 narrowed | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index c91d85f7e8..7c25a473d6 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -149,7 +149,7 @@ down-arrow options menu (DYNPROMPT), and DYNDIM. | Clickable keywords in the prompt | yes | yes (`cmdline.rs:253-267`) | | UNDO with Mark, Back, BEgin, End, Auto, Control | yes | count only, whole-document snapshots capped at 2,000 (`lib.rs:477`, `edit.rs:56`) | | SETVAR for every system variable | ~1,000 sysvars | about 60 session/header variables by name (`sysvars.rs`) | -| Attribute values when inserting (ATTREQ, ATTDIA, Verify, Preset) | prompts or the Edit Attributes dialog | both: ATTDIA 1 opens Edit Attributes (OK, Enter, Cancel; typed answers still work), ATTDIA 0 asks at the command line, Verify attributes asked twice there, Preset ones and ATTREQ 0 take their defaults (`attentry.rs`); no Previous/Next pages (one scrolling list) | +| Attribute values when inserting (ATTREQ, ATTDIA, Verify, Preset) | prompts or the Edit Attributes dialog | both: ATTDIA 1 opens Edit Attributes (OK, Enter, Cancel; typed answers still work), ATTDIA 0 (the default) asks at the command line, Verify attributes asked twice there, Preset ones and ATTREQ 0 take their defaults (`attentry.rs`); no Previous/Next pages (one scrolling list) | | Scripts (SCRIPT, `.scr`) | yes | script text via CLI/MCP/control; no `.scr` file command | | Floating/docked command window, transparency, lines of history | yes | floating overlay, history lines setting |