diff --git a/lib/sch/convert-circuit-json-to-schematic-svg.ts b/lib/sch/convert-circuit-json-to-schematic-svg.ts index 1535cb6..9e197ee 100644 --- a/lib/sch/convert-circuit-json-to-schematic-svg.ts +++ b/lib/sch/convert-circuit-json-to-schematic-svg.ts @@ -168,7 +168,7 @@ export function convertCircuitJsonToSchematicSvg( .component { fill: none; stroke: ${colorMap.schematic.component_outline}; } .chip { fill: ${colorMap.schematic.component_body}; stroke: ${colorMap.schematic.component_outline}; } .component-pin { fill: none; stroke: ${colorMap.schematic.component_outline}; } - .trace { stroke: ${colorMap.schematic.wire}; } + .trace { } .text { font-family: sans-serif; fill: ${colorMap.schematic.wire}; } .pin-number { fill: ${colorMap.schematic.pin_number}; } .port-label { fill: ${colorMap.schematic.reference}; } diff --git a/lib/sch/draw-schematic-grid.ts b/lib/sch/draw-schematic-grid.ts index 0c22cc0..a2b28f7 100644 --- a/lib/sch/draw-schematic-grid.ts +++ b/lib/sch/draw-schematic-grid.ts @@ -25,7 +25,7 @@ export function drawSchematicGrid(params: { } // Vertical lines - for (let x = Math.ceil(minX); x <= Math.floor(maxX); x += cellSize) { + for (let x = Math.floor(minX); x <= Math.ceil(maxX); x += cellSize) { const start = transformPoint(x, minY) const end = transformPoint(x, maxY) @@ -45,7 +45,7 @@ export function drawSchematicGrid(params: { } // Horizontal lines - for (let y = Math.ceil(minY); y <= Math.floor(maxY); y += cellSize) { + for (let y = Math.floor(minY); y <= Math.ceil(maxY); y += cellSize) { const start = transformPoint(minX, y) const end = transformPoint(maxX, y) @@ -66,8 +66,12 @@ export function drawSchematicGrid(params: { // Add cell labels if enabled if (labelCells) { - for (let x = Math.ceil(minX); x <= Math.floor(maxX); x += cellSize) { - for (let y = Math.ceil(minY); y <= Math.floor(maxY); y += cellSize) { + const formatPoint = (x: number, y: number) => { + if (cellSize <= 0.1) return `${x.toFixed(1)},${y.toFixed(1)}` + return `${x},${y}` + } + for (let x = Math.floor(minX); x <= Math.ceil(maxX); x += cellSize) { + for (let y = Math.floor(minY); y <= Math.ceil(maxY); y += cellSize) { const point = transformPoint(x, y) gridLines.push({ @@ -89,7 +93,7 @@ export function drawSchematicGrid(params: { children: [ { type: "text", - value: `${x},${y}`, + value: formatPoint(x, y), name: "", attributes: {}, children: [], diff --git a/lib/sch/get-schematic-bounds-from-circuit-json.ts b/lib/sch/get-schematic-bounds-from-circuit-json.ts index ea28152..42d7faa 100644 --- a/lib/sch/get-schematic-bounds-from-circuit-json.ts +++ b/lib/sch/get-schematic-bounds-from-circuit-json.ts @@ -33,6 +33,11 @@ export function getSchematicBoundsFromCircuitJson( } } else if (item.type === "schematic_net_label") { updateBounds(item.center, { width: 1, height: 1 }, 0) + } else if (item.type === "schematic_trace") { + for (const edge of item.edges) { + updateBounds(edge.from, { width: 0.1, height: 0.1 }, 0) + updateBounds(edge.to, { width: 0.1, height: 0.1 }, 0) + } } } diff --git a/lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts b/lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts index c897350..97d32cf 100644 --- a/lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts +++ b/lib/sch/svg-object-fns/create-svg-objects-from-sch-trace.ts @@ -12,7 +12,36 @@ export function createSchematicTrace( if (edges.length === 0) return [] const svgObjects: SvgObject[] = [] - let path = "" + let currentPath = "" + const paths: SvgObject[] = [] + + let colors = [ + "rgb(255,0,0)", + "rgb(0,255,0)", + "rgb(0,0,255)", + "rgb(255,255,0)", + "rgb(255, 0, 255)", + "rgb(0, 255,255)", + ] + let colorIndex = -1 + + function addPath() { + paths.push({ + name: "path", + type: "element", + attributes: { + class: "trace", + d: currentPath, + stroke: colors[colorIndex++ % colors.length], + fill: "none", + "stroke-width": `${getSchStrokeSize(transform) * (1 + colorIndex / 2)}px`, + "stroke-linecap": "round", + opacity: "0.5", + }, + value: "", + children: [], + }) + } // Process edges into an SVG path for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) { @@ -31,13 +60,16 @@ export function createSchematicTrace( ]) // Regular straight line for non-crossing traces - if (edgeIndex === 0 || edges[edgeIndex - 1]?.is_crossing) { - path += `M ${screenFromX} ${screenFromY} L ${screenToX} ${screenToY}` - } else { - path += ` L ${screenToX} ${screenToY}` - } + // if (edgeIndex === 0 || edges[edgeIndex - 1]?.is_crossing) { + addPath() + currentPath = `M ${screenFromX} ${screenFromY} L ${screenToX} ${screenToY}` + // } else { + // currentPath += ` L ${screenToX} ${screenToY}` + // } } + if (currentPath) addPath() + // Process wire crossings with little "hops" or arcs for (const edge of edges) { if (!edge.is_crossing) continue @@ -98,23 +130,6 @@ export function createSchematicTrace( }) } - if (path) { - svgObjects.push({ - name: "path", - type: "element", - attributes: { - class: "trace", - d: path, - stroke: colorMap.schematic.wire, - fill: "none", - "stroke-width": `${getSchStrokeSize(transform)}px`, - "stroke-linecap": "round", - }, - value: "", - children: [], - }) - } - // Add junction circles if (trace.junctions) { for (const junction of trace.junctions) { @@ -137,5 +152,7 @@ export function createSchematicTrace( } } + svgObjects.push(...paths) + return svgObjects } diff --git a/tests/sch/__snapshots__/crossing-traces.snap.svg b/tests/sch/__snapshots__/crossing-traces.snap.svg new file mode 100644 index 0000000..d8cfd2c --- /dev/null +++ b/tests/sch/__snapshots__/crossing-traces.snap.svg @@ -0,0 +1,12 @@ +-5.0,-1.0-5.0,-0.9-5.0,-0.8-5.0,-0.7-5.0,-0.6-5.0,-0.5-5.0,-0.4-5.0,-0.3-5.0,-0.2-5.0,-0.1-5.0,-0.0-5.0,0.1-5.0,0.2-5.0,0.3-5.0,0.4-5.0,0.5-5.0,0.6-5.0,0.7-5.0,0.8-5.0,0.9-5.0,1.0-4.9,-1.0-4.9,-0.9-4.9,-0.8-4.9,-0.7-4.9,-0.6-4.9,-0.5-4.9,-0.4-4.9,-0.3-4.9,-0.2-4.9,-0.1-4.9,-0.0-4.9,0.1-4.9,0.2-4.9,0.3-4.9,0.4-4.9,0.5-4.9,0.6-4.9,0.7-4.9,0.8-4.9,0.9-4.9,1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,0.5-0.3,0.6-0.3,0.7-0.3,0.8-0.3,0.9-0.3,1.0-0.2,-1.0-0.2,-0.9-0.2,-0.8-0.2,-0.7-0.2,-0.6-0.2,-0.5-0.2,-0.4-0.2,-0.3-0.2,-0.2-0.2,-0.1-0.2,-0.0-0.2,0.1-0.2,0.2-0.2,0.3-0.2,0.4-0.2,0.5-0.2,0.6-0.2,0.7-0.2,0.8-0.2,0.9-0.2,1.0-0.1,-1.0-0.1,-0.9-0.1,-0.8-0.1,-0.7-0.1,-0.6-0.1,-0.5-0.1,-0.4-0.1,-0.3-0.1,-0.2-0.1,-0.1-0.1,-0.0-0.1,0.1-0.1,0.2-0.1,0.3-0.1,0.4-0.1,0.5-0.1,0.6-0.1,0.7-0.1,0.8-0.1,0.9-0.1,1.0-0.0,-1.0-0.0,-0.9-0.0,-0.8-0.0,-0.7-0.0,-0.6-0.0,-0.5-0.0,-0.4-0.0,-0.3-0.0,-0.2-0.0,-0.1-0.0,-0.0-0.0,0.1-0.0,0.2-0.0,0.3-0.0,0.4-0.0,0.5-0.0,0.6-0.0,0.7-0.0,0.8-0.0,0.9-0.0,1.0 \ No newline at end of file diff --git a/tests/sch/crossing-traces.test.tsx b/tests/sch/crossing-traces.test.tsx new file mode 100644 index 0000000..2b2e4d6 --- /dev/null +++ b/tests/sch/crossing-traces.test.tsx @@ -0,0 +1,119 @@ +import { test, expect } from "bun:test" +import type { SchematicTrace } from "circuit-json" +import { convertCircuitJsonToSchematicSvg } from "lib" + +test("schematic crossing traces", () => { + expect( + convertCircuitJsonToSchematicSvg( + [ + { + type: "schematic_trace", + schematic_trace_id: "schematic_trace_2", + source_trace_id: "source_trace_2", + edges: [ + { + from: { + route_type: "wire", + x: -3.4662092999999996, + y: 0.004741299999999338, + width: 0.1, + layer: "top", + }, + to: { + x: -2.25, + y: 0.004741299999999338, + }, + }, + { + from: { + x: -2.25, + y: 0.004741299999999338, + }, + to: { + x: -2.1500000000000004, + y: 0.004741299999999338, + }, + is_crossing: true, + }, + { + from: { + route_type: "wire", + x: -3.4662092999999996, + y: 0.004741299999999338, + width: 0.1, + layer: "top", + }, + to: { + x: -2.4662092999999996, + y: 0.004741299999999338, + }, + }, + { + from: { + x: -2.4662092999999996, + y: 0.004741299999999338, + }, + to: { + x: -2.3662093, + y: 0.004741299999999338, + }, + is_crossing: true, + }, + { + from: { + x: -2.3662093, + y: 0.004741299999999338, + }, + to: { + route_type: "wire", + x: -2.0999999999999996, + y: 0.004741299999999338, + width: 0.1, + layer: "top", + }, + }, + { + from: { + route_type: "wire", + x: -2.0999999999999996, + y: 0.004741299999999338, + width: 0.1, + layer: "top", + }, + to: { + route_type: "wire", + x: -2.0999999999999996, + y: -0.30000000000000004, + width: 0.1, + layer: "top", + }, + }, + { + from: { + route_type: "wire", + x: -2.0999999999999996, + y: -0.30000000000000004, + width: 0.1, + layer: "top", + }, + to: { + route_type: "wire", + x: -1.2999999999999998, + y: -0.30000000000000004, + width: 0.1, + layer: "top", + }, + }, + ], + junctions: [], + } as SchematicTrace, + ], + { + grid: { + cellSize: 0.1, + labelCells: true, + }, + }, + ), + ).toMatchSvgSnapshot(import.meta.path) +})