-
Notifications
You must be signed in to change notification settings - Fork 10
/
process.php
67 lines (59 loc) · 2.17 KB
/
process.php
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
<?php
$debug = isset($_GET['debug']) ? filter_var($_GET['debug'] ,FILTER_VALIDATE_BOOLEAN) : false;
$lookahead = 10; //
$pos_error = 0.1; // absolute
$alignment_error = 0.01; // absolute
$extrusion_error = 0.15; // percent
$outFile = './output.gcode';
include "GCodeArcOptimiser.php";
$inputGcode = null;
$errorFiles = array();
if (!empty($_FILES) && !empty($_FILES['upload'])) {
if($_FILES['upload']['error'] !== 0){
die("Error with file.");
} else {
if (!is_uploaded_file($_FILES['upload']['tmp_name'])) {
die("Could not read file.");
} else {
$inputGcode = file_get_contents($_FILES['upload']['tmp_name']);
$gcode = explode("\n", $inputGcode);
$gcode = SplFixedArray::fromArray($gcode);
}
}
} else if(isset($_POST['file']) || isset($_GET['file'])) {
$input = isset($_POST['file']) ? $_POST['file'] : $_GET['file'];
$gcode = $inputGcode = file_get_contents($input);
}
$optimiser = new GCodeArcOptimiser(
$lookahead,
$pos_error,
$alignment_error,
$extrusion_error,
$debug
);
$output = $optimiser->process($gcode);
file_put_contents($outFile, $output);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
echo "<pre>";
print_r([
'time' => $output['time'],
'timings_granular' => $optimiser->getTimingsFormatted(),
'total_replacements' => $output['total_replacements'],
'input_lines' => $output['input_lines'],
'output_lines' => $output['output_lines'],
// 'optimised' => $output['gcode'],
// 'original' => $inputGcode,
]);
echo "</pre>";
} else {
header('Content-Type: application/json');
echo json_encode([
'time' => $output['time'],
'timings_granular' => $optimiser->getTimingsFormatted(),
'total_replacements' => $output['total_replacements'],
'input_lines' => $output['input_lines'],
'output_lines' => $output['output_lines'],
'optimised' => $output['gcode'],
'original' => $inputGcode,
]);
}