-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.js
72 lines (63 loc) · 1.86 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//filename and worker
let file = null;
let worker = null;
//go button handler
function handleOnGo(evt)
{
if (file !== null)
{
//params
let arg_g = +document.getElementById('arg_g').value;
let arg_t = +document.getElementById('arg_t').value;
let arg_v = +document.getElementById('arg_v').value;
let arg_s = +document.getElementById('arg_s').value;
let arg_z = +document.getElementById('arg_z').value;
let arg_r = +document.getElementById('arg_r').value;
let arg_q = +document.getElementById('arg_q').value;
let arg_d = +document.getElementById('arg_d').value;
let arg_fr = +document.getElementById('arg_fr').value;
let arg_xr = +document.getElementById('arg_xr').value;
let arg_yr = +document.getElementById('arg_yr').value;
//run pcb solver web worker thread, register output listner
if (worker !== null) worker.terminate();
worker = new Worker('worker.js');
worker.addEventListener('message', function(event)
{
if (event.data.length)
{
//view the pcb output
let scale = +document.getElementById('scale').value;
js_pcb.view_pcb(event.data, scale, 2);
}
}, false);
//post to solver thread
worker.postMessage([js_pcb.dsn2pcb(file, arg_g),
arg_t, arg_v, arg_s, arg_z, arg_r, arg_q, arg_d, arg_fr, arg_xr, arg_yr]);
}
}
//file onload handler
function handleOnLoad(evt)
{
//the onload get a string of the dsn file
file = evt.target.result;
}
//file selection handler
function handleFileSelect(evt)
{
//filelist
let files = evt.target.files;
let f = files[0];
//dsn files only.
if (f.name.match('.*[.]dsn'))
{
//file reader
let reader = new FileReader();
//onload handler
reader.onload = handleOnLoad;
//read the dsn file
reader.readAsText(f);
}
}
//register action handlers
document.getElementById('files').addEventListener('change', handleFileSelect, false);
document.getElementById('go').onclick = handleOnGo;