review(#1627): one UPDATEFIELD, honest counts, safe field boxes, one-pass host redraw

- UPDATEFIELD stays the command main already had (Select objects, undo,
  locale strings); it now takes the PR's reach — a block reference's
  attributes and block definition, a table's cell texts — and reports
  the fields that really changed. The PR's second implementation and its
  duplicate registration are gone.
- FIELDEVAL's range error goes through the locale catalog.
- Field boxes: no slicing inside a character, one layout per multi-line
  attribute, and TEXT boxes scale about the annotative reference point
  like the glyphs do. Comment and indentation put back where they belong.
- bump_text_hosts classifies every host in one pass over the drawing
  instead of scanning all layouts and blocks per host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5.5 committed 2026-10-06 20:42:07 +03:00
1 parent 711799371a
commit af75cf42a8
6 files changed
+180 -169

No files matched your search

+3 -43
View File
@@ -17,48 +17,6 @@ impl OpenCADStudio {
self.open_field_dialog(FieldTarget::NewText);
Some(Task::none())
}
// UPDATEFIELD — re-evaluate the fields of the selected objects
// (a block reference's attributes included), whatever FIELDEVAL.
"UPDATEFIELD" => {
let selected: Vec<codec::Handle> =
self.tabs[i].scene.selected_entities().into_iter().map(|(h, _)| h).collect();
if selected.is_empty() {
use crate::modules::draw::select::SelectObjectsCommand;
let cmd = SelectObjectsCommand::new("UPDATEFIELD");
self.command_line.push_info(&cmd.prompt());
self.tabs[i].active_cmd = Some(Box::new(cmd));
return Some(Task::none());
}
// A block reference brings its attributes and the fields of its
// block definition; a table, the texts of its cells.
let document = &self.tabs[i].scene.document;
let mut hosts = selected.clone();
for handle in &selected {
let record = match document.get_entity(*handle) {
Some(codec::EntityType::Insert(insert)) => {
hosts.extend(insert.attributes.iter().map(|a| a.common.handle));
document.block_records.iter().find(|r| r.name.eq_ignore_ascii_case(&insert.block_name))
}
Some(codec::EntityType::Table(table)) => table
.block_record_handle
.and_then(|h| document.block_records.iter().find(|r| r.handle == h)),
_ => None,
};
if let Some(record) = record {
hosts.extend(record.entity_handles.iter().copied());
}
}
self.push_undo_snapshot(i, "UPDATEFIELD");
let found = self.tabs[i].scene.update_fields(32, Some(&hosts));
self.tabs[i].scene.deselect_all();
self.refresh_properties();
if found > 0 {
self.tabs[i].dirty = true;
}
self.command_line.push_output(crate::tf!("{} field(s) found.", found).as_ref());
self.command_line.push_output(crate::tf!("{} field(s) updated.", found).as_ref());
Some(Task::none())
}
// FIELDEVAL — the events that update fields, kept in the drawing.
cmd if cmd == "FIELDEVAL" || cmd.starts_with("FIELDEVAL ") || cmd.starts_with("SETVAR FIELDEVAL") => {
let value = cmd
@@ -85,7 +43,9 @@ impl OpenCADStudio {
}
}
_ => {
self.command_line.push_error("Requires an integer between 0 and 31.");
let (min, max) = (0, 31);
self.command_line
.push_error(&crate::tf!("Requires an integer between {min} and {max}."));
ask(self);
}
}