source: git/src/mainfrm.cc @ e9b71b2

stereo-2025
Last change on this file since e9b71b2 was 815b25e, checked in by Olly Betts <olly@…>, 8 months ago

Avoid recurring "no GDAL" dialog box

This dialog is now only shown if you try to add an overlay. Reported
by Špela Borko.

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