Skip to content

Commit 694436e

Browse files
authored
add: render the circle in schematic (#176)
* add: kicad8 circle support in schematic * add: simple test for circle drawings
1 parent df8a735 commit 694436e

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

src/kc-ui/icon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class KCUIIconElement extends KCUIElement {
4646
const text = this.textContent ?? "";
4747
if (text.startsWith("svg:")) {
4848
const name = text.slice(4);
49+
// TODO: 404 error?
4950
const url = `${KCUIIconElement.sprites_url}#${name}`;
5051
return html`<svg viewBox="0 0 48 48" width="48">
5152
<use xlink:href="${url}" />

src/kicad/schematic.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ export const DefaultValues = {
5656
pin_name_offset: 0.508, // 20 mils
5757
};
5858

59+
export type SchematicDrawing = Polyline | Text | Circle | Image;
60+
5961
export class KicadSch {
6062
project?: Project;
6163
version: number;
@@ -75,7 +77,7 @@ export class KicadSch {
7577
hierarchical_labels: HierarchicalLabel[] = [];
7678
symbols = new Map<string, SchematicSymbol>();
7779
no_connects: NoConnect[] = [];
78-
drawings: (Polyline | Text)[] = [];
80+
drawings: SchematicDrawing[] = [];
7981
images: Image[] = [];
8082
sheet_instances?: SheetInstances;
8183
symbol_instances?: SymbolInstances;
@@ -116,7 +118,6 @@ export class KicadSch {
116118
"hierarchical_label",
117119
T.item(HierarchicalLabel, this),
118120
),
119-
// images
120121
P.mapped_collection(
121122
"symbols",
122123
"symbol",
@@ -127,6 +128,7 @@ export class KicadSch {
127128
P.collection("drawings", "rectangle", T.item(Rectangle, this)),
128129
P.collection("drawings", "arc", T.item(Arc, this)),
129130
P.collection("drawings", "text", T.item(Text, this)),
131+
P.collection("drawings", "circle", T.item(Circle, this)),
130132
P.collection("images", "image", T.item(Image)),
131133
P.item("sheet_instances", SheetInstances),
132134
P.item("symbol_instances", SymbolInstances),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(kicad_sch
2+
(version 20250114)
3+
(generator "eeschema")
4+
(generator_version "9.0")
5+
(uuid "5efcc5ba-dc52-4033-83ee-2f99ed02f6eb")
6+
(paper "A4")
7+
(lib_symbols)
8+
(circle
9+
(center 0 0)
10+
(radius 5.08)
11+
(stroke
12+
(width 0.25)
13+
(type solid)
14+
)
15+
(fill
16+
(type none)
17+
)
18+
(uuid 1281e40f-f1db-465e-8de5-84a912042e35)
19+
)
20+
(sheet_instances
21+
(path "/"
22+
(page "1")
23+
)
24+
)
25+
(embedded_fonts no)
26+
)

test/kicad/schematic.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import paper_sch_src from "./files/paper.kicad_sch";
1313
import wires_sch_src from "./files/wires.kicad_sch";
1414
import labels_sch_src from "./files/labels.kicad_sch";
1515
import drawings_sch_src from "./files/drawings.kicad_sch";
16+
import drawings_kicad9_sch_src from "./files/drawings_kicad9.kicad_sch";
1617
import symbols_sch_src from "./files/symbols.kicad_sch";
1718
import symbols_kicad8_sch_src from "./files/symbols_kicad8.kicad_sch";
1819

@@ -314,6 +315,25 @@ suite("kicad.schematic.KicadSch(): schematic parsing", function () {
314315
assert.equal(sch.images.length, 1);
315316
});
316317

318+
test("with kicad9 drawings", function () {
319+
const sch = new schematic.KicadSch(
320+
"test.kicad_sch",
321+
drawings_kicad9_sch_src,
322+
);
323+
324+
assert.equal(sch.drawings.length, 1);
325+
326+
const circle1 = sch.drawings[0] as schematic.Circle;
327+
assert_deep_partial(circle1, {
328+
center: { x: 0, y: 0 },
329+
radius: 5.08,
330+
stroke: {
331+
width: 0.25,
332+
type: "solid",
333+
},
334+
});
335+
});
336+
317337
test("with library symbols", function () {
318338
const sch = new schematic.KicadSch("test.kicad_sch", symbols_sch_src);
319339

0 commit comments

Comments
 (0)