Skip to content

Commit 3f9ef44

Browse files
upd
1 parent 239db37 commit 3f9ef44

File tree

2 files changed

+162
-127
lines changed

2 files changed

+162
-127
lines changed

lib/components/base-components/Renderable.ts

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const orderedRenderPhases = [
1616
"InflateSubcircuitCircuitJson",
1717
"SourceNameDuplicateComponentRemoval",
1818
"PcbFootprintStringRender",
19+
"StandardConnectorCircuitJsonRender",
1920
"InitializePortsFromChildren",
2021
"CreateNetsFromProps",
2122
"AssignFallbackProps",
@@ -77,27 +78,73 @@ export const renderPhaseIndexMap = new Map<RenderPhase, number>(
7778
// current component's subtree.
7879
const asyncPhaseDependencies: Partial<Record<RenderPhase, RenderPhase[]>> = {
7980
InflateSubcircuitCircuitJson: ["RenderIsolatedSubcircuits"],
80-
PcbFootprintLayout: ["PcbFootprintStringRender"],
81-
PcbComponentSizeCalculation: ["PcbFootprintStringRender"],
82-
PcbLayout: ["PcbFootprintStringRender"],
83-
PcbBoardAutoSize: ["PcbFootprintStringRender"],
84-
PcbTraceHintRender: ["PcbFootprintStringRender"],
85-
PcbManualTraceRender: ["PcbFootprintStringRender"],
81+
PcbFootprintLayout: [
82+
"PcbFootprintStringRender",
83+
"StandardConnectorCircuitJsonRender",
84+
],
85+
PcbComponentSizeCalculation: [
86+
"PcbFootprintStringRender",
87+
"StandardConnectorCircuitJsonRender",
88+
],
89+
PcbLayout: ["PcbFootprintStringRender", "StandardConnectorCircuitJsonRender"],
90+
PcbBoardAutoSize: [
91+
"PcbFootprintStringRender",
92+
"StandardConnectorCircuitJsonRender",
93+
],
94+
PcbTraceHintRender: [
95+
"PcbFootprintStringRender",
96+
"StandardConnectorCircuitJsonRender",
97+
],
98+
PcbManualTraceRender: [
99+
"PcbFootprintStringRender",
100+
"StandardConnectorCircuitJsonRender",
101+
],
86102
PcbCopperPourRender: [
87103
"PcbFootprintStringRender",
104+
"StandardConnectorCircuitJsonRender",
88105
"PcbTraceRender",
89106
"PcbRouteNetIslands",
90107
],
91-
PcbTraceRender: ["PcbFootprintStringRender"],
92-
PcbRouteNetIslands: ["PcbFootprintStringRender"],
93-
PcbDesignRuleChecks: ["PcbFootprintStringRender"],
94-
SilkscreenOverlapAdjustment: ["PcbFootprintStringRender"],
95-
CadModelRender: ["PcbFootprintStringRender"],
96-
PartsEngineRender: ["PcbFootprintStringRender"],
97-
PcbComponentAnchorAlignment: ["PcbFootprintStringRender"],
98-
PcbCalcPlacementResolution: ["PcbFootprintStringRender"],
99-
ValidatePcbCoordinates: ["PcbFootprintStringRender"],
100-
SourceTraceRender: ["PcbFootprintStringRender"],
108+
PcbTraceRender: [
109+
"PcbFootprintStringRender",
110+
"StandardConnectorCircuitJsonRender",
111+
],
112+
PcbRouteNetIslands: [
113+
"PcbFootprintStringRender",
114+
"StandardConnectorCircuitJsonRender",
115+
],
116+
PcbDesignRuleChecks: [
117+
"PcbFootprintStringRender",
118+
"StandardConnectorCircuitJsonRender",
119+
],
120+
SilkscreenOverlapAdjustment: [
121+
"PcbFootprintStringRender",
122+
"StandardConnectorCircuitJsonRender",
123+
],
124+
CadModelRender: [
125+
"PcbFootprintStringRender",
126+
"StandardConnectorCircuitJsonRender",
127+
],
128+
PartsEngineRender: [
129+
"PcbFootprintStringRender",
130+
"StandardConnectorCircuitJsonRender",
131+
],
132+
PcbComponentAnchorAlignment: [
133+
"PcbFootprintStringRender",
134+
"StandardConnectorCircuitJsonRender",
135+
],
136+
PcbCalcPlacementResolution: [
137+
"PcbFootprintStringRender",
138+
"StandardConnectorCircuitJsonRender",
139+
],
140+
ValidatePcbCoordinates: [
141+
"PcbFootprintStringRender",
142+
"StandardConnectorCircuitJsonRender",
143+
],
144+
SourceTraceRender: [
145+
"PcbFootprintStringRender",
146+
"StandardConnectorCircuitJsonRender",
147+
],
101148
}
102149

103150
export type RenderPhaseFn<K extends RenderPhase = RenderPhase> =

lib/components/normal-components/Connector.ts

Lines changed: 99 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -42,132 +42,120 @@ export class Connector<
4242
}
4343

4444
doInitialPcbFootprintStringRender(): void {
45+
super.doInitialPcbFootprintStringRender()
46+
}
47+
48+
doInitialStandardConnectorCircuitJsonRender(): void {
4549
const { _parsedProps: props } = this
4650
const connectorProps = this.props as ConnectorProps
4751
const standard = connectorProps.standard
4852

49-
if (standard) {
50-
if (this._hasStartedFootprintUrlLoad) return
51-
if (this.getInheritedProperty("partsEngineDisabled")) {
52-
super.doInitialPcbFootprintStringRender()
53-
return
54-
}
55-
const partsEngine = this.getInheritedProperty("partsEngine")
56-
if (!partsEngine?.fetchPartCircuitJson) {
57-
super.doInitialPcbFootprintStringRender()
58-
return
59-
}
60-
61-
this._hasStartedFootprintUrlLoad = true
62-
63-
// source_component_id is not yet set (SourceRender runs after PcbFootprintStringRender),
64-
// but after the first `await` in the async effect all synchronous render phases
65-
// including SourceRender will have run, making source_component_id available.
66-
const sourceComponentForQuery = {
67-
ftype: "simple_connector",
68-
name: this.name,
69-
manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
70-
standard,
71-
}
53+
if (!standard) return
54+
if (this._hasStartedFootprintUrlLoad) return
55+
if (this.getInheritedProperty("partsEngineDisabled")) return
56+
const partsEngine = this.getInheritedProperty("partsEngine")
57+
if (!partsEngine?.fetchPartCircuitJson) return
7258

73-
this._queueAsyncEffect(
74-
"load-standard-connector-circuit-json",
75-
async () => {
76-
const { db } = this.root!
77-
try {
78-
// Step 1: findPart → supplier part numbers
79-
const supplierPartNumbers = await this._getSupplierPartNumbers(
80-
partsEngine,
81-
sourceComponentForQuery,
82-
`standard:${standard}`,
83-
)
84-
85-
if (this.source_component_id) {
86-
db.source_component.update(this.source_component_id, {
87-
supplier_part_numbers: supplierPartNumbers,
88-
})
89-
}
59+
this._hasStartedFootprintUrlLoad = true
9060

91-
// Step 2: fetchPartCircuitJson with first available supplier part number
92-
let circuitJson: AnyCircuitElement[] | null = null
93-
for (const supplier of Object.keys(supplierPartNumbers ?? {})) {
94-
const nums = supplierPartNumbers[supplier]
95-
if (Array.isArray(nums) && nums.length > 0) {
96-
const maybeCircuitJson =
97-
(await Promise.resolve(
98-
partsEngine.fetchPartCircuitJson({
99-
supplierPartNumber: nums[0],
100-
}),
101-
)) ?? null
102-
if (
103-
Array.isArray(maybeCircuitJson) &&
104-
maybeCircuitJson.length > 0
105-
) {
106-
circuitJson = maybeCircuitJson
107-
break
108-
}
109-
}
110-
}
61+
// source_component_id is not yet set (SourceRender runs later), but after
62+
// the first await in this async effect synchronous phases complete and
63+
// source_component_id will be available for db updates.
64+
const sourceComponentForQuery = {
65+
ftype: "simple_connector",
66+
name: this.name,
67+
manufacturer_part_number: props.manufacturerPartNumber ?? props.mfn,
68+
standard,
69+
}
11170

112-
// Fallback: manufacturer part number
71+
this._queueAsyncEffect("load-standard-connector-circuit-json", async () => {
72+
const { db } = this.root!
73+
try {
74+
// Step 1: findPart → supplier part numbers
75+
const supplierPartNumbers = await this._getSupplierPartNumbers(
76+
partsEngine,
77+
sourceComponentForQuery,
78+
`standard:${standard}`,
79+
)
80+
81+
if (this.source_component_id) {
82+
db.source_component.update(this.source_component_id, {
83+
supplier_part_numbers: supplierPartNumbers,
84+
})
85+
}
86+
87+
// Step 2: fetchPartCircuitJson with first available supplier part number
88+
let circuitJson: AnyCircuitElement[] | null = null
89+
for (const supplier of Object.keys(supplierPartNumbers ?? {})) {
90+
const nums = supplierPartNumbers[supplier]
91+
if (Array.isArray(nums) && nums.length > 0) {
92+
const maybeCircuitJson =
93+
(await Promise.resolve(
94+
partsEngine.fetchPartCircuitJson({
95+
supplierPartNumber: nums[0],
96+
}),
97+
)) ?? null
11398
if (
114-
(!circuitJson || circuitJson.length === 0) &&
115-
sourceComponentForQuery.manufacturer_part_number
99+
Array.isArray(maybeCircuitJson) &&
100+
maybeCircuitJson.length > 0
116101
) {
117-
const maybeCircuitJson =
118-
(await Promise.resolve(
119-
partsEngine.fetchPartCircuitJson({
120-
manufacturerPartNumber:
121-
sourceComponentForQuery.manufacturer_part_number,
122-
}),
123-
)) ?? null
124-
if (
125-
Array.isArray(maybeCircuitJson) &&
126-
maybeCircuitJson.length > 0
127-
) {
128-
circuitJson = maybeCircuitJson
129-
}
130-
}
131-
132-
if (circuitJson && circuitJson.length > 0) {
133-
const fpComponents = createComponentsFromCircuitJson(
134-
{
135-
componentName: this.name,
136-
componentRotation: String(props.pcbRotation ?? 0),
137-
footprinterString: `standard:${standard}`,
138-
pinLabels: props.pinLabels,
139-
pcbPinLabels: props.pcbPinLabels,
140-
},
141-
circuitJson,
142-
)
143-
this.addAll(fpComponents)
144-
this._markDirty("InitializePortsFromChildren")
145-
}
146-
} catch (error: any) {
147-
if (this.source_component_id) {
148-
db.source_component.update(this.source_component_id, {
149-
supplier_part_numbers: {},
150-
})
102+
circuitJson = maybeCircuitJson
103+
break
151104
}
152-
const errorObj = unknown_error_finding_part.parse({
153-
type: "unknown_error_finding_part",
154-
message: `Failed to fetch circuit JSON for ${this.getString()} (standard="${standard}"): ${error.message}`,
155-
source_component_id: this.source_component_id ?? undefined,
156-
subcircuit_id: this.getSubcircuit()?.subcircuit_id,
157-
})
158-
db.unknown_error_finding_part.insert(errorObj)
159105
}
160-
},
161-
)
162-
return
163-
}
164-
165-
super.doInitialPcbFootprintStringRender()
106+
}
107+
108+
// Fallback: manufacturer part number
109+
if (
110+
(!circuitJson || circuitJson.length === 0) &&
111+
sourceComponentForQuery.manufacturer_part_number
112+
) {
113+
const maybeCircuitJson =
114+
(await Promise.resolve(
115+
partsEngine.fetchPartCircuitJson({
116+
manufacturerPartNumber:
117+
sourceComponentForQuery.manufacturer_part_number,
118+
}),
119+
)) ?? null
120+
if (Array.isArray(maybeCircuitJson) && maybeCircuitJson.length > 0) {
121+
circuitJson = maybeCircuitJson
122+
}
123+
}
124+
125+
if (circuitJson && circuitJson.length > 0) {
126+
const fpComponents = createComponentsFromCircuitJson(
127+
{
128+
componentName: this.name,
129+
componentRotation: String(props.pcbRotation ?? 0),
130+
footprinterString: `standard:${standard}`,
131+
pinLabels: props.pinLabels,
132+
pcbPinLabels: props.pcbPinLabels,
133+
},
134+
circuitJson,
135+
)
136+
this.addAll(fpComponents)
137+
this._markDirty("InitializePortsFromChildren")
138+
}
139+
} catch (error: any) {
140+
if (this.source_component_id) {
141+
db.source_component.update(this.source_component_id, {
142+
supplier_part_numbers: {},
143+
})
144+
}
145+
const errorObj = unknown_error_finding_part.parse({
146+
type: "unknown_error_finding_part",
147+
message: `Failed to fetch circuit JSON for ${this.getString()} (standard="${standard}"): ${error.message}`,
148+
source_component_id: this.source_component_id ?? undefined,
149+
subcircuit_id: this.getSubcircuit()?.subcircuit_id,
150+
})
151+
db.unknown_error_finding_part.insert(errorObj)
152+
}
153+
})
166154
}
167155

168156
doInitialPartsEngineRender(): void {
169157
// For standard connectors, supplier part numbers are already resolved
170-
// during PcbFootprintStringRender via findPart + fetchPartCircuitJson
158+
// during StandardConnectorCircuitJsonRender via findPart + fetchPartCircuitJson
171159
if (this._isUsingStandardPartsEngineCircuitJsonFlow()) return
172160
super.doInitialPartsEngineRender()
173161
}

0 commit comments

Comments
 (0)