Skip to content

Commit

Permalink
fix session parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Nov 18, 2024
1 parent c361883 commit d8acf6d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
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 / 1000)
const transformUmToMm = scale(1 / 10000)

if (debug.enabled) {
Bun.write("dsn-session.json", JSON.stringify(dsnSession, null, 2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function convertWiresToPcbTraces(
}

if ("path" in wire) {
console.log("adding wiring path")
traces.push(
...convertWiringPathToPcbTraces({ wire, transformUmToMm, netName }),
)
Expand Down
49 changes: 29 additions & 20 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 @@ -301,33 +301,44 @@ function processBoundary(nodes: ASTNode[]): Boundary {

function processPath(nodes: ASTNode[]): Path {
// Find the path node which contains layer, width and coordinates
const pathNode = nodes.find(node =>
node.type === "List" &&
node.children?.[0]?.type === "Atom" &&
node.children[0].value === "path"
);
const pathNode = nodes.find(
(node) =>
node.type === "List" &&
node.children?.[0]?.type === "Atom" &&
node.children[0].value === "path",
)

if (!pathNode) {
// If no path node found, use the nodes directly
// This handles the case where nodes is already the path content
return {
layer: nodes[1]?.type === "Atom" ? nodes[1].value as string : "F.Cu",
width: nodes[2]?.type === "Atom" ? nodes[2].value as number : 200,
coordinates: nodes.slice(3)
.filter(node => node.type === "Atom" && typeof node.value === "number")
.map(node => node.value as number)
};
layer: nodes[1]?.type === "Atom" ? (nodes[1].value as string) : "F.Cu",
width: nodes[2]?.type === "Atom" ? (nodes[2].value as number) : 200,
coordinates: nodes
.slice(3)
.filter(
(node) => node.type === "Atom" && typeof node.value === "number",
)
.map((node) => node.value as number),
}
}

// Process the path node children
const pathChildren = pathNode.children!;
const pathChildren = pathNode.children!
return {
layer: pathChildren[1]?.type === "Atom" ? pathChildren[1].value as string : "F.Cu",
width: pathChildren[2]?.type === "Atom" ? pathChildren[2].value as number : 200,
coordinates: pathChildren.slice(3)
.filter(node => node.type === "Atom" && typeof node.value === "number")
.map(node => node.value as number)
};
layer:
pathChildren[1]?.type === "Atom"
? (pathChildren[1].value as string)
: "F.Cu",
width:
pathChildren[2]?.type === "Atom"
? (pathChildren[2].value as number)
: 200,
coordinates: pathChildren
.slice(3)
.filter((node) => node.type === "Atom" && typeof node.value === "number")
.map((node) => node.value as number),
}
}

function processRule(nodes: ASTNode[]): Rule {
Expand Down Expand Up @@ -973,8 +984,6 @@ function processSessionNode(ast: ASTNode): DsnSession {
child.children[0].value === "wire",
)

console.dir(wireNodes, { depth: 1000 })

return {
name: netName,
wires: wireNodes.map((wireNode) => ({
Expand Down
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 d8acf6d

Please sign in to comment.