Skip to content

Commit

Permalink
Improved PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Abse2001 committed Dec 21, 2024
1 parent 8d1ede9 commit fa162c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
53 changes: 19 additions & 34 deletions lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ function processImage(nodes: ASTNode[]): Image {
if (key === "outline") {
image.outlines!.push(processOutline(node.children!))
} else if (key === "pin") {
image.pins!.push(processPin(node.children!))
const pin = processPin(node.children!)
if (pin) image.pins!.push(pin)
}
}
}
Expand All @@ -564,7 +565,7 @@ function processOutline(nodes: ASTNode[]): Outline {
return outline as Outline
}

function processPin(nodes: ASTNode[]): Pin {
function processPin(nodes: ASTNode[]): Pin | null {
const pin: Partial<Pin> = {}
// default pin
pin.padstack_name = "default"
Expand All @@ -578,7 +579,8 @@ function processPin(nodes: ASTNode[]): Pin {
if (nodes[1]?.type === "Atom") {
pin.padstack_name = String(nodes[1].value)
} else {
throw new Error("Missing padstack name")
debug("Unsupported pin padstack_name format:", nodes)
return null
}

// Helper function to parse pin number
Expand All @@ -594,8 +596,8 @@ function processPin(nodes: ASTNode[]): Pin {
if (nodes[2]?.type === "Atom") {
pin.pin_number = parsePinNumber(nodes[2].value)
} else {
console.warn("Warning: Missing pin number")
console.error("Missing pin number")
debug("Unsupported pin number format:", nodes)
return null
}

// Handle coordinates, accounting for scientific notation
Expand Down Expand Up @@ -834,8 +836,10 @@ export function processNetwork(nodes: ASTNode[]): Network {

function processNet(nodes: ASTNode[]): Net {
const net: Partial<Net> = {}
// in the smoothie board some of the nets names are numbers like 3.3 so I need to convert them to strings
if (nodes[1].type === "Atom") {
net.name = nodes[1].value?.toString()
debug("net name was not string before parsing", net.name)
}

nodes.slice(2).forEach((node) => {
Expand Down Expand Up @@ -938,22 +942,16 @@ export function processWiring(nodes: ASTNode[]): Wiring {
node.children![0].type === "Atom" &&
node.children![0].value === "via"
) {
wiring.wires!.push(processVia(node.children!))
const via = processVia(node.children!)
if (via) wiring.wires!.push(via)
}
})

return wiring as Wiring
}

function processVia(nodes: ASTNode[]): Wire {
const wire: Partial<Wire> = {
type: "via",
path: {
layer: "all", // Default: vias connect all layers
width: 0, // Default width
coordinates: [], // Fallback to empty if coordinates are missing
},
}
function processVia(nodes: ASTNode[]): Wire | null {
const wire: Partial<Wire> = {}

// Find the path node which contains coordinates
const pathNode = nodes.find(
Expand All @@ -971,29 +969,16 @@ function processVia(nodes: ASTNode[]): Wire {
if (coords.length === 2) {
wire.path!.coordinates = coords.map((node) => node.value as number)

Check failure on line 970 in lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'wire.path.coordinates = coords.map((node) => node.value)')

at processVia (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:970:12) at /home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:945:19 at forEach (1:11) at processWiring (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:932:9) at processPCB (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:148:26) at /home/runner/work/dsn-converter/dsn-converter/tests/dsn-pcb/merge-dsn-session-with-conversion.test.tsx:47:26

Check failure on line 970 in lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts

View workflow job for this annotation

GitHub Actions / test

TypeError: undefined is not an object (evaluating 'wire.path.coordinates = coords.map((node) => node.value)')

at processVia (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:970:12) at /home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:945:19 at forEach (1:11) at processWiring (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:932:9) at processPCB (/home/runner/work/dsn-converter/dsn-converter/lib/dsn-pcb/dsn-json-to-circuit-json/parse-dsn-to-dsn-json.ts:148:26) at /home/runner/work/dsn-converter/dsn-converter/tests/dsn-pcb/basic-via-pcb-layer-change.test.tsx:40:19
} else {
console.warn("Warning: Missing or incomplete coordinates for via")
console.error("problematic node", nodes)
debug("Warning: Missing or incomplete coordinates for via", nodes)
return null
}
} else {
console.warn("Warning: Missing path node for via")
console.error("problematic node", nodes)
}

// Find net name if present
const netNode = nodes.find(
(node) =>
node.type === "List" &&
node.children?.[0]?.type === "Atom" &&
node.children[0].value === "net",
)
if (netNode?.children?.[1]?.type === "Atom") {
wire.net = String(netNode.children[1].value)
} else {
console.warn("Warning: Missing net information for via")
console.error("problematic node", nodes)
debug("Warning: Missing path node for via", nodes)
return null
}

return wire as Wire
debug("Unsupported via format", nodes)
return null
}

function processWire(nodes: ASTNode[]): Wire {
Expand Down
2 changes: 1 addition & 1 deletion tests/repros/__snapshots__/smoothieboard.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fa162c4

Please sign in to comment.