Skip to content

Commit

Permalink
moved to circuit-json (#78)
Browse files Browse the repository at this point in the history
* moved to circuit-json

* type fixes

* fixed resistor test
  • Loading branch information
ShiboSoftwareDev authored Sep 23, 2024
1 parent 5498ccd commit ebc078f
Show file tree
Hide file tree
Showing 25 changed files with 197 additions and 69 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/pcb/convert-circuit-json-to-pcb-svg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Point, AnyCircuitElement } from "@tscircuit/soup"
import type { Point, AnyCircuitElement } from "circuit-json"
import { type INode as SvgObject, stringify } from "svgson"
import {
type Matrix,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBBoard, Point } from "@tscircuit/soup"
import type { PCBBoard, Point } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import type { SvgObject } from "lib/svg-object"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PcbSilkscreenPath, PcbFabricationNotePath } from "@tscircuit/soup"
import type { PcbSilkscreenPath, PcbFabricationNotePath } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import type { SvgObject } from "lib/svg-object"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PcbFabricationNoteText } from "@tscircuit/soup"
import type { PcbFabricationNoteText } from "circuit-json"
import type { INode as SvgObject } from "svgson"
import { toString as matrixToString } from "transformation-matrix"
import {
Expand Down
2 changes: 1 addition & 1 deletion lib/pcb/svg-object-fns/create-svg-objects-from-pcb-hole.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBHole } from "@tscircuit/soup"
import type { PCBHole } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import type { SvgObject } from "lib/svg-object"
import { HOLE_COLOR } from "../colors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBPlatedHole } from "@tscircuit/soup"
import type { PCBPlatedHole } from "circuit-json"
import { applyToPoint } from "transformation-matrix"
import type { SvgObject } from "lib/svg-object"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PcbSilkscreenPath } from "@tscircuit/soup"
import type { PcbSilkscreenPath } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import type { SvgObject } from "lib/svg-object"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PcbSilkscreenText } from "@tscircuit/soup"
import type { PcbSilkscreenText } from "circuit-json"
import type { INode as SvgObject } from "svgson"
import {
type Matrix,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBTrace } from "@tscircuit/soup"
import type { PCBTrace } from "circuit-json"
import { pairs } from "lib/utils/pairs"
import type { INode as SvgObject } from "svgson"
import { applyToPoint } from "transformation-matrix"
Expand Down
2 changes: 1 addition & 1 deletion lib/pcb/svg-object-fns/create-svg-objects-from-pcb-via.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBVia } from "@tscircuit/soup"
import type { PCBVia } from "circuit-json"
import { applyToPoint } from "transformation-matrix"

export function createSvgObjectsFromPcbVia(hole: PCBVia, transform: any): any {
Expand Down
2 changes: 1 addition & 1 deletion lib/pcb/svg-object-fns/create-svg-objects-from-smt-pads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PCBSMTPad } from "@tscircuit/soup"
import type { PCBSMTPad } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import { layerNameToColor } from "../layer-name-to-color"

Expand Down
2 changes: 1 addition & 1 deletion lib/sch/convert-circuit-json-to-schematic-svg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyCircuitElement } from "@tscircuit/soup"
import type { AnyCircuitElement } from "circuit-json"
import { getSvg, symbols } from "schematic-symbols"
import { parseSync, stringify } from "svgson"

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"vite-tsconfig-paths": "^5.0.1"
},
"peerDependencies": {
"@tscircuit/soup": "*"
"circuit-json": "*"
},
"dependencies": {
"@tscircuit/footprinter": "^0.0.57",
"@tscircuit/routing": "^1.3.5",
"@tscircuit/soup": "*",
"circuit-json": "*",
"@tscircuit/soup-util": "^0.0.28",
"@types/node": "^22.5.5",
"schematic-symbols": "^0.0.17",
Expand Down
4 changes: 2 additions & 2 deletions stories/net-label-not-overlap.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react"
import { circuitJsonToSchematicSvg, circuitJsonToPcbSvg } from "../lib/index.js"
import { circuitJsonToSchematicSvg, convertCircuitJsonToPcbSvg } from "../lib/index.js"

const soup: any = [
{
Expand Down Expand Up @@ -1130,7 +1130,7 @@ const soup: any = [
]

export const NetLabelNotOverlap = () => {
const result = circuitJsonToPcbSvg(soup)
const result = convertCircuitJsonToPcbSvg(soup)

return <div dangerouslySetInnerHTML={{ __html: result }} />
}
Expand Down
7 changes: 4 additions & 3 deletions stories/pcb-silkscreen-text.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react"
import { circuitJsonToPcbSvg } from "../lib/index.js"
import type { AnyCircuitElement } from "@tscircuit/soup"
import { convertCircuitJsonToPcbSvg } from "../lib/index.js"
import type { AnyCircuitElement } from "circuit-json"

export const PcbSilkScreenText = () => {
const result = circuitJsonToPcbSvg(pcbSoup)
const result = convertCircuitJsonToPcbSvg(pcbSoup)

// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
return <div dangerouslySetInnerHTML={{ __html: result }} />
Expand Down Expand Up @@ -189,6 +189,7 @@ const pcbSoup: AnyCircuitElement[] = [
{
type: "pcb_silkscreen_text",
layer: "top",
pcb_silkscreen_text_id: "pcb_silkscreen_text_0",
font: "tscircuit2024",
font_size: 1,
pcb_component_id: "pcb_generic_component_0",
Expand Down
58 changes: 30 additions & 28 deletions stories/pcb-via.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { AnyCircuitElement } from "@tscircuit/soup"
import { circuitJsonToPcbSvg } from "../lib/index.js"
import type { AnyCircuitElement } from "circuit-json"
import { convertCircuitJsonToPcbSvg } from "../lib/index.js"

export const PcbViaInNullTraceHit = () => {
const result = circuitJsonToPcbSvg(pcbSoup)
const result = convertCircuitJsonToPcbSvg(pcbSoup)

// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
return <div dangerouslySetInnerHTML={{ __html: result }} />
Expand Down Expand Up @@ -1999,6 +1999,8 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_board",
num_layers: 2,
thickness: 1.2,
pcb_board_id: "pcb_board_0",
center: {
x: 0,
Expand Down Expand Up @@ -3923,7 +3925,7 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_via",
// pcb_via_id: "pcb_via_0",
pcb_via_id: "pcb_via_0",
x: -4.281249780862737,
y: -14.233181814231745,
hole_diameter: 0.3,
Expand All @@ -3934,7 +3936,7 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_via",
// pcb_via_id: "pcb_via_1",
pcb_via_id: "pcb_via_1",
x: 34.20591131679997,
y: -5.359753005603952,
hole_diameter: 0.3,
Expand Down Expand Up @@ -4189,8 +4191,8 @@ const pcbSoup: AnyCircuitElement[] = [
source_trace_id: "source_trace_12",
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_0",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_0",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#117(from:.SW5 .pin1 to:.U1 .D6) />]",
Expand All @@ -4205,7 +4207,7 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_via",
// pcb_via_id: "pcb_via_2",
pcb_via_id: "pcb_via_2",
x: 13.702636532712475,
y: -2.1984238421998494,
hole_diameter: 0.3,
Expand All @@ -4216,7 +4218,7 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_via",
// pcb_via_id: "pcb_via_3",
pcb_via_id: "pcb_via_3",
x: 37.17086973641227,
y: -10.456476442519742,
hole_diameter: 0.3,
Expand Down Expand Up @@ -4394,8 +4396,8 @@ const pcbSoup: AnyCircuitElement[] = [
source_trace_id: "source_trace_15",
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_1",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_1",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#120(from:.SW8 .pin1 to:.U1 .D6) />]",
Expand Down Expand Up @@ -4500,8 +4502,8 @@ const pcbSoup: AnyCircuitElement[] = [
source_trace_id: "source_trace_17",
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_2",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_2",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#122(from:.D1 .pin2 to:.U1 .D2) />]",
Expand All @@ -4515,8 +4517,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_3",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_3",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#123(from:.D2 .pin2 to:.U1 .D2) />]",
Expand All @@ -4530,8 +4532,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_4",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_4",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#124(from:.D3 .pin2 to:.U1 .D2) />]",
Expand All @@ -4545,8 +4547,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_5",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_5",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#125(from:.D4 .pin2 to:.U1 .D3) />]",
Expand All @@ -4560,8 +4562,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_6",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_6",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#126(from:.D5 .pin2 to:.U1 .D3) />]",
Expand All @@ -4575,8 +4577,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_7",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_7",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#127(from:.D6 .pin2 to:.U1 .D3) />]",
Expand All @@ -4590,8 +4592,8 @@ const pcbSoup: AnyCircuitElement[] = [
pcb_component_ids: [],
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_8",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_8",
error_type: "pcb_trace_error",
message:
"Could not find a route for [object <trace#128(from:.D7 .pin2 to:.U1 .D4) />]",
Expand All @@ -4606,7 +4608,7 @@ const pcbSoup: AnyCircuitElement[] = [
},
{
type: "pcb_via",
// pcb_via_id: "pcb_via_4",
pcb_via_id: "pcb_via_4",
x: 23.674326938532413,
y: 12.282089990345455,
hole_diameter: 0.3,
Expand Down Expand Up @@ -4728,8 +4730,8 @@ const pcbSoup: AnyCircuitElement[] = [
source_trace_id: "source_trace_25",
},
{
type: "pcb_error",
pcb_error_id: "pcb_error_9",
type: "pcb_trace_error",
pcb_trace_error_id: "pcb_error_9",
error_type: "pcb_trace_error",
message:
"Error getting obstacles for autorouting: getObstaclesFromTrace currently only supports horizontal and vertical traces (not diagonals) Conflicting trace: source_trace_25, start: (7, 12.200000000000001), end: (23.674326938532413, 12.282089990345455)",
Expand Down
4 changes: 2 additions & 2 deletions stories/silkscreen-with-hole-and-trace.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react"
import { circuitJsonToPcbSvg } from "../lib/index.js"
import { convertCircuitJsonToPcbSvg } from "../lib/index.js"

export const SilkScreenPcbPlatedHole = () => {
const result = circuitJsonToPcbSvg(pcbSoup as any)
const result = convertCircuitJsonToPcbSvg(pcbSoup as any)

// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
return <div dangerouslySetInnerHTML={{ __html: result }} />
Expand Down
4 changes: 2 additions & 2 deletions tests/pcb/bottom-smtpads-in-blue.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from "bun:test"
import { circuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"

test("bottom trace is blue", () => {
expect(
circuitJsonToPcbSvg([
convertCircuitJsonToPcbSvg([
{
type: "pcb_smtpad",
x: 0,
Expand Down
4 changes: 2 additions & 2 deletions tests/pcb/bottom-trace-in-blue.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test"
import { circuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"

const soup: any = [
{
Expand Down Expand Up @@ -331,5 +331,5 @@ const soup: any = [
]

test("bottom trace is blue", () => {
expect(circuitJsonToPcbSvg(soup)).toMatchSvgSnapshot(import.meta.path)
expect(convertCircuitJsonToPcbSvg(soup)).toMatchSvgSnapshot(import.meta.path)
})
4 changes: 2 additions & 2 deletions tests/pcb/colored-fabnotes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test"
import { circuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"
import { Circuit } from "@tscircuit/core"

test("fabrication note path and fabrication note text", () => {
Expand Down Expand Up @@ -32,7 +32,7 @@ test("fabrication note path and fabrication note text", () => {

const circuitJson = circuit.getCircuitJson()

const svg = circuitJsonToPcbSvg(circuitJson as any)
const svg = convertCircuitJsonToPcbSvg(circuitJson as any)

expect(svg).toMatchSvgSnapshot(import.meta.path)
})
4 changes: 2 additions & 2 deletions tests/pcb/fabnotes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test"
import { circuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"
import { Circuit } from "@tscircuit/core"

test("fabrication note path and fabrication note text", () => {
Expand Down Expand Up @@ -27,7 +27,7 @@ test("fabrication note path and fabrication note text", () => {

const circuitJson = circuit.getCircuitJson()

const svg = circuitJsonToPcbSvg(circuitJson as any)
const svg = convertCircuitJsonToPcbSvg(circuitJson as any)

expect(svg).toMatchSvgSnapshot(import.meta.path)
})
2 changes: 1 addition & 1 deletion tests/pcb/hole.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test"
import { circuitJsonToPcbSvg, convertCircuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"
import { Circuit } from "@tscircuit/core"

test("should render a hole", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/pcb/silkscreen-with-hole-and-trace.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from "bun:test"
import { circuitJsonToPcbSvg } from "lib"
import { convertCircuitJsonToPcbSvg } from "lib"

const pcbSoup: any[] = [
{
Expand Down Expand Up @@ -1075,5 +1075,5 @@ const pcbSoup: any[] = [
]

test("Silkscreen with PCB Plated Hole", () => {
expect(circuitJsonToPcbSvg(pcbSoup)).toMatchSvgSnapshot(import.meta.path)
expect(convertCircuitJsonToPcbSvg(pcbSoup)).toMatchSvgSnapshot(import.meta.path)
})
Loading

0 comments on commit ebc078f

Please sign in to comment.