Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contributors/people.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ real_name = "Richard Sauer"
display_name = "Richard Sauer"
sync_github_name = false

[people.assamaral]
real_name = "assamaral"
sync_github_name = false
17 changes: 16 additions & 1 deletion crates/io/src/dxf_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ fn entity_with_table_budget(kind: &str, tags: &[Tag], table_cells_left: &mut usi
height: t.fd(41, 1.0),
view_center: Vec2::new(t.fd(12, 0.0), t.fd(22, 0.0)),
view_height: t.fd(45, 1.0),
id: t.i(69).unwrap_or(0) as u32,
// ZWCAD writes -1 (unknown): 0 here, numbered in order below.
id: t.i(69).filter(|i| *i > 0).unwrap_or(0) as u32,
locked: t.i(90).unwrap_or(0) & 16384 != 0,
frozen_layers: crate::dxf_ext::read_frozen(tags),
layer_colors: crate::dxf_ext::read_layer_colors(tags),
Expand Down Expand Up @@ -1866,6 +1867,20 @@ fn read_budgeted(bytes: &[u8], mut table_cells_left: usize) -> Result<Drawing> {
d.model.push(e);
}
}
// A layout whose viewports all lack an id (ZWCAD writes 69 = -1) gets them numbered in file
// order, as DWG readers do: its first viewport is the paper-space one (id 1), so saving does
// not add a second sheet viewport ahead of it (#1463).
for l in d.layouts.iter_mut() {
let vps: Vec<Entity> = l.entities.iter().filter(|e| matches!(&e.kind, EntityKind::Viewport(_))).map(|e| (**e).clone()).collect();
if vps.iter().all(|e| matches!(&e.kind, EntityKind::Viewport(v) if v.id == 0)) {
for (i, mut e) in vps.into_iter().enumerate() {
if let EntityKind::Viewport(v) = &mut e.kind {
v.id = i as u32 + 1;
}
l.entities.replace(e);
}
}
}
apply_sortents(&mut d, &objs.sortents, &rx.brs, &paper_block_for, &first_layout);
objs.apply(&mut d, &rx);
crate::dxf_image::resolve(&secs, &mut d);
Expand Down
48 changes: 48 additions & 0 deletions crates/io/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,54 @@ fn viewport_frozen_layers_roundtrip() {
assert!(frozen.contains(&(3, Vec::new())), "{frozen:?}");
}

/// `Layout1` with viewports 1 (the sheet), 2 and 3, written to DXF and read back with the id (69)
/// of every viewport `blank` names replaced by -1 (ZWCAD's "unknown"): the ids and widths read.
fn viewport_ids_read_back(blank: impl Fn(&str) -> bool) -> (Drawing, Vec<(u32, f64)>) {
let mut d = sample();
let paper = Space::Paper("Layout1".into());
for (id, w) in [(1, 420.0), (2, 8.0), (3, 4.0)] {
let vp = Viewport {
center: Vec3::new(5.0, 4.0, 0.0),
width: w,
height: 6.0,
view_center: Vec2::new(5.0, 4.0),
view_height: 6.0,
id,
..Viewport::default()
};
d.add(&paper, Common::default(), EntityKind::Viewport(vp)).unwrap();
}
let text = write_dxf(&d);
let mut lines: Vec<String> = text.lines().map(String::from).collect();
for i in (0..lines.len() - 1).step_by(2) {
if lines[i].trim() == "69" && blank(lines[i + 1].trim()) {
lines[i + 1] = "-1".into();
}
}
let back = read_dxf(lines.join("\n").as_bytes()).unwrap();
let ids =
back.layouts[0].entities.iter().filter_map(|e| if let EntityKind::Viewport(v) = &e.kind { Some((v.id, v.width)) } else { None }).collect();
(back, ids)
}

/// ZWCAD writes every VIEWPORT with id (69) -1: they are numbered in file order, the first being
/// the paper-space viewport, so saving adds no second sheet viewport (#1463).
#[test]
fn viewport_ids_unknown_are_numbered_in_order() {
let (back, ids) = viewport_ids_read_back(|_| true);
assert_eq!(ids, [(1, 420.0), (2, 8.0), (3, 4.0)]);
assert!(!write_dxf(&back).contains("PAPERVIEW"), "the layout already has its paper-space viewport");
}

/// A layout that mixes known ids with -1 is left alone: the known ids stay, the unknown one reads
/// as 0 (not numbered), as before #1463.
#[test]
fn viewport_ids_mixed_are_kept() {
let (back, ids) = viewport_ids_read_back(|v| v == "2");
assert_eq!(ids, [(1, 420.0), (0, 8.0), (3, 4.0)]);
assert!(!write_dxf(&back).contains("PAPERVIEW"), "viewport 1 is still the sheet");
}

/// A layout with viewport 2 frozen on `Walls` and `A B` (both real layers), and its written DXF as
/// (code, value) pairs.
fn frozen_vp_dxf() -> (Drawing, Vec<(String, String)>) {
Expand Down
3 changes: 2 additions & 1 deletion docs/file-format-parity.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# File-format parity

> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (DIMASSOC objects for angular, diametric and radial dimensions) · **Target:** Autodesk AutoCAD 2027
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (DXF read: viewports without ids numbered in file order) · **Target:** Autodesk AutoCAD 2027

Every format AutoCAD 2027 reads or writes, with CADCraft's support, fidelity and tests. Work
items are in [gaps.md](gaps.md#file-formats); the weighted score feeds
Expand Down Expand Up @@ -140,6 +140,7 @@ our output in AutoCAD black-box.

| Date | Change | Summary |
|---|---|---|
| 2026-10-24 | minor | DXF read: a layout whose VIEWPORTs all carry id (69) -1 (ZWCAD writes no ids) gets them numbered in file order, the first being the paper-space viewport, so a save no longer adds a second sheet viewport that turns the real one into a model viewport and inflates the drawing extents (#1463) |
| 2026-10-22 | minor | DXF/DWG save: angular, diametric and radial dimensions get standard DIMASSOC objects (one centre reference to the circle for radial/diametric, the definition points for angular), so AutoCAD follows their geometry; the standard objects of those kinds are read back too, without CADCraft's xdata (#1651) |
| 2026-10-19 | minor | DXF/DWG save: angular dimension block text honors DIMDSEP, including per-dimension overrides (#1646) |
| 2026-10-19 | minor | A file's own arrowhead blocks with standard names (AutoCAD's `_Dot`, `_DotSmall`), named only by a dimension style, are kept and saved as they were instead of being replaced by CADCraft's solids; PURGE keeps arrowhead blocks dimension styles name |
Expand Down