Skip to content

Drawings: a drawing can name another design file to draw, and the path survives Save As and undo (#3890) - #9402

Merged
bherbruck merged 2 commits into
tangency-labs:drawingsfrom
CamWight:drawing-storage-links-3890
Nov 15, 2026
Merged

bherbruck merged 2 commits into
tangency-labs:drawingsfrom
CamWight:drawing-storage-links-3890

Conversation

@CamWight

@CamWight CamWight commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Cam

Change

A drawing can now name another design file as what it draws. Until now, a drawing drew only the design it is saved in. This PR is the record and the paths only: the drawing keeps the other file's path, and the path stays right when the design is saved somewhere else, undone, redone or recovered. Reading that file and drawing its views come in the next parts.

This is the first of a series (L1 to L6 of #3890). It sets the shape the rest build on (a source with an optional path, and one walk over every link path), so it asks for a design review before the later parts go up. Part of #3890, into drawings.

Changes a default: no
A drawing made without source is saved and read exactly as before.

What it adds

  • The record. A drawing's source gets an optional path, written only when present. A drawing has at most 64 sources, listed by id, and at most one without a path (the design it is in). A path isn't empty, only spaces, or holding control characters. One pending format note, source-paths.rs.
  • drawing.create {source} names another design file to draw. It is refused, with nothing changed, for: a text over 4,096 bytes; a network or device path; a file that isn't a design; the design's own file in any spelling (sub/../case.sc too); a file that isn't there. The path is kept whole in memory and relative to the design's folder in the file, as Insert Design keeps a component link (component_link.rs:556).
  • drawing.inspect lists each source as {id, path?}, the path as the file keeps it.
  • One walk over every link path (design_link.rs): map_paths takes every link path of a design, component links and drawing sources alike, through one map. Opening makes them whole (located). Save As writes them relative to the new folder (filed). linked_files lists each file the links name, once. The two old link walks are now one line each over it.
  • One answer to "which design does this source mean": Session::drawn(drawing, source). Every reader asks it: base views, new parts lists, a sheet's documented component, and the title block's and notes' fields. In this PR a linked source answers "not supported yet: reading a linked design (Drawing W11, W12, W15: where drawings are saved, their records and their commands #3890)", so nothing reads the wrong design. The next part makes it open the file.

Decisions

  • No byte cap on a path in the record. This changes the 4,096-byte cap in the plan posted on Drawing W11, W12, W15: where drawings are saved, their records and their commands #3890. DesignLink.path has no cap either, and a relative text kept in memory would break "whole in memory": the next Save As or undo would rebase it from the wrong folder. So the 4,096-byte limit is on the source parameter only. A deep folder that makes a longer whole path still works; a test covers it.
  • No digest of the linked file in the record. That is on purpose, unlike DesignLink.file_sha256 (Linked components: a part file changed while the assembly was closed isn't picked up when the assembly opens, and component.links doesn't say it is out of date #9739). Which file a drawing draws is a path. Whether that file changed is the next part's question, answered when it opens the file.
  • One file, one source, decided in the engine, not the record. The record can't tell that a/../p.sc and p.sc are one file. A record that opened and then failed its check would block every edit of that drawing.
  • What an older build does with such a drawing comes from reading the code; it is not run. v0.40.1 doesn't know drawings: it opens the design with a warning and keeps them (crates/format/src/newer.rs:120-124 at v0.40.1). A drawings build from before this PR refuses the design as "saved by a newer SolidCraft". Nothing is dropped. Only unreleased builds can meet this.

Known limits

  • A relative source text is resolved against the program's working folder, as Insert Design does.
  • drawing.create's default template and name still come from the design the drawing is in, also for a drawing of another file. Until the next part can read the file, pass template with source.

Validation

Local, Windows, --profile ci, Rust 1.99.1.

On drawings db49054, 15 Nov 07:55 UTC:

  • cargo check of doc, io and engine, all targets; rustfmt; clippy -D warnings; format pending; lists; wasm: all passed.
  • Tests: doc drawing 134 passed; io design::drawing, mutate::designs and design::provenance 38 passed; engine drawing, design-link, component-link, file, schema, scene and title-block tests with the registry 1,304 passed (3 ignored, as on drawings); hostile params passed.
  • Planted faults: 10 of 10 caught, each by a failed test of its own rule, then a clean run passed. Faults 1 to 7 ran on the first commit. Fault 8 (the network check in drawing.create taken out) was missed at first; the second commit adds the check that catches it (below), and it was caught at 09:40 UTC. Faults 9 and 10 (the walk and the source accessor) ran in the earlier group run with the next part.

On drawings 8647608 after the last rebase, 10:09 UTC: clippy -D warnings of doc, io and engine (all targets), rustfmt, and the engine's drawing command tests, the design-path scan test and the registry check: all passed (32 tests).

The second commit: the order of the network check. drawing.create refuses a network or device path from its text before it compares the path with the design's own file. That comparison canonicalises the path, which would touch the network. Without the check, the reply is the same, because the presence check later refuses the path with the same text. So no reply test can see the order. The existing design-path scan test (every_link_path_goes_through_the_design_path_rule) now checks it, as it already does for Relink.

  • New tests, each in its area's existing test file:
    • the record's source rules: 64 and 65 sources, the id order, two own sources, empty, spaces, NUL and newline paths, two sources with one path;
    • drawing.create {source}: each refusal above with nothing changed, 4,096 bytes still looked for, the design's own file in another spelling;
    • a deep folder resolves to a whole path over 4,096 bytes, and Save As and undo still resolve it;
    • Save As keeps drawing sources through undo, redo and checkpoints;
    • one walk takes every kind of link path: a component link and two drawing sources, one naming the same file as the link;
    • a linked source is never read as the design the drawing is in: sheet set and add, parts list, base view and the title block's fields;
    • the design mutation fuzz now has a linked source in each drawing.

What the tests don't reach:

  • A relative source text that exists.
  • An older build opening such a file (read from the code, above).
  • A path over 4,096 bytes on Windows without long-path support. The test builds the path in memory only.

Screenshots of the behavior

UI: none. There is no picker for a source yet; it comes with the later parts and the drawing UI. The evidence is drawing.create's reply, which answers as drawing.inspect, for a drawing of another design file:

The reply, cut to the drawing's id, name and sources (the folder is shortened here):

{
  "id": "9na55vkffykys",
  "name": "Bracket drawing",
  "sources": [
    {
      "id": "364vpyycqnksq",
      "path": "<folder>\bracket.sc"
    }
  ]
}

The design was not saved yet when the drawing was made, so the path is whole. Once the design is saved, drawing.inspect shows it relative to the design's folder.

Integration status

Rebased onto drawings 8647608, 15 Nov 2026. Three conflicts on the way, each in drawing.inspect's parameter text, and each resolved to keep both: with #16838 (view_letters), with #17127 (each sheet's notes, tables, images and revision tags) and with #13064 (the drawing's symbols). One change git doesn't flag: a test the last drawings sync added in io/src/design/provenance.rs builds a source as Source { id }. It now reads Source { id, path: None }.

git merge-tree against each open PR into drawings that changes cmd/drawing.rs, drawing_tests.rs or component_link.rs (#16144, #13033, #7608): no new conflict for any of them. Our #16842, #13058 and #3876 add a function beside new_list in cmd/drawing_table.rs, which this PR changes. Whichever lands second keeps both.

Follow-ups, not in this PR:

  • One check for "may this text name a design file to link": drawing.create, Insert Design, Relink, the link reader and the pack each write it a little differently.
  • The separate-file drawing reader and writer in io that nothing calls since drawings moved into the design.
  • drawing.create judges a source path's network rule twice: once directly, and again in the presence check. One call that refuses, compares and checks presence in order would remove the repeat.

@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch 3 times, most recently from 9aa2101 to e7bc90f Compare November 2, 2026 06:06
@CamWight CamWight changed the title Drawing storage: links to other designs, last results and model edits (#3890) Drawings: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Nov 2, 2026
@CamWight CamWight changed the title Drawings: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Drawings W11, W12, W15: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Nov 2, 2026
@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch from e7bc90f to 0c07788 Compare November 3, 2026 05:56
@CamWight CamWight changed the title Drawings W11, W12, W15: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Drawings: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Nov 3, 2026
@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch from 0c07788 to f353055 Compare November 4, 2026 09:00
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1

Check name Status Explanation
Existing Defaults Unchanged Passed PR #9402 (CamWight) changes no existing UX default. The check passes because the changes are additive, and the description's Changes a default: no matches the code. Evidence from the committed PR ra…
Full details: Existing Defaults Unchanged

Explanation

PR #9402 (CamWight) changes no existing UX default. The check passes because the changes are additive, and the description's Changes a default: no matches the code. Evidence from the committed PR range (4562dbe and 02b5e26, against 4562dbe^): - Files touched are only under crates/doc, crates/engine and crates/io. No apps/, UI, look, preference, shortcut or layout files change. - drawing.create (crates/engine/src/cmd/drawing.rs): the optional source parameter is new. The "design is empty" refusal is kept for every call without source (if linked.is_none() &amp;&amp; s.doc.features.is_empty()). The old refusal only moves for the new linked-source path. Calls without source behave as before. - drawing.inspect: sources entries gain an optional path, written only for linked sources. Drawings without a linked source keep {id} only. - Save As and open: the old link rebase is replaced by located/filed, which use the same path mapping for component links. Drawing sources are new, so they add no change for existing designs. - Removed lines in non-test code are the old single-source check, the old rebased helper and the old title_block_text signatures. These are refactors or additive extensions, not user-visible default changes. - The kernel and geometry results are unchanged. Under the check's rules, kernel results are not UX defaults in any case. No named UX default changes. Nothing needs a before/after entry.

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

@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch 3 times, most recently from 8d3c575 to 96597d6 Compare November 7, 2026 02:00
@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch 2 times, most recently from b647a24 to 5861432 Compare November 9, 2026 01:56
@CamWight
CamWight force-pushed the drawing-storage-links-3890 branch from daba0c4 to 4fbb670 Compare November 15, 2026 09:46
@CamWight CamWight changed the title Drawings: show parts from other designs, keep each view's last lines, and update after model changes (#3890) Drawings: a drawing can name another design file to draw, and the path survives Save As and undo (#3890) Nov 15, 2026
@CamWight
CamWight marked this pull request as ready for review November 15, 2026 09:46
CamWight and others added 2 commits November 15, 2026 09:47
…ngency-labs#3890)

A drawing's source may now carry a path to another design file, relative
to the folder of the design the drawing is in. A source without a path is
the design the drawing is in, at most one of them, and a drawing lists at
most 64 sources by id.

- The record checks the count, the order, one source without a path and
  every path (drawing.rs check_sources).
- One walk in design_link takes every link path of a design, component
  links and drawing sources alike (map_paths, and linked_files to list the
  files they name). Opening makes the paths whole (located); saving writes
  them relative to the new folder (filed), through Save As, undo, redo and
  checkpoints.
- drawing.create takes a source path, checks it as a component link's path
  is checked and refuses a path that names the design itself.
- Which design a source means has one answer, Session::drawn: the design
  the drawing is in for its own source. Another design's file is refused
  as not supported yet, so a base view, a parts list and a sheet's
  documents never take one, and a sheet that documents one shows its
  fields as gone, never this design's.
- The format note is crates/doc/src/drawing/format/pending/source-paths.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efore it is compared (tangency-labs#3890)

linked_source refuses a network or device path from its text before same_file canonicalises it,
which would touch the network. The reply is the same without that order (link_presence refuses the
path later with the same text), so no reply test can see it. The design-path scan test now checks
the order, as it already does for relink's canonicalize.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants