From 41f9e394b90b30d327c30a2fc95a8c0eb8e45063 Mon Sep 17 00:00:00 2001 From: Walter Haslbeck <8794773+whaslbeck@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:42:49 +0100 Subject: [PATCH 01/19] fix(io): draw a tilted 2D POLYLINE as seen from above, like LWPOLYLINE (follow-up to #2584) --- crates/io/src/dxf_read/entities.rs | 24 ++++++++++---- crates/io/src/tests.rs | 51 ++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/crates/io/src/dxf_read/entities.rs b/crates/io/src/dxf_read/entities.rs index 3636d32a9..083cdc14d 100644 --- a/crates/io/src/dxf_read/entities.rs +++ b/crates/io/src/dxf_read/entities.rs @@ -539,7 +539,7 @@ pub(super) fn polyline_entity(recs: &[(String, Vec)], i: &mut usize, t: &T) break; } } - let c = common(t); + let mut c = common(t); let mut extra: Vec = Vec::new(); let k = if flags & (16 | 64) != 0 { // Polyface (64) and polygon (16) meshes become 3D faces; the first takes the @@ -552,13 +552,25 @@ pub(super) fn polyline_entity(recs: &[(String, Vec)], i: &mut usize, t: &T) } else if flags & 8 != 0 { EntityKind::Polyline3d(Polyline3d { points: pts.iter().map(|p| p.0).collect(), closed: flags & 1 != 0 }) } else { - // A 2D polyline's vertices are in its OCS: mirrored like LWPOLYLINE. - let m = if c.extrusion.z < 0.0 { -1.0 } else { 1.0 }; + // A 2D polyline's vertices are in its OCS, at the elevation of the POLYLINE's own point: + // in a tilted plane drawn as seen from above like LWPOLYLINE, else mirrored like it. + let closed = flags & 1 != 0; + let mut vertices: Vec = pts.iter().map(|p| PolyVertex { p: p.0.xy(), bulge: p.1, start_width: p.2, end_width: p.3 }).collect(); + let mut elevation = t.p(10).z; + if tilted(c.extrusion, run_points(&vertices, elevation, closed)) { + (vertices, elevation) = plan_of_tilted(c.extrusion, elevation, &vertices, closed); + c.extrusion = Vec3::Z; + } else if c.extrusion.z < 0.0 { + for v in &mut vertices { + v.p.x = -v.p.x; + v.bulge = -v.bulge; + } + } EntityKind::LwPolyline(LwPolyline { - vertices: pts.iter().map(|p| PolyVertex { p: Vec2::new(m * p.0.x, p.0.y), bulge: m * p.1, start_width: p.2, end_width: p.3 }).collect(), - closed: flags & 1 != 0, + vertices, + closed, const_width: t.fd(40, 0.0).min(t.fd(41, 0.0)).max(0.0), - elevation: t.p(10).z, + elevation, plinegen: flags & 128 != 0, }) }; diff --git a/crates/io/src/tests.rs b/crates/io/src/tests.rs index 2f5206971..3a34f1572 100644 --- a/crates/io/src/tests.rs +++ b/crates/io/src/tests.rs @@ -2238,6 +2238,57 @@ fn tilted_lwpolyline_is_drawn_as_seen_from_above() { assert_eq!(p.vertices.iter().map(|v| v.bulge).collect::>(), vec![1.0, 1.0]); } +/// A 2D POLYLINE (heavy polyline) in a tilted plane is drawn as seen from above, like a +/// LWPOLYLINE: before, its OCS points were taken for world coordinates. With extrusion +/// (0, 0.5, -√3/2) the OCS axes are x = (-1,0,0) and y = (0, √3/2, 1/2), and the elevation of 2 +/// moves the plane by twice the normal, (0, 1, -√3): the square (1,0)..(3,2) lies over +/// (-3,1)..(-1,1+√3), its corners at a mean height of 1/2 - √3. +#[test] +fn tilted_2d_polyline_is_drawn_as_seen_from_above() { + let square = |n: &str| { + format!( + "0\nSECTION\n2\nENTITIES\n0\nPOLYLINE\n8\n0\n66\n1\n10\n0\n20\n0\n30\n2\n70\n1\n{n}\ + 0\nVERTEX\n8\n0\n10\n1\n20\n0\n0\nVERTEX\n8\n0\n10\n3\n20\n0\n0\nVERTEX\n8\n0\n10\n3\n20\n2\n\ + 0\nVERTEX\n8\n0\n10\n1\n20\n2\n0\nSEQEND\n0\nENDSEC\n0\nEOF\n" + ) + }; + let d = read(square("210\n0\n220\n0.5\n230\n-0.8660254037844386\n").as_bytes(), "p.dxf").unwrap(); + let b = d.extents(&Space::Model); + let r3 = 3f64.sqrt(); + for (got, want) in [(b.min.x, -3.0), (b.min.y, 1.0), (b.max.x, -1.0), (b.max.y, 1.0 + r3)] { + assert!((got - want).abs() < 1e-9, "extents {b:?}"); + } + let e = d.model.iter().next().unwrap(); + assert_eq!(e.common.extrusion, Vec3::Z, "its points are plan coordinates now"); + let EntityKind::LwPolyline(p) = &e.kind else { panic!("not a polyline") }; + assert!((p.elevation - (0.5 - r3)).abs() < 1e-9, "the mean height of its corners: {}", p.elevation); + // In plan and in the mirrored plane the polyline stays as it was: mirrored only in x. + let plain = read(square("").as_bytes(), "p.dxf").unwrap(); + let b = plain.extents(&Space::Model); + assert!((b.min.x - 1.0).abs() < 1e-9 && (b.max.y - 2.0).abs() < 1e-9, "extents {b:?}"); + let mirrored = read(square("210\n0\n220\n0\n230\n-1\n").as_bytes(), "p.dxf").unwrap(); + let b = mirrored.extents(&Space::Model); + assert!((b.min.x + 3.0).abs() < 1e-9 && (b.max.x + 1.0).abs() < 1e-9, "extents {b:?}"); + assert_eq!(mirrored.model.iter().next().unwrap().common.extrusion, Vec3::new(0.0, 0.0, -1.0)); +} + +/// A tilted 2D POLYLINE with an arc keeps its shape as seen from above: the half circle from +/// (0,0) to (2,0) is flattened into its half ellipse, in plan x from -2 to 0 and reaching √3/2. +#[test] +fn tilted_2d_polyline_arc_is_flattened() { + let text = "0\nSECTION\n2\nENTITIES\n0\nPOLYLINE\n8\n0\n66\n1\n10\n0\n20\n0\n30\n0\n70\n0\n210\n0\n220\n0.5\n230\n-0.8660254037844386\n\ + 0\nVERTEX\n8\n0\n10\n0\n20\n0\n42\n1\n0\nVERTEX\n8\n0\n10\n2\n20\n0\n0\nSEQEND\n0\nENDSEC\n0\nEOF\n"; + let d = read(text.as_bytes(), "p.dxf").unwrap(); + let p = first(&d, |k| if let EntityKind::LwPolyline(p) = k { Some(p.clone()) } else { None }); + assert!(p.vertices.len() > 8 && p.vertices.iter().all(|v| v.bulge == 0.0), "{} vertices", p.vertices.len()); + let b = d.extents(&Space::Model); + // Bulge 1 turns counter-clockwise from (0,0) to (2,0), so the arc runs below its chord, down + // to OCS y -1: plan y -√3/2. + for (got, want) in [(b.min.x, -2.0), (b.max.x, 0.0), (b.min.y, -(3f64.sqrt()) / 2.0), (b.max.y, 0.0)] { + assert!((got - want).abs() < 5e-3, "extents {b:?}"); + } +} + /// The model extents of a one-loop solid HATCH whose edge boundary is `edges` (group 72 onwards). fn hatch_edge_extents(edges: &str) -> Bounds2 { let n = edges.matches("72\n").count(); From e928316c4d38422e614fe19f995df426da1510f4 Mon Sep 17 00:00:00 2001 From: Walter Haslbeck <8794773+whaslbeck@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:55:57 +0100 Subject: [PATCH 02/19] docs: leave file-format-parity.md to the maintainers (AGENTS.md); the rows are named in the PR description --- docs/file-format-parity.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index c12279a8d..8085f422c 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -73,7 +73,7 @@ on read with a note, so such files no longer exceed the DXF limit (#1482). **DWG | Content | Read | Write | Notes | |---|---|---|---| -| LINE, POINT, CIRCLE, ARC, ELLIPSE, LWPOLYLINE (widths, bulges, elevation), SPLINE, RAY, XLINE | yes | yes; a LWPOLYLINE in a tilted plane is read as seen from above (arcs flattened, #1886) | round-trip tests | +| LINE, POINT, CIRCLE, ARC, ELLIPSE, LWPOLYLINE (widths, bulges, elevation), SPLINE, RAY, XLINE | yes | yes | round-trip tests | | POLYLINE 2D/3D | yes | yes (as LWPOLYLINE / 3D POLYLINE) | polyface and polygon meshes flattened: lossy | | TEXT, MTEXT, ATTDEF, INSERT + ATTRIB | yes; multiline attributes (embedded MTEXT) read and drawn | yes; multiline attributes written as embedded MTEXT (DXF 2007 and later; older versions: one line); changed attribute values refresh justified baselines, including small width changes | ATTDEF prompt kept (#137); unchanged values retain imported-font placement; a justified TEXT's insertion point (group 10, which AutoCAD takes from a DWG as it is) is computed as AutoCAD computes it: Middle (M) centred on the string's own extents, bottom justifications at a TrueType face's descent (#2229) | | DIMENSION (all 7 kinds) | yes | yes, with anonymous `*D` blocks | a reopened dimension's `*D` block is regenerated under its name, unreferenced ones dropped (#495); DIMASSOC objects written for every associated kind — linear/aligned, angular, radial/diametric, ordinate and arc length — and read back without CADCraft's xdata (#1651) | @@ -81,11 +81,11 @@ on read with a note, so such files no longer exceed the DXF limit (#1482). **DWG | DIMENSION (all 7 kinds) | yes | yes, with anonymous `*D` blocks; their text keeps the diameter sign as `%%c`, so SHX styles plot it (#1645) | a reopened dimension's `*D` block is regenerated under its name, unreferenced ones dropped (#495); DIMASSOC objects written | | LEADER | yes | yes | | | MULTILEADER | yes (#459) | yes, native MULTILEADER with MLEADERSTYLE (#459) | several landings per multileader are folded into one; per-object overrides and annotative scale contexts not kept | -| HATCH pattern / solid | yes | yes; associative hatches keep their boundary objects in blocks too, and the boundary carries the hatch reactor (stretched dynamic blocks drag the fill in AutoCAD); a hatch in a tilted plane is read as seen from above (#1886), its pattern and gradient turned with it; a pattern keeps the line spacing and dashes of its plane | | +| HATCH pattern / solid | yes | yes; associative hatches keep their boundary objects in blocks too, and the boundary carries the hatch reactor (stretched dynamic blocks drag the fill in AutoCAD) | | | HATCH gradient | yes | yes (#162, fixes #80) | | | SOLID, TRACE, 3DFACE | yes | yes | | | ACAD_TABLE | yes | yes (entity + block) | | -| VIEWPORT | yes | yes; frozen-layer lists kept (#150), also as standard group 341 layer handles that other programs read | DWG: the DXF→DWG converter does not yet write group 341 (frozen layers survive a CADCraft round trip via xdata); VP layer colour overrides lost (#99, PR #197) | +| VIEWPORT | yes | yes; frozen-layer lists kept (#150), also as standard group 341 layer handles that other programs read; view twist (51) | DWG: the DXF→DWG converter does not yet write group 341 (frozen layers survive a CADCraft round trip via xdata); VP layer colour overrides lost (#99, PR #197) | | IMAGE | yes, with IMAGEDEF | yes, with IMAGEDEF and IMAGEDEF_REACTOR | the picture is loaded from its file and drawn (#1756); brightness and contrast are kept but not applied (FF10) | | WIPEOUT | yes | yes (#147, fixes #79) | Implicit or explicit closure in memory; explicit closing point on save. Same logical grips and edit results before/after DXF/DWG round trips (#2256). | | MLINE (+ MLINESTYLE), HELIX, TOLERANCE | yes (#510, #420) | yes | | @@ -93,7 +93,7 @@ on read with a note, so such files no longer exceed the DXF limit (#1482). **DWG | 3DSOLID, BODY, SURFACE, MESH, SHAPE, UNDERLAY, OLE2FRAME, LIGHT, CAMERA, SECTION, POINTCLOUD, proxy entities | kept as Unknown (raw tags) | written back as read, with their CLASS records (#528); a proxy entity's class number (group 91) is renumbered to its class's place in the written CLASSES (#1812); **dropped by DWG save** (acadrust) | only their layer follows edits | | Header variables | all read | 36 written | AutoCAD writes about 280 | | Tables: LAYER (+ transparency, description), LTYPE, STYLE, DIMSTYLE, BLOCK_RECORD | yes | yes | | -| Tables: VPORT, VIEW, UCS, APPID | yes | yes: saved viewport configurations (#504), named views, UCSs | UCS elevation lost | +| Tables: VPORT, VIEW, UCS, APPID | yes | yes: saved viewport configurations (#504) with each tile's view twist (51), named views, UCSs | UCS elevation lost | | Objects: LAYOUT, DICTIONARY, XRECORD, TABLESTYLE, DIMASSOC | yes | yes | | | Objects: GROUP, MLINESTYLE, MLEADERSTYLE, IMAGEDEF, SCALE | yes | yes (groups #417, scale list #468) | | | Objects: VISUALSTYLE, PLOTSETTINGS, materials, field objects and other unmodelled objects | kept raw (#528) | written back as read; a proxy object (ACAD_PROXY_OBJECT) keeps its class: its group 91 is renumbered to the written CLASSES, which keep the class it names, and one whose number names no class is dropped (#1812) | not editable | @@ -140,7 +140,6 @@ our output in AutoCAD black-box. | Date | Change | Summary | |---|---|---| -| 2026-10-31 | minor | HATCH and LWPOLYLINE in a tilted plane (extrusion off the Z axis) are read as seen from above at their mean height, instead of keeping plane coordinates that turned them about the origin (#1886) | | 2026-10-30 | minor | Raster images: the picture is loaded from its file when a drawing opens and drawn on screen and in PNG output (#1756, viewport part; based on #1029) | | 2026-10-29 | minor | R2000 DXF: CLASS records written without group 91 (instance count), which came with the 2004 format; AutoCAD LT 2026 stopped responding on every R2000 DXF CADCraft saved (checked black-box in AutoCAD LT 2026) | | 2026-10-26 | minor | CC-046: ATTEDIT and -ATTEDIT value changes invalidate derived justified baselines before DXF/DWG export; preserve alignment anchors, unchanged values and Aligned/Fit endpoints. Review follow-up: baseline recomputation preserves insertion elevation independently of alignment elevation. The shared writer correction also applies to justified TEXT. Independent of attribute editor UI; reverting the follow-up restores elevation loss on recomputation, while reverting the value setter restores stale XY baselines. | @@ -152,6 +151,7 @@ our output in AutoCAD black-box. | 2026-10-20 | minor | DIMENSION: the `*D` block's MTEXT, and the MTEXT EXPLODE leaves, hold the diameter sign as `%%c` instead of the decoded U+2300, which no SHX font has, so other programs plotted diameter dimensions in an SHX style without the sign (#1645) | | 2026-10-21 | minor | Proxy objects and entities keep their class through a save: group 91 renumbered to the written CLASSES (the class it names is kept), a proxy whose number names no class dropped (#1812) | | 2026-10-17 | minor | DWG read: DGN line style components no line style definition reaches are left out before the DXF bridge, with a read note; an 83 MB site plan with 888,483 of them (1.2 GB of DXF, over the limit) now opens (#1482) | +| 2026-11-03 | minor | View twist (group 51) read and written for each tiled viewport (VPORT) and each layout viewport (VIEWPORT); named views' twist (VIEW group 50) now applied on Restore; a twisted view's centre (VIEWPORT and VPORT group 12, VIEW group 10) is read and written in display coordinates, turned by the twist | | 2026-10-12 | minor | PDF output: object transparency plotted as PDF alpha (`/ExtGState` `/ca` `/CA`) when the page setup's or the plot's "Plot transparency" is on; PNG plots blend it, SVG uses `opacity`; plots without it are unchanged byte for byte | | 2026-10-12 | minor | DXF/DWG save: the Model layout's plot settings are written as CADCraft plots model space, drawing extents scaled to fit (PLOTSETTINGS 74 = 1, 75 = 0), instead of plot type 5 "Layout information", which other programs' Plot dialogs can't use for model space | | 2026-10-12 | minor | VIEWPORT frozen layers also written and read as AutoCAD's group 341 layer handles, so third-party viewers honour per-viewport freezing in DXF (DWG converter gap noted) | From 0bd4d54f4ad3c31fa7bd5dcd4eae9f9efdb9e030 Mon Sep 17 00:00:00 2001 From: okereke-dev <293682657+okereke-dev@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:02:24 -0500 Subject: [PATCH 03/19] HATCHGENERATEBOUNDARY: Generate Boundary in the right-click menu of a hatch (#2801) A closed polyline around every boundary loop (outer and islands) of the selected hatches, which stay as they are: an associative hatch keeps its own boundary objects and is not linked to the new polylines. Runs at once on a pickfirst selection, otherwise asks for objects; one undo step. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/hatch.rs | 5 + crates/engine/src/cmd/hatch/edit.rs | 36 ++++- .../tests/it/hatch_generate_boundary.rs | 124 ++++++++++++++++++ crates/engine/tests/it/main.rs | 1 + crates/ui-egui/src/context_menu.rs | 6 +- crates/ui-egui/src/i18n/es.tsv | 1 + crates/ui-egui/src/i18n/zh.tsv | 1 + 7 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 crates/engine/tests/it/hatch_generate_boundary.rs diff --git a/crates/engine/src/cmd/hatch.rs b/crates/engine/src/cmd/hatch.rs index a362a3502..2402823a6 100644 --- a/crates/engine/src/cmd/hatch.rs +++ b/crates/engine/src/cmd/hatch.rs @@ -1,4 +1,5 @@ //! HATCH, GRADIENT, BOUNDARY, REGION: boundaries from pick points or selected closed objects. +//! HATCHGENERATEBOUNDARY: polylines around existing hatches. mod patfile; pub use patfile::{PatternChoice, pattern_choices}; @@ -10,6 +11,7 @@ use cadcraft_geom::{Bounds2, PolyVertex, Polyline, Vec2, point_in_polygon}; use serde_json::{Value, json}; use super::helpers::lwpoly; +use super::machines::SelectRun; use super::{CommandSpec, bad, bool_or, f64_or, point_param, points_param, size_param, str_param, targets}; use crate::{Accept, EngineError, Input, Interactive, Picker, Prompt, Result, Session, Step}; @@ -29,6 +31,9 @@ pub fn specs() -> Vec { CommandSpec::new("boundary", "Boundary...", run_boundary).menu(&["Draw", "Boundary..."]).alias(&["bo", "bpoly"]).params("{points: [[x,y]]}").interactive(|_| Ok(Box::new(BoundaryM { region: false }))), CommandSpec::new("region", "Region", run_region).menu(&["Draw", "Region"]).alias(&["reg"]).params("{handles?}"), CommandSpec::new("hatchedit", "Hatch Edit", edit::run_hatchedit).menu(&["Modify", "Object", "Hatch..."]).alias(&["he", "-hatchedit"]).params("{handles?, pattern?, scale?, angle?, gradient?: {name?, color1?, color2?, angle? (degrees), centered?} (makes or changes a gradient fill; `pattern` turns it back), associative?: bool (false unlinks; true links each loop to a closed object of the same shape, or to `boundary` objects), boundary?: [hex], addPoints?: [[x,y]], addBoundary?: [hex], removeLoops?: [zero-based index] (geometry edits require one hatch), style?, origin? | originMode?, separate?: true, recreate?: \"polyline\"|\"region\", associate?: bool (link to the recreated boundary)}").interactive(|s| Ok(Box::new(edit::HatchEditM::new(s)))), + CommandSpec::new("hatchgenerateboundary", "Generate Boundary", edit::run_hatchgenerateboundary) + .params("{handles?} (a closed polyline around each boundary loop of the hatches, which stay as they are) → handles") + .interactive(|_| Ok(Box::new(SelectRun::new("hatchgenerateboundary", "HATCHGENERATEBOUNDARY")))), CommandSpec::new("hatchpick", "Hatch Pick", pick::run_hatchpick) .params("{points?: [[x,y]] (internal points), handles?: [hex] (closed objects)} (typed: Points, Objects, oRigin or Hatch, then the picks): the Hatch and Gradient dialog's picks, kept in the session; changes nothing") .enabled(has_doc) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index c0f5c7440..49ddaf3b2 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -20,15 +20,49 @@ const MAX_EDITED: usize = 10_000; const MAX_LOOPS: usize = 2000; fn hatches(s: &Session, p: &Value) -> Result> { + hatches_for(s, p, "hatchedit") +} + +/// The hatches among the targets of command `cmd` (an error names `cmd` when there are none). +fn hatches_for(s: &Session, p: &Value, cmd: &str) -> Result> { let hs = targets(s, p)?; let d = s.doc()?; let out: Vec = hs.into_iter().filter(|h| matches!(d.entity(*h).map(|e| &e.kind), Some(EntityKind::Hatch(_)))).take(MAX_EDITED).collect(); if out.is_empty() { - return Err(bad("hatchedit", "select one or more hatches")); + return Err(bad(cmd, "select one or more hatches")); } Ok(out) } +/// Most polylines one HATCHGENERATEBOUNDARY call creates. +const MAX_GENERATED: usize = 10_000; + +/// HATCHGENERATEBOUNDARY: a closed polyline around every boundary loop (outer and islands) of +/// the selected hatches. The hatches are not changed: an associative hatch stays linked to its +/// own boundary objects and is not linked to the new polylines. +pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result { + let hs = hatches_for(s, p, "hatchgenerateboundary")?; + let mut loops = Vec::new(); + { + let d = s.doc()?; + for h in &hs { + if let Some(EntityKind::Hatch(x)) = d.entity(*h).map(|e| &e.kind) { + loops.extend(x.loops.iter().map(|l| l.vertices.clone())); + } + } + } + // Refused before anything is added, so a refused call leaves no partial result behind. + if loops.len() > MAX_GENERATED { + return Err(bad("hatchgenerateboundary", format!("more than {MAX_GENERATED} boundary polylines in one call; select fewer hatches"))); + } + let mut created = Vec::new(); + for vs in loops { + created.push(s.add_entity(lwpoly(vs, true))?.hex()); + } + let n = created.len(); + Ok(json!({ "handles": created, "message": format!("{n} boundary polyline(s) created.") })) +} + fn outline(l: &HatchLoop) -> Vec { Polyline { vertices: l.vertices.clone(), closed: true }.tessellate(1e-3) } diff --git a/crates/engine/tests/it/hatch_generate_boundary.rs b/crates/engine/tests/it/hatch_generate_boundary.rs new file mode 100644 index 000000000..030f35031 --- /dev/null +++ b/crates/engine/tests/it/hatch_generate_boundary.rs @@ -0,0 +1,124 @@ +//! HATCHGENERATEBOUNDARY (#2801): closed polylines around existing hatches, which stay as they are. + +use cadcraft_engine::doc::{EntityKind, Handle, Hatch, LwPolyline}; +use cadcraft_engine::{Input, Session}; +use serde_json::{Value, json}; + +fn hatch(s: &Session, h: &str) -> Hatch { + match &s.doc().unwrap().entity(Handle::parse_hex(h).unwrap()).unwrap().kind { + EntityKind::Hatch(x) => x.clone(), + k => panic!("not a hatch: {k:?}"), + } +} + +fn poly(s: &Session, h: &str) -> LwPolyline { + match &s.doc().unwrap().entity(Handle::parse_hex(h).unwrap()).unwrap().kind { + EntityKind::LwPolyline(p) => p.clone(), + k => panic!("not a polyline: {k:?}"), + } +} + +fn handle(v: &Value) -> String { + v["handle"].as_str().unwrap().to_string() +} + +fn handles(v: &Value) -> Vec { + v["handles"].as_array().unwrap().iter().map(|h| h.as_str().unwrap().to_string()).collect() +} + +fn rect(s: &mut Session, a: [f64; 2], b: [f64; 2]) -> String { + handle(&s.execute("rectang", &json!({ "p1": a, "p2": b })).unwrap()) +} + +fn count(s: &Session) -> usize { + s.doc().unwrap().model.iter().count() +} + +#[test] +fn generates_a_closed_polyline_around_a_hatch_without_its_outline() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r.clone()] })).unwrap()); + s.execute("erase", &json!({ "handles": [r] })).unwrap(); + let before = hatch(&s, &h); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [h.clone()] })).unwrap(); + let new = handles(&v); + assert_eq!(new.len(), 1); + let p = poly(&s, &new[0]); + assert!(p.closed); + assert_eq!(p.vertices, before.loops[0].vertices); + assert_eq!(hatch(&s, &h), before, "the hatch is not changed"); + s.execute("undo", &json!({})).unwrap(); + assert_eq!(count(&s), 1, "one undo step removes what was generated"); +} + +#[test] +fn islands_get_their_own_polylines() { + let mut s = Session::new(); + rect(&mut s, [0.0, 0.0], [20.0, 20.0]); + rect(&mut s, [5.0, 5.0], [10.0, 10.0]); + let h = handle(&s.execute("hatch", &json!({ "points": [[2, 2]] })).unwrap()); + assert_eq!(hatch(&s, &h).loops.len(), 2); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [h] })).unwrap(); + assert_eq!(handles(&v).len(), 2); +} + +#[test] +fn every_selected_hatch_gets_its_boundary() { + let mut s = Session::new(); + let a = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let b = rect(&mut s, [10.0, 0.0], [14.0, 2.0]); + let ha = handle(&s.execute("hatch", &json!({ "handles": [a] })).unwrap()); + let hb = handle(&s.execute("hatch", &json!({ "handles": [b] })).unwrap()); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [ha, hb] })).unwrap(); + assert_eq!(handles(&v).len(), 2); +} + +#[test] +fn an_associative_hatch_stays_linked_to_its_own_boundary() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r.clone()], "associative": true })).unwrap()); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [h.clone()] })).unwrap(); + let p = handles(&v)[0].clone(); + // Moving the generated polyline leaves the hatch where it is. + s.execute("move", &json!({ "handles": [p], "delta": [0, 10] })).unwrap(); + assert_eq!(hatch(&s, &h).loops[0].vertices[0].p.y, 0.0); + // Moving the original rectangle still moves the hatch. + s.execute("move", &json!({ "handles": [r], "delta": [10, 0] })).unwrap(); + assert!(hatch(&s, &h).associative); + assert_eq!(hatch(&s, &h).loops[0].vertices[0].p.x, 10.0); +} + +#[test] +fn needs_a_hatch() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + assert!(s.execute("hatchgenerateboundary", &json!({ "handles": [r] })).is_err()); + assert_eq!(count(&s), 1, "nothing is added"); +} + +#[test] +fn runs_at_once_on_selected_hatches() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + s.set_selection(vec![Handle::parse_hex(&h).unwrap()]); + s.start("hatchgenerateboundary").unwrap(); + assert!(s.current_prompt().is_none(), "a pickfirst selection needs no prompt"); + assert_eq!(count(&s), 3); +} + +#[test] +fn asks_for_hatches_without_a_selection() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + s.set_selection(Vec::new()); + s.start("hatchgenerateboundary").unwrap(); + assert!(s.current_prompt().is_some()); + s.input(Input::Pick(vec![Handle::parse_hex(&h).unwrap()])).unwrap(); + s.input(Input::Enter).unwrap(); + assert!(s.current_prompt().is_none()); + assert_eq!(count(&s), 3); +} diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index 3a1537bee..694633f92 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -58,6 +58,7 @@ mod group_selection; mod groups; mod hatch_assoc; mod hatch_dialog_helpers; +mod hatch_generate_boundary; mod hatch_numeric_validation; mod hatch_options; mod helix; diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs index bbaf48df3..e93f91494 100644 --- a/crates/ui-egui/src/context_menu.rs +++ b/crates/ui-egui/src/context_menu.rs @@ -122,8 +122,8 @@ pub fn entries(app: &CadApp) -> Vec> { } /// The edit commands of the selected objects' type (when they are all of one type), with their -/// labels: Edit Text for text, Block Editor and Edit Attributes for block references, Hatch Edit, -/// Polyline Edit, Spline Edit… +/// labels: Edit Text for text, Block Editor and Edit Attributes for block references, Hatch Edit +/// and Generate Boundary for hatches, Polyline Edit, Spline Edit… fn object_commands(app: &CadApp) -> Vec<(&'static str, Option<&'static str>)> { let Ok(d) = app.session.doc() else { return Vec::new() }; let sel = app.session.selection(); @@ -142,7 +142,7 @@ fn object_commands(app: &CadApp) -> Vec<(&'static str, Option<&'static str>)> { } v } - EntityKind::Hatch(_) => vec![("hatchedit", None)], + EntityKind::Hatch(_) => vec![("hatchedit", None), ("hatchgenerateboundary", None)], EntityKind::LwPolyline(_) | EntityKind::Polyline3d(_) => vec![("pedit", Some("Polyline Edit"))], EntityKind::Spline(_) => vec![("splinedit", Some("Spline Edit"))], EntityKind::Dimension(_) => vec![("dimtedit", None)], diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index f0e6471ee..b2d44f309 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -372,6 +372,7 @@ From Desde From Template... Desde plantilla... General General + Generate Boundary Generar contorno Geometric Center Centro geométrico Geometric Constraint Restricción geométrica Geometric Constraints Restricciones geométricas diff --git a/crates/ui-egui/src/i18n/zh.tsv b/crates/ui-egui/src/i18n/zh.tsv index a07b4f027..ed4b9c6b4 100644 --- a/crates/ui-egui/src/i18n/zh.tsv +++ b/crates/ui-egui/src/i18n/zh.tsv @@ -294,6 +294,7 @@ Freeze/Thaw in the current viewport 在当前视口中冻结/解冻 From 自 General 常规 + Generate Boundary 生成边界 Geometric Center 几何中心 Geometric Constraint 几何约束 Geometric Constraints 几何约束 From f7c4c148a3a9287761ed59aa6b93bfb823d66062 Mon Sep 17 00:00:00 2001 From: okereke-dev <293682657+okereke-dev@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:25:18 -0500 Subject: [PATCH 04/19] HATCHGENERATEBOUNDARY: keep the hatch elevation, refuse other spaces and over-limit calls (CodeRabbit on #2804) Each polyline takes its hatch's elevation; a hatch outside the current space is refused with a clear message; every selected hatch counts toward the 10,000-polyline limit, refused before anything is added. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/hatch/edit.rs | 43 +++++++++------- .../tests/it/hatch_generate_boundary.rs | 49 +++++++++++++++++++ 2 files changed, 75 insertions(+), 17 deletions(-) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index 49ddaf3b2..00725df0c 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -20,16 +20,11 @@ const MAX_EDITED: usize = 10_000; const MAX_LOOPS: usize = 2000; fn hatches(s: &Session, p: &Value) -> Result> { - hatches_for(s, p, "hatchedit") -} - -/// The hatches among the targets of command `cmd` (an error names `cmd` when there are none). -fn hatches_for(s: &Session, p: &Value, cmd: &str) -> Result> { let hs = targets(s, p)?; let d = s.doc()?; let out: Vec = hs.into_iter().filter(|h| matches!(d.entity(*h).map(|e| &e.kind), Some(EntityKind::Hatch(_)))).take(MAX_EDITED).collect(); if out.is_empty() { - return Err(bad(cmd, "select one or more hatches")); + return Err(bad("hatchedit", "select one or more hatches")); } Ok(out) } @@ -38,26 +33,40 @@ fn hatches_for(s: &Session, p: &Value, cmd: &str) -> Result> { const MAX_GENERATED: usize = 10_000; /// HATCHGENERATEBOUNDARY: a closed polyline around every boundary loop (outer and islands) of -/// the selected hatches. The hatches are not changed: an associative hatch stays linked to its -/// own boundary objects and is not linked to the new polylines. +/// the selected hatches, at each hatch's elevation. The hatches are not changed: an associative +/// hatch stays linked to its own boundary objects and is not linked to the new polylines. pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result { - let hs = hatches_for(s, p, "hatchgenerateboundary")?; + let selected = targets(s, p)?; + // The polylines go to the current space, so every hatch must be there too. + let space = s.space(); let mut loops = Vec::new(); + let mut found = false; { let d = s.doc()?; - for h in &hs { - if let Some(EntityKind::Hatch(x)) = d.entity(*h).map(|e| &e.kind) { - loops.extend(x.loops.iter().map(|l| l.vertices.clone())); + for h in selected { + let Some(EntityKind::Hatch(x)) = d.entity(h).map(|e| &e.kind) else { continue }; + found = true; + if d.space_of(h).as_ref() != Some(&space) { + return Err(bad("hatchgenerateboundary", format!("hatch {} is not in the current space; switch to its layout first", h.hex()))); } + // Every selected hatch counts: none is left out of a call that succeeds. + if loops.len() + x.loops.len() > MAX_GENERATED { + return Err(bad("hatchgenerateboundary", format!("more than {MAX_GENERATED} boundary polylines in one call; select fewer hatches"))); + } + loops.extend(x.loops.iter().map(|l| (l.vertices.clone(), x.elevation))); } } - // Refused before anything is added, so a refused call leaves no partial result behind. - if loops.len() > MAX_GENERATED { - return Err(bad("hatchgenerateboundary", format!("more than {MAX_GENERATED} boundary polylines in one call; select fewer hatches"))); + if !found { + return Err(bad("hatchgenerateboundary", "select one or more hatches")); } + // Everything is checked before anything is added, so a refused call leaves nothing behind. let mut created = Vec::new(); - for vs in loops { - created.push(s.add_entity(lwpoly(vs, true))?.hex()); + for (vs, elevation) in loops { + let mut kind = lwpoly(vs, true); + if let EntityKind::LwPolyline(pl) = &mut kind { + pl.elevation = elevation; + } + created.push(s.add_entity(kind)?.hex()); } let n = created.len(); Ok(json!({ "handles": created, "message": format!("{n} boundary polyline(s) created.") })) diff --git a/crates/engine/tests/it/hatch_generate_boundary.rs b/crates/engine/tests/it/hatch_generate_boundary.rs index 030f35031..07d1d5443 100644 --- a/crates/engine/tests/it/hatch_generate_boundary.rs +++ b/crates/engine/tests/it/hatch_generate_boundary.rs @@ -90,6 +90,55 @@ fn an_associative_hatch_stays_linked_to_its_own_boundary() { assert_eq!(hatch(&s, &h).loops[0].vertices[0].p.x, 10.0); } +#[test] +fn boundaries_keep_the_hatch_elevation() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + s.doc_mut() + .unwrap() + .modify_entity(Handle::parse_hex(&h).unwrap(), |e| { + if let EntityKind::Hatch(x) = &mut e.kind { + x.elevation = 300.0; + } + }) + .unwrap(); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [h] })).unwrap(); + assert_eq!(poly(&s, &handles(&v)[0]).elevation, 300.0); +} + +#[test] +fn refuses_a_hatch_in_another_space_and_adds_nothing() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + s.execute("layout.set", &json!({ "name": "Layout1" })).unwrap(); + let before = s.doc().unwrap().entity_count(); + let e = s.execute("hatchgenerateboundary", &json!({ "handles": [h] })).unwrap_err(); + assert!(e.to_string().contains("not in the current space"), "{e}"); + assert_eq!(s.doc().unwrap().entity_count(), before); +} + +#[test] +fn refuses_more_boundaries_than_the_limit_and_adds_nothing() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + // One hatch with more loops than one call may turn into polylines. + s.doc_mut() + .unwrap() + .modify_entity(Handle::parse_hex(&h).unwrap(), |e| { + if let EntityKind::Hatch(x) = &mut e.kind { + let l = x.loops[0].clone(); + x.loops = vec![l; 10_001]; + } + }) + .unwrap(); + let before = count(&s); + assert!(s.execute("hatchgenerateboundary", &json!({ "handles": [h] })).is_err()); + assert_eq!(count(&s), before); +} + #[test] fn needs_a_hatch() { let mut s = Session::new(); From 6412e9c99a0aea028dd2281fae5d10c05e7cb282 Mon Sep 17 00:00:00 2001 From: okereke-dev <293682657+okereke-dev@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:36:46 -0500 Subject: [PATCH 05/19] HATCHGENERATEBOUNDARY: a hatch named twice gets one boundary (CodeRabbit on #2804) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/hatch/edit.rs | 5 +++++ crates/engine/tests/it/hatch_generate_boundary.rs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index 00725df0c..884ce9fbb 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -41,10 +41,15 @@ pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result Date: Wed, 4 Nov 2026 21:53:26 -0500 Subject: [PATCH 06/19] HATCHGENERATEBOUNDARY: compare the loop count with the room left, so it can't overflow (CodeRabbit on #2804) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/hatch/edit.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index 884ce9fbb..854c80513 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -54,8 +54,9 @@ pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result MAX_GENERATED { + // Every selected hatch counts: none is left out of a call that succeeds. Compared + // against the room left, so a hostile loop count can't overflow the sum. + if x.loops.len() > MAX_GENERATED.saturating_sub(loops.len()) { return Err(bad("hatchgenerateboundary", format!("more than {MAX_GENERATED} boundary polylines in one call; select fewer hatches"))); } loops.extend(x.loops.iter().map(|l| (l.vertices.clone(), x.elevation))); From 275f989aa53f94734d5b50a735ef31a800e6d6bb Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Sat, 7 Nov 2026 20:30:03 +0700 Subject: [PATCH 07/19] DXF: mirrored objects keep their world height and extrusion side The reader keeps a mirrored object's normal (0,0,-1) but brings its points into world coordinates; a polyline's or hatch's elevation stays along the normal. The writer writes these objects with no normal, along +Z, so a mirrored polyline or hatch at elevation 5 (world Z -5) came back at Z +5, and a mirrored circle, arc, point, solid or text extruded up instead of down. Their elevation and thickness are now written along +Z too: negated when the normal points down Z. LINE writes its normal and keeps its thickness as read. Measured in AutoCAD 2024 (AutoCAD's objects, converted by CADCraft, reopened in AutoCAD): every world point and thickness top now matches the original. Co-Authored-By: Claude Opus 5.5 --- crates/io/src/dxf_write/entity.rs | 25 ++++++++---- crates/io/src/tests.rs | 63 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/crates/io/src/dxf_write/entity.rs b/crates/io/src/dxf_write/entity.rs index 5d759e223..b9f2c9259 100644 --- a/crates/io/src/dxf_write/entity.rs +++ b/crates/io/src/dxf_write/entity.rs @@ -108,7 +108,10 @@ fn write_basic_entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bo EntityKind::Line(l) => { w.s(0, "LINE"); common(w, e, owner, paper, "AcDbLine"); - thickness(w, e); + // Along the normal written with it (210 below), as read. + if e.common.thickness != 0.0 { + w.f(39, e.common.thickness); + } w.p(10, l.a); w.p(11, l.b); extrusion(w, e); @@ -156,8 +159,11 @@ fn write_basic_entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bo if p.const_width > 0.0 { w.f(43, p.const_width); } - if p.elevation != 0.0 { - w.f(38, p.elevation); + // The elevation runs along the polyline's normal, which isn't written: one facing down + // Z is at the elevation's negative. + let elevation = if e.common.extrusion.z < 0.0 { -p.elevation } else { p.elevation }; + if elevation != 0.0 { + w.f(38, elevation); } thickness(w, e); for v in &p.vertices { @@ -607,7 +613,9 @@ fn write_hatch_entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bo if let EntityKind::Hatch(h) = &e.kind { w.s(0, "HATCH"); common(w, e, owner, paper, "AcDbHatch"); - w.p(10, Vec3::new(0.0, 0.0, h.elevation)); + // Its elevation runs along its normal, written as Z: one facing down is at the negative. + let elevation = if e.common.extrusion.z < 0.0 { -h.elevation } else { h.elevation }; + w.p(10, Vec3::new(0.0, 0.0, elevation)); w.p(210, Vec3::Z); w.s(2, &h.pattern); w.i(70, i64::from(h.solid)); @@ -826,10 +834,13 @@ fn gradient(w: &mut W, g: &Gradient) { w.s(1000, g.color2.name()); } -/// Group 39 (thickness) of the entities whose DXF Reference record has one; only when set. +/// Group 39 (thickness) of the entities whose DXF Reference record has one; only when set. They +/// are written with no normal, so they extrude along Z: one whose normal points down Z extrudes +/// the other way, and its thickness changes sign. fn thickness(w: &mut W, e: &Entity) { - if e.common.thickness != 0.0 { - w.f(39, e.common.thickness); + let t = if e.common.extrusion.z < 0.0 { -e.common.thickness } else { e.common.thickness }; + if t != 0.0 { + w.f(39, t); } } diff --git a/crates/io/src/tests.rs b/crates/io/src/tests.rs index 0a10424bc..15c19ffa2 100644 --- a/crates/io/src/tests.rs +++ b/crates/io/src/tests.rs @@ -2599,6 +2599,69 @@ fn mirrored_2d_polyline_extrusion_flips_x_and_bulge() { assert_eq!(got, vec![(-1.0, 0.0, -1.0), (-3.0, 0.0, 0.0)]); } +/// Objects whose normal is 0,0,-1, at OCS height 5 and most of them 2 thick, keep their world height +/// and the side they extrude to through a save. They are written with no normal (along Z), so an +/// elevation or a thickness written as read put a polyline or a hatch at Z +5 instead of -5, and +/// extruded a circle, point, solid or text up instead of down (AutoCAD 2024 opening the saved file, +/// measured). A line writes its normal, and keeps its thickness as read. +#[test] +fn mirrored_objects_keep_their_world_height_and_thickness_side() { + let down = "210\n0\n220\n0\n230\n-1\n"; + let text = format!( + "0\nSECTION\n2\nENTITIES\n\ + 0\nLWPOLYLINE\n8\n0\n90\n2\n70\n0\n38\n5\n39\n2\n{down}10\n0\n20\n0\n42\n0.5\n10\n-10\n20\n0\n\ + 0\nPOLYLINE\n8\n0\n66\n1\n70\n0\n10\n0\n20\n0\n30\n5\n{down}0\nVERTEX\n8\n0\n10\n0\n20\n10\n0\nVERTEX\n8\n0\n10\n-10\n20\n10\n0\nSEQEND\n\ + 0\nCIRCLE\n8\n0\n10\n-10\n20\n5\n30\n5\n40\n5\n39\n2\n{down}\ + 0\nARC\n8\n0\n10\n-30\n20\n5\n30\n5\n40\n5\n50\n180\n51\n270\n{down}\ + 0\nPOINT\n8\n0\n10\n-40\n20\n0\n30\n5\n39\n2\n{down}\ + 0\nSOLID\n8\n0\n10\n50\n20\n0\n30\n5\n11\n60\n21\n0\n31\n5\n12\n50\n22\n5\n32\n5\n13\n60\n23\n5\n33\n5\n39\n2\n{down}\ + 0\nHATCH\n8\n0\n10\n0\n20\n0\n30\n5\n{down}2\nSOLID\n70\n1\n71\n0\n91\n1\n92\n2\n72\n0\n73\n1\n93\n4\n\ + 10\n70\n20\n0\n10\n80\n20\n0\n10\n80\n20\n5\n10\n70\n20\n5\n97\n0\n75\n0\n76\n1\n98\n0\n\ + 0\nTEXT\n8\n0\n10\n-90\n20\n0\n30\n5\n40\n2\n1\nA\n39\n2\n{down}\ + 0\nLINE\n8\n0\n39\n2\n10\n0\n20\n20\n30\n3\n11\n10\n21\n20\n31\n3\n{down}\ + 0\nENDSEC\n0\nEOF\n" + ); + // Each object's kind, world height and thickness along world Z. + let place = |d: &Drawing| -> Vec<(&'static str, f64, f64)> { + d.model + .iter() + .map(|e| { + let n = e.common.extrusion.z.signum(); + let (kind, z) = match &e.kind { + EntityKind::LwPolyline(p) => ("polyline", n * p.elevation), + EntityKind::Circle(c) => ("circle", c.center.z), + EntityKind::Arc(a) => ("arc", a.center.z), + EntityKind::Point(p) => ("point", p.p.z), + EntityKind::Solid(s) => ("solid", s.corners[0].z), + EntityKind::Hatch(h) => ("hatch", n * h.elevation), + EntityKind::Text(t) => ("text", t.insert.z), + EntityKind::Line(l) => ("line", l.a.z), + _ => ("other", f64::NAN), + }; + (kind, z, n * e.common.thickness) + }) + .collect() + }; + let d = read(text.as_bytes(), "m.dxf").unwrap(); + let want = vec![ + ("polyline", -5.0, -2.0), + ("polyline", -5.0, 0.0), + ("circle", -5.0, -2.0), + ("arc", -5.0, 0.0), + ("point", 5.0, -2.0), + ("solid", -5.0, -2.0), + ("hatch", -5.0, 0.0), + ("text", -5.0, -2.0), + ("line", 3.0, -2.0), + ]; + assert_eq!(place(&d), want, "as read"); + let out = write(&d, "m.dxf").unwrap(); + assert_eq!(place(&read(&out, "m.dxf").unwrap()), want, "after a save"); + let pairs = dxf_pairs(std::str::from_utf8(&out).unwrap()); + let line = dxf_records(&pairs, "LINE")[0]; + assert_eq!((group(line, "39"), group(line, "230")), (Some("2.0"), Some("-1.0")), "{line:?}"); +} + #[test] fn mirrored_hatch_extrusion_flips_boundary() { // HATCH boundaries are OCS: the square (1,0)..(3,2) under extrusion (0,0,-1) lies at (-3,0)..(-1,2). From 48bcb817edb3b43f6c704d2207b5dd848c0ec8b7 Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:04:50 +0700 Subject: [PATCH 08/19] DXF writer: say the mirrored flips are exact for 0,0,-1 only The elevation and thickness flips are exact for a normal of 0,0,-1; a tilted normal pointing partly down is flipped the same way, an approximation. The comments now say so (CodeRabbit's note on #2905). Co-Authored-By: Claude Opus 5.5 --- crates/io/src/dxf_write/entity.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/io/src/dxf_write/entity.rs b/crates/io/src/dxf_write/entity.rs index b9f2c9259..b965a5058 100644 --- a/crates/io/src/dxf_write/entity.rs +++ b/crates/io/src/dxf_write/entity.rs @@ -160,7 +160,9 @@ fn write_basic_entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bo w.f(43, p.const_width); } // The elevation runs along the polyline's normal, which isn't written: one facing down - // Z is at the elevation's negative. + // Z is at the elevation's negative. That is exact for a normal of 0,0,-1 only; a tilted + // one pointing partly down is flipped the same way (the reader brings tilted polylines + // into plan with normal Z, so only other sources make one). let elevation = if e.common.extrusion.z < 0.0 { -p.elevation } else { p.elevation }; if elevation != 0.0 { w.f(38, elevation); @@ -614,6 +616,7 @@ fn write_hatch_entity(w: &mut W, d: &Drawing, e: &Entity, owner: &str, paper: bo w.s(0, "HATCH"); common(w, e, owner, paper, "AcDbHatch"); // Its elevation runs along its normal, written as Z: one facing down is at the negative. + // Exact for a normal of 0,0,-1; the reader brings a tilted hatch into plan with normal Z. let elevation = if e.common.extrusion.z < 0.0 { -h.elevation } else { h.elevation }; w.p(10, Vec3::new(0.0, 0.0, elevation)); w.p(210, Vec3::Z); @@ -836,7 +839,8 @@ fn gradient(w: &mut W, g: &Gradient) { /// Group 39 (thickness) of the entities whose DXF Reference record has one; only when set. They /// are written with no normal, so they extrude along Z: one whose normal points down Z extrudes -/// the other way, and its thickness changes sign. +/// the other way, and its thickness changes sign. That is exact for a normal of 0,0,-1; a tilted +/// one pointing partly down only gets the closer of the two directions. fn thickness(w: &mut W, e: &Entity) { let t = if e.common.extrusion.z < 0.0 { -e.common.thickness } else { e.common.thickness }; if t != 0.0 { From b325046f766e2328b80d0959c78b7f95847b8a38 Mon Sep 17 00:00:00 2001 From: mkzung <103102868+mkzung@users.noreply.github.com> Date: Sat, 7 Nov 2026 23:32:34 +0000 Subject: [PATCH 09/19] DXF/DWG: a file's registered applications are kept when no xdata names them The writer rebuilt the APPID table only from the applications whose xdata the drawing still had, so every other registered application of the file was dropped at each save. The reader now keeps the names of all of the file's APPID records, and the writer adds them to the table with the ones in use. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H43qQA41CJLauqXnPgBQ7r --- crates/doc/src/foreign.rs | 4 ++ crates/io/src/dxf_raw.rs | 15 ++-- .../io/tests/registered_applications_kept.rs | 72 +++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 crates/io/tests/registered_applications_kept.rs diff --git a/crates/doc/src/foreign.rs b/crates/doc/src/foreign.rs index 319478cd9..fbe14befa 100644 --- a/crates/doc/src/foreign.rs +++ b/crates/doc/src/foreign.rs @@ -79,6 +79,9 @@ pub struct Foreign { /// The drawing's own `$ACADVER` is the version it is saved as, which SAVEAS changes, so a /// later save must not take it for this one (#2471). pub version: Option, + /// The file's registered applications (APPID names as read, in file order). Saving writes + /// them all back, whether or not any xdata still names them. + pub appids: Vec, } impl Foreign { @@ -97,6 +100,7 @@ impl Foreign { && self.targets.is_empty() && self.class_order.is_empty() && self.data_store.is_empty() + && self.appids.is_empty() } /// The entities with a geometry record in the data store: an `ACDSRECORD` naming the entity diff --git a/crates/io/src/dxf_raw.rs b/crates/io/src/dxf_raw.rs index 3be39aa5b..0d1014d02 100644 --- a/crates/io/src/dxf_raw.rs +++ b/crates/io/src/dxf_raw.rs @@ -348,7 +348,8 @@ pub(crate) fn read(secs: &[Section], d: &mut Drawing) { !by_handle.contains_key(&o) && xdict_of.get(&o) == Some(&h) && (ents.contains_key(&o) || ids.contains_key(&o)) }; let memo = retained_objects(&objects, &ents, &ids, &by_handle, root.as_deref(), &root_entries, &xdict_of); - let mut f = Foreign::default(); + let appids = tables.iter().filter(|(k, _, _)| k == "APPID").filter_map(|(_, _, t)| val(t, 2)).map(|n| n.trim().to_string()); + let mut f = Foreign { appids: appids.take(MAX_OBJECTS).collect(), ..Foreign::default() }; let mut kept: HashSet = HashSet::new(); for (i, (kind, _, t)) in objects.iter().enumerate() { if memo.get(&i) != Some(&true) || f.objects.len() >= MAX_OBJECTS { @@ -991,7 +992,7 @@ pub(crate) fn finish(tags: &mut Vec, d: &Drawing, reactors: &HashMap, out: &mut Vec) } } -/// APPID records for every application with xdata in the file, added to the APPID table. -fn add_appids(out: &mut Vec) { - let used: BTreeMap = out.iter().filter(|t| t.code == 1001).map(|t| (up(&t.str()), t.str().trim().to_string())).collect(); +/// APPID records for every application with xdata in the file and every one the file read had +/// (`kept`), added to the APPID table. +fn add_appids(out: &mut Vec, kept: &[String]) { + let mut used: BTreeMap = out.iter().filter(|t| t.code == 1001).map(|t| (up(&t.str()), t.str().trim().to_string())).collect(); + for name in kept.iter().filter(|n| !n.is_empty()) { + used.entry(up(name)).or_insert_with(|| name.clone()); + } let recs = written_records(out); let Some(table) = recs.iter().position(|r| { r.sec == "TABLES" && r.kind == "TABLE" && val(out.get(r.start + 1..r.end).unwrap_or(&[]), 2).is_some_and(|n| up(&n) == "APPID") diff --git a/crates/io/tests/registered_applications_kept.rs b/crates/io/tests/registered_applications_kept.rs new file mode 100644 index 000000000..09da3b45d --- /dev/null +++ b/crates/io/tests/registered_applications_kept.rs @@ -0,0 +1,72 @@ +//! The registered applications (APPID) of a file are saved back, in DXF and in DWG, save after +//! save, also those no xdata names. + +use cadcraft_doc::Drawing; +use cadcraft_io::{read, read_dxf, write, write_dxf}; + +/// The records of a DXF: each `(code, value)` from its `0` group on. +fn records(text: &str) -> Vec> { + let lines: Vec<&str> = text.lines().collect(); + let mut out: Vec> = Vec::new(); + for chunk in lines.chunks(2) { + let [code, value] = chunk else { break }; + let Ok(c) = code.trim().parse::() else { continue }; + let pair = (c, value.trim().to_string()); + if c == 0 { + out.push(vec![pair]); + } else if let Some(r) = out.last_mut() { + r.push(pair); + } + } + out +} + +fn value(r: &[(i32, String)], code: i32) -> Option<&str> { + r.iter().find(|(c, _)| *c == code).map(|(_, v)| v.as_str()) +} + +/// A file whose APPID table has `Other_App` (handle 7A00), which no xdata names. +fn source() -> String { + let mut out = String::new(); + let mut put = |c: i32, v: &str| out.push_str(&format!("{c:>3}\n{v}\n")); + for r in records(&write_dxf(&Drawing::new_metric())) { + for (c, v) in &r { + put(*c, v); + } + if r[0].1 == "TABLE" && value(&r, 2) == Some("APPID") { + let table = value(&r, 5).unwrap_or("0").to_string(); + for (c, v) in [ + (0, "APPID"), + (5, "7A00"), + (330, table.as_str()), + (100, "AcDbSymbolTableRecord"), + (100, "AcDbRegAppTableRecord"), + (2, "Other_App"), + (70, "0"), + ] { + put(c, v); + } + } + } + out +} + +/// Whether the DXF has an APPID record named `Other_App`. +fn appid(text: &str) -> bool { + records(text).into_iter().any(|r| r[0].1 == "APPID" && value(&r, 2) == Some("Other_App")) +} + +#[test] +fn registered_applications_no_xdata_names_are_kept() { + let mut d = read_dxf(source().as_bytes()).expect("read"); + for generation in 1..=2 { + let text = write_dxf(&d); + assert!(appid(&text), "DXF {generation}"); + d = read_dxf(text.as_bytes()).expect("reread"); + } + for generation in 1..=2 { + let dwg = write(&d, "kept.dwg").expect("DWG"); + d = read(&dwg, "kept.dwg").expect("DWG read"); + assert!(appid(&write_dxf(&d)), "DWG {generation}"); + } +} From 18effe68b42e67602e71d6ceefed1dd6f114995d Mon Sep 17 00:00:00 2001 From: mkzung <103102868+mkzung@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:17:58 +0000 Subject: [PATCH 10/19] DXF/DWG: the registered applications test counts the records The test only checked that an `Other_App` record was there, so a second record for the same application would have passed. It now asks for exactly one, and a second test has a line's xdata name the application as `OTHER_APP` beside the registered `Other_App`: DXF and DWG, twice, keep the xdata and one APPID record. With `add_appids` keyed by the name as written instead of case-insensitively, that test fails (2 records). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01H43qQA41CJLauqXnPgBQ7r --- .../io/tests/registered_applications_kept.rs | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/crates/io/tests/registered_applications_kept.rs b/crates/io/tests/registered_applications_kept.rs index 09da3b45d..4c548700b 100644 --- a/crates/io/tests/registered_applications_kept.rs +++ b/crates/io/tests/registered_applications_kept.rs @@ -21,18 +21,39 @@ fn records(text: &str) -> Vec> { out } +/// The value of the record's first group `code`. fn value(r: &[(i32, String)], code: i32) -> Option<&str> { r.iter().find(|(c, _)| *c == code).map(|(_, v)| v.as_str()) } -/// A file whose APPID table has `Other_App` (handle 7A00), which no xdata names. -fn source() -> String { +/// A file whose APPID table has `Other_App` (handle 7A00), which no xdata names; with `xdata`, +/// a line's xdata names it as `OTHER_APP`. +fn source(xdata: bool) -> String { let mut out = String::new(); let mut put = |c: i32, v: &str| out.push_str(&format!("{c:>3}\n{v}\n")); for r in records(&write_dxf(&Drawing::new_metric())) { for (c, v) in &r { put(*c, v); } + if xdata && r[0].1 == "SECTION" && value(&r, 2) == Some("ENTITIES") { + for (c, v) in [ + (0, "LINE"), + (5, "7A01"), + (100, "AcDbEntity"), + (8, "0"), + (100, "AcDbLine"), + (10, "0"), + (20, "0"), + (30, "0"), + (11, "10"), + (21, "0"), + (31, "0"), + (1001, "OTHER_APP"), + (1000, "x"), + ] { + put(c, v); + } + } if r[0].1 == "TABLE" && value(&r, 2) == Some("APPID") { let table = value(&r, 5).unwrap_or("0").to_string(); for (c, v) in [ @@ -51,22 +72,39 @@ fn source() -> String { out } -/// Whether the DXF has an APPID record named `Other_App`. -fn appid(text: &str) -> bool { - records(text).into_iter().any(|r| r[0].1 == "APPID" && value(&r, 2) == Some("Other_App")) +/// How many APPID records of the DXF are named `Other_App`, in any case. +fn appids(text: &str) -> usize { + records(text).into_iter().filter(|r| r[0].1 == "APPID" && value(r, 2).is_some_and(|n| n.eq_ignore_ascii_case("Other_App"))).count() } #[test] fn registered_applications_no_xdata_names_are_kept() { - let mut d = read_dxf(source().as_bytes()).expect("read"); + let mut d = read_dxf(source(false).as_bytes()).expect("read"); for generation in 1..=2 { let text = write_dxf(&d); - assert!(appid(&text), "DXF {generation}"); + assert_eq!(appids(&text), 1, "DXF {generation}"); d = read_dxf(text.as_bytes()).expect("reread"); } for generation in 1..=2 { let dwg = write(&d, "kept.dwg").expect("DWG"); d = read(&dwg, "kept.dwg").expect("DWG read"); - assert!(appid(&write_dxf(&d)), "DWG {generation}"); + assert_eq!(appids(&write_dxf(&d)), 1, "DWG {generation}"); + } +} + +/// An application both registered and named by xdata, in another case, gets one record. +#[test] +fn a_registered_application_xdata_names_gets_one_record() { + let mut d = read_dxf(source(true).as_bytes()).expect("read"); + for generation in 1..=2 { + let text = write_dxf(&d); + assert!(text.contains("OTHER_APP"), "DXF {generation}: the line's xdata is kept"); + assert_eq!(appids(&text), 1, "DXF {generation}"); + d = read_dxf(text.as_bytes()).expect("reread"); + } + for generation in 1..=2 { + let dwg = write(&d, "kept.dwg").expect("DWG"); + d = read(&dwg, "kept.dwg").expect("DWG read"); + assert_eq!(appids(&write_dxf(&d)), 1, "DWG {generation}"); } } From 6ec0f2400ae5b03521bb1ea664872900d0072ffc Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:28:55 +0700 Subject: [PATCH 11/19] DXF test: the same objects facing up keep their height and thickness The mirrored-objects test only had objects whose normal is 0,0,-1, so a writer that flips the elevation and thickness of every object passed it. It now reads the same nine objects with no normal and with 0,0,1 as well: those keep +5 and +2 through a save, and their LINEs keep 39 = 2.0 with no 230. Co-Authored-By: Claude Opus 5.5 --- crates/io/src/tests.rs | 53 +++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/crates/io/src/tests.rs b/crates/io/src/tests.rs index 15c19ffa2..4e37f633f 100644 --- a/crates/io/src/tests.rs +++ b/crates/io/src/tests.rs @@ -2603,24 +2603,26 @@ fn mirrored_2d_polyline_extrusion_flips_x_and_bulge() { /// and the side they extrude to through a save. They are written with no normal (along Z), so an /// elevation or a thickness written as read put a polyline or a hatch at Z +5 instead of -5, and /// extruded a circle, point, solid or text up instead of down (AutoCAD 2024 opening the saved file, -/// measured). A line writes its normal, and keeps its thickness as read. +/// measured). A line writes its normal, and keeps its thickness as read. The same objects facing up +/// (no normal, and 0,0,1) keep +5 and +2: only a normal pointing down Z changes the sign. #[test] fn mirrored_objects_keep_their_world_height_and_thickness_side() { - let down = "210\n0\n220\n0\n230\n-1\n"; - let text = format!( - "0\nSECTION\n2\nENTITIES\n\ - 0\nLWPOLYLINE\n8\n0\n90\n2\n70\n0\n38\n5\n39\n2\n{down}10\n0\n20\n0\n42\n0.5\n10\n-10\n20\n0\n\ - 0\nPOLYLINE\n8\n0\n66\n1\n70\n0\n10\n0\n20\n0\n30\n5\n{down}0\nVERTEX\n8\n0\n10\n0\n20\n10\n0\nVERTEX\n8\n0\n10\n-10\n20\n10\n0\nSEQEND\n\ - 0\nCIRCLE\n8\n0\n10\n-10\n20\n5\n30\n5\n40\n5\n39\n2\n{down}\ - 0\nARC\n8\n0\n10\n-30\n20\n5\n30\n5\n40\n5\n50\n180\n51\n270\n{down}\ - 0\nPOINT\n8\n0\n10\n-40\n20\n0\n30\n5\n39\n2\n{down}\ - 0\nSOLID\n8\n0\n10\n50\n20\n0\n30\n5\n11\n60\n21\n0\n31\n5\n12\n50\n22\n5\n32\n5\n13\n60\n23\n5\n33\n5\n39\n2\n{down}\ - 0\nHATCH\n8\n0\n10\n0\n20\n0\n30\n5\n{down}2\nSOLID\n70\n1\n71\n0\n91\n1\n92\n2\n72\n0\n73\n1\n93\n4\n\ - 10\n70\n20\n0\n10\n80\n20\n0\n10\n80\n20\n5\n10\n70\n20\n5\n97\n0\n75\n0\n76\n1\n98\n0\n\ - 0\nTEXT\n8\n0\n10\n-90\n20\n0\n30\n5\n40\n2\n1\nA\n39\n2\n{down}\ - 0\nLINE\n8\n0\n39\n2\n10\n0\n20\n20\n30\n3\n11\n10\n21\n20\n31\n3\n{down}\ - 0\nENDSEC\n0\nEOF\n" - ); + let records = |normal: &str| { + format!( + "0\nLWPOLYLINE\n8\n0\n90\n2\n70\n0\n38\n5\n39\n2\n{normal}10\n0\n20\n0\n42\n0.5\n10\n-10\n20\n0\n\ + 0\nPOLYLINE\n8\n0\n66\n1\n70\n0\n10\n0\n20\n0\n30\n5\n{normal}0\nVERTEX\n8\n0\n10\n0\n20\n10\n0\nVERTEX\n8\n0\n10\n-10\n20\n10\n0\nSEQEND\n\ + 0\nCIRCLE\n8\n0\n10\n-10\n20\n5\n30\n5\n40\n5\n39\n2\n{normal}\ + 0\nARC\n8\n0\n10\n-30\n20\n5\n30\n5\n40\n5\n50\n180\n51\n270\n{normal}\ + 0\nPOINT\n8\n0\n10\n-40\n20\n0\n30\n5\n39\n2\n{normal}\ + 0\nSOLID\n8\n0\n10\n50\n20\n0\n30\n5\n11\n60\n21\n0\n31\n5\n12\n50\n22\n5\n32\n5\n13\n60\n23\n5\n33\n5\n39\n2\n{normal}\ + 0\nHATCH\n8\n0\n10\n0\n20\n0\n30\n5\n{normal}2\nSOLID\n70\n1\n71\n0\n91\n1\n92\n2\n72\n0\n73\n1\n93\n4\n\ + 10\n70\n20\n0\n10\n80\n20\n0\n10\n80\n20\n5\n10\n70\n20\n5\n97\n0\n75\n0\n76\n1\n98\n0\n\ + 0\nTEXT\n8\n0\n10\n-90\n20\n0\n30\n5\n40\n2\n1\nA\n39\n2\n{normal}\ + 0\nLINE\n8\n0\n39\n2\n10\n0\n20\n20\n30\n3\n11\n10\n21\n20\n31\n3\n{normal}" + ) + }; + let (down, up) = ("210\n0\n220\n0\n230\n-1\n", "210\n0\n220\n0\n230\n1\n"); + let text = format!("0\nSECTION\n2\nENTITIES\n{}{}{}0\nENDSEC\n0\nEOF\n", records(down), records(""), records(up)); // Each object's kind, world height and thickness along world Z. let place = |d: &Drawing| -> Vec<(&'static str, f64, f64)> { d.model @@ -2643,7 +2645,7 @@ fn mirrored_objects_keep_their_world_height_and_thickness_side() { .collect() }; let d = read(text.as_bytes(), "m.dxf").unwrap(); - let want = vec![ + let mut want = vec![ ("polyline", -5.0, -2.0), ("polyline", -5.0, 0.0), ("circle", -5.0, -2.0), @@ -2654,12 +2656,25 @@ fn mirrored_objects_keep_their_world_height_and_thickness_side() { ("text", -5.0, -2.0), ("line", 3.0, -2.0), ]; + let facing_up = [ + ("polyline", 5.0, 2.0), + ("polyline", 5.0, 0.0), + ("circle", 5.0, 2.0), + ("arc", 5.0, 0.0), + ("point", 5.0, 2.0), + ("solid", 5.0, 2.0), + ("hatch", 5.0, 0.0), + ("text", 5.0, 2.0), + ("line", 3.0, 2.0), + ]; + want.extend(facing_up); + want.extend(facing_up); assert_eq!(place(&d), want, "as read"); let out = write(&d, "m.dxf").unwrap(); assert_eq!(place(&read(&out, "m.dxf").unwrap()), want, "after a save"); let pairs = dxf_pairs(std::str::from_utf8(&out).unwrap()); - let line = dxf_records(&pairs, "LINE")[0]; - assert_eq!((group(line, "39"), group(line, "230")), (Some("2.0"), Some("-1.0")), "{line:?}"); + let lines: Vec<_> = dxf_records(&pairs, "LINE").into_iter().map(|l| (group(l, "39"), group(l, "230"))).collect(); + assert_eq!(lines, [(Some("2.0"), Some("-1.0")), (Some("2.0"), None), (Some("2.0"), None)]); } #[test] From 3ee12a8c626f4bbfd467dd8af5de9e39bc684a00 Mon Sep 17 00:00:00 2001 From: Ray <66087717+iHateStupidPeople@users.noreply.github.com> Date: Mon, 16 Nov 2026 21:18:35 -0700 Subject: [PATCH 12/19] Layouts: save the plot layout flags as read (#3227) The DXF writer, which also feeds the DWG bridge, built the layout's plot flags (AcDbPlotSettings group 70) from the bits CADCraft models and always set 512 (plot paper space last) and 32 (plot with plot styles), plus 16 for a standard scale. A layout read with flags 0 came back as 560. The page setup now keeps the flags as read; saving sets or clears only the bits the page models (2, 4, 128, and 16 when the scale decides it). Page setups made in CADCraft keep the old defaults. --- crates/doc/src/tables.rs | 7 +++ crates/io/src/dxf_read/objects.rs | 2 + crates/io/src/dxf_write/sections.rs | 24 ++++++--- crates/io/tests/it/layout_plot_flags.rs | 54 +++++++++++++++++++ crates/io/tests/it/main.rs | 1 + crates/io/tests/it/roundtrip/collections.rs | 2 +- .../io/tests/it/tables_objects_roundtrip.rs | 2 +- 7 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 crates/io/tests/it/layout_plot_flags.rs diff --git a/crates/doc/src/tables.rs b/crates/doc/src/tables.rs index 5707e0c90..dc16d65be 100644 --- a/crates/doc/src/tables.rs +++ b/crates/doc/src/tables.rs @@ -818,6 +818,12 @@ pub struct PageSetup { /// save keeps where the sheet sits; `None` for a page CADCraft made, written as 0,0 (#2109). #[serde(skip_serializing_if = "Option::is_none")] pub image_origin: Option, + /// The plot layout flags (DXF group 70 of AcDbPlotSettings) as the file had them. Saving keeps + /// the bits CADCraft doesn't model (plot paper space last, plot with plot styles, standard + /// scale and the rest) as read instead of forcing its defaults (#3227); `None` for page setups + /// made in CADCraft. + #[serde(skip)] + pub file_plot_flags: Option, } impl Default for PageSetup { @@ -841,6 +847,7 @@ impl Default for PageSetup { paper_mm: false, file_paper: None, image_origin: None, + file_plot_flags: None, } } } diff --git a/crates/io/src/dxf_read/objects.rs b/crates/io/src/dxf_read/objects.rs index 98cdf7d52..34e197a2f 100644 --- a/crates/io/src/dxf_read/objects.rs +++ b/crates/io/src/dxf_read/objects.rs @@ -267,6 +267,8 @@ pub(super) fn page_setup(t: &T) -> PageSetup { // Plot layout flags: 2 display plot styles, 4 centred, 16 standard scale (75 = 0: scaled // to fit), 128 lineweights. if let Some(flags) = t.i(70) { + // Kept to be written back (a 16-bit group: only those bits). + p.file_plot_flags = Some(flags & 0xFFFF); p.show_plot_styles = flags & 2 != 0; p.center = flags & 4 != 0; p.lineweights = flags & 128 != 0; diff --git a/crates/io/src/dxf_write/sections.rs b/crates/io/src/dxf_write/sections.rs index 24c877b72..79afc4b39 100644 --- a/crates/io/src/dxf_write/sections.rs +++ b/crates/io/src/dxf_write/sections.rs @@ -389,6 +389,23 @@ struct LayoutWriteData<'a> { limits: Option<(Vec2, Vec2)>, } +/// The plot layout flags (AcDbPlotSettings group 70) for `page`. The bits CADCraft models come +/// from the page: 2 display plot styles, 4 centred, 128 lineweights, and 16 standard scale where +/// the scale decides it (scaled to fit: set; a custom scale: clear). The rest are kept as the file +/// had them (#3227); a page CADCraft made gets 512 (plot paper space last) and 32 (plot with plot +/// styles), and 16 when its scale is standard. +fn plot_layout_flags(page: &PageSetup, standard: bool) -> i64 { + const MODELED: i64 = 2 | 4 | 128; + const STANDARD_SCALE: i64 = 16; + let kept = match page.file_plot_flags { + Some(f) if page.scale_to_fit => (f & !MODELED) | STANDARD_SCALE, + Some(f) if !standard => f & !MODELED & !STANDARD_SCALE, + Some(f) => f & !MODELED, + None => 512 | 32 | if standard { STANDARD_SCALE } else { 0 }, + }; + kept | if page.lineweights { 128 } else { 0 } | if page.center { 4 } else { 0 } | if page.show_plot_styles { 2 } else { 0 } +} + fn layout_obj(w: &mut W, context: LayoutWriteContext<'_>, data: LayoutWriteData<'_>) { let d = context.drawing; let layout_dict = context.dictionary; @@ -403,12 +420,7 @@ fn layout_obj(w: &mut W, context: LayoutWriteContext<'_>, data: LayoutWriteData< // per 143 drawing units). let scale = if page.scale.is_finite() && page.scale > 0.0 { page.scale } else { 1.0 }; let standard = page.scale_to_fit || scale == 1.0; - let plot_flags = 512 - | 32 - | if standard { 16 } else { 0 } - | if page.lineweights { 128 } else { 0 } - | if page.center { 4 } else { 0 } - | if page.show_plot_styles { 2 } else { 0 }; + let plot_flags = plot_layout_flags(page, standard); let plot_type = match page.plot_area.as_str() { "display" => 0, "extents" => 1, diff --git a/crates/io/tests/it/layout_plot_flags.rs b/crates/io/tests/it/layout_plot_flags.rs new file mode 100644 index 000000000..82cf1e433 --- /dev/null +++ b/crates/io/tests/it/layout_plot_flags.rs @@ -0,0 +1,54 @@ +//! #3227: saving kept the layout's plot flags only for the bits CADCraft models and forced 512 +//! (plot paper space last), 32 (plot with plot styles) and 16 (standard scale) on, so a layout +//! with flags 0 came back as 560, in DXF and in DWG. + +use cadcraft_doc::{Drawing, Layout, PageSetup}; +use cadcraft_io::{read, write}; + +/// A drawing with layout SHEET read with plot layout `flags` (lineweights, centring and display +/// plot styles follow them, as the reader sets them). +fn drawing(flags: i64) -> Drawing { + let mut d = Drawing::new_imperial(); + let mut l = Layout::new("SHEET", 1); + l.page = PageSetup { + lineweights: flags & 128 != 0, + center: flags & 4 != 0, + show_plot_styles: flags & 2 != 0, + file_plot_flags: Some(flags), + ..PageSetup::default() + }; + d.layouts.push(l); + d +} + +/// The plot layout flags of SHEET after saving `d` as `name` and reading it back. +fn flags_after_save(d: &Drawing, name: &str) -> Option { + let bytes = write(d, name).unwrap(); + let back = read(&bytes, name).unwrap(); + back.layouts.iter().find(|l| l.name == "SHEET")?.page.file_plot_flags +} + +#[test] +fn plot_layout_flags_are_saved_as_read() { + for name in ["sheet.dxf", "sheet.dwg"] { + for flags in [0, 176, 560, 688] { + assert_eq!(flags_after_save(&drawing(flags), name), Some(flags), "{name}: flags {flags}"); + } + } +} + +#[test] +fn the_page_still_decides_the_bits_cadcraft_models() { + // Lineweights turned on and a custom scale chosen after reading flags 16: 128 is set and the + // standard scale bit cleared, the rest kept. + let mut d = drawing(16 | 512); + let page = &mut d.layouts.last_mut().unwrap().page; + page.lineweights = true; + page.scale = 0.02; + assert_eq!(flags_after_save(&d, "sheet.dxf"), Some(512 | 128)); + // A page made in CADCraft keeps the defaults (plot paper space last, plot with plot styles, + // standard scale, lineweights). + let mut d = drawing(0); + d.layouts.last_mut().unwrap().page = PageSetup::default(); + assert_eq!(flags_after_save(&d, "sheet.dxf"), Some(512 | 128 | 32 | 16)); +} diff --git a/crates/io/tests/it/main.rs b/crates/io/tests/it/main.rs index c53acb9a1..d777d350f 100644 --- a/crates/io/tests/it/main.rs +++ b/crates/io/tests/it/main.rs @@ -33,6 +33,7 @@ mod hatch_pattern_def; mod helix_roundtrip; mod layout_limits_roundtrip; mod layout_paper_units; +mod layout_plot_flags; mod layout_plot_window; mod leader_vertex_elevation; #[cfg(not(target_arch = "wasm32"))] diff --git a/crates/io/tests/it/roundtrip/collections.rs b/crates/io/tests/it/roundtrip/collections.rs index e83e1d876..46c9c4349 100644 --- a/crates/io/tests/it/roundtrip/collections.rs +++ b/crates/io/tests/it/roundtrip/collections.rs @@ -257,7 +257,7 @@ pub(super) fn assert_layouts(a: &Drawing, b: &Drawing, context: &str) { let back = b.layouts.iter().find(|l| l.name == layout.name).expect("layout must survive"); assert_eq!(back.tab_order, layout.tab_order, "{context}.{}.tab_order", layout.name); // The groups 44, 45 and 73 the file stored are provenance, not a setting. - let setting = |p: &cadcraft_doc::PageSetup| cadcraft_doc::PageSetup { file_paper: None, ..p.clone() }; + let setting = |p: &cadcraft_doc::PageSetup| cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, ..p.clone() }; assert_eq!(setting(&back.page), setting(&layout.page), "{context}.{}.page", layout.name); assert_eq!(back.view, layout.view, "{context}.{}.view", layout.name); compare::entities(a, b, &layout.entities, &back.entities, &format!("{context}.layout[{}]", layout.name)); diff --git a/crates/io/tests/it/tables_objects_roundtrip.rs b/crates/io/tests/it/tables_objects_roundtrip.rs index 17b21f742..b285a9cd9 100644 --- a/crates/io/tests/it/tables_objects_roundtrip.rs +++ b/crates/io/tests/it/tables_objects_roundtrip.rs @@ -112,7 +112,7 @@ fn layout_page_setup_and_paper_view_round_trip() { for (a, b) in d.layouts.iter().zip(&r.layouts) { assert_eq!(a.name, b.name); // The groups 44, 45 and 73 the file stored are provenance, not a setting. - let read = cadcraft_doc::PageSetup { file_paper: None, ..b.page.clone() }; + let read = cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, ..b.page.clone() }; assert_eq!(a.page, read, "{}", a.name); assert_eq!(a.view, b.view, "{}", a.name); } From dab89a38ed6913be447fde4fcb9b4c4eba0e9495 Mon Sep 17 00:00:00 2001 From: Ray <66087717+iHateStupidPeople@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:33:43 -0700 Subject: [PATCH 13/19] Layouts: keep an unchanged standard plot scale (#3227) A layout read with a standard scale other than 1:1 (flags 176, group 75 = 25, scale 0.02 for 1:50) lost plot layout flag 16 and its standard-scale choice on save, because only scaled to fit and 1:1 counted as standard. The page now keeps the file's group 75 with the scale it was read with; while the scale is unchanged, saving writes that choice and keeps flag 16. --- crates/doc/src/tables.rs | 7 +++++++ crates/io/src/dxf_read/objects.rs | 7 +++++++ crates/io/src/dxf_write/sections.rs | 6 ++++-- crates/io/tests/it/layout_plot_flags.rs | 18 ++++++++++++++++++ crates/io/tests/it/roundtrip/collections.rs | 3 ++- crates/io/tests/it/tables_objects_roundtrip.rs | 2 +- 6 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/doc/src/tables.rs b/crates/doc/src/tables.rs index dc16d65be..bdbc14d3f 100644 --- a/crates/doc/src/tables.rs +++ b/crates/doc/src/tables.rs @@ -824,6 +824,12 @@ pub struct PageSetup { /// made in CADCraft. #[serde(skip)] pub file_plot_flags: Option, + /// The standard scale the file chose (DXF group 75, such as 25 for 1:50) and the plot scale it + /// was read with. While the scale is unchanged, saving keeps that choice and the standard scale + /// flag instead of writing the scale as a custom one; `None` for a custom scale, scaled to + /// fit, or a page setup made in CADCraft. + #[serde(skip)] + pub file_standard_scale: Option<(i64, f64)>, } impl Default for PageSetup { @@ -848,6 +854,7 @@ impl Default for PageSetup { file_paper: None, image_origin: None, file_plot_flags: None, + file_standard_scale: None, } } } diff --git a/crates/io/src/dxf_read/objects.rs b/crates/io/src/dxf_read/objects.rs index 34e197a2f..a92f63916 100644 --- a/crates/io/src/dxf_read/objects.rs +++ b/crates/io/src/dxf_read/objects.rs @@ -280,6 +280,13 @@ pub(super) fn page_setup(t: &T) -> PageSetup { if let Some(s) = pos(ratio).or_else(|| pos(t.f(147))) { p.scale = s; } + // A standard scale (flag 16, group 75 above 0: 0 is scaled to fit, the DXF Reference lists + // 1 to 32), kept with the scale it stands for so a save can tell it was not changed. + if t.i(70).is_some_and(|f| f & 16 != 0) + && let Some(code) = t.i(75).filter(|c| (1..=32).contains(c)) + { + p.file_standard_scale = Some((code, p.scale)); + } p.plot_area = match t.i(74) { Some(0) => "display", Some(1) => "extents", diff --git a/crates/io/src/dxf_write/sections.rs b/crates/io/src/dxf_write/sections.rs index 79afc4b39..5f787ab79 100644 --- a/crates/io/src/dxf_write/sections.rs +++ b/crates/io/src/dxf_write/sections.rs @@ -419,7 +419,9 @@ fn layout_obj(w: &mut W, context: LayoutWriteContext<'_>, data: LayoutWriteData< // Plot scale: a standard scale when fitting or 1:1, otherwise custom (142 paper units // per 143 drawing units). let scale = if page.scale.is_finite() && page.scale > 0.0 { page.scale } else { 1.0 }; - let standard = page.scale_to_fit || scale == 1.0; + // The file's standard scale (such as 1:50) while the scale is still the one read with it. + let file_standard = page.file_standard_scale.filter(|&(_, s)| !page.scale_to_fit && s == scale).map(|(code, _)| code); + let standard = page.scale_to_fit || scale == 1.0 || file_standard.is_some(); let plot_flags = plot_layout_flags(page, standard); let plot_type = match page.plot_area.as_str() { "display" => 0, @@ -462,7 +464,7 @@ fn layout_obj(w: &mut W, context: LayoutWriteContext<'_>, data: LayoutWriteData< w.i(73, rotation); w.i(74, plot_type); w.s(7, &page.plot_style_table); - w.i(75, if page.scale_to_fit { 0 } else { 16 }); + w.i(75, if page.scale_to_fit { 0 } else { file_standard.unwrap_or(16) }); w.f(147, scale); // The paper image origin the file had (#2109), else 0,0. let origin = page.image_origin.filter(|o| o.is_finite()).unwrap_or(Vec2::ZERO); diff --git a/crates/io/tests/it/layout_plot_flags.rs b/crates/io/tests/it/layout_plot_flags.rs index 82cf1e433..2044505f7 100644 --- a/crates/io/tests/it/layout_plot_flags.rs +++ b/crates/io/tests/it/layout_plot_flags.rs @@ -37,6 +37,24 @@ fn plot_layout_flags_are_saved_as_read() { } } +#[test] +fn an_unchanged_standard_scale_keeps_its_flag_and_choice() { + // Flags 176 with standard scale 25 (1:50): the scale is 0.02, not 1:1, and still standard. + let mut d = drawing(176); + let page = &mut d.layouts.last_mut().unwrap().page; + page.scale = 0.02; + page.file_standard_scale = Some((25, 0.02)); + for name in ["sheet.dxf", "sheet.dwg"] { + let back = read(&write(&d, name).unwrap(), name).unwrap(); + let page = &back.layouts.iter().find(|l| l.name == "SHEET").unwrap().page; + assert_eq!(page.file_plot_flags, Some(176), "{name}"); + assert_eq!(page.file_standard_scale, Some((25, 0.02)), "{name}"); + } + // A scale changed after reading is a custom one: 16 is cleared and the choice dropped. + d.layouts.last_mut().unwrap().page.scale = 0.05; + assert_eq!(flags_after_save(&d, "sheet.dxf"), Some(160)); +} + #[test] fn the_page_still_decides_the_bits_cadcraft_models() { // Lineweights turned on and a custom scale chosen after reading flags 16: 128 is set and the diff --git a/crates/io/tests/it/roundtrip/collections.rs b/crates/io/tests/it/roundtrip/collections.rs index 46c9c4349..d88d49c7d 100644 --- a/crates/io/tests/it/roundtrip/collections.rs +++ b/crates/io/tests/it/roundtrip/collections.rs @@ -257,7 +257,8 @@ pub(super) fn assert_layouts(a: &Drawing, b: &Drawing, context: &str) { let back = b.layouts.iter().find(|l| l.name == layout.name).expect("layout must survive"); assert_eq!(back.tab_order, layout.tab_order, "{context}.{}.tab_order", layout.name); // The groups 44, 45 and 73 the file stored are provenance, not a setting. - let setting = |p: &cadcraft_doc::PageSetup| cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, ..p.clone() }; + let setting = + |p: &cadcraft_doc::PageSetup| cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, file_standard_scale: None, ..p.clone() }; assert_eq!(setting(&back.page), setting(&layout.page), "{context}.{}.page", layout.name); assert_eq!(back.view, layout.view, "{context}.{}.view", layout.name); compare::entities(a, b, &layout.entities, &back.entities, &format!("{context}.layout[{}]", layout.name)); diff --git a/crates/io/tests/it/tables_objects_roundtrip.rs b/crates/io/tests/it/tables_objects_roundtrip.rs index b285a9cd9..502aafa3d 100644 --- a/crates/io/tests/it/tables_objects_roundtrip.rs +++ b/crates/io/tests/it/tables_objects_roundtrip.rs @@ -112,7 +112,7 @@ fn layout_page_setup_and_paper_view_round_trip() { for (a, b) in d.layouts.iter().zip(&r.layouts) { assert_eq!(a.name, b.name); // The groups 44, 45 and 73 the file stored are provenance, not a setting. - let read = cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, ..b.page.clone() }; + let read = cadcraft_doc::PageSetup { file_paper: None, file_plot_flags: None, file_standard_scale: None, ..b.page.clone() }; assert_eq!(a.page, read, "{}", a.name); assert_eq!(a.view, b.view, "{}", a.name); } From 50baa3cfae900fccf36a656991ac290616c0f66b Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 16:32:11 -0700 Subject: [PATCH 14/19] Parity docs: batch for the merges of 2026-11-19 and 2026-11-20, alpha-blocker marks follow the six-row gate --- ROADMAP.md | 23 ++++++++++++++--------- docs/gaps.md | 30 ++++++++++++++++-------------- docs/roadmap.md | 19 ++++++++++--------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 4998e6c0c..3ccc2bbf5 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -2,7 +2,7 @@ **Stage: pre-alpha** · next: alpha, when the six rows of the [alpha gate](docs/roadmap.md#alpha-gate) pass (five fail today; the gate was revised on 2026-11-19 and its hours are not re-estimated yet) -> **Last reviewed:** 2026-11-19 · **Last updated:** 2026-11-19 · **Change:** major (alpha gate revised from user reports: six rows, Windows first; Upcoming re-ranked into three priority tiers; previously minor: re-audit against main 41d9b5e95) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-11-19 · **Last updated:** 2026-11-20 · **Change:** minor (Upcoming updated for what merged on 2026-11-19 and 2026-11-20; previously major: alpha gate revised from user reports: six rows, Windows first; Upcoming re-ranked into three priority tiers; previously minor: re-audit against main 41d9b5e95) · **Target:** Autodesk AutoCAD 2027 CADCraft targets full parity with AutoCAD (2D drafting first, then annotation, layouts and plotting, DWG, parametrics and 3D), plus what AutoCAD doesn't have: agent control over MCP, a @@ -115,21 +115,23 @@ and the beta checklist are in [docs/roadmap.md](docs/roadmap.md). - The open findings of the security audit (#1919–#1935): check each against the input limits that landed on 2026-11-11, close what is fixed and fix the rest. A crafted handle that makes new entities overwrite existing ones (#1921) is fixed by #1276. -- Hostile-input fixes waiting in pull requests (#2820, #2821, #2765). +- A saved file that crashes AutoCAD 2021 (#3303) and dimension text lost on save (#3299). - Crashes and hangs with a reproduction: the web build on a large DXF (#1603), a DWG with 3D content (#2174), startup on older graphics hardware (#1724, #1631, #3222). **2. Parity with AutoCAD: the alpha gate rows, then the beta checklist (apart from its items named under tier 3).** -- It starts on common hardware (#1596, then an automatic fallback renderer). +- It starts on common hardware: an automatic fallback renderer (`CADCRAFT_STENCIL=0` is the manual + switch since #3336). - It opens the DWG and DXF files people already have: large files (#3102, #2633, #1088), layouts and paper units (#1672, #2836), and a corpus of real files run in CI. - Saving loses nothing and other CAD programs open the result (#2904, #1687, #3234, #2632). -- Input feels like AutoCAD for Windows: clicks while the mouse moves (#1001, #2092), right-click and - Space as Enter (#1387), double-click to edit text (#842). +- Input feels like AutoCAD for Windows: the fixes for clicks while the mouse moves, right-click and + Space as Enter, and double-click text editing landed (#3307, #3345); waiting for the reporters to + confirm, and table cells are left (#842). - The prompt options that still say "not available yet", and TRIM/EXTEND depth. -- Layouts print at scale on a system printer, and the menu bar and panels can always be restored - (#3216, #1240). -- 714 pull requests are open (2026-11-19). About 230 are mergeable, pass CI and are small; they are +- Layouts print at scale on a system printer (#3216); the menu bar and panels can be restored since + #3308. +- 661 pull requests are open (2026-11-20; 714 the day before). About 230 were mergeable, passed CI and were small; they are reviewed and landed in this order, the longest-waiting authors first within a row. **3. Lower priority: affects fewer people and nothing breaks without it.** @@ -139,7 +141,9 @@ and the beta checklist are in [docs/roadmap.md](docs/roadmap.md). but a file with 3D content must open safely (tier 1). - Menu breadth against AutoCAD for Mac as a headline number. -Done since the last ranking: precision input (#379, #441, #60, #519), prompt options in TRIM/EXTEND, +Done on 2026-11-19 and 2026-11-20: the hostile-input fixes #1276, #2820, #2821 and #2765 (#3304, #3305), clicks while the mouse moves and right-click or Space as Enter (#3307), the interface reset (#3308), paper units (#3309), the UCS command (#3310), -ATTEDIT, -RENAME and -LAYER options (#3311), TRIM/EXTEND depth (#3312), dimension values kept on save (#3335), the stencil switch (#3336), a typed OPEN path (#3343) and double-click text editing (#3345). + +Done before that: precision input (#379, #441, #60, #519), prompt options in TRIM/EXTEND, OFFSET, ROTATE, PLINE, SPLINE, MTEXT and MLEADER (#397, #408, #547), autosave, recovery, AUDIT and RECOVER on the desktop (#406, #416), xrefs (#525), groups (#417), the Block Editor (#824, #833, #885), REFEDIT (#818), XCLIP (#2354), dynamic block references (#838–#883), and the Dimension Style Manager @@ -166,6 +170,7 @@ REFEDIT (#818), XCLIP (#2354), dynamic block references (#838–#883), and the D | Date | Change | Summary | |---|---|---| +| 2026-11-20 | minor | Upcoming updated for the merges of 2026-11-19 and 2026-11-20 (security stacks, input, interface reset, paper units, UCS, prompt options, TRIM/EXTEND, text editing in place); pull-request count 714 → 661; percentages and hours not re-scored | | 2026-11-19 | major | Alpha gate revised from user reports (six rows, Windows first; block authoring, xref editing in place and exact curve geometry moved to beta); Upcoming re-ranked into three tiers: urgent (security, leaks, crashes, lost work), parity, lower priority; percentages and hours not re-scored | | 2026-10-24 | minor | Re-audit against main 41d9b5e95: language table, CI gate and open-PR count re-checked against main 41d9b5e95 | | 2026-10-21 | trivial | Progress log: proxy objects keep their class through a save (#1812) | diff --git a/docs/gaps.md b/docs/gaps.md index 289f0b4be..13286f9af 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -1,6 +1,6 @@ # Where CADCraft falls short of AutoCAD -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-31 · **Change:** minor (re-audit against main 7cee28580: file-test and catalog counts, REFEDIT, dynamic-block and QSAVE rows; previously: QSAVE asks before losing content and keeps a `.bak`: rows 1, FF1 and F20 updated; previously: BEDIT in the Block Editor switches blocks: F3 updated; previously: Named Viewports dialog: U11 narrowed; MVIEW Restore and PURGE of multiline styles had landed: F15 and F21 corrected; previously: DIMTFILL limits in the `*D` block, EXPLODE and DXF: F7 updated; re-audit against main 41d9b5e95: CI gate (#6, S1), MVIEW Restore (F15, U11), open-PR and catalog counts, file-test count; previously: Command Aliases dialog for ALIASEDIT: U12 and E5 narrowed) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-20 · **Change:** minor (alpha-blocker marks follow the six-row gate of 2026-11-19; rows updated for what merged on 2026-11-19 and 2026-11-20: the Dimension Style Manager, the UCS command, in-place TEXT editing, -ATTEDIT, -RENAME and -LAYER options, ARRAY Key point, right-click settings and the interface reset; new row P4 for startup on older graphics hardware; previously: re-audit against main 7cee28580: file-test and catalog counts, REFEDIT, dynamic-block and QSAVE rows; previously: QSAVE asks before losing content and keeps a `.bak`: rows 1, FF1 and F20 updated; previously: BEDIT in the Block Editor switches blocks: F3 updated; previously: Named Viewports dialog: U11 narrowed; MVIEW Restore and PURGE of multiline styles had landed: F15 and F21 corrected; previously: DIMTFILL limits in the `*D` block, EXPLODE and DXF: F7 updated; re-audit against main 41d9b5e95: CI gate (#6, S1), MVIEW Restore (F15, U11), open-PR and catalog counts, file-test count; previously: Command Aliases dialog for ALIASEDIT: U12 and E5 narrowed) · **Target:** Autodesk AutoCAD 2027 Every known shortfall, one row each, ranked within each section by user impact. This is the work list: agents pick from here (top of a section first). A PR names the rows it closes in its @@ -16,7 +16,7 @@ do them first. | 1 | **[alpha blocker]** **Saving DWG drops what we don't model** (DXF now writes back unknown entities and objects, foreign xdata, extension dictionaries, reactors, layer states and colour books, #528, and native MULTILEADERs, #459 (not yet tested through DWG); through DWG, acadrust drops custom-class entities and objects, xdata on table records and blocks, entity colour books and reactors; the ACIS data of 3D solids, regions and bodies is kept, #781; a user's QSAVE now asks before replacing the file and keeps the previous one as `.bak`, which reduces the harm but does not close this row) | Opening a colleague's DWG and saving it still deletes some content: the one thing a CAD user can't forgive | 6–10 | [file formats](file-format-parity.md) | | 2 | **[alpha blocker]** **No real-file test corpus and no check in AutoCAD** | All 88 file tests (`crates/io/src/tests.rs`) use synthetic data (the real-file runs in PRs #781 and #859 were manual and are not committed); nobody has verified a CADCraft DWG/DXF opens cleanly in AutoCAD | 10–15 + human | [file formats](file-format-parity.md#tests) | | 3 | **Ellipse and spline geometry is tessellated** (intersections, offsets, closest points; polyline offset recomputes arc bulges since #825 but has no loop cleanup) | Coordinates are subtly wrong; offsets of ellipses come out as polylines | 30–50 | [geometry](geometry-parity.md) | -| 4 | **[alpha blocker]** **No dynamic-block authoring; xrefs can't be edited in place** (REFEDIT, REFSET and REFCLOSE edit block references in place, #818; XCLIP and XCLIPFRAME clip block and xref references, #2354; dynamic block references are read and edited, #838–#883; xrefs, #525, groups, #417, and the Block Editor for static blocks landed) | Most production drawings use them | 55–90 | [features](#features) | +| 4 | **No dynamic-block authoring; xrefs can't be edited in place** (REFEDIT, REFSET and REFCLOSE edit block references in place, #818; XCLIP and XCLIPFRAME clip block and xref references, #2354; dynamic block references are read and edited, #838–#883; xrefs, #525, groups, #417, and the Block Editor for static blocks landed) | Most production drawings use them; counted under beta since the gate revision of 2026-11-19 (few reports) | 55–90 | [features](#features) | | 5 | **No autosave in the web build** (the desktop app has SAVETIME autosave, Drawing Recovery, AUDIT and RECOVER since #406) | Browser users lose unsaved work when the tab or the browser goes down | 3–5 | [features](#features) | | 6 | ~~**No CI runs the Rust tests on pull requests**~~ fixed: `.github/workflows/ci.yml` runs `cargo xtask ci` on every pull request and push to main through the shared gate workflow (#1987); `cargo fmt` on main is fixed. | — | 0 | [stability](#stability) | @@ -24,15 +24,15 @@ do them first. | # | Gap | Evidence | User impact | Est. | |---|---|---|---|---| -| F1 | **[alpha blocker]** Prompt options that still print "not available yet": -ATTEDIT one-at-a-time Position, Height, Angle and Style, colour books in -ATTEDIT Color, -RENAME of materials, plot styles and viewport configurations, DVIEW CAmera, TArget, Distance, POints, CLip and Hide (they need a 3D camera; TWist, PAn, Zoom, Off and Undo work). SPLINEDIT Join, Edit vertex Add and Elevate order (#559), PEDIT Edit vertex and the other SPLINEDIT options (#558) done: Edit vertex Tangent directions last for the PEDIT session only (LWPOLYLINE stores none). MTEXT Dynamic/Static columns done (#547). SPLINE, MTEXT and MLEADER options done (#408): SPLINE Object fits the polyline's vertices (no spline frame is kept) (STRETCH polygon, CP and WP, and fence selection done; TRIM/EXTEND, PLINE arc mode and Length, XLINE done (#397); OFFSET, ROTATE and FILLET options done earlier) | `cmd/blocks/attedit.rs`, `cmd/props/rename.rs`, `cmd/view/dview.rs` | Low: the most-used commands are done | 1–3 | +| F1 | Prompt options that still print "not available yet": colour books in -ATTEDIT Color, -RENAME of materials and plot styles, -LAYER stAte Import and EXport, DVIEW CAmera, TArget, Distance, POints, CLip and Hide (they need a 3D camera; TWist, PAn, Zoom, Off and Undo work). -ATTEDIT one-at-a-time Position, Height, Angle and Style, -RENAME of viewport configurations and -LAYER stAte landed (#3311); the new -ATTEDIT prompt texts are not yet compared with AutoCAD's. SPLINEDIT Join, Edit vertex Add and Elevate order (#559), PEDIT Edit vertex and the other SPLINEDIT options (#558) done: Edit vertex Tangent directions last for the PEDIT session only (LWPOLYLINE stores none). MTEXT Dynamic/Static columns done (#547). SPLINE, MTEXT and MLEADER options done (#408): SPLINE Object fits the polyline's vertices (no spline frame is kept) (STRETCH polygon, CP and WP, and fence selection done; TRIM/EXTEND, PLINE arc mode and Length, XLINE done (#397); OFFSET, ROTATE and FILLET options done earlier) | `cmd/blocks/attedit.rs`, `cmd/props/rename.rs`, `cmd/view/dview.rs` | Low: the most-used commands are done | 1–3 | | F2 | XREF editing in place: REFEDIT, REFSET and REFCLOSE edit a block reference in place (working set, faded rest of the block, everything else locked, save or discard; #813); left: editing an xref in place (its source drawing is not written back; XOPEN opens it), picking nested references, a dimmed look for the locked drawing and a banner with Save and Discard, attribute sync of other references (ATTSYNC). XCLIP clips a block or xref reference to a rectangular, polygonal or closed-polyline boundary (Invert clip, ON/OFF, Delete, generate Polyline; Clipdepth is ignored in 2D), drawn, plotted and framed as XCLIPFRAME says, with the extents cut to it, and kept through DXF and DWG as the reference's SPATIAL_FILTER (2026-10-27). XATTACH, the External References palette, -XREF (Bind/Detach/Path/Unload/Reload/Overlay), XBIND, XOPEN, overlays, relative paths and loading at open are done (#525). Unloaded state and xref-layer overrides last only for the session | `cmd/blocks/xref.rs` | Medium: xrefs can't be edited in place | 12–20 | -| F3 | **[alpha blocker]** (dynamic-block authoring is beta) No dynamic-block authoring: parameters and actions can't be added in the Block Editor. Dynamic blocks from other files are read and their references edited (visibility, distances, stretch and move, lookups, grips). BEDIT (with the Edit Block Definition dialog, which also starts new blocks and, in the Block Editor, switches to another block after asking to save), BSAVE, BSAVEAS and BCLOSE edit a static block definition, and every reference updates; REFEDIT edits a reference in place; no authoring palettes yet | issue #185 offers help | High: standard libraries are dynamic | 40–65 | +| F3 | No dynamic-block authoring (beta checklist): parameters and actions can't be added in the Block Editor. Dynamic blocks from other files are read and their references edited (visibility, distances, stretch and move, lookups, grips). BEDIT (with the Edit Block Definition dialog, which also starts new blocks and, in the Block Editor, switches to another block after asking to save), BSAVE, BSAVEAS and BCLOSE edit a static block definition, and every reference updates; REFEDIT edits a reference in place; no authoring palettes yet | issue #185 offers help | High: standard libraries are dynamic | 40–65 | | F4 | Autosave leftovers: no autosave in the web build (browser storage); autosave files are DXF, not DWG; no separate RECOVER mode in the file readers (SAVETIME, Drawing Recovery, AUDIT and RECOVER landed with #406; AUDITCTL `.adt` log landed) | `engine/src/autosave.rs`, `engine/src/audit.rs` | Low-medium (web users) | 2–4 | -| F5 | Associative arrays (ASsociative, Levels, polar ROWs, ARRAYEDIT, ARRAYCLOSE) landed (#448); left: grip editing of arrays (count/spacing grips), ARRAYPATH is not associative, ARRAYEDIT has no item deletion (CTRL+click) and no Key point base points, levels only shift Z (no 3D view) | `cmd/array.rs`, `cmd/array/edit.rs` | Medium | 4–6 | -| F7 | Dimensions: no DIMSTYLE manager dialog; no smart DIM; DIMALTTD/DIMALTTZ, DIMUPT and DIMTXTDIRECTION not modelled; jog height and break size not style settings; DIMBREAK breaks don't follow moved objects; with DIMTFILL 1 the written `*D` block and EXPLODE keep no background mask (a WIPEOUT over the text box would), and a true-color DIMTFILLCLR is written to DXF as the nearest ACI (style variables, DIMJOGGED, DIMJOGLINE, DIMBREAK, DIMEDIT, DIMINSPECT and QDIM modes done, #507; the DIMTFILL/DIMTFILLCLR text background done) | `doc/src/tables.rs`, `cmd/annotate_dimedit.rs`, `cmd/annotate_qdim.rs` | Medium | 10–15 | +| F5 | Associative arrays (ASsociative, Levels, polar ROWs, ARRAYEDIT, ARRAYCLOSE) landed (#448); left: grip editing of arrays (count/spacing grips), ARRAYPATH is not associative, ARRAYEDIT has no item deletion (CTRL+click) (the Key point base point of ARRAY and ARRAYEDIT landed, #2368), levels only shift Z (no 3D view) | `cmd/array.rs`, `cmd/array/edit.rs` | Medium | 4–6 | +| F7 | Dimensions: no smart DIM; DIMALTTD/DIMALTTZ, DIMUPT and DIMTXTDIRECTION not modelled; jog height and break size not style settings; DIMBREAK breaks don't follow moved objects; with DIMTFILL 1 the written `*D` block and EXPLODE keep no background mask (a WIPEOUT over the text box would), and a true-color DIMTFILLCLR is written to DXF as the nearest ACI (the Dimension Style Manager, -DIMSTYLE and dimension properties landed, #1460; an edited dimension keeps its values on save, #3335; style variables, DIMJOGGED, DIMJOGLINE, DIMBREAK, DIMEDIT, DIMINSPECT and QDIM modes done, #507; the DIMTFILL/DIMTFILLCLR text background done) | `doc/src/tables.rs`, `cmd/annotate_dimedit.rs`, `cmd/annotate_qdim.rs` | Medium | 10–15 | | F8 | TOLERANCE leftovers (feature control frames landed, #420: model, our own symbol drawing, DXF, command-line prompts, explode, grips): no Geometric Tolerance dialog, no LEADER/QLEADER tolerance annotation, no in-place editing of a frame's contents | `cmd/tolerance.rs` | Low-medium (mechanical) | 2–4 | | F10 | MLEADEREDIT (add/remove leader), MLEADERALIGN and MLEADERCOLLECT landed, but a multileader has one landing and one block (a collection keeps the other blocks as block references beside it; MLEADERALIGN has no Options-menu preview); MLEADERSTYLE has 6 settings (arrow size, text height, landing gap, dogleg, text style, annotative; block content and spline/no-leader types are per command, not in the style; block content has no attributes) | `annotate.rs`, `cmd/mleader_content.rs`, `cmd/mleader_edit.rs`, `doc/src/tables.rs` | Medium | 8–12 | -| F9 | MTEXT is typed in an on-canvas editor with a formatting toolbar (font, height, bold, italic, underline, overline, colour, alignment, lists, tab and special characters) and a ruler for indents and tab stops (#532); left: the box does not lay the text out by the indents, tabs, columns or font weights while typing (bold shows wider, overline is not drawn), no justification (attachment) or columns controls in the editor, existing TEXT is edited as plain text on the command line with TEXTEDIT (alias DDEDIT; a double-click starts it, #868), while an existing MTEXT opens in the in-place editor with its contents (#1002, merged 2026-11-06); stacked fractions and other codes show as placeholders; no fields (FIELD, UPDATEFIELD) and no spell check (SPELL): open PR #551. Paragraph indents, tabs, bullets, numbering and columns landed (#547) | `ui-egui/mtext_editor.rs`, `engine/mtext_edit.rs` | Medium | 10–18 | +| F9 | MTEXT is typed in an on-canvas editor with a formatting toolbar (font, height, bold, italic, underline, overline, colour, alignment, lists, tab and special characters) and a ruler for indents and tab stops (#532); left: the box does not lay the text out by the indents, tabs, columns or font weights while typing (bold shows wider, overline is not drawn), no justification (attachment) or columns controls in the editor, a double-click edits existing TEXT, an attribute definition or a dimension's text in a box on the canvas (#3345; table cells are not edited in place, and the box was not checked on a HiDPI screen or in a twisted view), and an existing MTEXT opens in the in-place editor with its contents (#1002); stacked fractions and other codes show as placeholders; no fields (FIELD, UPDATEFIELD) and no spell check (SPELL): open PR #551. Paragraph indents, tabs, bullets, numbering and columns landed (#547) | `ui-egui/mtext_editor.rs`, `engine/mtext_edit.rs` | Medium | 10–18 | | F11 | Tables (cell styles, formulas, TABLEDIT, TABLEEXPORT, table breaking and CSV data links landed, #534): formulas aren't read from or written as AutoCAD FIELD objects (other programs see values); number formats apply to formula results only; cell text doesn't wrap; custom cell styles, breaks and data links travel as CADCraft xdata (not through DWG); data links read CSV only (no Excel ranges, no write-back, not on the web); no cell-style tab in the Table Style dialog | `cmd/table/*`, `io/dxf_table.rs` | Low-medium | 6–10 | | F12 | Annotative scaling done (#468): scale list (SCALELISTEDIT), CANNOSCALE, OBJECTSCALE, ANNOALLVISIBLE/ANNOAUTOSCALE, viewport scale, DXF, status bar list. Left: per-scale positions (ANNORESET is a no-op), a viewport annotation scale apart from its viewport scale, annotative objects inside blocks and old LEADERs, AutoCAD files' per-object scale contexts (read as not annotative) | `cmd/annoscale.rs`, `doc/src/anno.rs` | Low-medium | 4–8 | | F14 | **[alpha blocker]** Plotting leftovers: binary `.ctb`/`.stb`/`.pc3` files can't be read; no system printers (H3); the page setup's "Plot transparency" is not saved in DXF/DWG (the public DXF Reference has no plot layout flag for it), so it lasts for the session and in JSON only. The Plot dialog (#160), Plot Preview and PUBLISH (#186), plot styles (CTB and STB, [plot-styles.md](plot-styles.md), #410) with their end, join and fill styles, plotter devices with paper sizes and printable areas ([plotters.md](plotters.md), #564), and plotted transparency (page setup and Plot dialog option, PLOTTRANSPARENCYOVERRIDE) landed | `io/src/plotter.rs`, `cmd/plotters.rs` | Medium | 4–8 | @@ -41,11 +41,11 @@ do them first. | F16 | Groups: no group bounding box or single grip when a group is selected (GROUPDISPLAYMODE), copying a whole group does not make a new group, no Object Grouping dialog (GROUP, GROUPEDIT, UNGROUP, -GROUP, PICKSTYLE group selection and the DXF/DWG round trip landed, #417); PICKSTYLE's associative-hatch bit is stored but unused | `cmd/groups.rs` | Low | 2–4 | | F17 | Attributes (ATTSYNC, global -ATTEDIT, BATTMAN editing and DATAEXTRACTION/EATTEXT landed, #433): the Verify, Preset and Lock position modes are kept in files and Lock position is applied by INSERT and ATTSYNC (#876), but INSERT doesn't act on Verify or Preset, and multiline attributes (read, drawn and saved since 2026-10-12) can't be created or switched in BATTMAN; data extraction covers block references and attribute values (CSV or a table) only — no wizard, nested blocks, other objects' properties, `.dxe` templates or spreadsheet output | `cmd/blocks/battman.rs`, `cmd/blocks/extract.rs` | Low | 4–6 | | F19 | MATCHPROP Settings is a keyword prompt (no dialog) and has no material, shadow or centre-object settings; TEXTTOFRONT and HATCHTOBACK act on the current space only; OVERKILL doesn't compare polyline segments with other objects (picker and Settings, DRAWORDER Above/Under, TEXTTOFRONT, HATCHTOBACK, OVERKILL tolerance/ignore/overlap/end-to-end options landed, #439) | `props/matchprop.rs`, `draworder.rs`, `overkill.rs` | Low | 2–4 | -| F20 | OPTIONS dialog done (#23): Display, Open and Save, Drafting, Selection, User Preferences and Profiles tabs, and the user profile (object snap modes, drafting toggles, Dynamic Input, PICKBOX, APERTURE, GRIPSIZE, CURSORSIZE, PICKFIRST, PICKADD, QPMODE, model and paper background, snap marker size, system cursor) survives restarts. Left: right-click customization, the autosave interval and default save version on Open and Save (the features themselves landed, #406, #421), AutoSnap magnet and tooltip toggles, colours of the other drawing-area elements, named profiles with import and export Open and Save has the backup copy checkbox (ISAVEBAK). | `ui-egui/src/options/` | Low | 2–4 | +| F20 | OPTIONS dialog done (#23): Display, Open and Save, Drafting, Selection, User Preferences and Profiles tabs, and the user profile (object snap modes, drafting toggles, Dynamic Input, PICKBOX, APERTURE, GRIPSIZE, CURSORSIZE, PICKFIRST, PICKADD, QPMODE, model and paper background, snap marker size, system cursor) survives restarts. Right-Click Customization and the time-sensitive right-click landed (#2371, #3307), and Reset restores the whole interface (#3308). Left: the autosave interval and default save version on Open and Save (the features themselves landed, #406, #421), AutoSnap magnet and tooltip toggles, colours of the other drawing-area elements, named profiles with import and export Open and Save has the backup copy checkbox (ISAVEBAK). | `ui-egui/src/options/` | Low | 2–4 | | F21 | MLINE, REGION and HELIX are objects since #510, with gaps: MLEDIT tees trim square; UNION/SUBTRACT/INTERSECT only combine regions whose boundaries don't meet; regions are saved as closed polylines (no ACIS data) | `draw2/mline.rs`, `inquiry/regions.rs`, `dxf_region.rs` | Low | 6–10 | | F22 | Inquiry leftovers (COUNT across spaces and nested blocks, the QuickCalc palette and COMPARE landed, #563; MASSPROP on regions, #510): COMPARE compares the tab shown, not every layout at once (COMPAREEXPORT, the comparison as a new drawing, landed); COMPAREEXPORT puts the two sets of objects in model-space groups, where AutoCAD puts them in blocks; QuickCalc keeps its history and variables for the session only | `file/compare.rs`, `palettes/quickcalc.rs` | Low | 3–5 | | F23 | No Sheet Set Manager, eTransmit, Share, Traces, Markup Import, Activity Insights | menu items uncovered | Low-medium (team workflows) | 40–70 | -| F24 | No 3D: UCS, 3D views, orbit, solids, surfaces, meshes, sections, visual styles, materials, lights, rendering (150 menu items) | [parity-checklist](parity-checklist.md) | Medium (3D users) | 300–450 | +| F24 | No 3D: 3D views (the UCS command, named UCSs and the UCS icon work in the drawing plane since #3310), orbit, solids, surfaces, meshes, sections, visual styles, materials, lights, rendering (150 menu items) | [parity-checklist](parity-checklist.md) | Medium (3D users) | 300–450 | ## UI/UX @@ -65,7 +65,7 @@ or allow clicks and drag (2, default), saved in the user profile. Drag-only mode | U10 | SETVAR covers about 150 of ~1,000 variables (UNDO options, MREDO and UNDOCTL, and header variables such as CIRCLERAD, OFFSETDIST, POLYSIDES, HPNAME and the dimension variables in SETVAR ? landed, #461; typing a bare variable name as a command runs SETVAR on it) | Low-medium | 3–5 | | U11 | VIEW Orthographic, UCS and background settings (view twist: DVIEW on the Model tab, each VPORTS tile and each layout viewport, VIEWTWIST, landed; Zoom Realtime and Dynamic, ZOOMFACTOR, named views (VIEW) and tiled model viewports with saved configurations (VPORTS) landed in #463, MVIEW Restore in #633, and the Named Viewports dialog, which restores or deletes a saved configuration) | Low | 1–2 | | U12 | Workspaces, navigation bar, CUI customisation, ViewCube drag (#7) (the Command Aliases dialog landed, #1381) | Low-medium | 13–23 | -| U13 | `.dxf` from Finder fails to open on macOS (#158) (window controls fixed, #161) | Medium | 1–2 | +| U13 | `.dxf` from Finder fails to open on macOS (#158; #3344, which lands #1347, is written but has never been built or run on a Mac and waits for someone to check it there) (window controls fixed, #161) | Medium | 1–2 | ## File formats @@ -78,7 +78,7 @@ Detail: [file-format-parity.md](file-format-parity.md). | FF3 | Save-version leftovers (DXF/DWG 2000–2018, binary DXF, SAVEAS `version`/`binary` and the default save version landed, #421): no R14 DWG or R12 DXF output; the Save dialog can't pick the version per file (the file picker doesn't report the chosen type; File > Default Save Format sets it); no command-line SAVEAS format prompt | Low | 2–4 | | FF4 | Code-page leftovers (pre-2007 DXF read in their `$DWGCODEPAGE` landed, #505): Johab (ANSI_1361) and DOS 855/857/860–865/869 read as ANSI_1252; saving declares `ANSI_1252` instead of the file's code page (the text is pure ASCII, so still correct); acadrust approximates DOS code pages in pre-2007 DWG (DOS437 as 866, DOS850 as 1252) | Low | 1–2 | | FF5 | **[alpha blocker]** Real-file corpus (`storytold/cadcraft-corpus`), open → save → reopen tests, black-box check in AutoCAD | High | 10–15 + human | -| FF6 | **[alpha blocker]** DWG throughput: a 10 MB DWG took ~2 min to fail (#57) | High for real projects | 6–10 | +| FF6 | **[alpha blocker]** DWG throughput: a 10 MB DWG took ~2 min to fail (#57); large DWGs are refused at the size limits of the shared DWG library (512 MB of DWG, 1 GiB once converted, which a DWG of about 150 MB can reach; #3102, #2633, #1088). A typed `OPEN ` reads in the background (#3343); an open can't be cancelled and shows no progress | High for real projects | 6–10 | | FF7 | Table record and object handles from other programs' files are renumbered on the first save (entity handles are kept; `*D` blocks no longer duplicate and once reopened, CADCraft's own files keep every handle across saves, #495) | Low | 4–6 | | FF8 | SHX shape fonts, big fonts and unifonts are read and drawn (2026-10-22; looked up by file name beside the drawing, in `CADCRAFT_SHXPATH`, via a font map or registered by the web app; FONTALT). Left: no Options entry for the search path or font map; no desktop drag-drop of `.shx`; big-font code page guessed from the file name; vertical text not justified along its column; extended big font box scaling unverified against real files | Medium | 2–4 | | FF9 | `.pc3` plotter configuration files; shape elements in user `.lin` files are dropped on load (DXF/DWG linetype shape elements are drawn since 2026-10-22; templates and `.dwt`, user `.lin`/`.pat` and `.pgp` alias files landed, #552; `.ctb`/`.stb`, #410) | Low-medium | 4–8 | @@ -96,7 +96,7 @@ Detail: [hardware-parity.md](hardware-parity.md). |---|---|---| | H1 | 3Dconnexion SpaceMouse: 2D pan and zoom through raw HID on Windows and Linux landed (#650, Tools ▸ 3D Mouse; PR #983 open); none on macOS or the web, no 3D navigation (needs 3D views), not yet checked on a physical device in #650 | 6–10 + human | | H2 | Multi-monitor: floating palettes on other screens, per-monitor DPI (the Windows 11 DPI fix is in open PR #668, which replaced the closed PR #110) | 4–6 | -| H3 | System printers (PC3 devices) beyond PDF, PNG and SVG plotter devices (CUPS printing on macOS and Linux is open PR #755) | 6–10 | +| H3 | **[alpha blocker]** System printers (PC3 devices) beyond PDF, PNG and SVG plotter devices (CUPS printing on macOS and Linux is open PR #755) | 6–10 | | H4 | Pen tablets / digitizer (TABLET) | 3–5 + human | | H5 | Screen magnifier tracking: the system-cursor option landed (PR #187); issue #39 is still open | 1–2 | @@ -117,7 +117,7 @@ Detail: [localization-parity.md](localization-parity.md). |---|---|---|---| | S1 | ~~No CI runs `cargo xtask ci` on pull requests~~ fixed: `ci.yml` runs it on every pull request and push to main (#1987) | `.github/workflows/ci.yml` | 0 | | S2 | ~~`cargo fmt --check` fails on main~~ fixed on main (8fceaaf) | — | 0 | -| S3 | 450 open PRs (2026-10-24), many community bug fixes awaiting review | `gh pr list` | 10–20 | +| S3 | 661 open PRs (2026-11-20; 714 the day before), many community bug fixes awaiting review | `gh pr list` | 10–20 | | S4 | Open correctness issues: extents union far-apart geometry (#166), lines not visible mid-command (#44), browser plot shows raw PDF bytes (#134) (closing a tab and browser saves fixed, #76, #133) | issues | 4–6 | | S5 | No smoke test of every command through the UI (open PR #42 proposes one) | — | 6–10 | @@ -127,7 +127,8 @@ Detail: [localization-parity.md](localization-parity.md). |---|---|---| | P1 | Web build: plot shows raw PDF bytes (#134), no DWG (File > Open and save downloads fixed, #55, #133) | 3–5 | | P2 | Windows and Linux get little runtime testing; Linux Mint mouse delay (#25: the vsync fix landed, #183, the issue is open); Windows magnifier (#39: system-cursor option landed, #187, the issue is open) | 6–10 | -| P3 | macOS file associations: opening `.dxf` from Finder fails (#158; open PRs #683 and #899) | 1–2 | +| P3 | macOS file associations: opening `.dxf` from Finder fails (#158; #3344 lands #1347 and waits for a check on a Mac; #683 and #899 are open) | 1–2 | +| P4 | **[alpha blocker]** Startup on older graphics hardware: a black window or a crash on older Intel graphics, older macOS and some virtual machines (#1724, #1631, #3222, #1780). `CADCRAFT_STENCIL=0` starts the app without a stencil buffer (#3336) but has to be set by hand; there is no automatic fallback renderer | not estimated | ## Ecosystem and automation @@ -150,6 +151,7 @@ Detail: [localization-parity.md](localization-parity.md). | Date | Change | Summary | |---|---|---| +| 2026-11-20 | minor | Batch for what merged on 2026-11-19 and 2026-11-20, and the six-row alpha gate: alpha-blocker marks removed from row 4, F1 and F3 (not gate rows any more) and added to H3 and the new P4 (startup on older graphics hardware, #3336); F1 narrowed (-ATTEDIT, -RENAME and -LAYER options, #3311); F5 (ARRAY Key point, #2368); F7 (Dimension Style Manager, #1460; dimension values kept on save, #3335); F9 (double-click edits TEXT, attribute definitions and dimension text in place, #3345); F20 (right-click settings, interface reset, #3308); F24 (UCS in the drawing plane, #3310); FF6 (size limits, typed OPEN in the background, #3343); U13 and P3 (#3344 waits for a Mac); S3 count. Hours not re-estimated | | 2026-11-03 | minor | XCLIP (rectangular, polygonal and polyline boundaries, Invert clip, ON/OFF, Delete, generate Polyline) and XCLIPFRAME: a boundary per block or xref reference (`Insert::clip`, block coordinates), drawn, plotted and framed clipped, the extents cut to it, and read and written as the reference's ACAD_FILTER/SPATIAL SPATIAL_FILTER in DXF and DWG: F2 and top-10 row 4 narrowed | | 2026-11-03 | minor | SHX fonts: shape fonts, big fonts and unifonts read (`cadcraft_fonts::shx`, every count and offset bounded) and drawn for TEXT, MTEXT, attributes, dimensions and tables, with the style's big font and vertical flag; found by file name beside the drawing, in `CADCRAFT_SHXPATH`, through a font map or from `.shx` files opened in the web app, never in another CAD program's folder; FONTALT may name a font and a big font; linetype shape elements drawn when their file is found: FF8 and FF9 narrowed | | 2026-10-30 | minor | QSAVE asks before replacing a file with content the DWG writer can't keep, and ISAVEBAK keeps the previous file as `.bak`: row 1 narrowed, FF1 and F20 updated | diff --git a/docs/roadmap.md b/docs/roadmap.md index b9f49796e..8057b8529 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -1,6 +1,6 @@ # CADCraft roadmap detail -> **Last reviewed:** 2026-11-19 · **Last updated:** 2026-11-19 · **Change:** major (alpha gate revised from user reports: six rows, Windows first; current focus re-ranked into three tiers; percentages and hours not re-scored; previously minor: re-audit against main 41d9b5e95) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-11-19 · **Last updated:** 2026-11-20 · **Change:** minor (alpha gate evidence updated for what merged on 2026-11-19 and 2026-11-20; no row changes its verdict until the reporters confirm; previously major: alpha gate revised from user reports: six rows, Windows first; current focus re-ranked into three tiers; percentages and hours not re-scored; previously minor: re-audit against main 41d9b5e95) · **Target:** Autodesk AutoCAD 2027 Forward-looking plan: milestones with status, the current focus, and what comes next with estimates. The summary is [ROADMAP.md](../ROADMAP.md); the work items behind every line are in @@ -14,11 +14,11 @@ already written and waiting in a pull request lands before new work starts, firs 1. **Urgent: security fixes, leaks, crashes and lost work.** The open security-audit findings (#1919–#1935) are checked against the input limits that landed on 2026-11-11, then closed or - fixed; #1276 fixes the crafted-handle overwrite (#1921). Hostile-input fixes are waiting in - #2820, #2821 and #2765. Crashes and hangs with a reproduction come next: #1603 (web, large DXF), + fixed; #1276 fixes the crafted-handle overwrite (#1921). The hostile-input fixes #2820, #2821 and #2765 landed on + 2026-11-20 (#3304, #3305). Crashes and hangs with a reproduction come next: #1603 (web, large DXF), #2174 (DWG with 3D content), #1724, #1631 and #3222 (startup). 2. **Parity with AutoCAD.** The failing [alpha gate](#alpha-gate) rows in their order, then the - [beta checklist](#beta-checklist), apart from the checklist items named under tier 3. 714 pull requests are open (2026-11-19); about 230 of them are + [beta checklist](#beta-checklist), apart from the checklist items named under tier 3. 661 pull requests are open (2026-11-20; 714 the day before); about 230 of them were mergeable, pass CI and are small, and many already fix a gate row. 3. **Lower priority.** Work that affects fewer people and that nothing breaks without: dynamic-block authoring, editing an xref in place, exact ellipse and spline geometry, prompt options that need @@ -40,12 +40,12 @@ evidence has limits: there is no telemetry, and someone whose copy never starts | Row | Passes? | Evidence | Passes when | |---|---|---|---| -| It starts on the hardware people have | **no** | Black window or a crash at startup on older Intel graphics, older macOS and some virtual machines (#1724, #1631, #3222, #1780); `CADCRAFT_STENCIL=0` is waiting in #1596; no automatic fallback renderer | It reaches a usable drawing area on Windows 10 and 11 with old integrated graphics, in a virtual machine, and on the supported macOS and Linux versions, choosing a fallback renderer by itself | -| It opens the DWG and DXF files people already have, correctly and in reasonable time | **no** | Large DWGs are refused at a size limit or freeze the window (#3102, #2633, #1088); layouts come in at the wrong scale or in the wrong units (#1672, #2836); a DWG with 3D content crashes or opens empty (#2174); the corpus holds four files, all written by CADCraft, and CI does not run it | A corpus of files made by AutoCAD and other CAD programs opens in CI with its objects, layouts, viewports and units right, compared with what the program that wrote it shows; a large file opens or says clearly why not; content we don't model is kept and never crashes | -| Saving loses nothing, and other CAD programs open the result | **no** | DXF keeps what we don't model (#528); other applications' objects are kept as proxies (#2917, #2919, #2654); through DWG, custom-class objects without data for the version written are still dropped; fixes for files AutoCAD or BricsCAD refuse are waiting (#2904, #1687, #3234); never checked against a corpus in AutoCAD | The corpus round-trips with every object kept and its geometry and properties unchanged, a save names anything it could not keep, and AutoCAD opens the saved files without a recovery prompt | -| Input feels like AutoCAD for Windows | **partial, blocking** | Running snaps, polar, ortho, coordinate entry, tracking, FROM/M2P/TK and dynamic input work; a click while the mouse moves can be lost (#1001, #2092), right-click and Space don't always act as Enter (#1387), a double-click doesn't edit TEXT in place (#842); fixes are waiting in pull requests | A click counts while the pointer moves; right-click and Space repeat or confirm as set in Options; a double-click edits text, multiline text and dimension text in place | +| It starts on the hardware people have | **no** | Black window or a crash at startup on older Intel graphics, older macOS and some virtual machines (#1724, #1631, #3222, #1780); `CADCRAFT_STENCIL=0` starts without a stencil buffer (#3336) but must be set by hand, and no reporter has confirmed it yet; no automatic fallback renderer | It reaches a usable drawing area on Windows 10 and 11 with old integrated graphics, in a virtual machine, and on the supported macOS and Linux versions, choosing a fallback renderer by itself | +| It opens the DWG and DXF files people already have, correctly and in reasonable time | **no** | Large DWGs are refused at the shared DWG library's size limit (#3102, #2633, #1088); a typed OPEN reads in the background (#3343), but an open can't be cancelled and shows no progress; a layout's paper units are explicit and kept since #3309 (#2836 closed; #1672 open); a DWG with 3D content crashes or opens empty (#2174); the corpus holds four files, all written by CADCraft, and CI does not run it | A corpus of files made by AutoCAD and other CAD programs opens in CI with its objects, layouts, viewports and units right, compared with what the program that wrote it shows; a large file opens or says clearly why not; content we don't model is kept and never crashes | +| Saving loses nothing, and other CAD programs open the result | **no** | DXF keeps what we don't model (#528); other applications' objects are kept as proxies (#2917, #2919, #2654); through DWG, custom-class objects without data for the version written are still dropped; an edited dimension keeps its values on save (#3335); fixes for files AutoCAD or BricsCAD refuse landed on 2026-11-20 (#2904, #1687, #3234, #1728, #2882), and a file saved from a Rhino drawing still crashes AutoCAD 2021 as DWG (#3303); never checked against a corpus in AutoCAD | The corpus round-trips with every object kept and its geometry and properties unchanged, a save names anything it could not keep, and AutoCAD opens the saved files without a recovery prompt | +| Input feels like AutoCAD for Windows | **partial, blocking until confirmed** | Running snaps, polar, ortho, coordinate entry, tracking, FROM/M2P/TK and dynamic input work; landed on 2026-11-20 and not yet confirmed by the people who reported them: a click counts where the button goes down (#3307; #1001, #2092), a quick right-click and Space act as Enter (#3307; #1387), a double-click edits TEXT, attribute definitions and dimension text in place (#3345; #842 stays open for table cells) | A click counts while the pointer moves; right-click and Space repeat or confirm as set in Options; a double-click edits text, multiline text and dimension text in place | | Draft, dimension and annotate a sheet, with styles | partial, not blocking | All core DIM types, associativity, the Dimension Style Manager (#1460), TEXT/MTEXT, MLEADER, tables, the in-place MTEXT editor, blocks with attributes, xrefs, the Block Editor and REFEDIT work; a few prompt options still print "not available yet" ([gaps.md](gaps.md) F1); ellipse and spline intersections are approximate | No "not available yet" in the most-used draw, modify and annotate commands, apart from options that need 3D | -| Lay out and print a sheet at scale, and the interface can always be restored | **partial, blocking** | Layers, layouts, viewports, page setups, PDF output, plot styles, the Plot dialog, preview and PUBLISH work; a print can come out off scale (#3216); printers are reached only through PDF, PNG and SVG files (F14, H3); a hidden menu bar or closed panels can't always be brought back (#1240) | A metric sheet prints 1:1 on a system printer, and one command or key restores the menu bar and default panels from any state | +| Lay out and print a sheet at scale, and the interface can always be restored | **partial, blocking** | Layers, layouts, viewports, page setups, PDF output, plot styles, the Plot dialog, preview and PUBLISH work; a print can come out off scale (#3216); printers are reached only through PDF, PNG and SVG files (F14, H3); MENUBAR, TOOLBAR and Options ▸ Reset bring a hidden menu bar and closed panels back (#3308; #1240 closed), and metric sheets are in millimetres (#3309) | A metric sheet prints 1:1 on a system printer, and one command or key restores the menu bar and default panels from any state | Moved to the beta checklist on 2026-11-19, with the reports behind each: dynamic-block authoring (none), editing an xref in place (one), exact ellipse and spline intersections (one). @@ -114,6 +114,7 @@ AutoLISP surface, AI features with openly licensed local models, and every remai | Date | Change | Summary | |---|---|---| +| 2026-11-20 | minor | Alpha gate evidence updated for what merged on 2026-11-19 and 2026-11-20: the stencil switch (#3336), typed OPEN in the background (#3343), paper units (#3309), dimension values kept on save (#3335), clicks while moving and right-click or Space as Enter (#3307), in-place text editing (#3345), the interface reset (#3308). No verdict changed: the input row waits for confirmation from the reporters; pull-request count 714 → 661 | | 2026-11-19 | major | Alpha gate revised from user reports: six rows (starts on common hardware; opens existing files; saves without loss; input feel; draft and annotate with styles; print at scale and a restorable interface), main platform Windows; dynamic-block authoring, xref editing in place and exact curve geometry counted under beta only; current focus re-ranked into three tiers; percentages and hours not re-scored | | 2026-10-24 | minor | Re-audit against main 41d9b5e95: alpha-gate evidence, CI gate (#1987), beta-checklist states, open-PR and catalog counts re-checked against main 41d9b5e95; percentages and hours not re-scored | | 2026-10-13 | minor | Re-audit against main e707ab4d: alpha-gate evidence for drafting, annotation, blocks and DWG rows; beta-checklist states for DWG/DXF, blocks and languages; current-focus items 4–7; milestone notes M1, M12, M13; percentages and hours not re-scored | From 4076a71dee32b60a04a6eb6157359d3a56e58d36 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 16:40:26 -0700 Subject: [PATCH 15/19] Registered applications alone note no file version; the APPID tests that save DWG opt in to the in-process bridge --- crates/io/src/dxf_raw.rs | 7 +++++-- crates/io/tests/registered_applications_kept.rs | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/crates/io/src/dxf_raw.rs b/crates/io/src/dxf_raw.rs index aaa44a1f6..3c1b7d124 100644 --- a/crates/io/src/dxf_raw.rs +++ b/crates/io/src/dxf_raw.rs @@ -350,8 +350,7 @@ pub(crate) fn read(secs: &[SectionRef<'_>], d: &mut Drawing) { !by_handle.contains_key(&o) && xdict_of.get(&o) == Some(&h) && (ents.contains_key(&o) || ids.contains_key(&o)) }; let memo = retained_objects(&objects, &ents, &ids, &by_handle, root.as_deref(), &root_entries, &xdict_of); - let appids = tables.iter().filter(|(k, _, _)| k == "APPID").filter_map(|(_, _, t)| val(t, 2)).map(|n| n.trim().to_string()); - let mut f = Foreign { appids: appids.take(MAX_OBJECTS).collect(), ..Foreign::default() }; + let mut f = Foreign::default(); let mut kept: HashSet = HashSet::new(); for (i, (kind, _, t)) in objects.iter().enumerate() { if memo.get(&i) != Some(&true) || f.objects.len() >= MAX_OBJECTS { @@ -458,6 +457,10 @@ pub(crate) fn read(secs: &[SectionRef<'_>], d: &mut Drawing) { if !f.is_empty() { f.version = file_version(secs); } + // Added after the version: registered applications alone are no kept objects whose groups + // the DWG writer must read as the file's version, and nearly every file has some (ACAD). + let appids = tables.iter().filter(|(k, _, _)| k == "APPID").filter_map(|(_, _, t)| val(t, 2)).map(|n| n.trim().to_string()); + f.appids = appids.take(MAX_OBJECTS).collect(); // The file's handles of the objects CADCraft writes itself (AutoLISP's `handent`). f.handles = ids.iter().filter(|(h, _)| !ents.contains_key(*h)).filter_map(|(h, k)| Some((handle(h)?, k.clone()))).take(MAX_OBJECTS).collect(); if !f.is_empty() || !f.handles.is_empty() { diff --git a/crates/io/tests/registered_applications_kept.rs b/crates/io/tests/registered_applications_kept.rs index 4c548700b..1be4e0952 100644 --- a/crates/io/tests/registered_applications_kept.rs +++ b/crates/io/tests/registered_applications_kept.rs @@ -79,6 +79,7 @@ fn appids(text: &str) -> usize { #[test] fn registered_applications_no_xdata_names_are_kept() { + cadcraft_io::dwg_worker::allow_in_process(); let mut d = read_dxf(source(false).as_bytes()).expect("read"); for generation in 1..=2 { let text = write_dxf(&d); @@ -95,6 +96,7 @@ fn registered_applications_no_xdata_names_are_kept() { /// An application both registered and named by xdata, in another case, gets one record. #[test] fn a_registered_application_xdata_names_gets_one_record() { + cadcraft_io::dwg_worker::allow_in_process(); let mut d = read_dxf(source(true).as_bytes()).expect("read"); for generation in 1..=2 { let text = write_dxf(&d); @@ -108,3 +110,12 @@ fn a_registered_application_xdata_names_gets_one_record() { assert_eq!(appids(&write_dxf(&d)), 1, "DWG {generation}"); } } + +/// Registered applications alone are not kept objects: a file with nothing else to keep notes no +/// version, so the DWG writer reads its R2000 text as before rather than as the file's version. +#[test] +fn registered_applications_alone_note_no_version() { + let d = read_dxf(source(false).as_bytes()).expect("read"); + assert!(d.foreign.appids.iter().any(|n| n == "Other_App"), "{:?}", d.foreign.appids); + assert_eq!(d.foreign.version, None); +} From 318d8d9de1201b53b506d9903456fcad0a54fc81 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 16:40:30 -0700 Subject: [PATCH 16/19] Plot layout flag tests that save DWG opt in to the in-process bridge --- crates/io/tests/it/layout_plot_flags.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/io/tests/it/layout_plot_flags.rs b/crates/io/tests/it/layout_plot_flags.rs index 2044505f7..35d6cdeb9 100644 --- a/crates/io/tests/it/layout_plot_flags.rs +++ b/crates/io/tests/it/layout_plot_flags.rs @@ -30,6 +30,7 @@ fn flags_after_save(d: &Drawing, name: &str) -> Option { #[test] fn plot_layout_flags_are_saved_as_read() { + cadcraft_io::dwg_worker::allow_in_process(); for name in ["sheet.dxf", "sheet.dwg"] { for flags in [0, 176, 560, 688] { assert_eq!(flags_after_save(&drawing(flags), name), Some(flags), "{name}: flags {flags}"); @@ -39,6 +40,7 @@ fn plot_layout_flags_are_saved_as_read() { #[test] fn an_unchanged_standard_scale_keeps_its_flag_and_choice() { + cadcraft_io::dwg_worker::allow_in_process(); // Flags 176 with standard scale 25 (1:50): the scale is 0.02, not 1:1, and still standard. let mut d = drawing(176); let page = &mut d.layouts.last_mut().unwrap().page; From 20d489f059d5729f8b838c4051cfebda91cf3a86 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 16:43:29 -0700 Subject: [PATCH 17/19] ROADMAP: TRIM/EXTEND depth landed, drop it from Upcoming --- ROADMAP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index 3ccc2bbf5..e30b0d73f 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -128,7 +128,7 @@ and the beta checklist are in [docs/roadmap.md](docs/roadmap.md). - Input feels like AutoCAD for Windows: the fixes for clicks while the mouse moves, right-click and Space as Enter, and double-click text editing landed (#3307, #3345); waiting for the reporters to confirm, and table cells are left (#842). -- The prompt options that still say "not available yet", and TRIM/EXTEND depth. +- The prompt options that still say "not available yet" (gaps F1). - Layouts print at scale on a system printer (#3216); the menu bar and panels can be restored since #3308. - 661 pull requests are open (2026-11-20; 714 the day before). About 230 were mergeable, passed CI and were small; they are From b39170aded9c9734b932ff0f85c92c71a51d1d6f Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 16:45:17 -0700 Subject: [PATCH 18/19] HATCHGENERATEBOUNDARY: a mirrored hatch's boundary goes to its world height; the command is classified as using no files --- crates/engine/src/cmd/hatch/edit.rs | 10 +++++--- crates/engine/src/file_access/commands.rs | 1 + .../tests/it/hatch_generate_boundary.rs | 23 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/hatch/edit.rs b/crates/engine/src/cmd/hatch/edit.rs index dfcd96944..0590dbe7a 100644 --- a/crates/engine/src/cmd/hatch/edit.rs +++ b/crates/engine/src/cmd/hatch/edit.rs @@ -33,7 +33,7 @@ fn hatches(s: &Session, p: &Value) -> Result> { const MAX_GENERATED: usize = 10_000; /// HATCHGENERATEBOUNDARY: a closed polyline around every boundary loop (outer and islands) of -/// the selected hatches, at each hatch's elevation. The hatches are not changed: an associative +/// the selected hatches, at each hatch's height. The hatches are not changed: an associative /// hatch stays linked to its own boundary objects and is not linked to the new polylines. pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result { let selected = targets(s, p)?; @@ -46,7 +46,8 @@ pub(super) fn run_hatchgenerateboundary(s: &mut Session, p: &Value) -> Result Result MAX_GENERATED.saturating_sub(loops.len()) { return Err(bad("hatchgenerateboundary", format!("more than {MAX_GENERATED} boundary polylines in one call; select fewer hatches"))); } - loops.extend(x.loops.iter().map(|l| (l.vertices.clone(), x.elevation))); + // The elevation runs along the hatch's normal: one facing down Z (mirrored) lies at its + // negative, where the polyline, facing up, goes. + let z = if e.common.extrusion.z < 0.0 { -x.elevation } else { x.elevation }; + loops.extend(x.loops.iter().map(|l| (l.vertices.clone(), z))); } } if !found { diff --git a/crates/engine/src/file_access/commands.rs b/crates/engine/src/file_access/commands.rs index c72521c9a..7b26f14f8 100644 --- a/crates/engine/src/file_access/commands.rs +++ b/crates/engine/src/file_access/commands.rs @@ -235,6 +235,7 @@ pub const NO_FILES: &[&str] = &[ "boundary", "region", "hatchedit", + "hatchgenerateboundary", "hatchpick", "overkill", "block", diff --git a/crates/engine/tests/it/hatch_generate_boundary.rs b/crates/engine/tests/it/hatch_generate_boundary.rs index 3266042dd..f79c4aca3 100644 --- a/crates/engine/tests/it/hatch_generate_boundary.rs +++ b/crates/engine/tests/it/hatch_generate_boundary.rs @@ -116,6 +116,29 @@ fn boundaries_keep_the_hatch_elevation() { assert_eq!(poly(&s, &handles(&v)[0]).elevation, 300.0); } +/// A mirrored hatch (normal 0,0,-1, as exploding a mirrored block makes) at elevation 300 lies at +/// world Z -300; its boundary, facing up, goes there too, not to +300. +#[test] +fn a_mirrored_hatchs_boundary_keeps_its_world_height() { + let mut s = Session::new(); + let r = rect(&mut s, [0.0, 0.0], [4.0, 2.0]); + let h = handle(&s.execute("hatch", &json!({ "handles": [r] })).unwrap()); + s.doc_mut() + .unwrap() + .modify_entity(Handle::parse_hex(&h).unwrap(), |e| { + e.common.extrusion = cadcraft_engine::geom::Vec3::new(0.0, 0.0, -1.0); + if let EntityKind::Hatch(x) = &mut e.kind { + x.elevation = 300.0; + } + }) + .unwrap(); + let v = s.execute("hatchgenerateboundary", &json!({ "handles": [h] })).unwrap(); + let new = Handle::parse_hex(&handles(&v)[0]).unwrap(); + let e = s.doc().unwrap().entity(new).unwrap().clone(); + let EntityKind::LwPolyline(p) = &e.kind else { panic!("not a polyline") }; + assert_eq!(e.common.extrusion.z.signum() * p.elevation, -300.0); +} + #[test] fn refuses_a_hatch_in_another_space_and_adds_nothing() { let mut s = Session::new(); From f4d4a6e4e17494fd03d91d235b9b704e05ea7a28 Mon Sep 17 00:00:00 2001 From: Tanish Manku Date: Fri, 20 Nov 2026 17:37:24 -0700 Subject: [PATCH 19/19] DXF read: a thick polyline drawn as seen from above keeps the side of Z it extruded toward --- crates/io/src/dxf_read/entities.rs | 10 ++++++++++ crates/io/src/tests.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/crates/io/src/dxf_read/entities.rs b/crates/io/src/dxf_read/entities.rs index ce3c9a76c..9d888af5a 100644 --- a/crates/io/src/dxf_read/entities.rs +++ b/crates/io/src/dxf_read/entities.rs @@ -88,6 +88,7 @@ fn lwpolyline(tags: &[Tag], c: &mut Common, t: &T) -> Option { // In a tilted plane: drawn as seen from above, at the vertices' mean height, its // vertices now plan coordinates. (verts, elevation) = plan_of_tilted(c.extrusion, elevation, &verts, flags & 1 != 0); + thickness_along_z(c); c.extrusion = Vec3::Z; } else if c.extrusion.z < 0.0 { for v in &mut verts { @@ -606,6 +607,7 @@ pub(super) fn polyline_entity(recs: &[(String, &[Tag])], i: &mut usize, t: &T) - let mut elevation = t.p(10).z; if tilted(c.extrusion, run_points(&vertices, elevation, closed)) { (vertices, elevation) = plan_of_tilted(c.extrusion, elevation, &vertices, closed); + thickness_along_z(&mut c); c.extrusion = Vec3::Z; } else if c.extrusion.z < 0.0 { for v in &mut vertices { @@ -726,3 +728,11 @@ fn helix(tags: &[Tag]) -> Helix { } .sanitized() } + +/// A polyline drawn as seen from above gets the normal +Z: its thickness keeps the side of Z it +/// extruded toward, which the normal it is losing said. +fn thickness_along_z(c: &mut Common) { + if c.extrusion.z < 0.0 { + c.thickness = -c.thickness; + } +} diff --git a/crates/io/src/tests.rs b/crates/io/src/tests.rs index 3a689db2a..f19bdb409 100644 --- a/crates/io/src/tests.rs +++ b/crates/io/src/tests.rs @@ -2805,6 +2805,20 @@ fn tilted_hatch_turns_its_gradient() { assert!((g.angle - std::f64::consts::PI).abs() < 1e-9, "gradient angle {}", g.angle); } +/// A tilted polyline with a thickness, its normal pointing partly down Z, still extrudes toward -Z +/// once it is drawn as seen from above and saved with no normal. +#[test] +fn tilted_thick_polyline_keeps_its_extrusion_side() { + let text = "0\nSECTION\n2\nENTITIES\n0\nLWPOLYLINE\n8\n0\n90\n2\n70\n0\n39\n5\n210\n0\n220\n0.5\n230\n-0.8660254037844386\n\ + 10\n1\n20\n0\n10\n3\n20\n2\n0\nENDSEC\n0\nEOF\n"; + let d = read(text.as_bytes(), "p.dxf").unwrap(); + let e = d.model.iter().next().unwrap(); + assert_eq!((e.common.thickness, e.common.extrusion), (-5.0, Vec3::Z)); + let back = roundtrip(&d); + let e = back.model.iter().next().unwrap(); + assert_eq!((e.common.thickness, e.common.extrusion), (-5.0, Vec3::Z), "saved with no normal, it still extrudes toward -Z"); +} + /// A straight tilted LWPOLYLINE keeps its vertex widths (groups 40/41) on the projected vertices. #[test] fn tilted_straight_lwpolyline_keeps_its_widths() {