Skip to content

Commit

Permalink
Merge pull request #224 from tscircuit/fix/shifting-port-position
Browse files Browse the repository at this point in the history
feat: add support for manualEdits
  • Loading branch information
imrishabh18 authored Nov 1, 2024
2 parents 288c421 + c1e2c72 commit c59aab9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
43 changes: 24 additions & 19 deletions lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions tests/components/primitive-components/json/manual-edits.json
Original file line number Diff line number Diff line change
@@ -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": []
}
17 changes: 17 additions & 0 deletions tests/components/primitive-components/manual-edits-layout.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<board width="10mm" height="10mm" manualEdits={manualEdits}>
<resistor name="R1" resistance="100" footprint="0402"/>
</board>,
)

project.render()

expect(project).toMatchPcbSnapshot(import.meta.path)
})

0 comments on commit c59aab9

Please sign in to comment.