forked from nraynaud/webgcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
251 lines (225 loc) · 8.77 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
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="chrome=1"/>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>g-code simulator</title>
<script src="webapp/libs/require.js"></script>
<script src="webapp/config.js"></script>
<script>
requirejs.config({
baseUrl: 'webapp'
});
</script>
<link rel="shortcut icon" href="webapp/images/icon_fraise_48.png"/>
<link rel="stylesheet" href="webapp/twoDView.css" type="text/css">
<link rel="stylesheet" href="webapp/threeDView.css" type="text/css">
<style>
body, html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: absolute;
height: 100%;
width: 100%;
margin: 0;
}
body {
padding-left: 8px;
padding-right: 8px;
}
h1 {
margin-top: 0;
}
.editBlock {
position: relative;
float: left;
width: 39%;
height: 400px;
padding: 1px;
margin: 0;
}
.editBlock pre {
width: 100%;
height: 350px;
margin: 0;
}
.viewContainer {
float: right;
width: 60%;
}
#loader {
display: inline-block;
background-size: 100% 100%;
background-image: url(webapp/images/spinner.svg);
width: 20px;
height: 20px;
}
.boundsTable {
border-collapse: collapse;
}
.boundsTable td {
border: dashed gray 1px;
padding: 3px;
}
.ThreeDView {
border: solid gray 1px;
background: #000;
height: 400px;
position: relative;
}
.TwoDView {
border: solid gray 1px;
background: #000;
height: 400px;
}
#app {
position: relative;
}
</style>
</head>
<body>
<h1>G-Code Q'n'dirty toolpath simulator</h1>
<p>
Paste your g-code in the left-hand window or drop a file on the page and see the preview of your tool path on the right.<br>
The right-hand pane are interactive, drag them to change the point of view.
</p>
<div id="app">
</div>
<script id="demoCode" type="application/gcode">G0 Y10 Z-5
G1 Z-10
G1 Y20
G02 X10 Y30 R10
G1 X30
G2 X40 Y20 R10
G1 Y10
G2 X30 Y0 R10
G1 X10
G2 X0 Y10 Z-15 R10 (yeah spiral !)
G3 X-10 Y20 R-10 (yeah, long arc !)
G3 X0 Y10 I10 (center)
G91 G1 X10 Z10
G3 Y10 R5 Z3 (circle in incremental)
Y10 R5 Z3 (again, testing modal state)
G20 G0 X1 (one inch to the right)
G3 X-1 R1 (radius in inches)
G3 X1 Z0.3 I0.5 J0.5 (I,J in inches)
G21 (back to mm)
G80 X10 (do nothing)
G90
G0 X30 Y30 Z30
G18 (X-Z plane)
G3 Z40 I0 K5
G19 (Y-Z plane)
G3 Z50 J0 K5
G17 (back to X-Y plane)
</script>
<script>
require(['Ember', 'cnc/ui/graphicView', 'cnc/cam/cam', 'cnc/util', 'cnc/ui/gcodeEditor', 'cnc/gcode/gcodeSimulation', 'templates'],
function (Ember, GraphicView, cam, util, gcodeEditor, gcodeSimulation) {
var demoCode = $('#demoCode').text();
Ember.Handlebars.helper('num', function (value) {
return new Handlebars.SafeString(Handlebars.Utils.escapeExpression(util.formatCoord(value)));
});
Ember.TEMPLATES['application'] = Ember.TEMPLATES['camApp'];
window.Simulator = Ember.Application.create({
rootElement: '#app'
});
Simulator.GcodeEditorComponent = gcodeEditor.GcodeEditorComponent;
Simulator.GraphicView = GraphicView;
Simulator.ApplicationController = Ember.ObjectController.extend({
init: function () {
this._super();
var _this = this;
$(window).on('dragover', function (event) {
event.preventDefault();
event.dataTransfer.dropEffect = 'move';
});
$(window).on('drop', function (evt) {
evt.preventDefault();
evt.stopPropagation();
var files = evt.dataTransfer.files;
var file = files[0];
var reader = new FileReader();
reader.onload = function (e) {
_this.set('code', e.target.result);
_this.launchSimulation();
};
reader.readAsText(file);
});
this.launchSimulation();
},
actions: {
simulate: function () {
this.launchSimulation();
},
loadBigSample: function () {
this.set('computing', true);
var _this = this;
require(['text!samples/aztec_calendar.ngc'], function (text) {
_this.set('code', text);
_this.launchSimulation();
});
}
},
launchSimulation: function () {
var _this = this;
function handleResult(result) {
_this.flushFragmentFile();
var errors = [];
for (var i = 0; i < result.errors.length; i++) {
var error = result.errors[i];
errors.push({row: error.lineNo, text: error.message, type: "error"});
}
_this.set('errors', errors);
_this.set('bbox', {min: result.min, max: result.max});
_this.set('totalTime', result.totalTime);
_this.set('lineSegmentMap', result.lineSegmentMap);
_this.set('computing', false);
console.timeEnd('simulation');
}
console.time('simulation');
this.set('computing', true);
_this.set('lineSegmentMap', []);
this.get('simulatedPath').clear();
gcodeSimulation.parseInWorker(this.get('code'), new util.Point(0, 0, 0),
Ember.run.bind(_this, handleResult),
Ember.run.bind(_this, function (fragment) {
_this.get('fragmentFile').pushObject(fragment);
Ember.run.throttle(_this, _this.flushFragmentFile, 500);
}));
},
flushFragmentFile: function () {
this.get('simulatedPath').pushObjects(this.get('fragmentFile'));
this.get('fragmentFile').clear();
},
formattedTotalTime: function () {
var totalTime = this.get('totalTime');
var humanized = util.humanizeDuration(totalTime);
return {humanized: humanized, detailed: Math.round(totalTime) + 's'};
}.property('totalTime'),
currentHighLight: function () {
return this.get('lineSegmentMap')[this.get('currentRow')];
}.property('currentRow', 'lineSegmentMap').readOnly(),
code: demoCode,
errors: [],
bbox: {},
totalTime: 0,
lineSegmentMap: [],
currentRow: null,
simulatedPath: [],
computing: false,
fragmentFile: [],
canSelectLanguage: false,
usingGcode: true,
decorations: []
});
});
</script>
<a href="https://github.com/nraynaud/webgcode/"><img
style="position: absolute; top: 0; right: 0; border: 0;"
src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png"></a>
</body>
</html>