copperflow 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/dist/app/assets/NewPartDialog-PSXlbLR2.js +1 -0
- package/dist/app/assets/PackagesDialog-C8ZyWl-g.css +1 -0
- package/dist/app/assets/PackagesDialog-DmIT8b2D.js +2 -0
- package/dist/app/assets/{VerifyPartDialog-Ey6xpQ_U.js → VerifyPartDialog-KiW1nDnZ.js} +2 -2
- package/dist/app/assets/footprint-preview-oJ27yBAB.js +160 -0
- package/dist/app/assets/index-CArKmuM_.css +1 -0
- package/dist/app/assets/index-Yj6ATP2T.js +20 -0
- package/dist/app/assets/texture-worker-e8zKC6dv.js +1 -0
- package/dist/app/index.html +2 -2
- package/dist/cli-commands.d.ts +2 -0
- package/dist/cli-commands.js +45 -0
- package/dist/cli-commands.js.map +1 -1
- package/dist/cli-graphic.d.ts +9 -0
- package/dist/cli-graphic.js +62 -0
- package/dist/cli-graphic.js.map +1 -0
- package/dist/core/annotations.js +2 -2
- package/dist/core/annotations.js.map +1 -1
- package/dist/core/board-edits.d.ts +2 -0
- package/dist/core/board-edits.js +14 -0
- package/dist/core/board-edits.js.map +1 -1
- package/dist/core/board-graphic-edits.d.ts +8 -0
- package/dist/core/board-graphic-edits.js +88 -0
- package/dist/core/board-graphic-edits.js.map +1 -0
- package/dist/core/board-items.d.ts +6 -0
- package/dist/core/board-items.js +8 -3
- package/dist/core/board-items.js.map +1 -1
- package/dist/core/board-shape-edit.js +4 -2
- package/dist/core/board-shape-edit.js.map +1 -1
- package/dist/core/edit.js +17 -1
- package/dist/core/edit.js.map +1 -1
- package/dist/core/graphic-import.d.ts +43 -0
- package/dist/core/graphic-import.js +142 -0
- package/dist/core/graphic-import.js.map +1 -0
- package/dist/core/html-export.d.ts +37 -0
- package/dist/core/html-export.js +139 -0
- package/dist/core/html-export.js.map +1 -0
- package/dist/core/html-page.d.ts +39 -0
- package/dist/core/html-page.js +114 -0
- package/dist/core/html-page.js.map +1 -0
- package/dist/core/html-style.d.ts +3 -0
- package/dist/core/html-style.js +117 -0
- package/dist/core/html-style.js.map +1 -0
- package/dist/core/model-export.d.ts +33 -0
- package/dist/core/model-export.js +36 -0
- package/dist/core/model-export.js.map +1 -0
- package/dist/core/out-name.d.ts +5 -0
- package/dist/core/out-name.js +10 -0
- package/dist/core/out-name.js.map +1 -0
- package/dist/core/packages.d.ts +22 -0
- package/dist/core/packages.js +64 -0
- package/dist/core/packages.js.map +1 -0
- package/dist/core/pad-lines.d.ts +7 -0
- package/dist/core/pad-lines.js +15 -0
- package/dist/core/pad-lines.js.map +1 -0
- package/dist/core/pour-edits.d.ts +12 -1
- package/dist/core/pour-edits.js +6 -6
- package/dist/core/pour-edits.js.map +1 -1
- package/dist/core/render.d.ts +2 -1
- package/dist/core/render.js.map +1 -1
- package/dist/core/rules-patch.d.ts +17 -0
- package/dist/core/rules-patch.js +102 -0
- package/dist/core/rules-patch.js.map +1 -0
- package/dist/core/silk-text-edits.d.ts +8 -0
- package/dist/core/silk-text-edits.js +72 -0
- package/dist/core/silk-text-edits.js.map +1 -0
- package/dist/core/step-export.js +3 -0
- package/dist/core/step-export.js.map +1 -1
- package/dist/core/types.d.ts +55 -3
- package/dist/engine/board-graphic.d.ts +49 -0
- package/dist/engine/board-graphic.js +175 -0
- package/dist/engine/board-graphic.js.map +1 -0
- package/dist/engine/checks/copper-clearance.d.ts +1 -1
- package/dist/engine/checks/copper-clearance.js +19 -1
- package/dist/engine/checks/copper-clearance.js.map +1 -1
- package/dist/engine/checks/copper-pieces.d.ts +8 -2
- package/dist/engine/checks/copper-pieces.js +23 -2
- package/dist/engine/checks/copper-pieces.js.map +1 -1
- package/dist/engine/checks/drc-board-graphic.d.ts +10 -0
- package/dist/engine/checks/drc-board-graphic.js +95 -0
- package/dist/engine/checks/drc-board-graphic.js.map +1 -0
- package/dist/engine/checks/drc-parts.js +3 -1
- package/dist/engine/checks/drc-parts.js.map +1 -1
- package/dist/engine/checks/drc-pours.js +3 -3
- package/dist/engine/checks/drc-pours.js.map +1 -1
- package/dist/engine/checks/drc-silk-text.d.ts +15 -0
- package/dist/engine/checks/drc-silk-text.js +65 -0
- package/dist/engine/checks/drc-silk-text.js.map +1 -0
- package/dist/engine/checks/fill-point.d.ts +7 -0
- package/dist/engine/checks/fill-point.js +58 -0
- package/dist/engine/checks/fill-point.js.map +1 -0
- package/dist/engine/checks/stranded-copper.d.ts +14 -0
- package/dist/engine/checks/stranded-copper.js +43 -0
- package/dist/engine/checks/stranded-copper.js.map +1 -0
- package/dist/engine/design.js +1 -1
- package/dist/engine/design.js.map +1 -1
- package/dist/engine/elaborate.d.ts +2 -0
- package/dist/engine/elaborate.js +30 -1
- package/dist/engine/elaborate.js.map +1 -1
- package/dist/engine/engine.d.ts +4 -1
- package/dist/engine/engine.js +5 -2
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/fab/graphic-objects.d.ts +7 -0
- package/dist/engine/fab/graphic-objects.js +24 -0
- package/dist/engine/fab/graphic-objects.js.map +1 -0
- package/dist/engine/fab/layers.d.ts +9 -0
- package/dist/engine/fab/layers.js +60 -8
- package/dist/engine/fab/layers.js.map +1 -1
- package/dist/engine/fab/silk-text-strokes.d.ts +16 -0
- package/dist/engine/fab/silk-text-strokes.js +28 -0
- package/dist/engine/fab/silk-text-strokes.js.map +1 -0
- package/dist/engine/fab/stroke-font.d.ts +4 -0
- package/dist/engine/fab/stroke-font.js +38 -1
- package/dist/engine/fab/stroke-font.js.map +1 -1
- package/dist/engine/footprints/array.d.ts +4 -0
- package/dist/engine/footprints/array.js +51 -0
- package/dist/engine/footprints/array.js.map +1 -0
- package/dist/engine/footprints/axial.d.ts +6 -0
- package/dist/engine/footprints/axial.js +115 -0
- package/dist/engine/footprints/axial.js.map +1 -0
- package/dist/engine/footprints/catalogue.d.ts +39 -0
- package/dist/engine/footprints/catalogue.js +284 -0
- package/dist/engine/footprints/catalogue.js.map +1 -0
- package/dist/engine/footprints/chip.js +10 -1
- package/dist/engine/footprints/chip.js.map +1 -1
- package/dist/engine/footprints/connector.d.ts +16 -0
- package/dist/engine/footprints/connector.js +31 -0
- package/dist/engine/footprints/connector.js.map +1 -0
- package/dist/engine/footprints/dcjack.d.ts +3 -0
- package/dist/engine/footprints/dcjack.js +46 -0
- package/dist/engine/footprints/dcjack.js.map +1 -0
- package/dist/engine/footprints/dpak.d.ts +7 -0
- package/dist/engine/footprints/dpak.js +172 -0
- package/dist/engine/footprints/dpak.js.map +1 -0
- package/dist/engine/footprints/dual.d.ts +11 -2
- package/dist/engine/footprints/dual.js +113 -12
- package/dist/engine/footprints/dual.js.map +1 -1
- package/dist/engine/footprints/index.js +46 -3
- package/dist/engine/footprints/index.js.map +1 -1
- package/dist/engine/footprints/inductor.d.ts +3 -0
- package/dist/engine/footprints/inductor.js +32 -0
- package/dist/engine/footprints/inductor.js.map +1 -0
- package/dist/engine/footprints/known.js +114 -14
- package/dist/engine/footprints/known.js.map +1 -1
- package/dist/engine/footprints/ledsmd.d.ts +3 -0
- package/dist/engine/footprints/ledsmd.js +52 -0
- package/dist/engine/footprints/ledsmd.js.map +1 -0
- package/dist/engine/footprints/ledth.d.ts +4 -0
- package/dist/engine/footprints/ledth.js +45 -0
- package/dist/engine/footprints/ledth.js.map +1 -0
- package/dist/engine/footprints/melf.d.ts +8 -0
- package/dist/engine/footprints/melf.js +56 -0
- package/dist/engine/footprints/melf.js.map +1 -0
- package/dist/engine/footprints/pad-roles.d.ts +4 -0
- package/dist/engine/footprints/pad-roles.js +32 -0
- package/dist/engine/footprints/pad-roles.js.map +1 -0
- package/dist/engine/footprints/plcc.d.ts +4 -0
- package/dist/engine/footprints/plcc.js +117 -0
- package/dist/engine/footprints/plcc.js.map +1 -0
- package/dist/engine/footprints/resonator.d.ts +3 -0
- package/dist/engine/footprints/resonator.js +33 -0
- package/dist/engine/footprints/resonator.js.map +1 -0
- package/dist/engine/footprints/screw.d.ts +3 -0
- package/dist/engine/footprints/screw.js +51 -0
- package/dist/engine/footprints/screw.js.map +1 -0
- package/dist/engine/footprints/smallsot.d.ts +8 -0
- package/dist/engine/footprints/smallsot.js +143 -0
- package/dist/engine/footprints/smallsot.js.map +1 -0
- package/dist/engine/footprints/smdbox.d.ts +33 -0
- package/dist/engine/footprints/smdbox.js +76 -0
- package/dist/engine/footprints/smdbox.js.map +1 -0
- package/dist/engine/footprints/smdcan.d.ts +3 -0
- package/dist/engine/footprints/smdcan.js +61 -0
- package/dist/engine/footprints/smdcan.js.map +1 -0
- package/dist/engine/footprints/smdip.d.ts +4 -0
- package/dist/engine/footprints/smdip.js +58 -0
- package/dist/engine/footprints/smdip.js.map +1 -0
- package/dist/engine/footprints/socket.d.ts +8 -0
- package/dist/engine/footprints/socket.js +21 -0
- package/dist/engine/footprints/socket.js.map +1 -0
- package/dist/engine/footprints/sod.d.ts +6 -0
- package/dist/engine/footprints/sod.js +63 -6
- package/dist/engine/footprints/sod.js.map +1 -1
- package/dist/engine/footprints/sot.d.ts +1 -1
- package/dist/engine/footprints/sot.js +17 -2
- package/dist/engine/footprints/sot.js.map +1 -1
- package/dist/engine/footprints/tact.d.ts +3 -0
- package/dist/engine/footprints/tact.js +65 -0
- package/dist/engine/footprints/tact.js.map +1 -0
- package/dist/engine/footprints/tantalum.d.ts +7 -0
- package/dist/engine/footprints/tantalum.js +91 -0
- package/dist/engine/footprints/tantalum.js.map +1 -0
- package/dist/engine/footprints/to92inline.d.ts +14 -0
- package/dist/engine/footprints/to92inline.js +21 -0
- package/dist/engine/footprints/to92inline.js.map +1 -0
- package/dist/engine/footprints/topower.d.ts +7 -0
- package/dist/engine/footprints/topower.js +119 -0
- package/dist/engine/footprints/topower.js.map +1 -0
- package/dist/engine/footprints/usb.d.ts +32 -0
- package/dist/engine/footprints/usb.js +109 -0
- package/dist/engine/footprints/usb.js.map +1 -0
- package/dist/engine/footprints/xtal.d.ts +4 -0
- package/dist/engine/footprints/xtal.js +61 -0
- package/dist/engine/footprints/xtal.js.map +1 -0
- package/dist/engine/graphic-place.d.ts +34 -0
- package/dist/engine/graphic-place.js +132 -0
- package/dist/engine/graphic-place.js.map +1 -0
- package/dist/engine/graphics/curves.d.ts +18 -0
- package/dist/engine/graphics/curves.js +75 -0
- package/dist/engine/graphics/curves.js.map +1 -0
- package/dist/engine/graphics/dxf-entities.d.ts +20 -0
- package/dist/engine/graphics/dxf-entities.js +184 -0
- package/dist/engine/graphics/dxf-entities.js.map +1 -0
- package/dist/engine/graphics/dxf-pairs.d.ts +22 -0
- package/dist/engine/graphics/dxf-pairs.js +77 -0
- package/dist/engine/graphics/dxf-pairs.js.map +1 -0
- package/dist/engine/graphics/dxf.d.ts +5 -0
- package/dist/engine/graphics/dxf.js +110 -0
- package/dist/engine/graphics/dxf.js.map +1 -0
- package/dist/engine/graphics/index.d.ts +9 -0
- package/dist/engine/graphics/index.js +30 -0
- package/dist/engine/graphics/index.js.map +1 -0
- package/dist/engine/graphics/path-data.d.ts +12 -0
- package/dist/engine/graphics/path-data.js +162 -0
- package/dist/engine/graphics/path-data.js.map +1 -0
- package/dist/engine/graphics/rings.d.ts +7 -0
- package/dist/engine/graphics/rings.js +93 -0
- package/dist/engine/graphics/rings.js.map +1 -0
- package/dist/engine/graphics/shapes.d.ts +47 -0
- package/dist/engine/graphics/shapes.js +85 -0
- package/dist/engine/graphics/shapes.js.map +1 -0
- package/dist/engine/graphics/svg-attributes.d.ts +26 -0
- package/dist/engine/graphics/svg-attributes.js +116 -0
- package/dist/engine/graphics/svg-attributes.js.map +1 -0
- package/dist/engine/graphics/svg.d.ts +5 -0
- package/dist/engine/graphics/svg.js +118 -0
- package/dist/engine/graphics/svg.js.map +1 -0
- package/dist/engine/graphics/transform.d.ts +21 -0
- package/dist/engine/graphics/transform.js +88 -0
- package/dist/engine/graphics/transform.js.map +1 -0
- package/dist/engine/graphics/xml.d.ts +10 -0
- package/dist/engine/graphics/xml.js +130 -0
- package/dist/engine/graphics/xml.js.map +1 -0
- package/dist/engine/model.d.ts +55 -0
- package/dist/engine/model.js.map +1 -1
- package/dist/engine/pcb-place/grow.d.ts +12 -0
- package/dist/engine/pcb-place/grow.js +100 -0
- package/dist/engine/pcb-place/grow.js.map +1 -0
- package/dist/engine/pcb.d.ts +5 -1
- package/dist/engine/pcb.js +2 -0
- package/dist/engine/pcb.js.map +1 -1
- package/dist/engine/pour/cache.js +1 -0
- package/dist/engine/pour/cache.js.map +1 -1
- package/dist/engine/pour/obstacles.js +18 -1
- package/dist/engine/pour/obstacles.js.map +1 -1
- package/dist/engine/router/route-board.d.ts +2 -0
- package/dist/engine/router/route-board.js +7 -2
- package/dist/engine/router/route-board.js.map +1 -1
- package/dist/engine/router/unplaced.d.ts +18 -0
- package/dist/engine/router/unplaced.js +27 -0
- package/dist/engine/router/unplaced.js.map +1 -0
- package/dist/engine/rules/rotations.d.ts +12 -3
- package/dist/engine/rules/rotations.js +77 -2
- package/dist/engine/rules/rotations.js.map +1 -1
- package/dist/engine/silk-text.d.ts +40 -0
- package/dist/engine/silk-text.js +85 -0
- package/dist/engine/silk-text.js.map +1 -0
- package/dist/engine/solid/heights-smd.d.ts +3 -0
- package/dist/engine/solid/heights-smd.js +81 -0
- package/dist/engine/solid/heights-smd.js.map +1 -0
- package/dist/engine/solid/heights-through.d.ts +7 -0
- package/dist/engine/solid/heights-through.js +93 -0
- package/dist/engine/solid/heights-through.js.map +1 -0
- package/dist/engine/solid/heights-uno.d.ts +2 -0
- package/dist/engine/solid/heights-uno.js +15 -0
- package/dist/engine/solid/heights-uno.js.map +1 -0
- package/dist/engine/solid/heights.d.ts +2 -0
- package/dist/engine/solid/heights.js +43 -18
- package/dist/engine/solid/heights.js.map +1 -1
- package/dist/library/attach-datasheet.d.ts +2 -0
- package/dist/library/attach-datasheet.js +1 -1
- package/dist/library/attach-datasheet.js.map +1 -1
- package/dist/library/part-fields.d.ts +23 -0
- package/dist/library/part-fields.js +55 -0
- package/dist/library/part-fields.js.map +1 -0
- package/dist/mcp/batch-steps.d.ts +33 -0
- package/dist/mcp/batch-steps.js +211 -0
- package/dist/mcp/batch-steps.js.map +1 -0
- package/dist/mcp/batch.d.ts +16 -0
- package/dist/mcp/batch.js +18 -5
- package/dist/mcp/batch.js.map +1 -1
- package/dist/mcp/board-import-tool.d.ts +1 -1
- package/dist/mcp/board-import-tool.js +1 -1
- package/dist/mcp/board-import-tool.js.map +1 -1
- package/dist/mcp/board-summary.d.ts +1 -1
- package/dist/mcp/board-summary.js +32 -1
- package/dist/mcp/board-summary.js.map +1 -1
- package/dist/mcp/board-tool.d.ts +36 -0
- package/dist/mcp/board-tool.js +109 -0
- package/dist/mcp/board-tool.js.map +1 -0
- package/dist/mcp/copper-summary.d.ts +2 -0
- package/dist/mcp/copper-summary.js +10 -2
- package/dist/mcp/copper-summary.js.map +1 -1
- package/dist/mcp/copper-tools.d.ts +1 -1
- package/dist/mcp/copper-tools.js +1 -1
- package/dist/mcp/copper-tools.js.map +1 -1
- package/dist/mcp/create-part.js +2 -2
- package/dist/mcp/create-part.js.map +1 -1
- package/dist/mcp/graphic-tool.d.ts +34 -0
- package/dist/mcp/graphic-tool.js +29 -0
- package/dist/mcp/graphic-tool.js.map +1 -0
- package/dist/mcp/guide.d.ts +3 -1
- package/dist/mcp/guide.js +15 -4
- package/dist/mcp/guide.js.map +1 -1
- package/dist/mcp/html-tool.d.ts +28 -0
- package/dist/mcp/html-tool.js +21 -0
- package/dist/mcp/html-tool.js.map +1 -0
- package/dist/mcp/model-tool.d.ts +31 -0
- package/dist/mcp/model-tool.js +27 -0
- package/dist/mcp/model-tool.js.map +1 -0
- package/dist/mcp/new-circuit.d.ts +1 -1
- package/dist/mcp/new-circuit.js +10 -11
- package/dist/mcp/new-circuit.js.map +1 -1
- package/dist/mcp/part-tools.d.ts +20 -0
- package/dist/mcp/part-tools.js +40 -0
- package/dist/mcp/part-tools.js.map +1 -0
- package/dist/mcp/place-tools.d.ts +1 -1
- package/dist/mcp/place-tools.js +11 -5
- package/dist/mcp/place-tools.js.map +1 -1
- package/dist/mcp/project-tools.js +2 -0
- package/dist/mcp/project-tools.js.map +1 -1
- package/dist/mcp/render-tool.d.ts +2 -0
- package/dist/mcp/render-tool.js +32 -1
- package/dist/mcp/render-tool.js.map +1 -1
- package/dist/mcp/route-tools.d.ts +1 -1
- package/dist/mcp/route-tools.js +3 -1
- package/dist/mcp/route-tools.js.map +1 -1
- package/dist/mcp/rules-tool.d.ts +19 -0
- package/dist/mcp/rules-tool.js +73 -0
- package/dist/mcp/rules-tool.js.map +1 -0
- package/dist/mcp/server.js +53 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/text-tool.d.ts +34 -0
- package/dist/mcp/text-tool.js +37 -0
- package/dist/mcp/text-tool.js.map +1 -0
- package/dist/render/render.js +2335 -389
- package/dist/studio/server.js +32 -0
- package/dist/studio/server.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -1
- package/skills/copperflow/SKILL.md +8 -8
- package/skills/copperflow/references/copper.md +9 -1
- package/skills/copperflow/references/design-rules.md +36 -7
- package/skills/copperflow/references/editable-subset.md +18 -8
- package/skills/copperflow/references/parts-library.md +19 -1
- package/skills/copperflow/references/writing-circuits.md +71 -0
- package/dist/app/assets/NewPartDialog-BBJaZFCo.js +0 -160
- package/dist/app/assets/index-BKoIKo22.css +0 -1
- package/dist/app/assets/index-DPmr2dR1.js +0 -20
- package/dist/app/assets/texture-worker-CyI_g_XZ.js +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// The agent's set_rules: a partial rules object merged into rules.yaml, checked exactly as a build reads the file, and
|
|
2
|
+
// written as one history entry. Objects merge key by key, any other value replaces what is there, null removes a key.
|
|
3
|
+
// The rest of the file stays as written, comments included.
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { isMap, parseDocument } from "yaml";
|
|
6
|
+
import { loadRules, RULES_PATH } from "../engine/rules/load.js";
|
|
7
|
+
import { EditError } from "./edit-error.js";
|
|
8
|
+
import { inProjectQueue, readIfThere, writeNew, writeWithHistory } from "./file-writes.js";
|
|
9
|
+
/** Flow lists stay as people write them, `[GND, VBUS]`, not `[ GND, VBUS ]`. */
|
|
10
|
+
const WRITE = { flowCollectionPadding: false };
|
|
11
|
+
const RESERVED = new Set(["__proto__", "constructor", "prototype"]);
|
|
12
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
/** Removes the maps a removal left empty, from the deepest up. */
|
|
14
|
+
function pruneEmpty(document, path) {
|
|
15
|
+
for (let length = path.length - 1; length >= 1; length -= 1) {
|
|
16
|
+
const node = document.getIn(path.slice(0, length), true);
|
|
17
|
+
if (!isMap(node) || node.items.length > 0)
|
|
18
|
+
return;
|
|
19
|
+
document.deleteIn(path.slice(0, length));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Applies the patch under `path` to the document; answers each change as "a.b = value" or "a.b removed". */
|
|
23
|
+
function applyPatch(document, path, patch) {
|
|
24
|
+
return Object.entries(patch).flatMap(([key, value]) => {
|
|
25
|
+
if (RESERVED.has(key))
|
|
26
|
+
throw new EditError("invalid", `"${key}" cannot be a key in ${RULES_PATH}`);
|
|
27
|
+
const at = [...path, key];
|
|
28
|
+
const name = at.join(".");
|
|
29
|
+
if (value === null) {
|
|
30
|
+
if (!document.hasIn(at))
|
|
31
|
+
return [];
|
|
32
|
+
document.deleteIn(at);
|
|
33
|
+
pruneEmpty(document, at);
|
|
34
|
+
return [`${name} removed`];
|
|
35
|
+
}
|
|
36
|
+
if (isPlainObject(value) && isMap(document.getIn(at, true)))
|
|
37
|
+
return applyPatch(document, at, value);
|
|
38
|
+
document.setIn(at, value);
|
|
39
|
+
return [`${name} = ${echoed(value)}`];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** The most characters of a value an answer repeats. */
|
|
43
|
+
const ECHO_LIMIT = 200;
|
|
44
|
+
const echoed = (value) => {
|
|
45
|
+
const text = JSON.stringify(value);
|
|
46
|
+
return text.length > ECHO_LIMIT ? `${text.slice(0, ECHO_LIMIT)}…` : text;
|
|
47
|
+
};
|
|
48
|
+
/** Throws on a reserved key anywhere in the value, before anything is merged. */
|
|
49
|
+
function checkKeys(value) {
|
|
50
|
+
if (Array.isArray(value))
|
|
51
|
+
return value.forEach(checkKeys);
|
|
52
|
+
if (!isPlainObject(value))
|
|
53
|
+
return;
|
|
54
|
+
for (const [key, child] of Object.entries(value)) {
|
|
55
|
+
if (RESERVED.has(key))
|
|
56
|
+
throw new EditError("invalid", `"${key}" cannot be a key in ${RULES_PATH}`);
|
|
57
|
+
checkKeys(child);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** A build's problems with the text, as the schema words them, without the file and line of a text no one sees. */
|
|
61
|
+
function problemsOf(text) {
|
|
62
|
+
const { diagnostics } = loadRules({ [RULES_PATH]: text });
|
|
63
|
+
return diagnostics.filter((d) => d.severity === "error").map((d) => d.message.replace(/^rules\.yaml(:\d+)?: /, ""));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* rules.yaml's text with the patch merged in, and the changes it made; refused (nothing changes) when the file cannot
|
|
67
|
+
* be read, when the result is a file a build would refuse, or when it changes nothing.
|
|
68
|
+
*/
|
|
69
|
+
export function patchRulesText(text, patch) {
|
|
70
|
+
if (!isPlainObject(patch) || Object.keys(patch).length === 0)
|
|
71
|
+
throw new EditError("invalid", 'rules must be an object of rules.yaml keys, e.g. { "fabrication": { "profile": "jlcpcb-4layer" } }');
|
|
72
|
+
const document = parseDocument(text);
|
|
73
|
+
const problem = document.errors[0];
|
|
74
|
+
if (problem)
|
|
75
|
+
throw new EditError("invalid", `${RULES_PATH} cannot be read (${problem.message.split("\n")[0]}); fix it first`);
|
|
76
|
+
checkKeys(patch);
|
|
77
|
+
if (document.contents !== null && !isMap(document.contents))
|
|
78
|
+
throw new EditError("invalid", `${RULES_PATH} is not a map of settings (key: value); it was not changed`);
|
|
79
|
+
const changes = applyPatch(document, [], patch);
|
|
80
|
+
const contents = document.contents;
|
|
81
|
+
const next = isMap(contents) && contents.items.length === 0 ? "" : document.toString(WRITE);
|
|
82
|
+
if (changes.length === 0 || next === text)
|
|
83
|
+
throw new EditError("invalid", `${RULES_PATH} already says that; nothing was written`);
|
|
84
|
+
const problems = problemsOf(next);
|
|
85
|
+
if (problems.length > 0)
|
|
86
|
+
throw new EditError("invalid", `${RULES_PATH} was not changed: ${problems.join("; ")}`);
|
|
87
|
+
return { text: next, changes };
|
|
88
|
+
}
|
|
89
|
+
/** Merges the patch into the project's rules.yaml (creating it when there is none) as one history entry. */
|
|
90
|
+
export function setRules(root, patch, meta) {
|
|
91
|
+
return inProjectQueue(root, async () => {
|
|
92
|
+
const path = resolve(root, RULES_PATH);
|
|
93
|
+
const source = await readIfThere(path);
|
|
94
|
+
const { text, changes } = patchRulesText(source ?? "", patch);
|
|
95
|
+
const summary = `Set rules: ${changes.join(", ")}`.slice(0, 200);
|
|
96
|
+
const entry = source === undefined
|
|
97
|
+
? await writeNew(root, path, text, { author: meta.author, summary })
|
|
98
|
+
: await writeWithHistory(root, { path, source, file: RULES_PATH }, text, { author: meta.author, summary, file: RULES_PATH, before: source, after: text });
|
|
99
|
+
return { entry, changes };
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=rules-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules-patch.js","sourceRoot":"","sources":["../../src/core/rules-patch.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,sHAAsH;AACtH,4DAA4D;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,aAAa,EAAiB,MAAM,MAAM,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,c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MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAA;QACtC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC,MAAM,IAAI,EAAE,EAAE,KAAK,CAAC,CAAA;QAC7D,MAAM,OAAO,GAAG,cAAc,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QAChE,MAAM,KAAK,GACT,MAAM,KAAK,SAAS;YAClB,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACpE,CAAC,CAAC,MAAM,gBAAgB,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QAC7J,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;IAC3B,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Scan } from "./analyze.js";
|
|
2
|
+
import type { Edit } from "./types.js";
|
|
3
|
+
export declare function addSilkText(source: string, scan: Scan, edit: Extract<Edit, {
|
|
4
|
+
kind: "addSilkText";
|
|
5
|
+
}>): string;
|
|
6
|
+
export declare function setSilkText(source: string, scan: Scan, edit: Extract<Edit, {
|
|
7
|
+
kind: "setSilkText";
|
|
8
|
+
}>, locked: ReadonlySet<string>): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Edits of the board's silkscreen texts (`<silkscreentext>`), addressed by the engine's ids ("silkscreentext:1"; see
|
|
2
|
+
// board-items.ts). The words, side and height are held to the engine's limits (engine/silk-text.ts), so a text the
|
|
3
|
+
// build would drop is refused here with the same reason. Each edit writes only its element's text.
|
|
4
|
+
import MagicString from "magic-string";
|
|
5
|
+
import { silkHeightProblem, silkLayerProblem, silkWordsProblem, SILK_TEXT_TAG } from "../engine/silk-text.js";
|
|
6
|
+
import { EditError } from "./edit-error.js";
|
|
7
|
+
import { atTop, attributeNamed, MAX_COORDINATE, putAttribute } from "./edit-text.js";
|
|
8
|
+
import { formatLiteral } from "./literals.js";
|
|
9
|
+
import { addItem, removeAttribute, requireEditableItem } from "./pour-edits.js";
|
|
10
|
+
/** The longest name a text may carry, in characters. */
|
|
11
|
+
const MAX_NAME = 100;
|
|
12
|
+
/** A turn beyond this many degrees either way is a slip. */
|
|
13
|
+
const MAX_TURN = 360;
|
|
14
|
+
/** The props that may be removed: the text then takes the default height, no turn, or no name. */
|
|
15
|
+
const REMOVABLE = new Set(["height", "rotation", "name"]);
|
|
16
|
+
const coordinate = (value) => (typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= MAX_COORDINATE ? undefined : "must be a number of mm");
|
|
17
|
+
/** Each prop a text takes, with what is wrong with a value for it. */
|
|
18
|
+
const PROPS = {
|
|
19
|
+
text: silkWordsProblem,
|
|
20
|
+
x: (value) => coordinate(value) && `x ${coordinate(value)}`,
|
|
21
|
+
y: (value) => coordinate(value) && `y ${coordinate(value)}`,
|
|
22
|
+
layer: silkLayerProblem,
|
|
23
|
+
height: silkHeightProblem,
|
|
24
|
+
rotation: (value) => (typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= MAX_TURN ? undefined : `rotation must be a number of degrees from -${MAX_TURN} to ${MAX_TURN}`),
|
|
25
|
+
name: (value) => (typeof value === "string" && value.trim() !== "" && value.length <= MAX_NAME ? undefined : `name must be some words of at most ${MAX_NAME} characters`),
|
|
26
|
+
};
|
|
27
|
+
function formatted(key, value) {
|
|
28
|
+
const check = PROPS[key];
|
|
29
|
+
if (!check)
|
|
30
|
+
throw new EditError("invalid", `A silkscreen text has no prop "${key}"; it takes ${Object.keys(PROPS).join(", ")}`);
|
|
31
|
+
const problem = check(value);
|
|
32
|
+
if (problem)
|
|
33
|
+
throw new EditError("invalid", problem);
|
|
34
|
+
return formatLiteral(value);
|
|
35
|
+
}
|
|
36
|
+
/** Refuses a centre off the board's rectangle, when the board's rectangle is known. */
|
|
37
|
+
function checkOnBoard(x, y, box) {
|
|
38
|
+
if (!box || typeof x !== "number" || typeof y !== "number")
|
|
39
|
+
return;
|
|
40
|
+
if (x < box.minX || x > box.maxX || y < box.minY || y > box.maxY)
|
|
41
|
+
throw new EditError("invalid", `the text's middle (${x}, ${y}) lies outside the board; put it on the board`);
|
|
42
|
+
}
|
|
43
|
+
export function addSilkText(source, scan, edit) {
|
|
44
|
+
const ordered = { name: edit.name, text: edit.text, x: edit.x, y: edit.y, layer: edit.layer, height: edit.height, rotation: edit.rotation };
|
|
45
|
+
const attributes = Object.entries(ordered).flatMap(([key, value]) => (value === undefined ? [] : [`${key}=${formatted(key, value)}`]));
|
|
46
|
+
checkOnBoard(edit.x, edit.y, scan.model.boardBox);
|
|
47
|
+
return addItem(source, scan, SILK_TEXT_TAG, `<${SILK_TEXT_TAG} ${attributes.join(" ")} />`);
|
|
48
|
+
}
|
|
49
|
+
export function setSilkText(source, scan, edit, locked) {
|
|
50
|
+
const { item, node } = requireEditableItem(scan, SILK_TEXT_TAG, edit.id, locked);
|
|
51
|
+
if (Object.keys(edit.props).length === 0)
|
|
52
|
+
throw new EditError("invalid", `Nothing to change on ${edit.id}; give text, x, y, layer, height, rotation or name`);
|
|
53
|
+
const value = (key) => (key in edit.props ? edit.props[key] : item.props[key]?.literal);
|
|
54
|
+
if (atTop(item.parent))
|
|
55
|
+
checkOnBoard(value("x"), value("y"), scan.model.boardBox);
|
|
56
|
+
const out = new MagicString(source);
|
|
57
|
+
for (const [key, one] of Object.entries(edit.props)) {
|
|
58
|
+
if (one === null) {
|
|
59
|
+
if (!REMOVABLE.has(key))
|
|
60
|
+
throw new EditError("invalid", `${key} cannot be removed; only ${[...REMOVABLE].join(", ")} can`);
|
|
61
|
+
removeAttribute(out, source, node, key);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const text = formatted(key, one);
|
|
65
|
+
if (attributeNamed(source, node, key) && !item.props[key]?.editable) {
|
|
66
|
+
throw new EditError("readonly", `${edit.id}.${key} is an expression (${item.props[key]?.source}) and cannot be edited`);
|
|
67
|
+
}
|
|
68
|
+
putAttribute(out, source, node, key, text);
|
|
69
|
+
}
|
|
70
|
+
return out.toString();
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=silk-text-edits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"silk-text-edits.js","sourceRoot":"","sources":["../../src/core/silk-text-edits.ts"],"names":[],"mappings":"AAAA,qHAAqH;AACrH,mHAAmH;AACnH,mGAAmG;AACnG,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE7G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAG/E,wDAAwD;AACxD,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,4DAA4D;AAC5D,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,kGAAkG;AAClG,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAA;AAIzD,MAAM,UAAU,GAAU,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO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AM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,MAAM,IAAI,SAAS,CAAC,SAAS,EAAE,GAAG,GAAG,4BAA4B,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAC1H,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAA;YACvC,SAAQ;QACV,CAAC;QACD,MAAM,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAChC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;YACpE,MAAM,IAAI,SAAS,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,GAAG,sBAAsB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,wBAAwB,CAAC,CAAA;QACzH,CAAC;QACD,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5C,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC"}
|
package/dist/core/step-export.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Writes a circuit's board and parts as a STEP file alone (copperflow step): `<name>.step` beside the circuit, or the
|
|
2
2
|
// project file given. The design is built, made into solids and written; a design with errors is still written, since
|
|
3
3
|
// the file is a look at the shape, not an order.
|
|
4
|
+
import { refuseStreamName } from "./out-name.js";
|
|
4
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
6
|
import { basename, dirname, join, relative, sep } from "node:path";
|
|
6
7
|
import { designName } from "../engine/fab/names.js";
|
|
@@ -15,6 +16,8 @@ import { resolveCircuit, resolveInRoot } from "./workspace.js";
|
|
|
15
16
|
export function exportStep(root, file, options = {}) {
|
|
16
17
|
if (options.out !== undefined && !options.out.toLowerCase().endsWith(".step"))
|
|
17
18
|
throw new Error(`--out takes a file ending in .step (got ${options.out})`);
|
|
19
|
+
if (options.out !== undefined)
|
|
20
|
+
refuseStreamName(options.out);
|
|
18
21
|
return inProjectQueue(root, async () => {
|
|
19
22
|
const { file: circuit } = await resolveCircuit(root, file);
|
|
20
23
|
const name = designName(circuit);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-export.js","sourceRoot":"","sources":["../../src/core/step-export.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,sHAAsH;AACtH,iDAAiD;AACjD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAqB,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAY9D,mHAAmH;AACnH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAAY,EAAE,OAAO,GAA4C,EAAE;IAC1G,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IA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K,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAA;IACxK,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,MAAM,KAAK,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAA;IACxE,OAAO,CAAC,SAAS,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,qBAAqB,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACjJ,CAAC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -68,8 +68,8 @@ export interface DrawingInfo {
|
|
|
68
68
|
start: number;
|
|
69
69
|
end: number;
|
|
70
70
|
}
|
|
71
|
-
/** The tags of the board's own items: copper pours
|
|
72
|
-
export type BoardItemTag = "copperpour" | "hole";
|
|
71
|
+
/** The tags of the board's own items: copper pours, non-plated holes, silkscreen texts and drawings from SVG or DXF files. */
|
|
72
|
+
export type BoardItemTag = "copperpour" | "hole" | "silkscreentext" | "boardgraphic";
|
|
73
73
|
/**
|
|
74
74
|
* A copper pour (`<copperpour>`) or hole (`<hole>`), addressed by the id the engine gives it: "copperpour:<n>" or
|
|
75
75
|
* "hole:<n>" in source order (board-items.ts).
|
|
@@ -288,6 +288,51 @@ export type Edit = {
|
|
|
288
288
|
kind: "removeHole";
|
|
289
289
|
id: string;
|
|
290
290
|
}
|
|
291
|
+
/** Adds a `<silkscreentext>`: words centred on x, y in mm, on the top or bottom silkscreen; height in mm, rotation in degrees. */
|
|
292
|
+
| {
|
|
293
|
+
kind: "addSilkText";
|
|
294
|
+
text: string;
|
|
295
|
+
x: number;
|
|
296
|
+
y: number;
|
|
297
|
+
layer: "top" | "bottom";
|
|
298
|
+
height?: number;
|
|
299
|
+
rotation?: number;
|
|
300
|
+
name?: string;
|
|
301
|
+
}
|
|
302
|
+
/** Rewords, moves, turns, resizes or flips a board text: any of text, x, y, layer, height, rotation, name (null removes name, height or rotation). */
|
|
303
|
+
| {
|
|
304
|
+
kind: "setSilkText";
|
|
305
|
+
id: string;
|
|
306
|
+
props: Record<string, Literal | null>;
|
|
307
|
+
} | {
|
|
308
|
+
kind: "removeSilkText";
|
|
309
|
+
id: string;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Adds a `<boardgraphic>`: the drawing in `file` (graphics/<name>.svg or .dxf) centred on x, y in mm on `layer`;
|
|
313
|
+
* `width` in mm keeping its aspect, or `scale`; rotation in degrees; `fill` fills its closed lines.
|
|
314
|
+
*/
|
|
315
|
+
| {
|
|
316
|
+
kind: "addBoardGraphic";
|
|
317
|
+
file: string;
|
|
318
|
+
layer: string;
|
|
319
|
+
x: number;
|
|
320
|
+
y: number;
|
|
321
|
+
width?: number;
|
|
322
|
+
scale?: number;
|
|
323
|
+
rotation?: number;
|
|
324
|
+
fill?: boolean;
|
|
325
|
+
name?: string;
|
|
326
|
+
}
|
|
327
|
+
/** Moves, resizes, turns, re-layers or renames a drawing: any of file, layer, x, y, width, scale, rotation, fill, name (null removes width, scale, rotation, fill or name). */
|
|
328
|
+
| {
|
|
329
|
+
kind: "setBoardGraphic";
|
|
330
|
+
id: string;
|
|
331
|
+
props: Record<string, Literal | null>;
|
|
332
|
+
} | {
|
|
333
|
+
kind: "removeBoardGraphic";
|
|
334
|
+
id: string;
|
|
335
|
+
}
|
|
291
336
|
/** In a sheet file: renames a `<port>` and the trace ends that name its net (`net.<from>`). */
|
|
292
337
|
| {
|
|
293
338
|
kind: "renamePort";
|
|
@@ -314,7 +359,8 @@ export type Edit = {
|
|
|
314
359
|
}
|
|
315
360
|
/**
|
|
316
361
|
* The board from a drawing: its outline, its holes and its keepouts (on all layers) at once. A board that has holes or
|
|
317
|
-
* keepouts already is refused unless `replace`, which removes them first.
|
|
362
|
+
* keepouts already is refused unless `replace`, which removes them first. `keepItems` changes only the outline and
|
|
363
|
+
* leaves the holes and keepouts as they are (then `holes` and `keepouts` must be empty).
|
|
318
364
|
*/
|
|
319
365
|
| {
|
|
320
366
|
kind: "setBoardShape";
|
|
@@ -326,4 +372,10 @@ export type Edit = {
|
|
|
326
372
|
}[];
|
|
327
373
|
keepouts: Point[][];
|
|
328
374
|
replace: boolean;
|
|
375
|
+
keepItems?: boolean;
|
|
376
|
+
}
|
|
377
|
+
/** The board's copper layer count, `layers` on `<board>`. */
|
|
378
|
+
| {
|
|
379
|
+
kind: "setBoardLayers";
|
|
380
|
+
layers: 2 | 4;
|
|
329
381
|
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Offset } from "./component.js";
|
|
2
|
+
import type { BoardGraphic, BoardGraphicLayer, Diagnostic, SourceRef } from "./model.js";
|
|
3
|
+
import { type Props } from "./read-props.js";
|
|
4
|
+
export declare const BOARD_GRAPHIC_TAG = "boardgraphic";
|
|
5
|
+
export declare const BOARD_GRAPHIC_LAYERS: readonly BoardGraphicLayer[];
|
|
6
|
+
/** The copper layers a drawing can be on, named as pours name them; inner ones only on a 4-layer board. */
|
|
7
|
+
export declare const COPPER_GRAPHIC_LAYERS: readonly BoardGraphicLayer[];
|
|
8
|
+
export declare const isCopperGraphic: (graphic: {
|
|
9
|
+
layer: BoardGraphicLayer;
|
|
10
|
+
}) => boolean;
|
|
11
|
+
/** Why a drawing cannot carry a net in this release. */
|
|
12
|
+
export declare const GRAPHIC_NET_REFUSAL = "a drawing on copper belongs to no net yet; leave net out (it stands clear of every net)";
|
|
13
|
+
/** The smallest and largest placed width or height, in mm. */
|
|
14
|
+
export declare const MIN_GRAPHIC_SIZE = 0.5;
|
|
15
|
+
export declare const MAX_GRAPHIC_SIZE = 300;
|
|
16
|
+
/** The largest scale taken: one mm of the drawing to this many on the board. */
|
|
17
|
+
export declare const MAX_GRAPHIC_SCALE = 1000;
|
|
18
|
+
/** The only files a drawing is read from: an .svg or .dxf directly inside the project's graphics/ folder. */
|
|
19
|
+
export declare const GRAPHIC_FILE: RegExp;
|
|
20
|
+
/** A drawing's id: "boardgraphic:1", or inside a sub-sheet instance its path first. */
|
|
21
|
+
export declare const boardGraphicId: (index: number, instance: string | undefined) => string;
|
|
22
|
+
/** What is wrong with the file's path, or undefined. */
|
|
23
|
+
export declare function graphicFileProblem(file: unknown): string | undefined;
|
|
24
|
+
/** What is wrong with the layer, or undefined. */
|
|
25
|
+
export declare function graphicLayerProblem(layer: unknown): string | undefined;
|
|
26
|
+
/** What is wrong with a width in mm, or undefined. */
|
|
27
|
+
export declare function graphicWidthProblem(width: unknown): string | undefined;
|
|
28
|
+
/** What is wrong with a scale, or undefined. */
|
|
29
|
+
export declare function graphicScaleProblem(scale: unknown): string | undefined;
|
|
30
|
+
interface Origin {
|
|
31
|
+
offset: Offset;
|
|
32
|
+
index: number;
|
|
33
|
+
source: SourceRef;
|
|
34
|
+
instance?: string | undefined;
|
|
35
|
+
}
|
|
36
|
+
type ReadFile = (path: string) => string | undefined;
|
|
37
|
+
/** " (left out: 2 text elements)", or nothing when the reader left nothing out. */
|
|
38
|
+
export declare const leftOut: (skipped: readonly string[]) => string;
|
|
39
|
+
/**
|
|
40
|
+
* One `<boardgraphic>`: the drawing in `file` centred on x, y (shifted and turned by the groups), on the top silkscreen
|
|
41
|
+
* unless `layer` says, `width` mm wide keeping its aspect (or `scale` times its own size; its own size when neither),
|
|
42
|
+
* turned `rotation` degrees, its closed lines filled when `fill`. A bad prop, a missing file or one the reader refuses
|
|
43
|
+
* is warned about with the reason and left out.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildBoardGraphic(props: Props, origin: Origin, readFile: ReadFile | undefined): {
|
|
46
|
+
graphic?: BoardGraphic;
|
|
47
|
+
diagnostics: Diagnostic[];
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// A drawing from an SVG or DXF file placed on the board (`<boardgraphic file layer x y width|scale rotation fill name />`):
|
|
2
|
+
// the limits a person or an agent is held to, shared by the build (which warns and leaves a bad one out) and the core's
|
|
3
|
+
// edits (which refuse it). The file is read through the build's project files, and only from graphics/. Pure.
|
|
4
|
+
import { pcbPoint } from "./component.js";
|
|
5
|
+
import { diagnostic } from "./diagnostics.js";
|
|
6
|
+
import { MAX_COPPER_TRIANGLES, placeGraphic, triangulate } from "./graphic-place.js";
|
|
7
|
+
import { graphicKind, parseGraphic } from "./graphics/index.js";
|
|
8
|
+
import { PropReader } from "./read-props.js";
|
|
9
|
+
export const BOARD_GRAPHIC_TAG = "boardgraphic";
|
|
10
|
+
export const BOARD_GRAPHIC_LAYERS = ["top-silkscreen", "bottom-silkscreen", "top-mask", "bottom-mask", "top", "bottom", "inner1", "inner2"];
|
|
11
|
+
/** The copper layers a drawing can be on, named as pours name them; inner ones only on a 4-layer board. */
|
|
12
|
+
export const COPPER_GRAPHIC_LAYERS = ["top", "bottom", "inner1", "inner2"];
|
|
13
|
+
export const isCopperGraphic = (graphic) => COPPER_GRAPHIC_LAYERS.includes(graphic.layer);
|
|
14
|
+
/** Why a drawing cannot carry a net in this release. */
|
|
15
|
+
export const GRAPHIC_NET_REFUSAL = "a drawing on copper belongs to no net yet; leave net out (it stands clear of every net)";
|
|
16
|
+
/** The smallest and largest placed width or height, in mm. */
|
|
17
|
+
export const MIN_GRAPHIC_SIZE = 0.5;
|
|
18
|
+
export const MAX_GRAPHIC_SIZE = 300;
|
|
19
|
+
/** The largest scale taken: one mm of the drawing to this many on the board. */
|
|
20
|
+
export const MAX_GRAPHIC_SCALE = 1000;
|
|
21
|
+
/** The only files a drawing is read from: an .svg or .dxf directly inside the project's graphics/ folder. */
|
|
22
|
+
export const GRAPHIC_FILE = /^graphics\/[A-Za-z0-9._ -]+\.(svg|dxf)$/i;
|
|
23
|
+
/** A drawing's id: "boardgraphic:1", or inside a sub-sheet instance its path first. */
|
|
24
|
+
export const boardGraphicId = (index, instance) => instance === undefined ? `${BOARD_GRAPHIC_TAG}:${index}` : `${instance}/${BOARD_GRAPHIC_TAG}:${index}`;
|
|
25
|
+
/** What is wrong with the file's path, or undefined. */
|
|
26
|
+
export function graphicFileProblem(file) {
|
|
27
|
+
if (typeof file !== "string" || !GRAPHIC_FILE.test(file) || file.split("/").some((part) => part.includes(".."))) {
|
|
28
|
+
return 'file must be "graphics/<name>.svg" or "graphics/<name>.dxf", a drawing in the project\'s graphics folder';
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
/** What is wrong with the layer, or undefined. */
|
|
33
|
+
export function graphicLayerProblem(layer) {
|
|
34
|
+
if (BOARD_GRAPHIC_LAYERS.includes(layer))
|
|
35
|
+
return undefined;
|
|
36
|
+
return `layer must be one of ${BOARD_GRAPHIC_LAYERS.join(", ")}`;
|
|
37
|
+
}
|
|
38
|
+
/** What is wrong with a width in mm, or undefined. */
|
|
39
|
+
export function graphicWidthProblem(width) {
|
|
40
|
+
if (typeof width !== "number" || !Number.isFinite(width))
|
|
41
|
+
return "width must be a number of mm";
|
|
42
|
+
if (width < MIN_GRAPHIC_SIZE || width > MAX_GRAPHIC_SIZE)
|
|
43
|
+
return `width must be from ${MIN_GRAPHIC_SIZE} to ${MAX_GRAPHIC_SIZE} mm`;
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** What is wrong with a scale, or undefined. */
|
|
47
|
+
export function graphicScaleProblem(scale) {
|
|
48
|
+
if (typeof scale !== "number" || !Number.isFinite(scale) || scale <= 0 || scale > MAX_GRAPHIC_SCALE)
|
|
49
|
+
return `scale must be a number above 0 and at most ${MAX_GRAPHIC_SCALE}`;
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/** The props as written, or the reason they cannot be used. */
|
|
53
|
+
function readWanted(props, reader) {
|
|
54
|
+
const [x, y] = [reader.length("x"), reader.length("y")];
|
|
55
|
+
const layer = props["layer"] ?? "top-silkscreen";
|
|
56
|
+
const width = props["width"] === undefined ? undefined : reader.length("width");
|
|
57
|
+
const scale = props["scale"];
|
|
58
|
+
const rotation = props["rotation"] === undefined ? 0 : reader.angle("rotation");
|
|
59
|
+
const fill = props["fill"] ?? false;
|
|
60
|
+
if (x === undefined || y === undefined)
|
|
61
|
+
return "needs x and y";
|
|
62
|
+
if (props["net"] !== undefined)
|
|
63
|
+
return GRAPHIC_NET_REFUSAL;
|
|
64
|
+
const problem = graphicFileProblem(props["file"]) ??
|
|
65
|
+
graphicLayerProblem(layer) ??
|
|
66
|
+
(props["width"] !== undefined && scale !== undefined ? "give width or scale, not both" : undefined) ??
|
|
67
|
+
(props["width"] === undefined ? undefined : graphicWidthProblem(width)) ??
|
|
68
|
+
(scale === undefined ? undefined : graphicScaleProblem(scale)) ??
|
|
69
|
+
(rotation === undefined ? "rotation must be a number of degrees" : undefined) ??
|
|
70
|
+
(typeof fill === "boolean" ? undefined : "fill must be true or false");
|
|
71
|
+
if (problem !== undefined)
|
|
72
|
+
return problem;
|
|
73
|
+
const name = reader.string("name");
|
|
74
|
+
return {
|
|
75
|
+
file: props["file"],
|
|
76
|
+
layer: layer,
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
rotation: rotation,
|
|
80
|
+
fill: fill,
|
|
81
|
+
...(width === undefined ? {} : { width }),
|
|
82
|
+
...(typeof scale === "number" ? { scale } : {}),
|
|
83
|
+
...(name === undefined ? {} : { name }),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** " (left out: 2 text elements)", or nothing when the reader left nothing out. */
|
|
87
|
+
export const leftOut = (skipped) => (skipped.length === 0 ? "" : ` (left out: ${skipped.join("; ")})`);
|
|
88
|
+
/** Drawings in a project are few; the bound only guards against unbounded growth (keys hold the file's text). */
|
|
89
|
+
const MAX_CACHED = 32;
|
|
90
|
+
const cache = new Map();
|
|
91
|
+
/** The drawing read and sized, turned and mirrored about (0, 0), or the reason it cannot be: what is the same however it is moved. */
|
|
92
|
+
function shaped(path, text, size, rotation, fill, bottom, copper) {
|
|
93
|
+
const shapes = parseGraphic(text, graphicKind(path) ?? "svg");
|
|
94
|
+
if ("error" in shapes)
|
|
95
|
+
return `${path} could not be read: ${shapes.error}`;
|
|
96
|
+
if (shapes.fills.length === 0 && shapes.strokes.length === 0)
|
|
97
|
+
return `${path}: the drawing has nothing to draw${leftOut(shapes.skipped)}`;
|
|
98
|
+
const scale = size.scale ?? (size.width === undefined ? 1 : size.width / Math.max(shapes.width, Number.MIN_VALUE));
|
|
99
|
+
const [width, height] = [shapes.width * scale, shapes.height * scale];
|
|
100
|
+
if (Math.max(width, height) > MAX_GRAPHIC_SIZE)
|
|
101
|
+
return `it would be ${width.toFixed(1)} × ${height.toFixed(1)} mm, larger than ${MAX_GRAPHIC_SIZE} mm; give a smaller width or scale`;
|
|
102
|
+
if (Math.max(width, height) < MIN_GRAPHIC_SIZE)
|
|
103
|
+
return `it would be ${width.toFixed(2)} × ${height.toFixed(2)} mm, smaller than ${MIN_GRAPHIC_SIZE} mm; give a larger width or scale`;
|
|
104
|
+
const geometry = placeGraphic(shapes, { x: 0, y: 0, scale, rotation, bottom, fill });
|
|
105
|
+
const triangles = copper ? triangulate(geometry.areas) : undefined;
|
|
106
|
+
if (triangles && triangles.length > MAX_COPPER_TRIANGLES) {
|
|
107
|
+
return `on copper it is ${triangles.length} triangles, more than ${MAX_COPPER_TRIANGLES}; simplify the drawing (fewer points or shapes)`;
|
|
108
|
+
}
|
|
109
|
+
return { ...geometry, ...(triangles ? { triangles } : {}), skipped: [...shapes.skipped, ...geometry.skipped] };
|
|
110
|
+
}
|
|
111
|
+
/** shaped, remembered by the file's text and everything but the position, so a rebuild reads and places a drawing once. */
|
|
112
|
+
function cachedShape(path, text, size, rotation, fill, bottom, copper) {
|
|
113
|
+
const key = `${path}\u0000${size.width ?? ""}|${size.scale ?? ""}|${rotation}|${fill}|${bottom}|${copper}\u0000${text}`;
|
|
114
|
+
const hit = cache.get(key);
|
|
115
|
+
if (hit !== undefined)
|
|
116
|
+
return hit;
|
|
117
|
+
const made = shaped(path, text, size, rotation, fill, bottom, copper);
|
|
118
|
+
const frozen = typeof made === "string" ? made : deepFreeze(made);
|
|
119
|
+
if (cache.size >= MAX_CACHED)
|
|
120
|
+
cache.delete(cache.keys().next().value);
|
|
121
|
+
cache.set(key, frozen);
|
|
122
|
+
return frozen;
|
|
123
|
+
}
|
|
124
|
+
function deepFreeze(value) {
|
|
125
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
126
|
+
Object.freeze(value);
|
|
127
|
+
for (const one of Object.values(value))
|
|
128
|
+
deepFreeze(one);
|
|
129
|
+
}
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
/** The drawing placed, or the reason it cannot be: the file missing or refused by the reader, or too small or large once sized. */
|
|
133
|
+
function placed(wanted, origin, readFile) {
|
|
134
|
+
const text = readFile?.(wanted.file);
|
|
135
|
+
if (text === undefined)
|
|
136
|
+
return `${wanted.file} was not found in the project; put the drawing there first`;
|
|
137
|
+
const at = pcbPoint(origin.offset, wanted.x, wanted.y);
|
|
138
|
+
const rotation = wanted.rotation + (origin.offset.pcbRotation ?? 0);
|
|
139
|
+
const size = { ...(wanted.width === undefined ? {} : { width: wanted.width }), ...(wanted.scale === undefined ? {} : { scale: wanted.scale }) };
|
|
140
|
+
const shape = cachedShape(wanted.file, text, size, rotation, wanted.fill, wanted.layer.startsWith("bottom"), isCopperGraphic(wanted));
|
|
141
|
+
if (typeof shape === "string")
|
|
142
|
+
return shape;
|
|
143
|
+
const move = (p) => ({ x: p.x + at.x, y: p.y + at.y });
|
|
144
|
+
const { width: _w, scale: _s, ...rest } = wanted;
|
|
145
|
+
return {
|
|
146
|
+
...rest,
|
|
147
|
+
areas: shape.areas.map((area) => ({ outer: area.outer.map(move), holes: area.holes.map((hole) => hole.map(move)) })),
|
|
148
|
+
lines: shape.lines.map((line) => ({ points: line.points.map(move), width: line.width })),
|
|
149
|
+
...(shape.triangles ? { triangles: shape.triangles.map((triangle) => triangle.map(move)) } : {}),
|
|
150
|
+
width: shape.width,
|
|
151
|
+
height: shape.height,
|
|
152
|
+
skipped: [...shape.skipped],
|
|
153
|
+
x: at.x,
|
|
154
|
+
y: at.y,
|
|
155
|
+
rotation,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* One `<boardgraphic>`: the drawing in `file` centred on x, y (shifted and turned by the groups), on the top silkscreen
|
|
160
|
+
* unless `layer` says, `width` mm wide keeping its aspect (or `scale` times its own size; its own size when neither),
|
|
161
|
+
* turned `rotation` degrees, its closed lines filled when `fill`. A bad prop, a missing file or one the reader refuses
|
|
162
|
+
* is warned about with the reason and left out.
|
|
163
|
+
*/
|
|
164
|
+
export function buildBoardGraphic(props, origin, readFile) {
|
|
165
|
+
const id = boardGraphicId(origin.index, origin.instance);
|
|
166
|
+
const reader = new PropReader(props, BOARD_GRAPHIC_TAG, origin.source);
|
|
167
|
+
const wanted = readWanted(props, reader);
|
|
168
|
+
const result = typeof wanted === "string" ? wanted : placed(wanted, origin, readFile);
|
|
169
|
+
if (typeof result === "string") {
|
|
170
|
+
const warning = diagnostic("bad-value", "warning", `${BOARD_GRAPHIC_TAG} ${id}: ${result}; it is ignored`, [id], origin.source);
|
|
171
|
+
return { diagnostics: [...reader.diagnostics, warning] };
|
|
172
|
+
}
|
|
173
|
+
return { graphic: { id, ...result, source: origin.source }, diagnostics: reader.diagnostics };
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=board-graphic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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SAAS,EAAE,GAAG,iBAAiB,IAAI,EAAE,KAAK,MAAM,iBAAiB,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAC/H,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,CAAA;IAC1D,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAA;AAC/F,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rules } from "../rules/schema.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type CopperPiece } from "./copper-pieces.js";
|
|
3
3
|
import type { Violation } from "./violation.js";
|
|
4
4
|
/** What sets the gap: the classes (their clearances and their pair entry), or the fabrication minimum when it is larger. */
|
|
5
5
|
export declare function ruleText(rules: Rules, a: string, b: string, required: number): string;
|
|
@@ -2,6 +2,7 @@ import { COPPER_LAYERS } from "../../core/layout-file.js";
|
|
|
2
2
|
import { copperTouches } from "../copper.js";
|
|
3
3
|
import { naturalCompare } from "../order.js";
|
|
4
4
|
import { requiredClearance } from "../rules/classes.js";
|
|
5
|
+
import { isDrawingNet } from "./copper-pieces.js";
|
|
5
6
|
import { bounds, closestPoints, shapeDistance } from "./geometry.js";
|
|
6
7
|
import { GridIndex } from "./grid-index.js";
|
|
7
8
|
import { breaksMinimum } from "./limits.js";
|
|
@@ -58,6 +59,9 @@ function measureLayer(slots, reach, cell, found) {
|
|
|
58
59
|
* centred on the pad. A pad with no net is never one conductor with copper, so copper on it is always reported.
|
|
59
60
|
*/
|
|
60
61
|
function joined({ a, b }) {
|
|
62
|
+
// A drawing on copper belongs to no net: whatever it meets, it is never one conductor with it.
|
|
63
|
+
if (a.piece.kind === "drawing" || b.piece.kind === "drawing")
|
|
64
|
+
return false;
|
|
61
65
|
if (a.piece.kind !== "pad" && b.piece.kind !== "pad")
|
|
62
66
|
return copperTouches(a.shape, b.shape);
|
|
63
67
|
const [pad, other] = a.piece.kind === "pad" ? [a, b] : [b, a];
|
|
@@ -79,6 +83,20 @@ export function ruleText(rules, a, b, required) {
|
|
|
79
83
|
const byClasses = requiredClearance({ ...rules, fabrication: { ...rules.fabrication, minClearance: 0 } }, a, b);
|
|
80
84
|
return byClasses < required ? `the fabrication minimum is ${mm(required)} mm` : `${pairName(rules, a, b)} needs ${mm(required)} mm`;
|
|
81
85
|
}
|
|
86
|
+
/** "the track t0007 of GND": a piece in words, its net named when it has a real one. */
|
|
87
|
+
function pieceWords(piece) {
|
|
88
|
+
const kind = piece.kind === "drawing" ? "drawing" : piece.kind;
|
|
89
|
+
return `the ${kind} ${piece.id}${piece.net !== undefined && !isDrawingNet(piece.net) ? ` of ${piece.net.replace(/^net\./, "")}` : ""}`;
|
|
90
|
+
}
|
|
91
|
+
/** A drawing on copper too near or touching other copper, in words for a person; undefined for two other pieces. */
|
|
92
|
+
function drawingMessage({ a, b, distance }, required, rules) {
|
|
93
|
+
const [drawing, other] = a.piece.kind === "drawing" ? [a.piece, b.piece] : b.piece.kind === "drawing" ? [b.piece, a.piece] : [undefined, undefined];
|
|
94
|
+
if (drawing === undefined || other === undefined)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (distance <= 0)
|
|
97
|
+
return `${drawing.id} touches ${pieceWords(other)}; a drawing on copper must stand clear of every net`;
|
|
98
|
+
return `${drawing.id} is ${mm(distance)} mm from ${pieceWords(other)}; ${ruleText(rules, drawing.className, other.className, required)}`;
|
|
99
|
+
}
|
|
82
100
|
/** Two named nets that differ: copper.ts never leaves joined copper so, unless the copper touches no pad. */
|
|
83
101
|
const twoNets = ({ a, b }) => a.piece.net !== undefined && b.piece.net !== undefined && a.piece.net !== b.piece.net;
|
|
84
102
|
/**
|
|
@@ -92,7 +110,7 @@ function judge(nearest, rules) {
|
|
|
92
110
|
const required = requiredClearance(rules, a.piece.className, b.piece.className);
|
|
93
111
|
if (!breaksMinimum(distance, required))
|
|
94
112
|
return undefined;
|
|
95
|
-
const message = `${a.piece.id} and ${b.piece.id} are ${gap(distance)}; ${ruleText(rules, a.piece.className, b.piece.className, required)}`;
|
|
113
|
+
const message = drawingMessage(nearest, required, rules) ?? `${a.piece.id} and ${b.piece.id} are ${gap(distance)}; ${ruleText(rules, a.piece.className, b.piece.className, required)}`;
|
|
96
114
|
return copperViolation("copper-clearance", message, [a.piece.id, b.piece.id], [a.piece.id, b.piece.id], midpoint(closestPoints(a.shape, b.shape)));
|
|
97
115
|
}
|
|
98
116
|
const onLayer = (layer) => (slot) => slot.piece.layers.includes(layer);
|