Skip to content

Commit

Permalink
Merge pull request #70 from tscircuit/feat/pcb-via
Browse files Browse the repository at this point in the history
feat: pcb via added
  • Loading branch information
imrishabh18 authored Sep 16, 2024
2 parents b527adc + 13ba88d commit 780a97e
Show file tree
Hide file tree
Showing 3 changed files with 4,994 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib/circuit-to-pcb-svg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnySoupElement } from "@tscircuit/soup"
import type { AnyCircuitElement } from "@tscircuit/soup"
import { type INode as SvgObject, stringify } from "svgson"
import {
type Matrix,
Expand All @@ -14,13 +14,15 @@ import { createSvgObjectsFromPcbSilkscreenPath } from "./svg-object-fns/create-s
import { createSvgObjectsFromPcbSilkscreenText } from "./svg-object-fns/create-svg-objects-from-pcb-silkscreen-text"
import { createSvgObjectsFromPcbTrace } from "./svg-object-fns/create-svg-objects-from-pcb-trace"
import { createSvgObjectsFromSmtPad } from "./svg-object-fns/create-svg-objects-from-smt-pads"
import { createSvgObjectsFromPcbVia } from "./svg-object-fns/create-svg-objects-from-pcb-via"

const OBJECT_ORDER: AnySoupElement["type"][] = [
const OBJECT_ORDER: AnyCircuitElement["type"][] = [
"pcb_plated_hole",
"pcb_fabrication_note_text",
"pcb_fabrication_note_path",
"pcb_silkscreen_text",
"pcb_silkscreen_path",
"pcb_via",
"pcb_trace",
"pcb_smtpad",
"pcb_component",
Expand All @@ -37,7 +39,7 @@ interface Options {
}

function circuitJsonToPcbSvg(
soup: AnySoupElement[],
soup: AnyCircuitElement[],
options?: Options,
): string {
let minX = Number.POSITIVE_INFINITY
Expand Down Expand Up @@ -176,7 +178,7 @@ function circuitJsonToPcbSvg(
}
}

function createSvgObjects(elm: AnySoupElement, transform: Matrix): SvgObject[] {
function createSvgObjects(elm: AnyCircuitElement, transform: Matrix): SvgObject[] {
switch (elm.type) {
case "pcb_component":
return [createSvgObjectsFromPcbComponent(elm, transform)].filter(Boolean)
Expand All @@ -194,6 +196,8 @@ function createSvgObjects(elm: AnySoupElement, transform: Matrix): SvgObject[] {
return createSvgObjectsFromPcbFabricationNoteText(elm, transform)
case "pcb_silkscreen_path":
return createSvgObjectsFromPcbSilkscreenPath(elm, transform)
case "pcb_via":
return createSvgObjectsFromPcbVia(elm, transform)
default:
return []
}
Expand Down
39 changes: 39 additions & 0 deletions src/lib/svg-object-fns/create-svg-objects-from-pcb-via.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { PCBVia } from "@tscircuit/soup"
import { applyToPoint } from "transformation-matrix"

export function createSvgObjectsFromPcbVia(hole: PCBVia, transform: any): any {
const [x, y] = applyToPoint(transform, [hole.x, hole.y])
const scaledOuterWidth = hole.outer_diameter * Math.abs(transform.a)
const scaledOuterHeight = hole.outer_diameter * Math.abs(transform.a)
const scaledHoleWidth = hole.hole_diameter * Math.abs(transform.a)
const scaledHoleHeight = hole.hole_diameter * Math.abs(transform.a)

const outerRadius = Math.min(scaledOuterWidth, scaledOuterHeight) / 2
const innerRadius = Math.min(scaledHoleWidth, scaledHoleHeight) / 2
return {
name: "g",
type: "element",
children: [
{
name: "circle",
type: "element",
attributes: {
class: "pcb-hole-outer",
cx: x.toString(),
cy: y.toString(),
r: outerRadius.toString(),
},
},
{
name: "circle",
type: "element",
attributes: {
class: "pcb-hole-inner",
cx: x.toString(),
cy: y.toString(),
r: innerRadius.toString(),
},
},
],
}
}
Loading

0 comments on commit 780a97e

Please sign in to comment.