Skip to content

Commit

Permalink
placeholder jumper
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Aug 31, 2024
1 parent 16bc48f commit 50e928e
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 2 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
preload = ["./tests/fixtures/preload.ts"]
1 change: 1 addition & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { Trace } from "./primitive-components/Trace"
export { TraceHint } from "./primitive-components/TraceHint"
export { Group } from "./primitive-components/Group"
export { Chip } from "./normal-components/Chip"
export { Jumper } from "./normal-components/Jumper"
3 changes: 2 additions & 1 deletion lib/components/normal-components/Chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class Chip<PinLabels extends string = never> extends NormalComponent<
const { _parsedProps: props } = this

if (props.pinLabels) {
for (const [pinNumber, label] of Object.entries(props.pinLabels)) {
for (let [pinNumber, label] of Object.entries(props.pinLabels)) {
pinNumber = pinNumber.replace("pin", "")
const port = this.selectOne(`port[pinNumber='${pinNumber}']`)
if (!port) {
throw new Error(
Expand Down
121 changes: 121 additions & 0 deletions lib/components/normal-components/Jumper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { NormalComponent } from "lib/components/base-components/NormalComponent"
import { jumperProps } from "@tscircuit/props"
import { Port } from "../primitive-components/Port"
import type { BaseSymbolName } from "lib/utils/constants"
import {
getAllDimensionsForSchematicBox,
type SchematicBoxDimensions,
} from "lib/utils/schematic/getAllDimensionsForSchematicBox"
import { underscorifyPortArrangement } from "lib/soup/underscorifyPortArrangement"
import { underscorifyPinStyles } from "lib/soup/underscorifyPinStyles"

export class Jumper<PinLabels extends string = never> extends NormalComponent<
typeof jumperProps,
PinLabels
> {
schematicDimensions: SchematicBoxDimensions | null = null

get config() {
return {
zodProps: jumperProps,
}
}

initPorts() {
super.initPorts()

const { _parsedProps: props } = this

if (props.pinLabels) {
for (let [pinNumber, label] of Object.entries(props.pinLabels)) {
pinNumber = pinNumber.replace("pin", "")
const port = this.selectOne(`port[pinNumber='${pinNumber}']`)
if (!port) {
throw new Error(
`Could not find port for pin number ${pinNumber} in chip ${this.getString()}`,
)
}
port.props.aliases.push(port.props.name)
port.props.name = label
}
}
}

doInitialSourceRender(): void {
const { db } = this.project!
const { _parsedProps: props } = this

const source_component = db.source_component.insert({
ftype: "simple_chip", // TODO unknown or jumper
name: props.name,
manufacturer_part_number: props.manufacturerPartNumber,
supplier_part_numbers: props.supplierPartNumbers,
})

this.source_component_id = source_component.source_component_id!
}

doInitialSchematicComponentRender() {
const { db } = this.project!
const { _parsedProps: props } = this

const ports = this.children.filter((child) => child instanceof Port)

const pinSpacing = props.schPinSpacing ?? 0.2

const dimensions = getAllDimensionsForSchematicBox({
schWidth: props.schWidth,
schHeight: props.schHeight,
schPinSpacing: pinSpacing,
schPinStyle: props.schPinStyle,

pinCount: ports.length,

// @ts-ignore there's a subtley in the definition difference with
// leftSide/rightSide/topSide/bottomSide in how the direction is defined
// that doesn't really matter
schPortArrangement: {
// TODO use schematic direction or schPortArrangement
rightSize: ports.length,
},
})
this.schematicDimensions = dimensions

const schematic_component = db.schematic_component.insert({
center: { x: props.schX ?? 0, y: props.schY ?? 0 },
rotation: props.schRotation ?? 0,
size: dimensions.getSize(),

port_arrangement: underscorifyPortArrangement(
props.schPortArrangement as any,
),

pin_spacing: pinSpacing,

// @ts-ignore soup needs to support distance for pin_styles
pin_styles: underscorifyPinStyles(props.schPinStyle),

port_labels: props.pinLabels,

source_component_id: this.source_component_id!,
})

this.schematic_component_id = schematic_component.schematic_component_id
}

doInitialPcbComponentRender() {
const { db } = this.project!
const { _parsedProps: props } = this

const pcb_component = db.pcb_component.insert({
center: { x: props.pcbX ?? 0, y: props.pcbY ?? 0 },
width: 2, // Default width, adjust as needed
height: 3, // Default height, adjust as needed
layer: props.layer ?? "top",
rotation: props.pcbRotation ?? 0,
source_component_id: this.source_component_id!,
})

this.pcb_component_id = pcb_component.pcb_component_id
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/bun": "latest",
"@types/react": "^18.3.3",
"@types/react-reconciler": "^0.28.8",
"bun-match-svg": "^0.0.1",
"circuit-to-svg": "^0.0.3",
"howfat": "^0.3.8",
"looks-same": "^9.0.1",
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/example1.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/examples/example1.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ test("example1", () => {
view: "pcb",
layer: "top",
}),
).toMatchSnapshot()
).toMatchSvgSnapshot(import.meta.dir, "example1")
})
1 change: 1 addition & 0 deletions tests/fixtures/preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "bun-match-svg"

0 comments on commit 50e928e

Please sign in to comment.