Skip to content

Commit

Permalink
Merge pull request #30 from tscircuit/manualplace1
Browse files Browse the repository at this point in the history
Fix Manual Placements not moving smtpads
  • Loading branch information
seveibar authored Sep 4, 2024
2 parents eed03ba + ea21364 commit 47bd16a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,31 @@ export abstract class PrimitiveComponent<

/**
* Compute a transformation matrix combining all parent transforms for PCB
* components
* components, including this component's translation and rotation.
*
* This is used to compute this component's position as well as all children
* components positions
*/
computePcbGlobalTransform(): Matrix {
const { _parsedProps: props } = this
const manualPlacement =
this.getSubcircuit()._getManualPlacementForComponent(this)

// pcbX or pcbY will override the manual placement
if (
manualPlacement &&
this.props.pcbX === undefined &&
this.props.pcbY === undefined
) {
return compose(
this.parent?.computePcbGlobalTransform() ?? identity(),
compose(
translate(manualPlacement.x, manualPlacement.y),
rotate(((props.pcbRotation ?? 0) * Math.PI) / 180),
),
)
}

return compose(
this.parent?.computePcbGlobalTransform() ?? identity(),
this.computePcbPropsTransform(),
Expand Down Expand Up @@ -198,11 +220,6 @@ export abstract class PrimitiveComponent<
}

getGlobalPcbPosition(): { x: number; y: number } {
const manualPlacement =
this.getSubcircuit()._getManualPlacementForComponent(this)
if (manualPlacement) {
return manualPlacement
}
return applyToPoint(this.computePcbGlobalTransform(), { x: 0, y: 0 })
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/components/normal-components/board-layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ test("board with manual layout edits", () => {

expect(capacitorPosition.x).toBeCloseTo(-5, 1)
expect(capacitorPosition.y).toBeCloseTo(-5, 1)

const r1SmtpadPositions = project
.selectAll(".R1 > smtpad")
.map((elm) => elm.getGlobalPcbPosition())

expect(Math.abs(r1SmtpadPositions[0].x - 5)).toBeLessThan(1)
expect(Math.abs(r1SmtpadPositions[1].x - 5)).toBeLessThan(1)

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

0 comments on commit 47bd16a

Please sign in to comment.