source: git/src/mainfrm.cc @ 028716d

stereo-2025
Last change on this file since 028716d was 2f94723, checked in by Olly Betts <olly@…>, 8 months ago

Don't expose Model::m_Labels

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