-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from tscircuit/pinheader
support for pinheaders and implied footprint strings
- Loading branch information
Showing
9 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { pinHeaderProps } from "@tscircuit/props" | ||
import { NormalComponent } from "../base-components/NormalComponent" | ||
import { Port } from "../primitive-components/Port" | ||
import type { BaseSymbolName } from "lib/utils/constants" | ||
|
||
export class PinHeader extends NormalComponent<typeof pinHeaderProps> { | ||
get config() { | ||
return { | ||
componentName: "PinHeader", | ||
zodProps: pinHeaderProps, | ||
schematicSymbolName: "pinrow_horz" as BaseSymbolName, | ||
} | ||
} | ||
|
||
_getImpliedFootprintString(): string | null { | ||
const pinCount = | ||
this._parsedProps.pinCount ?? this._parsedProps.pinLabels?.length ?? 0 | ||
const holeDiameter = this._parsedProps.holeDiameter | ||
const platedDiameter = this._parsedProps.platedDiameter | ||
const pitch = this._parsedProps.pitch | ||
if (pinCount > 0 && pitch) { | ||
if (!holeDiameter && !platedDiameter) { | ||
return `pinrow${pinCount}_p${pitch}` | ||
} | ||
return `pinrow${pinCount}_p${pitch}_id${holeDiameter}_od${platedDiameter}` | ||
} | ||
return null | ||
} | ||
|
||
initPorts() { | ||
const pinCount = | ||
this._parsedProps.pinCount ?? this._parsedProps.pinLabels?.length ?? 1 | ||
for (let i = 1; i <= pinCount; i++) { | ||
this.add( | ||
new Port({ | ||
name: `pin${i}`, | ||
pinNumber: i, | ||
aliases: [], | ||
}), | ||
) | ||
} | ||
} | ||
|
||
doInitialSourceRender() { | ||
const { db } = this.root! | ||
const { _parsedProps: props } = this | ||
|
||
const source_component = db.source_component.insert({ | ||
ftype: "simple_chip", | ||
name: props.name, | ||
// manufacturer_part_number: props., | ||
supplier_part_numbers: props.supplierPartNumbers, | ||
// gender: props.gender, | ||
// pitch: props.pitch, | ||
}) | ||
|
||
this.source_component_id = source_component.source_component_id | ||
} | ||
|
||
doInitialSchematicComponentRender() { | ||
const { db } = this.root! | ||
const { _parsedProps: props } = this | ||
|
||
const schematic_component = db.schematic_component.insert({ | ||
center: { x: props.schX ?? 0, y: props.schY ?? 0 }, | ||
rotation: props.schRotation ?? 0, | ||
size: { width: 2, height: props.pinCount ?? 1 }, | ||
source_component_id: this.source_component_id!, | ||
port_arrangement: { | ||
left_size: 0, | ||
right_size: props.pinCount ?? 1, | ||
}, | ||
}) | ||
|
||
this.schematic_component_id = schematic_component.schematic_component_id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/components/normal-components/__snapshots__/header-pcb.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
tests/components/normal-components/__snapshots__/header-schematic.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { test, expect } from "bun:test" | ||
import { getTestFixture } from "tests/fixtures/get-test-fixture" | ||
|
||
test("header with default pinrow footprint", () => { | ||
const { project } = getTestFixture() | ||
|
||
project.add( | ||
<board width="10mm" height="10mm"> | ||
<pinheader name="J1" pinCount={4} pitch="2.54mm" gender="male" /> | ||
</board>, | ||
) | ||
|
||
project.render() | ||
|
||
// Check if header component was created | ||
const header = project.selectOne("pinheader") | ||
|
||
expect(header).not.toBeNull() | ||
expect(header!.props.name).toBe("J1") | ||
|
||
// Check PCB primitives | ||
const platedHoles = project.db.pcb_plated_hole.list() | ||
expect(platedHoles).toHaveLength(4) | ||
|
||
// Verify pin spacing | ||
const holePositions = platedHoles.map((h) => h.x).sort((a, b) => a - b) | ||
const spacing = holePositions[1] - holePositions[0] | ||
expect(spacing).toBeCloseTo(2.54, 2) | ||
|
||
expect(project).toMatchPcbSnapshot(import.meta.path) | ||
expect(project).toMatchSchematicSnapshot(import.meta.path) | ||
}) |