Skip to content

Commit 6f23636

Browse files
authored
refactor: resolve component-specific Footprinter definitions in core (#4959)
* chore: update footprinter to 0.0.445 * Apply suggestion from @imrishabh18 * chore: consume footprinter 0.0.447 * fix: avoid duplicate LED polarity artwork * fix: use explicit polarity metadata instead of guessing from fabrication labels * refactor: generate automatic polarity fabrication notes only in core * test: verify indirect footprint consumers under core-owned polarity notes * refactor: resolve component-specific Footprinter definitions in core * fix: normalize footprints in typed components without config recursion * test: expect the resolved neutral connector CAD definition * fix: use Footprinter 0.0.449 and verify emitted polarity artwork * test: refresh neutral package fabrication snapshots * refactor: keep footprint policy in owning component classes * refactor: keep diode footprint helper specific to string definitions * refactor: type Footprinter inputs and terminal mappings * Use Footprinter 0.0.450 to resolve default passive families * Share diode and LED port initialization * fix: address footprint resolution review feedback * test: align chip footprint expectations with review fixes
1 parent d3d3451 commit 6f23636

75 files changed

Lines changed: 732 additions & 653 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎lib/components/base-components/NormalComponent/NormalComponent.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { resolveFootprinterPolarity } from "./utils/resolve-footprinter-polarity"
21
import { NormalComponent_doInitialSourcePinSpecificationChecks } from "./NormalComponent_doInitialSourcePinSpecificationChecks"
32
import {
43
getNumericPinLabels,
@@ -683,8 +682,9 @@ export class NormalComponent<
683682

684683
// Override to choose the effective footprint without rewriting user props.
685684
resolveFootprint() {
685+
// Footprint-driven config can discover ports before props have been parsed.
686686
return (
687-
this._parsedProps.footprint ??
687+
this._parsedProps?.footprint ??
688688
this.props.footprint ??
689689
this._getImpliedFootprintString?.()
690690
)
@@ -703,16 +703,7 @@ export class NormalComponent<
703703
if (parseLibraryFootprintRef(footprint)) return
704704
let fpCircuitJson: AnyCircuitElement[]
705705
try {
706-
const resolved = resolveFootprinterPolarity({
707-
footprint,
708-
componentName: this.componentName,
709-
name: this.name ?? this.componentName,
710-
pinLabels: this._resolvePinLabels(),
711-
polarized: this._parsedProps.polarized,
712-
})
713-
fpCircuitJson = fp
714-
.string(resolved.footprint)
715-
.soup() as AnyCircuitElement[]
706+
fpCircuitJson = fp.string(footprint).soup() as AnyCircuitElement[]
716707
} catch (error) {
717708
this._queueInvalidFootprintPropMessage(footprint, error)
718709
return
@@ -1657,7 +1648,7 @@ export class NormalComponent<
16571648
inferredInternallyConnectedPinNames,
16581649
implicitPinNumberByHint,
16591650
}
1660-
let { footprint } = this.props
1651+
let footprint = this.resolveFootprint()
16611652
if (
16621653
typeof footprint === "string" &&
16631654
parseLibraryFootprintRef(footprint) &&

‎lib/components/base-components/NormalComponent/utils/resolve-footprinter-polarity.ts‎

Lines changed: 0 additions & 125 deletions
This file was deleted.

‎lib/components/normal-components/Capacitor.ts‎

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resolvePassiveFootprintDefinition } from "@tscircuit/footprinter"
12
import { capacitorProps, resolveManufacturerPartNumber } from "@tscircuit/props"
23
import type { SourceSimpleCapacitorInput } from "circuit-json"
34
import { formatSiUnit } from "format-si-unit"
@@ -8,29 +9,67 @@ import {
89
} from "lib/utils/constants"
910
import { symbols } from "schematic-symbols"
1011
import { NormalComponent } from "../base-components/NormalComponent/NormalComponent"
11-
import { isFootprinterString } from "../base-components/NormalComponent/utils/isFootprinterString"
12-
import { resolveFootprinterPolarity } from "../base-components/NormalComponent/utils/resolve-footprinter-polarity"
12+
import { parseFootprinterDefinition } from "lib/utils/footprints/parse-footprinter-definition"
13+
import { resolveTwoTerminalPinMapping } from "lib/utils/footprints/resolve-two-terminal-pin-mapping"
1314
import { Trace } from "../primitive-components/Trace/Trace"
14-
import { Capacitor_addPolarityFabricationSymbols } from "./Capacitor_addPolarityFabricationSymbols"
1515
import { Capacitor_getAutomaticMaxDecouplingTraceLength } from "./Capacitor_getAutomaticMaxDecouplingTraceLength"
1616

17-
const CAPACITOR_CHIP_FOOTPRINTS = new Set([
18-
"01005",
19-
"0201",
20-
"0402",
21-
"0603",
22-
"0805",
23-
"1206",
24-
"1210",
25-
"2010",
26-
"2512",
27-
])
28-
2917
export class Capacitor extends NormalComponent<
3018
typeof capacitorProps,
3119
PolarizedPassivePorts
3220
> {
3321
_adjustSilkscreenTextAutomatically = true
22+
resolveFootprint() {
23+
const footprint = super.resolveFootprint()
24+
return typeof footprint === "string"
25+
? this.getFootprinterString()
26+
: footprint
27+
}
28+
29+
getFootprinterString(): string | null {
30+
// Read the authored definition directly: the base CAD getter calls resolveFootprint.
31+
const footprint = super.resolveFootprint()
32+
if (typeof footprint !== "string") return null
33+
const parsed = parseFootprinterDefinition(footprint)
34+
if (!parsed) return footprint
35+
const { definition, parameters } = parsed
36+
const terminals = resolveTwoTerminalPinMapping({
37+
name: this.name ?? "Capacitor",
38+
pinLabels: this._resolvePinLabels(),
39+
explicitPositive: parameters.positivepin,
40+
explicitNegative: parameters.negativepin,
41+
positiveOption: "positivepin",
42+
negativeOption: "negativepin",
43+
})
44+
const polarized = this._parsedProps.polarized
45+
if (
46+
polarized &&
47+
(parameters.nonpolarized ||
48+
parameters.polarized === false ||
49+
parameters.polarized === "false")
50+
) {
51+
throw new Error(
52+
`${this.name} is polarized but its footprint explicitly disables polarity.`,
53+
)
54+
}
55+
let resolved = resolvePassiveFootprintDefinition(definition, {
56+
defaultFamily: "cap",
57+
})
58+
if (
59+
parameters.polarized === undefined &&
60+
parameters.nonpolarized === undefined
61+
) {
62+
resolved += polarized ? "_polarized" : "_nonpolarized"
63+
}
64+
if (terminals.hasPolarityLabels) {
65+
if (parameters.positivepin === undefined)
66+
resolved += `_positivepin${terminals.positivePin}`
67+
if (parameters.negativepin === undefined)
68+
resolved += `_negativepin${terminals.negativePin}`
69+
}
70+
return resolved
71+
}
72+
3473
get config() {
3574
const baseSymbolName = this.props.symbolName ?? "capacitor"
3675
const compactSize =
@@ -59,14 +98,15 @@ export class Capacitor extends NormalComponent<
5998
initPorts() {
6099
// Keep electrical polarity aliases aligned with footprint terminal options.
61100
if (typeof this.props.footprint === "string") {
62-
const { positivePin, negativePin } = isFootprinterString(
63-
this.props.footprint,
64-
)
65-
? resolveFootprinterPolarity({
66-
footprint: this.props.footprint,
67-
componentName: this.componentName,
101+
const parsed = parseFootprinterDefinition(this.props.footprint)
102+
const { positivePin, negativePin } = parsed
103+
? resolveTwoTerminalPinMapping({
68104
name: this.name,
69-
polarized: this._parsedProps.polarized,
105+
pinLabels: this._resolvePinLabels(),
106+
explicitPositive: parsed.parameters.positivepin,
107+
explicitNegative: parsed.parameters.negativepin,
108+
positiveOption: "positivepin",
109+
negativeOption: "negativepin",
70110
})
71111
: { positivePin: 1, negativePin: 2 }
72112
super.initPorts({
@@ -112,14 +152,6 @@ export class Capacitor extends NormalComponent<
112152
return capacitanceDisplay
113153
}
114154

115-
getFootprinterString(): string | null {
116-
const baseFootprint = super.getFootprinterString()
117-
if (baseFootprint && CAPACITOR_CHIP_FOOTPRINTS.has(baseFootprint)) {
118-
return `cap${baseFootprint}`
119-
}
120-
return baseFootprint
121-
}
122-
123155
doInitialCreateNetsFromProps() {
124156
this._createNetsFromProps([
125157
this.props.decouplingFor,
@@ -146,11 +178,6 @@ export class Capacitor extends NormalComponent<
146178
this._createTracesFromConnectionsProp()
147179
}
148180

149-
doInitialPcbComponentSizeCalculation(): void {
150-
super.doInitialPcbComponentSizeCalculation()
151-
Capacitor_addPolarityFabricationSymbols(this)
152-
}
153-
154181
doInitialSourceRender() {
155182
const { db } = this.root!
156183
const { _parsedProps: props } = this

‎lib/components/normal-components/Capacitor_addPolarityFabricationSymbols.ts‎

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)