Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions assets/simple-route-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"layerCount": 2,
"minTraceWidth": 0.5,
"obstacles": [
{
"type": "rect",
"layers": ["top", "bottom"],
"center": { "x": 50, "y": 50 },
"width": 10,
"height": 20,
"connectedTo": ["net1", "net2"]
}
],
"connections": [
{
"name": "connection1",
"pointsToConnect": [
{ "x": 0, "y": 0, "layer": "top" },
{ "x": 10, "y": 10, "layer": "top" }
]
}
],
"bounds": {
"minX": 0,
"maxX": 100,
"minY": 0,
"maxY": 100
},
"traces": [
{
"type": "pcb_trace",
"pcb_trace_id": "trace1",
"route": [
{
"route_type": "wire",
"x": 0,
"y": 0,
"width": 0.5,
"layer": "top"
},
{
"route_type": "via",
"x": 10,
"y": 10,
"to_layer": "bottom",
"from_layer": "top"
}
]
}
]
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@tscircuit/core": "^0.0.331",
"circuit-json": "^0.0.144",
"zustand": "^5.0.3"
}
}
37 changes: 35 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import { useCallback } from "react"
import { useStore } from "./store"
import { CircuitJsonPreview } from "@tscircuit/runframe"
import type { AnyCircuitElement } from "circuit-json"
import type { SimpleRouteJson } from "@tscircuit/core"

export const App = () => {
const circuitJson = useStore((s) => s.circuitJson)
const setCircuitJson = useStore((s) => s.setCircuitJson)
const reset = useStore((s) => s.reset)

const convertSimpleRouteJsonToCircuitJson = (simpleRouteJson: SimpleRouteJson): AnyCircuitElement[] => {
const circuitJson: AnyCircuitElement[] = []

for (const connection of simpleRouteJson.connections) {
const trace: AnyCircuitElement = {
type: "pcb_trace",
pcb_trace_id: connection.name,
route: connection.pointsToConnect.map(point => ({
route_type: "wire",
x: point.x,
y: point.y,
layer: point.layer as "top" | "bottom" | "inner1" | "inner2" | "inner3" | "inner4" | "inner5" | "inner6",
width: simpleRouteJson.minTraceWidth,
})),
}
circuitJson.push(trace)
}

return circuitJson
}

const handleDrop = useCallback(
(e: React.DragEvent) => {
e.preventDefault()
Expand All @@ -16,7 +39,12 @@ export const App = () => {
reader.onload = (e) => {
try {
const json = JSON.parse(e.target?.result as string)
setCircuitJson(json)
if (json.connections && json.minTraceWidth !== undefined) {
const circuitJson = convertSimpleRouteJsonToCircuitJson(json)
setCircuitJson(circuitJson)
} else {
setCircuitJson(json)
}
} catch (err) {
console.error("Failed to parse JSON:", err)
}
Expand All @@ -35,7 +63,12 @@ export const App = () => {
reader.onload = (e) => {
try {
const json = JSON.parse(e.target?.result as string)
setCircuitJson(json)
if (json.connections && json.minTraceWidth !== undefined) {
const circuitJson = convertSimpleRouteJsonToCircuitJson(json)
setCircuitJson(circuitJson)
} else {
setCircuitJson(json)
}
} catch (err) {
console.error("Failed to parse JSON:", err)
}
Expand Down