app
Component Widgets
Public Made by Adomby adom
Reusable component widgets for pinouts, thermal vias, molecule relationships, reviewed chip outlines and lightweight four-level LOD cache listings.
← Commit history
moleculize: guide the user to the .kicad_pcb when a .kicad_pro/.kicad_sch is dropped (clearer error)
2 files changed
+20−6
files/moleculize-widget.js+10−3@@ -178,15 +178,22 @@ // Read a dropped/selected .kicad_pcb, parse its Edge.Cuts bbox, render the plan. _loadFile(file) { if (!file) return;+ const name = file.name || '';+ const fail = (msg) => { this._err = msg; this._data = null; this._render(); };+ // The board outline lives in the .kicad_pcb, not the sibling files. Point the+ // user at the right one rather than parsing a settings/schematic file.+ if (/\.kicad_pro$/i.test(name)) return fail('That is the KiCad project file (settings, no board outline). Drop the board file ' + name.replace(/\.kicad_pro$/i, '.kicad_pcb') + ' instead.');+ if (/\.kicad_sch$/i.test(name)) return fail('That is the schematic. Drop the PCB layout ' + name.replace(/\.kicad_sch$/i, '.kicad_pcb') + ' instead.');+ if (!/\.kicad_pcb$/i.test(name)) return fail('Drop a .kicad_pcb (the KiCad board layout file), not ' + (name || 'that file') + '.'); const rdr = new FileReader(); rdr.onload = () => { const bb = edgeCutsBBox(String(rdr.result || ''));- if (!bb || !(bb.w > 0) || !(bb.h > 0)) { this._err = 'No Edge.Cuts outline found in ' + file.name; this._data = null; this._render(); return; }+ if (!bb || !(bb.w > 0) || !(bb.h > 0)) return fail('No Edge.Cuts outline found in ' + name + '. Draw the board outline on the Edge.Cuts layer, then drop it again.'); this._err = null;- this._data = { name: file.name.replace(/\.kicad_pcb$/i, ''), width_mm: bb.w, height_mm: bb.h, kicad_pcb: file.name };+ this._data = { name: name.replace(/\.kicad_pcb$/i, ''), width_mm: bb.w, height_mm: bb.h, kicad_pcb: name }; this._render(); };- rdr.onerror = () => { this._err = 'could not read ' + file.name; this._render(); };+ rdr.onerror = () => fail('Could not read ' + name + '.'); rdr.readAsText(file); }
readme.html+10−3@@ -1004,15 +1004,22 @@ h2 .anchor:hover{opacity:1;color:var(--teal)} // Read a dropped/selected .kicad_pcb, parse its Edge.Cuts bbox, render the plan. _loadFile(file) { if (!file) return;+ const name = file.name || '';+ const fail = (msg) => { this._err = msg; this._data = null; this._render(); };+ // The board outline lives in the .kicad_pcb, not the sibling files. Point the+ // user at the right one rather than parsing a settings/schematic file.+ if (/\.kicad_pro$/i.test(name)) return fail('That is the KiCad project file (settings, no board outline). Drop the board file ' + name.replace(/\.kicad_pro$/i, '.kicad_pcb') + ' instead.');+ if (/\.kicad_sch$/i.test(name)) return fail('That is the schematic. Drop the PCB layout ' + name.replace(/\.kicad_sch$/i, '.kicad_pcb') + ' instead.');+ if (!/\.kicad_pcb$/i.test(name)) return fail('Drop a .kicad_pcb (the KiCad board layout file), not ' + (name || 'that file') + '.'); const rdr = new FileReader(); rdr.onload = () => { const bb = edgeCutsBBox(String(rdr.result || ''));- if (!bb || !(bb.w > 0) || !(bb.h > 0)) { this._err = 'No Edge.Cuts outline found in ' + file.name; this._data = null; this._render(); return; }+ if (!bb || !(bb.w > 0) || !(bb.h > 0)) return fail('No Edge.Cuts outline found in ' + name + '. Draw the board outline on the Edge.Cuts layer, then drop it again.'); this._err = null;- this._data = { name: file.name.replace(/\.kicad_pcb$/i, ''), width_mm: bb.w, height_mm: bb.h, kicad_pcb: file.name };+ this._data = { name: name.replace(/\.kicad_pcb$/i, ''), width_mm: bb.w, height_mm: bb.h, kicad_pcb: name }; this._render(); };- rdr.onerror = () => { this._err = 'could not read ' + file.name; this._render(); };+ rdr.onerror = () => fail('Could not read ' + name + '.'); rdr.readAsText(file); }