source: git/src/mainfrm.cc @ e748d1e

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

Add "Find" to right-click menu on survey tree

This triggers a search for the survey or station that was right-clicked
on, like double-clicking used to before 1.2.36. Requested by Patrick
Warren.

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