Skip to content

Commit

Permalink
support for decouplingTo and decouplingFor props
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Sep 2, 2024
1 parent 51f627e commit d09fda6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
45 changes: 42 additions & 3 deletions lib/components/normal-components/Capacitor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ledProps } from "@tscircuit/props"
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import { capacitorProps, ledProps } from "@tscircuit/props"
import { FTYPE, SYMBOL } from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import type { capacitance, SourceSimpleCapacitorInput } from "@tscircuit/soup"
import { Trace } from "../primitive-components/Trace"

type PortNames =
| "1"
Expand All @@ -13,12 +14,50 @@ type PortNames =
| "anode"
| "cathode"

export class Capacitor extends NormalComponent<typeof ledProps, PortNames> {
export class Capacitor extends NormalComponent<
typeof capacitorProps,
PortNames
> {
get config() {
return {
// schematicSymbolName: BASE_SYMBOLS.capacitor,
zodProps: ledProps,
sourceFtype: FTYPE.simple_capacitor,
}
}

pin1 = this.portMap.pin1
pin2 = this.portMap.pin2

doInitialCreateTracesFromProps() {
if (this.props.decouplingFor && this.props.decouplingTo) {
this.add(
new Trace({
from: `${this.getOpaqueGroupSelector()} > port.1`,
to: this.props.decouplingFor,
}),
)
this.add(
new Trace({
from: `${this.getOpaqueGroupSelector()} > port.2`,
to: this.props.decouplingTo,
}),
)
}
}

doInitialSourceRender() {
const { db } = this.project!
const { _parsedProps: props } = this
const source_component = db.source_component.insert({
ftype: "simple_capacitor",
name: props.name,
// @ts-ignore
manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
supplier_part_numbers: props.supplierPartNumbers,

capacitance: props.capacitance,
} as SourceSimpleCapacitorInput)
this.source_component_id = source_component.source_component_id
}
}
3 changes: 3 additions & 0 deletions lib/components/primitive-components/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export class Trace extends PrimitiveComponent<typeof traceProps> {

if (!inputPcbTrace) {
// TODO render error indicating we could not find a route
console.log(
`Failed to find route ffrom ${ports[0].port} to ${ports[1].port} render error!`,
)
return
}
const pcb_trace = db.pcb_trace.insert(inputPcbTrace as any)
Expand Down
2 changes: 1 addition & 1 deletion 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.
7 changes: 4 additions & 3 deletions tests/examples/example1.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getTestFixture } from "tests/fixtures/get-test-fixture"
test("example1", async () => {
const { circuit, logSoup } = getTestFixture()
circuit.add(
<board width="10mm" height="10mm">
<board width="12mm" height="10mm">
<chip
name="U1"
footprint="soic8"
Expand All @@ -28,10 +28,11 @@ test("example1", async () => {
capacitance="10uF"
footprint="0603"
decouplingFor=".U1 port.PWR"
decouplingTo="net.GND"
// decouplingTo="net.GND"
decouplingTo=".J1 pin.4"
pcbX={4}
pcbY={0}
pcbRotation={90}
pcbRotation={-90}
/>
<jumper pcbX={0} pcbY={-4} name="J1" footprint="pinrow4" />

Expand Down

0 comments on commit d09fda6

Please sign in to comment.