Skip to content

Commit

Permalink
Add tracks support to easyeda
Browse files Browse the repository at this point in the history
  • Loading branch information
qu1ck committed Oct 21, 2019
1 parent 5e4ee16 commit f5678ad
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
21 changes: 20 additions & 1 deletion InteractiveHtmlBom/ecad/easyeda.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ def parse_lib(self, shape):
if len(attr) % 2 != 0:
attr.pop()
attr = {attr[i]: attr[i + 1] for i in range(0, len(attr), 2)}
# TODO: determine layer, reference, value etc.
fp_layer = 'F' if fp_layer == self.TOP_COPPER_LAYER else 'B'
val = '??'
ref = '??'
Expand Down Expand Up @@ -466,4 +465,24 @@ def parse(self):
"font_data": {}
}

if self.config.include_tracks:
def filter_tracks(drawing_list, drawing_type, keys):
result = []
for drawing in drawing_list:
if drawing["type"] == drawing_type:
r = {}
for key in keys:
r[key] = drawing[key]
result.append(r)
return result

pcbdata["tracks"] = {
'F': filter_tracks(drawings.get(self.TOP_COPPER_LAYER, []),
"segment", ["start", "end", "width"]),
'B': filter_tracks(drawings.get(self.BOT_COPPER_LAYER, []),
"segment", ["start", "end", "width"]),
}
# zones are not supported
pcbdata["zones"] = {'F': [], 'B': []}

return pcbdata, components
42 changes: 22 additions & 20 deletions InteractiveHtmlBom/web/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,34 +168,35 @@ function getOblongPath(size) {
return getChamferedRectPath(size, Math.min(size[0], size[1]) / 2, 0, 0);
}

function getPolygonsPath(polygons) {
var combinedPath = new Path2D();
for (var polygon of polygons) {
var path = new Path2D();
for (var vertex of polygon) {
path.lineTo(...vertex)
function getPolygonsPath(shape) {
if (shape.path2d) {
return shape.path2d;
}
if (shape.svgpath) {
shape.path2d = new Path2D(shape.svgpath);
} else {
var combinedPath = new Path2D();
for (var polygon of shape.polygons) {
var path = new Path2D();
for (var vertex of polygon) {
path.lineTo(...vertex)
}
path.closePath();
combinedPath.addPath(path);
}
path.closePath();
combinedPath.addPath(path);
shape.path2d = combinedPath;
}
return combinedPath;
return shape.path2d;
}

function drawPolygonShape(ctx, shape, color) {
ctx.save();
ctx.fillStyle = color;
if (!shape.path2d) {
if (shape.svgpath) {
shape.path2d = new Path2D(shape.svgpath);
} else {
shape.path2d = getPolygonsPath(shape.polygons);
}
}
if (!shape.svgpath) {
ctx.translate(...shape.pos);
ctx.rotate(deg2rad(-shape.angle));
}
ctx.fill(shape.path2d);
ctx.fill(getPolygonsPath(shape));
ctx.restore();
}

Expand Down Expand Up @@ -360,10 +361,10 @@ function drawZones(canvas, layer, color, highlight) {
ctx.lineJoin = "round";
for(var zone of pcbdata.zones[layer]) {
if (!zone.path2d) {
zone.path2d = getPolygonsPath(zone.polygons);
zone.path2d = getPolygonsPath(zone);
}
if (highlight && highlightedNet != zone.net) continue;
ctx.lineWidth = zone.width;
ctx.lineWidth = zone.width ? zone.width : 0;
ctx.fill(zone.path2d);
ctx.stroke(zone.path2d);
}
Expand Down Expand Up @@ -422,12 +423,13 @@ function drawBackground(canvasdict) {
clearCanvas(canvasdict.bg);
clearCanvas(canvasdict.fab);
clearCanvas(canvasdict.silk);
drawEdgeCuts(canvasdict.bg, canvasdict.transform.s);

drawNets(canvasdict.bg, canvasdict.layer, false);
drawModules(canvasdict.bg, canvasdict.layer,
canvasdict.transform.s * canvasdict.transform.zoom, false);

drawEdgeCuts(canvasdict.bg, canvasdict.transform.s);

var style = getComputedStyle(topmostdiv);
var edgeColor = style.getPropertyValue('--silkscreen-edge-color');
var polygonColor = style.getPropertyValue('--silkscreen-polygon-color');
Expand Down

0 comments on commit f5678ad

Please sign in to comment.