forked from nraynaud/webgcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
155 lines (142 loc) · 6.76 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
<!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="zip.js"></script>
<script src="webapp/libs/require.js?v=4"></script>
<script src="webapp/config.js?v=4"></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?v=0.4" type="text/css">
<link rel="stylesheet" href="webapp/threeDView.css?v=0.4" type="text/css">
<script type="text/javascript" src="analyzer/gcodeAnalyser.js?1801221"></script>
<script type="text/javascript" src="analyzer/settings.js?1707260"></script>
<link rel="stylesheet" href="./css/style.css?v=0.4" type="text/css">
</head>
<body>
<h1>GCode Viewer</h1>
<menu>
<span class="view3d" onclick="setview3d()">3D view</span>
<span class="view2d" onclick="setview2d()">2D view</span>
</menu>
<div id="app">
<div id="create-stats">
<p>Filament Usage:</p>
<p id="filament-usage"></p>
</div>
</div>
<script id="demoCode" type="application/gcode"></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 () {
window.app = this;
window.gcdoesim = gcodeSimulation
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) {
window.result = 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>
<script src="./create.js?v=0.5"></script>
</body>
</html>