diff --git a/bun.lockb b/bun.lockb index 48aec24..a04686a 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/components/base-components/NormalComponent.ts b/lib/components/base-components/NormalComponent.ts index 8383495..2783d6b 100644 --- a/lib/components/base-components/NormalComponent.ts +++ b/lib/components/base-components/NormalComponent.ts @@ -4,6 +4,7 @@ import type { CadModelObj, CadModelProp, CadModelStl, + SchematicPortArrangement, } from "@tscircuit/props" import { point3, rotation } from "circuit-json" import Debug from "debug" @@ -25,6 +26,12 @@ import { ZodType, z } from "zod" import { Footprint } from "../primitive-components/Footprint" import { Port } from "../primitive-components/Port" import { PrimitiveComponent } from "./PrimitiveComponent" +import { + getAllDimensionsForSchematicBox, + type SchematicBoxDimensions, +} from "lib/utils/schematic/getAllDimensionsForSchematicBox" +import { underscorifyPortArrangement } from "lib/soup/underscorifyPortArrangement" +import { underscorifyPinStyles } from "lib/soup/underscorifyPinStyles" const debug = Debug("tscircuit:core") @@ -253,14 +260,29 @@ export class NormalComponent< /** * Render the schematic component for this NormalComponent using the - * config.schematicSymbolName if it exists. + * config.schematicSymbolName if it exists, or create a generic box if + * no symbol is defined. * * You can override this method to do more complicated things. */ doInitialSchematicComponentRender() { - const { db } = this.root! const { schematicSymbolName } = this.config - if (!schematicSymbolName) return + if (schematicSymbolName) { + return this._doInitialSchematicComponentRenderWithSymbol() + } + + const dimensions = this._getSchematicBoxDimensions() + if (dimensions) { + return this._doInitialSchematicComponentRenderWithSchematicBoxDimensions() + } + + // No schematic symbol or dimensions defined, this could be a board, group + // or other NormalComponent that doesn't have a schematic representation + } + + _doInitialSchematicComponentRenderWithSymbol() { + const { db } = this.root! + // TODO switch between horizontal and vertical based on schRotation const base_symbol_name = this.config.schematicSymbolName const symbol_name_horz = `${base_symbol_name}_horz` @@ -281,18 +303,48 @@ export class NormalComponent< const symbol: SchSymbol | undefined = symbols[symbol_name] - if (!symbol) { - throw new Error(`Could not find schematic-symbol "${symbol_name}"`) + if (symbol) { + const schematic_component = db.schematic_component.insert({ + center: { x: this.props.schX ?? 0, y: this.props.schY ?? 0 }, + rotation: this.props.schRotation ?? 0, + size: symbol.size, + source_component_id: this.source_component_id!, + + symbol_name, + }) + this.schematic_component_id = schematic_component.schematic_component_id + } + } + + _doInitialSchematicComponentRenderWithSchematicBoxDimensions() { + const { db } = this.root! + const { _parsedProps: props } = this + const dimensions = this._getSchematicBoxDimensions()! + + const primaryPortLabels: Record = {} + for (const [port, label] of Object.entries(props.pinLabels ?? {})) { + primaryPortLabels[port] = Array.isArray(label) ? label[0] : label } const schematic_component = db.schematic_component.insert({ - center: { x: this.props.schX ?? 0, y: this.props.schY ?? 0 }, - rotation: this.props.schRotation ?? 0, - size: symbol.size, - source_component_id: this.source_component_id!, + center: { x: props.schX ?? 0, y: props.schY ?? 0 }, + rotation: props.schRotation ?? 0, + size: dimensions.getSize(), + + port_arrangement: underscorifyPortArrangement( + props.schPortArrangement as any, + ), + + pin_spacing: props.schPinSpacing ?? 0.2, + + // @ts-ignore soup needs to support distance for pin_styles + pin_styles: underscorifyPinStyles(props.schPinStyle), - symbol_name, + port_labels: primaryPortLabels, + + source_component_id: this.source_component_id!, }) + this.schematic_component_id = schematic_component.schematic_component_id } @@ -545,6 +597,51 @@ export class NormalComponent< } } + _getPinCount(): number { + const schPortArrangement = this._getSchematicPortArrangement() + const pinCountFromSchArrangement = + (schPortArrangement?.leftSize ?? 0) + + (schPortArrangement?.rightSize ?? 0) + + (schPortArrangement?.topSize ?? 0) + + (schPortArrangement?.bottomSize ?? 0) + const pinCount = + pinCountFromSchArrangement || this.getPortsFromFootprint().length + return pinCount + } + + /** + * Override the schematic port arrangement if you want to customize where pins + * appear on a schematic box, e.g. for a pin header + */ + _getSchematicPortArrangement(): SchematicPortArrangement | null { + return this._parsedProps.schPortArrangement + } + + _getSchematicBoxDimensions(): SchematicBoxDimensions | null { + // Only valid if we don't have a schematic symbol + if (this.getSchematicSymbol()) return null + if (!this.config.shouldRenderAsSchematicBox) return null + + const { _parsedProps: props } = this + + const pinCount = this._getPinCount() + + const pinSpacing = props.schPinSpacing ?? 0.2 + + const dimensions = getAllDimensionsForSchematicBox({ + schWidth: props.schWidth, + schHeight: props.schHeight, + schPinSpacing: pinSpacing, + schPinStyle: props.schPinStyle, + + pinCount, + + schPortArrangement: this._getSchematicPortArrangement()!, + }) + + return dimensions + } + doInitialCadModelRender(): void { const { db } = this.root! const { boardThickness = 0 } = this.root?._getBoard() ?? {} diff --git a/lib/components/base-components/PrimitiveComponent.ts b/lib/components/base-components/PrimitiveComponent.ts index dee30fd..adf9edd 100644 --- a/lib/components/base-components/PrimitiveComponent.ts +++ b/lib/components/base-components/PrimitiveComponent.ts @@ -17,12 +17,14 @@ import { z } from "zod" import type { Circuit } from "../../Circuit" import type { ISubcircuit } from "../primitive-components/Group/ISubcircuit" import { Renderable } from "./Renderable" +import type { SchematicBoxDimensions } from "lib/utils/schematic/getAllDimensionsForSchematicBox" export interface BaseComponentConfig { componentName: string schematicSymbolName?: BaseSymbolName | null zodProps: ZodType sourceFtype?: AnySourceComponent["ftype"] | null + shouldRenderAsSchematicBox?: boolean } /** @@ -509,6 +511,22 @@ export abstract class PrimitiveComponent< return descendants } + /** + * Return the number of pins in this component, this is important for + * NormalComponents + */ + _getPinCount(): number { + return 0 + } + + /** + * If this component represents a SchematicBox (like a Chip), return the + * dimensions of the box, which allows computing the position of ports etc. + */ + _getSchematicBoxDimensions(): SchematicBoxDimensions | null { + return null + } + // TODO we shouldn't need to override this, errors can be rendered and handled // by the Renderable class, however, the Renderable class currently doesn't // have access to the database or cleanup diff --git a/lib/components/normal-components/Chip.ts b/lib/components/normal-components/Chip.ts index bb83c6f..99fa63e 100644 --- a/lib/components/normal-components/Chip.ts +++ b/lib/components/normal-components/Chip.ts @@ -11,12 +11,13 @@ export class Chip extends NormalComponent< typeof chipProps, PinLabels > { - schematicDimensions: SchematicBoxDimensions | null = null + schematicBoxDimensions: SchematicBoxDimensions | null = null get config() { return { componentName: "Chip", zodProps: chipProps, + shouldRenderAsSchematicBox: true, } } @@ -34,61 +35,6 @@ export class Chip extends NormalComponent< this.source_component_id = source_component.source_component_id! } - doInitialSchematicComponentRender() { - const { db } = this.root! - const { _parsedProps: props } = this - - const pinCountFromSchArrangement = - (props.schPortArrangement?.leftSize ?? 0) + - (props.schPortArrangement?.rightSize ?? 0) + - (props.schPortArrangement?.topSize ?? 0) + - (props.schPortArrangement?.bottomSize ?? 0) - const pinCount = pinCountFromSchArrangement || this.getPortsFromFootprint().length - - const pinSpacing = props.schPinSpacing ?? 0.2 - - const dimensions = getAllDimensionsForSchematicBox({ - schWidth: props.schWidth, - schHeight: props.schHeight, - schPinSpacing: pinSpacing, - schPinStyle: props.schPinStyle, - - pinCount, - - // @ts-ignore there's a subtley in the definition difference with - // leftSide/rightSide/topSide/bottomSide in how the direction is defined - // that doesn't really matter - schPortArrangement: props.schPortArrangement, - }) - this.schematicDimensions = dimensions - - const primaryPortLabels: Record = {} - for (const [port, label] of Object.entries(props.pinLabels ?? {})) { - primaryPortLabels[port] = Array.isArray(label) ? label[0] : label - } - - const schematic_component = db.schematic_component.insert({ - center: { x: props.schX ?? 0, y: props.schY ?? 0 }, - rotation: props.schRotation ?? 0, - size: dimensions.getSize(), - - port_arrangement: underscorifyPortArrangement( - props.schPortArrangement as any, - ), - - pin_spacing: pinSpacing, - - // @ts-ignore soup needs to support distance for pin_styles - pin_styles: underscorifyPinStyles(props.schPinStyle), - - port_labels: primaryPortLabels, - - source_component_id: this.source_component_id!, - }) - - this.schematic_component_id = schematic_component.schematic_component_id - } - doInitialPcbComponentRender() { const { db } = this.root! const { _parsedProps: props } = this diff --git a/lib/components/normal-components/Jumper.ts b/lib/components/normal-components/Jumper.ts index dcbd35a..d58d47d 100644 --- a/lib/components/normal-components/Jumper.ts +++ b/lib/components/normal-components/Jumper.ts @@ -19,6 +19,7 @@ export class Jumper extends NormalComponent< return { componentName: "Jumper", zodProps: jumperProps, + shouldRenderAsSchematicBox: true, } } @@ -36,54 +37,6 @@ export class Jumper extends NormalComponent< this.source_component_id = source_component.source_component_id! } - doInitialSchematicComponentRender() { - const { db } = this.root! - const { _parsedProps: props } = this - - const ports = this.children.filter((child) => child instanceof Port) - - const pinSpacing = props.schPinSpacing ?? 0.2 - - const dimensions = getAllDimensionsForSchematicBox({ - schWidth: props.schWidth, - schHeight: props.schHeight, - schPinSpacing: pinSpacing, - schPinStyle: props.schPinStyle, - - pinCount: ports.length, - - // @ts-ignore there's a subtley in the definition difference with - // leftSide/rightSide/topSide/bottomSide in how the direction is defined - // that doesn't really matter - schPortArrangement: { - // TODO use schematic direction or schPortArrangement - rightSize: ports.length, - }, - }) - this.schematicDimensions = dimensions - - const schematic_component = db.schematic_component.insert({ - center: { x: props.schX ?? 0, y: props.schY ?? 0 }, - rotation: props.schRotation ?? 0, - size: dimensions.getSize(), - - port_arrangement: underscorifyPortArrangement( - props.schPortArrangement as any, - ), - - pin_spacing: pinSpacing, - - // @ts-ignore soup needs to support distance for pin_styles - pin_styles: underscorifyPinStyles(props.schPinStyle), - - port_labels: props.pinLabels, - - source_component_id: this.source_component_id!, - }) - - this.schematic_component_id = schematic_component.schematic_component_id - } - doInitialPcbComponentRender() { const { db } = this.root! const { _parsedProps: props } = this diff --git a/lib/components/normal-components/PinHeader.ts b/lib/components/normal-components/PinHeader.ts index 94be2a2..c74fa95 100644 --- a/lib/components/normal-components/PinHeader.ts +++ b/lib/components/normal-components/PinHeader.ts @@ -1,4 +1,4 @@ -import { pinHeaderProps } from "@tscircuit/props" +import { pinHeaderProps, type SchematicPortArrangement } from "@tscircuit/props" import { NormalComponent } from "../base-components/NormalComponent" import { Port } from "../primitive-components/Port" import type { BaseSymbolName } from "lib/utils/constants" @@ -8,7 +8,7 @@ export class PinHeader extends NormalComponent { return { componentName: "PinHeader", zodProps: pinHeaderProps, - schematicSymbolName: "pinrow_horz" as BaseSymbolName, + shouldRenderAsSchematicBox: true, } } @@ -41,6 +41,13 @@ export class PinHeader extends NormalComponent { } } + _getSchematicPortArrangement(): SchematicPortArrangement | null { + return { + leftSize: 0, + rightSize: this._parsedProps.pinCount ?? 1, + } + } + doInitialSourceRender() { const { db } = this.root! const { _parsedProps: props } = this @@ -56,22 +63,4 @@ export class PinHeader extends NormalComponent { this.source_component_id = source_component.source_component_id } - - doInitialSchematicComponentRender() { - const { db } = this.root! - const { _parsedProps: props } = this - - const schematic_component = db.schematic_component.insert({ - center: { x: props.schX ?? 0, y: props.schY ?? 0 }, - rotation: props.schRotation ?? 0, - size: { width: 2, height: props.pinCount ?? 1 }, - source_component_id: this.source_component_id!, - port_arrangement: { - left_size: 0, - right_size: props.pinCount ?? 1, - }, - }) - - this.schematic_component_id = schematic_component.schematic_component_id - } } diff --git a/lib/components/primitive-components/Port.ts b/lib/components/primitive-components/Port.ts index b72a926..2ee2160 100644 --- a/lib/components/primitive-components/Port.ts +++ b/lib/components/primitive-components/Port.ts @@ -1,5 +1,8 @@ import { getRelativeDirection } from "lib/utils/get-relative-direction" -import type { SchematicBoxDimensions } from "lib/utils/schematic/getAllDimensionsForSchematicBox" +import type { + SchematicBoxDimensions, + SchematicBoxPortPositionWithMetadata, +} from "lib/utils/schematic/getAllDimensionsForSchematicBox" import { type SchSymbol } from "schematic-symbols" import { applyToPoint, compose, translate } from "transformation-matrix" import { z } from "zod" @@ -79,26 +82,31 @@ export class Port extends PrimitiveComponent { } _getGlobalSchematicPositionBeforeLayout(): { x: number; y: number } { - if (!this.schematicSymbolPortDef) { - return applyToPoint(this.parent!.computeSchematicGlobalTransform(), { - x: 0, - y: 0, - }) - } - const symbol = this.parent?.getSchematicSymbol() - if (!symbol) { - console.warn(`Could not find parent symbol for ${this}`) - return { x: 0, y: 0 } + if (symbol && this.schematicSymbolPortDef) { + const transform = compose( + this.parent!.computeSchematicGlobalTransform(), + translate(-symbol.center.x, -symbol.center.y), + ) + + return applyToPoint(transform, this.schematicSymbolPortDef!) } - const offsetY = -0.045 - const transform = compose( - this.parent!.computeSchematicGlobalTransform(), - translate(-symbol.center.x, -symbol.center.y + offsetY), - ) + const parentBoxDim = this?.parent?._getSchematicBoxDimensions() + if (parentBoxDim && this.props.pinNumber !== undefined) { + const localPortPosition = parentBoxDim.getPortPositionByPinNumber( + this.props.pinNumber!, + ) + if (!localPortPosition) { + return { x: 0, y: 0 } + } + return applyToPoint( + this.parent!.computeSchematicGlobalTransform(), + localPortPosition, + ) + } - return applyToPoint(transform, this.schematicSymbolPortDef) + return { x: 0, y: 0 } } _getGlobalSchematicPositionAfterLayout(): { x: number; y: number } { @@ -244,21 +252,19 @@ export class Port extends PrimitiveComponent { if (!container) return const containerCenter = container._getGlobalSchematicPositionBeforeLayout() - let center = this._getGlobalSchematicPositionBeforeLayout() + const portCenter = this._getGlobalSchematicPositionBeforeLayout() - if ("schematicDimensions" in container && props.pinNumber !== undefined) { - const chipDims = container.schematicDimensions as SchematicBoxDimensions - - center = chipDims.getPortPositionByPinNumber(props.pinNumber!) - center.x += containerCenter.x - center.y += containerCenter.y + let localPortInfo: SchematicBoxPortPositionWithMetadata | null = null + const containerDims = container._getSchematicBoxDimensions() + if (containerDims && props.pinNumber !== undefined) { + localPortInfo = containerDims.getPortPositionByPinNumber(props.pinNumber) } // For each obstacle, create a schematic_debug_object if (this.getSubcircuit().props._schDebugObjectsEnabled) { db.schematic_debug_object.insert({ shape: "rect", - center, + center: portCenter, size: { width: 0.1, height: 0.1, @@ -267,13 +273,17 @@ export class Port extends PrimitiveComponent { } as any) // TODO issue with discriminated union } - this.facingDirection = getRelativeDirection(containerCenter, center) + this.facingDirection = getRelativeDirection(containerCenter, portCenter) const schematic_port = db.schematic_port.insert({ schematic_component_id: this.parent?.schematic_component_id!, - center, + center: portCenter, source_port_id: this.source_port_id!, facing_direction: this.facingDirection, + distance_from_component_edge: localPortInfo?.distanceFromEdge, + side_of_component: localPortInfo?.side, + pin_number: props.pinNumber, + true_ccw_index: localPortInfo?.trueIndex, }) this.schematic_port_id = schematic_port.schematic_port_id diff --git a/lib/utils/schematic/getAllDimensionsForSchematicBox.ts b/lib/utils/schematic/getAllDimensionsForSchematicBox.ts index e618e93..ab63b7b 100644 --- a/lib/utils/schematic/getAllDimensionsForSchematicBox.ts +++ b/lib/utils/schematic/getAllDimensionsForSchematicBox.ts @@ -54,10 +54,10 @@ interface Params { type Side = "left" | "right" | "top" | "bottom" -type PortInfo = { +export type SchematicBoxPortPositionWithMetadata = { trueIndex: number pinNumber: number - side: "left" | "right" | "top" | "bottom" | "center" + side: "left" | "right" | "top" | "bottom" distanceFromEdge: number x: number y: number @@ -84,7 +84,9 @@ function isExplicitPinMappingArrangement( */ export interface SchematicBoxDimensions { pinCount: number - getPortPositionByPinNumber(pinNumber: number): PortInfo + getPortPositionByPinNumber( + pinNumber: number, + ): SchematicBoxPortPositionWithMetadata | null getSize(): { width: number; height: number } } @@ -157,7 +159,7 @@ export const getAllDimensionsForSchematicBox = ( return (sideLength - totalMargin) / (sideSize - 1) } - const orderedTruePorts: PortInfo[] = [] + const orderedTruePorts: SchematicBoxPortPositionWithMetadata[] = [] let truePinIndex = 0 @@ -357,13 +359,6 @@ export const getAllDimensionsForSchematicBox = ( const truePortsWithPositions = orderedTruePorts.map((p) => { const { distanceFromEdge, side } = p - if (side === "center") { - return { - ...p, - x: 0, - y: 0, - } - } const edgePos = trueEdgePositions[side] const edgeDir = trueEdgeTraversalDirections[side] @@ -375,19 +370,14 @@ export const getAllDimensionsForSchematicBox = ( }) return { - getPortPositionByPinNumber(pinNumber: number): PortInfo { + getPortPositionByPinNumber( + pinNumber: number, + ): SchematicBoxPortPositionWithMetadata | null { const port = truePortsWithPositions.find( (p) => p.pinNumber.toString() === pinNumber.toString(), ) if (!port) { - return { - trueIndex: -1, // Use -1 for non-existent ports - pinNumber: pinNumber, - side: "center", - distanceFromEdge: 0, - x: 0, - y: 0, - } + return null } return port }, diff --git a/package.json b/package.json index 4de2607..acf0a7c 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ "@tscircuit/props": "^0.0.83", "@tscircuit/schematic-autolayout": "^0.0.5", "@tscircuit/soup-util": "^0.0.33", - "circuit-json": "^0.0.91", + "circuit-json": "^0.0.93", "circuit-json-to-connectivity-map": "^0.0.17", - "circuit-to-svg": "^0.0.56", + "circuit-to-svg": "^0.0.57", "nanoid": "^5.0.7", "performance-now": "^2.1.0", "react": "^18.3.1", diff --git a/tests/components/normal-components/__snapshots__/chip-port-without-portarrangement-schematic.snap.svg b/tests/components/normal-components/__snapshots__/chip-port-without-portarrangement-schematic.snap.svg index 18d85f6..0686711 100644 --- a/tests/components/normal-components/__snapshots__/chip-port-without-portarrangement-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/chip-port-without-portarrangement-schematic.snap.svg @@ -9,4 +9,4 @@ .pin-number { font-size: 15.141690896176119px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { font-size: 25.236151493626867px; fill: rgb(0, 100, 100); } - 123456780.000001C10.000001C2 \ No newline at end of file + 123456780.000001C10.000001C2 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/header-schematic.snap.svg b/tests/components/normal-components/__snapshots__/header-schematic.snap.svg index 185ca88..cfdb586 100644 --- a/tests/components/normal-components/__snapshots__/header-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/header-schematic.snap.svg @@ -4,9 +4,9 @@ .component { fill: none; stroke: rgb(132, 0, 0); } .chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); } .component-pin { fill: none; stroke: rgb(132, 0, 0); } - .trace { stroke: rgb(0, 150, 0); stroke-width: 1.7142857142857142; fill: none; } - .text { font-family: Arial, sans-serif; font-size: 17.142857142857142px; fill: rgb(0, 150, 0); } - .pin-number { font-size: 12.857142857142856px; fill: rgb(169, 0, 0); } + .trace { stroke: rgb(0, 150, 0); stroke-width: 2.857142857142857; fill: none; } + .text { font-family: Arial, sans-serif; font-size: 28.571428571428573px; fill: rgb(0, 150, 0); } + .pin-number { font-size: 21.428571428571427px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } - .component-name { font-size: 21.428571428571427px; fill: rgb(0, 100, 100); } - 1234 \ No newline at end of file + .component-name { font-size: 35.714285714285715px; fill: rgb(0, 100, 100); } + 1234 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/jumper-schematic.snap.svg b/tests/components/normal-components/__snapshots__/jumper-schematic.snap.svg index cfdb586..5d51e10 100644 --- a/tests/components/normal-components/__snapshots__/jumper-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/jumper-schematic.snap.svg @@ -4,9 +4,9 @@ .component { fill: none; stroke: rgb(132, 0, 0); } .chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); } .component-pin { fill: none; stroke: rgb(132, 0, 0); } - .trace { stroke: rgb(0, 150, 0); stroke-width: 2.857142857142857; fill: none; } - .text { font-family: Arial, sans-serif; font-size: 28.571428571428573px; fill: rgb(0, 150, 0); } - .pin-number { font-size: 21.428571428571427px; fill: rgb(169, 0, 0); } + .trace { stroke: rgb(0, 150, 0); stroke-width: 3.1578947368421053; fill: none; } + .text { font-family: Arial, sans-serif; font-size: 31.578947368421055px; fill: rgb(0, 150, 0); } + .pin-number { font-size: 23.684210526315788px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } - .component-name { font-size: 35.714285714285715px; fill: rgb(0, 100, 100); } - 1234 \ No newline at end of file + .component-name { font-size: 39.473684210526315px; fill: rgb(0, 100, 100); } + 1234 \ No newline at end of file diff --git a/tests/components/normal-components/jumper.test.tsx b/tests/components/normal-components/jumper.test.tsx index e685a02..38d7679 100644 --- a/tests/components/normal-components/jumper.test.tsx +++ b/tests/components/normal-components/jumper.test.tsx @@ -2,9 +2,9 @@ import { it, expect } from "bun:test" import { getTestFixture } from "tests/fixtures/get-test-fixture" it("should render a jumper with pinrow4 footprint", async () => { - const { project } = getTestFixture() + const { circuit } = getTestFixture() - project.add( + circuit.add( { , ) - project.render() + circuit.render() - expect(project).toMatchPcbSnapshot(import.meta.path) - expect(project).toMatchSchematicSnapshot(import.meta.path) + expect(circuit).toMatchPcbSnapshot(import.meta.path) + expect(circuit).toMatchSchematicSnapshot(import.meta.path) }) diff --git a/tests/examples/__snapshots__/bug-high-port-number-schematic.snap.svg b/tests/examples/__snapshots__/bug-high-port-number-schematic.snap.svg index 1de4954..391d8ad 100644 --- a/tests/examples/__snapshots__/bug-high-port-number-schematic.snap.svg +++ b/tests/examples/__snapshots__/bug-high-port-number-schematic.snap.svg @@ -9,4 +9,4 @@ .pin-number { font-size: 12.40876490075511px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { font-size: 20.68127483459185px; fill: rgb(0, 100, 100); } - part-numberU11615201742728192625718211511329106232214131210000R110000R2 \ No newline at end of file + part-numberU11615201742728192625718211511329106232214131282410000R110000R2 \ No newline at end of file diff --git a/tests/examples/__snapshots__/example4-kicad-schematic.snap.svg b/tests/examples/__snapshots__/example4-kicad-schematic.snap.svg index d3d1eae..f6833dd 100644 --- a/tests/examples/__snapshots__/example4-kicad-schematic.snap.svg +++ b/tests/examples/__snapshots__/example4-kicad-schematic.snap.svg @@ -9,4 +9,4 @@ .pin-number { font-size: 8.490566037735848px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { font-size: 14.150943396226413px; fill: rgb(0, 100, 100); } - 100000R10.0001C1ATmega8-16AU229GND7-V+82019221213141516172341823 \ No newline at end of file + 100000R10.0001C1ATmega8-16AU229GND7-V+82019221213141516172341823 \ No newline at end of file diff --git a/tests/examples/__snapshots__/example5-simple-circuit-schematic.snap.svg b/tests/examples/__snapshots__/example5-simple-circuit-schematic.snap.svg index 21d3a76..796da2e 100644 --- a/tests/examples/__snapshots__/example5-simple-circuit-schematic.snap.svg +++ b/tests/examples/__snapshots__/example5-simple-circuit-schematic.snap.svg @@ -4,9 +4,9 @@ .component { fill: none; stroke: rgb(132, 0, 0); } .chip { fill: rgb(255, 255, 194); stroke: rgb(132, 0, 0); } .component-pin { fill: none; stroke: rgb(132, 0, 0); } - .trace { stroke: rgb(0, 150, 0); stroke-width: 2.560921166758245; fill: none; } - .text { font-family: Arial, sans-serif; font-size: 25.609211667582453px; fill: rgb(0, 150, 0); } - .pin-number { font-size: 19.20690875068684px; fill: rgb(169, 0, 0); } + .trace { stroke: rgb(0, 150, 0); stroke-width: 2.569589461188567; fill: none; } + .text { font-family: Arial, sans-serif; font-size: 25.695894611885674px; fill: rgb(0, 150, 0); } + .pin-number { font-size: 19.271920958914254px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } - .component-name { font-size: 32.011514584478064px; fill: rgb(0, 100, 100); } - 0.0001C1100000R11234 \ No newline at end of file + .component-name { font-size: 32.11986826485709px; fill: rgb(0, 100, 100); } + 0.0001C1100000R11234 \ No newline at end of file diff --git a/tests/examples/example4-kicad.test.tsx b/tests/examples/example4-kicad.test.tsx index 61fb9ed..6db3560 100644 --- a/tests/examples/example4-kicad.test.tsx +++ b/tests/examples/example4-kicad.test.tsx @@ -2,9 +2,9 @@ import { expect, it } from "bun:test" import { getTestFixture } from "tests/fixtures/get-test-fixture" it("example 4: kicad theme demo", async () => { - const { project, logSoup } = getTestFixture() + const { circuit, logSoup } = getTestFixture() - project.add( + circuit.add( { , ) - project.render() + circuit.render() - expect(project).toMatchSchematicSnapshot(import.meta.path) + expect(circuit).toMatchSchematicSnapshot(import.meta.path) }) diff --git a/tests/repros/__snapshots__/repro3-usb-port-footprint-schematic.snap.svg b/tests/repros/__snapshots__/repro3-usb-port-footprint-schematic.snap.svg index 1d75ca6..348ab52 100644 --- a/tests/repros/__snapshots__/repro3-usb-port-footprint-schematic.snap.svg +++ b/tests/repros/__snapshots__/repro3-usb-port-footprint-schematic.snap.svg @@ -9,4 +9,4 @@ .pin-number { font-size: 6.315789473684211px; fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { font-size: 10.526315789473685px; fill: rgb(0, 100, 100); } - 1237891011121314151617181920212223242526 \ No newline at end of file + 12037891011121314151617181920212223242526 \ No newline at end of file diff --git a/tests/utils/schematic/getSchematicBoxSvg.ts b/tests/utils/schematic/getSchematicBoxSvg.ts index fe04308..e408223 100644 --- a/tests/utils/schematic/getSchematicBoxSvg.ts +++ b/tests/utils/schematic/getSchematicBoxSvg.ts @@ -14,6 +14,7 @@ export const getSchematicBoxSvg = ( // Draw the pins for (let i = 1; i <= dimensions.pinCount; i++) { const pos = dimensions.getPortPositionByPinNumber(i) + if (!pos) continue svg += `` svg += `${i}` }