-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from tscircuit/fix/convert-circuitjson-to-dsn-…
…file fix: convert circuit json to dsn file
- Loading branch information
Showing
5 changed files
with
641 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
lib/dsn-pcb/circuit-json-to-dsn-json/process-pcb-traces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { AnyCircuitElement } from "circuit-json" | ||
import type { DsnPcb } from "../types" | ||
|
||
export function processPcbTraces( | ||
circuitElements: AnyCircuitElement[], | ||
pcb: DsnPcb, | ||
) { | ||
for (const element of circuitElements) { | ||
if (element.type === "pcb_trace") { | ||
const pcbTrace = element | ||
|
||
const netName = | ||
pcbTrace.source_trace_id || `Net-${pcb.network.nets.length + 1}` | ||
|
||
const wire = { | ||
path: { | ||
layer: | ||
pcbTrace.route[0].route_type === "wire" | ||
? pcbTrace.route[0].layer === "top" | ||
? "F.Cu" | ||
: "B.Cu" | ||
: "F.Cu", // Default to F.Cu if not a wire route | ||
width: | ||
pcbTrace.route[0].route_type === "wire" | ||
? pcbTrace.route[0].width * 1000 | ||
: 200, // Convert mm to um, or use a default value | ||
coordinates: [] as number[], | ||
}, | ||
net: netName, | ||
type: "route", | ||
} | ||
|
||
for (const point of pcbTrace.route) { | ||
wire.path.coordinates.push(point.x * 1000) // Convert mm to um | ||
wire.path.coordinates.push(-point.y * 1000) // Negate Y to match DSN coordinate system | ||
} | ||
|
||
pcb.wiring.wires.push(wire) | ||
} | ||
} | ||
} |
Oops, something went wrong.