Skip to content

Commit 6610e68

Browse files
committed
Chamfered pads support
Fixes #83
1 parent dfc6ad6 commit 6610e68

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def get_all_drawings(self):
212212
return drawings
213213

214214
def parse_pad(self, pad):
215+
# type: (pcbnew.D_PAD) -> dict or None
215216
layers_set = list(pad.GetLayerSet().Seq())
216217
layers = []
217218
if pcbnew.F_Cu in layers_set:
@@ -231,6 +232,8 @@ def parse_pad(self, pad):
231232
shape_lookup[pcbnew.PAD_SHAPE_ROUNDRECT] = "roundrect"
232233
if hasattr(pcbnew, "PAD_SHAPE_CUSTOM"):
233234
shape_lookup[pcbnew.PAD_SHAPE_CUSTOM] = "custom"
235+
if hasattr(pcbnew, "PAD_SHAPE_CHAMFERED_RECT"):
236+
shape_lookup[pcbnew.PAD_SHAPE_CHAMFERED_RECT] = "chamfrect"
234237
shape = shape_lookup.get(pad.GetShape(), "")
235238
if shape == "":
236239
self.logger.info("Unsupported pad shape %s, skipping.",
@@ -251,12 +254,15 @@ def parse_pad(self, pad):
251254
self.logger.warn('Detected holes in custom pad polygons')
252255
if polygon_set.IsSelfIntersecting():
253256
self.logger.warn(
254-
'Detected self intersecting polygons in custom pad')
257+
'Detected self intersecting polygons in custom pad')
255258
pad_dict["polygons"] = self.parse_poly_set(polygon_set)
256-
if shape == "roundrect":
259+
if shape in ["roundrect", "chamfrect"]:
257260
pad_dict["radius"] = pad.GetRoundRectCornerRadius() * 1e-6
261+
if shape == "chamfrect":
262+
pad_dict["chamfpos"] = pad.GetChamferPositions()
263+
pad_dict["chamfratio"] = pad.GetChamferRectRatio()
258264
if (pad.GetAttribute() == pcbnew.PAD_ATTRIB_STANDARD or
259-
pad.GetAttribute() == pcbnew.PAD_ATTRIB_HOLE_NOT_PLATED):
265+
pad.GetAttribute() == pcbnew.PAD_ATTRIB_HOLE_NOT_PLATED):
260266
pad_dict["type"] = "th"
261267
pad_dict["drillshape"] = {
262268
pcbnew.PAD_DRILL_SHAPE_CIRCLE: "circle",

InteractiveHtmlBom/web/render.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,50 @@ function drawedge(ctx, scalefactor, edge, color) {
121121
}
122122
}
123123

124-
function drawRoundRect(ctx, color, size, radius, ctxmethod) {
124+
function drawChamferedRect(ctx, color, size, radius, chamfpos, chamfratio, ctxmethod) {
125+
// chamfpos is a bitmask, left = 1, right = 2, bottom left = 4, bottom right = 8
125126
ctx.beginPath();
126127
ctx.strokeStyle = color;
127-
var x = size[0] * -0.5;
128-
var y = size[1] * -0.5;
129128
var width = size[0];
130129
var height = size[1];
130+
var x = width * -0.5;
131+
var y = height * -0.5;
132+
var chamfOffset = Math.min(width, height) * chamfratio;
131133
ctx.moveTo(x, 0);
132-
ctx.arcTo(x, y + height, x + width, y + height, radius);
133-
ctx.arcTo(x + width, y + height, x + width, y, radius);
134-
ctx.arcTo(x + width, y, x, y, radius);
135-
ctx.arcTo(x, y, x, y + height, radius);
134+
if (chamfpos & 4) {
135+
ctx.lineTo(x, y + height - chamfOffset);
136+
ctx.lineTo(x + chamfOffset, y + height);
137+
ctx.lineTo(0, y + height);
138+
} else {
139+
ctx.arcTo(x, y + height, x + width, y + height, radius);
140+
}
141+
if (chamfpos & 8) {
142+
ctx.lineTo(x + width - chamfOffset, y + height);
143+
ctx.lineTo(x + width, y + height - chamfOffset);
144+
ctx.lineTo(x + width, 0);
145+
} else {
146+
ctx.arcTo(x + width, y + height, x + width, y, radius);
147+
}
148+
if (chamfpos & 2) {
149+
ctx.lineTo(x + width, y + chamfOffset);
150+
ctx.lineTo(x + width - chamfOffset, y);
151+
ctx.lineTo(0, y);
152+
} else {
153+
ctx.arcTo(x + width, y, x, y, radius);
154+
}
155+
if (chamfpos & 1) {
156+
ctx.lineTo(x + chamfOffset, y);
157+
ctx.lineTo(x, y + chamfOffset);
158+
ctx.lineTo(x, 0);
159+
} else {
160+
ctx.arcTo(x, y, x, y + height, radius);
161+
}
136162
ctx.closePath();
137163
ctxmethod();
138164
}
139165

140166
function drawOblong(ctx, color, size, ctxmethod) {
141-
drawRoundRect(ctx, color, size, Math.min(size[0], size[1]) / 2, ctxmethod);
167+
drawChamferedRect(ctx, color, size, Math.min(size[0], size[1]) / 2, 0, 0, ctxmethod);
142168
}
143169

144170
function drawPolygons(ctx, color, polygons, ctxmethod) {
@@ -205,7 +231,9 @@ function drawPad(ctx, pad, color, outline, hole) {
205231
} else if (pad.shape == "circle") {
206232
drawCircle(ctx, pad.size[0] / 2, ctxmethod);
207233
} else if (pad.shape == "roundrect") {
208-
drawRoundRect(ctx, color, pad.size, pad.radius, ctxmethod);
234+
drawChamferedRect(ctx, color, pad.size, pad.radius, 0, 0, ctxmethod);
235+
} else if (pad.shape == "chamfrect") {
236+
drawChamferedRect(ctx, color, pad.size, pad.radius, pad.chamfpos, pad.chamfratio, ctxmethod)
209237
} else if (pad.shape == "custom") {
210238
drawPolygons(ctx, color, pad.polygons, ctxmethod);
211239
}

0 commit comments

Comments
 (0)