Skip to content
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
de73d8c
Text formulas and fields: =... in text, dimensions and leaders; UPDAT…
claude Oct 27, 2026
43087b5
Register the CADCRAFTFORMULA xdata application in the APPID table
claude Oct 27, 2026
8675424
Text formulas: review fixes
claude Oct 27, 2026
3bcfb17
Text formulas: ^ left to right; a replaced AutoCAD field is not writt…
claude Oct 27, 2026
f20306e
Merge upstream main (release 0.14.0)
claude Oct 28, 2026
ec32ad2
Keep DXF finishing within upstream's complexity limit
claude Oct 28, 2026
2fc041b
CLI perf drawing: the text formula field
claude Oct 28, 2026
ae9e57f
Merge upstream main (0.15.1) into the text formula part
claude Oct 31, 2026
98139c3
Text formulas: the formula field in upstream 0.15's new objects and r…
claude Oct 31, 2026
90c9d06
Text formulas: an AutoCAD field the reader declines is kept on save
claude Oct 31, 2026
780f469
Merge upstream main into split/text-formulas
claude Oct 31, 2026
466fe69
Merge upstream main into split/text-formulas
claude Nov 2, 2026
ffa7310
Text formulas: Chinese labels for Text Formulas and Update Fields
claude Nov 2, 2026
eb87356
Fit upstream 0.15.1: the new fields in its added objects and tests
claude Nov 2, 2026
60709f6
Text formulas: an AutoCAD field's text is saved as read while the fie…
claude Nov 2, 2026
5fe9571
Merge upstream main into split/text-formulas
claude Nov 4, 2026
3bf07c1
Fit main: the new fields in its added tests
claude Nov 4, 2026
748d920
Text formulas: a block reference's attribute formulas are worked out …
claude Nov 4, 2026
2144528
Merge upstream main into split/text-formulas
claude Nov 4, 2026
f22ff80
Fit main: the new fields in its added code and tests
claude Nov 4, 2026
0c0d027
Merge upstream main into split/text-formulas
claude Nov 5, 2026
420d851
Merge remote-tracking branch 'upstream/main' into split/text-formulas
claude Nov 13, 2026
57783dc
Merge upstream main into split/text-formulas
claude Nov 17, 2026
4c6774c
Merge upstream/main into split/text-formulas
claude Nov 20, 2026
d48d599
Merge upstream/main into split/text-formulas (with FredApps's fixes f…
claude Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/cadcraft-cli/src/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn synthetic(n: usize, side: f64) -> Result<cadcraft_engine::doc::Drawing, cadcr
plinegen: false,
}),
_ => EntityKind::Text(d::Text {
formula: None,
insert: v3(x, y),
align_pt: None,
height: s * 0.2,
Expand Down
1 change: 1 addition & 0 deletions crates/constraints/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ fn invalid_references_and_purge() {
let t = add_e(
&mut d,
EntityKind::Text(cadcraft_doc::Text {
formula: None,
insert: v(0.0, 0.0),
align_pt: None,
height: 1.0,
Expand Down
4 changes: 4 additions & 0 deletions crates/doc/src/entity/dim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ pub struct DimMarks {
/// Inspection frame, label and rate (DIMINSPECT).
#[serde(skip_serializing_if = "Option::is_none")]
pub inspect: Option<Inspection>,
/// A formula for the dimension text (`=<>/2`, `=TEXT(<>,"0.0")&" mm"`; `<>` is the
/// measurement); `Dimension::text` holds the last result.
#[serde(skip_serializing_if = "Option::is_none")]
pub formula: Option<String>,
}

impl DimMarks {
Expand Down
8 changes: 8 additions & 0 deletions crates/doc/src/entity/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub struct Text {
pub halign: HAlign,
#[serde(default)]
pub valign: VAlign,
/// The formula the text shows the result of: `=...` (CADCraft text formulas) or an AutoCAD
/// field code (`%<\AcVar date \f "dd.MM.yyyy">%`). `value` holds the last result.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub formula: Option<String>,
}

impl Text {
Expand Down Expand Up @@ -83,6 +87,10 @@ pub struct MText {
/// one column.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub columns: Option<MTextColumns>,
/// The formula the text shows the result of (see [`Text::formula`]); `contents` holds the
/// last result.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub formula: Option<String>,
}

fn attach_tl() -> u8 {
Expand Down
3 changes: 3 additions & 0 deletions crates/doc/src/extents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ mod tests {

fn text(halign: HAlign, valign: VAlign) -> Text {
Text {
formula: None,
insert: Vec3::new(0.0, 0.0, 0.0),
align_pt: Some(Vec3::new(0.0, 0.0, 0.0)),
height: 1.0,
Expand All @@ -618,6 +619,7 @@ mod tests {

fn mtext(contents: &str, width: f64) -> crate::MText {
crate::MText {
formula: None,
insert: Vec3::new(10.0, 10.0, 0.0),
height: 2.5,
width,
Expand Down Expand Up @@ -684,6 +686,7 @@ mod tests {
#[test]
fn multileader_text_is_inside_its_bounds() {
let mtext = crate::MText {
formula: None,
insert: Vec3::new(25.45, 0.0, 0.0),
height: 5.0,
width: 0.0,
Expand Down
12 changes: 11 additions & 1 deletion crates/doc/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ pub struct ForeignExtra {
pub color_book: Option<(String, String)>,
/// Other unmodelled property groups (material 347, shadow mode 284).
pub props: Vec<RawTag>,
/// A TEXT or MTEXT with an AutoCAD field: the formula the field was read as and the text the
/// file showed. While the formula is unchanged the text is written back as read, so it
/// matches the value cached in the field and AutoCAD keeps the field (it works it out again
/// itself); CADCraft shows the field worked out for today meanwhile.
pub field_text: Option<(String, String)>,
}

impl ForeignExtra {
pub fn is_empty(&self) -> bool {
self.xdict.is_none() && self.reactors.is_empty() && self.xdata.is_empty() && self.color_book.is_none() && self.props.is_empty()
self.xdict.is_none()
&& self.reactors.is_empty()
&& self.xdata.is_empty()
&& self.color_book.is_none()
&& self.props.is_empty()
&& self.field_text.is_none()
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/doc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ fn visible_attributes_of_a_missing_block_still_count() {
let attrib = |invisible: bool| Attrib {
tag: "TAG".into(),
text: Text {
formula: None,
insert: Vec3::new(1000.0, 1000.0, 0.0),
align_pt: None,
height: 10.0,
Expand Down Expand Up @@ -433,6 +434,7 @@ fn plain_attrib(tag: &str) -> Attrib {
Attrib {
tag: tag.into(),
text: Text {
formula: None,
insert: Vec3::ZERO,
align_pt: None,
height: 1.0,
Expand Down Expand Up @@ -573,6 +575,7 @@ fn attdef_in_block_is_ignored_in_insert_extents() {
EntityKind::AttDef(Attrib {
tag: "TAG".into(),
text: Text {
formula: None,
insert: Vec3::new(5000.0, 5000.0, 0.0),
align_pt: None,
height: 1.0,
Expand All @@ -598,6 +601,7 @@ fn attdef_in_block_is_ignored_in_insert_extents() {

fn text_kind(value: &str) -> EntityKind {
EntityKind::Text(Text {
formula: None,
insert: Vec3::new(10.0, 10.0, 0.0),
align_pt: None,
height: 2.0,
Expand All @@ -613,6 +617,7 @@ fn text_kind(value: &str) -> EntityKind {

fn mtext_kind(contents: &str) -> EntityKind {
EntityKind::MText(MText {
formula: None,
insert: Vec3::new(10.0, 10.0, 0.0),
height: 2.0,
width: 0.0,
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/annotate/leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl Interactive for LeaderM {
};
let text = picked.and_then(|h| s.doc().ok()?.entity(h).cloned()).and_then(|e| match &e.kind {
EntityKind::Text(t) => Some(MText {
formula: None,
insert: t.insert,
height: t.height,
width: 0.0,
Expand Down Expand Up @@ -298,6 +299,7 @@ fn add_leader(s: &mut Session, pts: &[Vec2], spline: bool, arrow: bool, ann: Ann
(false, false) => (6, 0.0),
};
Some(s.add_entity(EntityKind::MText(MText {
formula: None,
insert: v3(end + Vec2::new(dir * z.gap, lift)),
height: z.text,
width: 0.0,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/annotate/mleader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn mleader_kind(s: &Session, pts: &[Vec2], text: &str, landing: bool) -> Option<
landing: v3(*landing_pt),
dogleg,
text: (!text.is_empty()).then(|| MText {
formula: None,
insert: v3(tpos),
height: th,
width: 0.0,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ fn attdef_kind(s: &Session, tag: &str, prompt: &str, default: &str, at: Vec2, he
EntityKind::AttDef(Attrib {
tag: tag.to_ascii_uppercase(),
text: Text {
formula: None,
insert: v3(at),
align_pt: None,
height,
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/blocks/attdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl AttdefM {
s.add_entity(EntityKind::AttDef(Attrib {
tag: self.tag.to_uppercase(),
text: Text {
formula: None,
insert: v3(self.at),
align_pt: if left { None } else { Some(v3(self.at)) },
height: self.height,
Expand Down
4 changes: 4 additions & 0 deletions crates/engine/src/cmd/blocks/attedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ fn all_in_space(s: &Session) -> Result<Vec<Handle>> {
/// Change attribute `k` of block reference `h`; returns whether its value changed.
fn edit(s: &mut Session, (h, k): (Handle, usize), f: impl FnOnce(&str) -> Option<String>) -> Result<bool> {
let mut changed = false;
let env = crate::textformula::env(s);
s.doc_mut()?.modify_entity(h, |e| {
if let EntityKind::Insert(ins) = &mut e.kind
&& let Some(a) = ins.attribs.get_mut(k)
&& let Some(v) = f(&a.text.value).filter(|v| *v != a.text.value)
{
set_value(&mut a.text, v);
// A typed value replaces the attribute's formula (or field); a typed formula is kept
// and shows its result.
crate::textformula::apply_text(&mut a.text, &env, true);
changed = true;
}
})?;
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/draw/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) fn make_text(s: &Session, at: Vec2, value: &str, height: f64, rotatio
let (h, v) = j;
let left = h == HAlign::Left && v == VAlign::Baseline;
EntityKind::Text(Text {
formula: None,
insert: v3(at),
align_pt: if left { None } else { Some(v3(at)) },
height,
Expand Down Expand Up @@ -72,6 +73,7 @@ pub(super) fn run_mtext(s: &mut Session, p: &Value) -> Result<Value> {
};
let width = f64_or(p, "width", 0.0).max(0.0);
let k = EntityKind::MText(MText {
formula: None,
insert: v3(at),
height,
width,
Expand Down
5 changes: 4 additions & 1 deletion crates/engine/src/cmd/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ fn read_bytes(bytes: &[u8], name: &str, path: Option<String>) -> Result<ReadFile
Ok(ReadFile { drawing, binary_dxf: craft_dxf::is_binary(bytes), name: name.to_string(), path })
}

fn add_read(s: &mut Session, drawing: Drawing, binary_dxf: bool, name: &str, path: Option<String>) -> usize {
fn add_read(s: &mut Session, mut drawing: Drawing, binary_dxf: bool, name: &str, path: Option<String>) -> usize {
// Formulas and fields (dates) worked out for today.
let env = crate::textformula::Env { now: crate::textformula::local_now(), file: file_name(name), sheet: "Model".into(), measured: None };
crate::textformula::refresh(&mut drawing, &env);
let notes = drawing.read_notes.clone();
let i = s.open_drawing(drawing, &file_name(name), path);
if let Some(st) = s.docs.get_mut(i) {
Expand Down
2 changes: 2 additions & 0 deletions crates/engine/src/cmd/modify/explode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn explode_mtext(e: &Entity, m: &cadcraft_doc::MText) -> Vec<Entity> {
handle: Handle(0),
common: e.common.clone(),
kind: EntityKind::Text(cadcraft_doc::Text {
formula: None,
insert: v3(at),
align_pt: None,
height: m.height,
Expand Down Expand Up @@ -167,6 +168,7 @@ fn explode_dimension(d: &cadcraft_doc::Drawing, e: &Entity, dm: &cadcraft_doc::D
handle: Handle(0),
common: e.common.clone(),
kind: EntityKind::MText(cadcraft_doc::MText {
formula: None,
insert: v3(g.text_pos),
height: g.text_height,
width: 0.0,
Expand Down
5 changes: 4 additions & 1 deletion crates/engine/src/cmd/modify2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub fn specs() -> Vec<CommandSpec> {
.menu(&["Modify", "Array", "Path Array"])
.params("{handles?, path (handle), count? (default 6) | spacing?, align?: bool (default true)}")
.interactive(|_| Ok(Box::new(PathArrayM::default()))),
CommandSpec::new("updatefield", "Update Fields", run_updatefield)
.menu(&["Tools", "Update Fields"])
.params("{} (works out every text formula and known field again: dates, file name)"),
CommandSpec::new("textedit", "Edit Text...", run_textedit)
.menu(&["Modify", "Object", "Edit Text..."])
.alias(&["ed", "ddedit"])
Expand Down Expand Up @@ -154,7 +157,7 @@ pub(super) use patharray::PathArrayM;
use patharray::run_arraypath;
use pedit::{PPhase, PeditM, run_pedit};
use selop::{SelKind, SelOp, run_chspace, run_flatten, run_reverse};
use textedit::{TextEditM, run_textedit};
use textedit::{TextEditM, run_textedit, run_updatefield};
use trimext::{ellipse_kind, ellipse_of};
pub(crate) use trimext::{extend_other, trim_other};

Expand Down
Loading
Loading