Skip to content

Commit 776cc30

Browse files
authored
Add CAD components section to generated docs (#301)
1 parent 8207ed7 commit 776cc30

File tree

2 files changed

+138
-61
lines changed

2 files changed

+138
-61
lines changed

README.md

Lines changed: 88 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ https://github.com/user-attachments/assets/2f28b7ba-689e-4d80-85b2-5bdef84b41f8
3939
## Table of Contents
4040

4141
<!-- toc:start -->
42-
4342
- [Circuit JSON Specification `circuit-json`](#circuit-json-specification-circuit-json)
44-
4543
- [Things You Can Do With Circuit JSON](#things-you-can-do-with-circuit-json)
4644
- [Typescript Usage](#typescript-usage)
4745

@@ -79,6 +77,8 @@ https://github.com/user-attachments/assets/2f28b7ba-689e-4d80-85b2-5bdef84b41f8
7977
- [SourceSimpleTransistor](#sourcesimpletransistor)
8078
- [SourceTrace](#sourcetrace)
8179
- [SourceTraceNotConnectedError](#sourcetracenotconnectederror)
80+
- [CAD Components](#cad-components)
81+
- [CadComponent](#cadcomponent)
8282
- [PCB Elements](#pcb-elements)
8383
- [PcbAutoroutingError](#pcbautoroutingerror)
8484
- [PcbBoard](#pcbboard)
@@ -214,7 +214,6 @@ There are 3 main element prefixes:
214214
- `schematic_` - e.g. `schematic_component`. Anything required to render the Schematic
215215

216216
<!-- circuit-json-docs:start -->
217-
218217
## Source Components
219218

220219
### SourceComponentBase
@@ -253,13 +252,13 @@ interface SourceFailedToCreateComponentError {
253252
subcircuit_id?: string
254253
parent_source_component_id?: string
255254
pcb_center?: {
256-
x?: number
257-
y?: number
258-
}
255+
x?: number
256+
y?: number
257+
}
259258
schematic_center?: {
260-
x?: number
261-
y?: number
262-
}
259+
x?: number
260+
y?: number
261+
}
263262
}
264263
```
265264

@@ -748,6 +747,36 @@ interface SourceTraceNotConnectedError {
748747
}
749748
```
750749

750+
## CAD Components
751+
752+
### CadComponent
753+
754+
[Source](https://github.com/tscircuit/circuit-json/blob/main/src/cad/cad_component.ts)
755+
756+
```typescript
757+
interface CadComponent {
758+
type: "cad_component"
759+
cad_component_id: string
760+
pcb_component_id: string
761+
source_component_id: string
762+
position: Point3
763+
rotation?: Point3
764+
size?: Point3
765+
layer?: LayerRef
766+
subcircuit_id?: string
767+
footprinter_string?: string
768+
model_obj_url?: string
769+
model_stl_url?: string
770+
model_3mf_url?: string
771+
model_gltf_url?: string
772+
model_glb_url?: string
773+
model_step_url?: string
774+
model_wrl_url?: string
775+
model_unit_to_mm_scale_factor?: number
776+
model_jscad?: any
777+
}
778+
```
779+
751780
## PCB Elements
752781

753782
### PcbAutoroutingError
@@ -839,7 +868,8 @@ interface PcbComponent {
839868
Error emitted when a PCB component is placed outside the board boundaries
840869

841870
```typescript
842-
/** Error emitted when a PCB component is placed outside the board boundaries */ interface PcbComponentOutsideBoardError {
871+
/** Error emitted when a PCB component is placed outside the board boundaries */
872+
interface PcbComponentOutsideBoardError {
843873
type: "pcb_component_outside_board_error"
844874
pcb_component_outside_board_error_id: string
845875
error_type: "pcb_component_outside_board_error"
@@ -848,11 +878,11 @@ Error emitted when a PCB component is placed outside the board boundaries
848878
pcb_board_id: string
849879
component_center: Point
850880
component_bounds: {
851-
min_x: number
852-
max_x: number
853-
min_y: number
854-
max_y: number
855-
}
881+
min_x: number
882+
max_x: number
883+
min_y: number
884+
max_y: number
885+
}
856886
subcircuit_id?: string
857887
source_component_id?: string
858888
}
@@ -941,12 +971,11 @@ interface PcbFabricationNoteText {
941971
text: string
942972
layer: VisibleLayer
943973
anchor_position: Point
944-
anchor_alignment:
945-
| "center"
946-
| "top_left"
947-
| "top_right"
948-
| "bottom_left"
949-
| "bottom_right"
974+
anchor_alignment: | "center"
975+
| "top_left"
976+
| "top_right"
977+
| "bottom_left"
978+
| "bottom_right"
950979
color?: string
951980
}
952981
```
@@ -958,7 +987,8 @@ interface PcbFabricationNoteText {
958987
Error emitted when a pcb footprint overlaps with another element
959988

960989
```typescript
961-
/** Error emitted when a pcb footprint overlaps with another element */ interface PcbFootprintOverlapError {
990+
/** Error emitted when a pcb footprint overlaps with another element */
991+
interface PcbFootprintOverlapError {
962992
type: "pcb_footprint_overlap_error"
963993
pcb_error_id: string
964994
error_type: "pcb_footprint_overlap_error"
@@ -1029,8 +1059,8 @@ interface PcbGroup {
10291059
description?: string
10301060
layout_mode?: string
10311061
autorouter_configuration?: {
1032-
trace_clearance: Length
1033-
}
1062+
trace_clearance: Length
1063+
}
10341064
autorouter_used_string?: string
10351065
}
10361066
```
@@ -1446,11 +1476,11 @@ interface PcbSilkscreenText {
14461476
text: string
14471477
is_knockout?: boolean
14481478
knockout_padding?: {
1449-
left: Length
1450-
top: Length
1451-
bottom: Length
1452-
right: Length
1453-
}
1479+
left: Length
1480+
top: Length
1481+
bottom: Length
1482+
right: Length
1483+
}
14541484
ccw_rotation?: number
14551485
layer: LayerRef
14561486
is_mirrored?: boolean
@@ -1642,7 +1672,8 @@ interface PcbVia {
16421672
Draws a styled arc on the schematic
16431673

16441674
```typescript
1645-
/** Draws a styled arc on the schematic */ interface SchematicArc {
1675+
/** Draws a styled arc on the schematic */
1676+
interface SchematicArc {
16461677
type: "schematic_arc"
16471678
schematic_arc_id: string
16481679
schematic_component_id: string
@@ -1682,7 +1713,8 @@ interface SchematicBox {
16821713
Draws a styled circle on the schematic
16831714

16841715
```typescript
1685-
/** Draws a styled circle on the schematic */ interface SchematicCircle {
1716+
/** Draws a styled circle on the schematic */
1717+
interface SchematicCircle {
16861718
type: "schematic_circle"
16871719
schematic_circle_id: string
16881720
schematic_component_id: string
@@ -1710,13 +1742,13 @@ interface SchematicComponent {
17101742
schematic_component_id: string
17111743
pin_spacing?: number
17121744
pin_styles?: Record<
1713-
string,
1714-
{
1715-
left_margin?: number
1716-
right_margin?: number
1717-
top_margin?: number
1718-
bottom_margin?: number
1719-
}
1745+
string,
1746+
{
1747+
left_margin?: number
1748+
right_margin?: number
1749+
top_margin?: number
1750+
bottom_margin?: number
1751+
}
17201752
>
17211753
box_width?: number
17221754
symbol_name?: string
@@ -1742,9 +1774,9 @@ interface SchematicPortArrangementBySides {
17421774
right_side?: { pins: number[]; direction?: "top-to-bottom" | "bottom-to-top" }
17431775
top_side?: { pins: number[]; direction?: "left-to-right" | "right-to-left" }
17441776
bottom_side?: {
1745-
pins: number[]
1746-
direction?: "left-to-right" | "right-to-left"
1747-
}
1777+
pins: number[]
1778+
direction?: "left-to-right" | "right-to-left"
1779+
}
17481780
}
17491781

17501782
type SchematicPortArrangement =
@@ -1850,7 +1882,8 @@ interface SchematicLayoutError {
18501882
Draws a styled line on the schematic
18511883

18521884
```typescript
1853-
/** Draws a styled line on the schematic */ interface SchematicLine {
1885+
/** Draws a styled line on the schematic */
1886+
interface SchematicLine {
18541887
type: "schematic_line"
18551888
schematic_line_id: string
18561889
schematic_component_id: string
@@ -1902,8 +1935,8 @@ interface SchematicNetLabel {
19021935
text: string
19031936
symbol_name?: string | undefined
19041937
/** When true the net label can be repositioned. When false the label's
1905-
* position is fixed by the element it is attached to. */
1906-
1938+
* position is fixed by the element it is attached to. */
1939+
19071940
is_movable?: boolean
19081941
subcircuit_id?: string
19091942
}
@@ -1955,7 +1988,8 @@ interface SchematicPort {
19551988
Draws a styled rectangle on the schematic
19561989

19571990
```typescript
1958-
/** Draws a styled rectangle on the schematic */ interface SchematicRect {
1991+
/** Draws a styled rectangle on the schematic */
1992+
interface SchematicRect {
19591993
type: "schematic_rect"
19601994
schematic_rect_id: string
19611995
schematic_component_id: string
@@ -2033,9 +2067,9 @@ interface SchematicText {
20332067
text: string
20342068
font_size: number
20352069
position: {
2036-
x: number
2037-
y: number
2038-
}
2070+
x: number
2071+
y: number
2072+
}
20392073
rotation: number
20402074
anchor: NinePointAnchor | FivePointAnchor
20412075
color: string
@@ -2050,13 +2084,13 @@ interface SchematicText {
20502084
```typescript
20512085
interface SchematicTraceEdge {
20522086
from: {
2053-
x: number
2054-
y: number
2055-
}
2087+
x: number
2088+
y: number
2089+
}
20562090
to: {
2057-
x: number
2058-
y: number
2059-
}
2091+
x: number
2092+
y: number
2093+
}
20602094
is_crossing?: boolean
20612095
from_schematic_port_id?: string
20622096
to_schematic_port_id?: string

scripts/generate-readme-docs.ts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ interface ElementDoc {
3939

4040
async function generateDocs() {
4141
const sourceFiles = await glob(
42-
"src/{source,pcb,schematic,simulation}/**/*.ts",
42+
"src/{source,pcb,schematic,simulation,cad}/**/*.ts",
4343
)
4444

4545
const sections = {
4646
source: [] as ElementDoc[],
4747
pcb: [] as ElementDoc[],
48+
cad: [] as ElementDoc[],
4849
schematic: [] as ElementDoc[],
4950
simulation: [] as ElementDoc[],
5051
misc: [] as ElementDoc[],
@@ -57,11 +58,13 @@ async function generateDocs() {
5758
? "source"
5859
: file.includes("\\simulation\\") || file.includes("/simulation/")
5960
? "simulation"
60-
: file.includes("pcb_")
61-
? "pcb"
62-
: file.includes("schematic_")
63-
? "schematic"
64-
: "misc"
61+
: file.includes("\\cad\\") || file.includes("/cad/")
62+
? "cad"
63+
: file.includes("pcb_")
64+
? "pcb"
65+
: file.includes("schematic_")
66+
? "schematic"
67+
: "misc"
6568

6669
const basename = path.basename(file, ".ts")
6770
const primaryName = basename
@@ -117,7 +120,6 @@ async function generateDocs() {
117120
.replace(/\s*=\s*{/g, " {")
118121
.replace(/;\s*$/gm, "")
119122
// Fix spacing around special characters
120-
.replace(/\s*\|\s*/g, " | ")
121123
.replace(/\s*:\s*/g, ": ")
122124
.replace(/\s*,\s*\n/g, ",\n")
123125

@@ -178,6 +180,13 @@ async function generateDocs() {
178180
toc += ` - [${elem.name}](#${elem.name.toLowerCase()})\n`
179181
}
180182

183+
toc += " - [CAD Components](#cad-components)\n"
184+
for (const elem of sections.cad.sort((a, b) =>
185+
a.name.localeCompare(b.name),
186+
)) {
187+
toc += ` - [${elem.name}](#${elem.name.toLowerCase()})\n`
188+
}
189+
181190
toc += " - [PCB Elements](#pcb-elements)\n"
182191
for (const elem of sections.pcb.sort((a, b) =>
183192
a.name.localeCompare(b.name),
@@ -233,6 +242,37 @@ async function generateDocs() {
233242
docs += "\n```\n\n"
234243
}
235244

245+
docs += "## CAD Components\n\n"
246+
for (const elem of sections.cad.sort((a, b) =>
247+
a.name.localeCompare(b.name),
248+
)) {
249+
const sourceFilePath = sourceFiles.find((file) => {
250+
const basename = path.basename(file, ".ts")
251+
const primaryName = basename
252+
.split("_")
253+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
254+
.join("")
255+
return primaryName === elem.name
256+
})
257+
const githubSourceLink = sourceFilePath
258+
? `https://github.com/tscircuit/circuit-json/blob/main/${sourceFilePath}`
259+
: null
260+
261+
docs += `### ${elem.name}\n\n`
262+
if (githubSourceLink) {
263+
docs += `[Source](${githubSourceLink})\n\n`
264+
}
265+
if (elem.description) {
266+
docs += `${elem.description}\n\n`
267+
}
268+
docs += "```typescript\n"
269+
docs += elem.interface
270+
if (elem.otherInterfaces.length > 0) {
271+
docs += `\n\n${elem.otherInterfaces.join("\n\n")}`
272+
}
273+
docs += "\n```\n\n"
274+
}
275+
236276
docs += "## PCB Elements\n\n"
237277
for (const elem of sections.pcb.sort((a, b) =>
238278
a.name.localeCompare(b.name),
@@ -326,6 +366,9 @@ async function generateDocs() {
326366
docs += "\n```\n\n"
327367
}
328368

369+
docs = docs.replace(/\*\/interface/g, "*/\ninterface")
370+
docs = docs.replace(/= \|/g, "=\n |")
371+
329372
const readme = fs.readFileSync("README.md", "utf8")
330373

331374
const tocRegex = /<!-- toc:start -->[\s\S]*?<!-- toc:end -->/

0 commit comments

Comments
 (0)