Merge updated source references, etc to po files
[survex.git] / src / pos.cc
blobf0c21a2f6285cee39573a5683a91ce2efd050b75
1 /* pos.cc
2 * Export from Aven as Survex .pos.
3 */
4 /* Copyright (C) 2001,2002,2011,2013,2014,2015 Olly Betts
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.
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.
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
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include "pos.h"
27 #include "export.h" // For LABELS, etc
29 #include <algorithm>
30 #include <stdio.h>
31 #include <string.h>
33 #include "message.h"
34 #include "namecompare.h"
35 #include "osalloc.h"
36 #include "useful.h"
38 using namespace std;
40 POS::~POS()
42 vector<pos_label*>::const_iterator i;
43 for (i = todo.begin(); i != todo.end(); ++i) {
44 delete [] *i;
46 todo.clear();
49 const int *
50 POS::passes() const
52 static const int default_passes[] = { LABELS|ENTS|FIXES|EXPORTS, 0 };
53 return default_passes;
56 void POS::header(const char *, const char *, time_t,
57 double, double, double, double, double, double)
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);
64 void
65 POS::label(const img_point *p, const char *s, bool /*fSurface*/, int /*type*/)
67 size_t len = strlen(s);
68 pos_label * l = (pos_label*)new char[offsetof(pos_label, name) + len + 1];
69 l->x = p->x;
70 l->y = p->y;
71 l->z = p->z;
72 memcpy(l->name, s, len + 1);
73 todo.push_back(l);
76 class pos_label_ptr_cmp {
77 char separator;
79 public:
80 explicit pos_label_ptr_cmp(char separator_) : separator(separator_) { }
82 bool operator()(const POS::pos_label* a, const POS::pos_label* b) {
83 return name_cmp(a->name, b->name, separator) < 0;
87 void
88 POS::footer()
90 sort(todo.begin(), todo.end(), pos_label_ptr_cmp(separator));
91 vector<pos_label*>::const_iterator i;
92 for (i = todo.begin(); i != todo.end(); ++i) {
93 fprintf(fh, "(%8.2f, %8.2f, %8.2f ) %s\n",
94 (*i)->x, (*i)->y, (*i)->z, (*i)->name);