Skip to content

Commit

Permalink
Merge pull request #268 from ShiboSoftwareDev/main
Browse files Browse the repository at this point in the history
Added capacitor, inductor, diode and led schRotation support
  • Loading branch information
seveibar authored Nov 10, 2024
2 parents f640ded + d412cda commit d7b76da
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 96 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ export abstract class PrimitiveComponent<
const symbol_name_horz = `${base_symbol_name}_horz` as keyof typeof symbols
const symbol_name_vert = `${base_symbol_name}_vert` as keyof typeof symbols

if (base_symbol_name in symbols) return base_symbol_name
if (symbol_name_horz in symbols) {
if (props.schRotation === 0 || props.schRotation === undefined)
return symbol_name_horz
Expand All @@ -293,6 +292,7 @@ export abstract class PrimitiveComponent<
if (props.schRotation === 90) return symbol_name_vert
if (props.schRotation === 270) return symbol_name_vert
}
if (base_symbol_name in symbols) return base_symbol_name

return undefined
}
Expand Down
22 changes: 7 additions & 15 deletions lib/components/normal-components/Capacitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@ export class Capacitor extends NormalComponent<
return {
componentName: "Capacitor",
schematicSymbolName:
this.props.symbolName ?? ("capacitor_horz" as BaseSymbolName),
this.props.symbolName ?? ("capacitor" as BaseSymbolName),
zodProps: capacitorProps,
sourceFtype: FTYPE.simple_capacitor,
}
}

initPorts() {
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
super.initPorts({
additionalAliases: {
pin1: ["anode", "pos", "left"],
pin2: ["cathode", "neg", "right"],
},
})
}

_getSchematicSymbolDisplayValue(): string | undefined {
Expand Down
23 changes: 7 additions & 16 deletions lib/components/normal-components/Diode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ export class Diode extends NormalComponent<
// @ts-ignore
get config() {
return {
schematicSymbolName:
this.props.symbolName ?? ("diode_horz" as BaseSymbolName),
schematicSymbolName: this.props.symbolName ?? ("diode" as BaseSymbolName),
componentName: "Diode",
zodProps: diodeProps,
sourceFtype: "simple_diode" as Ftype,
}
}

initPorts() {
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
super.initPorts({
additionalAliases: {
pin1: ["anode", "pos", "left"],
pin2: ["cathode", "neg", "right"],
},
})
}

pos = this.portMap.pin1
Expand Down
20 changes: 6 additions & 14 deletions lib/components/normal-components/Inductor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ export class Inductor extends NormalComponent<
}

initPorts() {
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
super.initPorts({
additionalAliases: {
pin1: ["anode", "pos", "left"],
pin2: ["cathode", "neg", "right"],
},
})
}

doInitialSourceRender() {
Expand Down
23 changes: 7 additions & 16 deletions lib/components/normal-components/Led.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,19 @@ export class Led extends NormalComponent<
get config() {
return {
componentName: "Led",
schematicSymbolName:
this.props.symbolName ?? ("led_horz" as BaseSymbolName),
schematicSymbolName: this.props.symbolName ?? ("led" as BaseSymbolName),
zodProps: ledProps,
sourceFtype: "simple_diode" as Ftype,
}
}

initPorts() {
this.add(
new Port({
name: "pin1",
pinNumber: 1,
aliases: ["anode", "pos", "left"],
}),
)
this.add(
new Port({
name: "pin2",
pinNumber: 2,
aliases: ["cathode", "neg", "right"],
}),
)
super.initPorts({
additionalAliases: {
pin1: ["anode", "pos", "left"],
pin2: ["cathode", "neg", "right"],
},
})
}

pos = this.portMap.pin1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"performance-now": "^2.1.0",
"react": "^18.3.1",
"react-reconciler": "^0.29.2",
"schematic-symbols": "0.0.90",
"schematic-symbols": "^0.0.92",
"transformation-matrix": "^2.16.1",
"zod": "^3.23.8"
}
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.

This file was deleted.

48 changes: 48 additions & 0 deletions tests/components/normal-components/rotated-components.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect } from "bun:test"
import { getTestFixture } from "tests/fixtures/get-test-fixture"

test("rotated resistor/diode/inductor/led/capacitor schematic", () => {
const { circuit } = getTestFixture()

circuit.add(
<board width="10mm" height="10mm">
<resistor
name="R1"
schY={0}
schX={0}
resistance="10k"
schRotation="90deg"
/>
<led name="L1" schY={0} schX={2} schRotation="90deg" />
<inductor
name="I1"
schY={0}
schX={4}
inductance="10k"
schRotation="90deg"
/>
<capacitor
name="C1"
schY={0}
schX={6}
capacitance="10k"
schRotation="90deg"
/>
<diode name="D1" schY={0} schX={8} schRotation="90deg" />
</board>,
)

circuit.render()

const symbolNames = circuit.db.schematic_component
.list()
.map((elm) => elm.symbol_name)

expect(symbolNames.includes("capacitor_vert")).toBeTruthy()
expect(symbolNames.includes("inductor_vert")).toBeTruthy()
expect(symbolNames.includes("led_vert")).toBeTruthy()
expect(symbolNames.includes("boxresistor_vert")).toBeTruthy()
expect(symbolNames.includes("diode_vert")).toBeTruthy()

expect(circuit).toMatchSchematicSnapshot(import.meta.path)
})
20 changes: 0 additions & 20 deletions tests/components/normal-components/rotated-resistor.test.tsx

This file was deleted.

0 comments on commit d7b76da

Please sign in to comment.