Skip to content

Commit dde8ce1

Browse files
committed
update
1 parent 191a067 commit dde8ce1

4 files changed

Lines changed: 43 additions & 41 deletions

File tree

lib/stages/pcb/CollectFootprintsStage/layer-utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function determineLayerFromLayers(layers: any): LayerRef {
3030
}
3131

3232
export interface LayerMapping {
33-
side: "top" | "bottom"
34-
type: PcbRenderLayer | "unknown"
33+
selectedLayer: "top" | "bottom"
34+
layers: PcbRenderLayer[]
3535
}
3636

3737
/**
@@ -43,15 +43,17 @@ export function getLayerMapping(kicadLayer: any): LayerMapping {
4343
? kicadLayer
4444
: kicadLayer?.names?.join(" ") || ""
4545

46-
const side: "top" | "bottom" =
46+
const selectedLayer: "top" | "bottom" =
4747
layerStr.includes("B.") || layerStr.includes("Back") ? "bottom" : "top"
4848

49-
let type: PcbRenderLayer | "unknown" = "unknown"
49+
const layers: PcbRenderLayer[] = []
5050
if (layerStr.includes("Silk")) {
51-
type = side === "top" ? "top_silkscreen" : "bottom_silkscreen"
51+
layers.push(
52+
selectedLayer === "top" ? "top_silkscreen" : "bottom_silkscreen",
53+
)
5254
} else if (layerStr.includes("Edge.Cuts")) {
53-
type = "edge_cuts"
55+
layers.push("edge_cuts")
5456
}
5557

56-
return { side, type }
58+
return { selectedLayer, layers }
5759
}

lib/stages/pcb/CollectFootprintsStage/process-graphics.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ export function createFootprintLine(
120120
const startPos = applyToPoint(ctx.k2cMatPcb, startKicadPos)
121121
const endPos = applyToPoint(ctx.k2cMatPcb, endKicadPos)
122122

123-
const mapping = getLayerMapping(line.layer)
123+
const layerMapping = getLayerMapping(line.layer)
124124
const strokeWidth = line.stroke?.width || line.width || 0.12
125125

126-
if (mapping.type.includes("silkscreen")) {
126+
if (layerMapping.layers[0]?.includes("silkscreen")) {
127127
ctx.db.pcb_silkscreen_path.insert({
128128
pcb_component_id: componentId,
129-
layer: mapping.side,
129+
layer: layerMapping.selectedLayer,
130130
route: [startPos, endPos],
131131
stroke_width: strokeWidth,
132132
})
@@ -163,7 +163,7 @@ export function createFootprintCircle(
163163
// Transform to Circuit JSON coordinates
164164
const centerPos = applyToPoint(ctx.k2cMatPcb, centerKicadPos)
165165

166-
const mapping = getLayerMapping(circle.layer)
166+
const layerMapping = getLayerMapping(circle.layer)
167167
const strokeWidth = circle.stroke?.width || circle.width || 0.12
168168

169169
// Create circle as a pcb_silkscreen_circle (if supported) or as a path with many points
@@ -177,10 +177,10 @@ export function createFootprintCircle(
177177
circleRoute.push({ x, y })
178178
}
179179

180-
if (mapping.type.includes("silkscreen")) {
180+
if (layerMapping.layers[0]?.includes("silkscreen")) {
181181
ctx.db.pcb_silkscreen_path.insert({
182182
pcb_component_id: componentId,
183-
layer: mapping.side,
183+
layer: layerMapping.selectedLayer,
184184
route: circleRoute,
185185
stroke_width: strokeWidth,
186186
})
@@ -253,7 +253,7 @@ export function createFootprintArc(
253253
y: kicadComponentPos.y + rotatedEnd.y,
254254
}
255255

256-
const mapping = getLayerMapping(arc.layer)
256+
const layerMapping = getLayerMapping(arc.layer)
257257
const strokeWidth = arc.stroke?.width || arc.width || 0.12
258258

259259
// Calculate the arc center and radius IN KICAD SPACE (before coordinate transformation)
@@ -264,10 +264,10 @@ export function createFootprintArc(
264264
const startPos = applyToPoint(ctx.k2cMatPcb, startKicadPos)
265265
const endPos = applyToPoint(ctx.k2cMatPcb, endKicadPos)
266266

267-
if (mapping.type.includes("silkscreen")) {
267+
if (layerMapping.layers[0]?.includes("silkscreen")) {
268268
ctx.db.pcb_silkscreen_path.insert({
269269
pcb_component_id: componentId,
270-
layer: mapping.side,
270+
layer: layerMapping.selectedLayer,
271271
route: [startPos, endPos],
272272
stroke_width: strokeWidth,
273273
})
@@ -336,10 +336,10 @@ export function createFootprintArc(
336336
arcRoute.push(cjPoint)
337337
}
338338

339-
if (mapping.type.includes("silkscreen")) {
339+
if (layerMapping.layers[0]?.includes("silkscreen")) {
340340
ctx.db.pcb_silkscreen_path.insert({
341341
pcb_component_id: componentId,
342-
layer: mapping.side,
342+
layer: layerMapping.selectedLayer,
343343
route: arcRoute,
344344
stroke_width: strokeWidth,
345345
})
@@ -360,7 +360,7 @@ export function createFootprintPoly(
360360
if (ptArray.length === 0) return
361361

362362
// Extract layer
363-
const mapping = getLayerMapping(poly.layer)
363+
const layerMapping = getLayerMapping(poly.layer)
364364

365365
// Extract stroke width
366366
const strokeWidth = poly.stroke?.width || poly.width || 0.12
@@ -378,10 +378,10 @@ export function createFootprintPoly(
378378
return applyToPoint(ctx.k2cMatPcb!, kicadPos)
379379
})
380380

381-
if (mapping.type.includes("silkscreen")) {
381+
if (layerMapping.layers[0]?.includes("silkscreen")) {
382382
ctx.db.pcb_silkscreen_path.insert({
383383
pcb_component_id: componentId,
384-
layer: mapping.side,
384+
layer: layerMapping.selectedLayer,
385385
route: transformedPts,
386386
stroke_width: strokeWidth,
387387
})

lib/stages/pcb/CollectFootprintsStage/process-text.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export function processFootprintText(
3131

3232
for (const text of textArray) {
3333
// Check if the layer is one we want to process
34-
const mapping = getLayerMapping(text.layer)
35-
if (!mapping.type.includes("silkscreen")) continue
34+
const layerMapping = getLayerMapping(text.layer)
35+
if (!layerMapping.layers[0]?.includes("silkscreen")) continue
3636

3737
// Create a properly structured text element with _sxPosition mapped to at
3838
const textElement = {
@@ -74,8 +74,8 @@ export function processFootprintProperties(
7474
if (!property.layer) continue
7575

7676
// Check if the property is on a supported layer
77-
const mapping = getLayerMapping(property.layer)
78-
if (!mapping.type.includes("silkscreen")) continue
77+
const layerMapping = getLayerMapping(property.layer)
78+
if (!layerMapping.layers[0]?.includes("silkscreen")) continue
7979

8080
// Create footprint text for this property
8181
// Property structure uses _sxAt for position (kicadts internal field)
@@ -129,7 +129,7 @@ export function createFootprintText(
129129
}
130130
const pos = applyToPoint(ctx.k2cMatPcb, textKicadPos)
131131

132-
const mapping = getLayerMapping(text.layer)
132+
const layerMapping = getLayerMapping(text.layer)
133133

134134
// Substitute KiCad variables in text
135135
const processedText = substituteKicadVariables(text.text || "", footprint)
@@ -140,14 +140,14 @@ export function createFootprintText(
140140
text.effects?.font?.size?.y ||
141141
1
142142

143-
if (mapping.type.includes("silkscreen")) {
143+
if (layerMapping.layers[0]?.includes("silkscreen")) {
144144
ctx.db.pcb_silkscreen_text.insert({
145145
pcb_component_id: componentId,
146146
font: "tscircuit2024",
147147
font_size: kicadFontSize * 1.5,
148148
text: processedText,
149149
anchor_position: pos,
150-
layer: mapping.side,
150+
layer: layerMapping.selectedLayer,
151151
anchor_alignment: "center",
152152
})
153153
}

lib/stages/pcb/CollectGraphicsStage.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export class CollectGraphicsStage extends ConverterStage {
2525
const otherLines: any[] = []
2626

2727
for (const line of lineArray) {
28-
const mapping = getLayerMapping(line.layer)
29-
if (mapping.type === "edge_cuts") {
28+
const layerMapping = getLayerMapping(line.layer)
29+
if (layerMapping.layers[0] === "edge_cuts") {
3030
edgeCutLines.push(line)
31-
} else if (mapping.type.includes("silkscreen")) {
31+
} else if (layerMapping.layers[0]?.includes("silkscreen")) {
3232
otherLines.push(line)
3333
}
3434
}
@@ -63,9 +63,9 @@ export class CollectGraphicsStage extends ConverterStage {
6363
const textArray = Array.isArray(texts) ? texts : [texts]
6464

6565
for (const text of textArray) {
66-
const mapping = getLayerMapping(text.layer)
66+
const layerMapping = getLayerMapping(text.layer)
6767
// Include text from silk, copper, and fab/courtyard layers
68-
if (mapping.type.includes("silkscreen")) {
68+
if (layerMapping.layers[0]?.includes("silkscreen")) {
6969
this.createGraphicText(text)
7070
}
7171
}
@@ -188,13 +188,13 @@ export class CollectGraphicsStage extends ConverterStage {
188188
})
189189
const endPos = applyToPoint(this.ctx.k2cMatPcb, { x: end.x, y: end.y })
190190

191-
const mapping = getLayerMapping(line.layer)
191+
const layerMapping = getLayerMapping(line.layer)
192192
const strokeWidth = line.width || 0.15
193193

194-
if (mapping.type.includes("silkscreen")) {
194+
if (layerMapping.layers[0]?.includes("silkscreen")) {
195195
this.ctx.db.pcb_silkscreen_path.insert({
196196
pcb_component_id: "", // Not attached to a specific component
197-
layer: mapping.side,
197+
layer: layerMapping.selectedLayer,
198198
route: [startPos, endPos],
199199
stroke_width: strokeWidth,
200200
})
@@ -241,7 +241,7 @@ export class CollectGraphicsStage extends ConverterStage {
241241
const centerCJ = applyToPoint(this.ctx.k2cMatPcb, centerKicad)
242242

243243
// Map layer to top/bottom
244-
const layer = getLayerMapping(rect._sxLayer).side
244+
const layer = getLayerMapping(rect._sxLayer).selectedLayer
245245

246246
// Create pcb_smtpad
247247
this.ctx.db.pcb_smtpad.insert({
@@ -271,20 +271,20 @@ export class CollectGraphicsStage extends ConverterStage {
271271
y: at?.y ?? 0,
272272
})
273273

274-
const mapping = getLayerMapping(text.layer)
274+
const layerMapping = getLayerMapping(text.layer)
275275
// Access font size from kicadts internal structure (_sxEffects._sxFont._sxSize._height)
276276
const kicadFontSize =
277277
text._sxEffects?._sxFont?._sxSize?._height ||
278278
text.effects?.font?.size?.y ||
279279
1
280280
const fontSize = kicadFontSize * 1.5
281281

282-
if (mapping.type.includes("silkscreen")) {
282+
if (layerMapping.layers[0]?.includes("silkscreen")) {
283283
this.ctx.db.pcb_silkscreen_text.insert({
284284
pcb_component_id: "",
285285
text: text.text || text._text || "",
286286
anchor_position: pos,
287-
layer: mapping.side,
287+
layer: layerMapping.selectedLayer,
288288
font_size: fontSize,
289289
font: "tscircuit2024",
290290
anchor_alignment: "center",
@@ -367,7 +367,7 @@ export class CollectGraphicsStage extends ConverterStage {
367367
)
368368

369369
// Map layer to top/bottom
370-
const layer = getLayerMapping(poly._sxLayer).side
370+
const layer = getLayerMapping(poly._sxLayer).selectedLayer
371371

372372
// Create pcb_smtpad with polygon shape
373373
this.ctx.db.pcb_smtpad.insert({

0 commit comments

Comments
 (0)