@@ -313,12 +313,108 @@ function saveImage(layer) {
313
313
filename += `.${ pcbdata . metadata . revision } ` ;
314
314
}
315
315
filename += `.${ layer } .png` ;
316
- saveFile ( filename , imgdata ) ;
316
+ saveFile ( filename , dataURLtoBlob ( imgdata ) ) ;
317
317
}
318
318
319
- function saveFile ( filename , data ) {
319
+ function saveSettings ( ) {
320
+ var data = {
321
+ type : "InteractiveHtmlBom settings" ,
322
+ version : 1 ,
323
+ pcbmetadata : pcbdata . metadata ,
324
+ settings : settings ,
325
+ }
326
+ var blob = new Blob ( [ JSON . stringify ( data , null , 4 ) ] , { type : "application/json" } ) ;
327
+ saveFile ( `${ pcbdata . metadata . title } .settings.json` , blob ) ;
328
+ }
329
+
330
+ function loadSettings ( ) {
331
+ var input = document . createElement ( "input" ) ;
332
+ input . type = "file" ;
333
+ input . accept = ".settings.json" ;
334
+ input . onchange = function ( e ) {
335
+ var file = e . target . files [ 0 ] ;
336
+ var reader = new FileReader ( ) ;
337
+ reader . onload = readerEvent => {
338
+ var content = readerEvent . target . result ;
339
+ var newSettings ;
340
+ try {
341
+ newSettings = JSON . parse ( content ) ;
342
+ } catch ( e ) {
343
+ alert ( "Selected file is not InteractiveHtmlBom settings file." ) ;
344
+ return ;
345
+ }
346
+ if ( newSettings . type != "InteractiveHtmlBom settings" ) {
347
+ alert ( "Selected file is not InteractiveHtmlBom settings file." ) ;
348
+ return ;
349
+ }
350
+ var metadataMatches = newSettings . hasOwnProperty ( "pcbmetadata" ) ;
351
+ if ( metadataMatches ) {
352
+ for ( var k in pcbdata . metadata ) {
353
+ if ( ! newSettings . pcbmetadata . hasOwnProperty ( k ) || newSettings . pcbmetadata [ k ] != pcbdata . metadata [ k ] ) {
354
+ metadataMatches = false ;
355
+ }
356
+ }
357
+ }
358
+ if ( ! metadataMatches ) {
359
+ var currentMetadata = JSON . stringify ( pcbdata . metadata , null , 4 ) ;
360
+ var fileMetadata = JSON . stringify ( newSettings . pcbmetadata , null , 4 ) ;
361
+ if ( ! confirm (
362
+ `Settins file metadata does not match current metadata.\n\n` +
363
+ `Page metadata:\n${ currentMetadata } \n\n` +
364
+ `Settings file metadata:\n${ fileMetadata } \n\n` +
365
+ `Press OK if you would like to import settings anyway.` ) ) {
366
+ return ;
367
+ }
368
+ }
369
+ overwriteSettings ( newSettings . settings ) ;
370
+ }
371
+ reader . readAsText ( file , 'UTF-8' ) ;
372
+ }
373
+ input . click ( ) ;
374
+ }
375
+
376
+ function overwriteSettings ( newSettings ) {
377
+ initDone = false ;
378
+ settings = newSettings ;
379
+ writeStorage ( "bomlayout" , settings . bomlayout ) ;
380
+ writeStorage ( "canvaslayout" , settings . canvaslayout ) ;
381
+ writeStorage ( "bomCheckboxes" , settings . checkboxes . join ( "," ) ) ;
382
+ document . getElementById ( "bomCheckboxes" ) . value = settings . checkboxes . join ( "," ) ;
383
+ for ( var checkbox of settings . checkboxes ) {
384
+ writeStorage ( "checkbox_" + checkbox , settings . checkboxStoredRefs [ checkbox ] ) ;
385
+ }
386
+ padsVisible ( settings . renderPads ) ;
387
+ document . getElementById ( "padsCheckbox" ) . checked = settings . renderPads ;
388
+ fabricationVisible ( settings . renderFabrication ) ;
389
+ document . getElementById ( "fabricationCheckbox" ) . checked = settings . renderFabrication ;
390
+ silkscreenVisible ( settings . renderSilkscreen ) ;
391
+ document . getElementById ( "silkscreenCheckbox" ) . checked = settings . renderSilkscreen ;
392
+ referencesVisible ( settings . renderReferences ) ;
393
+ document . getElementById ( "referencesCheckbox" ) . checked = settings . renderReferences ;
394
+ valuesVisible ( settings . renderValues ) ;
395
+ document . getElementById ( "valuesCheckbox" ) . checked = settings . renderValues ;
396
+ tracksVisible ( settings . renderTracks ) ;
397
+ document . getElementById ( "tracksCheckbox" ) . checked = settings . renderTracks ;
398
+ zonesVisible ( settings . renderZones ) ;
399
+ document . getElementById ( "zonesCheckbox" ) . checked = settings . renderZones ;
400
+ dnpOutline ( settings . renderDnpOutline ) ;
401
+ document . getElementById ( "dnpOutlineCheckbox" ) . checked = settings . renderDnpOutline ;
402
+ setRedrawOnDrag ( settings . redrawOnDrag ) ;
403
+ document . getElementById ( "dragCheckbox" ) . checked = settings . redrawOnDrag ;
404
+ setDarkMode ( settings . darkMode ) ;
405
+ document . getElementById ( "darkmodeCheckbox" ) . checked = settings . darkMode ;
406
+ setHighlightPin1 ( settings . highlightpin1 ) ;
407
+ document . getElementById ( "highlightpin1Checkbox" ) . checked = settings . highlightpin1 ;
408
+ writeStorage ( "boardRotation" , settings . boardRotation ) ;
409
+ document . getElementById ( "boardRotation" ) . value = settings . boardRotation / 5 ;
410
+ document . getElementById ( "rotationDegree" ) . textContent = settings . boardRotation ;
411
+ initDone = true ;
412
+ prepCheckboxes ( ) ;
413
+ changeBomLayout ( settings . bomlayout ) ;
414
+ }
415
+
416
+ function saveFile ( filename , blob ) {
320
417
var link = document . createElement ( "a" ) ;
321
- var blob = dataURLtoBlob ( data ) ;
322
418
var objurl = URL . createObjectURL ( blob ) ;
323
419
link . download = filename ;
324
420
link . href = objurl ;
0 commit comments