Skip to content

Commit f5678ad

Browse files
committed
Add tracks support to easyeda
1 parent 5e4ee16 commit f5678ad

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

InteractiveHtmlBom/ecad/easyeda.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ def parse_lib(self, shape):
318318
if len(attr) % 2 != 0:
319319
attr.pop()
320320
attr = {attr[i]: attr[i + 1] for i in range(0, len(attr), 2)}
321-
# TODO: determine layer, reference, value etc.
322321
fp_layer = 'F' if fp_layer == self.TOP_COPPER_LAYER else 'B'
323322
val = '??'
324323
ref = '??'
@@ -466,4 +465,24 @@ def parse(self):
466465
"font_data": {}
467466
}
468467

468+
if self.config.include_tracks:
469+
def filter_tracks(drawing_list, drawing_type, keys):
470+
result = []
471+
for drawing in drawing_list:
472+
if drawing["type"] == drawing_type:
473+
r = {}
474+
for key in keys:
475+
r[key] = drawing[key]
476+
result.append(r)
477+
return result
478+
479+
pcbdata["tracks"] = {
480+
'F': filter_tracks(drawings.get(self.TOP_COPPER_LAYER, []),
481+
"segment", ["start", "end", "width"]),
482+
'B': filter_tracks(drawings.get(self.BOT_COPPER_LAYER, []),
483+
"segment", ["start", "end", "width"]),
484+
}
485+
# zones are not supported
486+
pcbdata["zones"] = {'F': [], 'B': []}
487+
469488
return pcbdata, components

InteractiveHtmlBom/web/render.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,34 +168,35 @@ function getOblongPath(size) {
168168
return getChamferedRectPath(size, Math.min(size[0], size[1]) / 2, 0, 0);
169169
}
170170

171-
function getPolygonsPath(polygons) {
172-
var combinedPath = new Path2D();
173-
for (var polygon of polygons) {
174-
var path = new Path2D();
175-
for (var vertex of polygon) {
176-
path.lineTo(...vertex)
171+
function getPolygonsPath(shape) {
172+
if (shape.path2d) {
173+
return shape.path2d;
174+
}
175+
if (shape.svgpath) {
176+
shape.path2d = new Path2D(shape.svgpath);
177+
} else {
178+
var combinedPath = new Path2D();
179+
for (var polygon of shape.polygons) {
180+
var path = new Path2D();
181+
for (var vertex of polygon) {
182+
path.lineTo(...vertex)
183+
}
184+
path.closePath();
185+
combinedPath.addPath(path);
177186
}
178-
path.closePath();
179-
combinedPath.addPath(path);
187+
shape.path2d = combinedPath;
180188
}
181-
return combinedPath;
189+
return shape.path2d;
182190
}
183191

184192
function drawPolygonShape(ctx, shape, color) {
185193
ctx.save();
186194
ctx.fillStyle = color;
187-
if (!shape.path2d) {
188-
if (shape.svgpath) {
189-
shape.path2d = new Path2D(shape.svgpath);
190-
} else {
191-
shape.path2d = getPolygonsPath(shape.polygons);
192-
}
193-
}
194195
if (!shape.svgpath) {
195196
ctx.translate(...shape.pos);
196197
ctx.rotate(deg2rad(-shape.angle));
197198
}
198-
ctx.fill(shape.path2d);
199+
ctx.fill(getPolygonsPath(shape));
199200
ctx.restore();
200201
}
201202

@@ -360,10 +361,10 @@ function drawZones(canvas, layer, color, highlight) {
360361
ctx.lineJoin = "round";
361362
for(var zone of pcbdata.zones[layer]) {
362363
if (!zone.path2d) {
363-
zone.path2d = getPolygonsPath(zone.polygons);
364+
zone.path2d = getPolygonsPath(zone);
364365
}
365366
if (highlight && highlightedNet != zone.net) continue;
366-
ctx.lineWidth = zone.width;
367+
ctx.lineWidth = zone.width ? zone.width : 0;
367368
ctx.fill(zone.path2d);
368369
ctx.stroke(zone.path2d);
369370
}
@@ -422,12 +423,13 @@ function drawBackground(canvasdict) {
422423
clearCanvas(canvasdict.bg);
423424
clearCanvas(canvasdict.fab);
424425
clearCanvas(canvasdict.silk);
425-
drawEdgeCuts(canvasdict.bg, canvasdict.transform.s);
426426

427427
drawNets(canvasdict.bg, canvasdict.layer, false);
428428
drawModules(canvasdict.bg, canvasdict.layer,
429429
canvasdict.transform.s * canvasdict.transform.zoom, false);
430430

431+
drawEdgeCuts(canvasdict.bg, canvasdict.transform.s);
432+
431433
var style = getComputedStyle(topmostdiv);
432434
var edgeColor = style.getPropertyValue('--silkscreen-edge-color');
433435
var polygonColor = style.getPropertyValue('--silkscreen-polygon-color');

0 commit comments

Comments
 (0)