diff --git a/__snapshots__/potentiometer-default-schematic.snap.svg b/__snapshots__/potentiometer-default-schematic.snap.svg new file mode 100644 index 00000000..bf51d8f2 --- /dev/null +++ b/__snapshots__/potentiometer-default-schematic.snap.svg @@ -0,0 +1,17 @@ +-2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1P3 \ No newline at end of file diff --git a/__snapshots__/potentiometer-three-pin-schematic.snap.svg b/__snapshots__/potentiometer-three-pin-schematic.snap.svg new file mode 100644 index 00000000..131da091 --- /dev/null +++ b/__snapshots__/potentiometer-three-pin-schematic.snap.svg @@ -0,0 +1,17 @@ +-2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1P2 \ No newline at end of file diff --git a/__snapshots__/potentiometer-two-pin-schematic.snap.svg b/__snapshots__/potentiometer-two-pin-schematic.snap.svg new file mode 100644 index 00000000..6497cba4 --- /dev/null +++ b/__snapshots__/potentiometer-two-pin-schematic.snap.svg @@ -0,0 +1,17 @@ +-2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1P1 \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 443565b4..30f8399f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/components/normal-components/Potentiometer.ts b/lib/components/normal-components/Potentiometer.ts index 9fb4e94c..2ba1a36e 100644 --- a/lib/components/normal-components/Potentiometer.ts +++ b/lib/components/normal-components/Potentiometer.ts @@ -1,50 +1,41 @@ import { potentiometerProps } from "@tscircuit/props" -import { - type BaseSymbolName, - type Ftype, - type PolarizedPassivePorts, -} from "lib/utils/constants" import { NormalComponent } from "../base-components/NormalComponent/NormalComponent" -import { Port } from "../primitive-components/Port" -import type { SourceSimplePotentiometer } from "circuit-json" -import { formatSiUnit } from "format-si-unit" +import type { BaseSymbolName } from "lib/utils/constants" -export class Potentiometer extends NormalComponent< - typeof potentiometerProps, - PolarizedPassivePorts -> { - // @ts-ignore +function getPotentiometerSymbolName( + variant: string | undefined, +): BaseSymbolName { + switch (variant) { + case "three_pin": + return "potentiometer3" + case "two_pin": + return "potentiometer2" + default: + return "potentiometer2" + } +} + +export class Potentiometer extends NormalComponent { get config() { return { - schematicSymbolName: - this.props.symbolName ?? ("potentiometer2" as BaseSymbolName), componentName: "Potentiometer", + schematicSymbolName: + this.props.symbolName ?? + getPotentiometerSymbolName(this.props.pinVariant), zodProps: potentiometerProps, - sourceFtype: "simple_potentiometer" as Ftype, + shouldRenderAsSchematicBox: false, } } - initPorts() { - super.initPorts({ - additionalAliases: { - pin1: ["pos", "left"], - pin2: ["neg", "right"], - }, - }) - } - - _getSchematicSymbolDisplayValue(): string | undefined { - return `${formatSiUnit(this._parsedProps.maxResistance)}Ω` - } - doInitialSourceRender() { const { db } = this.root! const { _parsedProps: props } = this const source_component = db.source_component.insert({ - name: props.name, ftype: "simple_potentiometer", + name: props.name, max_resistance: props.maxResistance, - } as SourceSimplePotentiometer) + pin_variant: props.pinVariant || "two_pin", + } as any) this.source_component_id = source_component.source_component_id } } diff --git a/lib/components/primitive-components/Group/Group.ts b/lib/components/primitive-components/Group/Group.ts index b1146a65..e478f3a0 100644 --- a/lib/components/primitive-components/Group/Group.ts +++ b/lib/components/primitive-components/Group/Group.ts @@ -167,31 +167,27 @@ export class Group = typeof groupProps> } _shouldRouteAsync(): boolean { - const props = this._parsedProps as SubcircuitGroupProps - if (props.autorouter === "auto-local") return true - if (props.autorouter === "auto-cloud") return true - if (props.autorouter === "sequential-trace") return false - if (typeof props.autorouter === "object") return true - return false + const autorouter = this._getAutorouterConfig() + if (autorouter.local) return false + if (autorouter.groupMode === "sequential-trace") return false + return true + } + + _hasTracesToRoute(): boolean { + const debug = Debug("tscircuit:core:_hasTracesToRoute") + const traces = this.selectAll("trace") as Trace[] + debug(`[${this.getString()}] has ${traces.length} traces to route`) + return traces.length > 0 } async _runEffectMakeHttpAutoroutingRequest() { const debug = Debug("tscircuit:core:_runEffectMakeHttpAutoroutingRequest") const props = this._parsedProps as SubcircuitGroupProps - const autorouterPropObj = - typeof props.autorouter === "object" ? props.autorouter : {} - - const autoroutingOptions: AutorouterConfig = { - ...autorouterPropObj, - serverUrl: - autorouterPropObj.serverUrl ?? "https://registry-api.tscircuit.com", - serverMode: autorouterPropObj.serverMode ?? "job", - serverCacheEnabled: autorouterPropObj.serverCacheEnabled ?? false, - } + const autorouterConfig = this._getAutorouterConfig() - const serverUrl = autoroutingOptions.serverUrl! - const serverMode = autoroutingOptions.serverMode! + const serverUrl = autorouterConfig.serverUrl! + const serverMode = autorouterConfig.serverMode! const fetchWithDebug = (url: string, options: RequestInit) => { debug("fetching", url) @@ -252,7 +248,7 @@ export class Group = typeof groupProps> autostart: true, display_name: this.root?.name, subcircuit_id: this.subcircuit_id, - server_cache_enabled: autoroutingOptions.serverCacheEnabled, + server_cache_enabled: autorouterConfig.serverCacheEnabled, }), headers: { "Content-Type": "application/json" }, }, @@ -321,6 +317,7 @@ export class Group = typeof groupProps> doInitialPcbTraceRender() { const debug = Debug("tscircuit:core:doInitialPcbTraceRender") + if (!this.isSubcircuit) return if (this.root?.pcbDisabled) return if (this._shouldUseTraceByTraceRouting()) return @@ -334,12 +331,18 @@ export class Group = typeof groupProps> debug( `[${this.getString()}] no child subcircuits to wait for, initiating async routing`, ) + if (!this._hasTracesToRoute()) return this._startAsyncAutorouting() } updatePcbTraceRender() { const debug = Debug("tscircuit:core:updatePcbTraceRender") - if (this._shouldRouteAsync() && !this._hasStartedAsyncAutorouting) { + if (!this.isSubcircuit) return + if ( + this._shouldRouteAsync() && + this._hasTracesToRoute() && + !this._hasStartedAsyncAutorouting + ) { if (this._areChildSubcircuitsRouted()) { debug( `[${this.getString()}] child subcircuits are now routed, starting async autorouting`, @@ -463,6 +466,42 @@ export class Group = typeof groupProps> SAL.mutateSoupForScene(db.toArray(), laidOutScene) } + _getAutorouterConfig(): AutorouterConfig { + const defaults = { + serverUrl: "https://registry-api.tscircuit.com", + serverMode: "job", + serverCacheEnabled: false, + } + // Inherit from parent if not set by props + const autorouter = + this._parsedProps.autorouter ?? this.getInheritedProperty("autorouter") + + if (typeof autorouter === "object") { + return { + local: !( + autorouter.serverUrl || + autorouter.serverMode || + autorouter.serverCacheEnabled + ), + ...defaults, + ...autorouter, + } + } + + if (autorouter === "auto-local") + return { + local: true, + } + if (autorouter === "sequential-trace") + return { + local: true, + groupMode: "sequential-trace", + } + return { + local: true, + groupMode: "sequential-trace", + } + } /** * Trace-by-trace autorouting is where each trace routes itself in a well-known * order. It's the most deterministic way to autoroute, because a new trace @@ -473,11 +512,7 @@ export class Group = typeof groupProps> */ _shouldUseTraceByTraceRouting(): boolean { // Inherit from parent if not set by props - const autorouter = - this._parsedProps.autorouter ?? this.getInheritedProperty("autorouter") - if (autorouter === "auto-local") return true - if (autorouter === "sequential-trace") return true - if (autorouter) return false - return true + const autorouter = this._getAutorouterConfig() + return autorouter.groupMode === "sequential-trace" } } diff --git a/package.json b/package.json index ba8d73a7..9c260b89 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@tscircuit/core", "type": "module", - "version": "0.0.307", + "version": "0.0.310", "types": "dist/index.d.ts", "main": "dist/index.js", "module": "dist/index.js", @@ -54,7 +54,7 @@ "@tscircuit/footprinter": "^0.0.97", "@tscircuit/infgrid-ijump-astar": "^0.0.33", "@tscircuit/math-utils": "^0.0.9", - "@tscircuit/props": "^0.0.142", + "@tscircuit/props": "^0.0.145", "@tscircuit/schematic-autolayout": "^0.0.6", "@tscircuit/soup-util": "^0.0.41", "circuit-json": "^0.0.136", @@ -64,7 +64,7 @@ "performance-now": "^2.1.0", "react-reconciler": "^0.31.0", "react-reconciler-18": "npm:react-reconciler@0.29.2", - "schematic-symbols": "^0.0.113", + "schematic-symbols": "^0.0.119", "transformation-matrix": "^2.16.1", "zod": "^3.23.8" } diff --git a/tests/components/normal-components/__snapshots__/capacitor-polarized-schematic.snap.svg b/tests/components/normal-components/__snapshots__/capacitor-polarized-schematic.snap.svg index b91f2abd..ee794ca4 100644 --- a/tests/components/normal-components/__snapshots__/capacitor-polarized-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/capacitor-polarized-schematic.snap.svg @@ -1,4 +1,4 @@ --2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1C110µF \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/mosfet-schematic.snap.svg b/tests/components/normal-components/__snapshots__/mosfet-schematic.snap.svg index 628cb4d9..29b636da 100644 --- a/tests/components/normal-components/__snapshots__/mosfet-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/mosfet-schematic.snap.svg @@ -1,4 +1,4 @@ --6,-3-6,-2-6,-1-6,0-6,1-6,2-6,3-5,-3-5,-2-5,-1-5,0-5,1-5,2-5,3-4,-3-4,-2-4,-1-4,0-4,1-4,2-4,3-3,-3-3,-2-3,-1-3,0-3,1-3,2-3,3-2,-3-2,-2-2,-1-2,0-2,1-2,2-2,3-1,-3-1,-2-1,-1-1,0-1,1-1,2-1,30,-30,-20,-10,00,10,20,31,-31,-21,-11,01,11,21,3M1M2M3M4 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/potentiometer-schematic.snap.svg b/tests/components/normal-components/__snapshots__/potentiometer-schematic.snap.svg index f4efb654..cfd55c56 100644 --- a/tests/components/normal-components/__snapshots__/potentiometer-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/potentiometer-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,23,-23,-13,03,13,24,-24,-14,04,14,25,-25,-15,05,15,26,-26,-16,06,16,27,-27,-17,07,17,210kΩP110kΩP210kΩP310kΩP4 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,23,-23,-13,03,13,24,-24,-14,04,14,25,-25,-15,05,15,26,-26,-16,06,16,27,-27,-17,07,17,2P1P2P3P4 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/pushbutton1-schematic.snap.svg b/tests/components/normal-components/__snapshots__/pushbutton1-schematic.snap.svg index aa166369..836b8c3c 100644 --- a/tests/components/normal-components/__snapshots__/pushbutton1-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/pushbutton1-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1PB1 \ No newline at end of file + -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1PB1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/pushbutton2-schematic.snap.svg b/tests/components/normal-components/__snapshots__/pushbutton2-schematic.snap.svg index eeab2b9d..7d01b2da 100644 --- a/tests/components/normal-components/__snapshots__/pushbutton2-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/pushbutton2-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -5,-1-5,0-5,1-5,2-4,-1-4,0-4,1-4,2-3,-1-3,0-3,1-3,2-2,-1-2,0-2,1-2,2-1,-1-1,0-1,1-1,20,-10,00,10,21,-11,01,11,22,-12,02,12,23,-13,03,13,24,-14,04,14,25,-15,05,15,2SW1SW2 \ No newline at end of file + -5,-1-5,0-5,1-5,2-4,-1-4,0-4,1-4,2-3,-1-3,0-3,1-3,2-2,-1-2,0-2,1-2,2-1,-1-1,0-1,1-1,20,-10,00,10,21,-11,01,11,22,-12,02,12,23,-13,03,13,24,-14,04,14,25,-15,05,15,2SW1SW2 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.0-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.0-schematic.snap.svg index 6b9ac524..98b0e4a7 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.0-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.0-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,2Q1 \ No newline at end of file + -1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,2Q1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.180-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.180-schematic.snap.svg index 0e7fe183..7f388055 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.180-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.180-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q1 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.270-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.270-schematic.snap.svg index e955729b..ef46d2a0 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.270-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.270-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1Q1 \ No newline at end of file + -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1Q1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.90-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.90-schematic.snap.svg index d00faaa9..19b89b55 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.90-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.npn.90-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q1 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q1 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.0-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.0-schematic.snap.svg index 89bcb2b1..9daf7db8 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.0-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.0-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,2Q2 \ No newline at end of file + -1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,2Q2 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.180-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.180-schematic.snap.svg index 3f7b55cd..62db5739 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.180-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.180-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q2 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q2 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.270-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.270-schematic.snap.svg index 28fca448..b80f610f 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.270-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.270-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1Q2 \ No newline at end of file + -2,-1-2,0-2,1-1,-1-1,0-1,10,-10,00,11,-11,01,12,-12,02,1Q2 \ No newline at end of file diff --git a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.90-schematic.snap.svg b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.90-schematic.snap.svg index d9d2d084..bc51aa8b 100644 --- a/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.90-schematic.snap.svg +++ b/tests/components/normal-components/__snapshots__/transistor.test.tsx.pnp.90-schematic.snap.svg @@ -14,4 +14,4 @@ .pin-number { fill: rgb(169, 0, 0); } .port-label { fill: rgb(0, 100, 100); } .component-name { fill: rgb(0, 100, 100); } - -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q2 \ No newline at end of file + -2,-2-2,-1-2,0-2,1-2,2-1,-2-1,-1-1,0-1,1-1,20,-20,-10,00,10,21,-21,-11,01,11,22,-22,-12,02,12,2Q2 \ No newline at end of file diff --git a/tests/components/normal-components/potentiometer.test.tsx b/tests/components/normal-components/potentiometer.test.tsx index e4fdae92..81bbd2be 100644 --- a/tests/components/normal-components/potentiometer.test.tsx +++ b/tests/components/normal-components/potentiometer.test.tsx @@ -1,9 +1,41 @@ import { test, expect } from "bun:test" import { getTestFixture } from "tests/fixtures/get-test-fixture" -test("potentiometer schematic", () => { +test("should render a two-pin potentiometer", async () => { const { circuit } = getTestFixture() + circuit.add( + + + , + ) + circuit.render() + expect(circuit).toMatchSchematicSnapshot("potentiometer-two-pin") +}) +test("should render a three-pin potentiometer", async () => { + const { circuit } = getTestFixture() + circuit.add( + + + , + ) + circuit.render() + expect(circuit).toMatchSchematicSnapshot("potentiometer-three-pin") +}) + +test("should render a potentiometer without pinVariant specified", async () => { + const { circuit } = getTestFixture() + circuit.add( + + + , + ) + circuit.render() + expect(circuit).toMatchSchematicSnapshot("potentiometer-default") +}) + +test("should render multiple potentiometers with different rotations", async () => { + const { circuit } = getTestFixture() circuit.add( 1,-21,-11,01,11,21,31,41,52,-22,-12,02,12,22,32,42,53,-23,-13,03,13,23,33,43,54,-24,-14,04,14,24,34,44,55,-25,-15,05,15,25,35,45,56,-26,-16,06,16,26,36,46,57,-27,-17,07,17,27,37,47,58,-28,-18,08,18,28,38,48,59,-29,-19,09,19,29,39,49,510,-210,-110,010,110,210,310,410,5C1_n9010µFC2_n18010µFC3_n27010µFC4_n36010µFC5_noRotation10µF \ No newline at end of file + 1,-21,-11,01,11,21,31,41,52,-22,-12,02,12,22,32,42,53,-23,-13,03,13,23,33,43,54,-24,-14,04,14,24,34,44,55,-25,-15,05,15,25,35,45,56,-26,-16,06,16,26,36,46,57,-27,-17,07,17,27,37,47,58,-28,-18,08,18,28,38,48,59,-29,-19,09,19,29,39,49,510,-210,-110,010,110,210,310,410,5C1_n9010µFC2_n18010µFC3_n27010µFC4_n36010µFC5_noRotation10µF \ No newline at end of file diff --git a/tests/examples/__snapshots__/example19-subcircuit-overlap-traces-pcb.snap.svg b/tests/examples/__snapshots__/example19-subcircuit-overlap-traces-pcb.snap.svg index 18e3a18a..c7051fd3 100644 --- a/tests/examples/__snapshots__/example19-subcircuit-overlap-traces-pcb.snap.svg +++ b/tests/examples/__snapshots__/example19-subcircuit-overlap-traces-pcb.snap.svg @@ -10,4 +10,4 @@ .pcb-silkscreen-top { stroke: #f2eda1; } .pcb-silkscreen-bottom { stroke: #f2eda1; } .pcb-silkscreen-text { fill: #f2eda1; } - \ No newline at end of file + \ No newline at end of file diff --git a/tests/examples/example19-subcircuit-overlap-traces.test.tsx b/tests/examples/example19-subcircuit-overlap-traces.test.tsx index 3a11d15f..fb515763 100644 --- a/tests/examples/example19-subcircuit-overlap-traces.test.tsx +++ b/tests/examples/example19-subcircuit-overlap-traces.test.tsx @@ -83,7 +83,7 @@ test.skip("If the subcircuit is routing disabled, it should not have traces from `) }) -test("Autorouter should not create traces if the parent subcircuit has async autorouter enabled", async () => { +test("Autorouter should inherit if the parent subcircuit has async autorouter enabled", async () => { const { circuit } = getTestFixture() const { autoroutingServerUrl } = getTestAutoroutingServer() @@ -109,61 +109,44 @@ test("Autorouter should not create traces if the parent subcircuit has async aut expect(pcb_traces).toMatchInlineSnapshot(` [ { - "pcb_trace_id": "pcb_trace_Net-(R1_source_component_0-Pad1)", + "pcb_trace_id": "pcb_trace_0", "route": [ { "layer": "top", "route_type": "wire", - "width": 0.16, - "x": 1.5, + "width": 0.1, + "x": -2.5, "y": 0, }, { "layer": "top", "route_type": "wire", - "width": 0.16, - "x": 0.9483, + "width": 0.1, + "x": -2, "y": 0, }, - ], - "source_trace_id": "source_trace_0", - "trace_length": 0.5517, - "type": "pcb_trace", - }, - { - "pcb_trace_id": "pcb_trace_Net-(R1_source_component_0-Pad1)", - "route": [ { "layer": "top", "route_type": "wire", - "width": 0.16, - "x": 0.9483, - "y": 0, + "width": 0.1, + "x": -2, + "y": 1.3, }, { "layer": "top", "route_type": "wire", - "width": 0.16, - "x": 0.3966, - "y": -0.5517, - }, - { - "layer": "top", - "route_type": "wire", - "width": 0.16, - "x": -1.9483, - "y": -0.5517, + "width": 0.1, + "x": 1.5, + "y": 1.3, }, { "layer": "top", "route_type": "wire", - "width": 0.16, - "x": -2.5, + "width": 0.1, + "x": 1.5, "y": 0, }, ], - "source_trace_id": "source_trace_0", - "trace_length": 3.9053, "type": "pcb_trace", }, ] diff --git a/tests/subcircuits/__snapshots__/subcircuit3-dependent-autorouting-pcb.snap.svg b/tests/subcircuits/__snapshots__/subcircuit3-dependent-autorouting-pcb.snap.svg index 12831a8d..4c071f04 100644 --- a/tests/subcircuits/__snapshots__/subcircuit3-dependent-autorouting-pcb.snap.svg +++ b/tests/subcircuits/__snapshots__/subcircuit3-dependent-autorouting-pcb.snap.svg @@ -10,4 +10,4 @@ .pcb-silkscreen-top { stroke: #f2eda1; } .pcb-silkscreen-bottom { stroke: #f2eda1; } .pcb-silkscreen-text { fill: #f2eda1; } - \ No newline at end of file + \ No newline at end of file diff --git a/tests/subcircuits/subcircuit3-dependent-autorouting.test.tsx b/tests/subcircuits/subcircuit3-dependent-autorouting.test.tsx index 590f2842..36d8bda0 100644 --- a/tests/subcircuits/subcircuit3-dependent-autorouting.test.tsx +++ b/tests/subcircuits/subcircuit3-dependent-autorouting.test.tsx @@ -33,7 +33,10 @@ test("subcircuit3-dependent-autorouting", async () => { /> - + { "effectName": "make-http-autorouting-request", "phase": "PcbTraceRender", }, - { - "componentDisplayName": "", - "effectName": "make-http-autorouting-request", - "phase": "PcbTraceRender", - }, ] `) diff --git a/tests/subcircuits/subcircuit4-nested-group-autorouter.test.tsx b/tests/subcircuits/subcircuit4-nested-group-autorouter.test.tsx new file mode 100644 index 00000000..272db4e4 --- /dev/null +++ b/tests/subcircuits/subcircuit4-nested-group-autorouter.test.tsx @@ -0,0 +1,59 @@ +import React from "react" +import { test, expect } from "bun:test" +import { getTestFixture } from "tests/fixtures/get-test-fixture" +import { getTestAutoroutingServer } from "tests/fixtures/get-test-autorouting-server" + +test("Nested group within a subcircuit triggers autorouter only once", async () => { + const { autoroutingServerUrl } = getTestAutoroutingServer() + + const cloudAutorouterConfig = { + serverUrl: autoroutingServerUrl, + serverMode: "solve-endpoint", + inputFormat: "simplified", + } as const + const { circuit } = getTestFixture() + + // Count the number of times the autorouter is triggered + let autorouterCallCount = 0 + circuit.on("asyncEffect:start", (event) => { + if (event.effectName === "make-http-autorouting-request") { + autorouterCallCount++ + } + }) + + // Add a board with autorouter configuration + circuit.add( + + + + + + + + + , + ) + + await circuit.renderUntilSettled() + + // Expect that the autorouter is called only once for the subcircuit, + // not once for the nested group + expect(autorouterCallCount).toBe(1) +})