Skip to content

Commit

Permalink
Added Root Circuit.ts pcbDisabled option
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasSarkiz committed Dec 11, 2024
1 parent 3ecee57 commit e9f388f
Show file tree
Hide file tree
Showing 25 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Circuit {
root: Circuit | null = null
isRoot = true
schematicDisabled = false

pcbDisabled = false
_hasRenderedAtleastOnce = false

constructor() {
Expand Down
2 changes: 2 additions & 0 deletions lib/components/base-components/NormalComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export class NormalComponent<
}

doInitialPcbComponentRender() {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const pcb_component = db.pcb_component.insert({
Expand Down Expand Up @@ -501,6 +502,7 @@ export class NormalComponent<
* the width/height of the component
*/
doInitialPcbComponentSizeCalculation(): void {
if (this.root?.pcbDisabled) return
if (!this.pcb_component_id) return
const { db } = this.root!
const { _parsedProps: props } = this
Expand Down
1 change: 1 addition & 0 deletions lib/components/normal-components/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Board extends Group<typeof boardProps> {
}

doInitialPcbComponentRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/normal-components/Chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Chip<PinLabels extends string = never> extends NormalComponent<
this.source_component_id = source_component.source_component_id!
}
doInitialPcbComponentRender() {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/normal-components/Jumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class Jumper<PinLabels extends string = never> extends NormalComponent<
}

doInitialPcbComponentRender() {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/FabricationNotePath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class FabricationNotePath extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/FabricationNoteText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class FabricationNoteText extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const container = this.getPrimitiveContainer()!
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Footprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Footprint extends PrimitiveComponent<typeof footprintProps> {
* to any constraints that are defined.
*/
doInitialPcbFootprintLayout() {
if (this.root?.pcbDisabled) return
const constraints = this.children.filter(
(child) => child.componentName === "Constraint",
) as Constraint[]
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Group/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class Group<Props extends z.ZodType<any, any, any> = typeof groupProps>
}

doInitialPcbTraceRender() {
if (this.root?.pcbDisabled) return
if (this._shouldUseTraceByTraceRouting()) return

const serverUrl =
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Hole extends PrimitiveComponent<typeof holeProps> {
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Keepout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class Keepout extends PrimitiveComponent<typeof pcbKeepoutProps> {
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class Net extends PrimitiveComponent<typeof netProps> {
* routing phase for autorouters that don't care about connecting nets.
*/
doInitialPcbRouteNetIslands(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
2 changes: 2 additions & 0 deletions lib/components/primitive-components/PlatedHole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()
Expand Down Expand Up @@ -126,6 +127,7 @@ export class PlatedHole extends PrimitiveComponent<typeof platedHoleProps> {
}

doInitialPcbPortAttachment(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
db.pcb_plated_hole.update(this.pcb_plated_hole_id!, {
pcb_port_id: this.matchedPort?.pcb_port_id!,
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export class Port extends PrimitiveComponent<typeof portProps> {
}

doInitialPcbPortRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { matchedComponents } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/SilkscreenCircle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class SilkscreenCircle extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const layer = props.layer ?? "top"
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/SilkscreenPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SilkscreenPath extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/SilkscreenRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class SilkscreenRect extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/SilkscreenText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class SilkscreenText extends PrimitiveComponent<
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const container = this.getPrimitiveContainer()!
Expand Down
2 changes: 2 additions & 0 deletions lib/components/primitive-components/SmtPad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
if (!props.portHints) return
Expand Down Expand Up @@ -151,6 +152,7 @@ export class SmtPad extends PrimitiveComponent<typeof smtPadProps> {
}

doInitialPcbPortAttachment(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
db.pcb_smtpad.update(this.pcb_smtpad_id!, {
pcb_port_id: this.matchedPort?.pcb_port_id!,
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Trace/Trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export class Trace
}

doInitialPcbTraceRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props, parent } = this
const subcircuit = this.getSubcircuit()
Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/TraceHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class TraceHint extends PrimitiveComponent<typeof traceHintProps> {
}

doInitialPcbTraceHintRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this

Expand Down
1 change: 1 addition & 0 deletions lib/components/primitive-components/Via.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Via extends PrimitiveComponent<typeof viaProps> {
}

doInitialPcbPrimitiveRender(): void {
if (this.root?.pcbDisabled) return
const { db } = this.root!
const { _parsedProps: props } = this
const position = this._getGlobalPcbPositionBeforeLayout()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getTestFixture } from "../fixtures/get-test-fixture"
test("Should not render any schematic components", async () => {
const { circuit } = getTestFixture()
circuit.schematicDisabled = true

circuit.pcbDisabled = true
circuit.add(
<board width={10} height={10}>
<chip
Expand Down Expand Up @@ -38,4 +38,9 @@ test("Should not render any schematic components", async () => {
.filter((c) => c.type === "schematic_trace")
expect(traces.length).toBe(0)
expect(circuit).toMatchSchematicSnapshot(import.meta.path)
const pcbComponents = circuit
.getCircuitJson()
.filter((c) => c.type === "pcb_component")
expect(pcbComponents.length).toBe(0)
expect(circuit).toMatchPcbSnapshot(import.meta.path)
})

0 comments on commit e9f388f

Please sign in to comment.