source: git/src/mainfrm.cc @ ff0f549

stereo-2025
Last change on this file since ff0f549 was 87c9067, checked in by Olly Betts <olly@…>, 4 months ago

Fix build on macos

Seems we can't call our fwrite()/fwrite_unlocked() wrapper FWRITE() because
then macos errors out on uses with:

error: called object type 'int' is not a function or function pointer

It's unclear what's going on - a conditional #undef FWRITE before
defining doesn't help.

Thanks Apple!

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