Skip to content

Commit

Permalink
Merge pull request #64 from tscircuit/order-fab-notes
Browse files Browse the repository at this point in the history
order the fab notes to be on top
  • Loading branch information
seveibar authored Sep 11, 2024
2 parents b5c482e + d5f8dbb commit 3df66bf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 48 deletions.
61 changes: 19 additions & 42 deletions src/lib/circuit-to-pcb-svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import { createSvgObjectsFromPcbFabricationNotePath } from "./svg-object-fns/cre
import { createSvgObjectsFromPcbSilkscreenPath } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-path"
import { createSvgObjectsFromPcbFabricationNoteText } from "./svg-object-fns/create-svg-objects-from-pcb-fabrication-note-text"

const OBJECT_ORDER: AnySoupElement["type"][] = [
"pcb_fabrication_note_text",
"pcb_fabrication_note_path",
"pcb_silkscreen_text",
"pcb_silkscreen_path",
"pcb_trace",
"pcb_plated_hole",
"pcb_smtpad",
"pcb_component",
]

interface PointObjectNotation {
x: number
y: number
Expand Down Expand Up @@ -66,24 +77,11 @@ function circuitJsonToPcbSvg(soup: AnySoupElement[]): string {
scale(scaleFactor, -scaleFactor), // Flip in y-direction
)

const traceElements = soup
.filter((elm) => elm.type === "pcb_trace")
.flatMap((elm) => createSvgObjects(elm, transform))

const holeElements = soup
.filter((elm) => elm.type === "pcb_plated_hole")
.flatMap((elm) => createSvgObjects(elm, transform))

const silkscreenElements = soup
.filter((elm) => elm.type === "pcb_silkscreen_path")
.flatMap((elm) => createSvgObjectsFromPcbSilkscreenPath(elm, transform))

const otherElements = soup
.filter(
(elm) =>
!["pcb_trace", "pcb_plated_hole", "pcb_silkscreen_path"].includes(
elm.type,
),
const svgObjects = soup
.sort(
(a, b) =>
(OBJECT_ORDER.indexOf(b.type) ?? 9999) -
(OBJECT_ORDER.indexOf(a.type) ?? 9999),
)
.flatMap((item) => createSvgObjects(item, transform))

Expand Down Expand Up @@ -139,30 +137,7 @@ function circuitJsonToPcbSvg(soup: AnySoupElement[]): string {
},
},
createSvgObjectFromPcbBoundary(transform, minX, minY, maxX, maxY),
{
name: "g",
type: "element",
attributes: { id: "other-elements" },
children: otherElements,
},
{
name: "g",
type: "element",
attributes: { id: "traces" },
children: traceElements,
},
{
name: "g",
type: "element",
attributes: { id: "holes" },
children: holeElements,
},
{
name: "g",
type: "element",
attributes: { id: "silkscreen" },
children: silkscreenElements,
},
...svgObjects,
].filter((child): child is SvgObject => child !== null),
}

Expand Down Expand Up @@ -208,6 +183,8 @@ function createSvgObjects(elm: AnySoupElement, transform: Matrix): SvgObject[] {
return createSvgObjectsFromPcbFabricationNotePath(elm, transform)
case "pcb_fabrication_note_text":
return createSvgObjectsFromPcbFabricationNoteText(elm, transform)
case "pcb_silkscreen_path":
return createSvgObjectsFromPcbSilkscreenPath(elm, transform)
default:
return []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function createSvgObjectsFromPcbFabricationNotePath(
attributes: {
class: "pcb-fabrication-note-path",
stroke: "rgba(255,255,255,0.5)",
fill: "none",
d: path,
"stroke-width": (
fabNotePath.stroke_width * Math.abs(transform.a)
Expand Down
3 changes: 2 additions & 1 deletion tests/__snapshots__/bottom-smtpads-in-blue.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions tests/__snapshots__/bottom-trace-in-blue.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/__snapshots__/fabnotes.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3df66bf

Please sign in to comment.