forked from 1b-agent/opencadstudio-upstream
Merge PR #1590 from ramox81/codex/field-table-placeholders: table formula buttons, block placeholders, attribute fields on insert, plot-time fields
The PR pinned the codec to its fork through [patch]; codec #81 is merged upstream and main already points at it, so the patch section is dropped.
This commit is contained in:
commit
29ed1cae9b
29 files changed
+524
-12
No files matched your search
@@ -360,3 +360,59 @@ fn display_name() -> Option<String> {
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
None
|
||||
}
|
||||
|
||||
/// Copy each attribute definition's field onto the matching attribute of a
|
||||
/// new block reference (block placeholders resolve against the reference).
|
||||
/// Returns the attributes that received a field.
|
||||
pub fn attach_attribute_fields(document: &mut CadDocument, insert: Handle) -> Vec<Handle> {
|
||||
let context = OcsFieldContext(None);
|
||||
document.attach_attribute_fields(insert, &context)
|
||||
}
|
||||
|
||||
/// Whether any attribute definition of `block` hosts a field.
|
||||
pub fn block_has_attribute_fields(document: &CadDocument, block: &str) -> bool {
|
||||
let Some(record) = document.block_records.iter().find(|r| r.name.eq_ignore_ascii_case(block)) else {
|
||||
return false;
|
||||
};
|
||||
record.entity_handles.iter().filter_map(|h| document.get_entity(*h)).any(|e| {
|
||||
matches!(e, codec::entities::EntityType::AttributeDefinition(_)) && hosts_field(document, e)
|
||||
})
|
||||
}
|
||||
|
||||
/// Give plot-time fields (PlotDate) the plot's time; returns the hosts whose
|
||||
/// text changed.
|
||||
pub fn stamp_plot_fields(document: &mut CadDocument) -> Vec<Handle> {
|
||||
let snapshot = document.clone();
|
||||
let context = PlotContext(OcsFieldContext(Some(&snapshot)));
|
||||
document.stamp_plot_fields(&context)
|
||||
}
|
||||
|
||||
/// The app context while a plot is produced.
|
||||
struct PlotContext<'a>(OcsFieldContext<'a>);
|
||||
|
||||
impl FieldContext for PlotContext<'_> {
|
||||
fn now_julian(&self) -> f64 {
|
||||
self.0.now_julian()
|
||||
}
|
||||
fn file_times(&self) -> Option<(f64, f64)> {
|
||||
self.0.file_times()
|
||||
}
|
||||
fn plotting(&self) -> bool {
|
||||
true
|
||||
}
|
||||
fn login(&self) -> Option<String> {
|
||||
self.0.login()
|
||||
}
|
||||
fn getvar(&self, name: &str) -> Option<String> {
|
||||
self.0.getvar(name)
|
||||
}
|
||||
fn file_size(&self) -> Option<u64> {
|
||||
self.0.file_size()
|
||||
}
|
||||
fn date_locale(&self) -> codec::fields::DateLocale {
|
||||
self.0.date_locale()
|
||||
}
|
||||
fn getenv(&self, name: &str) -> Option<String> {
|
||||
self.0.getenv(name)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user