source: git/src/mainfrm.cc @ 1afe833

stereo-2025
Last change on this file since 1afe833 was ce4e37f, checked in by Olly Betts <olly@…>, 7 months ago

Use ′ and ″ for feet and inches

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