diff --git a/bun.lock b/bun.lock index 4e469a1..9887759 100644 --- a/bun.lock +++ b/bun.lock @@ -9,7 +9,7 @@ "@tscircuit/math-utils": "^0.0.18", "@vitejs/plugin-react": "^4.5.0", "circuit-json-to-connectivity-map": "^0.0.22", - "circuit-to-svg": "^0.0.130", + "circuit-to-svg": "^0.0.144", "color": "^4.2.3", "graphics-debug": "^0.0.24", "react-supergrid": "^1.0.10", @@ -30,7 +30,7 @@ "@types/color": "^3.0.6", "@types/node": "18.7.23", "@types/react": "^18.3.3", - "circuit-json": "^0.0.194", + "circuit-json": "^0.0.195", "next": "^14.1.4", "pixi.js": "^8.6.6", "react": "^18.2.0", @@ -540,11 +540,11 @@ "chownr": ["chownr@1.1.4", "", {}, "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg=="], - "circuit-json": ["circuit-json@0.0.194", "", { "dependencies": { "nanoid": "^5.0.7", "zod": "^3.23.6" } }, "sha512-/zYxKZs9rHDjoSHlcJFq1I5A0fJaEfwa/CgZ1DzylxGvf10Q4uQ3icE3br26G/jfRGMRu/ocH+v5sJuo1453Vg=="], + "circuit-json": ["circuit-json@0.0.195", "", { "dependencies": { "nanoid": "^5.0.7", "zod": "^3.23.6" } }, "sha512-DZvOJOF/sZPskGFdWWGQ4fFKDhBSf8ok/jgw08t3IxyUzAiykVMghFtXj+D+2pU4YRYtH99ZUsbj3DYuflC0OQ=="], "circuit-json-to-connectivity-map": ["circuit-json-to-connectivity-map@0.0.22", "", { "dependencies": { "@tscircuit/math-utils": "^0.0.9" }, "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-HN8DiISjZZLTglGEkYNRpKeQ/DMG4dDo5j4Hck0UGSJbpux9aFwtJOGszMf06Inh/gu5oKBrpZJIeWxaNacKUg=="], - "circuit-to-svg": ["circuit-to-svg@0.0.130", "", { "dependencies": { "@types/node": "^22.5.5", "bun-types": "^1.1.40", "svgson": "^5.3.1", "transformation-matrix": "^2.16.1" }, "peerDependencies": { "@tscircuit/circuit-json-util": "*", "@tscircuit/footprinter": "*", "circuit-json": "*", "schematic-symbols": "*" } }, "sha512-xL5LkvwylGVwmxIjWX9Rp/x6v02ppBay+eNyhH4D5bOjQ8KWvwC2aCwCTBft2l5GPn/KAJeI2vNKy/njzGbJhw=="], + "circuit-to-svg": ["circuit-to-svg@0.0.144", "", { "dependencies": { "@types/node": "^22.5.5", "bun-types": "^1.1.40", "svgson": "^5.3.1", "transformation-matrix": "^2.16.1" }, "peerDependencies": { "@tscircuit/circuit-json-util": "*", "@tscircuit/footprinter": "*", "circuit-json": "*", "schematic-symbols": "*" } }, "sha512-RgVVkuds5fy+OYbg4xatcP4DJBDD0v0kL6ANcOsT53SyjmIvQGmoI/0Ox341lRH5EpQKnJcAGdC20Gtb7fBSLA=="], "clean-stack": ["clean-stack@2.2.0", "", {}, "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A=="], diff --git a/package.json b/package.json index 06a2929..2f78504 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "@types/color": "^3.0.6", "@types/node": "18.7.23", "@types/react": "^18.3.3", - "circuit-json": "^0.0.194", + "circuit-json": "^0.0.195", "next": "^14.1.4", "pixi.js": "^8.6.6", "react": "^18.2.0", @@ -53,7 +53,7 @@ "@tscircuit/math-utils": "^0.0.18", "@vitejs/plugin-react": "^4.5.0", "circuit-json-to-connectivity-map": "^0.0.22", - "circuit-to-svg": "^0.0.130", + "circuit-to-svg": "^0.0.144", "color": "^4.2.3", "graphics-debug": "^0.0.24", "react-supergrid": "^1.0.10", diff --git a/src/components/EditTraceHintOverlay.tsx b/src/components/EditTraceHintOverlay.tsx index 5c7ee13..b269101 100644 --- a/src/components/EditTraceHintOverlay.tsx +++ b/src/components/EditTraceHintOverlay.tsx @@ -43,15 +43,19 @@ const isInsideOfSmtpad = ( // Not implemented return false } - const halfWidth = elm.width / 2 - const halfHeight = elm.height / 2 + if (elm.shape === "rect" || elm.shape === "rotated_rect") { + const halfWidth = elm.width / 2 + const halfHeight = elm.height / 2 - const left = elm.x - halfWidth - padding - const right = elm.x + halfWidth + padding - const top = elm.y - halfHeight - padding - const bottom = elm.y + halfHeight + padding + const left = elm.x - halfWidth - padding + const right = elm.x + halfWidth + padding + const top = elm.y - halfHeight - padding + const bottom = elm.y + halfHeight + padding - return point.x > left && point.x < right && point.y > top && point.y < bottom + return ( + point.x > left && point.x < right && point.y > top && point.y < bottom + ) + } } const isInsideOfPlatedHole = ( @@ -185,21 +189,32 @@ export const EditTraceHintOverlay = ({ } setSelectedElement(e) setShouldCreateAsVia(false) - setDragState({ - dragStart: rwMousePoint, - originalCenter: { x: e.x, y: e.y }, - dragEnd: rwMousePoint, - editEvent: { - pcb_edit_event_type: "edit_trace_hint", - pcb_port_id: e.pcb_port_id!, - pcb_trace_hint_id: Math.random().toString(), - route: [], - created_at: Date.now(), - edit_event_id: Math.random().toString(), - in_progress: true, - }, - shouldDrawRouteHint: false, - }) + + if (e.type === "pcb_smtpad") { + if ( + e.shape === "rotated_rect" || + e.shape === "rect" || + e.shape === "circle" + ) { + setDragState({ + dragStart: rwMousePoint, + originalCenter: { x: e.x, y: e.y }, + dragEnd: rwMousePoint, + editEvent: { + pcb_edit_event_type: "edit_trace_hint", + pcb_port_id: e.pcb_port_id!, + pcb_trace_hint_id: Math.random().toString(), + route: [], + created_at: Date.now(), + edit_event_id: Math.random().toString(), + in_progress: true, + }, + shouldDrawRouteHint: false, + }) + } else { + console.warn(`Unsupported shape "${e.shape}" for pcb_smtpad`) + } + } cancelPanDrag() break diff --git a/src/examples/trace-error.fixture.tsx b/src/examples/trace-error.fixture.tsx index dd51bf3..8616e5d 100644 --- a/src/examples/trace-error.fixture.tsx +++ b/src/examples/trace-error.fixture.tsx @@ -164,6 +164,18 @@ export const TraceErrorCircuit4 = () => ( width: 1, height: 1, }, + { + type: "pcb_smtpad", + layer: "top" as const, + shape: "polygon", + points: [ + { x: -4.1, y: 5.6 }, + { x: -3.8, y: 4.4 }, + { x: -6.2, y: 4.4 }, + { x: -5.9, y: 5.6 }, + ], + pcb_smtpad_id: "test_polygon_pad_1", + }, { type: "pcb_port", pcb_port_id: "pcb_port_0", diff --git a/src/lib/convert-element-to-primitive.ts b/src/lib/convert-element-to-primitive.ts index d8adf67..50e2d3f 100644 --- a/src/lib/convert-element-to-primitive.ts +++ b/src/lib/convert-element-to-primitive.ts @@ -156,6 +156,21 @@ export const convertElementToPrimitives = ( _source_port, }, ] + } else if (element.shape === "polygon") { + const { points, layer } = element + + return [ + { + _pcb_drawing_object_id: `polygon_${globalPcbDrawingObjectCount++}`, + pcb_drawing_type: "polygon", + points, + layer: layer || "top", + _element: element, + _parent_pcb_component, + _parent_source_component, + _source_port, + }, + ] } return [] }