Skip to content

Commit 8d7f5bb

Browse files
kichManqu1ck
authored andcommitted
fix ref attribute
restyle parseValue using the correct types fixed forgotten context object fix returned selected bom list fix used only full bom list Flatten the bom table only once for efficiency
1 parent b94e8d9 commit 8d7f5bb

File tree

2 files changed

+61
-53
lines changed

2 files changed

+61
-53
lines changed

InteractiveHtmlBom/web/ibom.js

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,35 @@ function highlightFilter(s) {
362362
return r;
363363
}
364364

365+
function getBomListByLayer(layer) {
366+
switch (layer) {
367+
case 'F': return pcbdata.bom.F.slice();
368+
case 'B': return pcbdata.bom.B.slice();
369+
case 'FB': return pcbdata.bom.both.slice();
370+
}
371+
return [];
372+
}
373+
374+
function getSelectedBomList() {
375+
if (settings.bommode == "netlist") {
376+
return pcbdata.nets.slice();
377+
}
378+
var out = getBomListByLayer(settings.canvaslayout);
379+
380+
if (settings.bommode == "ungrouped") {
381+
// expand bom table
382+
var expandedTable = [];
383+
for (var bomentry of out) {
384+
for (var ref of bomentry) {
385+
expandedTable.push([ref]);
386+
}
387+
}
388+
return expandedTable;
389+
}
390+
391+
return out;
392+
}
393+
365394
function checkboxSetUnsetAllHandler(checkboxname) {
366395
return function () {
367396
var checkboxnum = 0;
@@ -619,31 +648,9 @@ function populateBomBody(placeholderColumn = null, placeHolderElements = null) {
619648
var first = true;
620649
var style = getComputedStyle(topmostdiv);
621650
var defaultNetColor = style.getPropertyValue('--track-color').trim();
622-
if (settings.bommode == "netlist") {
623-
bomtable = pcbdata.nets.slice();
624-
} else {
625-
switch (settings.canvaslayout) {
626-
case 'F':
627-
bomtable = pcbdata.bom.F.slice();
628-
break;
629-
case 'FB':
630-
bomtable = pcbdata.bom.both.slice();
631-
break;
632-
case 'B':
633-
bomtable = pcbdata.bom.B.slice();
634-
break;
635-
}
636-
if (settings.bommode == "ungrouped") {
637-
// expand bom table
638-
expandedTable = []
639-
for (var bomentry of bomtable) {
640-
for (var ref of bomentry) {
641-
expandedTable.push([ref]);
642-
}
643-
}
644-
bomtable = expandedTable;
645-
}
646-
}
651+
652+
bomtable = getSelectedBomList();
653+
647654
if (bomSortFunction) {
648655
bomtable = bomtable.sort(bomSortFunction);
649656
}
@@ -1294,10 +1301,10 @@ function topToggle() {
12941301
}
12951302

12961303
window.onload = function (e) {
1297-
initUtils();
12981304
initRender();
12991305
initStorage();
13001306
initDefaults();
1307+
initUtils();
13011308
cleanGutters();
13021309
populateMetadata();
13031310
dbgdiv = document.getElementById("dbg");

InteractiveHtmlBom/web/util.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ function initUtils() {
206206
if (config.fields.includes("Value")) {
207207
var index = config.fields.indexOf("Value");
208208
pcbdata.bom["parsedValues"] = {};
209+
var allList = getBomListByLayer('FB').flat();
209210
for (var id in pcbdata.bom.fields) {
210-
pcbdata.bom.parsedValues[id] = parseValue(pcbdata.bom.fields[id][index])
211+
var ref_key = allList.find(item => item[1] == Number(id)) || [];
212+
pcbdata.bom.parsedValues[id] = parseValue(pcbdata.bom.fields[id][index], ref_key);
211213
}
212214
}
213215
}
@@ -219,45 +221,44 @@ function parseValue(val, ref) {
219221
if (unit == 'Ω' || unit == "ohm" || unit == "ohms") {
220222
unit = 'r';
221223
}
222-
unit = unit[0];
223-
} else {
224-
ref = /^([a-z]+)\d+$/i.exec(ref);
225-
if (ref) {
226-
ref = ref[1].toLowerCase();
227-
if (ref == "c") unit = 'f';
228-
else if (ref == "l") unit = 'h';
229-
else if (ref == "r" || ref == "rv") unit = 'r';
230-
else unit = null;
231-
}
224+
return unit[0];
232225
}
233-
return unit;
226+
227+
var resarr = /^([a-z]+)\d+$/i.exec(ref);
228+
switch (Array.isArray(resarr) && resarr[1].toLowerCase()) {
229+
case "c": return 'f';
230+
case "l": return 'h';
231+
case "r":
232+
case "rv": return 'r';
233+
}
234+
return null;
234235
};
235236
val = val.replace(/,/g, "");
236237
var match = units.valueRegex.exec(val);
237-
var unit;
238-
if (match) {
239-
val = parseFloat(match[1]);
238+
if (Array.isArray(match)) {
239+
var unit = inferUnit(match[3], ref);
240+
var val_i = parseFloat(match[1]);
241+
if (!unit) return null;
240242
if (match[2]) {
241-
val = val * units.getMultiplier(match[2]);
243+
val_i = val_i * units.getMultiplier(match[2]);
242244
}
243-
unit = inferUnit(match[3], ref);
244-
if (!unit) return null;
245-
else return {
246-
val: val,
245+
return {
246+
val: val_i,
247247
unit: unit,
248248
extra: match[4],
249249
}
250250
}
251+
251252
match = units.valueAltRegex.exec(val);
252-
if (match && (match[1] || match[4])) {
253-
val = parseFloat(match[1] + "." + match[4]);
253+
if (Array.isArray(match) && (match[1] || match[4])) {
254+
var unit = inferUnit(match[2], ref);
255+
var val_i = parseFloat(match[1] + "." + match[4]);
256+
if (!unit) return null;
254257
if (match[3]) {
255-
val = val * units.getMultiplier(match[3]);
258+
val_i = val_i * units.getMultiplier(match[3]);
256259
}
257-
unit = inferUnit(match[2], ref);
258-
if (!unit) return null;
259-
else return {
260-
val: val,
260+
return {
261+
val: val_i,
261262
unit: unit,
262263
extra: match[5],
263264
}

0 commit comments

Comments
 (0)