Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
0d93100
Properties: Annotative scale row, Annotation Object Scale dialog, pap…
codyvogt Oct 15, 2026
0f448ff
Annotation Object Scale: one scale per line, the dialog centred
codyvogt Oct 15, 2026
0b26bb6
Properties: Annotative scale shows the current scale; the dialog is m…
codyvogt Oct 15, 2026
a5b70e4
Properties: Annotative scale lists every scale again; no Escape handl…
codyvogt Oct 15, 2026
02dfcc4
Properties: annoScales only for annotative objects; dialog keys follo…
codyvogt Oct 20, 2026
5c11e62
Properties test: a SOLID pattern replaces a gradient fill
codyvogt Oct 24, 2026
a500419
Annotation Object Scale: egui ids without the API this egui deprecates
codyvogt Oct 26, 2026
e916a0b
Properties: pass the palette's ids on without a borrow (main's ids ar…
codyvogt Nov 21, 2026
e6bdda4
Tests: a scale change to many objects is one undo step; the current s…
codyvogt Nov 21, 2026
706586b
Merge remote-tracking branch 'upstream/main' into feat/properties-ann…
codyvogt Nov 24, 2026
12c03bf
Merge remote-tracking branch 'upstream/main' into feat/properties-ann…
codyvogt Nov 24, 2026
a670e19
Merge remote-tracking branch 'upstream/main' into feat/properties-ann…
codyvogt Nov 29, 2026
a76a26d
Translations to craft-i18n, tests into the engine's it binary (AGENTS…
codyvogt Nov 30, 2026
d566f33
Merge main into feat/properties-annotative-scales
codyvogt Dec 1, 2026
f17ecf8
Properties: annotative rows in helpers, within main's complexity limit
codyvogt Dec 1, 2026
85704ca
Merge main into feat/properties-annotative-scales
codyvogt Dec 2, 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
5 changes: 5 additions & 0 deletions crates/engine/src/cmd/annoscale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ fn list_json(d: &Drawing) -> Value {
}

/// Scale names given as one string or an array of strings.
/// Scale names given as one name or an array of names (`cmd` names the caller in errors).
pub(crate) fn scale_names(cmd: &str, v: Option<&Value>) -> Result<Vec<String>> {
names(cmd, v)
}

fn names(cmd: &str, v: Option<&Value>) -> Result<Vec<String>> {
match v {
None | Some(Value::Null) => Ok(Vec::new()),
Expand Down
5 changes: 3 additions & 2 deletions crates/engine/src/cmd/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn specs() -> Vec<CommandSpec> {
CommandSpec::new("properties", "Properties", run_get).menu(&["Modify", "Properties"]).alias(&["pr", "props", "ch"]).params("{handles?} → properties of the selection").noundo(),
CommandSpec::new("properties.set", "Set Properties", run_set).params(
"{handles?, layer?, color?, linetype?, lineweight?, ltscale?, thickness?, transparency?: \"ByLayer\" | \"ByBlock\" | 0..90, visible?, annotative?, \
annoScales?: [scale name] (the scales an annotative object supports), \
<geometry fields: radius, center, start, end, text, height, rotation…>, text: style?, justify?, oblique?, positionX/Y/Z?, alignmentX/Y?, \
mtext: style?, justify?, lineSpacing?, lineSpacingDistance?, lineSpacingStyle?: atLeast | exactly, positionX/Y/Z?, \
dimension: dimStyle?, textOverride?, textRotation?, textPositionX/Y?, prefix?, suffix?, altPrefix?, altSuffix?, dimScale?, precision?, \
Expand All @@ -41,8 +42,8 @@ pub fn specs() -> Vec<CommandSpec> {
CommandSpec::new("properties.describe", "Describe Properties", run_describe)
.params(
"{handles?, type?: one of the `types` names, to describe only those objects} → {types: [{type, count}], filter?, count, \
groups: [{name, rows: [{key, label, kind, value, varies, display, editable, note?, overridden?, options?: [{value, label}], quick?}]}]} \
(each row's `key` is the `properties.set` key that changes it; text, mtext and dimensions have their own groups)",
groups: [{name, extra?, rows: [{key, label, kind, value, varies, display, editable, note?, overridden?, options?: [{value, label}], quick?}]}]} \
(each row's `key` is the `properties.set` key that changes it; text, mtext and dimensions have their own groups; hatches and multileaders an `extra` group of annotative rows)",
)
.noundo(),
CommandSpec::new("matchprop", "Match Properties", matchprop::run_matchprop)
Expand Down
37 changes: 36 additions & 1 deletion crates/engine/src/cmd/props/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const SET_KEYS: &[&str] = &[
"transparency",
"visible",
"annotative",
"annoScales",
"dimStyle",
"textOverride",
"textRotation",
Expand Down Expand Up @@ -214,6 +215,8 @@ struct Call<'a> {
dim_vars: DimVars,
prep: Prepared,
anno_scale: AnnoScale,
/// `annoScales`: the exact scales an annotative object supports.
anno_scales: Option<Vec<AnnoScale>>,
}

/// The keys some object took.
Expand Down Expand Up @@ -330,13 +333,14 @@ pub(super) fn run_set(s: &mut Session, p: &Value) -> Result<Value> {
{
return Err(bad("properties.set", format!("unknown pattern {}", v.trim().to_ascii_uppercase())));
}
let anno_scales = anno_scales_of(d, p)?;
if hs.is_empty() {
// Every object was left out: the drawing stays as it was, with no undo step.
return Ok(left_out.result(0, &[]));
}
let prep = Prepared::new(d, p, &hs);
let anno_scale = d.current_anno_scale();
let c = Call { p, color, transparency, thickness, lineweight, linetype, dim_style, text_style, dim_vars, prep, anno_scale };
let c = Call { p, color, transparency, thickness, lineweight, linetype, dim_style, text_style, dim_vars, prep, anno_scale, anno_scales };
// A failed call changes nothing (a command's error doesn't undo what it did), so the drawing
// is taken for writing, and the layer made, only after every check.
let d = s.doc_mut()?;
Expand Down Expand Up @@ -395,6 +399,26 @@ fn mleader<'c>(m: &mut cadcraft_doc::MLeader, c: &'c Call<'_>, used: &mut Used<'
}
}

/// `annoScales`: the exact scales an annotative object supports (names of the scale list, each
/// once; at least one), or `None` when the call doesn't give any.
fn anno_scales_of(d: &Drawing, p: &Value) -> Result<Option<Vec<AnnoScale>>> {
let v = match p.get("annoScales") {
None | Some(Value::Null) => return Ok(None),
Some(v) => v,
};
let mut list: Vec<AnnoScale> = Vec::new();
for n in crate::cmd::annoscale::scale_names("properties.set", Some(v))? {
let sc = d.anno_scale(&n).cloned().ok_or_else(|| bad("properties.set", format!("`{n}` is not in the scale list")))?;
if !list.iter().any(|x| x.name.eq_ignore_ascii_case(&sc.name)) {
list.push(sc);
}
}
if list.is_empty() {
return Err(bad("properties.set", "an annotative object keeps at least one scale"));
}
Ok(Some(list))
}

/// The properties every object has: annotative, layer, color, linetype, lineweight, linetype
/// scale, transparency, thickness and visibility.
fn common<'c>(e: &mut Entity, c: &'c Call<'_>, used: &mut Used<'c>) {
Expand All @@ -409,6 +433,17 @@ fn common<'c>(e: &mut Entity, c: &'c Call<'_>, used: &mut Used<'c>) {
}
used.insert("annotative");
}
// The scales of an annotative object (one made annotative just above included): a plain
// object stays plain, as `annotative: false` leaves it.
if let Some(list) = &c.anno_scales
&& cadcraft_doc::is_annotative(e)
{
e.common.anno_scales.clone_from(list);
if let EntityKind::Dimension(dm) = &mut e.kind {
dm.block = None;
}
used.insert("annoScales");
}
if let Some(l) = str_param(p, "layer") {
e.common.layer = l.to_string();
used.insert("layer");
Expand Down
115 changes: 93 additions & 22 deletions crates/engine/src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ pub struct TypeCount {
pub struct Group {
pub name: &'static str,
pub rows: Vec<Row>,
/// Rows the palette shows after its own for the object (a hatch's or multileader's
/// annotative scaling), rather than in their place.
#[serde(skip_serializing_if = "is_false")]
pub extra: bool,
}

impl Group {
fn new(name: &'static str, rows: Vec<Row>) -> Self {
Group { name, rows, extra: false }
}
}

/// One property of the described objects.
Expand Down Expand Up @@ -141,6 +151,9 @@ pub enum Kind {
Transparency,
TextStyle,
DimStyle,
/// The annotation scales an annotative object supports: names of the drawing's scale list,
/// changed in the Annotation Object Scale dialog (OBJECTSCALE) or with `annoScales`.
AnnoScales,
}

/// A transparency as `properties.set` takes it: "ByLayer", "ByBlock" or a percentage.
Expand Down Expand Up @@ -182,6 +195,9 @@ pub fn describe(d: &Drawing, handles: &[Handle], filter: Option<&str>) -> Descri
groups.extend(mtext_groups(&c, &ents, &mtexts));
} else if dims.len() == ents.len() {
groups.extend(dimension_groups(&c, &ents, &dims));
} else if ents.iter().all(|e| matches!(e.kind, EntityKind::Hatch(_) | EntityKind::MLeader(_))) {
// Hatches and multileaders: their annotative scaling, after the palette's own rows.
groups.push(Group { name: "Misc", rows: annotative_rows(&c, &ents), extra: true });
}
}
Description { types, filter, count: ents.len(), groups }
Expand Down Expand Up @@ -272,13 +288,51 @@ fn general(c: &Ctx, ents: &[&Entity]) -> Group {
c.row("lineweight", "Lineweight", Kind::Lineweight, ents.iter().map(|e| json!(e.common.lineweight.name()))),
c.row("transparency", "Transparency", Kind::Transparency, ents.iter().map(|e| transparency_value(e.common.transparency))),
];
Group { name: "General", rows }
Group::new("General", rows)
}

fn annotative(c: &Ctx, ents: &[&Entity]) -> Row {
c.row("annotative", "Annotative", Kind::Bool, ents.iter().map(|e| json!(cadcraft_doc::is_annotative(e)))).quick()
}

/// Annotative, and when every described object is annotative, the scales they support
/// (Annotative scale).
fn annotative_rows(c: &Ctx, ents: &[&Entity]) -> Vec<Row> {
let mut rows = vec![annotative(c, ents)];
if ents.iter().all(|e| cadcraft_doc::is_annotative(e)) {
let names = |e: &Entity| json!(e.common.anno_scales.iter().map(|s| s.name.clone()).collect::<Vec<_>>());
let mut r = c.row("annoScales", "Annotative scale", Kind::AnnoScales, ents.iter().map(|e| names(e)));
if !r.varies {
r.display = r.value.as_array().into_iter().flatten().filter_map(Value::as_str).collect::<Vec<_>>().join(", ");
}
rows.push(r);
}
rows
}

/// Whether every described object is annotative: its sizes are then paper sizes, shown at the
/// current annotation scale too (Model text height…).
fn all_annotative(ents: &[&Entity]) -> bool {
!ents.is_empty() && ents.iter().all(|e| cadcraft_doc::is_annotative(e))
}

/// The factor `e` draws at in model space now: the current annotation scale's when it supports
/// it, else the scale it shows at (1 when hidden or not annotative).
fn model_factor(d: &Drawing, e: &Entity) -> f64 {
match d.anno_draw(e) {
cadcraft_doc::AnnoDraw::Scaled(f) if f.is_finite() && f > 0.0 => f,
_ => 1.0,
}
}

/// A paper size row's model size companion (read-only): `paper` × each object's factor.
fn model_row(c: &Ctx, key: &'static str, label: &'static str, ents: &[&Entity], paper: impl IntoIterator<Item = f64>) -> Row {
let vals: Vec<Value> = ents.iter().zip(paper).map(|(e, v)| json!(v * model_factor(c.d, e))).collect();
let mut r = c.row(key, label, Kind::Distance, vals).read_only();
r.note = Some("The paper size at the current annotation scale".into());
r
}

/// TEXT justifications as `properties.set` takes them, with their labels.
pub const TEXT_JUSTIFY: &[(&str, &str)] = &[
("Left", "Left"),
Expand Down Expand Up @@ -345,13 +399,21 @@ fn text_groups(c: &Ctx, ents: &[&Entity], texts: &[&Text]) -> Vec<Group> {
let mut text = vec![
c.row("text", "Contents", Kind::Text, texts.iter().map(|t| json!(t.value))).quick(),
c.choice("style", "Style", Kind::TextStyle, c.text_styles(), texts.iter().map(|t| json!(t.style))).quick(),
annotative(c, ents),
c.choice("justify", "Justification", Kind::Choice, options(TEXT_JUSTIFY), texts.iter().map(|t| json!(text_justify(t)))).quick(),
c.row("height", "Height", Kind::Distance, texts.iter().map(|t| json!(t.height))).quick(),
];
text.extend(annotative_rows(c, ents));
text.push(c.choice("justify", "Justification", Kind::Choice, options(TEXT_JUSTIFY), texts.iter().map(|t| json!(text_justify(t)))).quick());
// Annotative text's height is on paper; AutoCAD shows it in the model too.
if all_annotative(ents) {
text.push(c.row("height", "Paper text height", Kind::Distance, texts.iter().map(|t| json!(t.height))).quick());
text.push(model_row(c, "modelHeight", "Model text height", ents, texts.iter().map(|t| t.height)));
} else {
text.push(c.row("height", "Height", Kind::Distance, texts.iter().map(|t| json!(t.height))).quick());
}
text.extend([
c.row("rotation", "Rotation", Kind::Direction, texts.iter().map(|t| json!(t.rotation.to_degrees()))).quick(),
c.row("widthFactor", "Width factor", Kind::Number, texts.iter().map(|t| json!(t.width_factor))),
c.row("oblique", "Obliquing", Kind::Angle, texts.iter().map(|t| json!(t.oblique.to_degrees()))),
];
]);
// Aligned and fit text sit between two points: the second is the text alignment point.
let second: Option<Vec<cadcraft_geom::Vec3>> =
texts.iter().map(|t| if matches!(t.halign, HAlign::Aligned | HAlign::Fit) { t.align_pt } else { None }).collect();
Expand All @@ -365,7 +427,7 @@ fn text_groups(c: &Ctx, ents: &[&Entity], texts: &[&Text]) -> Vec<Group> {
c.row("positionY", "Position Y", Kind::Distance, texts.iter().map(|t| json!(t.justify_point().y))),
c.row("positionZ", "Position Z", Kind::Distance, texts.iter().map(|t| json!(t.insert.z))),
];
vec![Group { name: "Text", rows: text }, Group { name: "Geometry", rows: geometry }]
vec![Group::new("Text", text), Group::new("Geometry", geometry)]
}

fn mtext_groups(c: &Ctx, ents: &[&Entity], mts: &[&MText]) -> Vec<Group> {
Expand All @@ -377,12 +439,20 @@ fn mtext_groups(c: &Ctx, ents: &[&Entity], mts: &[&MText]) -> Vec<Group> {
cadcraft_doc::MTextColumnType::Dynamic => "Dynamic".to_string(),
},
};
let text = vec![
let anno = all_annotative(ents);
let mut text = vec![
c.row("text", "Contents", Kind::Contents, mts.iter().map(|t| json!(t.contents))).quick(),
c.choice("style", "Style", Kind::TextStyle, c.text_styles(), mts.iter().map(|t| json!(t.style))).quick(),
annotative(c, ents),
c.choice("justify", "Justification", Kind::Choice, options(MTEXT_JUSTIFY), mts.iter().map(|t| json!(mtext_justify(t.attach)))).quick(),
c.row("height", "Text height", Kind::Distance, mts.iter().map(|t| json!(t.height))).quick(),
];
text.extend(annotative_rows(c, ents));
text.push(c.choice("justify", "Justification", Kind::Choice, options(MTEXT_JUSTIFY), mts.iter().map(|t| json!(mtext_justify(t.attach)))).quick());
if anno {
text.push(c.row("height", "Paper text height", Kind::Distance, mts.iter().map(|t| json!(t.height))).quick());
text.push(model_row(c, "modelHeight", "Model text height", ents, mts.iter().map(|t| t.height)));
} else {
text.push(c.row("height", "Text height", Kind::Distance, mts.iter().map(|t| json!(t.height))).quick());
}
text.extend([
c.row("rotation", "Rotation", Kind::Direction, mts.iter().map(|t| json!(t.rotation.to_degrees()))).quick(),
c.row("lineSpacing", "Line space factor", Kind::Number, mts.iter().map(|t| json!(t.line_spacing))),
c.row("lineSpacingDistance", "Line space distance", Kind::Distance, mts.iter().map(|t| json!(t.line_spacing * t.height * LINE_PITCH))),
Expand All @@ -393,15 +463,20 @@ fn mtext_groups(c: &Ctx, ents: &[&Entity], mts: &[&MText]) -> Vec<Group> {
spacing,
mts.iter().map(|t| json!(if t.line_spacing_exact { "exactly" } else { "atLeast" })),
),
c.row("width", "Defined width", Kind::Distance, mts.iter().map(|t| json!(t.width))),
c.row("columns", "Columns", Kind::Text, mts.iter().map(|t| json!(columns(t)))).read_only(),
];
]);
if anno {
text.push(c.row("width", "Paper defined width", Kind::Distance, mts.iter().map(|t| json!(t.width))));
text.push(model_row(c, "modelWidth", "Model defined width", ents, mts.iter().map(|t| t.width)));
} else {
text.push(c.row("width", "Defined width", Kind::Distance, mts.iter().map(|t| json!(t.width))));
}
text.push(c.row("columns", "Columns", Kind::Text, mts.iter().map(|t| json!(columns(t)))).read_only());
let geometry = vec![
c.row("positionX", "Position X", Kind::Distance, mts.iter().map(|t| json!(t.insert.x))),
c.row("positionY", "Position Y", Kind::Distance, mts.iter().map(|t| json!(t.insert.y))),
c.row("positionZ", "Position Z", Kind::Distance, mts.iter().map(|t| json!(t.insert.z))),
];
vec![Group { name: "Text", rows: text }, Group { name: "Geometry", rows: geometry }]
vec![Group::new("Text", text), Group::new("Geometry", geometry)]
}

/// How a dimension style variable is entered.
Expand Down Expand Up @@ -685,13 +760,9 @@ fn dimension_groups(c: &Ctx, ents: &[&Entity], dims: &[&Dimension]) -> Vec<Group
// Measurement and text position need each dimension's geometry.
let geometry: Option<Vec<cadcraft_render::DimGeometry>> =
(dims.len() <= GEOMETRY_CAP).then(|| dims.iter().map(|dm| cadcraft_render::dimension_in(c.d, dm)).collect());
let mut groups = vec![Group {
name: "Misc",
rows: vec![
c.choice("dimStyle", "Dim style", Kind::DimStyle, c.dim_styles(), dims.iter().map(|dm| json!(dm.style))).quick(),
annotative(c, ents),
],
}];
let mut misc = vec![c.choice("dimStyle", "Dim style", Kind::DimStyle, c.dim_styles(), dims.iter().map(|dm| json!(dm.style))).quick()];
misc.extend(annotative_rows(c, ents));
let mut groups = vec![Group::new("Misc", misc)];
for &name in DIM_GROUPS {
let mut rows: Vec<Row> = Vec::new();
for p in DIM_PROPS.iter().filter(|p| p.group == name && p.palette) {
Expand Down Expand Up @@ -754,7 +825,7 @@ fn dimension_groups(c: &Ctx, ents: &[&Entity], dims: &[&Dimension]) -> Vec<Group
}
_ => {}
}
groups.push(Group { name, rows });
groups.push(Group::new(name, rows));
}
groups
}
Expand Down
1 change: 1 addition & 0 deletions crates/engine/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod polyface_explode;
mod post_command_passes;
mod prompt_keywords;
mod prompt_or_once;
mod properties_annotative;
mod properties_describe;
mod properties_set_locked;
mod properties_set_text_dims;
Expand Down
Loading
Loading