Skip to content

Drawing export: a sheet exported to a file runs in the background, like the view DXF (#4890) - #10431

Merged
bherbruck merged 2 commits into
tangency-labs:drawingsfrom
CamWight:drawing-export-png-4890-ex2
Nov 7, 2026
Merged

bherbruck merged 2 commits into
tangency-labs:drawingsfrom
CamWight:drawing-export-png-4890-ex2

Conversation

@CamWight

@CamWight CamWight commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

A sheet exported to a file through the control channel was drawn and written on the window's thread. A large PNG at a high dpi held the window up until it was done. Now drawing.export with a path runs in the background the way the view DXF export does. The window keeps drawing, an "Exporting sheet" card shows the rows done, and Cancel on it stops a PNG between bands.

Part of #4890 (EX2), into drawings. It replaces this PR's earlier version (a separate export job with its own status and cancel commands). That version is gone. This one is two commits on the latest drawings: the background export, then a held sheet's lines in it.

Changes a default: no
The command, its parameters, its reply and the file it writes are the same. Only where it runs changes.

What it does

  • Through file_load, like the view DXF: Kind::ExportSheet sits beside Kind::ExportDxf. control sends a drawing.export that has a path to the worker thread, on a copy of the design, and answers the caller when the file is in. Without a path the reply holds the document, which is quick, so it runs at once as before.
  • One rule for "an export": Kind::exports() now holds what the two kinds share: the copy of the design, never adopting the worker's session, Cancel waiting for the worker, a drop cancelling it, and a finished export staying finished. That replaces seven separate == Kind::ExportDxf tests and a check on the command's name.
  • Progress and Cancel between bands: paper_png already draws a band of rows at a time. Before each band it now reports ("sheet_png", rows done, rows) to the current solidcraft_kernel::watch, and it stops with "the sheet PNG: cancelled" once that watch is cancelled. The command writes the file only after the PNG is complete, so a cancelled export writes nothing. With no watch, which is every other caller, nothing changes: the byte-for-byte PNG tests pass as they were.
  • Why those lines are in crates/io: the band loop is the only place that knows how far a PNG has got. crates/io already depends on solidcraft-kernel, so there is no new dependency. The other choice was a progress parameter on paper_png, which would change it for every caller to carry what the watch already carries.
  • Unchanged: drawing.export's checks and its write, the commands, the schema and the file format. No command is added, so there are no new EXEMPT lines.
  • What Cancel says: the card's Cancel said "DXF export cancelled" for any export, which was right while the view DXF was the only one. It now says which export it stopped, so a sheet says "Sheet export cancelled".
  • Strings: drawing_export.exporting, drawing_export.progress.rows and drawing_export.cancelled (with its UK spelling in en-GB), in assets/locales/pending/drawing-export-background.json.

Nothing in the window calls drawing.export yet (the sheet page's Export button is still drawing.export.planned). When it does, it can start a Request::new(path, Kind::ExportSheet) the way dialogs_view_dxf.rs starts the view DXF.

A held sheet exports what the page shows

A drawing can be set to update only when asked ("updates": "deferred"). After a model change it keeps its last lines until Update. The page showed them, but the background export did not. It ran on Session::scratch, whose drawing cache is empty, so a held sheet came out with no views or dimensions. @theironchef found this.

  • The copy it runs on: the two export kinds now take Session::scratch_as_shown. That is scratch() plus Cache::shown_copy.
  • What the copy holds: the world state of the last update, each view's and dimension's last drawing, and the serial they were numbered to. The serial keeps the copy's numbers from repeating the entries' own.
  • What it leaves out: the lines kept for closed drawings, the last answer and a view in flight. Only the window's page uses them.
  • Why not in scratch() itself: inserts, updates, previews and dialogs use scratch() and never draw a sheet. They would copy every view's lines for nothing.

Validation

Local, Windows, --profile ci, on drawings 8067a0a, then replayed onto 69709bd (only #12232 in between, which touches none of these files), with cargo check --all-targets again on the replayed commit:

  • cargo check --all-targets, fmt, xtask lists and xtask i18n --check pass.
  • clippy on io, engine and ui-egui, all targets, -D warnings, passes.
  • cargo xtask wasm: 14 crates build for wasm32.
  • Tests: io paper 43 passed, the engine's drawing tests 324 passed, ui-egui file_load 30 passed, 0 failed.

Tests first: the io and engine tests fail on the base and pass with the change.

  • io: a_watched_sheet_png_reports_its_rows_and_stops_when_cancelled.
  • engine: a_cancelled_png_export_writes_no_file (unwatched, the same request writes the file).
  • ui-egui: a_sheet_export_to_a_file_runs_off_the_window_thread, and the view DXF's frames-and-session test, now run for both kinds. That test now also checks what Cancel says for each kind, and drops a running export and checks it is cancelled, which nothing tested before for either kind.

The held sheet (second commit): on drawings 2a25449, then replayed onto 594945b (no shared files; cargo check --all-targets and fmt again).

  • Tests: the engine's drawing scene and export tests 86 passed, ui-egui file_load 29 passed, io png 24 passed.
  • New: a_held_deferred_drawing_exports_the_same_from_a_scratch_copy. It compares the svg and out_of_date from the session and from the copy. The cases are a drawing that isn't deferred, the same after a view's edit, a deferred one after its update with a view edited since, and a held one. The held one is checked on the sheet last shown and on a second sheet.
  • The window test now writes a held sheet through the background export and compares the file with the synchronous export.
  • Planted faults, 5 of 5 caught, and the clean runs pass after them: the copy a plain scratch(), its last update left out, the views' entries left out, the dimensions' entries left out, and file_load back on scratch().
  • Explained, not planted: a copy that numbers from 0 instead of the cache's serial. A view drawn again reads its dimensions again in the same step, and the copy has no last answer to match an old number against, so every path a test can drive exports the same. The serial is copied so that the numbers never repeat.
  • Gate on the affected crates: every check passes. The failing tests are the same set as on the base, none in the files changed here.

Planted faults: 10 of 11 caught, and the clean runs pass after them. They cover:

  • the cancel check skipped (seen by the io and the engine tests);
  • progress never reported;
  • a watched export refused until cancelled;
  • an export without a path sent to the worker;
  • the path dropped from the options;
  • the worker's session adopted;
  • a drop that doesn't cancel (missed at first; the drop test above was added for it);
  • drawing.export not sent to the worker;
  • a cancelled sheet export saying the DXF was cancelled.

The one not caught: a finished export reported as cancelled when Cancel comes in after the file is written. Testing it needs Cancel to land between the command writing the file and the worker's next check, which only a race with another thread can do. The view DXF's version of this line had no test either.

Not covered:

  • An export button in the window: there isn't one yet (above).
  • A late Cancel after the file is written (above).
  • A sheet at the size this is for: the tests use small sheets. The card was checked in the real app on a large one (below).
  • A held sheet exported while one of its views is being drawn beside the window. The copy has no request in flight, so it draws that view itself. The result is the same, but the work isn't shared.

Screenshots of the behavior

The drawing recipe's plate with its top view on an A3 sheet, exported through the control channel as a PNG at 2400 dpi (39686 x 28063 pixels) to a file:

While it runs: the window keeps drawing, and the card shows the rows drawn so far.

The Exporting sheet card over the model, with big.png, Drawing the sheet's rows: 10395/28063, a progress bar and Cancel

After Cancel: the toast says "Sheet export cancelled" (it said "DXF export cancelled" before this change). The caller got "file operation cancelled", and there is no file at the path. A 150 dpi export straight after it finished and wrote its file.

The model with a Sheet export cancelled toast at the bottom right

A held sheet, written in the background: the drawing recipe's plate, with its top view at 1:2 and a length dimension. The drawing is deferred and was updated with the plate 140 mm long. Then the model went back to 100 mm (a restored checkpoint), so the sheet is held. drawing.export with a path wrote this file in the background. It has the last update's view and its 140.00 dimension, and the reply lists the view out of date. The same export without a path gives the same bytes. The window has no sheet page yet, so the picture is the exported sheet itself.

An A3 sheet with the plate's top view, 140 mm long with two bores, and its 140.00 length dimension, written by the background export while the model is 100 mm long

Before this change the same file had no views or dimensions: the window test's planted fault (the export back on scratch()) shows it. A build of the earlier head couldn't reach a held sheet over the control channel, so there is no app picture of it.

Integration status

Two commits on drawings 594945b, the latest when pushed.

@github-actions github-actions Bot added area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES area:ui desktop/web front end, dialogs, viewport labels Nov 1, 2026
@CamWight
CamWight force-pushed the drawing-export-png-4890-ex2 branch from 43287fa to 546c159 Compare November 2, 2026 03:27
@CamWight CamWight changed the title Drawing export: a large sheet PNG written as a job, a band at a time (#4890 EX2) Drawing export EX2: a large sheet PNG is written in the background, so the window keeps responding (#4890) Nov 2, 2026
@CamWight CamWight changed the title Drawing export EX2: a large sheet PNG is written in the background, so the window keeps responding (#4890) Drawing export: a large sheet PNG is written in the background, so the window keeps responding (#4890) Nov 3, 2026
@CamWight
CamWight force-pushed the drawing-export-png-4890-ex2 branch from 546c159 to 953a9d8 Compare November 3, 2026 13:08
@CamWight
CamWight force-pushed the drawing-export-png-4890-ex2 branch from 953a9d8 to c51daba Compare November 5, 2026 11:39
@CamWight CamWight changed the title Drawing export: a large sheet PNG is written in the background, so the window keeps responding (#4890) Drawing export: a sheet exported to a file runs in the background, like the view DXF (#4890) Nov 5, 2026
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@theironchef theironchef left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read at c51daba4d (source only, not built locally). The routing looks right: control sends a drawing.export to the worker only when it has a path, and Kind::exports() replaces the seven == Kind::ExportDxf checks one for one. The band check in paper_png costs nothing when nothing is watching.

One interaction to check before merging: a deferred drawing exported in the background.

This branch is from before #12449 ("a deferred drawing keeps its lines until it is updated"). GitHub shows it as mergeable, but the two may disagree once both are in:

  • On drawings today, what a deferred drawing may draw from lives in the session's drawing_scenes cache: Cache::updated (drawing_scene.rs:672) and the views and dimensions it holds "as they last were" (:164). held() (:339, :768-770) reads a missing updated as "held".
  • Session::scratch() gives the copy drawing_scenes: Default::default() (lib.rs:2064).
  • So when the window exports a deferred drawing whose model has moved on since its last drawing.update, the worker's copy has no updated and no held lines. If I read held right, it then draws nothing for those views, while the screen and an export run at once (the CLI, or this PR's no-path path) show the last-updated lines.

If that's the case, scratch() (or the export's copy, if other copies shouldn't carry it) could take the drawing cache's updated state and held entries. Or the export could be refused off-thread while held() is true. A test like this one's a_sheet_export_to_a_file_runs_off_the_window_thread, with a deferred drawing and a parameter change before the export, comparing the file with a synchronous export, would pin it.

@theironchef

Copy link
Copy Markdown
Contributor

Follow-up to my comment above: confirmed by running it, on drawings a7c0310ab (Windows, MSVC, --profile ci).

The background export's copy is Session::scratch(). For a deferred drawing that is held (the model changed since its last drawing.update), that copy exports a sheet without its views. The session itself exports the views' last lines, as a_deferred_drawing_keeps_its_lines_until_it_is_updated expects:

SVG bytes <g groups <path
s.execute("drawing.export") 2434 5 38
s.scratch().execute("drawing.export") 1923 3 30

Both replies list the two views in out_of_date, so the copy's file claims to show them "as they last were" but leaves them out. With this PR, that copy is what writes the file when the window exports with a path.

The test I used (in drawing_scene_tests.rs; it fails on drawings today because it calls scratch() directly):

#[test]
fn a_held_deferred_drawing_exports_the_same_from_a_scratch_copy() {
    let (mut s, sheet, _) = front_and_top();
    let drawing = json!({"drawing": ids::encode(s.open_drawing.unwrap())});
    run(&mut s, "drawing.set", json!({"updates": "deferred"}));
    extract(&mut s, sheet).unwrap();
    run(&mut s, "drawing.update", json!({}));
    settled(&mut s, sheet);
    run(&mut s, "drawing.close", json!({}));
    let block = s.doc.features[0].id;
    run(&mut s, "timeline.edit", json!({"feature": block.to_string(), "set": {"height": 40}}));
    run(&mut s, "drawing.open", drawing);
    settled(&mut s, sheet);
    let p = json!({"sheet": ids::encode(sheet), "format": "svg"});
    let here = run(&mut s, "drawing.export", p.clone());
    let there = s.scratch().execute("drawing.export", &p).unwrap();
    assert_eq!(there, here);
}

The likely cause is scratch()'s drawing_scenes: Default::default() (lib.rs:2064), which drops the cache's updated state and the held entries. Carrying those into the copy (or into the export's copy only) should make this test pass. That's for you to decide; I haven't tried a fix.

@CamWight

CamWight commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @theironchef, good spot, and thanks for running it and writing the test. The fix will come in this PR, with your test in it and credited to you.

@theironchef

Copy link
Copy Markdown
Contributor

A fix for the deferred-drawing export I reported above, in case it's useful. It's tested on drawings a7c0310ab (Windows, MSVC, --profile ci).

Session::scratch() now takes a copy of the open drawing's scene entries and its last drawing.update, so a held deferred drawing draws the same lines in the copy as in the session. It leaves out closed drawings' kept lines, the last assembled scene and a pending request; the copy assembles its own.

--- a/crates/engine/src/drawing_scene.rs
+++ b/crates/engine/src/drawing_scene.rs
 /// A view's last drawing, and what it was drawn from: the world state (held, so its address can't
 /// be reused while it is compared), what that showed, and the view as it drew.
+#[derive(Clone)]
 struct Entry {
@@
 /// A dimension's last drawing, and what it was drawn from: its record, the world state, its view's
 /// drawing (by serial, which holds its frame) and the drawing's units.
+#[derive(Clone)]
 struct DimensionEntry {
@@
 impl Cache {
+    /// What a copy of the session ([`Session::scratch`]) takes: the open drawing's views and
+    /// dimensions as they were last drawn, and its last [`update`], so a deferred drawing that holds
+    /// draws the same lines in the copy (a background export) as here. Closed drawings' kept lines,
+    /// the last scene and a pending request stay behind: the copy assembles its own.
+    pub(crate) fn for_copy(&self) -> Cache {
+        Cache {
+            drawing: self.drawing,
+            sheet: self.sheet,
+            views: self.views.clone(),
+            dimensions: self.dimensions.clone(),
+            updated: self.updated.clone(),
+            serial: self.serial,
+            ..Cache::default()
+        }
+    }
+
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
             render_jobs: self.render_jobs.scratch(),
-            drawing_scenes: Default::default(),
+            drawing_scenes: self.drawing_scenes.for_copy(),

Results:

  • The test I posted above (a_held_deferred_drawing_exports_the_same_from_a_scratch_copy) now passes. Both exports are 38 paths in 5 groups and byte-for-byte equal; before, the copy gave 30 paths in 3 groups.
  • The whole solidcraft-engine lib suite gives the same result with and without the change. I ran the ten tests that fail on this machine both ways and they fail identically: kernel and fillet cases such as chord_and_variable_fillets, plus each_format_has_an_export_command_of_its_own. None of them is in drawings code. cargo clippy -p solidcraft-engine --all-targets -- -D warnings is clean.

The cost is cloning the entries, which are mostly Arcs, but Drawn's line groups are copied in full. That happens only when a background job takes a copy, which for exports is once per export. If that's too much for other scratch() callers (insert, update), the same for_copy could be called from the export path only. I didn't add the test here because it calls scratch() directly; it would sit best next to this PR's own tests.

CamWight and others added 2 commits November 7, 2026 01:07
…ke the view DXF (tangency-labs#4890 EX2)

A sheet exported to a file through the control channel was drawn and written on the window's
thread, so a large PNG at a high dpi held the window up until it was done. `drawing.export` with a
`path` now goes through `file_load` as `Kind::ExportSheet`, beside the view DXF's `ExportDxf`: on a
copy of the design, off the window thread, with an "Exporting sheet" card. Without a path the
reply holds the document, so it runs at once as before. Cancel on the card says which export it
stopped: it said "DXF export cancelled" for every export while the view DXF was the only one.

`Kind::exports()` holds what the two export kinds share (the copy, never adopting the worker's
session, Cancel waiting for the worker, a drop cancelling it, a finished export staying finished),
in place of seven `ExportDxf` tests and a check on the command's name.

`paper_png`'s band loop reports its rows to the current `solidcraft_kernel::watch` and stops
between bands once it is cancelled. The command writes the file only after the PNG is complete, so a
cancelled export writes nothing. With no watch, every other caller, the bytes are unchanged.
`drawing.export`'s checks and write, its commands and its schema are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, as on the page (tangency-labs#4890 EX2)

A sheet exported to a file runs on a copy of the session. `Session::scratch` leaves the copy's
drawing-scene cache empty, so a deferred drawing that was held (the model changed since its last
`drawing.update`) exported from the copy with no views or dimensions. The same export without a
path, on the window's session, wrote the lines the sheet page shows.

`Session::scratch_as_shown` is `scratch()` plus `Cache::shown_copy`: the world state the cache last
updated against, each view's and dimension's last drawing, and the serial they were numbered to.
That is what `as_shown` reads. The lines kept for closed drawings, the last answer and a request in
flight stay out, since only the window's page uses them. `file_load` takes that copy for its two
export kinds; inserts, updates and opens keep `scratch()`, which is cheaper and never draws a sheet.

Tests: the engine compares the export (svg and out-of-date list) from the session and from the copy
for a drawing that isn't deferred (also after a view's edit), a deferred one with a view edited
since its update (drawn at once), and a held one, its dimension included, on the sheet last shown
and on a second sheet. The window
test writes a held sheet through the background export and compares the file with the synchronous
export.

Co-authored-by: theironchef <6278036+theironchef@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CamWight
CamWight force-pushed the drawing-export-png-4890-ex2 branch from c51daba to 09674e3 Compare November 7, 2026 01:29
@bherbruck
bherbruck merged commit f1153f4 into tangency-labs:drawings Nov 7, 2026
32 checks passed
@CamWight
CamWight deleted the drawing-export-png-4890-ex2 branch November 7, 2026 04:01
CamWight added a commit to CamWight/solidcraft that referenced this pull request Nov 7, 2026
… lists them out of date (tangency-labs#12802)

A deferred drawing closed during a model change came back with its views' last lines but no
dimensions: the close kept only the views', and a held drawing reads nothing again. Now the close
keeps each dimension's entry too, beside the views' lines, with its world state let go (an empty
one), so a closed drawing still holds no model. Opened again, each comes back read from a state
that has gone: a drawing that may draw reads it again once its view is up to date, as before, and a
held one shows it as it was.

A held view's dimensions are out of date with it, so every command that reads a sheet now lists
them in `out_of_date`, after the views, with the drawing open or reopened. They are listed only:
the page never reads them again against the view's old lines. A dimension or view gone while the
drawing was closed is forgotten by the rule that was already there when the sheet is put together.

Tests: a deferred drawing closed during a change keeps its dimension and lists it, reads it again
once updated, and lists it held with the drawing open; a dimension gone while closed is not shown,
listed or kept; a deleted drawing keeps no dimension either. tangency-labs#10431's held export test now
expects the held view's dimension listed with its views (3, was 2), and takes the shared edge helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bherbruck pushed a commit that referenced this pull request Nov 7, 2026
… lists them out of date (#12802) (#12803)

* claim: #12802

* Drawings: a deferred drawing keeps its dimensions across a close, and lists them out of date (#12802)

A deferred drawing closed during a model change came back with its views' last lines but no
dimensions: the close kept only the views', and a held drawing reads nothing again. Now the close
keeps each dimension's entry too, beside the views' lines, with its world state let go (an empty
one), so a closed drawing still holds no model. Opened again, each comes back read from a state
that has gone: a drawing that may draw reads it again once its view is up to date, as before, and a
held one shows it as it was.

A held view's dimensions are out of date with it, so every command that reads a sheet now lists
them in `out_of_date`, after the views, with the drawing open or reopened. They are listed only:
the page never reads them again against the view's old lines. A dimension or view gone while the
drawing was closed is forgotten by the rule that was already there when the sheet is put together.

Tests: a deferred drawing closed during a change keeps its dimension and lists it, reads it again
once updated, and lists it held with the drawing open; a dimension gone while closed is not shown,
listed or kept; a deleted drawing keeps no dimension either. #10431's held export test now
expects the held view's dimension listed with its views (3, was 2), and takes the shared edge helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Drawings: a closed drawing's kept dimensions hold no world state, like its views

A dimension kept at a drawing's close is now a `KeptDimension`: its record, its view's drawing, its
lettering and its lines, with no world state, as `KeptView` already is for a view. So the type keeps
"a closed drawing holds no model", where before a swap for an empty state in `forget_closed` did.
`take_kept` gives the views and the dimensions the one gone state, so both are read again from the
same place. Nothing changes in what a drawing shows or lists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) area:kernel B-rep kernel, booleans, blends, STEP/IGES area:ui desktop/web front end, dialogs, viewport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants