Skip to content

Commit 8587d54

Browse files
committed
Add Bezier curve support
Fixes #120
1 parent d0bd8d5 commit 8587d54

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ def normalize(point):
3939
return [point[0] * 1e-6, point[1] * 1e-6]
4040

4141
def parse_draw_segment(self, d):
42+
# type: (pcbnew.DRAWSEGMENT) -> dict | None
4243
shape = {
4344
pcbnew.S_SEGMENT: "segment",
4445
pcbnew.S_CIRCLE: "circle",
4546
pcbnew.S_ARC: "arc",
4647
pcbnew.S_POLYGON: "polygon",
48+
pcbnew.S_CURVE: "curve",
4749
}.get(d.GetShape(), "")
4850
if shape == "":
4951
self.logger.info("Unsupported shape %s, skipping", d.GetShape())
@@ -93,6 +95,15 @@ def parse_draw_segment(self, d):
9395
"angle": angle,
9496
"polygons": polygons
9597
}
98+
if shape == "curve":
99+
return {
100+
"type": shape,
101+
"start": start,
102+
"cpa": self.normalize(d.GetBezControl1()),
103+
"cpb": self.normalize(d.GetBezControl2()),
104+
"end": end,
105+
"width": d.GetWidth() * 1e-6
106+
}
96107

97108
def parse_poly_set(self, polygon_set):
98109
result = []
@@ -373,7 +384,7 @@ def parse_tracks(self, tracks):
373384

374385
def parse_zones(self, zones):
375386
result = {pcbnew.F_Cu: [], pcbnew.B_Cu: []}
376-
for zone in zones: # type: (pcbnew.ZONE_CONTAINER)
387+
for zone in zones: # type: pcbnew.ZONE_CONTAINER
377388
if not zone.IsFilled() or zone.GetIsKeepout():
378389
continue
379390
if zone.GetLayer() in [pcbnew.F_Cu, pcbnew.B_Cu]:

InteractiveHtmlBom/web/render.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,32 +103,32 @@ function drawedge(ctx, scalefactor, edge, color) {
103103
ctx.strokeStyle = color;
104104
ctx.lineWidth = Math.max(1 / scalefactor, edge.width);
105105
ctx.lineCap = "round";
106-
if (edge.type == "segment") {
107-
ctx.beginPath();
108-
ctx.moveTo(...edge.start);
109-
ctx.lineTo(...edge.end);
110-
ctx.stroke();
111-
}
112-
if (edge.type == "arc") {
106+
if (edge.svgpath) {
107+
ctx.stroke(new Path2D(edge.svgpath));
108+
} else {
113109
ctx.beginPath();
114-
if (edge.svgpath) {
115-
ctx.stroke(new Path2D(edge.svgpath));
116-
} else {
110+
if (edge.type == "segment") {
111+
ctx.moveTo(...edge.start);
112+
ctx.lineTo(...edge.end);
113+
}
114+
if (edge.type == "arc") {
117115
ctx.arc(
118116
...edge.start,
119117
edge.radius,
120118
deg2rad(edge.startangle),
121119
deg2rad(edge.endangle));
122-
ctx.stroke();
123120
}
124-
}
125-
if (edge.type == "circle") {
126-
ctx.beginPath();
127-
ctx.arc(
128-
...edge.start,
129-
edge.radius,
130-
0, 2 * Math.PI);
131-
ctx.closePath();
121+
if (edge.type == "circle") {
122+
ctx.arc(
123+
...edge.start,
124+
edge.radius,
125+
0, 2 * Math.PI);
126+
ctx.closePath();
127+
}
128+
if (edge.type == "curve") {
129+
ctx.moveTo(...edge.start);
130+
ctx.bezierCurveTo(...edge.cpa, ...edge.cpb, ...edge.end);
131+
}
132132
ctx.stroke();
133133
}
134134
}

0 commit comments

Comments
 (0)