Skip to content
Open
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
2 changes: 1 addition & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ export function convertDsnPcbToCircuitJson(
)
}

if (dsnPcb.structure.planes) {
for (const plane of dsnPcb.structure.planes) {
if (!plane.polygon) continue
const coords = plane.polygon.coordinates
const points = []
for (let i = 0; i < coords.length; i += 2) {
const pt = applyToPoint(transformDsnUnitToMm, {
x: coords[i],
y: coords[i + 1],
})
points.push(pt)
}
elements.push({
type: "pcb_copper_pour",
pcb_copper_pour_id: `pcb_copper_pour_${plane.net}`,
layer: plane.polygon.layer === "Route2" ? "top" : "bottom", // TODO: proper layer mapping
shape: "polygon",
points,
// Optional net assignment:
// pcb_net_id: `pcb_net_${plane.net}`
} as any)
}
}

elements.push(
...convertDsnPcbComponentsToSourceComponentsAndPorts({
dsnPcb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ export const convertDsnPcbComponentsToSourceComponentsAndPorts = ({
// Create ports for each pin in the image
if (image.pins) {
for (const pin of image.pins) {
const parsedPinNumber = Number(pin.pin_number)
const port: SourcePort = {
type: "source_port",
source_port_id: `source_port_${component.name}-Pad${pin.pin_number}_${place.refdes}`,
source_component_id: sourceComponent.source_component_id,
name: `${place.refdes}-${pin.pin_number}`,
pin_number: Number(pin.pin_number),
port_hints: [],
}
if (!isNaN(parsedPinNumber)) {
port.pin_number = parsedPinNumber
}
// Handle case where place coordinates might be null/undefined
const placeX = place.x || 0
const placeY = place.y || 0
Expand Down
33 changes: 33 additions & 0 deletions lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export function processResolution(nodes: ASTNode[]): Resolution {
export function processStructure(nodes: ASTNode[]): Structure {
const structure: Partial<Structure> = {
layers: [],
planes: [],
}

nodes.forEach((node) => {
Expand All @@ -225,6 +226,9 @@ export function processStructure(nodes: ASTNode[]): Structure {
case "boundary":
structure.boundary = processBoundary(node.children!.slice(1))
break
case "plane":
structure.planes!.push(processPlane(node.children!.slice(1)))
break
case "via":
if (
node.children![1].type === "Atom" &&
Expand Down Expand Up @@ -306,6 +310,35 @@ function processBoundary(nodes: ASTNode[]): Boundary {
return boundary as Boundary
}

function processPlane(nodes: ASTNode[]): Plane {
const plane: Partial<Plane> = {}

if (nodes[0]?.type === "Atom" && typeof nodes[0].value === "string") {
plane.net = nodes[0].value
}

const polygonNode = nodes.find(
(node) =>
node.type === "List" &&
node.children?.[0]?.type === "Atom" &&
node.children[0].value === "polygon",
)

if (polygonNode) {
const polyChildren = polygonNode.children!
plane.polygon = {
layer: polyChildren[1]?.type === "Atom" ? (polyChildren[1].value as string) : "",
width: polyChildren[2]?.type === "Atom" ? (polyChildren[2].value as number) : 0,
coordinates: polyChildren
.slice(3)
.filter((node) => node.type === "Atom" && typeof node.value === "number")
.map((node) => node.value as number),
}
}

return plane as Plane
}

function processPath(nodes: ASTNode[]): Path {
// Find the path node which contains layer, width and coordinates
const pathNode = nodes.find(
Expand Down
10 changes: 10 additions & 0 deletions lib/dsn-pcb/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export interface Structure {
boundary: Boundary
via: string
rule: Rule
planes?: Plane[]
}

export interface Layer {
Expand Down Expand Up @@ -139,6 +140,15 @@ export interface Boundary {
}
}

export interface Plane {
net: string
polygon?: {
layer: string
width: number
coordinates: number[]
}
}

export interface Path {
layer: string
width: number
Expand Down
Loading
Loading