Skip to content

Commit

Permalink
add keyswitch implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 6, 2024
1 parent ed8676f commit 3c0b27e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export abstract class PrimitiveComponent<
) as z.infer<ZodProps>
if (!this.componentName) {
this.componentName = this.constructor.name
this.lowercaseComponentName = this.componentName.toLowerCase()
}
this.lowercaseComponentName = this.componentName.toLowerCase()
}

setProps(props: Partial<z.input<ZodProps>>) {
Expand Down
2 changes: 2 additions & 0 deletions lib/components/primitive-components/Constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const edgeSpecifiers = [
export type EdgeSpecifier = (typeof edgeSpecifiers)[number]

export class Constraint extends PrimitiveComponent<typeof constraintProps> {
componentName = "Constraint"

get config() {
return {
zodProps: constraintProps,
Expand Down
11 changes: 11 additions & 0 deletions tests/examples/__snapshots__/example2-switchshaft-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.
63 changes: 63 additions & 0 deletions tests/examples/example2-switchshaft.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

const SwitchShaft = (props: {
name: string
pcbX?: number
pcbY?: number
}) => (
<chip
{...props}
footprint={
<footprint>
<smtpad
shape="rect"
width="2.55mm"
height="2.5mm"
portHints={["pin1"]}
/>
<smtpad
shape="rect"
width="2.55mm"
height="2.5mm"
portHints={["pin2"]}
/>
<platedhole
shape="circle"
name="H1"
holeDiameter="3mm"
outerDiameter="3.1mm"
/>
<platedhole
shape="circle"
name="H2"
holeDiameter="3mm"
outerDiameter="3.1mm"
/>
<constraint xDist="6.35mm" centerToCenter left=".H1" right=".H2" />
<constraint yDist="2.54mm" centerToCenter top=".H1" bottom=".H2" />
<constraint edgeToEdge xDist="11.3mm" left=".pin1" right=".pin2" />
<constraint sameY for={[".pin1", ".H1"]} />
<constraint sameY for={[".pin2", ".H2"]} />
<constraint
edgeToEdge
xDist={(11.3 - 6.35 - 3) / 2}
left=".pin1"
right=".H1"
/>
</footprint>
}
/>
)

test("example2-switchshaft", async () => {
const { circuit } = getTestFixture()

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

expect(circuit.getCircuitJson()).toMatchPcbSnapshot(import.meta.path)
})

0 comments on commit 3c0b27e

Please sign in to comment.