Show location for backsights out of tolerance
[survex.git] / src / mainfrm.cc
blob16fbb4a093dee109182122a196248027db61b964
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,2016,2018 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.
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.
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
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #include "cavernlog.h"
30 #include "mainfrm.h"
31 #include "aven.h"
32 #include "aboutdlg.h"
34 #include "message.h"
35 #include "img_hosted.h"
36 #include "namecompare.h"
37 #include "printing.h"
38 #include "filename.h"
39 #include "useful.h"
41 #include <wx/confbase.h>
42 //#include <wx/filefn.h>
43 #include <wx/filename.h>
44 #include <wx/image.h>
45 #include <wx/imaglist.h>
46 #include <wx/process.h>
47 #include <wx/regex.h>
48 #ifdef USING_GENERIC_TOOLBAR
49 # include <wx/sysopt.h>
50 #endif
52 #include <cerrno>
53 #include <cstdlib>
54 #include <float.h>
55 #include <functional>
56 #include <vector>
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 #ifndef __WXMSW__
63 #include "../lib/icons/aven.xpm"
64 #endif
65 #include "../lib/icons/log.xpm"
66 #include "../lib/icons/open.xpm"
67 #include "../lib/icons/open_pres.xpm"
68 #include "../lib/icons/rotation.xpm"
69 #include "../lib/icons/plan.xpm"
70 #include "../lib/icons/elevation.xpm"
71 #include "../lib/icons/defaults.xpm"
72 #include "../lib/icons/names.xpm"
73 #include "../lib/icons/crosses.xpm"
74 #include "../lib/icons/entrances.xpm"
75 #include "../lib/icons/fixed_pts.xpm"
76 #include "../lib/icons/exported_pts.xpm"
77 #include "../lib/icons/ug_legs.xpm"
78 #include "../lib/icons/surface_legs.xpm"
79 #include "../lib/icons/tubes.xpm"
80 #include "../lib/icons/solid_surface.xpm"
81 #include "../lib/icons/pres_frew.xpm"
82 #include "../lib/icons/pres_rew.xpm"
83 #include "../lib/icons/pres_go_back.xpm"
84 #include "../lib/icons/pres_pause.xpm"
85 #include "../lib/icons/pres_go.xpm"
86 #include "../lib/icons/pres_ff.xpm"
87 #include "../lib/icons/pres_fff.xpm"
88 #include "../lib/icons/pres_stop.xpm"
89 #include "../lib/icons/find.xpm"
90 #include "../lib/icons/hideresults.xpm"
91 #include "../lib/icons/survey_tree.xpm"
92 #include "../lib/icons/pres_tree.xpm"
93 #undef static
94 #ifdef __WXMSW__
95 # define TOOL(x) wxBitmap(x##_xpm)
96 #else
97 # define TOOL(x) wxBITMAP(x)
98 #endif
100 using namespace std;
102 class AvenSplitterWindow : public wxSplitterWindow {
103 MainFrm *parent;
105 public:
106 explicit AvenSplitterWindow(MainFrm *parent_)
107 : wxSplitterWindow(parent_, -1, wxDefaultPosition, wxDefaultSize,
108 wxSP_3DSASH),
109 parent(parent_)
113 void OnSplitterDClick(wxSplitterEvent &) {
114 parent->ToggleSidePanel();
117 private:
118 DECLARE_EVENT_TABLE()
121 BEGIN_EVENT_TABLE(AvenSplitterWindow, wxSplitterWindow)
122 EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick)
123 END_EVENT_TABLE()
125 class EditMarkDlg : public wxDialog {
126 wxTextCtrl * easting, * northing, * altitude;
127 wxTextCtrl * angle, * tilt_angle, * scale, * time;
128 public:
129 // TRANSLATORS: Title of dialog to edit a waypoint in a presentation.
130 EditMarkDlg(wxWindow* parent, const PresentationMark & p)
131 : wxDialog(parent, 500, wmsg(/*Edit Waypoint*/404))
133 easting = new wxTextCtrl(this, 601, wxString::Format(wxT("%.3f"), p.GetX()));
134 northing = new wxTextCtrl(this, 602, wxString::Format(wxT("%.3f"), p.GetY()));
135 altitude = new wxTextCtrl(this, 603, wxString::Format(wxT("%.3f"), p.GetZ()));
136 angle = new wxTextCtrl(this, 604, wxString::Format(wxT("%.3f"), p.angle));
137 tilt_angle = new wxTextCtrl(this, 605, wxString::Format(wxT("%.3f"), p.tilt_angle));
138 scale = new wxTextCtrl(this, 606, wxString::Format(wxT("%.3f"), p.scale));
139 if (p.time > 0.0) {
140 time = new wxTextCtrl(this, 607, wxString::Format(wxT("%.3f"), p.time));
141 } else if (p.time < 0.0) {
142 time = new wxTextCtrl(this, 607, wxString::Format(wxT("*%.3f"), -p.time));
143 } else {
144 time = new wxTextCtrl(this, 607, wxT("0"));
147 wxBoxSizer * coords = new wxBoxSizer(wxHORIZONTAL);
148 coords->Add(new wxStaticText(this, 610, wxT("(")), 0, wxALIGN_CENTRE_VERTICAL);
149 coords->Add(easting, 1);
150 coords->Add(new wxStaticText(this, 611, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
151 coords->Add(northing, 1);
152 coords->Add(new wxStaticText(this, 612, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
153 coords->Add(altitude, 1);
154 coords->Add(new wxStaticText(this, 613, wxT(")")), 0, wxALIGN_CENTRE_VERTICAL);
155 wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL);
156 vert->Add(coords, 0, wxALL, 8);
157 wxBoxSizer * r2 = new wxBoxSizer(wxHORIZONTAL);
158 r2->Add(new wxStaticText(this, 614, wmsg(/*Bearing*/259) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
159 r2->Add(angle);
160 vert->Add(r2, 0, wxALL, 8);
161 wxBoxSizer * r3 = new wxBoxSizer(wxHORIZONTAL);
162 r3->Add(new wxStaticText(this, 615, wmsg(/*Elevation*/118) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
163 r3->Add(tilt_angle);
164 vert->Add(r3, 0, wxALL, 8);
165 wxBoxSizer * r4 = new wxBoxSizer(wxHORIZONTAL);
166 r4->Add(new wxStaticText(this, 616, wmsg(/*Scale*/154) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
167 r4->Add(scale);
168 /* TRANSLATORS: Note after "Scale" field in dialog to edit a waypoint
169 * in a presentation. */
170 r4->Add(new wxStaticText(this, 617, wmsg(/* (unused in perspective view)*/278)),
171 0, wxALIGN_CENTRE_VERTICAL);
172 vert->Add(r4, 0, wxALL, 8);
174 wxBoxSizer * r5 = new wxBoxSizer(wxHORIZONTAL);
175 /* TRANSLATORS: Field label in dialog to edit a waypoint in a
176 * presentation. */
177 r5->Add(new wxStaticText(this, 616, wmsg(/*Time: */279)), 0, wxALIGN_CENTRE_VERTICAL);
178 r5->Add(time);
179 /* TRANSLATORS: units+info after time field in dialog to edit a
180 * waypoint in a presentation. */
181 r5->Add(new wxStaticText(this, 617, wmsg(/* secs (0 = auto; *6 = 6 times auto)*/282)),
182 0, wxALIGN_CENTRE_VERTICAL);
183 vert->Add(r5, 0, wxALL, 8);
185 wxBoxSizer * buttons = new wxBoxSizer(wxHORIZONTAL);
186 wxButton* cancel = new wxButton(this, wxID_CANCEL);
187 buttons->Add(cancel, 0, wxALL, 8);
188 wxButton* ok = new wxButton(this, wxID_OK);
189 ok->SetDefault();
190 buttons->Add(ok, 0, wxALL, 8);
191 vert->Add(buttons, 0, wxALL|wxALIGN_RIGHT);
193 SetAutoLayout(true);
194 SetSizer(vert);
196 vert->SetSizeHints(this);
198 PresentationMark GetMark() const {
199 double a, t, s, T;
200 Vector3 v(wxAtof(easting->GetValue()),
201 wxAtof(northing->GetValue()),
202 wxAtof(altitude->GetValue()));
203 a = wxAtof(angle->GetValue());
204 t = wxAtof(tilt_angle->GetValue());
205 s = wxAtof(scale->GetValue());
206 wxString str = time->GetValue();
207 if (!str.empty() && str[0u] == '*') str[0u] = '-';
208 T = wxAtof(str);
209 return PresentationMark(v, a, t, s, T);
212 private:
213 DECLARE_EVENT_TABLE()
216 // Write a value without trailing zeros after the decimal point.
217 static void write_double(double d, FILE * fh) {
218 char buf[64];
219 snprintf(buf, sizeof(buf), "%.21f", d);
220 char * p = strchr(buf, ',');
221 if (p) *p = '.';
222 size_t l = strlen(buf);
223 while (l > 1 && buf[l - 1] == '0') --l;
224 if (l > 1 && buf[l - 1] == '.') --l;
225 fwrite(buf, l, 1, fh);
228 class AvenPresList : public wxListCtrl {
229 MainFrm * mainfrm;
230 GfxCore * gfx;
231 vector<PresentationMark> entries;
232 long current_item;
233 bool modified;
234 bool force_save_as;
235 wxString filename;
237 public:
238 AvenPresList(MainFrm * mainfrm_, wxWindow * parent, GfxCore * gfx_)
239 : wxListCtrl(parent, listctrl_PRES, wxDefaultPosition, wxDefaultSize,
240 wxLC_REPORT|wxLC_VIRTUAL),
241 mainfrm(mainfrm_), gfx(gfx_), current_item(-1), modified(false),
242 force_save_as(true)
244 InsertColumn(0, wmsg(/*Easting*/378));
245 InsertColumn(1, wmsg(/*Northing*/379));
246 InsertColumn(2, wmsg(/*Altitude*/335));
249 void OnBeginLabelEdit(wxListEvent& event) {
250 event.Veto(); // No editting allowed
252 void OnDeleteItem(wxListEvent& event) {
253 long item = event.GetIndex();
254 if (current_item == item) {
255 current_item = -1;
256 } else if (current_item > item) {
257 --current_item;
259 entries.erase(entries.begin() + item);
260 SetItemCount(entries.size());
261 modified = true;
263 void OnDeleteAllItems(wxListEvent&) {
264 entries.clear();
265 SetItemCount(entries.size());
266 filename = wxString();
267 modified = false;
268 force_save_as = true;
270 void OnListKeyDown(wxListEvent& event) {
271 switch (event.GetKeyCode()) {
272 case WXK_DELETE: {
273 long item = GetNextItem(-1, wxLIST_NEXT_ALL,
274 wxLIST_STATE_SELECTED);
275 while (item != -1) {
276 DeleteItem(item);
277 // - 1 because the indices were shifted by DeleteItem()
278 item = GetNextItem(item - 1, wxLIST_NEXT_ALL,
279 wxLIST_STATE_SELECTED);
281 break;
283 default:
284 //printf("event.GetIndex() = %ld %d\n", event.GetIndex(), event.GetKeyCode());
285 event.Skip();
288 void OnActivated(wxListEvent& event) {
289 // Jump to this view.
290 long item = event.GetIndex();
291 gfx->SetView(entries[item]);
293 void OnFocused(wxListEvent& event) {
294 current_item = event.GetIndex();
296 void OnRightClick(wxListEvent& event) {
297 long item = event.GetIndex();
298 if (item < 0) {
299 AddMark(item, gfx->GetView());
300 item = 0;
302 EditMarkDlg edit(mainfrm, entries[item]);
303 if (edit.ShowModal() == wxID_OK) {
304 entries[item] = edit.GetMark();
307 void OnChar(wxKeyEvent& event) {
308 switch (event.GetKeyCode()) {
309 case WXK_INSERT:
310 if (event.GetModifiers() == wxMOD_CONTROL) {
311 if (current_item != -1 &&
312 size_t(current_item) < entries.size()) {
313 AddMark(current_item, entries[current_item]);
315 } else {
316 AddMark(current_item);
318 break;
319 case WXK_DELETE:
320 // Already handled in OnListKeyDown.
321 break;
322 case WXK_UP: case WXK_DOWN:
323 event.Skip();
324 break;
325 default:
326 gfx->OnKeyPress(event);
329 void AddMark(long item = -1) {
330 AddMark(item, gfx->GetView());
332 void AddMark(long item, const PresentationMark & mark) {
333 if (item == -1) item = entries.size();
334 entries.insert(entries.begin() + item, mark);
335 SetItemCount(entries.size());
336 modified = true;
338 virtual wxString OnGetItemText(long item, long column) const {
339 if (item < 0 || item >= (long)entries.size()) return wxString();
340 const PresentationMark & p = entries[item];
341 double v;
342 switch (column) {
343 case 0: v = p.GetX(); break;
344 case 1: v = p.GetY(); break;
345 case 2: v = p.GetZ(); break;
346 #if 0
347 case 3: v = p.angle; break;
348 case 4: v = p.tilt_angle; break;
349 case 5: v = p.scale; break;
350 case 6: v = p.time; break;
351 #endif
352 default: return wxString();
354 return wxString::Format(wxT("%ld"), (long)v);
356 void Save(bool use_default_name) {
357 wxString fnm = filename;
358 if (!use_default_name || force_save_as) {
359 #ifdef __WXMOTIF__
360 wxString ext(wxT("*.fly"));
361 #else
362 wxString ext = wmsg(/*Aven presentations*/320);
363 ext += wxT("|*.fly");
364 #endif
365 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
366 wxString(), fnm, ext,
367 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
368 if (dlg.ShowModal() != wxID_OK) return;
369 fnm = dlg.GetPath();
372 FILE * fh_pres = wxFopen(fnm, wxT("w"));
373 if (!fh_pres) {
374 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm.c_str()));
375 return;
377 vector<PresentationMark>::const_iterator i;
378 for (i = entries.begin(); i != entries.end(); ++i) {
379 const PresentationMark &p = *i;
380 write_double(p.GetX(), fh_pres);
381 PUTC(' ', fh_pres);
382 write_double(p.GetY(), fh_pres);
383 PUTC(' ', fh_pres);
384 write_double(p.GetZ(), fh_pres);
385 PUTC(' ', fh_pres);
386 write_double(p.angle, fh_pres);
387 PUTC(' ', fh_pres);
388 write_double(p.tilt_angle, fh_pres);
389 PUTC(' ', fh_pres);
390 write_double(p.scale, fh_pres);
391 if (p.time != 0.0) {
392 PUTC(' ', fh_pres);
393 write_double(p.time, fh_pres);
395 PUTC('\n', fh_pres);
397 fclose(fh_pres);
398 filename = fnm;
399 modified = false;
400 force_save_as = false;
402 void New(const wxString &fnm) {
403 DeleteAllItems();
404 wxFileName::SplitPath(fnm, NULL, NULL, &filename, NULL, wxPATH_NATIVE);
405 filename += wxT(".fly");
406 force_save_as = true;
408 bool Load(const wxString &fnm) {
409 FILE * fh_pres = wxFopen(fnm, wxT("r"));
410 if (!fh_pres) {
411 wxString m;
412 m.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm.c_str());
413 wxGetApp().ReportError(m);
414 return false;
416 DeleteAllItems();
417 long item = 0;
418 while (!feof(fh_pres)) {
419 char buf[4096];
420 size_t i = 0;
421 while (i < sizeof(buf) - 1) {
422 int ch = GETC(fh_pres);
423 if (ch == EOF || ch == '\n' || ch == '\r') break;
424 buf[i++] = ch;
426 if (i) {
427 buf[i] = 0;
428 double x, y, z, a, t, s, T;
429 int c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
430 if (c < 6) {
431 char *p = buf;
432 while ((p = strchr(p, '.'))) *p++ = ',';
433 c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
434 if (c < 6) {
435 DeleteAllItems();
436 wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm.c_str()));
437 return false;
440 if (c == 6) T = 0;
441 AddMark(item, PresentationMark(Vector3(x, y, z), a, t, s, T));
442 ++item;
445 fclose(fh_pres);
446 filename = fnm;
447 modified = false;
448 force_save_as = false;
449 return true;
451 bool Modified() const { return modified; }
452 bool Empty() const { return entries.empty(); }
453 PresentationMark GetPresMark(int which) {
454 long item = current_item;
455 if (which == MARK_FIRST) {
456 item = 0;
457 } else if (which == MARK_NEXT) {
458 ++item;
459 } else if (which == MARK_PREV) {
460 --item;
462 if (item == -1 || item == (long)entries.size())
463 return PresentationMark();
464 if (item != current_item) {
465 // Move the focus
466 if (current_item != -1) {
467 wxListCtrl::SetItemState(current_item, wxLIST_STATE_FOCUSED,
470 wxListCtrl::SetItemState(item, wxLIST_STATE_FOCUSED,
471 wxLIST_STATE_FOCUSED);
473 return entries[item];
476 private:
478 DECLARE_NO_COPY_CLASS(AvenPresList)
479 DECLARE_EVENT_TABLE()
482 BEGIN_EVENT_TABLE(EditMarkDlg, wxDialog)
483 END_EVENT_TABLE()
485 BEGIN_EVENT_TABLE(AvenPresList, wxListCtrl)
486 EVT_LIST_BEGIN_LABEL_EDIT(listctrl_PRES, AvenPresList::OnBeginLabelEdit)
487 EVT_LIST_DELETE_ITEM(listctrl_PRES, AvenPresList::OnDeleteItem)
488 EVT_LIST_DELETE_ALL_ITEMS(listctrl_PRES, AvenPresList::OnDeleteAllItems)
489 EVT_LIST_KEY_DOWN(listctrl_PRES, AvenPresList::OnListKeyDown)
490 EVT_LIST_ITEM_ACTIVATED(listctrl_PRES, AvenPresList::OnActivated)
491 EVT_LIST_ITEM_FOCUSED(listctrl_PRES, AvenPresList::OnFocused)
492 EVT_LIST_ITEM_RIGHT_CLICK(listctrl_PRES, AvenPresList::OnRightClick)
493 EVT_CHAR(AvenPresList::OnChar)
494 END_EVENT_TABLE()
496 BEGIN_EVENT_TABLE(MainFrm, wxFrame)
497 EVT_TEXT(textctrl_FIND, MainFrm::OnFind)
498 EVT_TEXT_ENTER(textctrl_FIND, MainFrm::OnGotoFound)
499 EVT_MENU(wxID_FIND, MainFrm::OnGotoFound)
500 EVT_MENU(button_HIDE, MainFrm::OnHide)
501 EVT_UPDATE_UI(button_HIDE, MainFrm::OnHideUpdate)
502 EVT_IDLE(MainFrm::OnIdle)
504 EVT_MENU(wxID_OPEN, MainFrm::OnOpen)
505 EVT_MENU(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrain)
506 EVT_MENU(menu_FILE_LOG, MainFrm::OnShowLog)
507 EVT_MENU(wxID_PRINT, MainFrm::OnPrint)
508 EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup)
509 EVT_MENU(menu_FILE_SCREENSHOT, MainFrm::OnScreenshot)
510 // EVT_MENU(wxID_PREFERENCES, MainFrm::OnFilePreferences)
511 EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport)
512 EVT_MENU(menu_FILE_EXTEND, MainFrm::OnExtend)
513 EVT_MENU(wxID_EXIT, MainFrm::OnQuit)
514 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile)
516 EVT_MENU(menu_PRES_NEW, MainFrm::OnPresNew)
517 EVT_MENU(menu_PRES_OPEN, MainFrm::OnPresOpen)
518 EVT_MENU(menu_PRES_SAVE, MainFrm::OnPresSave)
519 EVT_MENU(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAs)
520 EVT_MENU(menu_PRES_MARK, MainFrm::OnPresMark)
521 EVT_MENU(menu_PRES_FREWIND, MainFrm::OnPresFRewind)
522 EVT_MENU(menu_PRES_REWIND, MainFrm::OnPresRewind)
523 EVT_MENU(menu_PRES_REVERSE, MainFrm::OnPresReverse)
524 EVT_MENU(menu_PRES_PLAY, MainFrm::OnPresPlay)
525 EVT_MENU(menu_PRES_FF, MainFrm::OnPresFF)
526 EVT_MENU(menu_PRES_FFF, MainFrm::OnPresFFF)
527 EVT_MENU(menu_PRES_PAUSE, MainFrm::OnPresPause)
528 EVT_MENU(wxID_STOP, MainFrm::OnPresStop)
529 EVT_MENU(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovie)
531 EVT_UPDATE_UI(menu_PRES_NEW, MainFrm::OnPresNewUpdate)
532 EVT_UPDATE_UI(menu_PRES_OPEN, MainFrm::OnPresOpenUpdate)
533 EVT_UPDATE_UI(menu_PRES_SAVE, MainFrm::OnPresSaveUpdate)
534 EVT_UPDATE_UI(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAsUpdate)
535 EVT_UPDATE_UI(menu_PRES_MARK, MainFrm::OnPresMarkUpdate)
536 EVT_UPDATE_UI(menu_PRES_FREWIND, MainFrm::OnPresFRewindUpdate)
537 EVT_UPDATE_UI(menu_PRES_REWIND, MainFrm::OnPresRewindUpdate)
538 EVT_UPDATE_UI(menu_PRES_REVERSE, MainFrm::OnPresReverseUpdate)
539 EVT_UPDATE_UI(menu_PRES_PLAY, MainFrm::OnPresPlayUpdate)
540 EVT_UPDATE_UI(menu_PRES_FF, MainFrm::OnPresFFUpdate)
541 EVT_UPDATE_UI(menu_PRES_FFF, MainFrm::OnPresFFFUpdate)
542 EVT_UPDATE_UI(menu_PRES_PAUSE, MainFrm::OnPresPauseUpdate)
543 EVT_UPDATE_UI(wxID_STOP, MainFrm::OnPresStopUpdate)
544 EVT_UPDATE_UI(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovieUpdate)
546 EVT_CLOSE(MainFrm::OnClose)
547 EVT_SET_FOCUS(MainFrm::OnSetFocus)
549 EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation)
550 EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation)
551 EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth)
552 EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast)
553 EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth)
554 EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest)
555 EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan)
556 EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation)
557 EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults)
558 EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs)
559 EVT_MENU(menu_SPLAYS_HIDE, MainFrm::OnHideSplays)
560 EVT_MENU(menu_SPLAYS_SHOW_DASHED, MainFrm::OnShowSplaysDashed)
561 EVT_MENU(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFaded)
562 EVT_MENU(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormal)
563 EVT_MENU(menu_DUPES_HIDE, MainFrm::OnHideDupes)
564 EVT_MENU(menu_DUPES_SHOW_DASHED, MainFrm::OnShowDupesDashed)
565 EVT_MENU(menu_DUPES_SHOW_FADED, MainFrm::OnShowDupesFaded)
566 EVT_MENU(menu_DUPES_SHOW_NORMAL, MainFrm::OnShowDupesNormal)
567 EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses)
568 EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances)
569 EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts)
570 EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts)
571 EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames)
572 EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames)
573 EVT_MENU(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepth)
574 EVT_MENU(menu_COLOUR_BY_DATE, MainFrm::OnColourByDate)
575 EVT_MENU(menu_COLOUR_BY_ERROR, MainFrm::OnColourByError)
576 EVT_MENU(menu_COLOUR_BY_H_ERROR, MainFrm::OnColourByHError)
577 EVT_MENU(menu_COLOUR_BY_V_ERROR, MainFrm::OnColourByVError)
578 EVT_MENU(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradient)
579 EVT_MENU(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLength)
580 EVT_MENU(menu_COLOUR_BY_SURVEY, MainFrm::OnColourBySurvey)
581 EVT_MENU(menu_COLOUR_BY_STYLE, MainFrm::OnColourByStyle)
582 EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
583 EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
584 EVT_MENU(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBox)
585 EVT_MENU(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspective)
586 EVT_MENU(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShading)
587 EVT_MENU(menu_VIEW_TEXTURED, MainFrm::OnViewTextured)
588 EVT_MENU(menu_VIEW_FOG, MainFrm::OnViewFog)
589 EVT_MENU(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLines)
590 EVT_MENU(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreen)
591 EVT_MENU(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubes)
592 EVT_MENU(menu_VIEW_TERRAIN, MainFrm::OnViewTerrain)
593 EVT_MENU(menu_IND_COMPASS, MainFrm::OnViewCompass)
594 EVT_MENU(menu_IND_CLINO, MainFrm::OnViewClino)
595 EVT_MENU(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKey)
596 EVT_MENU(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebar)
597 EVT_MENU(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanel)
598 EVT_MENU(menu_CTL_METRIC, MainFrm::OnToggleMetric)
599 EVT_MENU(menu_CTL_DEGREES, MainFrm::OnToggleDegrees)
600 EVT_MENU(menu_CTL_PERCENT, MainFrm::OnTogglePercent)
601 EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls)
602 EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine)
603 EVT_MENU(wxID_ABOUT, MainFrm::OnAbout)
605 EVT_UPDATE_UI(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrainUpdate)
606 EVT_UPDATE_UI(menu_FILE_LOG, MainFrm::OnShowLogUpdate)
607 EVT_UPDATE_UI(wxID_PRINT, MainFrm::OnPrintUpdate)
608 EVT_UPDATE_UI(menu_FILE_SCREENSHOT, MainFrm::OnScreenshotUpdate)
609 EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate)
610 EVT_UPDATE_UI(menu_FILE_EXTEND, MainFrm::OnExtendUpdate)
611 EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate)
612 EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate)
613 EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate)
614 EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate)
615 EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate)
616 EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate)
617 EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate)
618 EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate)
619 EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate)
620 EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate)
621 EVT_UPDATE_UI(menu_VIEW_SPLAYS, MainFrm::OnSplaysUpdate)
622 EVT_UPDATE_UI(menu_SPLAYS_HIDE, MainFrm::OnHideSplaysUpdate)
623 EVT_UPDATE_UI(menu_SPLAYS_SHOW_DASHED, MainFrm::OnShowSplaysDashedUpdate)
624 EVT_UPDATE_UI(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFadedUpdate)
625 EVT_UPDATE_UI(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormalUpdate)
626 EVT_UPDATE_UI(menu_VIEW_DUPES, MainFrm::OnDupesUpdate)
627 EVT_UPDATE_UI(menu_DUPES_HIDE, MainFrm::OnHideDupesUpdate)
628 EVT_UPDATE_UI(menu_DUPES_SHOW_DASHED, MainFrm::OnShowDupesDashedUpdate)
629 EVT_UPDATE_UI(menu_DUPES_SHOW_FADED, MainFrm::OnShowDupesFadedUpdate)
630 EVT_UPDATE_UI(menu_DUPES_SHOW_NORMAL, MainFrm::OnShowDupesNormalUpdate)
631 EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate)
632 EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate)
633 EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate)
634 EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate)
635 EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate)
636 EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate)
637 EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate)
638 EVT_UPDATE_UI(menu_VIEW_COLOUR_BY, MainFrm::OnColourByUpdate)
639 EVT_UPDATE_UI(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepthUpdate)
640 EVT_UPDATE_UI(menu_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
641 EVT_UPDATE_UI(menu_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
642 EVT_UPDATE_UI(menu_COLOUR_BY_H_ERROR, MainFrm::OnColourByHErrorUpdate)
643 EVT_UPDATE_UI(menu_COLOUR_BY_V_ERROR, MainFrm::OnColourByVErrorUpdate)
644 EVT_UPDATE_UI(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradientUpdate)
645 EVT_UPDATE_UI(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate)
646 EVT_UPDATE_UI(menu_COLOUR_BY_SURVEY, MainFrm::OnColourBySurveyUpdate)
647 EVT_UPDATE_UI(menu_COLOUR_BY_STYLE, MainFrm::OnColourByStyleUpdate)
648 EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
649 EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate)
650 EVT_UPDATE_UI(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspectiveUpdate)
651 EVT_UPDATE_UI(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShadingUpdate)
652 EVT_UPDATE_UI(menu_VIEW_TEXTURED, MainFrm::OnViewTexturedUpdate)
653 EVT_UPDATE_UI(menu_VIEW_FOG, MainFrm::OnViewFogUpdate)
654 EVT_UPDATE_UI(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLinesUpdate)
655 EVT_UPDATE_UI(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreenUpdate)
656 EVT_UPDATE_UI(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubesUpdate)
657 EVT_UPDATE_UI(menu_VIEW_TERRAIN, MainFrm::OnViewTerrainUpdate)
658 EVT_UPDATE_UI(menu_IND_COMPASS, MainFrm::OnViewCompassUpdate)
659 EVT_UPDATE_UI(menu_IND_CLINO, MainFrm::OnViewClinoUpdate)
660 EVT_UPDATE_UI(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKeyUpdate)
661 EVT_UPDATE_UI(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebarUpdate)
662 EVT_UPDATE_UI(menu_CTL_INDICATORS, MainFrm::OnIndicatorsUpdate)
663 EVT_UPDATE_UI(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate)
664 EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate)
665 EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate)
666 EVT_UPDATE_UI(menu_CTL_METRIC, MainFrm::OnToggleMetricUpdate)
667 EVT_UPDATE_UI(menu_CTL_DEGREES, MainFrm::OnToggleDegreesUpdate)
668 EVT_UPDATE_UI(menu_CTL_PERCENT, MainFrm::OnTogglePercentUpdate)
669 END_EVENT_TABLE()
671 class LabelCmp : public greater<const LabelInfo*> {
672 wxChar separator;
673 public:
674 explicit LabelCmp(wxChar separator_) : separator(separator_) {}
675 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
676 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
680 class LabelPlotCmp : public greater<const LabelInfo*> {
681 wxChar separator;
682 public:
683 explicit LabelPlotCmp(wxChar separator_) : separator(separator_) {}
684 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
685 int n = pt1->get_flags() - pt2->get_flags();
686 if (n) return n > 0;
687 wxString l1 = pt1->GetText().AfterLast(separator);
688 wxString l2 = pt2->GetText().AfterLast(separator);
689 n = name_cmp(l1, l2, separator);
690 if (n) return n < 0;
691 // Prefer non-2-nodes...
692 // FIXME; implement
693 // if leaf names are the same, prefer shorter labels as we can
694 // display more of them
695 n = pt1->GetText().length() - pt2->GetText().length();
696 if (n) return n < 0;
697 // make sure that we don't ever compare different labels as equal
698 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
702 #if wxUSE_DRAG_AND_DROP
703 class DnDFile : public wxFileDropTarget {
704 public:
705 explicit DnDFile(MainFrm *parent) : m_Parent(parent) { }
706 virtual bool OnDropFiles(wxCoord, wxCoord,
707 const wxArrayString &filenames);
709 private:
710 MainFrm * m_Parent;
713 bool
714 DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
716 // Load a survey file by drag-and-drop.
717 assert(filenames.GetCount() > 0);
719 if (filenames.GetCount() != 1) {
720 /* TRANSLATORS: error if you try to drag multiple files to the aven
721 * window */
722 wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336));
723 return false;
726 m_Parent->OpenFile(filenames[0]);
727 return true;
729 #endif
731 MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) :
732 wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE),
733 m_SashPosition(-1),
734 m_Gfx(NULL), m_Log(NULL),
735 pending_find(false), fullscreen_showing_menus(false)
736 #ifdef PREFDLG
737 , m_PrefsDlg(NULL)
738 #endif
740 #ifdef _WIN32
741 // The peculiar name is so that the icon is the first in the file
742 // (required by Microsoft Windows for this type of icon)
743 SetIcon(wxICON(AAA_aven));
744 #else
745 SetIcon(wxICON(aven));
746 #endif
748 #if wxCHECK_VERSION(3,1,0)
749 // Add a full screen button to the right upper corner of title bar under OS
750 // X 10.7 and later.
751 EnableFullScreenView();
752 #endif
753 CreateMenuBar();
754 MakeToolBar();
755 CreateStatusBar(2, wxST_SIZEGRIP);
756 CreateSidePanel();
758 int widths[2] = { -1 /* variable width */, -1 };
759 GetStatusBar()->SetStatusWidths(2, widths);
761 #ifdef __X__ // wxMotif or wxX11
762 int x;
763 int y;
764 GetSize(&x, &y);
765 // X seems to require a forced resize.
766 SetSize(-1, -1, x, y);
767 #endif
769 #if wxUSE_DRAG_AND_DROP
770 SetDropTarget(new DnDFile(this));
771 #endif
773 #ifdef __WXMAC__
774 m_Gfx->ForceRefresh();
775 m_Gfx->Show(true);
776 #endif
777 m_Gfx->SetFocus();
780 void MainFrm::CreateMenuBar()
782 // Create the menus and the menu bar.
784 wxMenu* filemenu = new wxMenu;
785 // wxID_OPEN stock label lacks the ellipses
786 /* TRANSLATORS: Aven menu items. An “&” goes before the letter of any
787 * accelerator key.
789 * The string "\t" separates the menu text and any accelerator key.
791 * "File" menu. The accelerators must be different within this group.
792 * c.f. 201, 380, 381. */
793 filemenu->Append(wxID_OPEN, wmsg(/*&Open...\tCtrl+O*/220));
794 /* TRANSLATORS: Open a "Terrain file" - i.e. a digital model of the
795 * terrain. */
796 filemenu->Append(menu_FILE_OPEN_TERRAIN, wmsg(/*Open &Terrain...*/453));
797 filemenu->AppendCheckItem(menu_FILE_LOG, wmsg(/*Show &Log*/144));
798 filemenu->AppendSeparator();
799 // wxID_PRINT stock label lacks the ellipses
800 filemenu->Append(wxID_PRINT, wmsg(/*&Print...\tCtrl+P*/380));
801 filemenu->Append(menu_FILE_PAGE_SETUP, wmsg(/*P&age Setup...*/381));
802 filemenu->AppendSeparator();
803 /* TRANSLATORS: In the "File" menu */
804 filemenu->Append(menu_FILE_SCREENSHOT, wmsg(/*&Screenshot...*/201));
805 filemenu->Append(menu_FILE_EXPORT, wmsg(/*&Export as...*/382));
806 /* TRANSLATORS: In the "File" menu - c.f. n:191 */
807 filemenu->Append(menu_FILE_EXTEND, wmsg(/*E&xtended Elevation...*/247));
808 #ifndef __WXMAC__
809 // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress
810 // this separator.
811 filemenu->AppendSeparator();
812 #else
813 // We suppress the "Help" menu under macOS as it would otherwise end up as
814 // an empty menu, but we need to add the "About" menu item somewhere. It
815 // really doesn't matter where as wxWidgets will move it to the "Apple"
816 // menu.
817 filemenu->Append(wxID_ABOUT);
818 #endif
819 filemenu->Append(wxID_EXIT);
821 m_history.UseMenu(filemenu);
822 m_history.Load(*wxConfigBase::Get());
824 wxMenu* rotmenu = new wxMenu;
825 /* TRANSLATORS: "Rotation" menu. The accelerators must be different within
826 * this group. Tickable menu item which toggles auto rotation.
827 * Please don't translate "Space" - that's the shortcut key to use which
828 * wxWidgets needs to parse and it should then handle translating.
830 rotmenu->AppendCheckItem(menu_ROTATION_TOGGLE, wmsg(/*Au&to-Rotate\tSpace*/231));
831 rotmenu->AppendSeparator();
832 rotmenu->Append(menu_ROTATION_REVERSE, wmsg(/*&Reverse Direction*/234));
834 wxMenu* orientmenu = new wxMenu;
835 orientmenu->Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240));
836 orientmenu->Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241));
837 orientmenu->Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242));
838 orientmenu->Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243));
839 orientmenu->AppendSeparator();
840 orientmenu->Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248));
841 orientmenu->Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249));
842 orientmenu->AppendSeparator();
843 orientmenu->Append(menu_ORIENT_DEFAULTS, wmsg(/*Restore De&fault View*/254));
845 wxMenu* presmenu = new wxMenu;
846 presmenu->Append(menu_PRES_NEW, wmsg(/*&New Presentation*/311));
847 presmenu->Append(menu_PRES_OPEN, wmsg(/*&Open Presentation...*/312));
848 presmenu->Append(menu_PRES_SAVE, wmsg(/*&Save Presentation*/313));
849 presmenu->Append(menu_PRES_SAVE_AS, wmsg(/*Sa&ve Presentation As...*/314));
850 presmenu->AppendSeparator();
851 /* TRANSLATORS: "Mark" as in "Mark this position" */
852 presmenu->Append(menu_PRES_MARK, wmsg(/*&Mark*/315));
853 /* TRANSLATORS: "Play" as in "Play back a recording" */
854 presmenu->AppendCheckItem(menu_PRES_PLAY, wmsg(/*Pla&y*/316));
855 presmenu->Append(menu_PRES_EXPORT_MOVIE, wmsg(/*&Export as Movie...*/317));
857 wxMenu* viewmenu = new wxMenu;
858 #ifndef PREFDLG
859 /* TRANSLATORS: Items in the "View" menu: */
860 viewmenu->AppendCheckItem(menu_VIEW_SHOW_NAMES, wmsg(/*Station &Names\tCtrl+N*/270));
861 /* TRANSLATORS: Toggles drawing of 3D passages */
862 viewmenu->AppendCheckItem(menu_VIEW_SHOW_TUBES, wmsg(/*Passage &Tubes\tCtrl+T*/346));
863 /* TRANSLATORS: Toggles drawing the surface of the Earth */
864 viewmenu->AppendCheckItem(menu_VIEW_TERRAIN, wmsg(/*Terr&ain*/449));
865 viewmenu->AppendCheckItem(menu_VIEW_SHOW_CROSSES, wmsg(/*&Crosses\tCtrl+X*/271));
866 viewmenu->AppendCheckItem(menu_VIEW_GRID, wmsg(/*&Grid\tCtrl+G*/297));
867 viewmenu->AppendCheckItem(menu_VIEW_BOUNDING_BOX, wmsg(/*&Bounding Box\tCtrl+B*/318));
868 viewmenu->AppendSeparator();
869 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
870 * "survey stations". */
871 viewmenu->AppendCheckItem(menu_VIEW_SHOW_LEGS, wmsg(/*&Underground Survey Legs\tCtrl+L*/272));
872 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
873 * "survey stations". */
874 viewmenu->AppendCheckItem(menu_VIEW_SHOW_SURFACE, wmsg(/*&Surface Survey Legs\tCtrl+F*/291));
876 wxMenu* splaymenu = new wxMenu;
877 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
878 * this is selected, such legs are not shown. */
879 splaymenu->AppendCheckItem(menu_SPLAYS_HIDE, wmsg(/*&Hide*/407));
880 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
881 * this is selected, aven will show such legs with dashed lines. */
882 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_DASHED, wmsg(/*&Dashed*/250));
883 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
884 * this is selected, aven will show such legs with less bright colours. */
885 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_FADED, wmsg(/*&Fade*/408));
886 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
887 * this is selected, such legs are shown the same as other legs. */
888 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_NORMAL, wmsg(/*&Show*/409));
889 viewmenu->Append(menu_VIEW_SPLAYS, wmsg(/*Spla&y Legs*/406), splaymenu);
891 wxMenu* dupemenu = new wxMenu;
892 dupemenu->AppendCheckItem(menu_DUPES_HIDE, wmsg(/*&Hide*/407));
893 dupemenu->AppendCheckItem(menu_DUPES_SHOW_DASHED, wmsg(/*&Dashed*/250));
894 dupemenu->AppendCheckItem(menu_DUPES_SHOW_FADED, wmsg(/*&Fade*/408));
895 dupemenu->AppendCheckItem(menu_DUPES_SHOW_NORMAL, wmsg(/*&Show*/409));
896 viewmenu->Append(menu_VIEW_DUPES, wmsg(/*&Duplicate Legs*/251), dupemenu);
898 viewmenu->AppendSeparator();
899 viewmenu->AppendCheckItem(menu_VIEW_SHOW_OVERLAPPING_NAMES, wmsg(/*&Overlapping Names*/273));
901 wxMenu* colourbymenu = new wxMenu;
902 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292));
903 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
904 colourbymenu->AppendCheckItem(menu_COLOUR_BY_ERROR, wmsg(/*Colour by &Error*/289));
905 colourbymenu->AppendCheckItem(menu_COLOUR_BY_H_ERROR, wmsg(/*Colour by &Horizontal Error*/480));
906 colourbymenu->AppendCheckItem(menu_COLOUR_BY_V_ERROR, wmsg(/*Colour by &Vertical Error*/481));
907 colourbymenu->AppendCheckItem(menu_COLOUR_BY_GRADIENT, wmsg(/*Colour by &Gradient*/85));
908 colourbymenu->AppendCheckItem(menu_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
909 colourbymenu->AppendCheckItem(menu_COLOUR_BY_SURVEY, wmsg(/*Colour by &Survey*/448));
910 colourbymenu->AppendCheckItem(menu_COLOUR_BY_STYLE, wmsg(/*Colour by St&yle*/482));
912 viewmenu->Append(menu_VIEW_COLOUR_BY, wmsg(/*Co&lour by*/450), colourbymenu);
914 viewmenu->AppendSeparator();
915 viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294));
916 viewmenu->AppendCheckItem(menu_VIEW_SHOW_FIXED_PTS, wmsg(/*Highlight &Fixed Points*/295));
917 viewmenu->AppendCheckItem(menu_VIEW_SHOW_EXPORTED_PTS, wmsg(/*Highlight E&xported Points*/296));
918 viewmenu->AppendSeparator();
919 #else
920 /* TRANSLATORS: Please don't translate "Escape" - that's the shortcut key
921 * to use which wxWidgets needs to parse and it should then handle
922 * translating.
924 viewmenu-> Append(menu_VIEW_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
925 #endif
926 viewmenu->AppendCheckItem(menu_VIEW_PERSPECTIVE, wmsg(/*&Perspective*/237));
927 // FIXME: enable this viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_SHADING, wmsg(/*&Smooth Shading*/?!?);
928 viewmenu->AppendCheckItem(menu_VIEW_TEXTURED, wmsg(/*Textured &Walls*/238));
929 /* TRANSLATORS: Toggles OpenGL "Depth Fogging" - feel free to translate
930 * using that term instead if it gives a better translation which most
931 * users will understand. */
932 viewmenu->AppendCheckItem(menu_VIEW_FOG, wmsg(/*Fade Distant Ob&jects*/239));
933 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
934 * "survey stations". */
935 viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_LINES, wmsg(/*Smoot&hed Survey Legs*/298));
936 viewmenu->AppendSeparator();
937 #ifdef __WXMAC__
938 // F11 on macOS is used by the desktop (for speaker volume and/or window
939 // navigation). The standard macOS shortcut for full screen mode is
940 // Ctrl-Command-F which in wxWidgets terms is RawCtrl+Ctrl+F.
941 wxString wxmac_fullscreen = wmsg(/*Full Screen &Mode\tF11*/356);
942 wxmac_fullscreen.Replace(wxT("\tF11"), wxT("\tRawCtrl+Ctrl+F"), false);
943 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wxmac_fullscreen);
944 // FIXME: On macOS, the standard wording here is "Enter Full Screen" and
945 // "Exit Full Screen", depending whether we are in full screen mode or not,
946 // and this isn't a checked menu item.
947 #else
948 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wmsg(/*Full Screen &Mode\tF11*/356));
949 #endif
950 #ifdef PREFDLG
951 viewmenu->AppendSeparator();
952 viewmenu-> Append(wxID_PREFERENCES, wmsg(/*&Preferences...*/347));
953 #endif
955 #ifndef PREFDLG
956 wxMenu* ctlmenu = new wxMenu;
957 ctlmenu->AppendCheckItem(menu_CTL_REVERSE, wmsg(/*&Reverse Sense\tCtrl+R*/280));
958 ctlmenu->AppendSeparator();
959 #ifdef __WXGTK__
960 // wxGTK (at least with GTK+ v2.24), if we specify a short-cut here then
961 // the key handler isn't called, so we can't exit full screen mode on
962 // Escape. wxGTK doesn't actually show the "Escape" shortcut text in the
963 // menu item, so removing it doesn't make any visual difference, and doing
964 // so allows Escape to still cancel the measuring line, but also serve to
965 // exit full screen mode if no measuring line is shown.
966 wxString wxgtk_cancelline = wmsg(/*&Cancel Measuring Line\tEscape*/281);
967 wxgtk_cancelline.Replace(wxT("\tEscape"), wxT(""), false);
968 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wxgtk_cancelline);
969 #else
970 // With wxMac and wxMSW, we can have the short-cut on the menu and still
971 // have Escape handled by the key handler to exit full screen mode.
972 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
973 #endif
974 ctlmenu->AppendSeparator();
975 wxMenu* indmenu = new wxMenu;
976 indmenu->AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Compass*/274));
977 indmenu->AppendCheckItem(menu_IND_CLINO, wmsg(/*C&linometer*/275));
978 /* TRANSLATORS: The "Colour Key" is the thing in aven showing which colour
979 * corresponds to which depth, date, survey closure error, etc. */
980 indmenu->AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*Colour &Key*/276));
981 indmenu->AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Scale Bar*/277));
982 ctlmenu->Append(menu_CTL_INDICATORS, wmsg(/*&Indicators*/299), indmenu);
983 ctlmenu->AppendCheckItem(menu_CTL_SIDE_PANEL, wmsg(/*&Side Panel*/337));
984 ctlmenu->AppendSeparator();
985 ctlmenu->AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342));
986 ctlmenu->AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343));
987 ctlmenu->AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430));
988 #endif
990 wxMenuBar* menubar = new wxMenuBar();
991 /* TRANSLATORS: Aven menu titles. An “&” goes before the letter of any
992 * accelerator key. The accelerators must be different within this group
994 menubar->Append(filemenu, wmsg(/*&File*/210));
995 menubar->Append(rotmenu, wmsg(/*&Rotation*/211));
996 menubar->Append(orientmenu, wmsg(/*&Orientation*/212));
997 menubar->Append(viewmenu, wmsg(/*&View*/213));
998 #ifndef PREFDLG
999 menubar->Append(ctlmenu, wmsg(/*&Controls*/214));
1000 #endif
1001 // TRANSLATORS: "Presentation" in the sense of a talk with a slideshow -
1002 // the items in this menu allow the user to animate between preset
1003 // views.
1004 menubar->Append(presmenu, wmsg(/*&Presentation*/216));
1005 #ifndef __WXMAC__
1006 // On wxMac the "About" menu item will be moved elsewhere, so we suppress
1007 // this menu since it will then be empty.
1008 wxMenu* helpmenu = new wxMenu;
1009 helpmenu->Append(wxID_ABOUT);
1011 menubar->Append(helpmenu, wmsg(/*&Help*/215));
1012 #endif
1013 SetMenuBar(menubar);
1016 void MainFrm::MakeToolBar()
1018 // Make the toolbar.
1020 #ifdef USING_GENERIC_TOOLBAR
1021 // This OS-X-specific code is only needed to stop the toolbar icons getting
1022 // scaled up, which just makes them look nasty and fuzzy. Once we have
1023 // larger versions of the icons, we can drop this code.
1024 wxSystemOptions::SetOption(wxT("mac.toolbar.no-native"), 1);
1025 wxToolBar* toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
1026 wxDefaultSize, wxNO_BORDER|wxTB_FLAT|wxTB_NODIVIDER|wxTB_NOALIGN);
1027 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
1028 sizer->Add(toolbar, 0, wxEXPAND);
1029 SetSizer(sizer);
1030 #else
1031 wxToolBar* toolbar = wxFrame::CreateToolBar();
1032 #endif
1034 #ifndef __WXGTK20__
1035 toolbar->SetMargins(5, 5);
1036 #endif
1038 // FIXME: TRANSLATE tooltips
1039 toolbar->AddTool(wxID_OPEN, wxT("Open"), TOOL(open), wxT("Open a survey file for viewing"));
1040 toolbar->AddTool(menu_PRES_OPEN, wxT("Open presentation"), TOOL(open_pres), wxT("Open a presentation"));
1041 toolbar->AddCheckTool(menu_FILE_LOG, wxT("View log"), TOOL(log), wxNullBitmap, wxT("View log from processing survey data"));
1042 toolbar->AddSeparator();
1043 toolbar->AddCheckTool(menu_ROTATION_TOGGLE, wxT("Toggle rotation"), TOOL(rotation), wxNullBitmap, wxT("Toggle rotation"));
1044 toolbar->AddTool(menu_ORIENT_PLAN, wxT("Plan"), TOOL(plan), wxT("Switch to plan view"));
1045 toolbar->AddTool(menu_ORIENT_ELEVATION, wxT("Elevation"), TOOL(elevation), wxT("Switch to elevation view"));
1046 toolbar->AddTool(menu_ORIENT_DEFAULTS, wxT("Default view"), TOOL(defaults), wxT("Restore default view"));
1047 toolbar->AddSeparator();
1048 toolbar->AddCheckTool(menu_VIEW_SHOW_NAMES, wxT("Names"), TOOL(names), wxNullBitmap, wxT("Show station names"));
1049 toolbar->AddCheckTool(menu_VIEW_SHOW_CROSSES, wxT("Crosses"), TOOL(crosses), wxNullBitmap, wxT("Show crosses on stations"));
1050 toolbar->AddCheckTool(menu_VIEW_SHOW_ENTRANCES, wxT("Entrances"), TOOL(entrances), wxNullBitmap, wxT("Highlight entrances"));
1051 toolbar->AddCheckTool(menu_VIEW_SHOW_FIXED_PTS, wxT("Fixed points"), TOOL(fixed_pts), wxNullBitmap, wxT("Highlight fixed points"));
1052 toolbar->AddCheckTool(menu_VIEW_SHOW_EXPORTED_PTS, wxT("Exported points"), TOOL(exported_pts), wxNullBitmap, wxT("Highlight exported stations"));
1053 toolbar->AddSeparator();
1054 toolbar->AddCheckTool(menu_VIEW_SHOW_LEGS, wxT("Underground legs"), TOOL(ug_legs), wxNullBitmap, wxT("Show underground surveys"));
1055 toolbar->AddCheckTool(menu_VIEW_SHOW_SURFACE, wxT("Surface legs"), TOOL(surface_legs), wxNullBitmap, wxT("Show surface surveys"));
1056 toolbar->AddCheckTool(menu_VIEW_SHOW_TUBES, wxT("Tubes"), TOOL(tubes), wxNullBitmap, wxT("Show passage tubes"));
1057 toolbar->AddCheckTool(menu_VIEW_TERRAIN, wxT("Terrain"), TOOL(solid_surface), wxNullBitmap, wxT("Show terrain"));
1058 toolbar->AddSeparator();
1059 toolbar->AddCheckTool(menu_PRES_FREWIND, wxT("Fast Rewind"), TOOL(pres_frew), wxNullBitmap, wxT("Very Fast Rewind"));
1060 toolbar->AddCheckTool(menu_PRES_REWIND, wxT("Rewind"), TOOL(pres_rew), wxNullBitmap, wxT("Fast Rewind"));
1061 toolbar->AddCheckTool(menu_PRES_REVERSE, wxT("Backwards"), TOOL(pres_go_back), wxNullBitmap, wxT("Play Backwards"));
1062 toolbar->AddCheckTool(menu_PRES_PAUSE, wxT("Pause"), TOOL(pres_pause), wxNullBitmap, wxT("Pause"));
1063 toolbar->AddCheckTool(menu_PRES_PLAY, wxT("Go"), TOOL(pres_go), wxNullBitmap, wxT("Play"));
1064 toolbar->AddCheckTool(menu_PRES_FF, wxT("FF"), TOOL(pres_ff), wxNullBitmap, wxT("Fast Forward"));
1065 toolbar->AddCheckTool(menu_PRES_FFF, wxT("Very FF"), TOOL(pres_fff), wxNullBitmap, wxT("Very Fast Forward"));
1066 toolbar->AddTool(wxID_STOP, wxT("Stop"), TOOL(pres_stop), wxT("Stop"));
1068 toolbar->AddSeparator();
1069 m_FindBox = new wxTextCtrl(toolbar, textctrl_FIND, wxString(), wxDefaultPosition,
1070 wxDefaultSize, wxTE_PROCESS_ENTER);
1071 toolbar->AddControl(m_FindBox);
1072 /* TRANSLATORS: "Find stations" button tooltip */
1073 toolbar->AddTool(wxID_FIND, wmsg(/*Find*/332), TOOL(find)/*, "Search for station name"*/);
1074 /* TRANSLATORS: "Hide stations" button default tooltip */
1075 toolbar->AddTool(button_HIDE, wmsg(/*Hide*/333), TOOL(hideresults)/*, "Hide search results"*/);
1077 toolbar->Realize();
1080 void MainFrm::CreateSidePanel()
1082 m_Splitter = new AvenSplitterWindow(this);
1083 #ifdef USING_GENERIC_TOOLBAR
1084 // This OS-X-specific code is only needed to stop the toolbar icons getting
1085 // scaled up, which just makes them look nasty and fuzzy. Once we have
1086 // larger versions of the icons, we can drop this code.
1087 GetSizer()->Add(m_Splitter, 1, wxEXPAND);
1088 Layout();
1089 #endif
1091 m_Notebook = new wxNotebook(m_Splitter, 400, wxDefaultPosition,
1092 wxDefaultSize,
1093 wxBK_BOTTOM);
1094 m_Notebook->Show(false);
1096 wxPanel * panel = new wxPanel(m_Notebook);
1097 m_Tree = new AvenTreeCtrl(this, panel);
1099 // m_RegexpCheckBox = new wxCheckBox(find_panel, -1,
1100 // msg(/*Regular expression*/));
1102 wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);
1103 panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2);
1104 panel->SetAutoLayout(true);
1105 panel->SetSizer(panel_sizer);
1106 // panel_sizer->SetSizeHints(panel);
1108 m_Control = new GUIControl();
1109 m_Gfx = new GfxCore(this, m_Splitter, m_Control);
1110 m_Control->SetView(m_Gfx);
1112 // Presentation panel:
1113 wxPanel * prespanel = new wxPanel(m_Notebook);
1115 m_PresList = new AvenPresList(this, prespanel, m_Gfx);
1117 wxBoxSizer *pres_panel_sizer = new wxBoxSizer(wxVERTICAL);
1118 pres_panel_sizer->Add(m_PresList, 1, wxALL | wxEXPAND, 2);
1119 prespanel->SetAutoLayout(true);
1120 prespanel->SetSizer(pres_panel_sizer);
1122 // Overall tabbed structure:
1123 // FIXME: this assumes images are 15x15
1124 wxImageList* image_list = new wxImageList(15, 15);
1125 image_list->Add(TOOL(survey_tree));
1126 image_list->Add(TOOL(pres_tree));
1127 m_Notebook->SetImageList(image_list);
1128 /* TRANSLATORS: labels for tabbed side panel this is for the tab with the
1129 * tree hierarchy of survey station names */
1130 m_Notebook->AddPage(panel, wmsg(/*Surveys*/376), true, 0);
1131 m_Notebook->AddPage(prespanel, wmsg(/*Presentation*/377), false, 1);
1133 m_Splitter->Initialize(m_Gfx);
1136 bool MainFrm::LoadData(const wxString& file, const wxString& prefix)
1138 // Load survey data from file, centre the dataset around the origin,
1139 // and prepare the data for drawing.
1141 #if 0
1142 wxStopWatch timer;
1143 timer.Start();
1144 #endif
1146 int err_msg_code = Model::Load(file, prefix);
1147 if (err_msg_code) {
1148 wxString m = wxString::Format(wmsg(err_msg_code), file.c_str());
1149 wxGetApp().ReportError(m);
1150 return false;
1153 // Update window title.
1154 SetTitle(GetSurveyTitle() + " - " APP_NAME);
1156 // Sort the labels ready for filling the tree.
1157 m_Labels.sort(LabelCmp(GetSeparator()));
1159 // Fill the tree of stations and prefixes.
1160 wxString root_name = wxFileNameFromPath(file);
1161 if (!prefix.empty()) {
1162 root_name += " (";
1163 root_name += prefix;
1164 root_name += ")";
1166 m_Tree->FillTree(root_name);
1168 // Sort labels so that entrances are displayed in preference,
1169 // then fixed points, then exported points, then other points.
1171 // Also sort by leaf name so that we'll tend to choose labels
1172 // from different surveys, rather than labels from surveys which
1173 // are earlier in the list.
1174 m_Labels.sort(LabelPlotCmp(GetSeparator()));
1176 if (!m_FindBox->GetValue().empty()) {
1177 // Highlight any stations matching the current search.
1178 DoFind();
1181 m_FileProcessed = file;
1183 return true;
1186 #if 0
1187 // Run along a newly read in traverse and make up plausible LRUD where
1188 // it is missing.
1189 void
1190 MainFrm::FixLRUD(traverse & centreline)
1192 assert(centreline.size() > 1);
1194 Double last_size = 0;
1195 vector<PointInfo>::iterator i = centreline.begin();
1196 while (i != centreline.end()) {
1197 // Get the coordinates of this vertex.
1198 Point & pt_v = *i++;
1199 Double size;
1201 if (i != centreline.end()) {
1202 Double h = sqrd(i->GetX() - pt_v.GetX()) +
1203 sqrd(i->GetY() - pt_v.GetY());
1204 Double v = sqrd(i->GetZ() - pt_v.GetZ());
1205 if (h + v > 30.0 * 30.0) {
1206 Double scale = 30.0 / sqrt(h + v);
1207 h *= scale;
1208 v *= scale;
1210 size = sqrt(h + v / 9);
1211 size /= 4;
1212 if (i == centreline.begin() + 1) {
1213 // First segment.
1214 last_size = size;
1215 } else {
1216 // Intermediate segment.
1217 swap(size, last_size);
1218 size += last_size;
1219 size /= 2;
1221 } else {
1222 // Last segment.
1223 size = last_size;
1226 Double & l = pt_v.l;
1227 Double & r = pt_v.r;
1228 Double & u = pt_v.u;
1229 Double & d = pt_v.d;
1231 if (l == 0 && r == 0 && u == 0 && d == 0) {
1232 l = r = u = d = -size;
1233 } else {
1234 if (l < 0 && r < 0) {
1235 l = r = -size;
1236 } else if (l < 0) {
1237 l = -(2 * size - r);
1238 if (l >= 0) l = -0.01;
1239 } else if (r < 0) {
1240 r = -(2 * size - l);
1241 if (r >= 0) r = -0.01;
1243 if (u < 0 && d < 0) {
1244 u = d = -size;
1245 } else if (u < 0) {
1246 u = -(2 * size - d);
1247 if (u >= 0) u = -0.01;
1248 } else if (d < 0) {
1249 d = -(2 * size - u);
1250 if (d >= 0) d = -0.01;
1255 #endif
1257 void MainFrm::OnMRUFile(wxCommandEvent& event)
1259 wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1));
1260 if (!f.empty()) OpenFile(f);
1263 void MainFrm::AddToFileHistory(const wxString & file)
1265 if (wxIsAbsolutePath(file)) {
1266 m_history.AddFileToHistory(file);
1267 } else {
1268 wxString abs = wxGetCwd();
1269 abs += wxCONFIG_PATH_SEPARATOR;
1270 abs += file;
1271 m_history.AddFileToHistory(abs);
1273 wxConfigBase *b = wxConfigBase::Get();
1274 m_history.Save(*b);
1275 b->Flush();
1278 void MainFrm::OpenFile(const wxString& file, const wxString& survey)
1280 wxBusyCursor hourglass;
1282 // Check if this is an unprocessed survey data file.
1283 if (file.length() > 4 && file[file.length() - 4] == '.') {
1284 wxString ext(file, file.length() - 3, 3);
1285 ext.MakeLower();
1286 if (ext == wxT("svx") || ext == wxT("dat") || ext == wxT("mak") ||
1287 ext == wxT("clp")) {
1288 CavernLogWindow * log = new CavernLogWindow(this, survey, m_Splitter);
1289 wxWindow * win = m_Splitter->GetWindow1();
1290 m_Splitter->ReplaceWindow(win, log);
1291 win->Show(false);
1292 if (m_Splitter->GetWindow2() == NULL) {
1293 if (win != m_Gfx) win->Destroy();
1294 } else {
1295 if (m_Splitter->IsSplit()) m_Splitter->Unsplit();
1298 if (wxFileExists(file)) AddToFileHistory(file);
1299 log->process(file);
1300 // Log window will tell us to load file if it successfully completes.
1301 return;
1305 if (!LoadData(file, survey))
1306 return;
1307 AddToFileHistory(file);
1308 InitialiseAfterLoad(file, survey);
1310 // If aven is showing the log for a .svx file and you load a .3d file, then
1311 // at this point m_Log will be the log window for the .svx file, so destroy
1312 // it - it should never legitimately be set if we get here.
1313 if (m_Log) {
1314 m_Log->Destroy();
1315 m_Log = NULL;
1319 void MainFrm::InitialiseAfterLoad(const wxString & file, const wxString & prefix)
1321 if (m_SashPosition < 0) {
1322 // Calculate sane default width for side panel.
1323 int x;
1324 int y;
1325 GetClientSize(&x, &y);
1326 if (x < 600)
1327 x /= 3;
1328 else if (x < 1000)
1329 x = 200;
1330 else
1331 x /= 5;
1332 m_SashPosition = x;
1335 // Do this before we potentially delete the log window which may own the
1336 // wxString which parameter file refers to!
1337 bool same_file = (file == m_File);
1338 if (!same_file)
1339 m_File = file;
1340 m_Survey = prefix;
1342 wxWindow * win = NULL;
1343 if (m_Splitter->GetWindow2() == NULL) {
1344 win = m_Splitter->GetWindow1();
1345 if (win == m_Gfx) win = NULL;
1348 if (!IsFullScreen()) {
1349 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1350 } else {
1351 was_showing_sidepanel_before_fullscreen = true;
1354 m_Gfx->Initialise(same_file);
1356 if (win) {
1357 // FIXME: check it actually is the log window!
1358 if (m_Log && m_Log != win)
1359 m_Log->Destroy();
1360 m_Log = win;
1361 m_Log->Show(false);
1364 if (!IsFullScreen()) {
1365 m_Notebook->Show(true);
1368 m_Gfx->Show(true);
1369 m_Gfx->SetFocus();
1372 void MainFrm::HideLog(wxWindow * log_window)
1374 if (!IsFullScreen()) {
1375 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1378 m_Log = log_window;
1379 m_Log->Show(false);
1381 if (!IsFullScreen()) {
1382 m_Notebook->Show(true);
1385 m_Gfx->Show(true);
1386 m_Gfx->SetFocus();
1390 // UI event handlers
1393 // For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx".
1394 #ifdef _WIN32
1395 # define CASE(X)
1396 #else
1397 # define CASE(X) ";" X
1398 #endif
1400 void MainFrm::OnOpen(wxCommandEvent&)
1402 #ifdef __WXMOTIF__
1403 wxString filetypes = wxT("*.3d");
1404 #else
1405 wxString filetypes;
1406 filetypes.Printf(wxT("%s|*.3d;*.svx;*.plt;*.plf;*.dat;*.mak;*.clp;*.adj;*.sht;*.una;*.xyz"
1407 CASE("*.3D;*.SVX;*.PLT;*.PLF;*.DAT;*.MAK;*.CLP;*.ADJ;*.SHT;*.UNA;*.XYZ")
1408 "|%s|*.3d" CASE("*.3D")
1409 "|%s|*.svx" CASE("*.SVX")
1410 "|%s|*.plt;*.plf" CASE("*.PLT;*.PLF")
1411 "|%s|*.mak" CASE("*.MAK")
1412 "|%s|*.dat" CASE("*.DAT")
1413 "|%s|*.clp" CASE("*.CLP")
1414 "|%s|*.adj;*.sht;*.una;*.xyz" CASE("*.ADJ;*.SHT;*.UNA;*.XYZ")
1415 "|%s|%s"),
1416 /* TRANSLATORS: Here "survey" is a "cave map" rather than
1417 * list of questions - it should be translated to the
1418 * terminology that cavers using the language would use.
1420 wmsg(/*All survey files*/229).c_str(),
1421 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
1422 * file extension, so neither should be translated. */
1423 wmsg(/*Survex 3d files*/207).c_str(),
1424 /* TRANSLATORS: Survex is the name of the software, and "svx" refers to a
1425 * file extension, so neither should be translated. */
1426 wmsg(/*Survex svx files*/329).c_str(),
1427 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1428 * surveying package, so probably shouldn’t be translated
1430 wmsg(/*Compass PLT files*/324).c_str(),
1431 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1432 * surveying package, so should not be translated
1434 wmsg(/*Compass MAK files*/330).c_str(),
1435 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1436 * surveying package, so should not be translated
1438 wmsg(/*Compass DAT files*/490).c_str(),
1439 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1440 * surveying package, so should not be translated
1442 wmsg(/*Compass CLP files*/491).c_str(),
1443 /* TRANSLATORS: "CMAP" is Bob Thrun’s cave surveying
1444 * package, so don’t translate it. */
1445 wmsg(/*CMAP XYZ files*/325).c_str(),
1446 wmsg(/*All files*/208).c_str(),
1447 wxFileSelectorDefaultWildcardStr);
1448 #endif
1449 /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
1450 * - it should be translated to the terminology that cavers using the
1451 * language would use.
1453 * File->Open dialog: */
1454 wxFileDialog dlg(this, wmsg(/*Select a survey file to view*/206),
1455 wxString(), wxString(),
1456 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1457 if (dlg.ShowModal() == wxID_OK) {
1458 OpenFile(dlg.GetPath());
1462 void MainFrm::OnOpenTerrain(wxCommandEvent&)
1464 if (!m_Gfx) return;
1466 if (GetCSProj().empty()) {
1467 wxMessageBox(wxT("No coordinate system specified in survey data"));
1468 return;
1471 #ifdef __WXMOTIF__
1472 wxString filetypes = wxT("*.*");
1473 #else
1474 wxString filetypes;
1475 filetypes.Printf(wxT("%s|*.bil;*.hgt;*.zip" CASE("*.BIL;*.HGT;*.ZIP")
1476 "|%s|%s"),
1477 wmsg(/*Terrain files*/452).c_str(),
1478 wmsg(/*All files*/208).c_str(),
1479 wxFileSelectorDefaultWildcardStr);
1480 #endif
1481 /* TRANSLATORS: "Terrain file" being a digital model of the terrain (e.g. a
1482 * grid of height values). */
1483 wxFileDialog dlg(this, wmsg(/*Select a terrain file to view*/451),
1484 wxString(), wxString(),
1485 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1486 if (dlg.ShowModal() == wxID_OK && m_Gfx->LoadDEM(dlg.GetPath())) {
1487 if (!m_Gfx->DisplayingTerrain()) m_Gfx->ToggleTerrain();
1491 void MainFrm::OnShowLog(wxCommandEvent&)
1493 if (!m_Log) {
1494 HideLog(m_Splitter->GetWindow1());
1495 return;
1497 wxWindow * win = m_Splitter->GetWindow1();
1498 m_Splitter->ReplaceWindow(win, m_Log);
1499 win->Show(false);
1500 if (m_Splitter->IsSplit()) {
1501 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
1502 m_Splitter->Unsplit();
1504 m_Log->Show(true);
1505 m_Log->SetFocus();
1506 m_Log = NULL;
1509 void MainFrm::OnScreenshot(wxCommandEvent&)
1511 wxString baseleaf;
1512 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
1513 /* TRANSLATORS: title of the save screenshot dialog */
1514 wxFileDialog dlg(this, wmsg(/*Save Screenshot*/321), wxString(),
1515 baseleaf + wxT(".png"),
1516 wxT("*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1517 if (dlg.ShowModal() == wxID_OK) {
1518 static bool png_handled = false;
1519 if (!png_handled) {
1520 #if 0 // FIXME : enable this to allow other export formats...
1521 ::wxInitAllImageHandlers();
1522 #else
1523 wxImage::AddHandler(new wxPNGHandler);
1524 #endif
1525 png_handled = true;
1527 if (!m_Gfx->SaveScreenshot(dlg.GetPath(), wxBITMAP_TYPE_PNG)) {
1528 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), dlg.GetPath().c_str()));
1533 void MainFrm::OnScreenshotUpdate(wxUpdateUIEvent& event)
1535 event.Enable(!m_File.empty());
1538 void MainFrm::OnFilePreferences(wxCommandEvent&)
1540 #ifdef PREFDLG
1541 m_PrefsDlg = new PrefsDlg(m_Gfx, this);
1542 m_PrefsDlg->Show(true);
1543 #endif
1546 void MainFrm::OnPrint(wxCommandEvent&)
1548 m_Gfx->OnPrint(m_File, GetSurveyTitle(), GetDateString());
1551 void MainFrm::PrintAndExit()
1553 m_Gfx->OnPrint(m_File, GetSurveyTitle(), GetDateString(), true);
1556 void MainFrm::OnPageSetup(wxCommandEvent&)
1558 wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData());
1559 if (dlg.ShowModal() == wxID_OK) {
1560 wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData());
1564 void MainFrm::OnExport(wxCommandEvent&)
1566 m_Gfx->OnExport(m_File, GetSurveyTitle(), GetDateString());
1569 void MainFrm::OnExtend(wxCommandEvent&)
1571 wxString output = m_Survey;
1572 if (output.empty()) {
1573 wxFileName::SplitPath(m_File, NULL, NULL, &output, NULL, wxPATH_NATIVE);
1575 output += wxT("_extend.3d");
1577 #ifdef __WXMOTIF__
1578 wxString ext(wxT("*.3d"));
1579 #else
1580 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
1581 * file extension, so neither should be translated. */
1582 wxString ext = wmsg(/*Survex 3d files*/207);
1583 ext += wxT("|*.3d");
1584 #endif
1585 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
1586 wxString(), output, ext,
1587 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1588 if (dlg.ShowModal() != wxID_OK) return;
1589 output = dlg.GetPath();
1591 wxString cmd = get_command_path(L"extend");
1592 cmd = escape_for_shell(cmd, false);
1593 if (!m_Survey.empty()) {
1594 cmd += wxT(" --survey=");
1595 cmd += escape_for_shell(m_Survey, false);
1597 cmd += wxT(" --show-breaks ");
1598 cmd += escape_for_shell(m_FileProcessed, true);
1599 cmd += wxT(" ");
1600 cmd += escape_for_shell(output, true);
1601 if (wxExecute(cmd, wxEXEC_SYNC) < 0) {
1602 wxString m;
1603 m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str());
1604 m += wxT(" (");
1605 m += wxString(strerror(errno), wxConvUTF8);
1606 m += wxT(')');
1607 wxGetApp().ReportError(m);
1608 return;
1610 if (LoadData(output, wxString()))
1611 InitialiseAfterLoad(output, wxString());
1614 void MainFrm::OnQuit(wxCommandEvent&)
1616 if (m_PresList->Modified()) {
1617 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1618 /* TRANSLATORS: and the question in that box */
1619 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1620 /* TRANSLATORS: title of message box */
1621 wmsg(/*Modified Presentation*/326),
1622 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1623 return;
1626 wxConfigBase *b = wxConfigBase::Get();
1627 if (IsFullScreen()) {
1628 b->Write(wxT("width"), -2);
1629 b->DeleteEntry(wxT("height"));
1630 } else if (IsMaximized()) {
1631 b->Write(wxT("width"), -1);
1632 b->DeleteEntry(wxT("height"));
1633 } else {
1634 int width, height;
1635 GetSize(&width, &height);
1636 b->Write(wxT("width"), width);
1637 b->Write(wxT("height"), height);
1639 b->Flush();
1640 exit(0);
1643 void MainFrm::OnClose(wxCloseEvent&)
1645 wxCommandEvent dummy;
1646 OnQuit(dummy);
1649 void MainFrm::OnAbout(wxCommandEvent&)
1651 #ifdef __WXMAC__
1652 // GetIcon() returns an invalid wxIcon under macOS.
1653 AboutDlg dlg(this, wxICON(aven));
1654 #else
1655 AboutDlg dlg(this, GetIcon());
1656 #endif
1657 dlg.Centre();
1658 dlg.ShowModal();
1661 void MainFrm::UpdateStatusBar()
1663 if (!here_text.empty()) {
1664 GetStatusBar()->SetStatusText(here_text);
1665 GetStatusBar()->SetStatusText(dist_text, 1);
1666 } else if (!coords_text.empty()) {
1667 GetStatusBar()->SetStatusText(coords_text);
1668 GetStatusBar()->SetStatusText(distfree_text, 1);
1669 } else {
1670 GetStatusBar()->SetStatusText(wxString());
1671 GetStatusBar()->SetStatusText(wxString(), 1);
1675 void MainFrm::ClearTreeSelection()
1677 m_Tree->UnselectAll();
1678 m_Gfx->SetThere();
1679 ShowInfo();
1682 void MainFrm::ClearCoords()
1684 if (!coords_text.empty()) {
1685 coords_text = wxString();
1686 UpdateStatusBar();
1690 void MainFrm::SetCoords(const Vector3 &v)
1692 Double x = v.GetX();
1693 Double y = v.GetY();
1694 Double z = v.GetZ();
1695 int units;
1696 if (m_Gfx->GetMetric()) {
1697 units = /*m*/424;
1698 } else {
1699 x /= METRES_PER_FOOT;
1700 y /= METRES_PER_FOOT;
1701 z /= METRES_PER_FOOT;
1702 units = /*ft*/428;
1704 /* TRANSLATORS: show coordinates (N = North or Northing, E = East or
1705 * Easting) */
1706 coords_text.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1707 coords_text += wxString::Format(wxT(", %s %.2f%s"),
1708 wmsg(/*Altitude*/335).c_str(),
1709 z, wmsg(units).c_str());
1710 distfree_text = wxString();
1711 UpdateStatusBar();
1714 const LabelInfo * MainFrm::GetTreeSelection() const {
1715 wxTreeItemData* sel_wx;
1716 if (!m_Tree->GetSelectionData(&sel_wx)) return NULL;
1718 const TreeData* data = static_cast<const TreeData*>(sel_wx);
1719 if (!data->IsStation()) return NULL;
1721 return data->GetLabel();
1724 void MainFrm::SetCoords(Double x, Double y, const LabelInfo * there)
1726 wxString & s = coords_text;
1727 if (m_Gfx->GetMetric()) {
1728 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1729 } else {
1730 s.Printf(wmsg(/*%.2f E, %.2f N*/338),
1731 x / METRES_PER_FOOT, y / METRES_PER_FOOT);
1734 wxString & t = distfree_text;
1735 t = wxString();
1736 if (m_Gfx->ShowingMeasuringLine() && there) {
1737 auto offset = GetOffset();
1738 Vector3 delta(x - offset.GetX() - there->GetX(),
1739 y - offset.GetY() - there->GetY(), 0);
1740 Double dh = sqrt(delta.GetX()*delta.GetX() + delta.GetY()*delta.GetY());
1741 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
1742 if (brg < 0) brg += 360;
1744 wxString from_str;
1745 /* TRANSLATORS: Used in Aven:
1746 * From <stationname>: H 12.24m, Brg 234.5°
1748 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1749 int brg_unit;
1750 if (m_Gfx->GetDegrees()) {
1751 brg_unit = /*°*/344;
1752 } else {
1753 brg *= 400.0 / 360.0;
1754 brg_unit = /*ᵍ*/345;
1757 int units;
1758 if (m_Gfx->GetMetric()) {
1759 units = /*m*/424;
1760 } else {
1761 dh /= METRES_PER_FOOT;
1762 units = /*ft*/428;
1764 /* TRANSLATORS: "H" is short for "Horizontal", "Brg" for "Bearing" (as
1765 * in Compass bearing) */
1766 t.Printf(wmsg(/*%s: H %.2f%s, Brg %03.1f%s*/374),
1767 from_str.c_str(), dh, wmsg(units).c_str(),
1768 brg, wmsg(brg_unit).c_str());
1771 UpdateStatusBar();
1774 void MainFrm::SetAltitude(Double z, const LabelInfo * there)
1776 double alt = z;
1777 int units;
1778 if (m_Gfx->GetMetric()) {
1779 units = /*m*/424;
1780 } else {
1781 alt /= METRES_PER_FOOT;
1782 units = /*ft*/428;
1784 coords_text.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
1785 alt, wmsg(units).c_str());
1787 wxString & t = distfree_text;
1788 t = wxString();
1789 if (m_Gfx->ShowingMeasuringLine() && there) {
1790 Double dz = z - GetOffset().GetZ() - there->GetZ();
1792 wxString from_str;
1793 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1795 if (!m_Gfx->GetMetric()) {
1796 dz /= METRES_PER_FOOT;
1798 // TRANSLATORS: "V" is short for "Vertical"
1799 t.Printf(wmsg(/*%s: V %.2f%s*/375), from_str.c_str(),
1800 dz, wmsg(units).c_str());
1803 UpdateStatusBar();
1806 void MainFrm::ShowInfo(const LabelInfo *here, const LabelInfo *there)
1808 assert(m_Gfx);
1810 if (!here) {
1811 m_Gfx->SetHere();
1812 m_Tree->SetHere(wxTreeItemId());
1813 // Don't clear "There" mark here.
1814 if (here_text.empty() && dist_text.empty()) return;
1815 here_text = wxString();
1816 dist_text = wxString();
1817 UpdateStatusBar();
1818 return;
1821 Vector3 v = *here + GetOffset();
1822 wxString & s = here_text;
1823 Double x = v.GetX();
1824 Double y = v.GetY();
1825 Double z = v.GetZ();
1826 int units;
1827 if (m_Gfx->GetMetric()) {
1828 units = /*m*/424;
1829 } else {
1830 x /= METRES_PER_FOOT;
1831 y /= METRES_PER_FOOT;
1832 z /= METRES_PER_FOOT;
1833 units = /*ft*/428;
1835 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1836 s += wxString::Format(wxT(", %s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
1837 z, wmsg(units).c_str());
1838 s += wxT(": ");
1839 s += here->name_or_anon();
1840 m_Gfx->SetHere(here);
1841 m_Tree->SetHere(here->tree_id);
1843 if (m_Gfx->ShowingMeasuringLine() && there) {
1844 Vector3 delta = *here - *there;
1846 Double d_horiz = sqrt(delta.GetX()*delta.GetX() +
1847 delta.GetY()*delta.GetY());
1848 Double dr = delta.magnitude();
1849 Double dz = delta.GetZ();
1851 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
1852 if (brg < 0) brg += 360;
1854 Double grd = deg(atan2(delta.GetZ(), d_horiz));
1856 wxString from_str;
1857 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1859 wxString hv_str;
1860 if (m_Gfx->GetMetric()) {
1861 units = /*m*/424;
1862 } else {
1863 d_horiz /= METRES_PER_FOOT;
1864 dr /= METRES_PER_FOOT;
1865 dz /= METRES_PER_FOOT;
1866 units = /*ft*/428;
1868 wxString len_unit = wmsg(units);
1869 /* TRANSLATORS: "H" is short for "Horizontal", "V" for "Vertical" */
1870 hv_str.Printf(wmsg(/*H %.2f%s, V %.2f%s*/340),
1871 d_horiz, len_unit.c_str(), dz, len_unit.c_str());
1872 int brg_unit;
1873 if (m_Gfx->GetDegrees()) {
1874 brg_unit = /*°*/344;
1875 } else {
1876 brg *= 400.0 / 360.0;
1877 brg_unit = /*ᵍ*/345;
1879 int grd_unit;
1880 wxString grd_str;
1881 if (m_Gfx->GetPercent()) {
1882 if (grd > 89.99) {
1883 grd = 1000000;
1884 } else if (grd < -89.99) {
1885 grd = -1000000;
1886 } else {
1887 grd = int(100 * tan(rad(grd)));
1889 if (grd > 99999 || grd < -99999) {
1890 grd_str = grd > 0 ? wxT("+") : wxT("-");
1891 /* TRANSLATORS: infinity symbol - used for the percentage gradient on
1892 * vertical angles. */
1893 grd_str += wmsg(/*∞*/431);
1895 grd_unit = /*%*/96;
1896 } else if (m_Gfx->GetDegrees()) {
1897 grd_unit = /*°*/344;
1898 } else {
1899 grd *= 400.0 / 360.0;
1900 grd_unit = /*ᵍ*/345;
1902 if (grd_str.empty()) {
1903 grd_str.Printf(wxT("%+02.1f%s"), grd, wmsg(grd_unit).c_str());
1906 wxString & d = dist_text;
1907 /* TRANSLATORS: "Dist" is short for "Distance", "Brg" for "Bearing" (as
1908 * in Compass bearing) and "Grd" for "Gradient" (the slope angle
1909 * measured by the clino) */
1910 d.Printf(wmsg(/*%s: %s, Dist %.2f%s, Brg %03.1f%s, Grd %s*/341),
1911 from_str.c_str(), hv_str.c_str(),
1912 dr, len_unit.c_str(),
1913 brg, wmsg(brg_unit).c_str(),
1914 grd_str.c_str());
1915 } else {
1916 dist_text = wxString();
1917 m_Gfx->SetThere();
1919 UpdateStatusBar();
1922 void MainFrm::DisplayTreeInfo(const wxTreeItemData* item)
1924 const TreeData* data = static_cast<const TreeData*>(item);
1925 if (data) {
1926 if (data->IsStation()) {
1927 m_Gfx->SetHereFromTree(data->GetLabel());
1928 } else {
1929 m_Gfx->SetHereSurvey(data->GetSurvey());
1930 ShowInfo();
1932 return;
1934 m_Gfx->SetHereSurvey(wxString());
1935 ShowInfo();
1938 void MainFrm::TreeItemSelected(const wxTreeItemData* item)
1940 const TreeData* data = static_cast<const TreeData*>(item);
1941 if (data && data->IsStation()) {
1942 const LabelInfo* label = data->GetLabel();
1943 if (m_Gfx->GetThere() == label) {
1944 m_Gfx->CentreOn(*label);
1945 } else {
1946 m_Gfx->SetThere(label);
1948 dist_text = wxString();
1949 // FIXME: Need to update dist_text (From ... etc)
1950 // But we don't currently know where "here" is at this point in the
1951 // code!
1952 } else {
1953 dist_text = wxString();
1954 m_Gfx->SetThere();
1955 if (!data) {
1956 // Must be the root.
1957 wxCommandEvent dummy;
1958 OnDefaults(dummy);
1959 } else {
1960 m_Gfx->ZoomToSurvey(data->GetSurvey());
1963 UpdateStatusBar();
1966 void MainFrm::OnPresNew(wxCommandEvent&)
1968 if (m_PresList->Modified()) {
1969 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1970 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1971 wmsg(/*Modified Presentation*/326),
1972 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1973 return;
1976 m_PresList->New(m_File);
1977 if (!ShowingSidePanel()) ToggleSidePanel();
1978 // Select the presentation page in the notebook.
1979 m_Notebook->SetSelection(1);
1982 void MainFrm::OnPresOpen(wxCommandEvent&)
1984 if (m_PresList->Modified()) {
1985 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1986 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1987 wmsg(/*Modified Presentation*/326),
1988 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1989 return;
1992 #ifdef __WXMOTIF__
1993 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
1994 wxT("*.fly"), wxFD_OPEN);
1995 #else
1996 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
1997 wxString::Format(wxT("%s|*.fly|%s|%s"),
1998 wmsg(/*Aven presentations*/320).c_str(),
1999 wmsg(/*All files*/208).c_str(),
2000 wxFileSelectorDefaultWildcardStr),
2001 wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2002 #endif
2003 if (dlg.ShowModal() == wxID_OK) {
2004 if (!m_PresList->Load(dlg.GetPath())) {
2005 return;
2007 // FIXME : keep a history of loaded/saved presentations, like we do for
2008 // loaded surveys...
2009 // Select the presentation page in the notebook.
2010 m_Notebook->SetSelection(1);
2014 void MainFrm::OnPresSave(wxCommandEvent&)
2016 m_PresList->Save(true);
2019 void MainFrm::OnPresSaveAs(wxCommandEvent&)
2021 m_PresList->Save(false);
2024 void MainFrm::OnPresMark(wxCommandEvent&)
2026 m_PresList->AddMark();
2029 void MainFrm::OnPresFRewind(wxCommandEvent&)
2031 m_Gfx->PlayPres(-100);
2034 void MainFrm::OnPresRewind(wxCommandEvent&)
2036 m_Gfx->PlayPres(-10);
2039 void MainFrm::OnPresReverse(wxCommandEvent&)
2041 m_Gfx->PlayPres(-1);
2044 void MainFrm::OnPresPlay(wxCommandEvent&)
2046 m_Gfx->PlayPres(1);
2049 void MainFrm::OnPresFF(wxCommandEvent&)
2051 m_Gfx->PlayPres(10);
2054 void MainFrm::OnPresFFF(wxCommandEvent&)
2056 m_Gfx->PlayPres(100);
2059 void MainFrm::OnPresPause(wxCommandEvent&)
2061 m_Gfx->PlayPres(0);
2064 void MainFrm::OnPresStop(wxCommandEvent&)
2066 m_Gfx->PlayPres(0, false);
2069 void MainFrm::OnPresExportMovie(wxCommandEvent&)
2071 #ifdef WITH_FFMPEG
2072 // FIXME : Taking the leaf of the currently loaded presentation as the
2073 // default might make more sense?
2074 wxString baseleaf;
2075 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
2076 wxFileDialog dlg(this, wmsg(/*Export Movie*/331), wxString(),
2077 baseleaf + wxT(".mp4"),
2078 wxT("MPEG|*.mp4|OGG|*.ogv|AVI|*.avi|QuickTime|*.mov|WMV|*.wmv;*.asf"),
2079 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2080 if (dlg.ShowModal() == wxID_OK) {
2081 // Error is reported by GfxCore.
2082 (void)m_Gfx->ExportMovie(dlg.GetPath());
2084 #else
2085 wxGetApp().ReportError(wxT("Movie generation support code not present"));
2086 #endif
2089 PresentationMark MainFrm::GetPresMark(int which)
2091 return m_PresList->GetPresMark(which);
2094 void MainFrm::RestrictTo(const wxString & survey)
2096 // The station names will change, so clear the current search.
2097 wxCommandEvent dummy;
2098 OnHide(dummy);
2100 wxString new_prefix;
2101 if (!survey.empty()) {
2102 if (!m_Survey.empty()) {
2103 new_prefix = m_Survey;
2104 new_prefix += GetSeparator();
2106 new_prefix += survey;
2108 // Reload the processed data rather rather than potentially reprocessing.
2109 if (!LoadData(m_FileProcessed, new_prefix))
2110 return;
2111 InitialiseAfterLoad(m_File, new_prefix);
2114 void MainFrm::OnOpenTerrainUpdate(wxUpdateUIEvent& event)
2116 event.Enable(!m_File.empty());
2119 void MainFrm::OnPresNewUpdate(wxUpdateUIEvent& event)
2121 event.Enable(!m_File.empty());
2124 void MainFrm::OnPresOpenUpdate(wxUpdateUIEvent& event)
2126 event.Enable(!m_File.empty());
2129 void MainFrm::OnPresSaveUpdate(wxUpdateUIEvent& event)
2131 event.Enable(!m_PresList->Empty());
2134 void MainFrm::OnPresSaveAsUpdate(wxUpdateUIEvent& event)
2136 event.Enable(!m_PresList->Empty());
2139 void MainFrm::OnPresMarkUpdate(wxUpdateUIEvent& event)
2141 event.Enable(!m_File.empty());
2144 void MainFrm::OnPresFRewindUpdate(wxUpdateUIEvent& event)
2146 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2147 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() < -10);
2150 void MainFrm::OnPresRewindUpdate(wxUpdateUIEvent& event)
2152 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2153 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -10);
2156 void MainFrm::OnPresReverseUpdate(wxUpdateUIEvent& event)
2158 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2159 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -1);
2162 void MainFrm::OnPresPlayUpdate(wxUpdateUIEvent& event)
2164 event.Enable(!m_PresList->Empty());
2165 event.Check(m_Gfx && m_Gfx->GetPresentationMode() &&
2166 m_Gfx->GetPresentationSpeed() == 1);
2169 void MainFrm::OnPresFFUpdate(wxUpdateUIEvent& event)
2171 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2172 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 10);
2175 void MainFrm::OnPresFFFUpdate(wxUpdateUIEvent& event)
2177 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2178 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() > 10);
2181 void MainFrm::OnPresPauseUpdate(wxUpdateUIEvent& event)
2183 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2184 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 0);
2187 void MainFrm::OnPresStopUpdate(wxUpdateUIEvent& event)
2189 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2192 void MainFrm::OnPresExportMovieUpdate(wxUpdateUIEvent& event)
2194 event.Enable(!m_PresList->Empty());
2197 void MainFrm::OnFind(wxCommandEvent&)
2199 pending_find = true;
2202 void MainFrm::OnIdle(wxIdleEvent&)
2204 if (pending_find) {
2205 DoFind();
2209 void MainFrm::DoFind()
2211 pending_find = false;
2212 wxBusyCursor hourglass;
2213 // Find stations specified by a string or regular expression pattern.
2215 wxString pattern = m_FindBox->GetValue();
2216 if (pattern.empty()) {
2217 // Hide any search result highlights.
2218 list<LabelInfo*>::iterator pos = m_Labels.begin();
2219 while (pos != m_Labels.end()) {
2220 LabelInfo* label = *pos++;
2221 label->clear_flags(LFLAG_HIGHLIGHTED);
2223 m_NumHighlighted = 0;
2224 } else {
2225 int re_flags = wxRE_NOSUB;
2227 if (true /* case insensitive */) {
2228 re_flags |= wxRE_ICASE;
2231 bool substring = true;
2232 if (false /*m_RegexpCheckBox->GetValue()*/) {
2233 re_flags |= wxRE_EXTENDED;
2234 } else if (true /* simple glob-style */) {
2235 wxString pat;
2236 for (size_t i = 0; i < pattern.size(); i++) {
2237 wxChar ch = pattern[i];
2238 // ^ only special at start; $ at end. But this is simpler...
2239 switch (ch) {
2240 case '^': case '$': case '.': case '[': case '\\':
2241 pat += wxT('\\');
2242 pat += ch;
2243 break;
2244 case '*':
2245 pat += wxT(".*");
2246 substring = false;
2247 break;
2248 case '?':
2249 pat += wxT('.');
2250 substring = false;
2251 break;
2252 default:
2253 pat += ch;
2256 pattern = pat;
2257 re_flags |= wxRE_BASIC;
2258 } else {
2259 wxString pat;
2260 for (size_t i = 0; i < pattern.size(); i++) {
2261 wxChar ch = pattern[i];
2262 // ^ only special at start; $ at end. But this is simpler...
2263 switch (ch) {
2264 case '^': case '$': case '*': case '.': case '[': case '\\':
2265 pat += wxT('\\');
2267 pat += ch;
2269 pattern = pat;
2270 re_flags |= wxRE_BASIC;
2273 if (!substring) {
2274 // FIXME "0u" required to avoid compilation error with g++-3.0
2275 if (pattern.empty() || pattern[0u] != '^') pattern = wxT('^') + pattern;
2276 // FIXME: this fails to cope with "\$" at the end of pattern...
2277 if (pattern[pattern.size() - 1] != '$') pattern += wxT('$');
2280 wxRegEx regex;
2281 if (!regex.Compile(pattern, re_flags)) {
2282 wxBell();
2283 return;
2286 int found = 0;
2288 list<LabelInfo*>::iterator pos = m_Labels.begin();
2289 while (pos != m_Labels.end()) {
2290 LabelInfo* label = *pos++;
2292 if (regex.Matches(label->GetText())) {
2293 label->set_flags(LFLAG_HIGHLIGHTED);
2294 ++found;
2295 } else {
2296 label->clear_flags(LFLAG_HIGHLIGHTED);
2300 m_NumHighlighted = found;
2302 // Re-sort so highlighted points get names in preference
2303 if (found) m_Labels.sort(LabelPlotCmp(GetSeparator()));
2306 m_Gfx->UpdateBlobs();
2307 m_Gfx->ForceRefresh();
2309 if (!m_NumHighlighted) {
2310 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*No matches were found.*/328));
2311 } else {
2312 /* TRANSLATORS: "Hide stations" button tooltip when stations are found
2314 GetToolBar()->SetToolShortHelp(button_HIDE, wxString::Format(wmsg(/*Hide %d found stations*/334).c_str(), m_NumHighlighted));
2318 void MainFrm::OnGotoFound(wxCommandEvent&)
2320 if (!m_NumHighlighted) {
2321 wxGetApp().ReportError(wmsg(/*No matches were found.*/328));
2322 return;
2325 Double xmin = DBL_MAX;
2326 Double xmax = -DBL_MAX;
2327 Double ymin = DBL_MAX;
2328 Double ymax = -DBL_MAX;
2329 Double zmin = DBL_MAX;
2330 Double zmax = -DBL_MAX;
2332 list<LabelInfo*>::iterator pos = m_Labels.begin();
2333 while (pos != m_Labels.end()) {
2334 LabelInfo* label = *pos++;
2336 if (label->get_flags() & LFLAG_HIGHLIGHTED) {
2337 if (label->GetX() < xmin) xmin = label->GetX();
2338 if (label->GetX() > xmax) xmax = label->GetX();
2339 if (label->GetY() < ymin) ymin = label->GetY();
2340 if (label->GetY() > ymax) ymax = label->GetY();
2341 if (label->GetZ() < zmin) zmin = label->GetZ();
2342 if (label->GetZ() > zmax) zmax = label->GetZ();
2346 m_Gfx->SetViewTo(xmin, xmax, ymin, ymax, zmin, zmax);
2347 m_Gfx->SetFocus();
2350 void MainFrm::OnHide(wxCommandEvent&)
2352 m_FindBox->SetValue(wxString());
2353 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*Hide*/333));
2356 void MainFrm::OnHideUpdate(wxUpdateUIEvent& ui)
2358 ui.Enable(m_NumHighlighted != 0);
2361 void MainFrm::OnViewSidePanel(wxCommandEvent&)
2363 ToggleSidePanel();
2366 void MainFrm::ToggleSidePanel()
2368 // Toggle display of the side panel.
2370 assert(m_Gfx);
2372 if (m_Splitter->IsSplit()) {
2373 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
2374 m_Splitter->Unsplit(m_Notebook);
2375 } else {
2376 m_Notebook->Show(true);
2377 m_Gfx->Show(true);
2378 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
2382 void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui)
2384 ui.Enable(!m_File.empty());
2385 ui.Check(ShowingSidePanel());
2388 bool MainFrm::ShowingSidePanel()
2390 return m_Splitter->IsSplit();
2393 void MainFrm::ViewFullScreen() {
2394 #ifdef __WXMAC__
2395 // On macOS, wxWidgets doesn't currently hide the toolbar or statusbar in
2396 // full screen mode (last checked with 3.0.2), but it is easy to do
2397 // ourselves.
2398 if (!IsFullScreen()) {
2399 GetToolBar()->Hide();
2400 GetStatusBar()->Hide();
2402 #endif
2404 ShowFullScreen(!IsFullScreen());
2405 fullscreen_showing_menus = false;
2406 if (IsFullScreen())
2407 was_showing_sidepanel_before_fullscreen = ShowingSidePanel();
2408 if (was_showing_sidepanel_before_fullscreen)
2409 ToggleSidePanel();
2411 #ifdef __WXMAC__
2412 if (!IsFullScreen()) {
2413 GetStatusBar()->Show();
2414 GetToolBar()->Show();
2415 #ifdef USING_GENERIC_TOOLBAR
2416 Layout();
2417 #endif
2419 #endif
2422 bool MainFrm::FullScreenModeShowingMenus() const
2424 return fullscreen_showing_menus;
2427 void MainFrm::FullScreenModeShowMenus(bool show)
2429 if (!IsFullScreen() || show == fullscreen_showing_menus)
2430 return;
2431 #ifdef __WXMAC__
2432 // On macOS, enabling the menu bar while in full
2433 // screen mode doesn't have any effect, so instead
2434 // make moving the mouse to the top of the screen
2435 // drop us out of full screen mode for now.
2436 ViewFullScreen();
2437 #else
2438 GetMenuBar()->Show(show);
2439 fullscreen_showing_menus = show;
2440 #endif