1 | /* json.cc |
---|
2 | * Export from Aven as JSON. |
---|
3 | */ |
---|
4 | /* Copyright (C) 2015,2016 Olly Betts |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifdef HAVE_CONFIG_H |
---|
22 | # include <config.h> |
---|
23 | #endif |
---|
24 | |
---|
25 | #include "json.h" |
---|
26 | |
---|
27 | #include "export.h" |
---|
28 | |
---|
29 | #include <stdio.h> |
---|
30 | |
---|
31 | using namespace std; |
---|
32 | |
---|
33 | const int * |
---|
34 | JSON::passes() const |
---|
35 | { |
---|
36 | static const int default_passes[] = { LEGS, 0 }; |
---|
37 | return default_passes; |
---|
38 | } |
---|
39 | |
---|
40 | void |
---|
41 | JSON::header(const char * title, const char *, time_t datestamp_numeric, |
---|
42 | double min_x, double min_y, double min_z, |
---|
43 | double max_x, double max_y, double max_z) |
---|
44 | { |
---|
45 | (void)title; |
---|
46 | (void)datestamp_numeric; |
---|
47 | #if 0 |
---|
48 | if (title) { |
---|
49 | fputs("title: \"", fh); |
---|
50 | json_escape(fh, title); |
---|
51 | fputs("\",\n", fh); |
---|
52 | } |
---|
53 | if (datestamp_numeric != time_t(-1)) { |
---|
54 | fprintf("date: %ld,\n", (long)datestamp_numeric); |
---|
55 | } |
---|
56 | #endif |
---|
57 | fprintf(fh, "var p = [%.2f,%.2f,%.2f,%.2f,%.2f,%.2f]\n", |
---|
58 | min_x, min_z, min_y, max_x, max_z, max_y); |
---|
59 | fputs("var groups = [\n", fh); |
---|
60 | } |
---|
61 | |
---|
62 | void |
---|
63 | JSON::line(const img_point *p1, const img_point *p, unsigned /*flags*/, bool fPendingMove) |
---|
64 | { |
---|
65 | if (fPendingMove) { |
---|
66 | if (in_segment) { |
---|
67 | fputs("],\n[", fh); |
---|
68 | } else { |
---|
69 | fputs("[", fh); |
---|
70 | in_segment = true; |
---|
71 | } |
---|
72 | fprintf(fh, "[%.2f,%.2f,%.2f]", p1->x, p1->z, p1->y); |
---|
73 | } |
---|
74 | fprintf(fh, ",[%.2f,%.2f,%.2f]", p->x, p->z, p->y); |
---|
75 | } |
---|
76 | |
---|
77 | void |
---|
78 | JSON::label(const img_point *p, const char *s, bool /*fSurface*/, int type) |
---|
79 | { |
---|
80 | (void)p; |
---|
81 | (void)s; |
---|
82 | (void)type; |
---|
83 | } |
---|
84 | |
---|
85 | void |
---|
86 | JSON::footer() |
---|
87 | { |
---|
88 | if (in_segment) |
---|
89 | fputs("]\n", fh); |
---|
90 | fputs("];\n", fh); |
---|
91 | } |
---|