-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3d-dense-supports-processor.html
92 lines (79 loc) · 3.64 KB
/
s3d-dense-supports-processor.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
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>S3D Dense Support Speed Modifier</title>
</head>
<body>
<div class="container">
<h1>S3D Dense Support Speed Modifier</h1>
<div class="alert alert-primary" role="alert">
<a href="https://www.youtube.com/watch?v=lRjM8IYMKVY" target="_blank">Video Demo</a>
</div>
<form>
<div class="form-group">
<label for="newSpeed">New Speed: </label>
<div class="input-group" style="width: 150px">
<input type="text" id="newSpeed" class="form-control" value="240">
<div class="input-group-append">
<div class="input-group-text">mm/s</div>
</div>
</div>
</div>
<div class="form-group">
<label for="fileinput">Original GCode File: </label>
<div class="custom-file" style="width: 350px; display:block">
<input type="file" class="custom-file-input" id="fileinput" style="border: none" />
<label class="custom-file-label" for="validatedCustomFile">Choose file...</label>
</div>
</div>
<button type="button" id="startOver" class="btn btn-sm btn-secondary">Start Over</button>
</form>
<hr>
Questions? <a href="https://twitter.com/vietphunguyen">@vietphunguyen</a> on Twitter
</div>
<!-- <textarea id="output" placeholder="Output GCODE"></textarea> -->
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/FileSaver.js"></script>
<script>
// Event Listener for when the file input changes
document.getElementById('fileinput').addEventListener('change', processGCodeFile, false);
// Event Listener for when the user clicks on the "Start Over" button
document.getElementById('startOver').addEventListener('click', function(){
document.getElementById('fileinput').value = ''
}, false);
function processGCodeFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
// Load the file
r.onload = function(e) {
var contents = e.target.result
// Split the file up by each feature
var featureSections = contents.split('; feature ')
// Loop through each feature
for(var i in featureSections) {
var newSection = '; feature ' + featureSections[i] // Add back the ; feature line
// Process the GCODE for the dense supports
if(featureSections[i].match(/^dense support/)){
newSection = newSection.replace(/(G1 X\d{1,3}\.\d{3} Y\d{1,3}\.\d{3} E\d{1,3}\.\d{4} F)(\d+)/g, "$1"+document.getElementById('newSpeed').value)
}
// Override the original section with the modified section
featureSections[i] = newSection
}
// Save the file with a modified name
var blob = new Blob([featureSections.join()], {type: "text/plain;charset=utf-8"});
saveAs(blob, f.name.replace(/\.gcode/,'-modded.gcode'));
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
</script>
</body>
</html>