Skip to content

Commit

Permalink
Merge branch 'tscircuit:main' into display-value
Browse files Browse the repository at this point in the history
  • Loading branch information
Anshgrover23 authored Dec 29, 2024
2 parents 3877916 + 7319745 commit c863612
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 4 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and is the primary way that Circuit JSON is defined and maintained.
- [SourceSimplePushButton](#sourcesimplepushbutton)
- [SourceSimpleResistor](#sourcesimpleresistor)
- [SourceSimpleResonator](#sourcesimpleresonator)
- [SourceSimpleTransistor](#sourcesimpletransistor)
- [SourceTrace](#sourcetrace)
- [PCB Elements](#pcb-elements)
- [PcbBoard](#pcbboard)
Expand Down Expand Up @@ -329,6 +330,19 @@ interface SourceSimpleResonator extends SourceComponentBase {
}
```

### SourceSimpleTransistor

```typescript
/** Defines a simple transistor component
* This is a three-pin semiconductor device (emitter, base, collector)
* Pin configuration is handled by the schematic port system */

interface SourceSimpleTransistor extends SourceComponentBase {
ftype: "simple_transistor"
transistor_type: "npn" | "pnp"
}
```

### SourceTrace

```typescript
Expand Down Expand Up @@ -517,6 +531,23 @@ interface PcbPlatedHoleCircle {
pcb_port_id?: string
pcb_plated_hole_id: string
}

interface PcbHoleCircularWithRectPad {
type: "pcb_plated_hole"
shape: "circular_hole_with_rect_pad"
hole_shape: "circle"
pad_shape: "rect"
hole_diameter: number
rect_pad_width: number
rect_pad_height: number
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_plated_hole_id: string
}
```

### PcbPort
Expand Down
19 changes: 18 additions & 1 deletion docs/PCB_COMPONENT_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,24 @@ export interface PcbPlatedHoleOval {
pcb_plated_hole_id: string
}

export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval
export interface PcbHoleCircularWithRectPad {
type: "pcb_plated_hole"
shape: "circular_hole_with_rect_pad"
hole_shape: "circle"
pad_shape: "rect"
hole_diameter: number
rect_pad_width: number
rect_pad_height: number
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_plated_hole_id: string
}

export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval | PcbHoleCircularWithRectPad

export interface PcbFabricationNoteText {
type: "pcb_fabrication_note_text"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "circuit-json",
"version": "0.0.121",
"version": "0.0.123",
"description": "Definitions for the tscircuit intermediary JSON format",
"main": "dist/index.mjs",
"files": [
Expand Down
1 change: 1 addition & 0 deletions src/any_circuit_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const any_circuit_element = z.union([
src.source_simple_inductor,
src.source_simple_pin_header,
src.source_simple_resonator,
src.source_simple_transistor,
src.source_simple_potentiometer,
src.source_simple_push_button,
pcb.pcb_component,
Expand Down
45 changes: 43 additions & 2 deletions src/pcb/pcb_plated_hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,58 @@ export interface PcbPlatedHoleOval {
pcb_plated_hole_id: string
}

const pcb_circular_hole_with_rect_pad = z.object({
type: z.literal("pcb_plated_hole"),
shape: z.literal("circular_hole_with_rect_pad"),
hole_shape: z.literal("circle"),
pad_shape: z.literal("rect"),
hole_diameter: z.number(),
rect_pad_width: z.number(),
rect_pad_height: z.number(),
x: distance,
y: distance,
layers: z.array(layer_ref),
port_hints: z.array(z.string()).optional(),
pcb_component_id: z.string().optional(),
pcb_port_id: z.string().optional(),
pcb_plated_hole_id: getZodPrefixedIdWithDefault("pcb_plated_hole"),
})

export interface PcbHoleCircularWithRectPad {
type: "pcb_plated_hole"
shape: "circular_hole_with_rect_pad"
hole_shape: "circle"
pad_shape: "rect"
hole_diameter: number
rect_pad_width: number
rect_pad_height: number
x: Distance
y: Distance
layers: LayerRef[]
port_hints?: string[]
pcb_component_id?: string
pcb_port_id?: string
pcb_plated_hole_id: string
}

export const pcb_plated_hole = z.union([
pcb_plated_hole_circle,
pcb_plated_hole_oval,
pcb_circular_hole_with_rect_pad,
])
export type PcbPlatedHole = PcbPlatedHoleCircle | PcbPlatedHoleOval
export type PcbPlatedHole =
| PcbPlatedHoleCircle
| PcbPlatedHoleOval
| PcbHoleCircularWithRectPad

expectTypesMatch<PcbPlatedHoleCircle, z.infer<typeof pcb_plated_hole_circle>>(
true,
)
expectTypesMatch<PcbPlatedHoleOval, z.infer<typeof pcb_plated_hole_oval>>(true)

expectTypesMatch<
PcbHoleCircularWithRectPad,
z.infer<typeof pcb_circular_hole_with_rect_pad>
>(true)
/**
* @deprecated use PcbPlatedHole
*/
Expand Down
2 changes: 2 additions & 0 deletions src/source/any_source_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { source_simple_potentiometer } from "./source_simple_potentiometer"
import { source_simple_crystal } from "./source_simple_crystal"
import { source_simple_pin_header } from "./source_simple_pin_header"
import { source_simple_resonator } from "./source_simple_resonator"
import { source_simple_transistor } from "./source_simple_transistor"

export const any_source_component = z.union([
source_simple_resistor,
Expand All @@ -31,6 +32,7 @@ export const any_source_component = z.union([
source_simple_crystal,
source_simple_pin_header,
source_simple_resonator,
source_simple_transistor,
])

export type AnySourceComponent = z.infer<typeof any_source_component>
1 change: 1 addition & 0 deletions src/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from "./source_simple_potentiometer"
export * from "./source_simple_crystal"
export * from "./source_simple_pin_header"
export * from "./source_simple_resonator"
export * from "./source_simple_transistor"
29 changes: 29 additions & 0 deletions src/source/source_simple_transistor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from "zod"
import {
source_component_base,
type SourceComponentBase,
} from "src/source/base/source_component_base"
import { expectTypesMatch } from "src/utils/expect-types-match"

export const source_simple_transistor = source_component_base.extend({
ftype: z.literal("simple_transistor"),
transistor_type: z.enum(["npn", "pnp"]),
})

export type SourceSimpleTransistorInput = z.input<
typeof source_simple_transistor
>
type InferredSourceSimpleTransistor = z.infer<typeof source_simple_transistor>

/**
* Defines a simple transistor component
* This is a three-pin semiconductor device (emitter, base, collector)
* Pin configuration is handled by the schematic port system
*/

export interface SourceSimpleTransistor extends SourceComponentBase {
ftype: "simple_transistor"
transistor_type: "npn" | "pnp"
}

expectTypesMatch<SourceSimpleTransistor, InferredSourceSimpleTransistor>(true)

0 comments on commit c863612

Please sign in to comment.