source: git/src/mainfrm.cc @ 6969b17

stereo-2025warn-only-for-hanging-survey
Last change on this file since 6969b17 was 6969b17, checked in by Olly Betts <olly@…>, 13 months ago

Use wxID_ANY instead of literal -1

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