Skip to content

Commit

Permalink
fix: port numbers in order
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishabh18 committed Dec 8, 2024
1 parent d9471a3 commit d0dd10d
Show file tree
Hide file tree
Showing 5 changed files with 2,466 additions and 1,011 deletions.
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
14 changes: 11 additions & 3 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,24 @@ 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,
pin_number: 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

1 comment on commit d0dd10d

@seveibar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imrishabh hmm we might be covering up a different bug with pcb port port_hints but not sure.

Make sure to use soup-util instead of the messy .find(…), it is much shorter and more readable!, it would change this from 10 lines into 1-2!

Please sign in to comment.