1 | /* pos.cc |
---|
2 | * Export from Aven as Survex .pos. |
---|
3 | */ |
---|
4 | /* Copyright (C) 2001,2002,2011,2013,2014,2015,2018 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 "pos.h" |
---|
26 | |
---|
27 | #include "export.h" // For LABELS, etc |
---|
28 | |
---|
29 | #include <algorithm> |
---|
30 | #include <stdio.h> |
---|
31 | #include <string.h> |
---|
32 | |
---|
33 | #include "message.h" |
---|
34 | #include "namecompare.h" |
---|
35 | #include "osalloc.h" |
---|
36 | #include "useful.h" |
---|
37 | |
---|
38 | using namespace std; |
---|
39 | |
---|
40 | POS::~POS() |
---|
41 | { |
---|
42 | vector<pos_label*>::const_iterator i; |
---|
43 | for (i = todo.begin(); i != todo.end(); ++i) { |
---|
44 | free(*i); |
---|
45 | } |
---|
46 | todo.clear(); |
---|
47 | } |
---|
48 | |
---|
49 | const int * |
---|
50 | POS::passes() const |
---|
51 | { |
---|
52 | static const int default_passes[] = { LABELS|ENTS|FIXES|EXPORTS, 0 }; |
---|
53 | return default_passes; |
---|
54 | } |
---|
55 | |
---|
56 | void POS::header(const char *, const char *, time_t, |
---|
57 | double, double, double, double, double, double) |
---|
58 | { |
---|
59 | /* TRANSLATORS: Heading line for .pos file. Please try to ensure the “,”s |
---|
60 | * (or at least the columns) are in the same place */ |
---|
61 | fputsnl(msg(/*( Easting, Northing, Altitude )*/195), fh); |
---|
62 | } |
---|
63 | |
---|
64 | void |
---|
65 | POS::label(const img_point *p, const char *s, bool /*fSurface*/, int /*type*/) |
---|
66 | { |
---|
67 | size_t len = strlen(s); |
---|
68 | pos_label * l = (pos_label*)malloc(offsetof(pos_label, name) + len + 1); |
---|
69 | if (l == NULL) |
---|
70 | throw std::bad_alloc(); |
---|
71 | l->x = p->x; |
---|
72 | l->y = p->y; |
---|
73 | l->z = p->z; |
---|
74 | memcpy(l->name, s, len + 1); |
---|
75 | todo.push_back(l); |
---|
76 | } |
---|
77 | |
---|
78 | class pos_label_ptr_cmp { |
---|
79 | char separator; |
---|
80 | |
---|
81 | public: |
---|
82 | explicit pos_label_ptr_cmp(char separator_) : separator(separator_) { } |
---|
83 | |
---|
84 | bool operator()(const POS::pos_label* a, const POS::pos_label* b) { |
---|
85 | return name_cmp(a->name, b->name, separator) < 0; |
---|
86 | } |
---|
87 | }; |
---|
88 | |
---|
89 | void |
---|
90 | POS::footer() |
---|
91 | { |
---|
92 | sort(todo.begin(), todo.end(), pos_label_ptr_cmp(separator)); |
---|
93 | vector<pos_label*>::const_iterator i; |
---|
94 | for (i = todo.begin(); i != todo.end(); ++i) { |
---|
95 | fprintf(fh, "(%8.2f, %8.2f, %8.2f ) %s\n", |
---|
96 | (*i)->x, (*i)->y, (*i)->z, (*i)->name); |
---|
97 | } |
---|
98 | } |
---|