1 | // |
---|
2 | // mainfrm.cc |
---|
3 | // |
---|
4 | // Main frame handling for Aven. |
---|
5 | // |
---|
6 | // Copyright (C) 2000-2002,2005,2006 Mark R. Shinwell |
---|
7 | // Copyright (C) 2001-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015 Olly Betts |
---|
8 | // Copyright (C) 2005 Martin Green |
---|
9 | // |
---|
10 | // This program is free software; you can redistribute it and/or modify |
---|
11 | // it under the terms of the GNU General Public License as published by |
---|
12 | // the Free Software Foundation; either version 2 of the License, or |
---|
13 | // (at your option) any later version. |
---|
14 | // |
---|
15 | // This program is distributed in the hope that it will be useful, |
---|
16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | // GNU General Public License for more details. |
---|
19 | // |
---|
20 | // You should have received a copy of the GNU General Public License |
---|
21 | // along with this program; if not, write to the Free Software |
---|
22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | // |
---|
24 | |
---|
25 | #ifdef HAVE_CONFIG_H |
---|
26 | #include <config.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #include "cavernlog.h" |
---|
30 | #include "mainfrm.h" |
---|
31 | #include "aven.h" |
---|
32 | #include "aboutdlg.h" |
---|
33 | |
---|
34 | #include "message.h" |
---|
35 | #include "img_hosted.h" |
---|
36 | #include "namecompare.h" |
---|
37 | #include "printwx.h" |
---|
38 | #include "filename.h" |
---|
39 | #include "useful.h" |
---|
40 | |
---|
41 | #include <wx/confbase.h> |
---|
42 | #include <wx/filename.h> |
---|
43 | #include <wx/image.h> |
---|
44 | #include <wx/imaglist.h> |
---|
45 | #include <wx/process.h> |
---|
46 | #include <wx/regex.h> |
---|
47 | |
---|
48 | #include <cstdlib> |
---|
49 | #include <float.h> |
---|
50 | #include <functional> |
---|
51 | #include <map> |
---|
52 | #include <stack> |
---|
53 | #include <vector> |
---|
54 | |
---|
55 | #ifdef __WXMSW__ |
---|
56 | #define TOOL(x) wxBitmap(wxT(#x), wxBITMAP_TYPE_PNG_RESOURCE) |
---|
57 | #else |
---|
58 | // XPM files declare the array as static, but we also want it to be const too. |
---|
59 | // This avoids a compiler warning, and also means the data can go in a |
---|
60 | // read-only page and be shared between processes. |
---|
61 | #define static static const |
---|
62 | #include "../lib/icons/aven.xpm" |
---|
63 | #include "../lib/icons/log.xpm" |
---|
64 | #include "../lib/icons/open.xpm" |
---|
65 | #include "../lib/icons/open_pres.xpm" |
---|
66 | #include "../lib/icons/rotation.xpm" |
---|
67 | #include "../lib/icons/plan.xpm" |
---|
68 | #include "../lib/icons/elevation.xpm" |
---|
69 | #include "../lib/icons/defaults.xpm" |
---|
70 | #include "../lib/icons/names.xpm" |
---|
71 | #include "../lib/icons/crosses.xpm" |
---|
72 | #include "../lib/icons/entrances.xpm" |
---|
73 | #include "../lib/icons/fixed_pts.xpm" |
---|
74 | #include "../lib/icons/exported_pts.xpm" |
---|
75 | #include "../lib/icons/ug_legs.xpm" |
---|
76 | #include "../lib/icons/surface_legs.xpm" |
---|
77 | #include "../lib/icons/tubes.xpm" |
---|
78 | #include "../lib/icons/pres_frew.xpm" |
---|
79 | #include "../lib/icons/pres_rew.xpm" |
---|
80 | #include "../lib/icons/pres_go_back.xpm" |
---|
81 | #include "../lib/icons/pres_pause.xpm" |
---|
82 | #include "../lib/icons/pres_go.xpm" |
---|
83 | #include "../lib/icons/pres_ff.xpm" |
---|
84 | #include "../lib/icons/pres_fff.xpm" |
---|
85 | #include "../lib/icons/pres_stop.xpm" |
---|
86 | #include "../lib/icons/find.xpm" |
---|
87 | #include "../lib/icons/hideresults.xpm" |
---|
88 | #include "../lib/icons/survey_tree.xpm" |
---|
89 | #include "../lib/icons/pres_tree.xpm" |
---|
90 | #undef static |
---|
91 | #define TOOL(x) wxBITMAP(x) |
---|
92 | #endif |
---|
93 | |
---|
94 | using namespace std; |
---|
95 | |
---|
96 | const static int img2aven_tab[] = { |
---|
97 | #include "img2aven.h" |
---|
98 | }; |
---|
99 | |
---|
100 | inline int |
---|
101 | img2aven(int flags) |
---|
102 | { |
---|
103 | flags &= (sizeof(img2aven_tab) / sizeof(img2aven_tab[0]) - 1); |
---|
104 | return img2aven_tab[flags]; |
---|
105 | } |
---|
106 | |
---|
107 | class AvenSplitterWindow : public wxSplitterWindow { |
---|
108 | MainFrm *parent; |
---|
109 | |
---|
110 | public: |
---|
111 | AvenSplitterWindow(MainFrm *parent_) |
---|
112 | : wxSplitterWindow(parent_, -1, wxDefaultPosition, wxDefaultSize, |
---|
113 | wxSP_3DSASH), |
---|
114 | parent(parent_) |
---|
115 | { |
---|
116 | } |
---|
117 | |
---|
118 | void OnSplitterDClick(wxSplitterEvent &) { |
---|
119 | parent->ToggleSidePanel(); |
---|
120 | } |
---|
121 | |
---|
122 | private: |
---|
123 | DECLARE_EVENT_TABLE() |
---|
124 | }; |
---|
125 | |
---|
126 | BEGIN_EVENT_TABLE(AvenSplitterWindow, wxSplitterWindow) |
---|
127 | EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick) |
---|
128 | END_EVENT_TABLE() |
---|
129 | |
---|
130 | class EditMarkDlg : public wxDialog { |
---|
131 | wxTextCtrl * easting, * northing, * altitude; |
---|
132 | wxTextCtrl * angle, * tilt_angle, * scale, * time; |
---|
133 | public: |
---|
134 | // TRANSLATORS: Title of dialog to edit a waypoint in a presentation. |
---|
135 | EditMarkDlg(wxWindow* parent, const PresentationMark & p) |
---|
136 | : wxDialog(parent, 500, wmsg(/*Edit Waypoint*/404)) |
---|
137 | { |
---|
138 | easting = new wxTextCtrl(this, 601, wxString::Format(wxT("%.3f"), p.GetX())); |
---|
139 | northing = new wxTextCtrl(this, 602, wxString::Format(wxT("%.3f"), p.GetY())); |
---|
140 | altitude = new wxTextCtrl(this, 603, wxString::Format(wxT("%.3f"), p.GetZ())); |
---|
141 | angle = new wxTextCtrl(this, 604, wxString::Format(wxT("%.3f"), p.angle)); |
---|
142 | tilt_angle = new wxTextCtrl(this, 605, wxString::Format(wxT("%.3f"), p.tilt_angle)); |
---|
143 | scale = new wxTextCtrl(this, 606, wxString::Format(wxT("%.3f"), p.scale)); |
---|
144 | if (p.time > 0.0) { |
---|
145 | time = new wxTextCtrl(this, 607, wxString::Format(wxT("%.3f"), p.time)); |
---|
146 | } else if (p.time < 0.0) { |
---|
147 | time = new wxTextCtrl(this, 607, wxString::Format(wxT("*%.3f"), -p.time)); |
---|
148 | } else { |
---|
149 | time = new wxTextCtrl(this, 607, wxT("0")); |
---|
150 | } |
---|
151 | |
---|
152 | wxBoxSizer * coords = new wxBoxSizer(wxHORIZONTAL); |
---|
153 | coords->Add(new wxStaticText(this, 610, wxT("(")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
154 | coords->Add(easting, 1); |
---|
155 | coords->Add(new wxStaticText(this, 611, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
156 | coords->Add(northing, 1); |
---|
157 | coords->Add(new wxStaticText(this, 612, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
158 | coords->Add(altitude, 1); |
---|
159 | coords->Add(new wxStaticText(this, 613, wxT(")")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
160 | wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL); |
---|
161 | vert->Add(coords, 0, wxALL, 8); |
---|
162 | wxBoxSizer * r2 = new wxBoxSizer(wxHORIZONTAL); |
---|
163 | r2->Add(new wxStaticText(this, 614, wmsg(/*Bearing*/259) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
164 | r2->Add(angle); |
---|
165 | vert->Add(r2, 0, wxALL, 8); |
---|
166 | wxBoxSizer * r3 = new wxBoxSizer(wxHORIZONTAL); |
---|
167 | r3->Add(new wxStaticText(this, 615, wmsg(/*Elevation*/118) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
168 | r3->Add(tilt_angle); |
---|
169 | vert->Add(r3, 0, wxALL, 8); |
---|
170 | wxBoxSizer * r4 = new wxBoxSizer(wxHORIZONTAL); |
---|
171 | r4->Add(new wxStaticText(this, 616, wmsg(/*Scale*/154) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL); |
---|
172 | r4->Add(scale); |
---|
173 | /* TRANSLATORS: Note after "Scale" field in dialog to edit a waypoint |
---|
174 | * in a presentation. */ |
---|
175 | r4->Add(new wxStaticText(this, 617, wmsg(/* (unused in perspective view)*/278)), |
---|
176 | 0, wxALIGN_CENTRE_VERTICAL); |
---|
177 | vert->Add(r4, 0, wxALL, 8); |
---|
178 | |
---|
179 | wxBoxSizer * r5 = new wxBoxSizer(wxHORIZONTAL); |
---|
180 | /* TRANSLATORS: Field label in dialog to edit a waypoint in a |
---|
181 | * presentation. */ |
---|
182 | r5->Add(new wxStaticText(this, 616, wmsg(/*Time: */279)), 0, wxALIGN_CENTRE_VERTICAL); |
---|
183 | r5->Add(time); |
---|
184 | /* TRANSLATORS: units+info after time field in dialog to edit a |
---|
185 | * waypoint in a presentation. */ |
---|
186 | r5->Add(new wxStaticText(this, 617, wmsg(/* secs (0 = auto; *6 = 6 times auto)*/282)), |
---|
187 | 0, wxALIGN_CENTRE_VERTICAL); |
---|
188 | vert->Add(r5, 0, wxALL, 8); |
---|
189 | |
---|
190 | wxBoxSizer * buttons = new wxBoxSizer(wxHORIZONTAL); |
---|
191 | wxButton* cancel = new wxButton(this, wxID_CANCEL); |
---|
192 | buttons->Add(cancel, 0, wxALL, 8); |
---|
193 | wxButton* ok = new wxButton(this, wxID_OK); |
---|
194 | ok->SetDefault(); |
---|
195 | buttons->Add(ok, 0, wxALL, 8); |
---|
196 | vert->Add(buttons, 0, wxALL|wxALIGN_RIGHT); |
---|
197 | |
---|
198 | SetAutoLayout(true); |
---|
199 | SetSizer(vert); |
---|
200 | |
---|
201 | vert->SetSizeHints(this); |
---|
202 | } |
---|
203 | PresentationMark GetMark() const { |
---|
204 | double a, t, s, T; |
---|
205 | Vector3 v(atof(easting->GetValue().mb_str()), |
---|
206 | atof(northing->GetValue().mb_str()), |
---|
207 | atof(altitude->GetValue().mb_str())); |
---|
208 | a = atof(angle->GetValue().mb_str()); |
---|
209 | t = atof(tilt_angle->GetValue().mb_str()); |
---|
210 | s = atof(scale->GetValue().mb_str()); |
---|
211 | wxString str = time->GetValue(); |
---|
212 | if (!str.empty() && str[0u] == '*') str[0u] = '-'; |
---|
213 | T = atof(str.mb_str()); |
---|
214 | return PresentationMark(v, a, t, s, T); |
---|
215 | } |
---|
216 | |
---|
217 | private: |
---|
218 | DECLARE_EVENT_TABLE() |
---|
219 | }; |
---|
220 | |
---|
221 | // Write a value without trailing zeros after the decimal point. |
---|
222 | static void write_double(double d, FILE * fh) { |
---|
223 | char buf[64]; |
---|
224 | sprintf(buf, "%.21f", d); |
---|
225 | char * p = strchr(buf, ','); |
---|
226 | if (p) *p = '.'; |
---|
227 | size_t l = strlen(buf); |
---|
228 | while (l > 1 && buf[l - 1] == '0') --l; |
---|
229 | if (l > 1 && buf[l - 1] == '.') --l; |
---|
230 | fwrite(buf, l, 1, fh); |
---|
231 | } |
---|
232 | |
---|
233 | class AvenPresList : public wxListCtrl { |
---|
234 | MainFrm * mainfrm; |
---|
235 | GfxCore * gfx; |
---|
236 | vector<PresentationMark> entries; |
---|
237 | long current_item; |
---|
238 | bool modified; |
---|
239 | bool force_save_as; |
---|
240 | wxString filename; |
---|
241 | |
---|
242 | public: |
---|
243 | AvenPresList(MainFrm * mainfrm_, wxWindow * parent, GfxCore * gfx_) |
---|
244 | : wxListCtrl(parent, listctrl_PRES, wxDefaultPosition, wxDefaultSize, |
---|
245 | wxLC_REPORT|wxLC_VIRTUAL), |
---|
246 | mainfrm(mainfrm_), gfx(gfx_), current_item(-1), modified(false), |
---|
247 | force_save_as(true) |
---|
248 | { |
---|
249 | InsertColumn(0, wmsg(/*Easting*/378)); |
---|
250 | InsertColumn(1, wmsg(/*Northing*/379)); |
---|
251 | InsertColumn(2, wmsg(/*Altitude*/335)); |
---|
252 | } |
---|
253 | |
---|
254 | void OnBeginLabelEdit(wxListEvent& event) { |
---|
255 | event.Veto(); // No editting allowed |
---|
256 | } |
---|
257 | void OnDeleteItem(wxListEvent& event) { |
---|
258 | long item = event.GetIndex(); |
---|
259 | if (current_item == item) { |
---|
260 | current_item = -1; |
---|
261 | } else if (current_item > item) { |
---|
262 | --current_item; |
---|
263 | } |
---|
264 | entries.erase(entries.begin() + item); |
---|
265 | SetItemCount(entries.size()); |
---|
266 | modified = true; |
---|
267 | } |
---|
268 | void OnDeleteAllItems(wxListEvent&) { |
---|
269 | entries.clear(); |
---|
270 | SetItemCount(entries.size()); |
---|
271 | filename = wxString(); |
---|
272 | modified = false; |
---|
273 | force_save_as = true; |
---|
274 | } |
---|
275 | void OnListKeyDown(wxListEvent& event) { |
---|
276 | switch (event.GetKeyCode()) { |
---|
277 | case WXK_DELETE: { |
---|
278 | long item = GetNextItem(-1, wxLIST_NEXT_ALL, |
---|
279 | wxLIST_STATE_SELECTED); |
---|
280 | while (item != -1) { |
---|
281 | DeleteItem(item); |
---|
282 | // - 1 because the indices were shifted by DeleteItem() |
---|
283 | item = GetNextItem(item - 1, wxLIST_NEXT_ALL, |
---|
284 | wxLIST_STATE_SELECTED); |
---|
285 | } |
---|
286 | break; |
---|
287 | } |
---|
288 | default: |
---|
289 | //printf("event.GetIndex() = %ld %d\n", event.GetIndex(), event.GetKeyCode()); |
---|
290 | event.Skip(); |
---|
291 | } |
---|
292 | } |
---|
293 | void OnActivated(wxListEvent& event) { |
---|
294 | // Jump to this view. |
---|
295 | long item = event.GetIndex(); |
---|
296 | gfx->SetView(entries[item]); |
---|
297 | } |
---|
298 | void OnFocused(wxListEvent& event) { |
---|
299 | current_item = event.GetIndex(); |
---|
300 | } |
---|
301 | void OnRightClick(wxListEvent& event) { |
---|
302 | long item = event.GetIndex(); |
---|
303 | if (item < 0) { |
---|
304 | AddMark(item, gfx->GetView()); |
---|
305 | item = 0; |
---|
306 | } |
---|
307 | EditMarkDlg edit(mainfrm, entries[item]); |
---|
308 | if (edit.ShowModal() == wxID_OK) { |
---|
309 | entries[item] = edit.GetMark(); |
---|
310 | } |
---|
311 | } |
---|
312 | void OnChar(wxKeyEvent& event) { |
---|
313 | switch (event.GetKeyCode()) { |
---|
314 | case WXK_INSERT: |
---|
315 | if (event.GetModifiers() == wxMOD_CONTROL) { |
---|
316 | if (current_item != -1 && |
---|
317 | size_t(current_item) < entries.size()) { |
---|
318 | AddMark(current_item, entries[current_item]); |
---|
319 | } |
---|
320 | } else { |
---|
321 | AddMark(current_item); |
---|
322 | } |
---|
323 | break; |
---|
324 | case WXK_DELETE: |
---|
325 | // Already handled in OnListKeyDown. |
---|
326 | break; |
---|
327 | case WXK_UP: case WXK_DOWN: |
---|
328 | event.Skip(); |
---|
329 | break; |
---|
330 | default: |
---|
331 | gfx->OnKeyPress(event); |
---|
332 | } |
---|
333 | } |
---|
334 | void AddMark(long item = -1) { |
---|
335 | AddMark(item, gfx->GetView()); |
---|
336 | } |
---|
337 | void AddMark(long item, const PresentationMark & mark) { |
---|
338 | if (item == -1) item = entries.size(); |
---|
339 | entries.insert(entries.begin() + item, mark); |
---|
340 | SetItemCount(entries.size()); |
---|
341 | modified = true; |
---|
342 | } |
---|
343 | virtual wxString OnGetItemText(long item, long column) const { |
---|
344 | if (item < 0 || item >= (long)entries.size()) return wxString(); |
---|
345 | const PresentationMark & p = entries[item]; |
---|
346 | double v; |
---|
347 | switch (column) { |
---|
348 | case 0: v = p.GetX(); break; |
---|
349 | case 1: v = p.GetY(); break; |
---|
350 | case 2: v = p.GetZ(); break; |
---|
351 | #if 0 |
---|
352 | case 3: v = p.angle; break; |
---|
353 | case 4: v = p.tilt_angle; break; |
---|
354 | case 5: v = p.scale; break; |
---|
355 | case 6: v = p.time; break; |
---|
356 | #endif |
---|
357 | default: return wxString(); |
---|
358 | } |
---|
359 | return wxString::Format(wxT("%ld"), (long)v); |
---|
360 | } |
---|
361 | void Save(bool use_default_name) { |
---|
362 | wxString fnm = filename; |
---|
363 | if (!use_default_name || force_save_as) { |
---|
364 | AvenAllowOnTop ontop(mainfrm); |
---|
365 | #ifdef __WXMOTIF__ |
---|
366 | wxString ext(wxT("*.fly")); |
---|
367 | #else |
---|
368 | wxString ext = wmsg(/*Aven presentations*/320); |
---|
369 | ext += wxT("|*.fly"); |
---|
370 | #endif |
---|
371 | wxFileDialog dlg(this, wmsg(/*Select an output filename*/319), |
---|
372 | wxString(), fnm, ext, |
---|
373 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
---|
374 | if (dlg.ShowModal() != wxID_OK) return; |
---|
375 | fnm = dlg.GetPath(); |
---|
376 | } |
---|
377 | |
---|
378 | #ifdef __WXMSW__ |
---|
379 | FILE * fh_pres = _wfopen(fnm.fn_str(), L"w"); |
---|
380 | #else |
---|
381 | FILE * fh_pres = fopen(fnm.mb_str(), "w"); |
---|
382 | #endif |
---|
383 | if (!fh_pres) { |
---|
384 | wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm.c_str())); |
---|
385 | return; |
---|
386 | } |
---|
387 | vector<PresentationMark>::const_iterator i; |
---|
388 | for (i = entries.begin(); i != entries.end(); ++i) { |
---|
389 | const PresentationMark &p = *i; |
---|
390 | write_double(p.GetX(), fh_pres); |
---|
391 | PUTC(' ', fh_pres); |
---|
392 | write_double(p.GetY(), fh_pres); |
---|
393 | PUTC(' ', fh_pres); |
---|
394 | write_double(p.GetZ(), fh_pres); |
---|
395 | PUTC(' ', fh_pres); |
---|
396 | write_double(p.angle, fh_pres); |
---|
397 | PUTC(' ', fh_pres); |
---|
398 | write_double(p.tilt_angle, fh_pres); |
---|
399 | PUTC(' ', fh_pres); |
---|
400 | write_double(p.scale, fh_pres); |
---|
401 | if (p.time != 0.0) { |
---|
402 | PUTC(' ', fh_pres); |
---|
403 | write_double(p.time, fh_pres); |
---|
404 | } |
---|
405 | PUTC('\n', fh_pres); |
---|
406 | } |
---|
407 | fclose(fh_pres); |
---|
408 | filename = fnm; |
---|
409 | modified = false; |
---|
410 | force_save_as = false; |
---|
411 | } |
---|
412 | void New(const wxString &fnm) { |
---|
413 | DeleteAllItems(); |
---|
414 | wxFileName::SplitPath(fnm, NULL, NULL, &filename, NULL, wxPATH_NATIVE); |
---|
415 | filename += wxT(".fly"); |
---|
416 | force_save_as = true; |
---|
417 | } |
---|
418 | bool Load(const wxString &fnm) { |
---|
419 | #ifdef __WXMSW__ |
---|
420 | FILE * fh_pres = _wfopen(fnm.fn_str(), L"r"); |
---|
421 | #else |
---|
422 | FILE * fh_pres = fopen(fnm.mb_str(), "r"); |
---|
423 | #endif |
---|
424 | if (!fh_pres) { |
---|
425 | wxString m; |
---|
426 | m.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm.c_str()); |
---|
427 | wxGetApp().ReportError(m); |
---|
428 | return false; |
---|
429 | } |
---|
430 | DeleteAllItems(); |
---|
431 | long item = 0; |
---|
432 | while (!feof(fh_pres)) { |
---|
433 | char buf[4096]; |
---|
434 | size_t i = 0; |
---|
435 | while (i < sizeof(buf) - 1) { |
---|
436 | int ch = GETC(fh_pres); |
---|
437 | if (ch == EOF || ch == '\n' || ch == '\r') break; |
---|
438 | buf[i++] = ch; |
---|
439 | } |
---|
440 | if (i) { |
---|
441 | buf[i] = 0; |
---|
442 | double x, y, z, a, t, s, T; |
---|
443 | int c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T); |
---|
444 | if (c < 6) { |
---|
445 | char *p = buf; |
---|
446 | while ((p = strchr(p, '.'))) *p++ = ','; |
---|
447 | c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T); |
---|
448 | if (c < 6) { |
---|
449 | DeleteAllItems(); |
---|
450 | wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm.c_str())); |
---|
451 | return false; |
---|
452 | } |
---|
453 | } |
---|
454 | if (c == 6) T = 0; |
---|
455 | AddMark(item, PresentationMark(Vector3(x, y, z), a, t, s, T)); |
---|
456 | ++item; |
---|
457 | } |
---|
458 | } |
---|
459 | fclose(fh_pres); |
---|
460 | filename = fnm; |
---|
461 | modified = false; |
---|
462 | force_save_as = false; |
---|
463 | return true; |
---|
464 | } |
---|
465 | bool Modified() const { return modified; } |
---|
466 | bool Empty() const { return entries.empty(); } |
---|
467 | PresentationMark GetPresMark(int which) { |
---|
468 | long item = current_item; |
---|
469 | if (which == MARK_FIRST) { |
---|
470 | item = 0; |
---|
471 | } else if (which == MARK_NEXT) { |
---|
472 | ++item; |
---|
473 | } else if (which == MARK_PREV) { |
---|
474 | --item; |
---|
475 | } |
---|
476 | if (item == -1 || item == (long)entries.size()) |
---|
477 | return PresentationMark(); |
---|
478 | if (item != current_item) { |
---|
479 | // Move the focus |
---|
480 | if (current_item != -1) { |
---|
481 | wxListCtrl::SetItemState(current_item, wxLIST_STATE_FOCUSED, |
---|
482 | 0); |
---|
483 | } |
---|
484 | wxListCtrl::SetItemState(item, wxLIST_STATE_FOCUSED, |
---|
485 | wxLIST_STATE_FOCUSED); |
---|
486 | } |
---|
487 | return entries[item]; |
---|
488 | } |
---|
489 | |
---|
490 | private: |
---|
491 | |
---|
492 | DECLARE_NO_COPY_CLASS(AvenPresList) |
---|
493 | DECLARE_EVENT_TABLE() |
---|
494 | }; |
---|
495 | |
---|
496 | BEGIN_EVENT_TABLE(EditMarkDlg, wxDialog) |
---|
497 | END_EVENT_TABLE() |
---|
498 | |
---|
499 | BEGIN_EVENT_TABLE(AvenPresList, wxListCtrl) |
---|
500 | EVT_LIST_BEGIN_LABEL_EDIT(listctrl_PRES, AvenPresList::OnBeginLabelEdit) |
---|
501 | EVT_LIST_DELETE_ITEM(listctrl_PRES, AvenPresList::OnDeleteItem) |
---|
502 | EVT_LIST_DELETE_ALL_ITEMS(listctrl_PRES, AvenPresList::OnDeleteAllItems) |
---|
503 | EVT_LIST_KEY_DOWN(listctrl_PRES, AvenPresList::OnListKeyDown) |
---|
504 | EVT_LIST_ITEM_ACTIVATED(listctrl_PRES, AvenPresList::OnActivated) |
---|
505 | EVT_LIST_ITEM_FOCUSED(listctrl_PRES, AvenPresList::OnFocused) |
---|
506 | EVT_LIST_ITEM_RIGHT_CLICK(listctrl_PRES, AvenPresList::OnRightClick) |
---|
507 | EVT_CHAR(AvenPresList::OnChar) |
---|
508 | END_EVENT_TABLE() |
---|
509 | |
---|
510 | BEGIN_EVENT_TABLE(MainFrm, wxFrame) |
---|
511 | EVT_TEXT(textctrl_FIND, MainFrm::OnFind) |
---|
512 | EVT_TEXT_ENTER(textctrl_FIND, MainFrm::OnGotoFound) |
---|
513 | EVT_MENU(wxID_FIND, MainFrm::OnGotoFound) |
---|
514 | EVT_MENU(button_HIDE, MainFrm::OnHide) |
---|
515 | EVT_UPDATE_UI(button_HIDE, MainFrm::OnHideUpdate) |
---|
516 | EVT_IDLE(MainFrm::OnIdle) |
---|
517 | |
---|
518 | EVT_MENU(wxID_OPEN, MainFrm::OnOpen) |
---|
519 | EVT_MENU(menu_FILE_LOG, MainFrm::OnShowLog) |
---|
520 | EVT_MENU(wxID_PRINT, MainFrm::OnPrint) |
---|
521 | EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup) |
---|
522 | EVT_MENU(menu_FILE_SCREENSHOT, MainFrm::OnScreenshot) |
---|
523 | // EVT_MENU(wxID_PREFERENCES, MainFrm::OnFilePreferences) |
---|
524 | EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport) |
---|
525 | EVT_MENU(wxID_EXIT, MainFrm::OnQuit) |
---|
526 | EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile) |
---|
527 | |
---|
528 | EVT_MENU(menu_PRES_NEW, MainFrm::OnPresNew) |
---|
529 | EVT_MENU(menu_PRES_OPEN, MainFrm::OnPresOpen) |
---|
530 | EVT_MENU(menu_PRES_SAVE, MainFrm::OnPresSave) |
---|
531 | EVT_MENU(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAs) |
---|
532 | EVT_MENU(menu_PRES_MARK, MainFrm::OnPresMark) |
---|
533 | EVT_MENU(menu_PRES_FREWIND, MainFrm::OnPresFRewind) |
---|
534 | EVT_MENU(menu_PRES_REWIND, MainFrm::OnPresRewind) |
---|
535 | EVT_MENU(menu_PRES_REVERSE, MainFrm::OnPresReverse) |
---|
536 | EVT_MENU(menu_PRES_PLAY, MainFrm::OnPresPlay) |
---|
537 | EVT_MENU(menu_PRES_FF, MainFrm::OnPresFF) |
---|
538 | EVT_MENU(menu_PRES_FFF, MainFrm::OnPresFFF) |
---|
539 | EVT_MENU(menu_PRES_PAUSE, MainFrm::OnPresPause) |
---|
540 | EVT_MENU(wxID_STOP, MainFrm::OnPresStop) |
---|
541 | EVT_MENU(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovie) |
---|
542 | |
---|
543 | EVT_UPDATE_UI(menu_PRES_NEW, MainFrm::OnPresNewUpdate) |
---|
544 | EVT_UPDATE_UI(menu_PRES_OPEN, MainFrm::OnPresOpenUpdate) |
---|
545 | EVT_UPDATE_UI(menu_PRES_SAVE, MainFrm::OnPresSaveUpdate) |
---|
546 | EVT_UPDATE_UI(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAsUpdate) |
---|
547 | EVT_UPDATE_UI(menu_PRES_MARK, MainFrm::OnPresMarkUpdate) |
---|
548 | EVT_UPDATE_UI(menu_PRES_FREWIND, MainFrm::OnPresFRewindUpdate) |
---|
549 | EVT_UPDATE_UI(menu_PRES_REWIND, MainFrm::OnPresRewindUpdate) |
---|
550 | EVT_UPDATE_UI(menu_PRES_REVERSE, MainFrm::OnPresReverseUpdate) |
---|
551 | EVT_UPDATE_UI(menu_PRES_PLAY, MainFrm::OnPresPlayUpdate) |
---|
552 | EVT_UPDATE_UI(menu_PRES_FF, MainFrm::OnPresFFUpdate) |
---|
553 | EVT_UPDATE_UI(menu_PRES_FFF, MainFrm::OnPresFFFUpdate) |
---|
554 | EVT_UPDATE_UI(menu_PRES_PAUSE, MainFrm::OnPresPauseUpdate) |
---|
555 | EVT_UPDATE_UI(wxID_STOP, MainFrm::OnPresStopUpdate) |
---|
556 | EVT_UPDATE_UI(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovieUpdate) |
---|
557 | |
---|
558 | EVT_CLOSE(MainFrm::OnClose) |
---|
559 | EVT_SET_FOCUS(MainFrm::OnSetFocus) |
---|
560 | |
---|
561 | EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation) |
---|
562 | EVT_MENU(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUp) |
---|
563 | EVT_MENU(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDown) |
---|
564 | EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation) |
---|
565 | EVT_MENU(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceAnticlockwise) |
---|
566 | EVT_MENU(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceClockwise) |
---|
567 | EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth) |
---|
568 | EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast) |
---|
569 | EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth) |
---|
570 | EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest) |
---|
571 | EVT_MENU(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeft) |
---|
572 | EVT_MENU(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRight) |
---|
573 | EVT_MENU(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUp) |
---|
574 | EVT_MENU(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDown) |
---|
575 | EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan) |
---|
576 | EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation) |
---|
577 | EVT_MENU(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpoint) |
---|
578 | EVT_MENU(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpoint) |
---|
579 | EVT_MENU(wxID_ZOOM_IN, MainFrm::OnZoomIn) |
---|
580 | EVT_MENU(wxID_ZOOM_OUT, MainFrm::OnZoomOut) |
---|
581 | EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults) |
---|
582 | EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs) |
---|
583 | EVT_MENU(menu_SPLAYS_HIDE, MainFrm::OnHideSplays) |
---|
584 | EVT_MENU(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormal) |
---|
585 | EVT_MENU(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFaded) |
---|
586 | EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses) |
---|
587 | EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances) |
---|
588 | EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts) |
---|
589 | EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts) |
---|
590 | EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames) |
---|
591 | EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames) |
---|
592 | EVT_MENU(menu_VIEW_COLOUR_BY_DEPTH, MainFrm::OnColourByDepth) |
---|
593 | EVT_MENU(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDate) |
---|
594 | EVT_MENU(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByError) |
---|
595 | EVT_MENU(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLength) |
---|
596 | EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface) |
---|
597 | EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid) |
---|
598 | EVT_MENU(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBox) |
---|
599 | EVT_MENU(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspective) |
---|
600 | EVT_MENU(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShading) |
---|
601 | EVT_MENU(menu_VIEW_TEXTURED, MainFrm::OnViewTextured) |
---|
602 | EVT_MENU(menu_VIEW_FOG, MainFrm::OnViewFog) |
---|
603 | EVT_MENU(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLines) |
---|
604 | EVT_MENU(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreen) |
---|
605 | EVT_MENU(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubes) |
---|
606 | EVT_MENU(menu_IND_COMPASS, MainFrm::OnViewCompass) |
---|
607 | EVT_MENU(menu_IND_CLINO, MainFrm::OnViewClino) |
---|
608 | EVT_MENU(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKey) |
---|
609 | EVT_MENU(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebar) |
---|
610 | EVT_MENU(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanel) |
---|
611 | EVT_MENU(menu_CTL_METRIC, MainFrm::OnToggleMetric) |
---|
612 | EVT_MENU(menu_CTL_DEGREES, MainFrm::OnToggleDegrees) |
---|
613 | EVT_MENU(menu_CTL_PERCENT, MainFrm::OnTogglePercent) |
---|
614 | EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls) |
---|
615 | EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine) |
---|
616 | EVT_MENU(wxID_ABOUT, MainFrm::OnAbout) |
---|
617 | |
---|
618 | EVT_UPDATE_UI(menu_FILE_LOG, MainFrm::OnShowLogUpdate) |
---|
619 | EVT_UPDATE_UI(wxID_PRINT, MainFrm::OnPrintUpdate) |
---|
620 | EVT_UPDATE_UI(menu_FILE_SCREENSHOT, MainFrm::OnScreenshotUpdate) |
---|
621 | EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate) |
---|
622 | EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate) |
---|
623 | EVT_UPDATE_UI(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUpUpdate) |
---|
624 | EVT_UPDATE_UI(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDownUpdate) |
---|
625 | EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate) |
---|
626 | EVT_UPDATE_UI(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceUpdate) |
---|
627 | EVT_UPDATE_UI(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceUpdate) |
---|
628 | EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate) |
---|
629 | EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate) |
---|
630 | EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate) |
---|
631 | EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate) |
---|
632 | EVT_UPDATE_UI(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeftUpdate) |
---|
633 | EVT_UPDATE_UI(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRightUpdate) |
---|
634 | EVT_UPDATE_UI(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUpUpdate) |
---|
635 | EVT_UPDATE_UI(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDownUpdate) |
---|
636 | EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate) |
---|
637 | EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate) |
---|
638 | EVT_UPDATE_UI(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpointUpdate) |
---|
639 | EVT_UPDATE_UI(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpointUpdate) |
---|
640 | EVT_UPDATE_UI(wxID_ZOOM_IN, MainFrm::OnZoomInUpdate) |
---|
641 | EVT_UPDATE_UI(wxID_ZOOM_OUT, MainFrm::OnZoomOutUpdate) |
---|
642 | EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate) |
---|
643 | EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate) |
---|
644 | EVT_UPDATE_UI(menu_VIEW_SPLAYS, MainFrm::OnSplaysUpdate) |
---|
645 | EVT_UPDATE_UI(menu_SPLAYS_HIDE, MainFrm::OnHideSplaysUpdate) |
---|
646 | EVT_UPDATE_UI(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormalUpdate) |
---|
647 | EVT_UPDATE_UI(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFadedUpdate) |
---|
648 | EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate) |
---|
649 | EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate) |
---|
650 | EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate) |
---|
651 | EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate) |
---|
652 | EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate) |
---|
653 | EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate) |
---|
654 | EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate) |
---|
655 | EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DEPTH, MainFrm::OnColourByDepthUpdate) |
---|
656 | EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate) |
---|
657 | EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate) |
---|
658 | EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate) |
---|
659 | EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate) |
---|
660 | EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate) |
---|
661 | EVT_UPDATE_UI(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspectiveUpdate) |
---|
662 | EVT_UPDATE_UI(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShadingUpdate) |
---|
663 | EVT_UPDATE_UI(menu_VIEW_TEXTURED, MainFrm::OnViewTexturedUpdate) |
---|
664 | EVT_UPDATE_UI(menu_VIEW_FOG, MainFrm::OnViewFogUpdate) |
---|
665 | EVT_UPDATE_UI(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLinesUpdate) |
---|
666 | EVT_UPDATE_UI(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreenUpdate) |
---|
667 | EVT_UPDATE_UI(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubesUpdate) |
---|
668 | EVT_UPDATE_UI(menu_IND_COMPASS, MainFrm::OnViewCompassUpdate) |
---|
669 | EVT_UPDATE_UI(menu_IND_CLINO, MainFrm::OnViewClinoUpdate) |
---|
670 | EVT_UPDATE_UI(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKeyUpdate) |
---|
671 | EVT_UPDATE_UI(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebarUpdate) |
---|
672 | EVT_UPDATE_UI(menu_CTL_INDICATORS, MainFrm::OnIndicatorsUpdate) |
---|
673 | EVT_UPDATE_UI(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate) |
---|
674 | EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate) |
---|
675 | EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate) |
---|
676 | EVT_UPDATE_UI(menu_CTL_METRIC, MainFrm::OnToggleMetricUpdate) |
---|
677 | EVT_UPDATE_UI(menu_CTL_DEGREES, MainFrm::OnToggleDegreesUpdate) |
---|
678 | EVT_UPDATE_UI(menu_CTL_PERCENT, MainFrm::OnTogglePercentUpdate) |
---|
679 | END_EVENT_TABLE() |
---|
680 | |
---|
681 | class LabelCmp : public greater<const LabelInfo*> { |
---|
682 | wxChar separator; |
---|
683 | public: |
---|
684 | LabelCmp(wxChar separator_) : separator(separator_) {} |
---|
685 | bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) { |
---|
686 | return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0; |
---|
687 | } |
---|
688 | }; |
---|
689 | |
---|
690 | class LabelPlotCmp : public greater<const LabelInfo*> { |
---|
691 | wxChar separator; |
---|
692 | public: |
---|
693 | LabelPlotCmp(wxChar separator_) : separator(separator_) {} |
---|
694 | bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) { |
---|
695 | int n = pt1->get_flags() - pt2->get_flags(); |
---|
696 | if (n) return n > 0; |
---|
697 | wxString l1 = pt1->GetText().AfterLast(separator); |
---|
698 | wxString l2 = pt2->GetText().AfterLast(separator); |
---|
699 | n = name_cmp(l1, l2, separator); |
---|
700 | if (n) return n < 0; |
---|
701 | // Prefer non-2-nodes... |
---|
702 | // FIXME; implement |
---|
703 | // if leaf names are the same, prefer shorter labels as we can |
---|
704 | // display more of them |
---|
705 | n = pt1->GetText().length() - pt2->GetText().length(); |
---|
706 | if (n) return n < 0; |
---|
707 | // make sure that we don't ever compare different labels as equal |
---|
708 | return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0; |
---|
709 | } |
---|
710 | }; |
---|
711 | |
---|
712 | #if wxUSE_DRAG_AND_DROP |
---|
713 | class DnDFile : public wxFileDropTarget { |
---|
714 | public: |
---|
715 | DnDFile(MainFrm *parent) : m_Parent(parent) { } |
---|
716 | virtual bool OnDropFiles(wxCoord, wxCoord, |
---|
717 | const wxArrayString &filenames); |
---|
718 | |
---|
719 | private: |
---|
720 | MainFrm * m_Parent; |
---|
721 | }; |
---|
722 | |
---|
723 | bool |
---|
724 | DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames) |
---|
725 | { |
---|
726 | // Load a survey file by drag-and-drop. |
---|
727 | assert(filenames.GetCount() > 0); |
---|
728 | |
---|
729 | if (filenames.GetCount() != 1) { |
---|
730 | /* TRANSLATORS: error if you try to drag multiple files to the aven |
---|
731 | * window */ |
---|
732 | wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336)); |
---|
733 | return false; |
---|
734 | } |
---|
735 | |
---|
736 | m_Parent->OpenFile(filenames[0]); |
---|
737 | return true; |
---|
738 | } |
---|
739 | #endif |
---|
740 | |
---|
741 | MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) : |
---|
742 | wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE), |
---|
743 | m_SashPosition(-1), |
---|
744 | m_Gfx(NULL), m_Log(NULL), |
---|
745 | m_NumEntrances(0), m_NumFixedPts(0), m_NumExportedPts(0), |
---|
746 | m_NumHighlighted(0), |
---|
747 | m_HasUndergroundLegs(false), m_HasSplays(false), m_HasSurfaceLegs(false), |
---|
748 | m_HasErrorInformation(false), m_IsExtendedElevation(false), |
---|
749 | pending_find(false), fullscreen_showing_menus(false) |
---|
750 | #ifdef PREFDLG |
---|
751 | , m_PrefsDlg(NULL) |
---|
752 | #endif |
---|
753 | { |
---|
754 | #ifdef _WIN32 |
---|
755 | // The peculiar name is so that the icon is the first in the file |
---|
756 | // (required by Microsoft Windows for this type of icon) |
---|
757 | SetIcon(wxICON(AAA_aven)); |
---|
758 | #else |
---|
759 | SetIcon(wxICON(aven)); |
---|
760 | #endif |
---|
761 | |
---|
762 | #if wxCHECK_VERSION(3,1,0) |
---|
763 | // Add a full screen button to the right upper corner of title bar under OS |
---|
764 | // X 10.7 and later. |
---|
765 | EnableFullScreenView(); |
---|
766 | #endif |
---|
767 | CreateMenuBar(); |
---|
768 | MakeToolBar(); |
---|
769 | CreateStatusBar(2, wxST_SIZEGRIP); |
---|
770 | CreateSidePanel(); |
---|
771 | |
---|
772 | int widths[2] = { -1 /* variable width */, -1 }; |
---|
773 | GetStatusBar()->SetStatusWidths(2, widths); |
---|
774 | |
---|
775 | #ifdef __X__ // wxMotif or wxX11 |
---|
776 | int x; |
---|
777 | int y; |
---|
778 | GetSize(&x, &y); |
---|
779 | // X seems to require a forced resize. |
---|
780 | SetSize(-1, -1, x, y); |
---|
781 | #endif |
---|
782 | |
---|
783 | #if wxUSE_DRAG_AND_DROP |
---|
784 | SetDropTarget(new DnDFile(this)); |
---|
785 | #endif |
---|
786 | } |
---|
787 | |
---|
788 | void MainFrm::CreateMenuBar() |
---|
789 | { |
---|
790 | // Create the menus and the menu bar. |
---|
791 | |
---|
792 | wxMenu* filemenu = new wxMenu; |
---|
793 | // wxID_OPEN stock label lacks the ellipses |
---|
794 | /* TRANSLATORS: Aven menu items. An “&” goes before the letter of any |
---|
795 | * accelerator key. |
---|
796 | * |
---|
797 | * The string "\t" separates the menu text and any accelerator key. |
---|
798 | * |
---|
799 | * "File" menu. The accelerators must be different within this group. |
---|
800 | * c.f. 201, 380, 381. */ |
---|
801 | filemenu->Append(wxID_OPEN, wmsg(/*&Open…\tCtrl+O*/220)); |
---|
802 | filemenu->Append(menu_FILE_LOG, wmsg(/*Show &Log*/144)); |
---|
803 | filemenu->AppendSeparator(); |
---|
804 | // wxID_PRINT stock label lacks the ellipses |
---|
805 | filemenu->Append(wxID_PRINT, wmsg(/*&Print…\tCtrl+P*/380)); |
---|
806 | filemenu->Append(menu_FILE_PAGE_SETUP, wmsg(/*P&age Setup…*/381)); |
---|
807 | filemenu->AppendSeparator(); |
---|
808 | /* TRANSLATORS: In the "File" menu */ |
---|
809 | filemenu->Append(menu_FILE_SCREENSHOT, wmsg(/*&Screenshot…*/201)); |
---|
810 | filemenu->Append(menu_FILE_EXPORT, wmsg(/*&Export as…*/382)); |
---|
811 | #ifndef __WXMAC__ |
---|
812 | // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress |
---|
813 | // this separator. |
---|
814 | filemenu->AppendSeparator(); |
---|
815 | #else |
---|
816 | // We suppress the "Help" menu under OS X as it would otherwise end up as |
---|
817 | // an empty menu, but we need to add the "About" menu item somewhere. It |
---|
818 | // really doesn't matter where as wxWidgets will move it to the "Apple" |
---|
819 | // menu. |
---|
820 | filemenu->Append(wxID_ABOUT); |
---|
821 | #endif |
---|
822 | filemenu->Append(wxID_EXIT); |
---|
823 | |
---|
824 | m_history.UseMenu(filemenu); |
---|
825 | m_history.Load(*wxConfigBase::Get()); |
---|
826 | |
---|
827 | wxMenu* rotmenu = new wxMenu; |
---|
828 | /* TRANSLATORS: "Rotation" menu. The accelerators must be different within |
---|
829 | * this group. Tickable menu item which toggles auto rotation */ |
---|
830 | rotmenu->AppendCheckItem(menu_ROTATION_TOGGLE, wmsg(/*Au&to-Rotate\tSpace*/231)); |
---|
831 | rotmenu->AppendSeparator(); |
---|
832 | rotmenu->Append(menu_ROTATION_SPEED_UP, wmsg(/*Speed &Up*/232)); |
---|
833 | rotmenu->Append(menu_ROTATION_SLOW_DOWN, wmsg(/*Slow &Down*/233)); |
---|
834 | rotmenu->AppendSeparator(); |
---|
835 | rotmenu->Append(menu_ROTATION_REVERSE, wmsg(/*&Reverse Direction*/234)); |
---|
836 | rotmenu->AppendSeparator(); |
---|
837 | rotmenu->Append(menu_ROTATION_STEP_CCW, wmsg(/*Step Once &Anticlockwise*/235)); |
---|
838 | rotmenu->Append(menu_ROTATION_STEP_CW, wmsg(/*Step Once &Clockwise*/236)); |
---|
839 | |
---|
840 | wxMenu* orientmenu = new wxMenu; |
---|
841 | orientmenu->Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240)); |
---|
842 | orientmenu->Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241)); |
---|
843 | orientmenu->Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242)); |
---|
844 | orientmenu->Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243)); |
---|
845 | orientmenu->AppendSeparator(); |
---|
846 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
847 | * - it should be translated to the terminology that cavers using the |
---|
848 | * language would use. */ |
---|
849 | orientmenu->Append(menu_ORIENT_SHIFT_LEFT, wmsg(/*Shift Survey &Left*/244)); |
---|
850 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
851 | * - it should be translated to the terminology that cavers using the |
---|
852 | * language would use. */ |
---|
853 | orientmenu->Append(menu_ORIENT_SHIFT_RIGHT, wmsg(/*Shift Survey &Right*/245)); |
---|
854 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
855 | * - it should be translated to the terminology that cavers using the |
---|
856 | * language would use. */ |
---|
857 | orientmenu->Append(menu_ORIENT_SHIFT_UP, wmsg(/*Shift Survey &Up*/246)); |
---|
858 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
859 | * - it should be translated to the terminology that cavers using the |
---|
860 | * language would use. */ |
---|
861 | orientmenu->Append(menu_ORIENT_SHIFT_DOWN, wmsg(/*Shift Survey &Down*/247)); |
---|
862 | orientmenu->AppendSeparator(); |
---|
863 | orientmenu->Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248)); |
---|
864 | orientmenu->Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249)); |
---|
865 | orientmenu->AppendSeparator(); |
---|
866 | orientmenu->Append(menu_ORIENT_HIGHER_VP, wmsg(/*&Higher Viewpoint*/250)); |
---|
867 | orientmenu->Append(menu_ORIENT_LOWER_VP, wmsg(/*L&ower Viewpoint*/251)); |
---|
868 | orientmenu->AppendSeparator(); |
---|
869 | // Default labels for wxID_ZOOM_IN and wxID_ZOOM_OUT don't have accels. |
---|
870 | orientmenu->Append(wxID_ZOOM_IN, wmsg(/*&Zoom In\t]*/252)); |
---|
871 | orientmenu->Append(wxID_ZOOM_OUT, wmsg(/*Zoo&m Out\t[*/253)); |
---|
872 | orientmenu->AppendSeparator(); |
---|
873 | orientmenu->Append(menu_ORIENT_DEFAULTS, wmsg(/*Restore De&fault View*/254)); |
---|
874 | |
---|
875 | wxMenu* presmenu = new wxMenu; |
---|
876 | presmenu->Append(menu_PRES_NEW, wmsg(/*&New Presentation*/311)); |
---|
877 | presmenu->Append(menu_PRES_OPEN, wmsg(/*&Open Presentation…*/312)); |
---|
878 | presmenu->Append(menu_PRES_SAVE, wmsg(/*&Save Presentation*/313)); |
---|
879 | presmenu->Append(menu_PRES_SAVE_AS, wmsg(/*Sa&ve Presentation As…*/314)); |
---|
880 | presmenu->AppendSeparator(); |
---|
881 | /* TRANSLATORS: "Mark" as in "Mark this position" */ |
---|
882 | presmenu->Append(menu_PRES_MARK, wmsg(/*&Mark*/315)); |
---|
883 | /* TRANSLATORS: "Play" as in "Play back a recording" */ |
---|
884 | presmenu->AppendCheckItem(menu_PRES_PLAY, wmsg(/*Pla&y*/316)); |
---|
885 | presmenu->Append(menu_PRES_EXPORT_MOVIE, wmsg(/*&Export as Movie…*/317)); |
---|
886 | |
---|
887 | wxMenu* viewmenu = new wxMenu; |
---|
888 | #ifndef PREFDLG |
---|
889 | /* TRANSLATORS: Items in the "View" menu: */ |
---|
890 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_NAMES, wmsg(/*Station &Names\tCtrl+N*/270)); |
---|
891 | /* TRANSLATORS: Toggles drawing of 3D passages */ |
---|
892 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_TUBES, wmsg(/*Passage &Tubes\tCtrl+T*/346)); |
---|
893 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_CROSSES, wmsg(/*&Crosses\tCtrl+X*/271)); |
---|
894 | viewmenu->AppendCheckItem(menu_VIEW_GRID, wmsg(/*&Grid\tCtrl+G*/297)); |
---|
895 | viewmenu->AppendCheckItem(menu_VIEW_BOUNDING_BOX, wmsg(/*&Bounding Box\tCtrl+B*/318)); |
---|
896 | viewmenu->AppendSeparator(); |
---|
897 | /* TRANSLATORS: Here a "survey leg" is a set of measurements between two |
---|
898 | * "survey stations". */ |
---|
899 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_LEGS, wmsg(/*&Underground Survey Legs\tCtrl+L*/272)); |
---|
900 | /* TRANSLATORS: Here a "survey leg" is a set of measurements between two |
---|
901 | * "survey stations". */ |
---|
902 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_SURFACE, wmsg(/*&Surface Survey Legs\tCtrl+F*/291)); |
---|
903 | |
---|
904 | wxMenu* splaymenu = new wxMenu; |
---|
905 | splaymenu->AppendCheckItem(menu_SPLAYS_HIDE, wmsg(/*&Hide*/407)); |
---|
906 | splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_FADED, wmsg(/*&Fade*/408)); |
---|
907 | splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_NORMAL, wmsg(/*&Show*/409)); |
---|
908 | viewmenu->Append(menu_VIEW_SPLAYS, wmsg(/*Spla&y Legs*/406), splaymenu); |
---|
909 | |
---|
910 | viewmenu->AppendSeparator(); |
---|
911 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_OVERLAPPING_NAMES, wmsg(/*&Overlapping Names*/273)); |
---|
912 | viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292)); |
---|
913 | viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293)); |
---|
914 | viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289)); |
---|
915 | viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82)); |
---|
916 | viewmenu->AppendSeparator(); |
---|
917 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294)); |
---|
918 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_FIXED_PTS, wmsg(/*Highlight &Fixed Points*/295)); |
---|
919 | viewmenu->AppendCheckItem(menu_VIEW_SHOW_EXPORTED_PTS, wmsg(/*Highlight E&xported Points*/296)); |
---|
920 | viewmenu->AppendSeparator(); |
---|
921 | #else |
---|
922 | viewmenu-> Append(menu_VIEW_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281)); |
---|
923 | #endif |
---|
924 | viewmenu->AppendCheckItem(menu_VIEW_PERSPECTIVE, wmsg(/*&Perspective*/237)); |
---|
925 | // FIXME: enable this viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_SHADING, wmsg(/*&Smooth Shading*/?!?); |
---|
926 | viewmenu->AppendCheckItem(menu_VIEW_TEXTURED, wmsg(/*Textured &Walls*/238)); |
---|
927 | /* TRANSLATORS: Toggles OpenGL "Depth Fogging" - feel free to translate |
---|
928 | * using that term instead if it gives a better translation which most |
---|
929 | * users will understand. */ |
---|
930 | viewmenu->AppendCheckItem(menu_VIEW_FOG, wmsg(/*Fade Distant Ob&jects*/239)); |
---|
931 | /* TRANSLATORS: Here a "survey leg" is a set of measurements between two |
---|
932 | * "survey stations". */ |
---|
933 | viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_LINES, wmsg(/*Smoot&hed Survey Legs*/298)); |
---|
934 | viewmenu->AppendSeparator(); |
---|
935 | #ifdef __WXMAC__ |
---|
936 | // F11 on OS X is used by the desktop (for speaker volume and/or window |
---|
937 | // navigation). The standard OS X shortcut for full screen mode is |
---|
938 | // Shift-Command-F which in wxWidgets terms is Shift+Ctrl+F. |
---|
939 | wxString wxmac_fullscreen = wmsg(/*Full Screen &Mode\tF11*/356); |
---|
940 | wxmac_fullscreen.Replace(wxT("\tF11"), wxT("\tShift+Ctrl+F"), false); |
---|
941 | viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wxmac_fullscreen); |
---|
942 | #else |
---|
943 | viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wmsg(/*Full Screen &Mode\tF11*/356)); |
---|
944 | #endif |
---|
945 | #ifdef PREFDLG |
---|
946 | viewmenu->AppendSeparator(); |
---|
947 | viewmenu-> Append(wxID_PREFERENCES, wmsg(/*&Preferences…*/347)); |
---|
948 | #endif |
---|
949 | |
---|
950 | #ifndef PREFDLG |
---|
951 | wxMenu* ctlmenu = new wxMenu; |
---|
952 | ctlmenu->AppendCheckItem(menu_CTL_REVERSE, wmsg(/*&Reverse Sense\tCtrl+R*/280)); |
---|
953 | ctlmenu->AppendSeparator(); |
---|
954 | ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281)); |
---|
955 | ctlmenu->AppendSeparator(); |
---|
956 | wxMenu* indmenu = new wxMenu; |
---|
957 | indmenu->AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Compass*/274)); |
---|
958 | indmenu->AppendCheckItem(menu_IND_CLINO, wmsg(/*C&linometer*/275)); |
---|
959 | /* TRANSLATORS: The "Colour Key" is the thing in aven showing which colour |
---|
960 | * corresponds to which depth, date, survey closure error, etc. */ |
---|
961 | indmenu->AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*Colour &Key*/276)); |
---|
962 | indmenu->AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Scale Bar*/277)); |
---|
963 | ctlmenu->Append(menu_CTL_INDICATORS, wmsg(/*&Indicators*/299), indmenu); |
---|
964 | ctlmenu->AppendCheckItem(menu_CTL_SIDE_PANEL, wmsg(/*&Side Panel*/337)); |
---|
965 | ctlmenu->AppendSeparator(); |
---|
966 | ctlmenu->AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342)); |
---|
967 | ctlmenu->AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343)); |
---|
968 | ctlmenu->AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430)); |
---|
969 | #endif |
---|
970 | |
---|
971 | wxMenuBar* menubar = new wxMenuBar(); |
---|
972 | /* TRANSLATORS: Aven menu titles. An “&” goes before the letter of any |
---|
973 | * accelerator key. The accelerators must be different within this group |
---|
974 | */ |
---|
975 | menubar->Append(filemenu, wmsg(/*&File*/210)); |
---|
976 | menubar->Append(rotmenu, wmsg(/*&Rotation*/211)); |
---|
977 | menubar->Append(orientmenu, wmsg(/*&Orientation*/212)); |
---|
978 | menubar->Append(viewmenu, wmsg(/*&View*/213)); |
---|
979 | #ifndef PREFDLG |
---|
980 | menubar->Append(ctlmenu, wmsg(/*&Controls*/214)); |
---|
981 | #endif |
---|
982 | menubar->Append(presmenu, wmsg(/*&Presentation*/216)); |
---|
983 | #ifndef __WXMAC__ |
---|
984 | // On wxMac the "About" menu item will be moved elsewhere, so we suppress |
---|
985 | // this menu since it will then be empty. |
---|
986 | wxMenu* helpmenu = new wxMenu; |
---|
987 | helpmenu->Append(wxID_ABOUT); |
---|
988 | |
---|
989 | menubar->Append(helpmenu, wmsg(/*&Help*/215)); |
---|
990 | #endif |
---|
991 | SetMenuBar(menubar); |
---|
992 | } |
---|
993 | |
---|
994 | void MainFrm::MakeToolBar() |
---|
995 | { |
---|
996 | // Make the toolbar. |
---|
997 | |
---|
998 | wxToolBar* toolbar = wxFrame::CreateToolBar(); |
---|
999 | |
---|
1000 | #ifndef __WXGTK20__ |
---|
1001 | toolbar->SetMargins(5, 5); |
---|
1002 | #endif |
---|
1003 | |
---|
1004 | // FIXME: TRANSLATE tooltips |
---|
1005 | toolbar->AddTool(wxID_OPEN, wxT("Open"), TOOL(open), wxT("Open a survey file for viewing")); |
---|
1006 | toolbar->AddTool(menu_PRES_OPEN, wxT("Open presentation"), TOOL(open_pres), wxT("Open a presentation")); |
---|
1007 | toolbar->AddTool(menu_FILE_LOG, wxT("View log"), TOOL(log), wxT("View log from processing survey data")); |
---|
1008 | toolbar->AddSeparator(); |
---|
1009 | toolbar->AddCheckTool(menu_ROTATION_TOGGLE, wxT("Toggle rotation"), TOOL(rotation), wxNullBitmap, wxT("Toggle rotation")); |
---|
1010 | toolbar->AddTool(menu_ORIENT_PLAN, wxT("Plan"), TOOL(plan), wxT("Switch to plan view")); |
---|
1011 | toolbar->AddTool(menu_ORIENT_ELEVATION, wxT("Elevation"), TOOL(elevation), wxT("Switch to elevation view")); |
---|
1012 | toolbar->AddTool(menu_ORIENT_DEFAULTS, wxT("Default view"), TOOL(defaults), wxT("Restore default view")); |
---|
1013 | toolbar->AddSeparator(); |
---|
1014 | toolbar->AddCheckTool(menu_VIEW_SHOW_NAMES, wxT("Names"), TOOL(names), wxNullBitmap, wxT("Show station names")); |
---|
1015 | toolbar->AddCheckTool(menu_VIEW_SHOW_CROSSES, wxT("Crosses"), TOOL(crosses), wxNullBitmap, wxT("Show crosses on stations")); |
---|
1016 | toolbar->AddCheckTool(menu_VIEW_SHOW_ENTRANCES, wxT("Entrances"), TOOL(entrances), wxNullBitmap, wxT("Highlight entrances")); |
---|
1017 | toolbar->AddCheckTool(menu_VIEW_SHOW_FIXED_PTS, wxT("Fixed points"), TOOL(fixed_pts), wxNullBitmap, wxT("Highlight fixed points")); |
---|
1018 | toolbar->AddCheckTool(menu_VIEW_SHOW_EXPORTED_PTS, wxT("Exported points"), TOOL(exported_pts), wxNullBitmap, wxT("Highlight exported stations")); |
---|
1019 | toolbar->AddSeparator(); |
---|
1020 | toolbar->AddCheckTool(menu_VIEW_SHOW_LEGS, wxT("Underground legs"), TOOL(ug_legs), wxNullBitmap, wxT("Show underground surveys")); |
---|
1021 | toolbar->AddCheckTool(menu_VIEW_SHOW_SURFACE, wxT("Surface legs"), TOOL(surface_legs), wxNullBitmap, wxT("Show surface surveys")); |
---|
1022 | toolbar->AddCheckTool(menu_VIEW_SHOW_TUBES, wxT("Tubes"), TOOL(tubes), wxNullBitmap, wxT("Show passage tubes")); |
---|
1023 | toolbar->AddSeparator(); |
---|
1024 | toolbar->AddCheckTool(menu_PRES_FREWIND, wxT("Fast Rewind"), TOOL(pres_frew), wxNullBitmap, wxT("Very Fast Rewind")); |
---|
1025 | toolbar->AddCheckTool(menu_PRES_REWIND, wxT("Rewind"), TOOL(pres_rew), wxNullBitmap, wxT("Fast Rewind")); |
---|
1026 | toolbar->AddCheckTool(menu_PRES_REVERSE, wxT("Backwards"), TOOL(pres_go_back), wxNullBitmap, wxT("Play Backwards")); |
---|
1027 | toolbar->AddCheckTool(menu_PRES_PAUSE, wxT("Pause"), TOOL(pres_pause), wxNullBitmap, wxT("Pause")); |
---|
1028 | toolbar->AddCheckTool(menu_PRES_PLAY, wxT("Go"), TOOL(pres_go), wxNullBitmap, wxT("Play")); |
---|
1029 | toolbar->AddCheckTool(menu_PRES_FF, wxT("FF"), TOOL(pres_ff), wxNullBitmap, wxT("Fast Forward")); |
---|
1030 | toolbar->AddCheckTool(menu_PRES_FFF, wxT("Very FF"), TOOL(pres_fff), wxNullBitmap, wxT("Very Fast Forward")); |
---|
1031 | toolbar->AddTool(wxID_STOP, wxT("Stop"), TOOL(pres_stop), wxT("Stop")); |
---|
1032 | |
---|
1033 | toolbar->AddSeparator(); |
---|
1034 | m_FindBox = new wxTextCtrl(toolbar, textctrl_FIND, wxString(), wxDefaultPosition, |
---|
1035 | wxDefaultSize, wxTE_PROCESS_ENTER); |
---|
1036 | toolbar->AddControl(m_FindBox); |
---|
1037 | /* TRANSLATORS: "Find stations" button tooltip */ |
---|
1038 | toolbar->AddTool(wxID_FIND, wmsg(/*Find*/332), TOOL(find)/*, "Search for station name"*/); |
---|
1039 | /* TRANSLATORS: "Hide stations" button default tooltip */ |
---|
1040 | toolbar->AddTool(button_HIDE, wmsg(/*Hide*/333), TOOL(hideresults)/*, "Hide search results"*/); |
---|
1041 | |
---|
1042 | toolbar->Realize(); |
---|
1043 | } |
---|
1044 | |
---|
1045 | void MainFrm::CreateSidePanel() |
---|
1046 | { |
---|
1047 | m_Splitter = new AvenSplitterWindow(this); |
---|
1048 | |
---|
1049 | m_Notebook = new wxNotebook(m_Splitter, 400, wxDefaultPosition, |
---|
1050 | wxDefaultSize, |
---|
1051 | wxBK_BOTTOM | wxBK_LEFT); |
---|
1052 | m_Notebook->Show(false); |
---|
1053 | |
---|
1054 | wxPanel * panel = new wxPanel(m_Notebook); |
---|
1055 | m_Tree = new AvenTreeCtrl(this, panel); |
---|
1056 | |
---|
1057 | // m_RegexpCheckBox = new wxCheckBox(find_panel, -1, |
---|
1058 | // msg(/*Regular expression*/)); |
---|
1059 | |
---|
1060 | wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL); |
---|
1061 | panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2); |
---|
1062 | panel->SetAutoLayout(true); |
---|
1063 | panel->SetSizer(panel_sizer); |
---|
1064 | // panel_sizer->SetSizeHints(panel); |
---|
1065 | |
---|
1066 | m_Control = new GUIControl(); |
---|
1067 | m_Gfx = new GfxCore(this, m_Splitter, m_Control); |
---|
1068 | m_Control->SetView(m_Gfx); |
---|
1069 | |
---|
1070 | // Presentation panel: |
---|
1071 | wxPanel * prespanel = new wxPanel(m_Notebook); |
---|
1072 | |
---|
1073 | m_PresList = new AvenPresList(this, prespanel, m_Gfx); |
---|
1074 | |
---|
1075 | wxBoxSizer *pres_panel_sizer = new wxBoxSizer(wxVERTICAL); |
---|
1076 | pres_panel_sizer->Add(m_PresList, 1, wxALL | wxEXPAND, 2); |
---|
1077 | prespanel->SetAutoLayout(true); |
---|
1078 | prespanel->SetSizer(pres_panel_sizer); |
---|
1079 | |
---|
1080 | // Overall tabbed structure: |
---|
1081 | // FIXME: this assumes images are 15x15 |
---|
1082 | wxImageList* image_list = new wxImageList(15, 15); |
---|
1083 | image_list->Add(TOOL(survey_tree)); |
---|
1084 | image_list->Add(TOOL(pres_tree)); |
---|
1085 | m_Notebook->SetImageList(image_list); |
---|
1086 | /* TRANSLATORS: labels for tabbed side panel this is for the tab with the |
---|
1087 | * tree hierarchy of survey station names */ |
---|
1088 | m_Notebook->AddPage(panel, wmsg(/*Surveys*/376), true, 0); |
---|
1089 | m_Notebook->AddPage(prespanel, wmsg(/*Presentation*/377), false, 1); |
---|
1090 | |
---|
1091 | m_Splitter->Initialize(m_Gfx); |
---|
1092 | } |
---|
1093 | |
---|
1094 | bool MainFrm::LoadData(const wxString& file, const wxString & prefix) |
---|
1095 | { |
---|
1096 | // Load survey data from file, centre the dataset around the origin, |
---|
1097 | // and prepare the data for drawing. |
---|
1098 | |
---|
1099 | #if 0 |
---|
1100 | wxStopWatch timer; |
---|
1101 | timer.Start(); |
---|
1102 | #endif |
---|
1103 | |
---|
1104 | // Load the processed survey data. |
---|
1105 | img* survey = img_open_survey(file.mb_str(), prefix.mb_str()); |
---|
1106 | if (!survey) { |
---|
1107 | wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str()); |
---|
1108 | wxGetApp().ReportError(m); |
---|
1109 | return false; |
---|
1110 | } |
---|
1111 | |
---|
1112 | m_IsExtendedElevation = survey->is_extended_elevation; |
---|
1113 | |
---|
1114 | m_Tree->DeleteAllItems(); |
---|
1115 | |
---|
1116 | // Create a list of all the leg vertices, counting them and finding the |
---|
1117 | // extent of the survey at the same time. |
---|
1118 | |
---|
1119 | m_NumFixedPts = 0; |
---|
1120 | m_NumExportedPts = 0; |
---|
1121 | m_NumEntrances = 0; |
---|
1122 | m_HasUndergroundLegs = false; |
---|
1123 | m_HasSplays = false; |
---|
1124 | m_HasSurfaceLegs = false; |
---|
1125 | m_HasErrorInformation = false; |
---|
1126 | |
---|
1127 | // FIXME: discard existing presentation? ask user about saving if we do! |
---|
1128 | |
---|
1129 | // Delete any existing list entries. |
---|
1130 | m_Labels.clear(); |
---|
1131 | |
---|
1132 | Double xmin = DBL_MAX; |
---|
1133 | Double xmax = -DBL_MAX; |
---|
1134 | Double ymin = DBL_MAX; |
---|
1135 | Double ymax = -DBL_MAX; |
---|
1136 | Double zmin = DBL_MAX; |
---|
1137 | Double zmax = -DBL_MAX; |
---|
1138 | |
---|
1139 | m_DepthMin = DBL_MAX; |
---|
1140 | Double depthmax = -DBL_MAX; |
---|
1141 | |
---|
1142 | m_DateMin = INT_MAX; |
---|
1143 | int datemax = -1; |
---|
1144 | complete_dateinfo = true; |
---|
1145 | |
---|
1146 | traverses.clear(); |
---|
1147 | surface_traverses.clear(); |
---|
1148 | tubes.clear(); |
---|
1149 | |
---|
1150 | // Ultimately we probably want different types (subclasses perhaps?) for |
---|
1151 | // underground and surface data, so we don't need to store LRUD for surface |
---|
1152 | // stuff. |
---|
1153 | traverse * current_traverse = NULL; |
---|
1154 | traverse * current_surface_traverse = NULL; |
---|
1155 | vector<XSect> * current_tube = NULL; |
---|
1156 | |
---|
1157 | map<wxString, LabelInfo *> labelmap; |
---|
1158 | list<LabelInfo*>::const_iterator last_mapped_label = m_Labels.begin(); |
---|
1159 | |
---|
1160 | int result; |
---|
1161 | img_point prev_pt = {0,0,0}; |
---|
1162 | bool current_polyline_is_surface = false; |
---|
1163 | bool current_polyline_is_splay = false; |
---|
1164 | bool pending_move = false; |
---|
1165 | // When a traverse is split between surface and underground, we split it |
---|
1166 | // into contiguous traverses of each, but we need to track these so we can |
---|
1167 | // assign the error statistics to all of them. So we keep counts of how |
---|
1168 | // many surface_traverses and traverses we've generated for the current |
---|
1169 | // traverse. |
---|
1170 | size_t n_traverses = 0; |
---|
1171 | size_t n_surface_traverses = 0; |
---|
1172 | do { |
---|
1173 | #if 0 |
---|
1174 | if (++items % 200 == 0) { |
---|
1175 | long pos = ftell(survey->fh); |
---|
1176 | int progress = int((double(pos) / double(file_size)) * 100.0); |
---|
1177 | // SetProgress(progress); |
---|
1178 | } |
---|
1179 | #endif |
---|
1180 | |
---|
1181 | img_point pt; |
---|
1182 | result = img_read_item(survey, &pt); |
---|
1183 | switch (result) { |
---|
1184 | case img_MOVE: |
---|
1185 | n_traverses = n_surface_traverses = 0; |
---|
1186 | pending_move = true; |
---|
1187 | prev_pt = pt; |
---|
1188 | break; |
---|
1189 | |
---|
1190 | case img_LINE: { |
---|
1191 | // Update survey extents. |
---|
1192 | if (pt.x < xmin) xmin = pt.x; |
---|
1193 | if (pt.x > xmax) xmax = pt.x; |
---|
1194 | if (pt.y < ymin) ymin = pt.y; |
---|
1195 | if (pt.y > ymax) ymax = pt.y; |
---|
1196 | if (pt.z < zmin) zmin = pt.z; |
---|
1197 | if (pt.z > zmax) zmax = pt.z; |
---|
1198 | |
---|
1199 | int date = survey->days1; |
---|
1200 | if (date != -1) { |
---|
1201 | date += (survey->days2 - date) / 2; |
---|
1202 | if (date < m_DateMin) m_DateMin = date; |
---|
1203 | if (date > datemax) datemax = date; |
---|
1204 | } else { |
---|
1205 | complete_dateinfo = false; |
---|
1206 | } |
---|
1207 | |
---|
1208 | if (survey->flags & img_FLAG_SPLAY) |
---|
1209 | m_HasSplays = true; |
---|
1210 | bool is_surface = (survey->flags & img_FLAG_SURFACE); |
---|
1211 | bool is_splay = (survey->flags & img_FLAG_SPLAY); |
---|
1212 | if (!is_surface) { |
---|
1213 | if (pt.z < m_DepthMin) m_DepthMin = pt.z; |
---|
1214 | if (pt.z > depthmax) depthmax = pt.z; |
---|
1215 | } |
---|
1216 | if (pending_move || current_polyline_is_surface != is_surface || current_polyline_is_splay != is_splay) { |
---|
1217 | if (!current_polyline_is_surface && current_traverse) { |
---|
1218 | //FixLRUD(*current_traverse); |
---|
1219 | } |
---|
1220 | |
---|
1221 | // Start new traverse (surface or underground). |
---|
1222 | if (is_surface) { |
---|
1223 | m_HasSurfaceLegs = true; |
---|
1224 | surface_traverses.push_back(traverse()); |
---|
1225 | current_surface_traverse = &surface_traverses.back(); |
---|
1226 | ++n_surface_traverses; |
---|
1227 | } else { |
---|
1228 | m_HasUndergroundLegs = true; |
---|
1229 | traverses.push_back(traverse()); |
---|
1230 | current_traverse = &traverses.back(); |
---|
1231 | current_traverse->isSplay = is_splay; |
---|
1232 | ++n_traverses; |
---|
1233 | // The previous point was at a surface->ug transition. |
---|
1234 | if (current_polyline_is_surface) { |
---|
1235 | if (prev_pt.z < m_DepthMin) m_DepthMin = prev_pt.z; |
---|
1236 | if (prev_pt.z > depthmax) depthmax = prev_pt.z; |
---|
1237 | } |
---|
1238 | } |
---|
1239 | |
---|
1240 | current_polyline_is_surface = is_surface; |
---|
1241 | current_polyline_is_splay = is_splay; |
---|
1242 | |
---|
1243 | if (pending_move) { |
---|
1244 | // Update survey extents. We only need to do this if |
---|
1245 | // there's a pending move, since for a surface <-> |
---|
1246 | // underground transition, we'll already have handled |
---|
1247 | // this point. |
---|
1248 | if (prev_pt.x < xmin) xmin = prev_pt.x; |
---|
1249 | if (prev_pt.x > xmax) xmax = prev_pt.x; |
---|
1250 | if (prev_pt.y < ymin) ymin = prev_pt.y; |
---|
1251 | if (prev_pt.y > ymax) ymax = prev_pt.y; |
---|
1252 | if (prev_pt.z < zmin) zmin = prev_pt.z; |
---|
1253 | if (prev_pt.z > zmax) zmax = prev_pt.z; |
---|
1254 | } |
---|
1255 | |
---|
1256 | if (is_surface) { |
---|
1257 | current_surface_traverse->push_back(PointInfo(prev_pt)); |
---|
1258 | } else { |
---|
1259 | current_traverse->push_back(PointInfo(prev_pt)); |
---|
1260 | } |
---|
1261 | } |
---|
1262 | |
---|
1263 | if (is_surface) { |
---|
1264 | current_surface_traverse->push_back(PointInfo(pt, date)); |
---|
1265 | } else { |
---|
1266 | current_traverse->push_back(PointInfo(pt, date)); |
---|
1267 | } |
---|
1268 | |
---|
1269 | prev_pt = pt; |
---|
1270 | pending_move = false; |
---|
1271 | break; |
---|
1272 | } |
---|
1273 | |
---|
1274 | case img_LABEL: { |
---|
1275 | wxString s(survey->label, wxConvUTF8); |
---|
1276 | if (s.empty()) { |
---|
1277 | // If label isn't valid UTF-8 then this conversion will |
---|
1278 | // give an empty string. In this case, assume that the |
---|
1279 | // label is CP1252 (the Microsoft superset of ISO8859-1). |
---|
1280 | static wxCSConv ConvCP1252(wxFONTENCODING_CP1252); |
---|
1281 | s = wxString(survey->label, ConvCP1252); |
---|
1282 | if (s.empty()) { |
---|
1283 | // Or if that doesn't work (ConvCP1252 doesn't like |
---|
1284 | // strings with some bytes in) let's just go for |
---|
1285 | // ISO8859-1. |
---|
1286 | s = wxString(survey->label, wxConvISO8859_1); |
---|
1287 | } |
---|
1288 | } |
---|
1289 | int flags = img2aven(survey->flags); |
---|
1290 | LabelInfo* label = new LabelInfo(pt, s, flags); |
---|
1291 | if (label->IsEntrance()) { |
---|
1292 | m_NumEntrances++; |
---|
1293 | } |
---|
1294 | if (label->IsFixedPt()) { |
---|
1295 | m_NumFixedPts++; |
---|
1296 | } |
---|
1297 | if (label->IsExportedPt()) { |
---|
1298 | m_NumExportedPts++; |
---|
1299 | } |
---|
1300 | m_Labels.push_back(label); |
---|
1301 | break; |
---|
1302 | } |
---|
1303 | |
---|
1304 | case img_XSECT: { |
---|
1305 | if (!current_tube) { |
---|
1306 | // Start new current_tube. |
---|
1307 | tubes.push_back(vector<XSect>()); |
---|
1308 | current_tube = &tubes.back(); |
---|
1309 | } |
---|
1310 | |
---|
1311 | LabelInfo * lab; |
---|
1312 | wxString label(survey->label, wxConvUTF8); |
---|
1313 | map<wxString, LabelInfo *>::const_iterator p; |
---|
1314 | p = labelmap.find(label); |
---|
1315 | if (p != labelmap.end()) { |
---|
1316 | lab = p->second; |
---|
1317 | } else { |
---|
1318 | // Initialise labelmap lazily - we may have no |
---|
1319 | // cross-sections. |
---|
1320 | list<LabelInfo*>::const_iterator i; |
---|
1321 | if (labelmap.empty()) { |
---|
1322 | i = m_Labels.begin(); |
---|
1323 | } else { |
---|
1324 | i = last_mapped_label; |
---|
1325 | ++i; |
---|
1326 | } |
---|
1327 | while (i != m_Labels.end() && (*i)->GetText() != label) { |
---|
1328 | labelmap[(*i)->GetText()] = *i; |
---|
1329 | ++i; |
---|
1330 | } |
---|
1331 | last_mapped_label = i; |
---|
1332 | if (i == m_Labels.end()) { |
---|
1333 | // Unattached cross-section - ignore for now. |
---|
1334 | printf("unattached cross-section\n"); |
---|
1335 | if (current_tube->size() <= 1) |
---|
1336 | tubes.resize(tubes.size() - 1); |
---|
1337 | current_tube = NULL; |
---|
1338 | if (!m_Labels.empty()) |
---|
1339 | --last_mapped_label; |
---|
1340 | break; |
---|
1341 | } |
---|
1342 | lab = *i; |
---|
1343 | labelmap[label] = lab; |
---|
1344 | } |
---|
1345 | |
---|
1346 | int date = survey->days1; |
---|
1347 | if (date != -1) { |
---|
1348 | date += (survey->days2 - date) / 2; |
---|
1349 | if (date < m_DateMin) m_DateMin = date; |
---|
1350 | if (date > datemax) datemax = date; |
---|
1351 | } |
---|
1352 | |
---|
1353 | current_tube->push_back(XSect(*lab, date, survey->l, survey->r, survey->u, survey->d)); |
---|
1354 | break; |
---|
1355 | } |
---|
1356 | |
---|
1357 | case img_XSECT_END: |
---|
1358 | // Finish off current_tube. |
---|
1359 | // If there's only one cross-section in the tube, just |
---|
1360 | // discard it for now. FIXME: we should handle this |
---|
1361 | // when we come to skinning the tubes. |
---|
1362 | if (current_tube && current_tube->size() <= 1) |
---|
1363 | tubes.resize(tubes.size() - 1); |
---|
1364 | current_tube = NULL; |
---|
1365 | break; |
---|
1366 | |
---|
1367 | case img_ERROR_INFO: { |
---|
1368 | if (survey->E == 0.0) { |
---|
1369 | // Currently cavern doesn't spot all articulating traverses |
---|
1370 | // so we assume that any traverse with no error isn't part |
---|
1371 | // of a loop. FIXME: fix cavern! |
---|
1372 | break; |
---|
1373 | } |
---|
1374 | m_HasErrorInformation = true; |
---|
1375 | list<traverse>::reverse_iterator t; |
---|
1376 | t = surface_traverses.rbegin(); |
---|
1377 | while (n_surface_traverses) { |
---|
1378 | assert(t != surface_traverses.rend()); |
---|
1379 | t->n_legs = survey->n_legs; |
---|
1380 | t->length = survey->length; |
---|
1381 | t->E = survey->E; |
---|
1382 | t->H = survey->H; |
---|
1383 | t->V = survey->V; |
---|
1384 | --n_surface_traverses; |
---|
1385 | ++t; |
---|
1386 | } |
---|
1387 | t = traverses.rbegin(); |
---|
1388 | while (n_traverses) { |
---|
1389 | assert(t != traverses.rend()); |
---|
1390 | t->n_legs = survey->n_legs; |
---|
1391 | t->length = survey->length; |
---|
1392 | t->E = survey->E; |
---|
1393 | t->H = survey->H; |
---|
1394 | t->V = survey->V; |
---|
1395 | --n_traverses; |
---|
1396 | ++t; |
---|
1397 | } |
---|
1398 | break; |
---|
1399 | } |
---|
1400 | |
---|
1401 | case img_BAD: { |
---|
1402 | m_Labels.clear(); |
---|
1403 | |
---|
1404 | // FIXME: Do we need to reset all these? - Olly |
---|
1405 | m_NumFixedPts = 0; |
---|
1406 | m_NumExportedPts = 0; |
---|
1407 | m_NumEntrances = 0; |
---|
1408 | m_HasUndergroundLegs = false; |
---|
1409 | m_HasSplays = false; |
---|
1410 | m_HasSurfaceLegs = false; |
---|
1411 | |
---|
1412 | img_close(survey); |
---|
1413 | |
---|
1414 | wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str()); |
---|
1415 | wxGetApp().ReportError(m); |
---|
1416 | |
---|
1417 | return false; |
---|
1418 | } |
---|
1419 | |
---|
1420 | default: |
---|
1421 | break; |
---|
1422 | } |
---|
1423 | } while (result != img_STOP); |
---|
1424 | |
---|
1425 | if (!current_polyline_is_surface && current_traverse) { |
---|
1426 | //FixLRUD(*current_traverse); |
---|
1427 | } |
---|
1428 | |
---|
1429 | // Finish off current_tube. |
---|
1430 | // If there's only one cross-section in the tube, just |
---|
1431 | // discard it for now. FIXME: we should handle this |
---|
1432 | // when we come to skinning the tubes. |
---|
1433 | if (current_tube && current_tube->size() <= 1) |
---|
1434 | tubes.resize(tubes.size() - 1); |
---|
1435 | |
---|
1436 | separator = survey->separator; |
---|
1437 | m_Title = wxString(survey->title, wxConvUTF8); |
---|
1438 | m_DateStamp_numeric = survey->datestamp_numeric; |
---|
1439 | if (survey->cs) { |
---|
1440 | m_cs_proj = wxString(survey->cs, wxConvUTF8); |
---|
1441 | } else { |
---|
1442 | m_cs_proj = wxString(); |
---|
1443 | } |
---|
1444 | if (strcmp(survey->datestamp, "?") == 0) { |
---|
1445 | /* TRANSLATORS: used a processed survey with no processing date/time info */ |
---|
1446 | m_DateStamp = wmsg(/*Date and time not available.*/108); |
---|
1447 | } else if (survey->datestamp[0] == '@') { |
---|
1448 | const struct tm * tm = localtime(&m_DateStamp_numeric); |
---|
1449 | char buf[256]; |
---|
1450 | /* TRANSLATORS: This is the date format string used to timestamp .3d |
---|
1451 | * files internally. Probably best to keep it the same for all |
---|
1452 | * translations. */ |
---|
1453 | strftime(buf, 256, msg(/*%a,%Y.%m.%d %H:%M:%S %Z*/107), tm); |
---|
1454 | m_DateStamp = wxString(buf, wxConvUTF8); |
---|
1455 | } |
---|
1456 | if (m_DateStamp.empty()) { |
---|
1457 | m_DateStamp = wxString(survey->datestamp, wxConvUTF8); |
---|
1458 | } |
---|
1459 | img_close(survey); |
---|
1460 | |
---|
1461 | // Check we've actually loaded some legs or stations! |
---|
1462 | if (!m_HasUndergroundLegs && !m_HasSurfaceLegs && m_Labels.empty()) { |
---|
1463 | wxString m = wxString::Format(wmsg(/*No survey data in 3d file “%s”*/202), file.c_str()); |
---|
1464 | wxGetApp().ReportError(m); |
---|
1465 | return false; |
---|
1466 | } |
---|
1467 | |
---|
1468 | if (traverses.empty() && surface_traverses.empty()) { |
---|
1469 | // No legs, so get survey extents from stations |
---|
1470 | list<LabelInfo*>::const_iterator i; |
---|
1471 | for (i = m_Labels.begin(); i != m_Labels.end(); ++i) { |
---|
1472 | if ((*i)->GetX() < xmin) xmin = (*i)->GetX(); |
---|
1473 | if ((*i)->GetX() > xmax) xmax = (*i)->GetX(); |
---|
1474 | if ((*i)->GetY() < ymin) ymin = (*i)->GetY(); |
---|
1475 | if ((*i)->GetY() > ymax) ymax = (*i)->GetY(); |
---|
1476 | if ((*i)->GetZ() < zmin) zmin = (*i)->GetZ(); |
---|
1477 | if ((*i)->GetZ() > zmax) zmax = (*i)->GetZ(); |
---|
1478 | } |
---|
1479 | } |
---|
1480 | |
---|
1481 | m_Ext.assign(xmax - xmin, ymax - ymin, zmax - zmin); |
---|
1482 | |
---|
1483 | if (datemax < m_DateMin) m_DateMin = datemax; |
---|
1484 | m_DateExt = datemax - m_DateMin; |
---|
1485 | |
---|
1486 | // Centre the dataset around the origin. |
---|
1487 | CentreDataset(Vector3(xmin, ymin, zmin)); |
---|
1488 | |
---|
1489 | if (depthmax < m_DepthMin) { |
---|
1490 | m_DepthMin = 0; |
---|
1491 | m_DepthExt = 0; |
---|
1492 | } else { |
---|
1493 | m_DepthExt = depthmax - m_DepthMin; |
---|
1494 | m_DepthMin -= m_Offsets.GetZ(); |
---|
1495 | } |
---|
1496 | |
---|
1497 | #if 0 |
---|
1498 | printf("time to load = %.3f\n", (double)timer.Time()); |
---|
1499 | #endif |
---|
1500 | |
---|
1501 | // Update window title. |
---|
1502 | SetTitle(m_Title + " - "APP_NAME); |
---|
1503 | |
---|
1504 | // Sort the labels ready for filling the tree. |
---|
1505 | m_Labels.sort(LabelCmp(separator)); |
---|
1506 | |
---|
1507 | // Fill the tree of stations and prefixes. |
---|
1508 | FillTree(wxFileNameFromPath(file)); |
---|
1509 | |
---|
1510 | // Sort labels so that entrances are displayed in preference, |
---|
1511 | // then fixed points, then exported points, then other points. |
---|
1512 | // |
---|
1513 | // Also sort by leaf name so that we'll tend to choose labels |
---|
1514 | // from different surveys, rather than labels from surveys which |
---|
1515 | // are earlier in the list. |
---|
1516 | m_Labels.sort(LabelPlotCmp(separator)); |
---|
1517 | |
---|
1518 | if (!m_FindBox->GetValue().empty()) { |
---|
1519 | // Highlight any stations matching the current search. |
---|
1520 | DoFind(); |
---|
1521 | } |
---|
1522 | |
---|
1523 | return true; |
---|
1524 | } |
---|
1525 | |
---|
1526 | #if 0 |
---|
1527 | // Run along a newly read in traverse and make up plausible LRUD where |
---|
1528 | // it is missing. |
---|
1529 | void |
---|
1530 | MainFrm::FixLRUD(traverse & centreline) |
---|
1531 | { |
---|
1532 | assert(centreline.size() > 1); |
---|
1533 | |
---|
1534 | Double last_size = 0; |
---|
1535 | vector<PointInfo>::iterator i = centreline.begin(); |
---|
1536 | while (i != centreline.end()) { |
---|
1537 | // Get the coordinates of this vertex. |
---|
1538 | Point & pt_v = *i++; |
---|
1539 | Double size; |
---|
1540 | |
---|
1541 | if (i != centreline.end()) { |
---|
1542 | Double h = sqrd(i->GetX() - pt_v.GetX()) + |
---|
1543 | sqrd(i->GetY() - pt_v.GetY()); |
---|
1544 | Double v = sqrd(i->GetZ() - pt_v.GetZ()); |
---|
1545 | if (h + v > 30.0 * 30.0) { |
---|
1546 | Double scale = 30.0 / sqrt(h + v); |
---|
1547 | h *= scale; |
---|
1548 | v *= scale; |
---|
1549 | } |
---|
1550 | size = sqrt(h + v / 9); |
---|
1551 | size /= 4; |
---|
1552 | if (i == centreline.begin() + 1) { |
---|
1553 | // First segment. |
---|
1554 | last_size = size; |
---|
1555 | } else { |
---|
1556 | // Intermediate segment. |
---|
1557 | swap(size, last_size); |
---|
1558 | size += last_size; |
---|
1559 | size /= 2; |
---|
1560 | } |
---|
1561 | } else { |
---|
1562 | // Last segment. |
---|
1563 | size = last_size; |
---|
1564 | } |
---|
1565 | |
---|
1566 | Double & l = pt_v.l; |
---|
1567 | Double & r = pt_v.r; |
---|
1568 | Double & u = pt_v.u; |
---|
1569 | Double & d = pt_v.d; |
---|
1570 | |
---|
1571 | if (l == 0 && r == 0 && u == 0 && d == 0) { |
---|
1572 | l = r = u = d = -size; |
---|
1573 | } else { |
---|
1574 | if (l < 0 && r < 0) { |
---|
1575 | l = r = -size; |
---|
1576 | } else if (l < 0) { |
---|
1577 | l = -(2 * size - r); |
---|
1578 | if (l >= 0) l = -0.01; |
---|
1579 | } else if (r < 0) { |
---|
1580 | r = -(2 * size - l); |
---|
1581 | if (r >= 0) r = -0.01; |
---|
1582 | } |
---|
1583 | if (u < 0 && d < 0) { |
---|
1584 | u = d = -size; |
---|
1585 | } else if (u < 0) { |
---|
1586 | u = -(2 * size - d); |
---|
1587 | if (u >= 0) u = -0.01; |
---|
1588 | } else if (d < 0) { |
---|
1589 | d = -(2 * size - u); |
---|
1590 | if (d >= 0) d = -0.01; |
---|
1591 | } |
---|
1592 | } |
---|
1593 | } |
---|
1594 | } |
---|
1595 | #endif |
---|
1596 | |
---|
1597 | void MainFrm::FillTree(const wxString & root_name) |
---|
1598 | { |
---|
1599 | // Create the root of the tree. |
---|
1600 | wxTreeItemId treeroot = m_Tree->AddRoot(root_name); |
---|
1601 | |
---|
1602 | // Fill the tree of stations and prefixes. |
---|
1603 | stack<wxTreeItemId> previous_ids; |
---|
1604 | wxString current_prefix; |
---|
1605 | wxTreeItemId current_id = treeroot; |
---|
1606 | |
---|
1607 | list<LabelInfo*>::iterator pos = m_Labels.begin(); |
---|
1608 | while (pos != m_Labels.end()) { |
---|
1609 | LabelInfo* label = *pos++; |
---|
1610 | |
---|
1611 | if (label->IsAnon()) continue; |
---|
1612 | |
---|
1613 | // Determine the current prefix. |
---|
1614 | wxString prefix = label->GetText().BeforeLast(separator); |
---|
1615 | |
---|
1616 | // Determine if we're still on the same prefix. |
---|
1617 | if (prefix == current_prefix) { |
---|
1618 | // no need to fiddle with branches... |
---|
1619 | } |
---|
1620 | // If not, then see if we've descended to a new prefix. |
---|
1621 | else if (prefix.length() > current_prefix.length() && |
---|
1622 | prefix.StartsWith(current_prefix) && |
---|
1623 | (prefix[current_prefix.length()] == separator || |
---|
1624 | current_prefix.empty())) { |
---|
1625 | // We have, so start as many new branches as required. |
---|
1626 | int current_prefix_length = current_prefix.length(); |
---|
1627 | current_prefix = prefix; |
---|
1628 | size_t next_dot = current_prefix_length; |
---|
1629 | if (!next_dot) --next_dot; |
---|
1630 | do { |
---|
1631 | size_t prev_dot = next_dot + 1; |
---|
1632 | |
---|
1633 | // Extract the next bit of prefix. |
---|
1634 | next_dot = prefix.find(separator, prev_dot + 1); |
---|
1635 | |
---|
1636 | wxString bit = prefix.substr(prev_dot, next_dot - prev_dot); |
---|
1637 | assert(!bit.empty()); |
---|
1638 | |
---|
1639 | // Add the current tree ID to the stack. |
---|
1640 | previous_ids.push(current_id); |
---|
1641 | |
---|
1642 | // Append the new item to the tree and set this as the current branch. |
---|
1643 | current_id = m_Tree->AppendItem(current_id, bit); |
---|
1644 | m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot))); |
---|
1645 | } while (next_dot != wxString::npos); |
---|
1646 | } |
---|
1647 | // Otherwise, we must have moved up, and possibly then down again. |
---|
1648 | else { |
---|
1649 | size_t count = 0; |
---|
1650 | bool ascent_only = (prefix.length() < current_prefix.length() && |
---|
1651 | current_prefix.StartsWith(prefix) && |
---|
1652 | (current_prefix[prefix.length()] == separator || |
---|
1653 | prefix.empty())); |
---|
1654 | if (!ascent_only) { |
---|
1655 | // Find out how much of the current prefix and the new prefix |
---|
1656 | // are the same. |
---|
1657 | // Note that we require a match of a whole number of parts |
---|
1658 | // between dots! |
---|
1659 | size_t n = min(prefix.length(), current_prefix.length()); |
---|
1660 | size_t i; |
---|
1661 | for (i = 0; i < n && prefix[i] == current_prefix[i]; ++i) { |
---|
1662 | if (prefix[i] == separator) count = i + 1; |
---|
1663 | } |
---|
1664 | } else { |
---|
1665 | count = prefix.length() + 1; |
---|
1666 | } |
---|
1667 | |
---|
1668 | // Extract the part of the current prefix after the bit (if any) |
---|
1669 | // which has matched. |
---|
1670 | // This gives the prefixes to ascend over. |
---|
1671 | wxString prefixes_ascended = current_prefix.substr(count); |
---|
1672 | |
---|
1673 | // Count the number of prefixes to ascend over. |
---|
1674 | int num_prefixes = prefixes_ascended.Freq(separator); |
---|
1675 | |
---|
1676 | // Reverse up over these prefixes. |
---|
1677 | for (int i = 1; i <= num_prefixes; i++) { |
---|
1678 | previous_ids.pop(); |
---|
1679 | } |
---|
1680 | current_id = previous_ids.top(); |
---|
1681 | previous_ids.pop(); |
---|
1682 | |
---|
1683 | if (!ascent_only) { |
---|
1684 | // Add branches for this new part. |
---|
1685 | size_t next_dot = count - 1; |
---|
1686 | do { |
---|
1687 | size_t prev_dot = next_dot + 1; |
---|
1688 | |
---|
1689 | // Extract the next bit of prefix. |
---|
1690 | next_dot = prefix.find(separator, prev_dot + 1); |
---|
1691 | |
---|
1692 | wxString bit = prefix.substr(prev_dot, next_dot - prev_dot); |
---|
1693 | assert(!bit.empty()); |
---|
1694 | |
---|
1695 | // Add the current tree ID to the stack. |
---|
1696 | previous_ids.push(current_id); |
---|
1697 | |
---|
1698 | // Append the new item to the tree and set this as the current branch. |
---|
1699 | current_id = m_Tree->AppendItem(current_id, bit); |
---|
1700 | m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot))); |
---|
1701 | } while (next_dot != wxString::npos); |
---|
1702 | } |
---|
1703 | |
---|
1704 | current_prefix = prefix; |
---|
1705 | } |
---|
1706 | |
---|
1707 | // Now add the leaf. |
---|
1708 | wxString bit = label->GetText().AfterLast(separator); |
---|
1709 | assert(!bit.empty()); |
---|
1710 | wxTreeItemId id = m_Tree->AppendItem(current_id, bit); |
---|
1711 | m_Tree->SetItemData(id, new TreeData(label)); |
---|
1712 | label->tree_id = id; |
---|
1713 | // Set the colour for an item in the survey tree. |
---|
1714 | if (label->IsEntrance()) { |
---|
1715 | // Entrances are green (like entrance blobs). |
---|
1716 | m_Tree->SetItemTextColour(id, wxColour(0, 255, 40)); |
---|
1717 | } else if (label->IsSurface()) { |
---|
1718 | // Surface stations are dark green. |
---|
1719 | m_Tree->SetItemTextColour(id, wxColour(49, 158, 79)); |
---|
1720 | } |
---|
1721 | } |
---|
1722 | |
---|
1723 | m_Tree->Expand(treeroot); |
---|
1724 | m_Tree->SetEnabled(); |
---|
1725 | } |
---|
1726 | |
---|
1727 | void MainFrm::CentreDataset(const Vector3 & vmin) |
---|
1728 | { |
---|
1729 | // Centre the dataset around the origin. |
---|
1730 | |
---|
1731 | m_Offsets = vmin + (m_Ext * 0.5); |
---|
1732 | |
---|
1733 | list<traverse>::iterator t = traverses.begin(); |
---|
1734 | while (t != traverses.end()) { |
---|
1735 | assert(t->size() > 1); |
---|
1736 | vector<PointInfo>::iterator pos = t->begin(); |
---|
1737 | while (pos != t->end()) { |
---|
1738 | Point & point = *pos++; |
---|
1739 | point -= m_Offsets; |
---|
1740 | } |
---|
1741 | ++t; |
---|
1742 | } |
---|
1743 | |
---|
1744 | t = surface_traverses.begin(); |
---|
1745 | while (t != surface_traverses.end()) { |
---|
1746 | assert(t->size() > 1); |
---|
1747 | vector<PointInfo>::iterator pos = t->begin(); |
---|
1748 | while (pos != t->end()) { |
---|
1749 | Point & point = *pos++; |
---|
1750 | point -= m_Offsets; |
---|
1751 | } |
---|
1752 | ++t; |
---|
1753 | } |
---|
1754 | |
---|
1755 | list<vector<XSect> >::iterator i = tubes.begin(); |
---|
1756 | while (i != tubes.end()) { |
---|
1757 | assert(i->size() > 1); |
---|
1758 | vector<XSect>::iterator pos = i->begin(); |
---|
1759 | while (pos != i->end()) { |
---|
1760 | Point & point = *pos++; |
---|
1761 | point -= m_Offsets; |
---|
1762 | } |
---|
1763 | ++i; |
---|
1764 | } |
---|
1765 | |
---|
1766 | list<LabelInfo*>::iterator lpos = m_Labels.begin(); |
---|
1767 | while (lpos != m_Labels.end()) { |
---|
1768 | Point & point = **lpos++; |
---|
1769 | point -= m_Offsets; |
---|
1770 | } |
---|
1771 | } |
---|
1772 | |
---|
1773 | void MainFrm::OnMRUFile(wxCommandEvent& event) |
---|
1774 | { |
---|
1775 | wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1)); |
---|
1776 | if (!f.empty()) OpenFile(f); |
---|
1777 | } |
---|
1778 | |
---|
1779 | void MainFrm::AddToFileHistory(const wxString & file) |
---|
1780 | { |
---|
1781 | if (wxIsAbsolutePath(file)) { |
---|
1782 | m_history.AddFileToHistory(file); |
---|
1783 | } else { |
---|
1784 | wxString abs = wxGetCwd(); |
---|
1785 | abs += wxCONFIG_PATH_SEPARATOR; |
---|
1786 | abs += file; |
---|
1787 | m_history.AddFileToHistory(abs); |
---|
1788 | } |
---|
1789 | wxConfigBase *b = wxConfigBase::Get(); |
---|
1790 | m_history.Save(*b); |
---|
1791 | b->Flush(); |
---|
1792 | } |
---|
1793 | |
---|
1794 | void MainFrm::OpenFile(const wxString& file, const wxString& survey) |
---|
1795 | { |
---|
1796 | wxBusyCursor hourglass; |
---|
1797 | |
---|
1798 | // Check if this is an unprocessed survey data file. |
---|
1799 | if (file.length() > 4 && file[file.length() - 4] == '.') { |
---|
1800 | wxString ext(file, file.length() - 3, 3); |
---|
1801 | ext.MakeLower(); |
---|
1802 | if (ext == wxT("svx") || ext == wxT("dat") || ext == wxT("mak")) { |
---|
1803 | CavernLogWindow * log = new CavernLogWindow(this, survey, m_Splitter); |
---|
1804 | wxWindow * win = m_Splitter->GetWindow1(); |
---|
1805 | m_Splitter->ReplaceWindow(win, log); |
---|
1806 | if (m_Splitter->GetWindow2() == NULL) { |
---|
1807 | if (win != m_Gfx) win->Destroy(); |
---|
1808 | } else { |
---|
1809 | if (m_Splitter->IsSplit()) m_Splitter->Unsplit(); |
---|
1810 | } |
---|
1811 | |
---|
1812 | int result = log->process(file); |
---|
1813 | if (result < 0) { |
---|
1814 | // Error running cavern or processing data. |
---|
1815 | return; |
---|
1816 | } |
---|
1817 | |
---|
1818 | AddToFileHistory(file); |
---|
1819 | wxString file3d(file, 0, file.length() - 3); |
---|
1820 | file3d.append(wxT("3d")); |
---|
1821 | if (!LoadData(file3d, survey)) |
---|
1822 | return; |
---|
1823 | if (result == 0) { |
---|
1824 | InitialiseAfterLoad(file); |
---|
1825 | } |
---|
1826 | return; |
---|
1827 | } |
---|
1828 | } |
---|
1829 | |
---|
1830 | if (!LoadData(file, survey)) |
---|
1831 | return; |
---|
1832 | AddToFileHistory(file); |
---|
1833 | InitialiseAfterLoad(file); |
---|
1834 | |
---|
1835 | // If aven is showing the log for a .svx file and you load a .3d file, then |
---|
1836 | // at this point m_Log will be the log window for the .svx file, so destroy |
---|
1837 | // it - it should never legitimately be set if we get here. |
---|
1838 | if (m_Log) { |
---|
1839 | m_Log->Destroy(); |
---|
1840 | m_Log = NULL; |
---|
1841 | } |
---|
1842 | } |
---|
1843 | |
---|
1844 | void MainFrm::InitialiseAfterLoad(const wxString & file) |
---|
1845 | { |
---|
1846 | if (m_SashPosition < 0) { |
---|
1847 | // Calculate sane default width for side panel. |
---|
1848 | int x; |
---|
1849 | int y; |
---|
1850 | GetClientSize(&x, &y); |
---|
1851 | if (x < 600) |
---|
1852 | x /= 3; |
---|
1853 | else if (x < 1000) |
---|
1854 | x = 200; |
---|
1855 | else |
---|
1856 | x /= 5; |
---|
1857 | m_SashPosition = x; |
---|
1858 | } |
---|
1859 | |
---|
1860 | // Do this before we potentially delete the log window which may own the |
---|
1861 | // wxString which parameter file refers to! |
---|
1862 | bool same_file = (file == m_File); |
---|
1863 | if (!same_file) |
---|
1864 | m_File = file; |
---|
1865 | |
---|
1866 | wxWindow * win = NULL; |
---|
1867 | if (m_Splitter->GetWindow2() == NULL) { |
---|
1868 | win = m_Splitter->GetWindow1(); |
---|
1869 | if (win == m_Gfx) win = NULL; |
---|
1870 | } |
---|
1871 | |
---|
1872 | if (!IsFullScreen()) { |
---|
1873 | m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition); |
---|
1874 | } else { |
---|
1875 | was_showing_sidepanel_before_fullscreen = true; |
---|
1876 | } |
---|
1877 | |
---|
1878 | m_Gfx->Initialise(same_file); |
---|
1879 | |
---|
1880 | if (win) { |
---|
1881 | // FIXME: check it actually is the log window! |
---|
1882 | if (m_Log && m_Log != win) |
---|
1883 | m_Log->Destroy(); |
---|
1884 | m_Log = win; |
---|
1885 | m_Log->Show(false); |
---|
1886 | } |
---|
1887 | |
---|
1888 | if (!IsFullScreen()) { |
---|
1889 | m_Notebook->Show(true); |
---|
1890 | } |
---|
1891 | |
---|
1892 | m_Gfx->Show(true); |
---|
1893 | m_Gfx->SetFocus(); |
---|
1894 | } |
---|
1895 | |
---|
1896 | void MainFrm::HideLog(wxWindow * log_window) |
---|
1897 | { |
---|
1898 | if (!IsFullScreen()) { |
---|
1899 | m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition); |
---|
1900 | } |
---|
1901 | |
---|
1902 | m_Log = log_window; |
---|
1903 | m_Log->Show(false); |
---|
1904 | |
---|
1905 | if (!IsFullScreen()) { |
---|
1906 | m_Notebook->Show(true); |
---|
1907 | } |
---|
1908 | |
---|
1909 | m_Gfx->Show(true); |
---|
1910 | m_Gfx->SetFocus(); |
---|
1911 | } |
---|
1912 | |
---|
1913 | // |
---|
1914 | // UI event handlers |
---|
1915 | // |
---|
1916 | |
---|
1917 | // For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx". |
---|
1918 | #ifdef _WIN32 |
---|
1919 | # define CASE(X) |
---|
1920 | #else |
---|
1921 | # define CASE(X) ";"X |
---|
1922 | #endif |
---|
1923 | |
---|
1924 | void MainFrm::OnOpen(wxCommandEvent&) |
---|
1925 | { |
---|
1926 | AvenAllowOnTop ontop(this); |
---|
1927 | #ifdef __WXMOTIF__ |
---|
1928 | wxString filetypes = wxT("*.3d"); |
---|
1929 | #else |
---|
1930 | wxString filetypes; |
---|
1931 | filetypes.Printf(wxT("%s|*.3d;*.svx;*.plt;*.plf;*.dat;*.mak;*.adj;*.sht;*.una;*.xyz" |
---|
1932 | CASE("*.3D;*.SVX;*.PLT;*.PLF;*.DAT;*.MAK;*.ADJ;*.SHT;*.UNA;*.XYZ") |
---|
1933 | "|%s|*.3d"CASE("*.3D") |
---|
1934 | "|%s|*.svx"CASE("*.SVX") |
---|
1935 | "|%s|*.plt;*.plf"CASE("*.PLT;*.PLF") |
---|
1936 | "|%s|*.dat;*.mak"CASE("*.DAT;*.MAK") |
---|
1937 | "|%s|*.adj;*.sht;*.una;*.xyz"CASE("*.ADJ;*.SHT;*.UNA;*.XYZ") |
---|
1938 | "|%s|%s"), |
---|
1939 | /* TRANSLATORS: Here "survey" is a "cave map" rather than |
---|
1940 | * list of questions - it should be translated to the |
---|
1941 | * terminology that cavers using the language would use. |
---|
1942 | */ |
---|
1943 | wmsg(/*All survey files*/229).c_str(), |
---|
1944 | /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a |
---|
1945 | * file extension, so neither should be translated. */ |
---|
1946 | wmsg(/*Survex 3d files*/207).c_str(), |
---|
1947 | /* TRANSLATORS: Survex is the name of the software, and "svx" refers to a |
---|
1948 | * file extension, so neither should be translated. */ |
---|
1949 | wmsg(/*Survex svx files*/329).c_str(), |
---|
1950 | /* TRANSLATORS: "Compass" as in Larry Fish’s cave |
---|
1951 | * surveying package, so probably shouldn’t be translated |
---|
1952 | */ |
---|
1953 | wmsg(/*Compass PLT files*/324).c_str(), |
---|
1954 | /* TRANSLATORS: "Compass" as in Larry Fish’s cave |
---|
1955 | * surveying package, so should not be translated |
---|
1956 | */ |
---|
1957 | wmsg(/*Compass DAT and MAK files*/330).c_str(), |
---|
1958 | /* TRANSLATORS: "CMAP" is Bob Thrun’s cave surveying |
---|
1959 | * package, so don’t translate it. */ |
---|
1960 | wmsg(/*CMAP XYZ files*/325).c_str(), |
---|
1961 | wmsg(/*All files*/208).c_str(), |
---|
1962 | wxFileSelectorDefaultWildcardStr); |
---|
1963 | #endif |
---|
1964 | /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions |
---|
1965 | * - it should be translated to the terminology that cavers using the |
---|
1966 | * language would use. |
---|
1967 | * |
---|
1968 | * File->Open dialog: */ |
---|
1969 | wxFileDialog dlg(this, wmsg(/*Select a survey file to view*/206), |
---|
1970 | wxString(), wxString(), |
---|
1971 | filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST); |
---|
1972 | if (dlg.ShowModal() == wxID_OK) { |
---|
1973 | OpenFile(dlg.GetPath()); |
---|
1974 | } |
---|
1975 | } |
---|
1976 | |
---|
1977 | void MainFrm::OnShowLog(wxCommandEvent&) |
---|
1978 | { |
---|
1979 | if (!m_Log) return; |
---|
1980 | wxWindow * win = m_Splitter->GetWindow1(); |
---|
1981 | m_Splitter->ReplaceWindow(win, m_Log); |
---|
1982 | if (m_Splitter->IsSplit()) { |
---|
1983 | m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel |
---|
1984 | m_Splitter->Unsplit(); |
---|
1985 | } |
---|
1986 | m_Log->Show(true); |
---|
1987 | m_Log->SetFocus(); |
---|
1988 | m_Log = NULL; |
---|
1989 | } |
---|
1990 | |
---|
1991 | void MainFrm::OnScreenshot(wxCommandEvent&) |
---|
1992 | { |
---|
1993 | AvenAllowOnTop ontop(this); |
---|
1994 | wxString baseleaf; |
---|
1995 | wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE); |
---|
1996 | /* TRANSLATORS: title of the save screenshot dialog */ |
---|
1997 | wxFileDialog dlg(this, wmsg(/*Save Screenshot*/321), wxString(), |
---|
1998 | baseleaf + wxT(".png"), |
---|
1999 | wxT("*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
---|
2000 | if (dlg.ShowModal() == wxID_OK) { |
---|
2001 | static bool png_handled = false; |
---|
2002 | if (!png_handled) { |
---|
2003 | #if 0 // FIXME : enable this to allow other export formats... |
---|
2004 | ::wxInitAllImageHandlers(); |
---|
2005 | #else |
---|
2006 | wxImage::AddHandler(new wxPNGHandler); |
---|
2007 | #endif |
---|
2008 | png_handled = true; |
---|
2009 | } |
---|
2010 | if (!m_Gfx->SaveScreenshot(dlg.GetPath(), wxBITMAP_TYPE_PNG)) { |
---|
2011 | wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), dlg.GetPath().c_str())); |
---|
2012 | } |
---|
2013 | } |
---|
2014 | } |
---|
2015 | |
---|
2016 | void MainFrm::OnScreenshotUpdate(wxUpdateUIEvent& event) |
---|
2017 | { |
---|
2018 | event.Enable(!m_File.empty()); |
---|
2019 | } |
---|
2020 | |
---|
2021 | void MainFrm::OnFilePreferences(wxCommandEvent&) |
---|
2022 | { |
---|
2023 | #ifdef PREFDLG |
---|
2024 | m_PrefsDlg = new PrefsDlg(m_Gfx, this); |
---|
2025 | m_PrefsDlg->Show(true); |
---|
2026 | #endif |
---|
2027 | } |
---|
2028 | |
---|
2029 | void MainFrm::OnPrint(wxCommandEvent&) |
---|
2030 | { |
---|
2031 | m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj); |
---|
2032 | } |
---|
2033 | |
---|
2034 | void MainFrm::PrintAndExit() |
---|
2035 | { |
---|
2036 | m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj, true); |
---|
2037 | } |
---|
2038 | |
---|
2039 | void MainFrm::OnPageSetup(wxCommandEvent&) |
---|
2040 | { |
---|
2041 | wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData()); |
---|
2042 | if (dlg.ShowModal() == wxID_OK) { |
---|
2043 | wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData()); |
---|
2044 | } |
---|
2045 | } |
---|
2046 | |
---|
2047 | void MainFrm::OnExport(wxCommandEvent&) |
---|
2048 | { |
---|
2049 | m_Gfx->OnExport(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj); |
---|
2050 | } |
---|
2051 | |
---|
2052 | void MainFrm::OnQuit(wxCommandEvent&) |
---|
2053 | { |
---|
2054 | if (m_PresList->Modified()) { |
---|
2055 | AvenAllowOnTop ontop(this); |
---|
2056 | // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel] |
---|
2057 | /* TRANSLATORS: and the question in that box */ |
---|
2058 | if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327), |
---|
2059 | /* TRANSLATORS: title of message box */ |
---|
2060 | wmsg(/*Modified Presentation*/326), |
---|
2061 | wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) { |
---|
2062 | return; |
---|
2063 | } |
---|
2064 | } |
---|
2065 | wxConfigBase *b = wxConfigBase::Get(); |
---|
2066 | if (IsFullScreen()) { |
---|
2067 | b->Write(wxT("width"), -2); |
---|
2068 | b->DeleteEntry(wxT("height")); |
---|
2069 | } else if (IsMaximized()) { |
---|
2070 | b->Write(wxT("width"), -1); |
---|
2071 | b->DeleteEntry(wxT("height")); |
---|
2072 | } else { |
---|
2073 | int width, height; |
---|
2074 | GetSize(&width, &height); |
---|
2075 | b->Write(wxT("width"), width); |
---|
2076 | b->Write(wxT("height"), height); |
---|
2077 | } |
---|
2078 | b->Flush(); |
---|
2079 | exit(0); |
---|
2080 | } |
---|
2081 | |
---|
2082 | void MainFrm::OnClose(wxCloseEvent&) |
---|
2083 | { |
---|
2084 | wxCommandEvent dummy; |
---|
2085 | OnQuit(dummy); |
---|
2086 | } |
---|
2087 | |
---|
2088 | void MainFrm::OnAbout(wxCommandEvent&) |
---|
2089 | { |
---|
2090 | AvenAllowOnTop ontop(this); |
---|
2091 | #ifdef __WXMAC__ |
---|
2092 | // GetIcon() returns an invalid wxIcon under OS X. |
---|
2093 | AboutDlg dlg(this, wxICON(aven)); |
---|
2094 | #else |
---|
2095 | AboutDlg dlg(this, GetIcon()); |
---|
2096 | #endif |
---|
2097 | dlg.Centre(); |
---|
2098 | dlg.ShowModal(); |
---|
2099 | } |
---|
2100 | |
---|
2101 | void MainFrm::UpdateStatusBar() |
---|
2102 | { |
---|
2103 | if (!here_text.empty()) { |
---|
2104 | GetStatusBar()->SetStatusText(here_text); |
---|
2105 | GetStatusBar()->SetStatusText(dist_text, 1); |
---|
2106 | } else if (!coords_text.empty()) { |
---|
2107 | GetStatusBar()->SetStatusText(coords_text); |
---|
2108 | GetStatusBar()->SetStatusText(distfree_text, 1); |
---|
2109 | } else { |
---|
2110 | GetStatusBar()->SetStatusText(wxString()); |
---|
2111 | GetStatusBar()->SetStatusText(wxString(), 1); |
---|
2112 | } |
---|
2113 | } |
---|
2114 | |
---|
2115 | void MainFrm::ClearTreeSelection() |
---|
2116 | { |
---|
2117 | m_Tree->UnselectAll(); |
---|
2118 | m_Gfx->SetThere(); |
---|
2119 | ShowInfo(); |
---|
2120 | } |
---|
2121 | |
---|
2122 | void MainFrm::ClearCoords() |
---|
2123 | { |
---|
2124 | if (!coords_text.empty()) { |
---|
2125 | coords_text = wxString(); |
---|
2126 | UpdateStatusBar(); |
---|
2127 | } |
---|
2128 | } |
---|
2129 | |
---|
2130 | void MainFrm::SetCoords(const Vector3 &v) |
---|
2131 | { |
---|
2132 | Double x = v.GetX(); |
---|
2133 | Double y = v.GetY(); |
---|
2134 | Double z = v.GetZ(); |
---|
2135 | int units; |
---|
2136 | if (m_Gfx->GetMetric()) { |
---|
2137 | units = /*m*/424; |
---|
2138 | } else { |
---|
2139 | x /= METRES_PER_FOOT; |
---|
2140 | y /= METRES_PER_FOOT; |
---|
2141 | z /= METRES_PER_FOOT; |
---|
2142 | units = /*ft*/428; |
---|
2143 | } |
---|
2144 | /* TRANSLATORS: show coordinates (N = North or Northing, E = East or |
---|
2145 | * Easting) */ |
---|
2146 | coords_text.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y); |
---|
2147 | coords_text += wxString::Format(wxT(", %s %.2f%s"), |
---|
2148 | wmsg(/*Altitude*/335).c_str(), |
---|
2149 | z, wmsg(units).c_str()); |
---|
2150 | distfree_text = wxString(); |
---|
2151 | UpdateStatusBar(); |
---|
2152 | } |
---|
2153 | |
---|
2154 | const LabelInfo * MainFrm::GetTreeSelection() const { |
---|
2155 | wxTreeItemData* sel_wx; |
---|
2156 | if (!m_Tree->GetSelectionData(&sel_wx)) return NULL; |
---|
2157 | |
---|
2158 | const TreeData* data = static_cast<const TreeData*>(sel_wx); |
---|
2159 | if (!data->IsStation()) return NULL; |
---|
2160 | |
---|
2161 | return data->GetLabel(); |
---|
2162 | } |
---|
2163 | |
---|
2164 | void MainFrm::SetCoords(Double x, Double y, const LabelInfo * there) |
---|
2165 | { |
---|
2166 | wxString & s = coords_text; |
---|
2167 | if (m_Gfx->GetMetric()) { |
---|
2168 | s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y); |
---|
2169 | } else { |
---|
2170 | s.Printf(wmsg(/*%.2f E, %.2f N*/338), |
---|
2171 | x / METRES_PER_FOOT, y / METRES_PER_FOOT); |
---|
2172 | } |
---|
2173 | |
---|
2174 | wxString & t = distfree_text; |
---|
2175 | t = wxString(); |
---|
2176 | if (m_Gfx->ShowingMeasuringLine() && there) { |
---|
2177 | Vector3 delta(x - m_Offsets.GetX() - there->GetX(), |
---|
2178 | y - m_Offsets.GetY() - there->GetY(), 0); |
---|
2179 | Double dh = sqrt(delta.GetX()*delta.GetX() + delta.GetY()*delta.GetY()); |
---|
2180 | Double brg = deg(atan2(delta.GetX(), delta.GetY())); |
---|
2181 | if (brg < 0) brg += 360; |
---|
2182 | |
---|
2183 | wxString from_str; |
---|
2184 | /* TRANSLATORS: Used in Aven: |
---|
2185 | * From <stationname> |
---|
2186 | * H: 123.45m V: 234.56m |
---|
2187 | * Dist: 456.78m Brg: 200 */ |
---|
2188 | from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str()); |
---|
2189 | int brg_unit; |
---|
2190 | if (m_Gfx->GetDegrees()) { |
---|
2191 | brg_unit = /*°*/344; |
---|
2192 | } else { |
---|
2193 | brg *= 400.0 / 360.0; |
---|
2194 | /* TRANSLATORS: alternative angle units (400 grad = 360 degrees = |
---|
2195 | * full circle). Try to make this as short as sensibly possible. |
---|
2196 | * |
---|
2197 | * E.g. in Italian and Spanish we use "g.cent." rather than |
---|
2198 | * "gradi quattrocentesimali"/"grados centesimales" */ |
---|
2199 | brg_unit = /*grad*/345; |
---|
2200 | } |
---|
2201 | |
---|
2202 | int units; |
---|
2203 | if (m_Gfx->GetMetric()) { |
---|
2204 | units = /*m*/424; |
---|
2205 | } else { |
---|
2206 | dh /= METRES_PER_FOOT; |
---|
2207 | units = /*ft*/428; |
---|
2208 | } |
---|
2209 | /* TRANSLATORS: "H" is short for "Horizontal", "Brg" for "Bearing" (as |
---|
2210 | * in Compass bearing) */ |
---|
2211 | t.Printf(wmsg(/*%s: H %.2f%s, Brg %03d%s*/374), |
---|
2212 | from_str.c_str(), dh, wmsg(units).c_str(), |
---|
2213 | int(brg), wmsg(brg_unit).c_str()); |
---|
2214 | } |
---|
2215 | |
---|
2216 | UpdateStatusBar(); |
---|
2217 | } |
---|
2218 | |
---|
2219 | void MainFrm::SetAltitude(Double z, const LabelInfo * there) |
---|
2220 | { |
---|
2221 | double alt = z; |
---|
2222 | int units; |
---|
2223 | if (m_Gfx->GetMetric()) { |
---|
2224 | units = /*m*/424; |
---|
2225 | } else { |
---|
2226 | alt /= METRES_PER_FOOT; |
---|
2227 | units = /*ft*/428; |
---|
2228 | } |
---|
2229 | coords_text.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(), |
---|
2230 | alt, wmsg(units).c_str()); |
---|
2231 | |
---|
2232 | wxString & t = distfree_text; |
---|
2233 | t = wxString(); |
---|
2234 | if (m_Gfx->ShowingMeasuringLine() && there) { |
---|
2235 | Double dz = z - m_Offsets.GetZ() - there->GetZ(); |
---|
2236 | |
---|
2237 | wxString from_str; |
---|
2238 | from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str()); |
---|
2239 | |
---|
2240 | if (!m_Gfx->GetMetric()) { |
---|
2241 | dz /= METRES_PER_FOOT; |
---|
2242 | } |
---|
2243 | // TRANSLATORS: "V" is short for "Vertical" |
---|
2244 | t.Printf(wmsg(/*%s: V %.2f%s*/375), from_str.c_str(), |
---|
2245 | dz, wmsg(units).c_str()); |
---|
2246 | } |
---|
2247 | |
---|
2248 | UpdateStatusBar(); |
---|
2249 | } |
---|
2250 | |
---|
2251 | void MainFrm::ShowInfo(const LabelInfo *here, const LabelInfo *there) |
---|
2252 | { |
---|
2253 | assert(m_Gfx); |
---|
2254 | |
---|
2255 | if (!here) { |
---|
2256 | m_Gfx->SetHere(); |
---|
2257 | m_Tree->SetHere(wxTreeItemId()); |
---|
2258 | // Don't clear "There" mark here. |
---|
2259 | if (here_text.empty() && dist_text.empty()) return; |
---|
2260 | here_text = wxString(); |
---|
2261 | dist_text = wxString(); |
---|
2262 | UpdateStatusBar(); |
---|
2263 | return; |
---|
2264 | } |
---|
2265 | |
---|
2266 | Vector3 v = *here + m_Offsets; |
---|
2267 | wxString & s = here_text; |
---|
2268 | Double x = v.GetX(); |
---|
2269 | Double y = v.GetY(); |
---|
2270 | Double z = v.GetZ(); |
---|
2271 | int units; |
---|
2272 | if (m_Gfx->GetMetric()) { |
---|
2273 | units = /*m*/424; |
---|
2274 | } else { |
---|
2275 | x /= METRES_PER_FOOT; |
---|
2276 | y /= METRES_PER_FOOT; |
---|
2277 | z /= METRES_PER_FOOT; |
---|
2278 | units = /*ft*/428; |
---|
2279 | } |
---|
2280 | s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y); |
---|
2281 | s += wxString::Format(wxT(", %s %.2f%s"), wmsg(/*Altitude*/335).c_str(), |
---|
2282 | z, wmsg(units).c_str()); |
---|
2283 | s += wxT(": "); |
---|
2284 | s += here->name_or_anon(); |
---|
2285 | m_Gfx->SetHere(here); |
---|
2286 | m_Tree->SetHere(here->tree_id); |
---|
2287 | |
---|
2288 | if (m_Gfx->ShowingMeasuringLine() && there) { |
---|
2289 | Vector3 delta = *here - *there; |
---|
2290 | |
---|
2291 | Double d_horiz = sqrt(delta.GetX()*delta.GetX() + |
---|
2292 | delta.GetY()*delta.GetY()); |
---|
2293 | Double dr = delta.magnitude(); |
---|
2294 | Double dz = delta.GetZ(); |
---|
2295 | |
---|
2296 | Double brg = deg(atan2(delta.GetX(), delta.GetY())); |
---|
2297 | if (brg < 0) brg += 360; |
---|
2298 | |
---|
2299 | wxString from_str; |
---|
2300 | from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str()); |
---|
2301 | |
---|
2302 | wxString hv_str; |
---|
2303 | if (m_Gfx->GetMetric()) { |
---|
2304 | units = /*m*/424; |
---|
2305 | } else { |
---|
2306 | d_horiz /= METRES_PER_FOOT; |
---|
2307 | dr /= METRES_PER_FOOT; |
---|
2308 | dz /= METRES_PER_FOOT; |
---|
2309 | units = /*ft*/428; |
---|
2310 | } |
---|
2311 | wxString len_unit = wmsg(units); |
---|
2312 | /* TRANSLATORS: "H" is short for "Horizontal", "V" for "Vertical" */ |
---|
2313 | hv_str.Printf(wmsg(/*H %.2f%s, V %.2f%s*/340), |
---|
2314 | d_horiz, len_unit.c_str(), dz, len_unit.c_str()); |
---|
2315 | int brg_unit; |
---|
2316 | if (m_Gfx->GetDegrees()) { |
---|
2317 | brg_unit = /*°*/344; |
---|
2318 | } else { |
---|
2319 | brg *= 400.0 / 360.0; |
---|
2320 | brg_unit = /*grad*/345; |
---|
2321 | } |
---|
2322 | wxString & d = dist_text; |
---|
2323 | /* TRANSLATORS: "Dist" is short for "Distance", "Brg" for "Bearing" (as |
---|
2324 | * in Compass bearing) */ |
---|
2325 | d.Printf(wmsg(/*%s: %s, Dist %.2f%s, Brg %03d%s*/341), |
---|
2326 | from_str.c_str(), hv_str.c_str(), |
---|
2327 | dr, len_unit.c_str(), int(brg), wmsg(brg_unit).c_str()); |
---|
2328 | } else { |
---|
2329 | dist_text = wxString(); |
---|
2330 | m_Gfx->SetThere(); |
---|
2331 | } |
---|
2332 | UpdateStatusBar(); |
---|
2333 | } |
---|
2334 | |
---|
2335 | void MainFrm::DisplayTreeInfo(const wxTreeItemData* item) |
---|
2336 | { |
---|
2337 | const TreeData* data = static_cast<const TreeData*>(item); |
---|
2338 | if (data && data->IsStation()) { |
---|
2339 | m_Gfx->SetHereFromTree(data->GetLabel()); |
---|
2340 | } else { |
---|
2341 | ShowInfo(); |
---|
2342 | } |
---|
2343 | } |
---|
2344 | |
---|
2345 | void MainFrm::TreeItemSelected(const wxTreeItemData* item, bool zoom) |
---|
2346 | { |
---|
2347 | const TreeData* data = static_cast<const TreeData*>(item); |
---|
2348 | if (data && data->IsStation()) { |
---|
2349 | const LabelInfo* label = data->GetLabel(); |
---|
2350 | if (zoom) m_Gfx->CentreOn(*label); |
---|
2351 | m_Gfx->SetThere(label); |
---|
2352 | dist_text = wxString(); |
---|
2353 | // FIXME: Need to update dist_text (From ... etc) |
---|
2354 | // But we don't currently know where "here" is at this point in the |
---|
2355 | // code! |
---|
2356 | } else { |
---|
2357 | dist_text = wxString(); |
---|
2358 | m_Gfx->SetThere(); |
---|
2359 | } |
---|
2360 | if (!data) { |
---|
2361 | // Must be the root. |
---|
2362 | m_FindBox->SetValue(wxString()); |
---|
2363 | if (zoom) { |
---|
2364 | wxCommandEvent dummy; |
---|
2365 | OnDefaults(dummy); |
---|
2366 | } |
---|
2367 | } else if (data && !data->IsStation()) { |
---|
2368 | m_FindBox->SetValue(data->GetSurvey() + wxT(".*")); |
---|
2369 | if (zoom) { |
---|
2370 | wxCommandEvent dummy; |
---|
2371 | OnGotoFound(dummy); |
---|
2372 | } |
---|
2373 | } |
---|
2374 | UpdateStatusBar(); |
---|
2375 | } |
---|
2376 | |
---|
2377 | void MainFrm::OnPresNew(wxCommandEvent&) |
---|
2378 | { |
---|
2379 | if (m_PresList->Modified()) { |
---|
2380 | AvenAllowOnTop ontop(this); |
---|
2381 | // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel] |
---|
2382 | if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327), |
---|
2383 | wmsg(/*Modified Presentation*/326), |
---|
2384 | wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) { |
---|
2385 | return; |
---|
2386 | } |
---|
2387 | } |
---|
2388 | m_PresList->New(m_File); |
---|
2389 | if (!ShowingSidePanel()) ToggleSidePanel(); |
---|
2390 | // Select the presentation page in the notebook. |
---|
2391 | m_Notebook->SetSelection(1); |
---|
2392 | } |
---|
2393 | |
---|
2394 | void MainFrm::OnPresOpen(wxCommandEvent&) |
---|
2395 | { |
---|
2396 | AvenAllowOnTop ontop(this); |
---|
2397 | if (m_PresList->Modified()) { |
---|
2398 | // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel] |
---|
2399 | if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327), |
---|
2400 | wmsg(/*Modified Presentation*/326), |
---|
2401 | wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) { |
---|
2402 | return; |
---|
2403 | } |
---|
2404 | } |
---|
2405 | #ifdef __WXMOTIF__ |
---|
2406 | wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(), |
---|
2407 | wxT("*.fly"), wxFD_OPEN); |
---|
2408 | #else |
---|
2409 | wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(), |
---|
2410 | wxString::Format(wxT("%s|*.fly|%s|%s"), |
---|
2411 | wmsg(/*Aven presentations*/320).c_str(), |
---|
2412 | wmsg(/*All files*/208).c_str(), |
---|
2413 | wxFileSelectorDefaultWildcardStr), |
---|
2414 | wxFD_OPEN|wxFD_FILE_MUST_EXIST); |
---|
2415 | #endif |
---|
2416 | if (dlg.ShowModal() == wxID_OK) { |
---|
2417 | if (!m_PresList->Load(dlg.GetPath())) { |
---|
2418 | return; |
---|
2419 | } |
---|
2420 | // FIXME : keep a history of loaded/saved presentations, like we do for |
---|
2421 | // loaded surveys... |
---|
2422 | // Select the presentation page in the notebook. |
---|
2423 | m_Notebook->SetSelection(1); |
---|
2424 | } |
---|
2425 | } |
---|
2426 | |
---|
2427 | void MainFrm::OnPresSave(wxCommandEvent&) |
---|
2428 | { |
---|
2429 | m_PresList->Save(true); |
---|
2430 | } |
---|
2431 | |
---|
2432 | void MainFrm::OnPresSaveAs(wxCommandEvent&) |
---|
2433 | { |
---|
2434 | m_PresList->Save(false); |
---|
2435 | } |
---|
2436 | |
---|
2437 | void MainFrm::OnPresMark(wxCommandEvent&) |
---|
2438 | { |
---|
2439 | m_PresList->AddMark(); |
---|
2440 | } |
---|
2441 | |
---|
2442 | void MainFrm::OnPresFRewind(wxCommandEvent&) |
---|
2443 | { |
---|
2444 | m_Gfx->PlayPres(-100); |
---|
2445 | } |
---|
2446 | |
---|
2447 | void MainFrm::OnPresRewind(wxCommandEvent&) |
---|
2448 | { |
---|
2449 | m_Gfx->PlayPres(-10); |
---|
2450 | } |
---|
2451 | |
---|
2452 | void MainFrm::OnPresReverse(wxCommandEvent&) |
---|
2453 | { |
---|
2454 | m_Gfx->PlayPres(-1); |
---|
2455 | } |
---|
2456 | |
---|
2457 | void MainFrm::OnPresPlay(wxCommandEvent&) |
---|
2458 | { |
---|
2459 | m_Gfx->PlayPres(1); |
---|
2460 | } |
---|
2461 | |
---|
2462 | void MainFrm::OnPresFF(wxCommandEvent&) |
---|
2463 | { |
---|
2464 | m_Gfx->PlayPres(10); |
---|
2465 | } |
---|
2466 | |
---|
2467 | void MainFrm::OnPresFFF(wxCommandEvent&) |
---|
2468 | { |
---|
2469 | m_Gfx->PlayPres(100); |
---|
2470 | } |
---|
2471 | |
---|
2472 | void MainFrm::OnPresPause(wxCommandEvent&) |
---|
2473 | { |
---|
2474 | m_Gfx->PlayPres(0); |
---|
2475 | } |
---|
2476 | |
---|
2477 | void MainFrm::OnPresStop(wxCommandEvent&) |
---|
2478 | { |
---|
2479 | m_Gfx->PlayPres(0, false); |
---|
2480 | } |
---|
2481 | |
---|
2482 | void MainFrm::OnPresExportMovie(wxCommandEvent&) |
---|
2483 | { |
---|
2484 | AvenAllowOnTop ontop(this); |
---|
2485 | // FIXME : Taking the leaf of the currently loaded presentation as the |
---|
2486 | // default might make more sense? |
---|
2487 | wxString baseleaf; |
---|
2488 | wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE); |
---|
2489 | wxFileDialog dlg(this, wmsg(/*Export Movie*/331), wxString(), |
---|
2490 | baseleaf + wxT(".mpg"), |
---|
2491 | wxT("MPEG|*.mpg|AVI|*.avi|QuickTime|*.mov|WMV|*.wmv;*.asf"), |
---|
2492 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
---|
2493 | if (dlg.ShowModal() == wxID_OK) { |
---|
2494 | // Error is reported by GfxCore. |
---|
2495 | (void)m_Gfx->ExportMovie(dlg.GetPath()); |
---|
2496 | } |
---|
2497 | } |
---|
2498 | |
---|
2499 | PresentationMark MainFrm::GetPresMark(int which) |
---|
2500 | { |
---|
2501 | return m_PresList->GetPresMark(which); |
---|
2502 | } |
---|
2503 | |
---|
2504 | //void MainFrm::OnFileOpenTerrainUpdate(wxUpdateUIEvent& event) |
---|
2505 | //{ |
---|
2506 | // event.Enable(!m_File.empty()); |
---|
2507 | //} |
---|
2508 | |
---|
2509 | void MainFrm::OnPresNewUpdate(wxUpdateUIEvent& event) |
---|
2510 | { |
---|
2511 | event.Enable(!m_File.empty()); |
---|
2512 | } |
---|
2513 | |
---|
2514 | void MainFrm::OnPresOpenUpdate(wxUpdateUIEvent& event) |
---|
2515 | { |
---|
2516 | event.Enable(!m_File.empty()); |
---|
2517 | } |
---|
2518 | |
---|
2519 | void MainFrm::OnPresSaveUpdate(wxUpdateUIEvent& event) |
---|
2520 | { |
---|
2521 | event.Enable(!m_PresList->Empty()); |
---|
2522 | } |
---|
2523 | |
---|
2524 | void MainFrm::OnPresSaveAsUpdate(wxUpdateUIEvent& event) |
---|
2525 | { |
---|
2526 | event.Enable(!m_PresList->Empty()); |
---|
2527 | } |
---|
2528 | |
---|
2529 | void MainFrm::OnPresMarkUpdate(wxUpdateUIEvent& event) |
---|
2530 | { |
---|
2531 | event.Enable(!m_File.empty()); |
---|
2532 | } |
---|
2533 | |
---|
2534 | void MainFrm::OnPresFRewindUpdate(wxUpdateUIEvent& event) |
---|
2535 | { |
---|
2536 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2537 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() < -10); |
---|
2538 | } |
---|
2539 | |
---|
2540 | void MainFrm::OnPresRewindUpdate(wxUpdateUIEvent& event) |
---|
2541 | { |
---|
2542 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2543 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -10); |
---|
2544 | } |
---|
2545 | |
---|
2546 | void MainFrm::OnPresReverseUpdate(wxUpdateUIEvent& event) |
---|
2547 | { |
---|
2548 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2549 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -1); |
---|
2550 | } |
---|
2551 | |
---|
2552 | void MainFrm::OnPresPlayUpdate(wxUpdateUIEvent& event) |
---|
2553 | { |
---|
2554 | event.Enable(!m_PresList->Empty()); |
---|
2555 | event.Check(m_Gfx && m_Gfx->GetPresentationMode() && |
---|
2556 | m_Gfx->GetPresentationSpeed() == 1); |
---|
2557 | } |
---|
2558 | |
---|
2559 | void MainFrm::OnPresFFUpdate(wxUpdateUIEvent& event) |
---|
2560 | { |
---|
2561 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2562 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 10); |
---|
2563 | } |
---|
2564 | |
---|
2565 | void MainFrm::OnPresFFFUpdate(wxUpdateUIEvent& event) |
---|
2566 | { |
---|
2567 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2568 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() > 10); |
---|
2569 | } |
---|
2570 | |
---|
2571 | void MainFrm::OnPresPauseUpdate(wxUpdateUIEvent& event) |
---|
2572 | { |
---|
2573 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2574 | event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 0); |
---|
2575 | } |
---|
2576 | |
---|
2577 | void MainFrm::OnPresStopUpdate(wxUpdateUIEvent& event) |
---|
2578 | { |
---|
2579 | event.Enable(m_Gfx && m_Gfx->GetPresentationMode()); |
---|
2580 | } |
---|
2581 | |
---|
2582 | void MainFrm::OnPresExportMovieUpdate(wxUpdateUIEvent& event) |
---|
2583 | { |
---|
2584 | event.Enable(!m_PresList->Empty()); |
---|
2585 | } |
---|
2586 | |
---|
2587 | void MainFrm::OnFind(wxCommandEvent&) |
---|
2588 | { |
---|
2589 | pending_find = true; |
---|
2590 | } |
---|
2591 | |
---|
2592 | void MainFrm::OnIdle(wxIdleEvent&) |
---|
2593 | { |
---|
2594 | if (pending_find) { |
---|
2595 | DoFind(); |
---|
2596 | } |
---|
2597 | } |
---|
2598 | |
---|
2599 | void MainFrm::DoFind() |
---|
2600 | { |
---|
2601 | pending_find = false; |
---|
2602 | wxBusyCursor hourglass; |
---|
2603 | // Find stations specified by a string or regular expression pattern. |
---|
2604 | |
---|
2605 | wxString pattern = m_FindBox->GetValue(); |
---|
2606 | if (pattern.empty()) { |
---|
2607 | // Hide any search result highlights. |
---|
2608 | list<LabelInfo*>::iterator pos = m_Labels.begin(); |
---|
2609 | while (pos != m_Labels.end()) { |
---|
2610 | LabelInfo* label = *pos++; |
---|
2611 | label->clear_flags(LFLAG_HIGHLIGHTED); |
---|
2612 | } |
---|
2613 | m_NumHighlighted = 0; |
---|
2614 | } else { |
---|
2615 | int re_flags = wxRE_NOSUB; |
---|
2616 | |
---|
2617 | if (true /* case insensitive */) { |
---|
2618 | re_flags |= wxRE_ICASE; |
---|
2619 | } |
---|
2620 | |
---|
2621 | bool substring = true; |
---|
2622 | if (false /*m_RegexpCheckBox->GetValue()*/) { |
---|
2623 | re_flags |= wxRE_EXTENDED; |
---|
2624 | } else if (true /* simple glob-style */) { |
---|
2625 | wxString pat; |
---|
2626 | for (size_t i = 0; i < pattern.size(); i++) { |
---|
2627 | wxChar ch = pattern[i]; |
---|
2628 | // ^ only special at start; $ at end. But this is simpler... |
---|
2629 | switch (ch) { |
---|
2630 | case '^': case '$': case '.': case '[': case '\\': |
---|
2631 | pat += wxT('\\'); |
---|
2632 | pat += ch; |
---|
2633 | break; |
---|
2634 | case '*': |
---|
2635 | pat += wxT(".*"); |
---|
2636 | substring = false; |
---|
2637 | break; |
---|
2638 | case '?': |
---|
2639 | pat += wxT('.'); |
---|
2640 | substring = false; |
---|
2641 | break; |
---|
2642 | default: |
---|
2643 | pat += ch; |
---|
2644 | } |
---|
2645 | } |
---|
2646 | pattern = pat; |
---|
2647 | re_flags |= wxRE_BASIC; |
---|
2648 | } else { |
---|
2649 | wxString pat; |
---|
2650 | for (size_t i = 0; i < pattern.size(); i++) { |
---|
2651 | wxChar ch = pattern[i]; |
---|
2652 | // ^ only special at start; $ at end. But this is simpler... |
---|
2653 | switch (ch) { |
---|
2654 | case '^': case '$': case '*': case '.': case '[': case '\\': |
---|
2655 | pat += wxT('\\'); |
---|
2656 | } |
---|
2657 | pat += ch; |
---|
2658 | } |
---|
2659 | pattern = pat; |
---|
2660 | re_flags |= wxRE_BASIC; |
---|
2661 | } |
---|
2662 | |
---|
2663 | if (!substring) { |
---|
2664 | // FIXME "0u" required to avoid compilation error with g++-3.0 |
---|
2665 | if (pattern.empty() || pattern[0u] != '^') pattern = wxT('^') + pattern; |
---|
2666 | // FIXME: this fails to cope with "\$" at the end of pattern... |
---|
2667 | if (pattern[pattern.size() - 1] != '$') pattern += wxT('$'); |
---|
2668 | } |
---|
2669 | |
---|
2670 | wxRegEx regex; |
---|
2671 | if (!regex.Compile(pattern, re_flags)) { |
---|
2672 | wxBell(); |
---|
2673 | return; |
---|
2674 | } |
---|
2675 | |
---|
2676 | int found = 0; |
---|
2677 | |
---|
2678 | list<LabelInfo*>::iterator pos = m_Labels.begin(); |
---|
2679 | while (pos != m_Labels.end()) { |
---|
2680 | LabelInfo* label = *pos++; |
---|
2681 | |
---|
2682 | if (regex.Matches(label->GetText())) { |
---|
2683 | label->set_flags(LFLAG_HIGHLIGHTED); |
---|
2684 | ++found; |
---|
2685 | } else { |
---|
2686 | label->clear_flags(LFLAG_HIGHLIGHTED); |
---|
2687 | } |
---|
2688 | } |
---|
2689 | |
---|
2690 | m_NumHighlighted = found; |
---|
2691 | |
---|
2692 | // Re-sort so highlighted points get names in preference |
---|
2693 | if (found) m_Labels.sort(LabelPlotCmp(separator)); |
---|
2694 | } |
---|
2695 | |
---|
2696 | m_Gfx->UpdateBlobs(); |
---|
2697 | m_Gfx->ForceRefresh(); |
---|
2698 | |
---|
2699 | if (!m_NumHighlighted) { |
---|
2700 | GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*No matches were found.*/328)); |
---|
2701 | } else { |
---|
2702 | /* TRANSLATORS: "Hide stations" button tooltip when stations are found |
---|
2703 | */ |
---|
2704 | GetToolBar()->SetToolShortHelp(button_HIDE, wxString::Format(wmsg(/*Hide %d found stations*/334).c_str(), m_NumHighlighted)); |
---|
2705 | } |
---|
2706 | } |
---|
2707 | |
---|
2708 | void MainFrm::OnGotoFound(wxCommandEvent&) |
---|
2709 | { |
---|
2710 | if (!m_NumHighlighted) { |
---|
2711 | wxGetApp().ReportError(wmsg(/*No matches were found.*/328)); |
---|
2712 | return; |
---|
2713 | } |
---|
2714 | |
---|
2715 | Double xmin = DBL_MAX; |
---|
2716 | Double xmax = -DBL_MAX; |
---|
2717 | Double ymin = DBL_MAX; |
---|
2718 | Double ymax = -DBL_MAX; |
---|
2719 | Double zmin = DBL_MAX; |
---|
2720 | Double zmax = -DBL_MAX; |
---|
2721 | |
---|
2722 | list<LabelInfo*>::iterator pos = m_Labels.begin(); |
---|
2723 | while (pos != m_Labels.end()) { |
---|
2724 | LabelInfo* label = *pos++; |
---|
2725 | |
---|
2726 | if (label->get_flags() & LFLAG_HIGHLIGHTED) { |
---|
2727 | if (label->GetX() < xmin) xmin = label->GetX(); |
---|
2728 | if (label->GetX() > xmax) xmax = label->GetX(); |
---|
2729 | if (label->GetY() < ymin) ymin = label->GetY(); |
---|
2730 | if (label->GetY() > ymax) ymax = label->GetY(); |
---|
2731 | if (label->GetZ() < zmin) zmin = label->GetZ(); |
---|
2732 | if (label->GetZ() > zmax) zmax = label->GetZ(); |
---|
2733 | } |
---|
2734 | } |
---|
2735 | |
---|
2736 | m_Gfx->SetViewTo(xmin, xmax, ymin, ymax, zmin, zmax); |
---|
2737 | m_Gfx->SetFocus(); |
---|
2738 | } |
---|
2739 | |
---|
2740 | void MainFrm::OnHide(wxCommandEvent&) |
---|
2741 | { |
---|
2742 | m_FindBox->SetValue(wxString()); |
---|
2743 | GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*Hide*/333)); |
---|
2744 | } |
---|
2745 | |
---|
2746 | void MainFrm::OnHideUpdate(wxUpdateUIEvent& ui) |
---|
2747 | { |
---|
2748 | ui.Enable(m_NumHighlighted != 0); |
---|
2749 | } |
---|
2750 | |
---|
2751 | void MainFrm::OnViewSidePanel(wxCommandEvent&) |
---|
2752 | { |
---|
2753 | ToggleSidePanel(); |
---|
2754 | } |
---|
2755 | |
---|
2756 | void MainFrm::ToggleSidePanel() |
---|
2757 | { |
---|
2758 | // Toggle display of the side panel. |
---|
2759 | |
---|
2760 | assert(m_Gfx); |
---|
2761 | |
---|
2762 | if (m_Splitter->IsSplit()) { |
---|
2763 | m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel |
---|
2764 | m_Splitter->Unsplit(m_Notebook); |
---|
2765 | } else { |
---|
2766 | m_Notebook->Show(true); |
---|
2767 | m_Gfx->Show(true); |
---|
2768 | m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition); |
---|
2769 | } |
---|
2770 | } |
---|
2771 | |
---|
2772 | void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui) |
---|
2773 | { |
---|
2774 | ui.Enable(!m_File.empty()); |
---|
2775 | ui.Check(ShowingSidePanel()); |
---|
2776 | } |
---|
2777 | |
---|
2778 | bool MainFrm::ShowingSidePanel() |
---|
2779 | { |
---|
2780 | return m_Splitter->IsSplit(); |
---|
2781 | } |
---|
2782 | |
---|
2783 | void MainFrm::ViewFullScreen() { |
---|
2784 | #ifdef __WXMAC__ |
---|
2785 | // On OS X, wxWidgets doesn't currently hide the toolbar or statusbar in |
---|
2786 | // full screen mode (last checked with 3.0.2), but it is easy to do |
---|
2787 | // ourselves. |
---|
2788 | if (!IsFullScreen()) { |
---|
2789 | GetToolBar()->Hide(); |
---|
2790 | GetStatusBar()->Hide(); |
---|
2791 | } |
---|
2792 | #endif |
---|
2793 | |
---|
2794 | ShowFullScreen(!IsFullScreen()); |
---|
2795 | fullscreen_showing_menus = false; |
---|
2796 | if (IsFullScreen()) |
---|
2797 | was_showing_sidepanel_before_fullscreen = ShowingSidePanel(); |
---|
2798 | if (was_showing_sidepanel_before_fullscreen) |
---|
2799 | ToggleSidePanel(); |
---|
2800 | |
---|
2801 | #ifdef __WXMAC__ |
---|
2802 | if (!IsFullScreen()) { |
---|
2803 | GetStatusBar()->Show(); |
---|
2804 | GetToolBar()->Show(); |
---|
2805 | } |
---|
2806 | #endif |
---|
2807 | } |
---|
2808 | |
---|
2809 | bool MainFrm::FullScreenModeShowingMenus() const |
---|
2810 | { |
---|
2811 | return fullscreen_showing_menus; |
---|
2812 | } |
---|
2813 | |
---|
2814 | void MainFrm::FullScreenModeShowMenus(bool show) |
---|
2815 | { |
---|
2816 | if (!IsFullScreen() || show == fullscreen_showing_menus) |
---|
2817 | return; |
---|
2818 | GetMenuBar()->Show(show); |
---|
2819 | fullscreen_showing_menus = show; |
---|
2820 | } |
---|