Repository navigation
Expand file tree
/
Copy pathResistor.ts
More file actions
111 lines (102 loc) · 3.26 KB
/
Copy pathResistor.ts
File metadata and controls
111 lines (102 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { resistorProps, resolveManufacturerPartNumber } from "@tscircuit/props"
import type { SourceSimpleResistorInput } from "circuit-json"
import { formatSiUnit } from "format-si-unit"
import type { Ftype, PassivePorts } from "lib/utils/constants"
import { symbols } from "schematic-symbols"
import { NormalComponent } from "../base-components/NormalComponent/NormalComponent"
import { Port } from "../primitive-components/Port"
import { Trace } from "../primitive-components/Trace/Trace"
export class Resistor extends NormalComponent<
typeof resistorProps,
PassivePorts
> {
_adjustSilkscreenTextAutomatically = true
get config() {
const baseSymbolName = this.props.symbolName ?? "boxresistor"
const compactSize =
this.props.schSize === "sm" || this.props.schSize === "xs"
? this.props.schSize
: undefined
const compactSymbolName =
compactSize &&
(baseSymbolName === "boxresistor" || baseSymbolName === "resistor")
? `${baseSymbolName}_${compactSize}`
: undefined
const schematicSymbolName =
compactSymbolName && `${compactSymbolName}_right` in symbols
? compactSymbolName
: baseSymbolName
return {
componentName: "Resistor",
schematicSymbolName,
zodProps: resistorProps,
sourceFtype: "simple_resistor" as Ftype,
}
}
initPorts() {
super.initPorts({
additionalAliases: {
pin1: ["anode", "pos", "left"],
pin2: ["cathode", "neg", "right"],
},
})
}
_getSchematicSymbolDisplayValue(): string | undefined {
return `${formatSiUnit(this._parsedProps.resistance)}Ω`
}
doInitialCreateNetsFromProps() {
this._createNetsFromProps([
this.props.pullupFor,
this.props.pullupTo,
this.props.pulldownFor,
this.props.pulldownTo,
...this._getNetsFromConnectionsProp(),
])
}
doInitialCreateTracesFromProps() {
if (this.props.pullupFor && this.props.pullupTo) {
this.add(
new Trace({
from: `${this.getSubcircuitSelector()} > port.1`,
to: this.props.pullupFor,
}),
)
this.add(
new Trace({
from: `${this.getSubcircuitSelector()} > port.2`,
to: this.props.pullupTo,
}),
)
}
if (this.props.pulldownFor && this.props.pulldownTo) {
this.add(
new Trace({
from: `${this.getSubcircuitSelector()} > port.1`,
to: this.props.pulldownFor,
}),
)
this.add(
new Trace({
from: `${this.getSubcircuitSelector()} > port.2`,
to: this.props.pulldownTo,
}),
)
}
this._createTracesFromConnectionsProp()
}
doInitialSourceRender() {
const { db } = this.root!
const { _parsedProps: props } = this
const source_component = db.source_component.insert({
ftype: "simple_resistor",
name: this.name,
manufacturer_part_number: resolveManufacturerPartNumber(props),
supplier_part_numbers: props.supplierPartNumbers,
resistance: props.resistance,
display_resistance: this._getSchematicSymbolDisplayValue(),
are_pins_interchangeable: true,
display_name: props.displayName,
} as SourceSimpleResistorInput)
this.source_component_id = source_component.source_component_id
}
}