diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index fa4d1c8..dee30fd 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -1,25 +1,22 @@ -import type { Circuit } from "../../Circuit" -import type { AnyCircuitElement, AnySourceComponent } from "circuit-json" -import type { ZodType } from "zod" -import { z } from "zod" -import { symbols, type SchSymbol, type BaseSymbolName } from "schematic-symbols" -import { isValidElement as isReactElement, type ReactElement } from "react" -import type { Port } from "../primitive-components/Port" -import { Renderable, type RenderPhase } from "./Renderable" +import type { LayoutBuilder } from "@tscircuit/layout" +import type { AnySourceComponent, LayerRef } from "circuit-json" +import { InvalidProps } from "lib/errors/InvalidProps" +import { isMatchingSelector } from "lib/utils/selector-matching" +import { type BaseSymbolName, type SchSymbol, symbols } from "schematic-symbols" import { + type Matrix, applyToPoint, compose, flipY, identity, rotate, translate, - type Matrix, } from "transformation-matrix" -import { isMatchingSelector } from "lib/utils/selector-matching" -import type { LayoutBuilder } from "@tscircuit/layout" -import type { LayerRef } from "circuit-json" -import { InvalidProps } from "lib/errors/InvalidProps" +import type { ZodType } from "zod" +import { z } from "zod" +import type { Circuit } from "../../Circuit" import type { ISubcircuit } from "../primitive-components/Group/ISubcircuit" +import { Renderable } from "./Renderable" export interface BaseComponentConfig { componentName: string @@ -294,18 +291,26 @@ export abstract class PrimitiveComponent< if (!this.isSubcircuit) return null const layout: LayoutBuilder = this.props.layout - if (!layout) return null + const manualEdits = this.props.manualEdits + + if (!layout && !manualEdits) return null + + const placementConfigPositions = + layout?.manual_pcb_placement_config?.positions || + manualEdits?.pcb_placements - const placementConfig = layout.manual_pcb_placement_config - if (!placementConfig) return null + if (!placementConfigPositions) return null - for (const position of placementConfig.positions) { - if (isMatchingSelector(component, position.selector)) { + for (const position of placementConfigPositions) { + if ( + (layout && isMatchingSelector(component, position.selector)) || + component.props.name === position.selector + ) { const center = applyToPoint( this._computePcbGlobalTransformBeforeLayout(), position.center, ) - return center + return Array.isArray(center) ? { x: center[0], y: center[1] } : center } } diff --git a/package.json b/package.json index 79b6727..7ac4079 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@tscircuit/footprinter": "^0.0.77", "@tscircuit/infgrid-ijump-astar": "^0.0.24", "@tscircuit/math-utils": "^0.0.4", - "@tscircuit/props": "^0.0.77", + "@tscircuit/props": "^0.0.78", "@tscircuit/schematic-autolayout": "^0.0.5", "@tscircuit/soup-util": "^0.0.33", "circuit-json": "^0.0.91", diff --git a/tests/components/primitive-components/__snapshots__/manual-edits-layout-pcb.snap.svg b/tests/components/primitive-components/__snapshots__/manual-edits-layout-pcb.snap.svg new file mode 100644 index 0000000..e953f3d --- /dev/null +++ b/tests/components/primitive-components/__snapshots__/manual-edits-layout-pcb.snap.svg @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/tests/components/primitive-components/json/manual-edits.json b/tests/components/primitive-components/json/manual-edits.json new file mode 100644 index 0000000..284a72d --- /dev/null +++ b/tests/components/primitive-components/json/manual-edits.json @@ -0,0 +1,15 @@ +{ + "pcb_placements": [ + { + "selector": "R1", + "center": { + "x": 0, + "y": 6.869495369849336 + }, + "relative_to": "group_center", + "_edit_event_id": "0.037205222437411756" + } + ], + "edit_events": [], + "manual_trace_hints": [] +} \ No newline at end of file diff --git a/tests/components/primitive-components/manual-edits-layout.test.tsx b/tests/components/primitive-components/manual-edits-layout.test.tsx new file mode 100644 index 0000000..4d7baa3 --- /dev/null +++ b/tests/components/primitive-components/manual-edits-layout.test.tsx @@ -0,0 +1,17 @@ +import { expect, test } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" +import manualEdits from "./json/manual-edits.json" + +test("Manual edits prop usage", () => { + const { project } = getTestFixture() + + project.add( + + + , + ) + + project.render() + + expect(project).toMatchPcbSnapshot(import.meta.path) +})