-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
351 lines (231 loc) · 9.48 KB
/
index.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-6KGWXDTF3J"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-6KGWXDTF3J');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Millcrum - Parametric 2.5D GCODE Generator</title>
<link rel="stylesheet" href="inc/screen.css" />
<link rel="stylesheet" href="inc/docco-highlight.min.css" />
<style type="text/css" rel="stylesheet">
a:link, a:active, a:visited {
color: red;
}
a:hover {
color: black;
}
</style>
</head>
<body style="background-color: #ddd;">
<div id="all" style="display: none;">
<canvas id="container" style="background-color: #fff; border-radius: 4px; z-index: 1;"></canvas>
<div id="gcview" style="float: right; border: 1px solid #000; border-radius: 4px;"></div>
<div style="position: fixed; top: 20px; left: 20px; color: #000; font-size: 14px;">2D Millcrum View</div>
<div style="position: fixed; top: 20px; right: 20px; color: #fff; font-size: 14px;">Actual 3D GCODE Toolpath</div>
<div id="drag" draggable="true" style="position: fixed; left: 50px; top: 20px; border-radius: 4px; border: 1px solid #333; width: 680px; background-color: #aaa; padding: 6px; z-index: 2; border-top: 20px solid #333;"> <!-- edit window -->
<div style="float: left; padding: 6px; clear: both;"> <!-- left buttons -->
Import .dxf <input id="openDxf" type="file" /> | <a href="examples/oshw.dxf">Sample DXF</a>
<br />
Import .svg <input id="openSvg" type="file" />
</div> <!-- end left buttons -->
<div style="float: left; padding: 6px;"> <!-- left buttons -->
Open .millcrum <input id="openMillcrum" type="file" /> | <a href="#" id="saveMillcrum">Save .millcrum file</a>
</div> <!-- end left buttons -->
<pre onfocus="this.parentNode.draggable = false;" onblur="this.parentNode.draggable = true;" contenteditable="true" id="millcrumCode" style="width: 670px; height: 400px; clear: both; background-color: #fff; white-space: pre; overflow: auto;"></pre>
<div style="float: right; text-align: right;"> <!-- bottom right buttons -->
<button id="generate">Generate</button>
<br />
<button style="display: none;" id="saveGcode">Save Gcode</button>
</div> <!-- end bottom right buttons -->
<div style="float: left;"> <!-- bottom left -->
<br />
<a href="#" id="examplesLink">Examples</a> <a href="about.html" target="_blank">About Millcrum</a>
</div> <!-- end bottom left -->
</div> <!-- end edit window -->
<div id="examples" style="display: none; top: 50px; left: 50px; position: absolute; width: 200px; height: 200px; overflow: auto; z-index: 3; border: 2px solid blue; background-color: #fff; border-radius: 4px; padding: 10px;">
<a href="#" id="closeExamples" style="float: right;">X</a>
<br style="clear: both;" />
<a href="#" class="example" id="all_objects.millcrum">All Objects</a>
<br />
<a href="#" class="example" id="pegboard.millcrum">Pegboard</a>
<br />
<a href="#" class="example" id="prusa_frame.millcrum">Prusa Frame</a>
<br />
<a href="#" class="example" id="vesa_plate.millcrum">Vesa Plate</a>
<br />
<a href="#" class="example" id="random_cubic_bezier.millcrum">Random Cubic Bezier</a>
</div>
<div id="pathInfo" style="display: none; position: absolute; left: 50px; top: 20px; border-radius: 4px; border: 1px solid blue; width: 200px; background-color: white; padding: 6px; z-index: 3;">
<h4 style="float: left; margin-bottom: 0px; margin-top: 0px; color: #d2691e;">Path Info:</h4>
<a href="#" id="closePathInfo" style="float: right;">X</a>
<br style="clear: both;" />
<span id="pathInfoText" style="white-space: pre-wrap; font-family: monospace;"></span>
</div>
<div id="alert" style="display: none; position: absolute; left: 50px; top: 20px; border-radius: 4px; border: 1px solid red; width: 400px; background-color: rgba(255,77,77,0.4); padding: 6px; z-index: 3; overflow: auto; height: 250px;">
<a href="#" id="closeAlert" style="float: right; font-weight: bold; font-size: 32px; color: #333; text-decoration: none;">X</a>
<br style="clear: both;" />
<span id="alertText" style="white-space: pre-wrap; font-family: monospace;"></span>
</div>
</div>
<script>
// load files
var load_files = function(files, progress_callback) {
// loads each file in files into a URL object that is in memory and calls fulfillment
// or calls rejection if the files did not all load
// track progress
var total = 0;
var loaded = 0;
var last_progress_update = performance.now();
var update_progress = function() {
last_progress_update = performance.now();
if (typeof(progress_callback) === 'function') {
progress_callback(loaded, total);
}
}
var promise = new Promise(function(result, reject) {
for (var l in files) {
if (files[l].type === 'module') {
// import() does not return a byte size
total++;
import(l).then(function(fulfillment) {
//console.log('load_files()', this.l, 'import() load');
// set the name in the global namespace
window[files[this.l].name] = fulfillment;
// increment loaded
loaded++;
update_progress();
// set loaded to true
files[this.l].loaded = true;
}.bind({l: l}), function(rejection) {
console.log('load_files()', this.l, 'import() rejection', rejection);
}.bind({l: l}));
} else {
// load file with XHR
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
total++;
var bytes_added = 0;
xhr.addEventListener('progress', function(e) {
if (e.lengthComputable === true) {
if (this.bytes_added === 0) {
// the progress of all files includes this files progress at this resolution
total += e.total;
}
// the progress of all files includes this files progress at this resolution
loaded += e.loaded - this.bytes_added;
update_progress();
this.bytes_added = e.loaded;
}
//console.log('load_files()', this.l, 'progress', e.loaded, e.total);
}.bind({xhr: xhr, l: l, bytes_added: bytes_added}));
xhr.addEventListener('load', function(e) {
//console.log('load_files()', this.l, 'xhr load');
// save the Blob object
files[this.l].blob = this.xhr.response;
// make a URL object by default
files[this.l].url = URL.createObjectURL(this.xhr.response);
// increment loaded
loaded++;
update_progress();
// set loaded to true
files[this.l].loaded = true;
}.bind({xhr: xhr, l: l}));
// open async, loads many at once
xhr.open('GET', l, true);
xhr.send();
}
}
var failure_check_interval = setInterval(function() {
if (performance.now() - last_progress_update > 1000 * 10) {
// 10 seconds without an update
clearInterval(failure_check_interval);
reject();
return;
}
var failure = false;
for (var l in files) {
if (files[l].loaded !== true) {
// this file is not finished yet
failure = true;
}
}
if (failure === false) {
// all files loaded
clearInterval(failure_check_interval);
result();
}
}, 100);
});
return promise;
}
var progress_element = document.createElement('div');
progress_element.style.position = 'fixed';
progress_element.style.width = '200px';
progress_element.style.left = 'calc(50% - 100px)';
progress_element.style['text-align'] = 'center';
document.body.appendChild(progress_element);
var progress_callback = function(loaded, total) {
var pct = loaded / total;
progress_element.innerHTML = 'loading: ' + loaded + '/' + total;
if (pct === 1) {
document.body.removeChild(progress_element);
}
}
progress_callback(0, 1);
var loaded_files = {'inc/three.min.js': {type: 'js'}, 'inc/TrackballControls.js': {type: 'js'}, 'inc/GCView.js': {type: 'js'}, 'inc/mc.js': {type: 'js'}, 'inc/dxf.js': {type: 'js'}, 'inc/svg.js': {type: 'js'}, 'inc/highlight.min.js': {type: 'js'}, 'inc/canvas.js': {type: 'js'}, 'inc/init.js': {type: 'js'}};
load_files(loaded_files, progress_callback).then(function(fullfillment) {
//console.log('loaded_files', loaded_files);
// load each in the order required
// files with .type: 'js', 'css' or 'blob' provide a .blob: Blob and a .url: URL
// files with .type: 'module' are loaded with import() and the Window property named .name contains the module
// any Worker() threads can use the files objects to access the existing URL object and not require many requests to the same HTTP source
var order = [];
for (var l in loaded_files) {
order.push(l);
}
var next_script = function(order_index) {
if (order_index === order.length) {
return;
}
var l = order[order_index];
//console.log(order_index, l);
var lf = null;
if (loaded_files[l].type === 'css') {
// loaded css file
lf = document.createElement('link');
lf.rel = 'stylesheet';
lf.href = loaded_files[l].url;
} else if (loaded_files[l].type === 'js') {
// loaded javascript file
lf = document.createElement('script');
lf.src = loaded_files[l].url;
}
if (lf !== null) {
document.body.appendChild(lf);
lf.addEventListener('load', function(e) {
//console.log('load event');
order_index++;
next_script(order_index);
});
} else {
order_index++;
next_script(order_index);
}
}
if (order.length > 0) {
next_script(0);
}
document.getElementById('all').style.display = 'block';
}, function(rejection) {
alert('Network error loading files, reload page.');
console.log('load_files() rejection', loaded_files);
});
</script>
</body>
</html>