-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprocess.php
More file actions
63 lines (51 loc) · 2.2 KB
/
process.php
File metadata and controls
63 lines (51 loc) · 2.2 KB
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
<?php
// This file is part of SunCAE.
// SunCAE is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// SunCAE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
$cad_hash = $_GET["cad_hash"];
// assume everything's fine
$response["status"] = "ok";
$response["username"] = $username;
$response["error"] = "";
if (isset($username) == false || $username == "") {
return_error_json("username is empty");
}
$cad_dir = $data_dir . "{$username}/cads/{$cad_hash}";
if (file_exists($cad_dir) === false) {
if (mkdir($cad_dir, $permissions, true) === false) {
return_error_json("cannot mkdir {$cad_dir}");
}
}
if (chdir($cad_dir) === false) {
return_error_json("cannot chdir to {$cad_dir}");
}
// ------------------------------------------------------------
if (file_exists("cad.json") === false) {
exec(sprintf("%s/cadimport.py 2>&1", __DIR__), $output, $error_level);
// TODO: keep output
if ($error_level != 0) {
$error_message = "Error {$error_level} when importing CAD: ";
for ($i = 0; $i < count($output); $i++) {
$error_message .= $output[$i];
}
return_error_json($error_message);
}
}
// ------------------------------------------------------------
if (file_exists("cad.json")) {
$cad = json_decode(file_get_contents("cad.json"), true);
$response["position"] = $cad["position"];
$response["orientation"] = $cad["orientation"];
$response["centerOfRotation"] = $cad["centerOfRotation"];
$response["fieldOfView"] = $cad["fieldOfView"];
} else {
return_error_json("cannot create CAD json");
}
// ------------------------------------------------------------
// leave running the mesher in the background
exec("../../../../cadprocessors/gmsh/initial_mesh.sh > cadmesh.log 2>&1 &");
if ($response["error"] != "") {
return_error_json("CAD {$cad_hash} process failed: {$response["error"]}");
} else {
return_back_json($response);
}