Skip to content

Commit

Permalink
Chamfered pads support
Browse files Browse the repository at this point in the history
Fixes #83
  • Loading branch information
qu1ck committed Oct 8, 2019
1 parent dfc6ad6 commit 6610e68
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
12 changes: 9 additions & 3 deletions InteractiveHtmlBom/ecad/kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def get_all_drawings(self):
return drawings

def parse_pad(self, pad):
# type: (pcbnew.D_PAD) -> dict or None
layers_set = list(pad.GetLayerSet().Seq())
layers = []
if pcbnew.F_Cu in layers_set:
Expand All @@ -231,6 +232,8 @@ def parse_pad(self, pad):
shape_lookup[pcbnew.PAD_SHAPE_ROUNDRECT] = "roundrect"
if hasattr(pcbnew, "PAD_SHAPE_CUSTOM"):
shape_lookup[pcbnew.PAD_SHAPE_CUSTOM] = "custom"
if hasattr(pcbnew, "PAD_SHAPE_CHAMFERED_RECT"):
shape_lookup[pcbnew.PAD_SHAPE_CHAMFERED_RECT] = "chamfrect"
shape = shape_lookup.get(pad.GetShape(), "")
if shape == "":
self.logger.info("Unsupported pad shape %s, skipping.",
Expand All @@ -251,12 +254,15 @@ def parse_pad(self, pad):
self.logger.warn('Detected holes in custom pad polygons')
if polygon_set.IsSelfIntersecting():
self.logger.warn(
'Detected self intersecting polygons in custom pad')
'Detected self intersecting polygons in custom pad')
pad_dict["polygons"] = self.parse_poly_set(polygon_set)
if shape == "roundrect":
if shape in ["roundrect", "chamfrect"]:
pad_dict["radius"] = pad.GetRoundRectCornerRadius() * 1e-6
if shape == "chamfrect":
pad_dict["chamfpos"] = pad.GetChamferPositions()
pad_dict["chamfratio"] = pad.GetChamferRectRatio()
if (pad.GetAttribute() == pcbnew.PAD_ATTRIB_STANDARD or
pad.GetAttribute() == pcbnew.PAD_ATTRIB_HOLE_NOT_PLATED):
pad.GetAttribute() == pcbnew.PAD_ATTRIB_HOLE_NOT_PLATED):
pad_dict["type"] = "th"
pad_dict["drillshape"] = {
pcbnew.PAD_DRILL_SHAPE_CIRCLE: "circle",
Expand Down
46 changes: 37 additions & 9 deletions InteractiveHtmlBom/web/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,24 +121,50 @@ function drawedge(ctx, scalefactor, edge, color) {
}
}

function drawRoundRect(ctx, color, size, radius, ctxmethod) {
function drawChamferedRect(ctx, color, size, radius, chamfpos, chamfratio, ctxmethod) {
// chamfpos is a bitmask, left = 1, right = 2, bottom left = 4, bottom right = 8
ctx.beginPath();
ctx.strokeStyle = color;
var x = size[0] * -0.5;
var y = size[1] * -0.5;
var width = size[0];
var height = size[1];
var x = width * -0.5;
var y = height * -0.5;
var chamfOffset = Math.min(width, height) * chamfratio;
ctx.moveTo(x, 0);
ctx.arcTo(x, y + height, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x + width, y, radius);
ctx.arcTo(x + width, y, x, y, radius);
ctx.arcTo(x, y, x, y + height, radius);
if (chamfpos & 4) {
ctx.lineTo(x, y + height - chamfOffset);
ctx.lineTo(x + chamfOffset, y + height);
ctx.lineTo(0, y + height);
} else {
ctx.arcTo(x, y + height, x + width, y + height, radius);
}
if (chamfpos & 8) {
ctx.lineTo(x + width - chamfOffset, y + height);
ctx.lineTo(x + width, y + height - chamfOffset);
ctx.lineTo(x + width, 0);
} else {
ctx.arcTo(x + width, y + height, x + width, y, radius);
}
if (chamfpos & 2) {
ctx.lineTo(x + width, y + chamfOffset);
ctx.lineTo(x + width - chamfOffset, y);
ctx.lineTo(0, y);
} else {
ctx.arcTo(x + width, y, x, y, radius);
}
if (chamfpos & 1) {
ctx.lineTo(x + chamfOffset, y);
ctx.lineTo(x, y + chamfOffset);
ctx.lineTo(x, 0);
} else {
ctx.arcTo(x, y, x, y + height, radius);
}
ctx.closePath();
ctxmethod();
}

function drawOblong(ctx, color, size, ctxmethod) {
drawRoundRect(ctx, color, size, Math.min(size[0], size[1]) / 2, ctxmethod);
drawChamferedRect(ctx, color, size, Math.min(size[0], size[1]) / 2, 0, 0, ctxmethod);
}

function drawPolygons(ctx, color, polygons, ctxmethod) {
Expand Down Expand Up @@ -205,7 +231,9 @@ function drawPad(ctx, pad, color, outline, hole) {
} else if (pad.shape == "circle") {
drawCircle(ctx, pad.size[0] / 2, ctxmethod);
} else if (pad.shape == "roundrect") {
drawRoundRect(ctx, color, pad.size, pad.radius, ctxmethod);
drawChamferedRect(ctx, color, pad.size, pad.radius, 0, 0, ctxmethod);
} else if (pad.shape == "chamfrect") {
drawChamferedRect(ctx, color, pad.size, pad.radius, pad.chamfpos, pad.chamfratio, ctxmethod)
} else if (pad.shape == "custom") {
drawPolygons(ctx, color, pad.polygons, ctxmethod);
}
Expand Down

0 comments on commit 6610e68

Please sign in to comment.