Skip to content

Commit

Permalink
add display_pin_label to schematic ports
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 7, 2024
1 parent 32f9e9e commit f388171
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 9 additions & 0 deletions lib/components/primitive-components/Port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ export class Port extends PrimitiveComponent<typeof portProps> {

this.facingDirection = getRelativeDirection(containerCenter, portCenter)

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

let bestDisplayPinLabel: string | undefined = undefined
for (const portHint of sourcePort?.port_hints ?? []) {
if (portHint.match(/^(pin)?\d+$/)) continue
bestDisplayPinLabel = portHint
}

const schematic_port = db.schematic_port.insert({
schematic_component_id: this.parent?.schematic_component_id!,
center: portCenter,
Expand All @@ -284,6 +292,7 @@ export class Port extends PrimitiveComponent<typeof portProps> {
side_of_component: localPortInfo?.side,
pin_number: props.pinNumber,
true_ccw_index: localPortInfo?.trueIndex,
display_pin_label: bestDisplayPinLabel,
})

this.schematic_port_id = schematic_port.schematic_port_id
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@tscircuit/props": "^0.0.83",
"@tscircuit/schematic-autolayout": "^0.0.5",
"@tscircuit/soup-util": "^0.0.33",
"circuit-json": "^0.0.93",
"circuit-json": "^0.0.94",
"circuit-json-to-connectivity-map": "^0.0.17",
"circuit-to-svg": "^0.0.59",
"nanoid": "^5.0.7",
Expand Down
140 changes: 140 additions & 0 deletions tests/examples/example6-voltage-regulator.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { createUseComponent } from "@tscircuit/core"
import type { CommonLayoutProps } from "@tscircuit/props"
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

const pinLabels = {
pin7: ["pin7", "EP"],
pin6: ["pin6", "IN"],
pin5: ["pin5", "PG"],
pin4: ["pin4", "EN"],
pin3: ["pin3", "GND"],
pin2: ["pin2", "FB"],
pin1: ["pin1", "OUT"],
} as const

interface Props extends CommonLayoutProps {
name: string
}

const TPS74601PDRVR = (props: Props) => {
return (
<chip
{...props}
cadModel={{
objUrl:
"https://modelcdn.tscircuit.com/easyeda_models/download?uuid=c909123e4a7a4da5a0270979fee6c02c&pn=C2837407",
rotationOffset: { x: 0, y: 0, z: 0 },
positionOffset: { x: 0, y: 0, z: 0 },
}}
pinLabels={pinLabels}
schPinSpacing={0.75}
supplierPartNumbers={{
lcsc: ["C2837407"],
}}
footprint={
<footprint>
<smtpad
portHints={["pin7"]}
pcbX="0mm"
pcbY="0mm"
width="1.5999967999999998mm"
height="0.9999979999999999mm"
shape="rect"
/>
<smtpad
portHints={["pin6"]}
pcbX="-0.6500113999999968mm"
pcbY="0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<smtpad
portHints={["pin5"]}
pcbX="0mm"
pcbY="0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<smtpad
portHints={["pin4"]}
pcbX="0.6500113999999968mm"
pcbY="0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<smtpad
portHints={["pin3"]}
pcbX="0.6500113999999968mm"
pcbY="-0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<smtpad
portHints={["pin2"]}
pcbX="0mm"
pcbY="-0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<smtpad
portHints={["pin1"]}
pcbX="-0.6500113999999968mm"
pcbY="-0.9751059999999967mm"
width="0.39999919999999994mm"
height="0.45001179999999996mm"
shape="rect"
/>
<silkscreenpath
route={[
{ x: -1.0500360000000057, y: -1.0490199999999987 },
{ x: -1.0500360000000057, y: 1.0500360000000057 },
]}
/>
<silkscreenpath
route={[
{ x: 1.0500359999999915, y: -1.0490199999999987 },
{ x: 1.0500359999999915, y: 1.0500360000000057 },
]}
/>
</footprint>
}
/>
)
}

const useTPS74601PDRVR = createUseComponent(TPS74601PDRVR, pinLabels)

test("example6 voltage regulator", async () => {
const { circuit } = await getTestFixture()
const U1 = useTPS74601PDRVR("U1")

circuit.add(
<board width="10mm" height="10mm">
<U1 />
</board>,
)

circuit.render()

const schematicPorts = circuit.db.schematic_port.list()

const displayPinLabels = schematicPorts.map((p) => p.display_pin_label)

expect(displayPinLabels.sort()).toEqual([
"EN",
"EP",
"FB",
"GND",
"IN",
"OUT",
"PG",
undefined,
undefined,
])
})

0 comments on commit f388171

Please sign in to comment.