Skip to content

Commit

Permalink
fix: Schematic capacitor & resistor symbol fix
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishabh18 committed Sep 24, 2024
1 parent 7e64120 commit 0d4a39a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 36 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/components/base-components/NormalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class NormalComponent<
const { schematicSymbolName } = this.config
if (!schematicSymbolName) return
// TODO switch between horizontal and vertical based on schRotation
const symbol_name = `${this.config.schematicSymbolName}_horz`
const symbol_name = `${this.config.schematicSymbolName}`

const symbol = (symbols as any)[symbol_name] as SchSymbol | undefined

Expand Down
35 changes: 17 additions & 18 deletions lib/components/normal-components/Capacitor.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import { capacitorProps, ledProps } from "@tscircuit/props"
import { FTYPE, SYMBOL } from "lib/utils/constants"
import { capacitorProps } from "@tscircuit/props"
import type { SourceSimpleCapacitorInput } from "@tscircuit/soup"
import {
FTYPE,
type BaseSymbolName,
type PassivePorts,
} from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import type { capacitance, SourceSimpleCapacitorInput } from "@tscircuit/soup"
import { Port } from "../primitive-components/Port"
import { Trace } from "../primitive-components/Trace"

type PortNames =
| "1"
| "2"
| "pin1"
| "pin2"
| "left"
| "right"
| "anode"
| "cathode"

export class Capacitor extends NormalComponent<
typeof capacitorProps,
PortNames
PassivePorts
> {
// @ts-ignore (cause the symbolName is string and not fixed)
get config() {
return {
// schematicSymbolName: BASE_SYMBOLS.capacitor,
zodProps: ledProps,
schematicSymbolName:
this.props.symbolName ?? ("capacitor_horz" as BaseSymbolName),
zodProps: capacitorProps,
sourceFtype: FTYPE.simple_capacitor,
}
}

pin1 = this.portMap.pin1
pin2 = this.portMap.pin2
initPorts() {
this.add(new Port({ name: "pin1", aliases: ["anode", "pos"] }))
this.add(new Port({ name: "pin2", aliases: ["cathode", "neg"] }))
}

doInitialCreateNetsFromProps() {
this._createNetsFromProps([
Expand Down
18 changes: 11 additions & 7 deletions lib/components/normal-components/Resistor.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { resistorProps } from "@tscircuit/props"
import type { PassivePorts, Ftype, BaseSymbolName } from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import type { SourceSimpleResistorInput } from "@tscircuit/soup"
import { z } from "zod"
import type { BaseSymbolName, Ftype, PassivePorts } from "lib/utils/constants"
import { NormalComponent } from "../base-components/NormalComponent"
import { Port } from "../primitive-components/Port"
import { Trace } from "../primitive-components/Trace"
import { Net } from "../primitive-components/Net"

export class Resistor extends NormalComponent<
typeof resistorProps,
PassivePorts
> {
// @ts-ignore (cause the symbolName is string and not fixed)
get config() {
return {
schematicSymbolName: "boxresistor" as BaseSymbolName,
schematicSymbolName:
this.props.symbolName ?? ("boxresistor_horz" as BaseSymbolName),
zodProps: resistorProps,
sourceFtype: "simple_resistor" as Ftype,
}
}

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

initPorts() {
this.add(new Port({ name: "pin1", aliases: ["anode", "pos"] }))
this.add(new Port({ name: "pin2", aliases: ["cathode", "neg"] }))
}

doInitialCreateNetsFromProps() {
this._createNetsFromProps([this.props.pullupFor, this.props.pullupTo])
Expand Down
17 changes: 8 additions & 9 deletions lib/components/primitive-components/Port.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { PCBSMTPad } from "@tscircuit/soup"
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import { z } from "zod"
import { getRelativeDirection } from "lib/utils/get-relative-direction"
import { symbols, type SchSymbol } from "schematic-symbols"
import type { SchematicBoxDimensions } from "lib/utils/schematic/getAllDimensionsForSchematicBox"
import { type SchSymbol } from "schematic-symbols"
import { applyToPoint, compose, translate } from "transformation-matrix"
import { z } from "zod"
import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
import type { Trace } from "./Trace"
import type { SchematicBoxDimensions } from "lib/utils/schematic/getAllDimensionsForSchematicBox"

export const portProps = z.object({
name: z.string().optional(),
Expand Down Expand Up @@ -69,13 +68,13 @@ export class Port extends PrimitiveComponent<typeof portProps> {
x: 0,
y: 0,
})
throw new Error(
`Could not find schematic symbol port for port ${this} so couldn't determine port position`,
)
}

const symbol = this.parent?.getSchematicSymbol()
if (!symbol) throw new Error(`Could not find parent symbol for ${this}`)
if (!symbol) {
console.warn(`Could not find parent symbol for ${this}`)
return { x: 0, y: 0 }
}

const transform = compose(
this.parent!.computeSchematicGlobalTransform(),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"performance-now": "^2.1.0",
"react": "^18.3.1",
"react-reconciler": "^0.29.2",
"schematic-symbols": "0.0.17",
"schematic-symbols": "0.0.19",
"transformation-matrix": "^2.16.1",
"zod": "^3.23.8"
}
Expand Down

0 comments on commit 0d4a39a

Please sign in to comment.