source: git/src/mainfrm.cc @ 8d74d05

stereo-2025
Last change on this file since 8d74d05 was 9284d37, checked in by Olly Betts <olly@…>, 4 months ago

Allow exaggerating Z in aven

Add a spin control to the toolbar which allows setting a Z scale
factor from 0.1 and 10.0.

Fixes #49

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