Skip to content

Commit ee81206

Browse files
committed
Configurable net colors
Fixes #373
1 parent af2fad7 commit ee81206

File tree

4 files changed

+93
-12
lines changed

4 files changed

+93
-12
lines changed

InteractiveHtmlBom/web/ibom.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,33 @@ a {
803803
.dark .help-link {
804804
border: 1px solid #00b9fd;
805805
}
806+
807+
.bom-color {
808+
width: 20%;
809+
}
810+
811+
.color-column input {
812+
width: 1.6rem;
813+
height: 1rem;
814+
border: 1px solid black;
815+
cursor: pointer;
816+
padding: 0;
817+
}
818+
819+
/* removes default styling from input color element */
820+
::-webkit-color-swatch {
821+
border: none;
822+
}
823+
824+
::-webkit-color-swatch-wrapper {
825+
padding: 0;
826+
}
827+
828+
::-moz-color-swatch,
829+
::-moz-focus-inner {
830+
border: none;
831+
}
832+
833+
::-moz-focus-inner {
834+
padding: 0;
835+
}

InteractiveHtmlBom/web/ibom.js

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ function setDarkMode(value) {
7171
writeStorage("darkmode", value);
7272
settings.darkMode = value;
7373
redrawIfInitDone();
74+
if (initDone) {
75+
populateBomTable();
76+
}
7477
}
7578

7679
function setShowBOMColumn(field, value) {
@@ -254,6 +257,33 @@ function createRowHighlightHandler(rowid, refs, net) {
254257
}
255258
}
256259

260+
function updateNetColors() {
261+
writeStorage("netColors", JSON.stringify(settings.netColors));
262+
redrawIfInitDone();
263+
}
264+
265+
function netColorChangeHandler(net) {
266+
return (event) => {
267+
settings.netColors[net] = event.target.value;
268+
updateNetColors();
269+
}
270+
}
271+
272+
function netColorRightClick(net) {
273+
return (event) => {
274+
if(event.button == 2) {
275+
event.preventDefault();
276+
event.stopPropagation();
277+
278+
var style = getComputedStyle(topmostdiv);
279+
var defaultNetColor = style.getPropertyValue('--track-color').trim();
280+
event.target.value = defaultNetColor;
281+
delete settings.netColors[net];
282+
updateNetColors();
283+
}
284+
}
285+
}
286+
257287
function entryMatches(entry) {
258288
if (settings.bommode == "netlist") {
259289
// entry is just a net name
@@ -487,12 +517,14 @@ function populateBomHeader(placeHolderColumn = null, placeHolderElements = null)
487517
}
488518
}
489519
if (settings.bommode == "netlist") {
490-
th = createColumnHeader("Net name", "bom-netname", (a, b) => {
520+
tr.appendChild(createColumnHeader("Net name", "bom-netname", (a, b) => {
491521
if (a > b) return -1;
492522
if (a < b) return 1;
493523
return 0;
494-
});
495-
tr.appendChild(th);
524+
}));
525+
tr.appendChild(createColumnHeader("Color", "bom-color", (a, b) => {
526+
return 0;
527+
}));
496528
} else {
497529
// Filter hidden columns
498530
var columns = settings.columnOrder.filter(e => !settings.hiddenColumns.includes(e));
@@ -561,6 +593,8 @@ function populateBomBody(placeholderColumn = null, placeHolderElements = null) {
561593
netsToHandler = {};
562594
currentHighlightedRowId = null;
563595
var first = true;
596+
var style = getComputedStyle(topmostdiv);
597+
var defaultNetColor = style.getPropertyValue('--track-color').trim();
564598
if (settings.bommode == "netlist") {
565599
bomtable = pcbdata.nets.slice();
566600
} else {
@@ -607,6 +641,17 @@ function populateBomBody(placeholderColumn = null, placeHolderElements = null) {
607641
td = document.createElement("TD");
608642
td.innerHTML = highlightFilter(netname ? netname : "&lt;no net&gt;");
609643
tr.appendChild(td);
644+
var color = settings.netColors[netname] || defaultNetColor;
645+
td = document.createElement("TD");
646+
var colorBox = document.createElement("INPUT");
647+
colorBox.type = "color";
648+
colorBox.value = color;
649+
colorBox.onchange = netColorChangeHandler(netname);
650+
colorBox.onmouseup = netColorRightClick(netname);
651+
colorBox.oncontextmenu = (e) => e.preventDefault();
652+
td.appendChild(colorBox);
653+
td.classList.add("color-column");
654+
tr.appendChild(td);
610655
} else {
611656
if (reflookup) {
612657
references = findRefInEntry(bomentry);

InteractiveHtmlBom/web/render.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,12 @@ function drawBgLayer(layername, canvas, layer, scalefactor, edgeColor, polygonCo
412412
}
413413
}
414414

415-
function drawTracks(canvas, layer, color, highlight) {
415+
function drawTracks(canvas, layer, defaultColor, highlight) {
416416
ctx = canvas.getContext("2d");
417-
ctx.strokeStyle = color;
418417
ctx.lineCap = "round";
419418
for (var track of pcbdata.tracks[layer]) {
420419
if (highlight && highlightedNet != track.net) continue;
420+
ctx.strokeStyle = highlight ? defaultColor : settings.netColors[track.net] || defaultColor;
421421
ctx.lineWidth = track.width;
422422
ctx.beginPath();
423423
if ('radius' in track) {
@@ -434,16 +434,16 @@ function drawTracks(canvas, layer, color, highlight) {
434434
}
435435
}
436436

437-
function drawZones(canvas, layer, color, highlight) {
437+
function drawZones(canvas, layer, defaultColor, highlight) {
438438
ctx = canvas.getContext("2d");
439-
ctx.strokeStyle = color;
440-
ctx.fillStyle = color;
441439
ctx.lineJoin = "round";
442440
for (var zone of pcbdata.zones[layer]) {
441+
if (highlight && highlightedNet != zone.net) continue;
442+
ctx.strokeStyle = highlight ? defaultColor : settings.netColors[zone.net] || defaultColor;
443+
ctx.fillStyle = highlight ? defaultColor : settings.netColors[zone.net] || defaultColor;
443444
if (!zone.path2d) {
444445
zone.path2d = getPolygonsPath(zone);
445446
}
446-
if (highlight && highlightedNet != zone.net) continue;
447447
ctx.fill(zone.path2d, zone.fillrule || "nonzero");
448448
if (zone.width > 0) {
449449
ctx.lineWidth = zone.width;

InteractiveHtmlBom/web/util.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ function dataURLtoBlob(dataurl) {
469469
}
470470

471471
var settings = {
472-
canvaslayout: "default",
473-
bomlayout: "default",
472+
canvaslayout: "FB",
473+
bomlayout: "left-right",
474474
bommode: "grouped",
475475
checkboxes: [],
476476
checkboxStoredRefs: {},
@@ -488,7 +488,8 @@ var settings = {
488488
renderTracks: true,
489489
renderZones: true,
490490
columnOrder: [],
491-
hiddenColumns: []
491+
hiddenColumns: [],
492+
netColors: {},
492493
}
493494

494495
function initDefaults() {
@@ -503,6 +504,9 @@ function initDefaults() {
503504
if (settings.bommode === null) {
504505
settings.bommode = "grouped";
505506
}
507+
if (settings.bommode == "netlist" && !pcbdata.nets) {
508+
settings.bommode = "grouped";
509+
}
506510
if (!["grouped", "ungrouped", "netlist"].includes(settings.bommode)) {
507511
settings.bommode = "grouped";
508512
}
@@ -575,6 +579,8 @@ function initDefaults() {
575579
document.getElementById("boardRotation").value = settings.boardRotation / 5;
576580
document.getElementById("rotationDegree").textContent = settings.boardRotation;
577581
initBooleanSetting("offsetBackRotation", config.offset_back_rotation, "offsetBackRotationCheckbox", setOffsetBackRotation);
582+
583+
settings.netColors = JSON.parse(readStorage("netColors")) || {};
578584
}
579585

580586
// Helper classes for user js callbacks.

0 commit comments

Comments
 (0)