source: git/src/mainfrm.cc @ 3bb963aa

RELEASE/1.2debug-cidebug-ci-sanitiserswalls-datawalls-data-hanging-as-warning
Last change on this file since 3bb963aa was 0642381, checked in by Olly Betts <olly@…>, 6 years ago

Highlight surveys on survey tree mouseover

This is cleaner than running a search to highlight them, and means
we can restore "double-click survey in tree to zoom".

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