Skip to content

Commit

Permalink
Merge pull request #25 from tscircuit/dsn-session-generation
Browse files Browse the repository at this point in the history
Session Json Fixes
  • Loading branch information
seveibar authored Nov 18, 2024
2 parents ee7a63b + abb2bbe commit 154ec83
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,6 @@ dist
#ignore the diff images
*.diff.png
*.diff.svg
dsn-session.json
dsn-session.json
.yalc
yalc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,27 @@ export function processComponentsAndPads(
const { pcb_component_id, pcb_smtpads } = group
if (pcb_smtpads.length === 0) continue

const sourceComponent = circuitElements.find(
const pcbComponent = circuitElements.find(
(e) =>
e.type === "pcb_component" && e.pcb_component_id === pcb_component_id,
) as PcbComponent
const srcComp =
sourceComponent &&
const sourceComponent =
pcbComponent &&
(circuitElements.find(
(e) =>
e.type === "source_component" &&
e.source_component_id === sourceComponent.source_component_id,
e.source_component_id === pcbComponent.source_component_id,
) as SourceComponentBase)

const footprintName = getFootprintName(srcComp?.ftype)
const componentName = srcComp?.name || "Unknown"
const footprintName = getFootprintName(sourceComponent?.ftype)
const componentName = sourceComponent?.name || "Unknown"

// Transform component coordinates
const circuitSpaceCoordinates = applyToPoint(
transformMmToUm,
sourceComponent.center,
pcbComponent.center,
)

// Fixed placement coordinates
// Get rotation from pcb_component
const pcbComponent = circuitElements.find(
(e) =>
e.type === "pcb_component" &&
e.pcb_component_id === sourceComponent.pcb_component_id,
) as PcbComponent

const componentPlacement = {
name: footprintName,
place: {
Expand All @@ -84,12 +76,12 @@ export function processComponentsAndPads(
y: circuitSpaceCoordinates.y,
side: "front" as const,
rotation: pcbComponent?.rotation || 0,
PN: getComponentValue(srcComp),
PN: getComponentValue(sourceComponent),
},
}

// Handle padstacks
const padstackName = `${getPadstackName(srcComp?.ftype)}_${srcComp?.source_component_id}`
const padstackName = `${getPadstackName(sourceComponent?.ftype)}_${sourceComponent?.source_component_id}`
if (!processedPadstacks.has(padstackName)) {
const padstack = createExactPadstack(padstackName)
pcb.library.padstacks.push(padstack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function convertDsnSessionToCircuitJson(
dsnInput: DsnPcb,
dsnSession: DsnSession,
): AnyCircuitElement[] {
const transformUmToMm = scale(1 / 10000)
const transformUmToMm = scale(1 / 1000)

if (debug.enabled) {
Bun.write("dsn-session.json", JSON.stringify(dsnSession, null, 2))
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/get-footprint-name.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @deprecated THIS DOES NOT WORK AT ALL!!!!!!!
*/
export function getFootprintName(componentType: string | undefined): string {
switch (componentType) {
case "simple_resistor":
Expand Down
119 changes: 119 additions & 0 deletions tests/assets/fake-freerouting-example-1/fake-freerouting-example-1.dsn
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
(pcb /Users/seve/Downloads/testkicadproject.dsn
(parser
(string_quote ")
(space_in_quoted_tokens on)
(host_cad "KiCad's Pcbnew")
(host_version "8.0.3")
)
(resolution um 10)
(unit um)
(structure
(layer F.Cu
(type signal)
(property
(index 0)
)
)
(layer B.Cu
(type signal)
(property
(index 1)
)
)
(boundary
(path pcb 0 158000 -108000 147500 -108000 147500 -102000 158000 -102000
158000 -108000)
)
(via "Via[0-1]_600:300_um")
(rule
(width 200)
(clearance 200)
(clearance 200 (type default_smd))
(clearance 50 (type smd_smd))
)
)
(placement
(component Capacitor_SMD:C_0603_1608Metric
(place C1 155020.000000 -105000.000000 front 0.000000 (PN 1uF))
)
(component Resistor_SMD:R_0402_1005Metric
(place R1 149990.000000 -105000.000000 front 0.000000 (PN 1k))
)
)
(library
(image Capacitor_SMD:C_0603_1608Metric
(outline (path signal 120 -140.58 510 140.58 510))
(outline (path signal 120 -140.58 -510 140.58 -510))
(outline (path signal 50 -1480 730 1480 730))
(outline (path signal 50 -1480 -730 -1480 730))
(outline (path signal 50 1480 730 1480 -730))
(outline (path signal 50 1480 -730 -1480 -730))
(outline (path signal 100 -800 400 800 400))
(outline (path signal 100 -800 -400 -800 400))
(outline (path signal 100 800 400 800 -400))
(outline (path signal 100 800 -400 -800 -400))
(pin RoundRect[T]Pad_900x950_225.856_um_0.000000_0 1 -775 0)
(pin RoundRect[T]Pad_900x950_225.856_um_0.000000_0 2 775 0)
)
(image Resistor_SMD:R_0402_1005Metric
(outline (path signal 120 -153.641 380 153.641 380))
(outline (path signal 120 -153.641 -380 153.641 -380))
(outline (path signal 50 -930 470 930 470))
(outline (path signal 50 -930 -470 -930 470))
(outline (path signal 50 930 470 930 -470))
(outline (path signal 50 930 -470 -930 -470))
(outline (path signal 100 -525 270 525 270))
(outline (path signal 100 -525 -270 -525 270))
(outline (path signal 100 525 270 525 -270))
(outline (path signal 100 525 -270 -525 -270))
(pin RoundRect[T]Pad_540x640_135.514_um_0.000000_0 1 -510 0)
(pin RoundRect[T]Pad_540x640_135.514_um_0.000000_0 2 510 0)
)
(padstack RoundRect[T]Pad_540x640_135.514_um_0.000000_0
(shape (polygon F.Cu 0 -270.514 185 -260.199 236.859 -230.823 280.823 -186.859 310.199
-135 320.514 135 320.514 186.859 310.199 230.823 280.823
260.199 236.859 270.514 185 270.514 -185 260.199 -236.859
230.823 -280.823 186.859 -310.199 135 -320.514 -135 -320.514
-186.859 -310.199 -230.823 -280.823 -260.199 -236.859 -270.514 -185
-270.514 185))
(attach off)
)
(padstack RoundRect[T]Pad_900x950_225.856_um_0.000000_0
(shape (polygon F.Cu 0 -450.856 250 -433.664 336.431 -384.704 409.704 -311.431 458.664
-225 475.856 225 475.856 311.431 458.664 384.704 409.704
433.664 336.431 450.856 250 450.856 -250 433.664 -336.431
384.704 -409.704 311.431 -458.664 225 -475.856 -225 -475.856
-311.431 -458.664 -384.704 -409.704 -433.664 -336.431 -450.856 -250
-450.856 250))
(attach off)
)
(padstack "Via[0-1]_600:300_um"
(shape (circle F.Cu 600))
(shape (circle B.Cu 600))
(attach off)
)
)
(network
(net "unconnected-(C1-Pad2)"
(pins C1-2)
)
(net "Net-(C1-Pad1)"
(pins C1-1 R1-2)
)
(net "unconnected-(R1-Pad1)"
(pins R1-1)
)
(class kicad_default "" "Net-(C1-Pad1)" "unconnected-(C1-Pad2)" "unconnected-(R1-Pad1)"
(circuit
(use_via Via[0-1]_600:300_um)
)
(rule
(width 200)
(clearance 200)
)
)
)
(wiring
(wire (path F.Cu 200 150500 -105000 154540 -105000)(net "Net-(C1-Pad1)")(type route))
)
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions tests/repros/repro1-fake-freerouting-example-1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { test, expect } from "bun:test"
import { parseDsnToCircuitJson } from "lib"

// @ts-ignore
import fakeFreeroutingExample1Dsn from "../assets/fake-freerouting-example-1/fake-freerouting-example-1.dsn" with {
type: "text",
}

test("repro1 fake-freerouting-example-1", () => {
const dsnPcb = parseDsnToCircuitJson(fakeFreeroutingExample1Dsn)
})

0 comments on commit 154ec83

Please sign in to comment.