forked from 1b-agent/opencadstudio-upstream
Fields: stored values on redraw, evaluation events, per-field shading
MTEXT draws its stored text instead of re-evaluating fields on every redraw. Fields update on their evaluation events as the reference does: open (1), save (2, not autosave), plot (4) and REGEN/REGENALL (16), each masked with the drawing's FIELDEVAL (variable dictionary, 0-31, with the reference's prompt and message), and the new UPDATEFIELD command (selection, attributes of selected block references, "N field(s) found." / "N field(s) updated."). A Date field (on demand only) keeps its value until UPDATEFIELD. The FIELDDISPLAY gray box now covers each field's own glyphs, one box per line it spans, instead of the whole text. Codec moved to the update_fields / field_spans revision. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71cebbb3fe
commit
1c242eb489
13 files changed
+229
-19
No files matched your search
+25
-5
@@ -84,10 +84,30 @@ impl FieldContext for OcsFieldContext<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Re-evaluate the field hosted by entity `host` (usually an MTEXT), or `None`
|
||||
/// to keep the cached text. Thin wrapper over the library engine.
|
||||
pub fn resolve(document: &CadDocument, host: Handle) -> Option<String> {
|
||||
codec::fields::resolve(document, host, &OcsFieldContext(Some(document)))
|
||||
/// FIELDEVAL of the drawing (kept in its variable dictionary; default 31):
|
||||
/// the events that update fields — 1 open, 2 save, 4 plot, 8 eTransmit,
|
||||
/// 16 regen.
|
||||
pub fn fieldeval(document: &CadDocument) -> i32 {
|
||||
crate::io::drawing_variable(document, "FIELDEVAL")
|
||||
.and_then(|v| v.trim().parse().ok())
|
||||
.unwrap_or(31)
|
||||
}
|
||||
|
||||
/// Update the fields an event evaluates and store their values in the host
|
||||
/// texts: `event` 1 open, 2 save or 16 regen (masked with FIELDEVAL), or 32
|
||||
/// an explicit UPDATEFIELD. `hosts` limits it to those hosts. Returns the
|
||||
/// hosts whose text changed and the number of fields the hosts hold.
|
||||
pub fn update_fields(
|
||||
document: &mut CadDocument,
|
||||
event: i32,
|
||||
hosts: Option<&[Handle]>,
|
||||
) -> (Vec<Handle>, usize) {
|
||||
let event = if event == 32 { event } else { event & fieldeval(document) };
|
||||
if event == 0 || document.fields.is_empty() {
|
||||
return (Vec::new(), 0);
|
||||
}
|
||||
let snapshot = document.clone();
|
||||
document.update_fields(&OcsFieldContext(Some(&snapshot)), event, hosts)
|
||||
}
|
||||
|
||||
pub fn resolve_handle(
|
||||
@@ -388,7 +408,7 @@ pub fn stamp_plot_fields(document: &mut CadDocument) -> Vec<Handle> {
|
||||
.objects
|
||||
.values()
|
||||
.any(|object| matches!(object, codec::objects::ObjectType::Field(_)));
|
||||
if !has_fields {
|
||||
if !has_fields || fieldeval(document) & 4 == 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
let snapshot = document.clone();
|
||||
|
||||
Reference in new issue
Block a user