-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
preload = ["./tests/fixtures/preload.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { NormalComponent } from "lib/components/base-components/NormalComponent" | ||
import { jumperProps } from "@tscircuit/props" | ||
import { Port } from "../primitive-components/Port" | ||
import type { BaseSymbolName } from "lib/utils/constants" | ||
import { | ||
getAllDimensionsForSchematicBox, | ||
type SchematicBoxDimensions, | ||
} from "lib/utils/schematic/getAllDimensionsForSchematicBox" | ||
import { underscorifyPortArrangement } from "lib/soup/underscorifyPortArrangement" | ||
import { underscorifyPinStyles } from "lib/soup/underscorifyPinStyles" | ||
|
||
export class Jumper<PinLabels extends string = never> extends NormalComponent< | ||
typeof jumperProps, | ||
PinLabels | ||
> { | ||
schematicDimensions: SchematicBoxDimensions | null = null | ||
|
||
get config() { | ||
return { | ||
zodProps: jumperProps, | ||
} | ||
} | ||
|
||
initPorts() { | ||
super.initPorts() | ||
|
||
const { _parsedProps: props } = this | ||
|
||
if (props.pinLabels) { | ||
for (let [pinNumber, label] of Object.entries(props.pinLabels)) { | ||
pinNumber = pinNumber.replace("pin", "") | ||
const port = this.selectOne(`port[pinNumber='${pinNumber}']`) | ||
if (!port) { | ||
throw new Error( | ||
`Could not find port for pin number ${pinNumber} in chip ${this.getString()}`, | ||
) | ||
} | ||
port.props.aliases.push(port.props.name) | ||
port.props.name = label | ||
} | ||
} | ||
} | ||
|
||
doInitialSourceRender(): void { | ||
const { db } = this.project! | ||
const { _parsedProps: props } = this | ||
|
||
const source_component = db.source_component.insert({ | ||
ftype: "simple_chip", // TODO unknown or jumper | ||
name: props.name, | ||
manufacturer_part_number: props.manufacturerPartNumber, | ||
supplier_part_numbers: props.supplierPartNumbers, | ||
}) | ||
|
||
this.source_component_id = source_component.source_component_id! | ||
} | ||
|
||
doInitialSchematicComponentRender() { | ||
const { db } = this.project! | ||
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.project! | ||
const { _parsedProps: props } = this | ||
|
||
const pcb_component = db.pcb_component.insert({ | ||
center: { x: props.pcbX ?? 0, y: props.pcbY ?? 0 }, | ||
width: 2, // Default width, adjust as needed | ||
height: 3, // Default height, adjust as needed | ||
layer: props.layer ?? "top", | ||
rotation: props.pcbRotation ?? 0, | ||
source_component_id: this.source_component_id!, | ||
}) | ||
|
||
this.pcb_component_id = pcb_component.pcb_component_id | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "bun-match-svg" |