Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 18, 2024
1 parent 893f958 commit ceee88e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function convertDsnPcbToCircuitJson(
const elements: AnyCircuitElement[] = []

// TODO use pcb.resolution.unit and pcb.resolution.value
const transformUmToMm = scale(1 / 1000)
const transformDsnUnitToMm = scale(1 / 1000)

// Add the board
// You must use the dsnPcb.boundary to get the center, width and height
Expand All @@ -34,12 +34,12 @@ export function convertDsnPcbToCircuitJson(
const minX = Math.min(...boundaryPath.map(([x]) => x))
const maxY = Math.max(...boundaryPath.map(([, y]) => y))
const minY = Math.min(...boundaryPath.map(([, y]) => y))
board.center = applyToPoint(transformUmToMm, {
board.center = applyToPoint(transformDsnUnitToMm, {
x: (maxX + minX) / 2,
y: (maxY + minY) / 2,
})
board.width = (maxX - minX) * transformUmToMm.a
board.height = (maxY - minY) * transformUmToMm.a
board.width = (maxX - minX) * transformDsnUnitToMm.a
board.height = (maxY - minY) * transformDsnUnitToMm.a
} else {
throw new Error(
`Couldn't read DSN boundary, add support for dsnPcb.structure.boundary["${Object.keys(dsnPcb.structure.boundary).join(",")}"]`,
Expand All @@ -49,20 +49,25 @@ export function convertDsnPcbToCircuitJson(
elements.push(board)

// Convert padstacks to SMT pads using the transformation matrix
elements.push(...convertPadstacksToSmtPads(dsnPcb, transformUmToMm))
elements.push(...convertPadstacksToSmtPads(dsnPcb, transformDsnUnitToMm))

// Convert wires to PCB traces using the transformation matrix
if (dsnPcb.wiring && dsnPcb.network) {
elements.push(
...convertWiresToPcbTraces(
dsnPcb.wiring,
dsnPcb.network,
transformUmToMm,
transformDsnUnitToMm,
),
)
}

elements.push(...convertDsnPcbComponentsToSourceComponentsAndPorts(dsnPcb))
elements.push(
...convertDsnPcbComponentsToSourceComponentsAndPorts({
dsnPcb,
transformDsnUnitToMm,
}),
)
elements.push(
...convertNetsToSourceNetsAndTraces({
dsnPcb,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { AnySourceComponent, PcbPort, SourcePort } from "circuit-json"
import { applyToPoint, type Matrix } from "transformation-matrix"
import type { DsnPcb, Image, Pin } from "lib/dsn-pcb/types"

export const convertDsnPcbComponentsToSourceComponentsAndPorts = (
dsnPcb: DsnPcb,
): Array<AnySourceComponent | SourcePort | PcbPort> => {
export const convertDsnPcbComponentsToSourceComponentsAndPorts = ({
dsnPcb,
transformDsnUnitToMm,
}: {
dsnPcb: DsnPcb
transformDsnUnitToMm: Matrix
}): Array<AnySourceComponent | SourcePort | PcbPort> => {
const result: Array<AnySourceComponent | SourcePort | PcbPort> = []

// Map to store image definitions for component lookup
Expand Down Expand Up @@ -35,14 +40,17 @@ export const convertDsnPcbComponentsToSourceComponentsAndPorts = (
pin_number: pin.pin_number,
port_hints: [],
}
const pcb_port_center = applyToPoint(transformDsnUnitToMm, {
x: component.place.x + pin.x,
y: component.place.y + pin.y,
})
const pcb_port: PcbPort = {
pcb_port_id: `pcb_port_${component.name}-Pad${pin.pin_number}`,
type: "pcb_port",
source_port_id: port.source_port_id,
pcb_component_id: component.name,
// TODO get X/Y position of pad from dsnPcb
x: 0,
y: 0,
x: pcb_port_center.x,
y: pcb_port_center.y,
layers: [],
}
result.push(port, pcb_port)
Expand Down

0 comments on commit ceee88e

Please sign in to comment.