Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f81b8b0
Fix schPinSpacing changing the width of the schematic box
RaghavArora14 Oct 24, 2025
e1e6fc4
Delete PR-DESCRIPTION.md
RaghavArora14 Oct 24, 2025
186d155
Delete reproduce-issue.md
RaghavArora14 Oct 24, 2025
551b80d
Remove comments on padding logic for dimensions
RaghavArora14 Oct 24, 2025
d5d3338
Simplify fix and combine tests into single file
RaghavArora14 Oct 24, 2025
5a3af2d
Move padding constant to root scope with descriptive name
RaghavArora14 Oct 24, 2025
c336810
Fix schPinSpacing changing the width of the schematic box
RaghavArora14 Oct 24, 2025
7b1179e
Rename test to repro68-schpinspacing-width
RaghavArora14 Oct 25, 2025
b8e82b6
Add minimum width for chips with left/right pin labels
RaghavArora14 Oct 26, 2025
e76cab9
Format code and rename schWidth to resolvedSchWidth
RaghavArora14 Oct 26, 2025
38ce274
Convert portHints to pinLabels for width calculation
RaghavArora14 Oct 26, 2025
fcb9a29
Format Fix
RaghavArora14 Oct 26, 2025
668fb8a
Fix portHints extraction to access footprint children directly
RaghavArora14 Oct 26, 2025
f356196
Fix portHints extraction to access footprint children directly
RaghavArora14 Oct 26, 2025
01d50a7
Access Footprint from children instead of props
RaghavArora14 Oct 26, 2025
c6f94c4
Update snapshot for chip-layer-flip test
RaghavArora14 Oct 26, 2025
3b93c88
refactor: use selectAll('port') and getNameAndAliases() for pin labels
RaghavArora14 Oct 27, 2025
bf92957
test: update snapshots for tests with numeric portHints
RaghavArora14 Oct 27, 2025
f56aee4
refactor: remove redundant pinLabels merging logic
RaghavArora14 Oct 27, 2025
d128a8f
bun format
RaghavArora14 Oct 27, 2025
232618b
fix: keep props.pinLabels for label-to-pin-number mapping and update …
RaghavArora14 Oct 27, 2025
55c6eaa
refactor: extract _getBestDisplayPinLabel() to consolidate pin label …
RaghavArora14 Oct 27, 2025
2ee7292
fix: add type cast for Port in _getPinLabelsFromPorts
RaghavArora14 Oct 27, 2025
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
31 changes: 29 additions & 2 deletions lib/components/base-components/NormalComponent/NormalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,26 @@ export class NormalComponent<
)
}

/**
* Extract pin labels from ports using existing Port logic
*/
_getPinLabelsFromPorts(): Record<string, string> {
const ports = this.selectAll("port") as Port[]
const pinLabels: Record<string, string> = {}

for (const port of ports) {
const pinNumber = port.props.pinNumber
if (pinNumber !== undefined) {
const bestLabel = port._getBestDisplayPinLabel()
if (bestLabel) {
pinLabels[`pin${pinNumber}`] = bestLabel
}
}
}

return pinLabels
}

_getSchematicBoxDimensions(): SchematicBoxDimensions | null {
// Only valid if we don't have a schematic symbol
if (this.getSchematicSymbol()) return null
Expand All @@ -1244,19 +1264,26 @@ export class NormalComponent<

const pinSpacing = props.schPinSpacing ?? 0.2

const pinLabelsFromPorts = this._getPinLabelsFromPorts()
// Merge with props.pinLabels for label-to-pin-number mapping
const allPinLabels = {
...pinLabelsFromPorts,
...props.pinLabels,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

is this merging necessary anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kept props.pinLabels merging - Still needed for label-to-pin-number mapping in getNumericSchPinStyle() and getAllDimensionsForSchematicBox() to handle non-numeric labels like "A4" or "C" in schPortArrangement

Copy link
Contributor

Choose a reason for hiding this comment

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

are you sure?

Copy link
Contributor

Choose a reason for hiding this comment

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

(please show the difference via a snapshot)


const dimensions = getAllDimensionsForSchematicBox({
schWidth: props.schWidth,
schHeight: props.schHeight,
schPinSpacing: pinSpacing,
numericSchPinStyle: getNumericSchPinStyle(
props.schPinStyle,
props.pinLabels,
allPinLabels,
),

pinCount,

schPortArrangement: this._getSchematicPortArrangement()!,
pinLabels: props.pinLabels,
pinLabels: allPinLabels,
})

return dimensions
Expand Down
54 changes: 33 additions & 21 deletions lib/components/primitive-components/Port/Port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,38 @@ export class Port extends PrimitiveComponent<typeof portProps> {
this.pcb_port_id = pcb_port.pcb_port_id
}

/**
* Get the best display label for this port based on port_hints
* Filters out generic patterns and applies showPinAliases logic
*/
_getBestDisplayPinLabel(): string | undefined {
const { db } = this.root!
const sourcePort = db.source_port.get(this.source_port_id!)

// Filter out generic patterns like "pin1", "1", etc.
const labelHints: string[] = []
for (const portHint of sourcePort?.port_hints ?? []) {
if (portHint.match(/^(pin)?\d+$/)) continue
if (
portHint.match(/^(left|right)/) &&
!sourcePort?.name.match(/^(left|right)/)
)
continue
labelHints.push(portHint)
}

const parentNormalComponent = this.getParentNormalComponent()
const showPinAliases = parentNormalComponent?.props?.showPinAliases

if (showPinAliases && labelHints.length > 0) {
return labelHints.join("/")
} else if (labelHints.length > 0) {
return labelHints[0]
}

return undefined
}

doInitialSchematicPortRender(): void {
const { db } = this.root!
const { _parsedProps: props } = this
Expand Down Expand Up @@ -514,28 +546,8 @@ export class Port extends PrimitiveComponent<typeof portProps> {
}[localPortInfo.side] as "up" | "down" | "left" | "right"
}

const sourcePort = db.source_port.get(this.source_port_id!)

const labelHints: string[] = []
for (const portHint of sourcePort?.port_hints ?? []) {
if (portHint.match(/^(pin)?\d+$/)) continue
if (
portHint.match(/^(left|right)/) &&
!sourcePort?.name.match(/^(left|right)/)
)
continue
labelHints.push(portHint)
}

let bestDisplayPinLabel: string | undefined = undefined
const bestDisplayPinLabel = this._getBestDisplayPinLabel()
const parentNormalComponent = this.getParentNormalComponent()
const showPinAliases = parentNormalComponent?.props?.showPinAliases
if (showPinAliases && labelHints.length > 0) {
bestDisplayPinLabel = labelHints.join("/")
} else if (labelHints.length > 0) {
// show the first label hint
bestDisplayPinLabel = labelHints[0]
}

const schematicPortInsertProps: Omit<SchematicPort, "schematic_port_id"> = {
type: "schematic_port",
Expand Down
44 changes: 32 additions & 12 deletions lib/utils/schematic/getAllDimensionsForSchematicBox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getSizeOfSidesFromPortArrangement } from "./getSizeOfSidesFromPortArrangement"
import { parsePinNumberFromLabelsOrThrow } from "./parsePinNumberFromLabelsOrThrow"

const DEFAULT_SCHEMATIC_BOX_PADDING_MM = 0.4

export type VerticalPortSideConfiguration = {
direction?: "top-to-bottom" | "bottom-to-top"
pins: number[]
Expand Down Expand Up @@ -344,13 +346,31 @@ export const getAllDimensionsForSchematicBox = (
}

// Use lengths to determine schWidth and schHeight
let schWidth = params.schWidth
if (schWidth === undefined) {
schWidth = Math.max(
sideLengths.top + params.schPinSpacing * 2,
sideLengths.bottom + params.schPinSpacing * 2,
let resolvedSchWidth = params.schWidth
if (resolvedSchWidth === undefined) {
resolvedSchWidth = Math.max(
sideLengths.top + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
sideLengths.bottom + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
)

// Check if there are actual pin labels on left/right sides
if (params.pinLabels) {
const leftRightPins = orderedTruePorts.filter(
(p) => p.side === "left" || p.side === "right",
)
const hasLeftRightLabels = leftRightPins.some(
(p) =>
params.pinLabels?.[`pin${p.pinNumber}`] ||
params.pinLabels?.[p.pinNumber],
)

if (hasLeftRightLabels) {
// Apply minimum width when there are left/right pins with labels
const MIN_WIDTH_FOR_SIDE_PINS = 0.5
resolvedSchWidth = Math.max(resolvedSchWidth, MIN_WIDTH_FOR_SIDE_PINS)
}
}

const labelWidth = params.pinLabels
? Math.max(
...Object.values(params.pinLabels).map(
Expand All @@ -361,21 +381,21 @@ export const getAllDimensionsForSchematicBox = (

// When label is present, only then add some padding to the width
const LABEL_PADDING = labelWidth > 0 ? 1.1 : 0
schWidth = Math.max(schWidth, labelWidth + LABEL_PADDING)
resolvedSchWidth = Math.max(resolvedSchWidth, labelWidth + LABEL_PADDING)
}

let schHeight = params.schHeight
if (!schHeight) {
schHeight = Math.max(
sideLengths.left + params.schPinSpacing * 2,
sideLengths.right + params.schPinSpacing * 2,
sideLengths.left + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
sideLengths.right + DEFAULT_SCHEMATIC_BOX_PADDING_MM,
)
}

const trueEdgePositions = {
// Top left corner
left: {
x: -schWidth / 2 - portDistanceFromEdge,
x: -resolvedSchWidth / 2 - portDistanceFromEdge,
y: sideLengths.left / 2,
},
// bottom left corner
Expand All @@ -385,7 +405,7 @@ export const getAllDimensionsForSchematicBox = (
},
// bottom right corner
right: {
x: schWidth / 2 + portDistanceFromEdge,
x: resolvedSchWidth / 2 + portDistanceFromEdge,
y: -sideLengths.right / 2,
},
// top right corner
Expand Down Expand Up @@ -426,12 +446,12 @@ export const getAllDimensionsForSchematicBox = (
return port
},
getSize(): { width: number; height: number } {
return { width: schWidth, height: schHeight }
return { width: resolvedSchWidth, height: schHeight }
},
getSizeIncludingPins(): { width: number; height: number } {
return {
width:
schWidth +
resolvedSchWidth +
(sidePinCounts.leftSize || sidePinCounts.rightSize ? 0.4 : 0),
height:
schHeight +
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading