forked from 1b-agent/opencadstudio-upstream
UPDATEFIELD: count fields as the reference does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a8ec02003
commit
6da3fea563
2 files changed
+23
-18
No files matched your search
+18
-14
@@ -546,6 +546,9 @@ impl OpenCADStudio {
|
||||
/// its attributes and the texts of its block definition; a table, the
|
||||
/// cell texts of its drawing (its `*T` block).
|
||||
fn update_fields(&mut self, i: usize, handles: &[Handle]) {
|
||||
if handles.is_empty() {
|
||||
return;
|
||||
}
|
||||
let doc = &self.tabs[i].scene.document;
|
||||
let mut hosts = handles.to_vec();
|
||||
for h in handles {
|
||||
@@ -572,25 +575,26 @@ impl OpenCADStudio {
|
||||
})
|
||||
.flatten()
|
||||
.collect();
|
||||
let found = hosts
|
||||
.iter()
|
||||
.filter(|h| match doc.get_entity(**h) {
|
||||
Some(entity) => crate::entities::field::hosts_field(doc, entity),
|
||||
None => attributes.iter().any(|common| {
|
||||
common.handle == **h && crate::entities::field::common_hosts_field(doc, common)
|
||||
}),
|
||||
})
|
||||
.count();
|
||||
self.command_line.push_output(&crate::tf!("{found} field(s) found."));
|
||||
if found == 0 {
|
||||
let hosting = hosts.iter().any(|h| match doc.get_entity(*h) {
|
||||
Some(entity) => crate::entities::field::hosts_field(doc, entity),
|
||||
None => attributes
|
||||
.iter()
|
||||
.any(|common| common.handle == *h && crate::entities::field::common_hosts_field(doc, common)),
|
||||
});
|
||||
if !hosting {
|
||||
self.command_line.push_output(&crate::tf!("{found} field(s) found.", found = 0));
|
||||
self.command_line.push_output(&crate::tf!("{updated} field(s) updated.", updated = 0));
|
||||
return;
|
||||
}
|
||||
// The reference counts fields, not the texts holding them, and
|
||||
// reports every field it evaluated as updated, changed or not.
|
||||
self.push_undo_snapshot(i, "UPDATEFIELD");
|
||||
let updated = self.tabs[i].scene.update_fields(32, Some(&hosts));
|
||||
if updated > 0 {
|
||||
let (changed, found) = self.tabs[i].scene.update_fields(32, Some(&hosts));
|
||||
if changed > 0 {
|
||||
self.tabs[i].dirty = true;
|
||||
}
|
||||
self.command_line.push_output(&crate::tf!("{updated} field(s) updated."));
|
||||
self.command_line.push_output(&crate::tf!("{found} field(s) found."));
|
||||
self.command_line.push_output(&crate::tf!("{updated} field(s) updated.", updated = found));
|
||||
}
|
||||
|
||||
/// A count table at `point`: `Item` | `Count`, one row per block (all
|
||||
|
||||
+5
-4
@@ -3419,13 +3419,14 @@ impl Scene {
|
||||
|
||||
/// Update the fields an evaluation event re-evaluates (see
|
||||
/// [`crate::entities::field::update_fields`]) and redraw the hosts whose
|
||||
/// text changed. Returns the number of fields the hosts hold.
|
||||
pub fn update_fields(&mut self, event: i32, hosts: Option<&[Handle]>) -> usize {
|
||||
let changed = crate::entities::field::update_fields(&mut self.document, event, hosts).0;
|
||||
/// text changed. Returns the number of hosts whose text changed and the
|
||||
/// number of fields the hosts hold.
|
||||
pub fn update_fields(&mut self, event: i32, hosts: Option<&[Handle]>) -> (usize, usize) {
|
||||
let (changed, found) = crate::entities::field::update_fields(&mut self.document, event, hosts);
|
||||
if !changed.is_empty() {
|
||||
self.bump_text_hosts(&changed);
|
||||
}
|
||||
changed.len()
|
||||
(changed.len(), found)
|
||||
}
|
||||
|
||||
/// Redraw text hosts whose stored text changed (re-evaluated fields). An
|
||||
|
||||
Reference in new issue
Block a user