Skip to content

Commit

Permalink
Fix zone rendering
Browse files Browse the repository at this point in the history
Issue #113
  • Loading branch information
qu1ck committed Oct 16, 2019
1 parent ec985b3 commit 65315f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 7 additions & 2 deletions InteractiveHtmlBom/ecad/kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def parse_zones(self, zones):
if zone.GetLayer() in [pcbnew.F_Cu, pcbnew.B_Cu]:
zone_dict = {
"polygons": self.parse_poly_set(zone.GetFilledPolysList()),
"width": zone.GetMinThickness() * 1e-6,
}
if self.config.include_nets:
zone_dict["net"] = zone.GetNetname()
Expand Down Expand Up @@ -468,8 +469,12 @@ def parse(self):
}
if self.config.include_tracks:
pcbdata["tracks"] = self.parse_tracks(self.board.GetTracks())
pcbdata["zones"] = self.parse_zones(self.board.Zones())
if self.config.include_nets:
if hasattr(self.board, "Zones"):
pcbdata["zones"] = self.parse_zones(self.board.Zones())
else:
self.logger.info("Zones not supported for KiCad 4, skipping")
pcbdata["zones"] = {'F': [], 'B': []}
if self.config.include_nets and hasattr(self.board, "GetNetInfo"):
pcbdata["nets"] = self.parse_netlist(self.board.GetNetInfo())
components = [self.module_to_component(m) for m in pcb_modules]

Expand Down
17 changes: 10 additions & 7 deletions InteractiveHtmlBom/web/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function drawtext(ctx, text, color, flip) {
ctx.fillStyle = color;
ctx.strokeStyle = color;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.lineWidth = text.thickness;
if (text.svgpath) {
ctx.stroke(new Path2D(text.svgpath));
Expand Down Expand Up @@ -74,14 +75,12 @@ function drawtext(ctx, text, color, flip) {
}
for (var c of txt[i]) {
for (var line of pcbdata.font_data[c].l) {
// Drawing each segment separately instead of
// polyline because round line caps don't work in joints
for (var i = 0; i < line.length - 1; i++) {
ctx.beginPath();
ctx.moveTo(...calcFontPoint(line[i], text, offsetx, offsety, tilt));
ctx.lineTo(...calcFontPoint(line[i + 1], text, offsetx, offsety, tilt));
ctx.stroke();
ctx.beginPath();
ctx.moveTo(...calcFontPoint(line[0], text, offsetx, offsety, tilt));
for (var i = 1; i < line.length; i++) {
ctx.lineTo(...calcFontPoint(line[i], text, offsetx, offsety, tilt));
}
ctx.stroke();
}
offsetx += pcbdata.font_data[c].w * text.width;
}
Expand Down Expand Up @@ -344,7 +343,11 @@ function drawTracks(canvas, layer, color) {

function drawZones(canvas, layer, color) {
ctx = canvas.getContext("2d");
ctx.strokeStyle = color;
ctx.lineJoin = "round";
for(var zone of pcbdata.zones[layer]) {
ctx.lineWidth = zone.width;
drawPolygons(ctx, color, zone.polygons, ctx.stroke.bind(ctx));
drawPolygons(ctx, color, zone.polygons, ctx.fill.bind(ctx));
}
}
Expand Down

0 comments on commit 65315f7

Please sign in to comment.