Repository navigation
Drawing export: a sheet exported to a file runs in the background, like the view DXF (#4890) - #10431
Conversation
43287fa to
546c159
Compare
546c159 to
953a9d8
Compare
953a9d8 to
c51daba
Compare
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
theironchef
left a comment
There was a problem hiding this comment.
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
drawingstoday, what a deferred drawing may draw from lives in the session'sdrawing_scenescache:Cache::updated(drawing_scene.rs:672) and the views and dimensions it holds "as they last were" (:164).held()(:339,:768-770) reads a missingupdatedas "held". Session::scratch()gives the copydrawing_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 noupdatedand no held lines. If I readheldright, it then draws nothing for those views, while the screen and an export run at once (the CLI, or this PR's no-pathpath) 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.
|
Follow-up to my comment above: confirmed by running it, on The background export's copy is
Both replies list the two views in The test I used (in #[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 |
|
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. |
|
A fix for the deferred-drawing export I reported above, in case it's useful. It's tested on
--- 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 cost is cloning the entries, which are mostly |
…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>
c51daba to
09674e3
Compare
… 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>
… 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>
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.exportwith apathruns 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 latestdrawings: 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
file_load, like the view DXF:Kind::ExportSheetsits besideKind::ExportDxf.controlsends adrawing.exportthat has apathto the worker thread, on a copy of the design, and answers the caller when the file is in. Without apaththe reply holds the document, which is quick, so it runs at once as before.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::ExportDxftests and a check on the command's name.paper_pngalready draws a band of rows at a time. Before each band it now reports("sheet_png", rows done, rows)to the currentsolidcraft_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.crates/io: the band loop is the only place that knows how far a PNG has got.crates/ioalready depends onsolidcraft-kernel, so there is no new dependency. The other choice was a progress parameter onpaper_png, which would change it for every caller to carry what the watch already carries.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.drawing_export.exporting,drawing_export.progress.rowsanddrawing_export.cancelled(with its UK spelling in en-GB), inassets/locales/pending/drawing-export-background.json.Nothing in the window calls
drawing.exportyet (the sheet page's Export button is stilldrawing.export.planned). When it does, it can start aRequest::new(path, Kind::ExportSheet)the waydialogs_view_dxf.rsstarts 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 onSession::scratch, whose drawing cache is empty, so a held sheet came out with no views or dimensions. @theironchef found this.Session::scratch_as_shown. That isscratch()plusCache::shown_copy.scratch()itself: inserts, updates, previews and dialogs usescratch()and never draw a sheet. They would copy every view's lines for nothing.Validation
Local, Windows,
--profile ci, ondrawings8067a0a, then replayed onto 69709bd (only #12232 in between, which touches none of these files), withcargo check --all-targetsagain on the replayed commit:cargo check --all-targets,fmt,xtask listsandxtask i18n --checkpass.io,engineandui-egui, all targets,-D warnings, passes.cargo xtask wasm: 14 crates build for wasm32.iopaper 43 passed, the engine's drawing tests 324 passed,ui-eguifile_load30 passed, 0 failed.Tests first: the io and engine tests fail on the base and pass with the change.
a_watched_sheet_png_reports_its_rows_and_stops_when_cancelled.a_cancelled_png_export_writes_no_file(unwatched, the same request writes the file).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
drawings2a25449, then replayed onto 594945b (no shared files;cargo check --all-targetsandfmtagain).ui-eguifile_load29 passed,iopng 24 passed.a_held_deferred_drawing_exports_the_same_from_a_scratch_copy. It compares the svg andout_of_datefrom 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.scratch(), its last update left out, the views' entries left out, the dimensions' entries left out, andfile_loadback onscratch().Planted faults: 10 of 11 caught, and the clean runs pass after them. They cover:
drawing.exportnot sent to the worker;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:
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.
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.
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.exportwith apathwrote 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 apathgives the same bytes. The window has no sheet page yet, so the picture is the exported sheet itself.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
drawings594945b, the latest when pushed.