Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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 @@ -85,6 +85,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 @@ -325,6 +325,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 @@ -344,6 +345,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 @@ -410,6 +412,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
5 changes: 5 additions & 0 deletions crates/doc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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 @@ -390,6 +391,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 @@ -530,6 +532,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 @@ -555,6 +558,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 @@ -570,6 +574,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/mleader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 Expand Up @@ -69,6 +70,7 @@ pub(super) fn run_leader(s: &mut Session, p: &Value) -> Result<Value> {
let th = s.doc()?.dim_style(&style(s)).map(|d| d.text_height).unwrap_or(0.18);
out.push(
s.add_entity(EntityKind::MText(MText {
formula: None,
insert: v3(*last + Vec2::new(th * 0.5, th * 0.5)),
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 @@ -330,6 +330,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
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 @@ -313,7 +313,10 @@ fn read_bytes(bytes: &[u8], name: &str, path: Option<String>) -> Result<ReadFile
Ok(ReadFile { drawing, binary_dxf: cadcraft_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 @@ -36,6 +36,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 @@ -108,6 +109,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
36 changes: 32 additions & 4 deletions crates/engine/src/cmd/modify2/textedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ use super::{
// TEXTEDIT
// =====================================================================================

/// A text formula (`=...`) of an object, which editing shows instead of its result.
fn formula_of(x: &Option<String>) -> Option<String> {
x.clone().filter(|f| crate::textformula::is_formula(f))
}

/// The text an edit starts from: the formula when the object has one, else its text.
fn text_of(k: &EntityKind) -> Option<String> {
match k {
EntityKind::Text(t) => Some(t.value.clone()),
EntityKind::AttDef(a) => Some(a.text.value.clone()),
EntityKind::MText(t) => Some(t.contents.replace("\\P", "\n")),
EntityKind::Dimension(d) => Some(if d.text.is_empty() { "<>".into() } else { d.text.clone() }),
EntityKind::Text(t) => Some(formula_of(&t.formula).unwrap_or_else(|| t.value.clone())),
EntityKind::AttDef(a) => Some(formula_of(&a.text.formula).unwrap_or_else(|| a.text.value.clone())),
EntityKind::MText(t) => Some(formula_of(&t.formula).unwrap_or_else(|| t.contents.replace("\\P", "\n"))),
EntityKind::Dimension(d) => {
Some(formula_of(&d.marks.formula).unwrap_or_else(|| if d.text.is_empty() { "<>".into() } else { d.text.clone() }))
}
_ => None,
}
}
Expand All @@ -21,6 +29,9 @@ pub(crate) fn set_text(s: &mut Session, h: Handle, text: &str) -> Result<()> {
return Err(other("The object is on a locked layer."));
}
let mut k = curves::entity(s, h)?.kind;
// The text as the edit showed it (a formula, else the value): unchanged, it keeps its
// formula or AutoCAD field.
let unchanged = text_of(&k).is_some_and(|shown| shown == text || shown == text.replace('\n', "\\P"));
match &mut k {
EntityKind::Text(t) => t.value = text.to_string(),
EntityKind::AttDef(a) => a.text.value = text.to_string(),
Expand All @@ -31,9 +42,26 @@ pub(crate) fn set_text(s: &mut Session, h: Handle, text: &str) -> Result<()> {
}
_ => return Err(other("Select a text, mtext, attribute definition or dimension.")),
}
let mut env = crate::textformula::env(s);
if let EntityKind::Dimension(dm) = &k {
env.measured = crate::textformula::measured(s.doc()?, dm);
}
crate::textformula::apply(&mut k, &env, !unchanged);
set_kind(s, h, k)
}

pub(super) fn run_updatefield(s: &mut Session, _p: &Value) -> Result<Value> {
// Without a formula or field the drawing is left as it is (not marked changed).
if !crate::textformula::has_any(s.doc()?) {
s.echo("0 field(s) updated");
return Ok(json!({ "updated": 0 }));
}
let env = crate::textformula::env(s);
let n = crate::textformula::refresh(s.doc_mut()?, &env);
s.echo(format!("{n} field(s) updated"));
Ok(json!({ "updated": n }))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

pub(super) fn run_textedit(s: &mut Session, p: &Value) -> Result<Value> {
let h = targets(s, p)?.first().copied().ok_or_else(|| bad("textedit", "`handle` is required"))?;
let text = str_param(p, "text").ok_or_else(|| bad("textedit", "`text` is required"))?;
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/cmd/mtext_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl MTextOpts {
(None, w) => (first, w.unwrap_or(0.0)),
};
MText {
formula: None,
insert: Vec3::new(insert.x, insert.y, 0.0),
height: self.height,
width,
Expand Down
Loading
Loading