Skip to content

Commit

Permalink
Add Bezier curve support
Browse files Browse the repository at this point in the history
Fixes #120
  • Loading branch information
qu1ck committed Nov 14, 2019
1 parent d0bd8d5 commit 8587d54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
13 changes: 12 additions & 1 deletion InteractiveHtmlBom/ecad/kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ def normalize(point):
return [point[0] * 1e-6, point[1] * 1e-6]

def parse_draw_segment(self, d):
# type: (pcbnew.DRAWSEGMENT) -> dict | None
shape = {
pcbnew.S_SEGMENT: "segment",
pcbnew.S_CIRCLE: "circle",
pcbnew.S_ARC: "arc",
pcbnew.S_POLYGON: "polygon",
pcbnew.S_CURVE: "curve",
}.get(d.GetShape(), "")
if shape == "":
self.logger.info("Unsupported shape %s, skipping", d.GetShape())
Expand Down Expand Up @@ -93,6 +95,15 @@ def parse_draw_segment(self, d):
"angle": angle,
"polygons": polygons
}
if shape == "curve":
return {
"type": shape,
"start": start,
"cpa": self.normalize(d.GetBezControl1()),
"cpb": self.normalize(d.GetBezControl2()),
"end": end,
"width": d.GetWidth() * 1e-6
}

def parse_poly_set(self, polygon_set):
result = []
Expand Down Expand Up @@ -373,7 +384,7 @@ def parse_tracks(self, tracks):

def parse_zones(self, zones):
result = {pcbnew.F_Cu: [], pcbnew.B_Cu: []}
for zone in zones: # type: (pcbnew.ZONE_CONTAINER)
for zone in zones: # type: pcbnew.ZONE_CONTAINER
if not zone.IsFilled() or zone.GetIsKeepout():
continue
if zone.GetLayer() in [pcbnew.F_Cu, pcbnew.B_Cu]:
Expand Down
38 changes: 19 additions & 19 deletions InteractiveHtmlBom/web/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,32 @@ function drawedge(ctx, scalefactor, edge, color) {
ctx.strokeStyle = color;
ctx.lineWidth = Math.max(1 / scalefactor, edge.width);
ctx.lineCap = "round";
if (edge.type == "segment") {
ctx.beginPath();
ctx.moveTo(...edge.start);
ctx.lineTo(...edge.end);
ctx.stroke();
}
if (edge.type == "arc") {
if (edge.svgpath) {
ctx.stroke(new Path2D(edge.svgpath));
} else {
ctx.beginPath();
if (edge.svgpath) {
ctx.stroke(new Path2D(edge.svgpath));
} else {
if (edge.type == "segment") {
ctx.moveTo(...edge.start);
ctx.lineTo(...edge.end);
}
if (edge.type == "arc") {
ctx.arc(
...edge.start,
edge.radius,
deg2rad(edge.startangle),
deg2rad(edge.endangle));
ctx.stroke();
}
}
if (edge.type == "circle") {
ctx.beginPath();
ctx.arc(
...edge.start,
edge.radius,
0, 2 * Math.PI);
ctx.closePath();
if (edge.type == "circle") {
ctx.arc(
...edge.start,
edge.radius,
0, 2 * Math.PI);
ctx.closePath();
}
if (edge.type == "curve") {
ctx.moveTo(...edge.start);
ctx.bezierCurveTo(...edge.cpa, ...edge.cpb, ...edge.end);
}
ctx.stroke();
}
}
Expand Down

0 comments on commit 8587d54

Please sign in to comment.