Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: port numbers in order #55

Merged
merged 2 commits into from
Dec 8, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type {
AnyCircuitElement,
PcbComponent,
PcbPort,
SourceComponentBase,
SourcePort,
} from "circuit-json"
import { getComponentValue } from "lib/utils/get-component-value"
import { getFootprintName } from "lib/utils/get-footprint-name"
Expand Down Expand Up @@ -119,15 +121,28 @@ export function processComponentsAndPads(
firstComponent.sourceComponent?.source_component_id,
) as PcbComponent
if (pad.shape === "rect") {
// Find the corresponding pcb_port and its source_port
const pcbPort = circuitElements.find(
(e) => e.type === "pcb_port" && e.pcb_port_id === pad.pcb_port_id,
) as PcbPort
const sourcePort =
pcbPort &&
(circuitElements.find(
(e) =>
e.type === "source_port" &&
e.source_port_id === pcbPort.source_port_id,
) as SourcePort)

return {
padstack_name: getPadstackName({
shape: "rect",
width: pad.width * 1000,
height: pad.height * 1000,
}),
pin_number:
pad.port_hints?.find((hint) => !Number.isNaN(Number(hint))) ||
1,
sourcePort?.port_hints?.find(
(hint) => !Number.isNaN(Number(hint)),
) || 1,
x: (pad.x - pcbComponent.center.x) * 1000,
y: (pad.y - pcbComponent.center.y) * 1000,
}
Expand Down
19 changes: 17 additions & 2 deletions lib/dsn-pcb/circuit-json-to-dsn-json/process-plated-holes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type {
AnyCircuitElement,
PcbComponent,
PcbPort,
SourceComponentBase,
SourcePort,
} from "circuit-json"
import {
createCircularPadstack,
Expand Down Expand Up @@ -153,18 +155,31 @@ export function processPlatedHoles(
? pin
: undefined
} else if (hole.shape === "oval" || hole.shape === "pill") {
// Find the corresponding pcb_port and its source_port
const pcbPort = circuitElements.find(
(e) => e.type === "pcb_port" && e.pcb_port_id === hole.pcb_port_id,
) as PcbPort
const sourcePort =
pcbPort &&
(circuitElements.find(
(e) =>
e.type === "source_port" &&
e.source_port_id === pcbPort.source_port_id,
) as SourcePort)

const pin = {
padstack_name: getPadstackName({
shape: hole.shape,
width: hole.hole_width * 1000,
height: hole.hole_height * 1000,
}),
pin_number:
hole.port_hints?.find((hint) => !Number.isNaN(Number(hint))) || 1,
sourcePort?.port_hints?.find(
(hint) => !Number.isNaN(Number(hint)),
) || 1,
x: (Number(hole.x.toFixed(3)) - pcbComponent.center.x) * 1000,
y: (Number(hole.y.toFixed(3)) - pcbComponent.center.y) * 1000,
}

// Only return pin if it doesn't already exist in the image
return !existingImage.pins.some(
(existingPin) =>
Expand Down
Loading
Loading