source: git/src/mainfrm.cc @ 26ae6a9

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 26ae6a9 was 63c2fe8, checked in by Olly Betts <olly@…>, 9 years ago
  • .gitignore,lib/icons/,src/aven.rc,src/mainfrm.cc: Rather than loading

all the toolbar and notebook icons from PNG files on disk, compile
them into the aven binary. On most platforms, as XPMs; on MSW as
.ico files via a generated .rc file.

  • Property mode set to 100644
File size: 87.9 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 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 "printwx.h"
38#include "filename.h"
39#include "useful.h"
40
41#include <wx/confbase.h>
42#include <wx/filename.h>
43#include <wx/image.h>
44#include <wx/imaglist.h>
45#include <wx/process.h>
46#include <wx/regex.h>
47
48#include <cstdlib>
49#include <float.h>
50#include <functional>
51#include <map>
52#include <stack>
53#include <vector>
54
55#ifndef __WXMSW__
56// XPM files declare the array as static, but we also want it to be const too.
57// This avoids a compiler warning, and also means the data can go in a
58// read-only page and be shared between processes.
59#define static static const
60#include "../lib/icons/open.xpm"
61#include "../lib/icons/open_pres.xpm"
62#include "../lib/icons/rotation.xpm"
63#include "../lib/icons/plan.xpm"
64#include "../lib/icons/elevation.xpm"
65#include "../lib/icons/defaults.xpm"
66#include "../lib/icons/names.xpm"
67#include "../lib/icons/crosses.xpm"
68#include "../lib/icons/entrances.xpm"
69#include "../lib/icons/fixed_pts.xpm"
70#include "../lib/icons/exported_pts.xpm"
71#include "../lib/icons/ug_legs.xpm"
72#include "../lib/icons/surface_legs.xpm"
73#include "../lib/icons/tubes.xpm"
74#include "../lib/icons/pres_frew.xpm"
75#include "../lib/icons/pres_rew.xpm"
76#include "../lib/icons/pres_go_back.xpm"
77#include "../lib/icons/pres_pause.xpm"
78#include "../lib/icons/pres_go.xpm"
79#include "../lib/icons/pres_ff.xpm"
80#include "../lib/icons/pres_fff.xpm"
81#include "../lib/icons/pres_stop.xpm"
82#include "../lib/icons/find.xpm"
83#include "../lib/icons/hideresults.xpm"
84#include "../lib/icons/survey_tree.xpm"
85#include "../lib/icons/pres_tree.xpm"
86#undef static
87#endif
88
89using namespace std;
90
91const static int img2aven_tab[] = {
92#include "img2aven.h"
93};
94
95inline int
96img2aven(int flags)
97{
98    flags &= (sizeof(img2aven_tab) / sizeof(img2aven_tab[0]) - 1);
99    return img2aven_tab[flags];
100}
101
102class AvenSplitterWindow : public wxSplitterWindow {
103    MainFrm *parent;
104
105    public:
106        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(atof(easting->GetValue().mb_str()),
201                  atof(northing->GetValue().mb_str()),
202                  atof(altitude->GetValue().mb_str()));
203        a = atof(angle->GetValue().mb_str());
204        t = atof(tilt_angle->GetValue().mb_str());
205        s = atof(scale->GetValue().mb_str());
206        wxString str = time->GetValue();
207        if (!str.empty() && str[0u] == '*') str[0u] = '-';
208        T = atof(str.mb_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#ifdef __WXMSW__
374            FILE * fh_pres = _wfopen(fnm.fn_str(), L"w");
375#else
376            FILE * fh_pres = fopen(fnm.mb_str(), "w");
377#endif
378            if (!fh_pres) {
379                wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm.c_str()));
380                return;
381            }
382            vector<PresentationMark>::const_iterator i;
383            for (i = entries.begin(); i != entries.end(); ++i) {
384                const PresentationMark &p = *i;
385                write_double(p.GetX(), fh_pres);
386                PUTC(' ', fh_pres);
387                write_double(p.GetY(), fh_pres);
388                PUTC(' ', fh_pres);
389                write_double(p.GetZ(), fh_pres);
390                PUTC(' ', fh_pres);
391                write_double(p.angle, fh_pres);
392                PUTC(' ', fh_pres);
393                write_double(p.tilt_angle, fh_pres);
394                PUTC(' ', fh_pres);
395                write_double(p.scale, fh_pres);
396                if (p.time != 0.0) {
397                    PUTC(' ', fh_pres);
398                    write_double(p.time, fh_pres);
399                }
400                PUTC('\n', fh_pres);
401            }
402            fclose(fh_pres);
403            filename = fnm;
404            modified = false;
405            force_save_as = false;
406        }
407        void New(const wxString &fnm) {
408            DeleteAllItems();
409            wxFileName::SplitPath(fnm, NULL, NULL, &filename, NULL, wxPATH_NATIVE);
410            filename += wxT(".fly");
411            force_save_as = true;
412        }
413        bool Load(const wxString &fnm) {
414#ifdef __WXMSW__
415            FILE * fh_pres = _wfopen(fnm.fn_str(), L"r");
416#else
417            FILE * fh_pres = fopen(fnm.mb_str(), "r");
418#endif
419            if (!fh_pres) {
420                wxString m;
421                m.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm.c_str());
422                wxGetApp().ReportError(m);
423                return false;
424            }
425            DeleteAllItems();
426            long item = 0;
427            while (!feof(fh_pres)) {
428                char buf[4096];
429                size_t i = 0;
430                while (i < sizeof(buf) - 1) {
431                    int ch = GETC(fh_pres);
432                    if (ch == EOF || ch == '\n' || ch == '\r') break;
433                    buf[i++] = ch;
434                }
435                if (i) {
436                    buf[i] = 0;
437                    double x, y, z, a, t, s, T;
438                    int c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
439                    if (c < 6) {
440                        char *p = buf;
441                        while ((p = strchr(p, '.'))) *p++ = ',';
442                        c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
443                        if (c < 6) {
444                            DeleteAllItems();
445                            wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm.c_str()));
446                            return false;
447                        }
448                    }
449                    if (c == 6) T = 0;
450                    AddMark(item, PresentationMark(Vector3(x, y, z), a, t, s, T));
451                    ++item;
452                }
453            }
454            fclose(fh_pres);
455            filename = fnm;
456            modified = false;
457            force_save_as = false;
458            return true;
459        }
460        bool Modified() const { return modified; }
461        bool Empty() const { return entries.empty(); }
462        PresentationMark GetPresMark(int which) {
463            long item = current_item;
464            if (which == MARK_FIRST) {
465                item = 0;
466            } else if (which == MARK_NEXT) {
467                ++item;
468            } else if (which == MARK_PREV) {
469                --item;
470            }
471            if (item == -1 || item == (long)entries.size())
472                return PresentationMark();
473            if (item != current_item) {
474                // Move the focus
475                if (current_item != -1) {
476                    wxListCtrl::SetItemState(current_item, wxLIST_STATE_FOCUSED,
477                                             0);
478                }
479                wxListCtrl::SetItemState(item, wxLIST_STATE_FOCUSED,
480                                         wxLIST_STATE_FOCUSED);
481            }
482            return entries[item];
483        }
484
485    private:
486
487        DECLARE_NO_COPY_CLASS(AvenPresList)
488        DECLARE_EVENT_TABLE()
489};
490
491BEGIN_EVENT_TABLE(EditMarkDlg, wxDialog)
492END_EVENT_TABLE()
493
494BEGIN_EVENT_TABLE(AvenPresList, wxListCtrl)
495    EVT_LIST_BEGIN_LABEL_EDIT(listctrl_PRES, AvenPresList::OnBeginLabelEdit)
496    EVT_LIST_DELETE_ITEM(listctrl_PRES, AvenPresList::OnDeleteItem)
497    EVT_LIST_DELETE_ALL_ITEMS(listctrl_PRES, AvenPresList::OnDeleteAllItems)
498    EVT_LIST_KEY_DOWN(listctrl_PRES, AvenPresList::OnListKeyDown)
499    EVT_LIST_ITEM_ACTIVATED(listctrl_PRES, AvenPresList::OnActivated)
500    EVT_LIST_ITEM_FOCUSED(listctrl_PRES, AvenPresList::OnFocused)
501    EVT_LIST_ITEM_RIGHT_CLICK(listctrl_PRES, AvenPresList::OnRightClick)
502    EVT_CHAR(AvenPresList::OnChar)
503END_EVENT_TABLE()
504
505BEGIN_EVENT_TABLE(MainFrm, wxFrame)
506    EVT_TEXT(textctrl_FIND, MainFrm::OnFind)
507    EVT_TEXT_ENTER(textctrl_FIND, MainFrm::OnGotoFound)
508    EVT_MENU(wxID_FIND, MainFrm::OnGotoFound)
509    EVT_MENU(button_HIDE, MainFrm::OnHide)
510    EVT_UPDATE_UI(button_HIDE, MainFrm::OnHideUpdate)
511    EVT_IDLE(MainFrm::OnIdle)
512
513    EVT_MENU(wxID_OPEN, MainFrm::OnOpen)
514    EVT_MENU(wxID_PRINT, MainFrm::OnPrint)
515    EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup)
516    EVT_MENU(menu_FILE_SCREENSHOT, MainFrm::OnScreenshot)
517//    EVT_MENU(wxID_PREFERENCES, MainFrm::OnFilePreferences)
518    EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport)
519    EVT_MENU(wxID_EXIT, MainFrm::OnQuit)
520    EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile)
521
522    EVT_MENU(menu_PRES_NEW, MainFrm::OnPresNew)
523    EVT_MENU(menu_PRES_OPEN, MainFrm::OnPresOpen)
524    EVT_MENU(menu_PRES_SAVE, MainFrm::OnPresSave)
525    EVT_MENU(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAs)
526    EVT_MENU(menu_PRES_MARK, MainFrm::OnPresMark)
527    EVT_MENU(menu_PRES_FREWIND, MainFrm::OnPresFRewind)
528    EVT_MENU(menu_PRES_REWIND, MainFrm::OnPresRewind)
529    EVT_MENU(menu_PRES_REVERSE, MainFrm::OnPresReverse)
530    EVT_MENU(menu_PRES_PLAY, MainFrm::OnPresPlay)
531    EVT_MENU(menu_PRES_FF, MainFrm::OnPresFF)
532    EVT_MENU(menu_PRES_FFF, MainFrm::OnPresFFF)
533    EVT_MENU(menu_PRES_PAUSE, MainFrm::OnPresPause)
534    EVT_MENU(wxID_STOP, MainFrm::OnPresStop)
535    EVT_MENU(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovie)
536
537    EVT_UPDATE_UI(menu_PRES_NEW, MainFrm::OnPresNewUpdate)
538    EVT_UPDATE_UI(menu_PRES_OPEN, MainFrm::OnPresOpenUpdate)
539    EVT_UPDATE_UI(menu_PRES_SAVE, MainFrm::OnPresSaveUpdate)
540    EVT_UPDATE_UI(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAsUpdate)
541    EVT_UPDATE_UI(menu_PRES_MARK, MainFrm::OnPresMarkUpdate)
542    EVT_UPDATE_UI(menu_PRES_FREWIND, MainFrm::OnPresFRewindUpdate)
543    EVT_UPDATE_UI(menu_PRES_REWIND, MainFrm::OnPresRewindUpdate)
544    EVT_UPDATE_UI(menu_PRES_REVERSE, MainFrm::OnPresReverseUpdate)
545    EVT_UPDATE_UI(menu_PRES_PLAY, MainFrm::OnPresPlayUpdate)
546    EVT_UPDATE_UI(menu_PRES_FF, MainFrm::OnPresFFUpdate)
547    EVT_UPDATE_UI(menu_PRES_FFF, MainFrm::OnPresFFFUpdate)
548    EVT_UPDATE_UI(menu_PRES_PAUSE, MainFrm::OnPresPauseUpdate)
549    EVT_UPDATE_UI(wxID_STOP, MainFrm::OnPresStopUpdate)
550    EVT_UPDATE_UI(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovieUpdate)
551
552    EVT_CLOSE(MainFrm::OnClose)
553    EVT_SET_FOCUS(MainFrm::OnSetFocus)
554
555    EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation)
556    EVT_MENU(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUp)
557    EVT_MENU(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDown)
558    EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation)
559    EVT_MENU(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceAnticlockwise)
560    EVT_MENU(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceClockwise)
561    EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth)
562    EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast)
563    EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth)
564    EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest)
565    EVT_MENU(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeft)
566    EVT_MENU(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRight)
567    EVT_MENU(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUp)
568    EVT_MENU(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDown)
569    EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan)
570    EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation)
571    EVT_MENU(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpoint)
572    EVT_MENU(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpoint)
573    EVT_MENU(wxID_ZOOM_IN, MainFrm::OnZoomIn)
574    EVT_MENU(wxID_ZOOM_OUT, MainFrm::OnZoomOut)
575    EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults)
576    EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs)
577    EVT_MENU(menu_SPLAYS_HIDE, MainFrm::OnHideSplays)
578    EVT_MENU(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormal)
579    EVT_MENU(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFaded)
580    EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses)
581    EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances)
582    EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts)
583    EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts)
584    EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames)
585    EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames)
586    EVT_MENU(menu_VIEW_COLOUR_BY_DEPTH, MainFrm::OnColourByDepth)
587    EVT_MENU(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDate)
588    EVT_MENU(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByError)
589    EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
590    EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
591    EVT_MENU(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBox)
592    EVT_MENU(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspective)
593    EVT_MENU(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShading)
594    EVT_MENU(menu_VIEW_TEXTURED, MainFrm::OnViewTextured)
595    EVT_MENU(menu_VIEW_FOG, MainFrm::OnViewFog)
596    EVT_MENU(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLines)
597    EVT_MENU(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreen)
598    EVT_MENU(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubes)
599    EVT_MENU(menu_IND_COMPASS, MainFrm::OnViewCompass)
600    EVT_MENU(menu_IND_CLINO, MainFrm::OnViewClino)
601    EVT_MENU(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKey)
602    EVT_MENU(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebar)
603    EVT_MENU(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanel)
604    EVT_MENU(menu_CTL_METRIC, MainFrm::OnToggleMetric)
605    EVT_MENU(menu_CTL_DEGREES, MainFrm::OnToggleDegrees)
606    EVT_MENU(menu_CTL_PERCENT, MainFrm::OnTogglePercent)
607    EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls)
608    EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine)
609    EVT_MENU(wxID_ABOUT, MainFrm::OnAbout)
610
611    EVT_UPDATE_UI(wxID_PRINT, MainFrm::OnPrintUpdate)
612    EVT_UPDATE_UI(menu_FILE_SCREENSHOT, MainFrm::OnScreenshotUpdate)
613    EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate)
614    EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate)
615    EVT_UPDATE_UI(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUpUpdate)
616    EVT_UPDATE_UI(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDownUpdate)
617    EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate)
618    EVT_UPDATE_UI(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceUpdate)
619    EVT_UPDATE_UI(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceUpdate)
620    EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate)
621    EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate)
622    EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate)
623    EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate)
624    EVT_UPDATE_UI(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeftUpdate)
625    EVT_UPDATE_UI(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRightUpdate)
626    EVT_UPDATE_UI(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUpUpdate)
627    EVT_UPDATE_UI(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDownUpdate)
628    EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate)
629    EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate)
630    EVT_UPDATE_UI(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpointUpdate)
631    EVT_UPDATE_UI(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpointUpdate)
632    EVT_UPDATE_UI(wxID_ZOOM_IN, MainFrm::OnZoomInUpdate)
633    EVT_UPDATE_UI(wxID_ZOOM_OUT, MainFrm::OnZoomOutUpdate)
634    EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate)
635    EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate)
636    EVT_UPDATE_UI(menu_VIEW_SPLAYS, MainFrm::OnSplaysUpdate)
637    EVT_UPDATE_UI(menu_SPLAYS_HIDE, MainFrm::OnHideSplaysUpdate)
638    EVT_UPDATE_UI(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormalUpdate)
639    EVT_UPDATE_UI(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFadedUpdate)
640    EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate)
641    EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate)
642    EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate)
643    EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate)
644    EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate)
645    EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate)
646    EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate)
647    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DEPTH, MainFrm::OnColourByDepthUpdate)
648    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
649    EVT_UPDATE_UI(menu_VIEW_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
650    EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
651    EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate)
652    EVT_UPDATE_UI(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspectiveUpdate)
653    EVT_UPDATE_UI(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShadingUpdate)
654    EVT_UPDATE_UI(menu_VIEW_TEXTURED, MainFrm::OnViewTexturedUpdate)
655    EVT_UPDATE_UI(menu_VIEW_FOG, MainFrm::OnViewFogUpdate)
656    EVT_UPDATE_UI(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLinesUpdate)
657    EVT_UPDATE_UI(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreenUpdate)
658    EVT_UPDATE_UI(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubesUpdate)
659    EVT_UPDATE_UI(menu_IND_COMPASS, MainFrm::OnViewCompassUpdate)
660    EVT_UPDATE_UI(menu_IND_CLINO, MainFrm::OnViewClinoUpdate)
661    EVT_UPDATE_UI(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKeyUpdate)
662    EVT_UPDATE_UI(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebarUpdate)
663    EVT_UPDATE_UI(menu_CTL_INDICATORS, MainFrm::OnIndicatorsUpdate)
664    EVT_UPDATE_UI(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate)
665    EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate)
666    EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate)
667    EVT_UPDATE_UI(menu_CTL_METRIC, MainFrm::OnToggleMetricUpdate)
668    EVT_UPDATE_UI(menu_CTL_DEGREES, MainFrm::OnToggleDegreesUpdate)
669    EVT_UPDATE_UI(menu_CTL_PERCENT, MainFrm::OnTogglePercentUpdate)
670END_EVENT_TABLE()
671
672class LabelCmp : public greater<const LabelInfo*> {
673    wxChar separator;
674public:
675    LabelCmp(wxChar separator_) : separator(separator_) {}
676    bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
677        return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
678    }
679};
680
681class LabelPlotCmp : public greater<const LabelInfo*> {
682    wxChar separator;
683public:
684    LabelPlotCmp(wxChar separator_) : separator(separator_) {}
685    bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
686        int n = pt1->get_flags() - pt2->get_flags();
687        if (n) return n > 0;
688        wxString l1 = pt1->GetText().AfterLast(separator);
689        wxString l2 = pt2->GetText().AfterLast(separator);
690        n = name_cmp(l1, l2, separator);
691        if (n) return n < 0;
692        // Prefer non-2-nodes...
693        // FIXME; implement
694        // if leaf names are the same, prefer shorter labels as we can
695        // display more of them
696        n = pt1->GetText().length() - pt2->GetText().length();
697        if (n) return n < 0;
698        // make sure that we don't ever compare different labels as equal
699        return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
700    }
701};
702
703#if wxUSE_DRAG_AND_DROP
704class DnDFile : public wxFileDropTarget {
705    public:
706        DnDFile(MainFrm *parent) : m_Parent(parent) { }
707        virtual bool OnDropFiles(wxCoord, wxCoord,
708                        const wxArrayString &filenames);
709
710    private:
711        MainFrm * m_Parent;
712};
713
714bool
715DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
716{
717    // Load a survey file by drag-and-drop.
718    assert(filenames.GetCount() > 0);
719
720    if (filenames.GetCount() != 1) {
721        /* TRANSLATORS: error if you try to drag multiple files to the aven
722         * window */
723        wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336));
724        return false;
725    }
726
727    m_Parent->OpenFile(filenames[0]);
728    return true;
729}
730#endif
731
732MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) :
733    wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE),
734    m_SashPosition(-1),
735    m_Gfx(NULL), m_NumEntrances(0), m_NumFixedPts(0), m_NumExportedPts(0),
736    m_NumHighlighted(0),
737    m_HasUndergroundLegs(false), m_HasSplays(false), m_HasSurfaceLegs(false),
738    m_HasErrorInformation(false), m_IsExtendedElevation(false),
739    pending_find(false), fullscreen_showing_menus(false)
740#ifdef PREFDLG
741    , m_PrefsDlg(NULL)
742#endif
743{
744    icon_path = wxString(wmsg_cfgpth());
745    icon_path += wxCONFIG_PATH_SEPARATOR;
746    icon_path += wxT("icons");
747    icon_path += wxCONFIG_PATH_SEPARATOR;
748
749#ifdef _WIN32
750    // The peculiar name is so that the icon is the first in the file
751    // (required by Microsoft Windows for this type of icon)
752    SetIcon(wxIcon(wxT("aaaaaAven")));
753#else
754    SetIcon(wxIcon(icon_path + APP_IMAGE, wxBITMAP_TYPE_PNG));
755#endif
756
757#if wxCHECK_VERSION(3,1,0)
758    // Add a full screen button to the right upper corner of title bar under OS
759    // X 10.7 and later.
760    EnableFullScreenView();
761#endif
762    CreateMenuBar();
763    MakeToolBar();
764    CreateStatusBar(2, wxST_SIZEGRIP);
765    CreateSidePanel();
766
767    int widths[2] = { -1 /* variable width */, -1 };
768    GetStatusBar()->SetStatusWidths(2, widths);
769
770#ifdef __X__ // wxMotif or wxX11
771    int x;
772    int y;
773    GetSize(&x, &y);
774    // X seems to require a forced resize.
775    SetSize(-1, -1, x, y);
776#endif
777
778#if wxUSE_DRAG_AND_DROP
779    SetDropTarget(new DnDFile(this));
780#endif
781}
782
783void MainFrm::CreateMenuBar()
784{
785    // Create the menus and the menu bar.
786
787    wxMenu* filemenu = new wxMenu;
788    // wxID_OPEN stock label lacks the ellipses
789    /* TRANSLATORS: Aven menu items.  An “&” goes before the letter of any
790     * accelerator key.
791     *
792     * The string "\t" separates the menu text and any accelerator key.
793     *
794     * "File" menu.  The accelerators must be different within this group.
795     * c.f. 201, 380, 381. */
796    filemenu->Append(wxID_OPEN, wmsg(/*&Open…\tCtrl+O*/220));
797    filemenu->AppendSeparator();
798    // wxID_PRINT stock label lacks the ellipses
799    filemenu->Append(wxID_PRINT, wmsg(/*&Print…\tCtrl+P*/380));
800    filemenu->Append(menu_FILE_PAGE_SETUP, wmsg(/*P&age Setup…*/381));
801    filemenu->AppendSeparator();
802    /* TRANSLATORS: In the "File" menu */
803    filemenu->Append(menu_FILE_SCREENSHOT, wmsg(/*&Screenshot…*/201));
804    filemenu->Append(menu_FILE_EXPORT, wmsg(/*&Export as…*/382));
805#ifndef __WXMAC__
806    // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress
807    // this separator.
808    filemenu->AppendSeparator();
809#else
810    // We suppress the "Help" menu under OS X as it would otherwise end up as
811    // an empty menu, but we need to add the "About" menu item somewhere.  It
812    // really doesn't matter where as wxWidgets will move it to the "Apple"
813    // menu.
814    filemenu->Append(wxID_ABOUT);
815#endif
816    filemenu->Append(wxID_EXIT);
817
818    m_history.UseMenu(filemenu);
819    m_history.Load(*wxConfigBase::Get());
820
821    wxMenu* rotmenu = new wxMenu;
822    /* TRANSLATORS: "Rotation" menu.  The accelerators must be different within
823     * this group.  Tickable menu item which toggles auto rotation */
824    rotmenu->AppendCheckItem(menu_ROTATION_TOGGLE, wmsg(/*Au&to-Rotate\tSpace*/231));
825    rotmenu->AppendSeparator();
826    rotmenu->Append(menu_ROTATION_SPEED_UP, wmsg(/*Speed &Up*/232));
827    rotmenu->Append(menu_ROTATION_SLOW_DOWN, wmsg(/*Slow &Down*/233));
828    rotmenu->AppendSeparator();
829    rotmenu->Append(menu_ROTATION_REVERSE, wmsg(/*&Reverse Direction*/234));
830    rotmenu->AppendSeparator();
831    rotmenu->Append(menu_ROTATION_STEP_CCW, wmsg(/*Step Once &Anticlockwise*/235));
832    rotmenu->Append(menu_ROTATION_STEP_CW, wmsg(/*Step Once &Clockwise*/236));
833
834    wxMenu* orientmenu = new wxMenu;
835    orientmenu->Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240));
836    orientmenu->Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241));
837    orientmenu->Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242));
838    orientmenu->Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243));
839    orientmenu->AppendSeparator();
840    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
841     * - it should be translated to the terminology that cavers using the
842     * language would use. */
843    orientmenu->Append(menu_ORIENT_SHIFT_LEFT, wmsg(/*Shift Survey &Left*/244));
844    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
845     * - it should be translated to the terminology that cavers using the
846     * language would use. */
847    orientmenu->Append(menu_ORIENT_SHIFT_RIGHT, wmsg(/*Shift Survey &Right*/245));
848    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
849     * - it should be translated to the terminology that cavers using the
850     * language would use. */
851    orientmenu->Append(menu_ORIENT_SHIFT_UP, wmsg(/*Shift Survey &Up*/246));
852    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
853     * - it should be translated to the terminology that cavers using the
854     * language would use. */
855    orientmenu->Append(menu_ORIENT_SHIFT_DOWN, wmsg(/*Shift Survey &Down*/247));
856    orientmenu->AppendSeparator();
857    orientmenu->Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248));
858    orientmenu->Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249));
859    orientmenu->AppendSeparator();
860    orientmenu->Append(menu_ORIENT_HIGHER_VP, wmsg(/*&Higher Viewpoint*/250));
861    orientmenu->Append(menu_ORIENT_LOWER_VP, wmsg(/*L&ower Viewpoint*/251));
862    orientmenu->AppendSeparator();
863    // Default labels for wxID_ZOOM_IN and wxID_ZOOM_OUT don't have accels.
864    orientmenu->Append(wxID_ZOOM_IN, wmsg(/*&Zoom In\t]*/252));
865    orientmenu->Append(wxID_ZOOM_OUT, wmsg(/*Zoo&m Out\t[*/253));
866    orientmenu->AppendSeparator();
867    orientmenu->Append(menu_ORIENT_DEFAULTS, wmsg(/*Restore De&fault View*/254));
868
869    wxMenu* presmenu = new wxMenu;
870    presmenu->Append(menu_PRES_NEW, wmsg(/*&New Presentation*/311));
871    presmenu->Append(menu_PRES_OPEN, wmsg(/*&Open Presentation…*/312));
872    presmenu->Append(menu_PRES_SAVE, wmsg(/*&Save Presentation*/313));
873    presmenu->Append(menu_PRES_SAVE_AS, wmsg(/*Sa&ve Presentation As…*/314));
874    presmenu->AppendSeparator();
875    /* TRANSLATORS: "Mark" as in "Mark this position" */
876    presmenu->Append(menu_PRES_MARK, wmsg(/*&Mark*/315));
877    /* TRANSLATORS: "Play" as in "Play back a recording" */
878    presmenu->AppendCheckItem(menu_PRES_PLAY, wmsg(/*Pla&y*/316));
879    presmenu->Append(menu_PRES_EXPORT_MOVIE, wmsg(/*&Export as Movie…*/317));
880
881    wxMenu* viewmenu = new wxMenu;
882#ifndef PREFDLG
883    /* TRANSLATORS: Items in the "View" menu: */
884    viewmenu->AppendCheckItem(menu_VIEW_SHOW_NAMES, wmsg(/*Station &Names\tCtrl+N*/270));
885    /* TRANSLATORS: Toggles drawing of 3D passages */
886    viewmenu->AppendCheckItem(menu_VIEW_SHOW_TUBES, wmsg(/*Passage &Tubes\tCtrl+T*/346));
887    viewmenu->AppendCheckItem(menu_VIEW_SHOW_CROSSES, wmsg(/*&Crosses\tCtrl+X*/271));
888    viewmenu->AppendCheckItem(menu_VIEW_GRID, wmsg(/*&Grid\tCtrl+G*/297));
889    viewmenu->AppendCheckItem(menu_VIEW_BOUNDING_BOX, wmsg(/*&Bounding Box\tCtrl+B*/318));
890    viewmenu->AppendSeparator();
891    /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
892     * "survey stations". */
893    viewmenu->AppendCheckItem(menu_VIEW_SHOW_LEGS, wmsg(/*&Underground Survey Legs\tCtrl+L*/272));
894    /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
895     * "survey stations". */
896    viewmenu->AppendCheckItem(menu_VIEW_SHOW_SURFACE, wmsg(/*&Surface Survey Legs\tCtrl+F*/291));
897
898    wxMenu* splaymenu = new wxMenu;
899    splaymenu->AppendCheckItem(menu_SPLAYS_HIDE, wmsg(/*&Hide*/407));
900    splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_FADED, wmsg(/*&Fade*/408));
901    splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_NORMAL, wmsg(/*&Show*/409));
902    viewmenu->Append(menu_VIEW_SPLAYS, wmsg(/*Spla&y Legs*/406), splaymenu);
903
904    viewmenu->AppendSeparator();
905    viewmenu->AppendCheckItem(menu_VIEW_SHOW_OVERLAPPING_NAMES, wmsg(/*&Overlapping Names*/273));
906    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292));
907    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
908    viewmenu->AppendCheckItem(menu_VIEW_COLOUR_BY_ERROR, wmsg(/*Colour by E&rror*/289));
909    viewmenu->AppendSeparator();
910    viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294));
911    viewmenu->AppendCheckItem(menu_VIEW_SHOW_FIXED_PTS, wmsg(/*Highlight &Fixed Points*/295));
912    viewmenu->AppendCheckItem(menu_VIEW_SHOW_EXPORTED_PTS, wmsg(/*Highlight E&xported Points*/296));
913    viewmenu->AppendSeparator();
914#else
915    viewmenu-> Append(menu_VIEW_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
916#endif
917    viewmenu->AppendCheckItem(menu_VIEW_PERSPECTIVE, wmsg(/*&Perspective*/237));
918// FIXME: enable this    viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_SHADING, wmsg(/*&Smooth Shading*/?!?);
919    viewmenu->AppendCheckItem(menu_VIEW_TEXTURED, wmsg(/*Textured &Walls*/238));
920    /* TRANSLATORS: Toggles OpenGL "Depth Fogging" - feel free to translate
921     * using that term instead if it gives a better translation which most
922     * users will understand. */
923    viewmenu->AppendCheckItem(menu_VIEW_FOG, wmsg(/*Fade Distant Ob&jects*/239));
924    /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
925     * "survey stations". */
926    viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_LINES, wmsg(/*Smoot&hed Survey Legs*/298));
927    viewmenu->AppendSeparator();
928#ifdef __WXMAC__
929    // F11 on OS X is used by the desktop (for speaker volume and/or window
930    // navigation).  The standard OS X shortcut for full screen mode is
931    // Shift-Command-F which in wxWidgets terms is Shift+Ctrl+F.
932    wxString wxmac_fullscreen = wmsg(/*Full Screen &Mode\tF11*/356);
933    wxmac_fullscreen.Replace(wxT("\tF11"), wxT("\tShift+Ctrl+F"), false);
934    viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wxmac_fullscreen);
935#else
936    viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wmsg(/*Full Screen &Mode\tF11*/356));
937#endif
938#ifdef PREFDLG
939    viewmenu->AppendSeparator();
940    viewmenu-> Append(wxID_PREFERENCES, wmsg(/*&Preferences…*/347));
941#endif
942
943#ifndef PREFDLG
944    wxMenu* ctlmenu = new wxMenu;
945    ctlmenu->AppendCheckItem(menu_CTL_REVERSE, wmsg(/*&Reverse Sense\tCtrl+R*/280));
946    ctlmenu->AppendSeparator();
947    ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
948    ctlmenu->AppendSeparator();
949    wxMenu* indmenu = new wxMenu;
950    indmenu->AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Compass*/274));
951    indmenu->AppendCheckItem(menu_IND_CLINO, wmsg(/*C&linometer*/275));
952    /* TRANSLATORS: The "Colour Key" is the thing in aven showing which colour
953     * corresponds to which depth, date, survey closure error, etc. */
954    indmenu->AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*Colour &Key*/276));
955    indmenu->AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Scale Bar*/277));
956    ctlmenu->Append(menu_CTL_INDICATORS, wmsg(/*&Indicators*/299), indmenu);
957    ctlmenu->AppendCheckItem(menu_CTL_SIDE_PANEL, wmsg(/*&Side Panel*/337));
958    ctlmenu->AppendSeparator();
959    ctlmenu->AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342));
960    ctlmenu->AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343));
961    ctlmenu->AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430));
962#endif
963
964    wxMenuBar* menubar = new wxMenuBar();
965    /* TRANSLATORS: Aven menu titles.  An “&” goes before the letter of any
966     * accelerator key.  The accelerators must be different within this group
967     */
968    menubar->Append(filemenu, wmsg(/*&File*/210));
969    menubar->Append(rotmenu, wmsg(/*&Rotation*/211));
970    menubar->Append(orientmenu, wmsg(/*&Orientation*/212));
971    menubar->Append(viewmenu, wmsg(/*&View*/213));
972#ifndef PREFDLG
973    menubar->Append(ctlmenu, wmsg(/*&Controls*/214));
974#endif
975    menubar->Append(presmenu, wmsg(/*&Presentation*/216));
976#ifndef __WXMAC__
977    // On wxMac the "About" menu item will be moved elsewhere, so we suppress
978    // this menu since it will then be empty.
979    wxMenu* helpmenu = new wxMenu;
980    helpmenu->Append(wxID_ABOUT);
981
982    menubar->Append(helpmenu, wmsg(/*&Help*/215));
983#endif
984    SetMenuBar(menubar);
985}
986
987void MainFrm::MakeToolBar()
988{
989    // Make the toolbar.
990
991    wxToolBar* toolbar = wxFrame::CreateToolBar();
992
993#ifndef __WXGTK20__
994    toolbar->SetMargins(5, 5);
995#endif
996
997    // FIXME: TRANSLATE tooltips
998    toolbar->AddTool(wxID_OPEN, wxT("Open"), wxBITMAP(open), wxT("Open a survey file for viewing"));
999    toolbar->AddTool(menu_PRES_OPEN, wxT("Open presentation"), wxBITMAP(open_pres), wxT("Open a presentation"));
1000    toolbar->AddSeparator();
1001    toolbar->AddCheckTool(menu_ROTATION_TOGGLE, wxT("Toggle rotation"), wxBITMAP(rotation), wxNullBitmap, wxT("Toggle rotation"));
1002    toolbar->AddTool(menu_ORIENT_PLAN, wxT("Plan"), wxBITMAP(plan), wxT("Switch to plan view"));
1003    toolbar->AddTool(menu_ORIENT_ELEVATION, wxT("Elevation"), wxBITMAP(elevation), wxT("Switch to elevation view"));
1004    toolbar->AddTool(menu_ORIENT_DEFAULTS, wxT("Default view"), wxBITMAP(defaults), wxT("Restore default view"));
1005    toolbar->AddSeparator();
1006    toolbar->AddCheckTool(menu_VIEW_SHOW_NAMES, wxT("Names"), wxBITMAP(names), wxNullBitmap, wxT("Show station names"));
1007    toolbar->AddCheckTool(menu_VIEW_SHOW_CROSSES, wxT("Crosses"), wxBITMAP(crosses), wxNullBitmap, wxT("Show crosses on stations"));
1008    toolbar->AddCheckTool(menu_VIEW_SHOW_ENTRANCES, wxT("Entrances"), wxBITMAP(entrances), wxNullBitmap, wxT("Highlight entrances"));
1009    toolbar->AddCheckTool(menu_VIEW_SHOW_FIXED_PTS, wxT("Fixed points"), wxBITMAP(fixed_pts), wxNullBitmap, wxT("Highlight fixed points"));
1010    toolbar->AddCheckTool(menu_VIEW_SHOW_EXPORTED_PTS, wxT("Exported points"), wxBITMAP(exported_pts), wxNullBitmap, wxT("Highlight exported stations"));
1011    toolbar->AddSeparator();
1012    toolbar->AddCheckTool(menu_VIEW_SHOW_LEGS, wxT("Underground legs"), wxBITMAP(ug_legs), wxNullBitmap, wxT("Show underground surveys"));
1013    toolbar->AddCheckTool(menu_VIEW_SHOW_SURFACE, wxT("Surface legs"), wxBITMAP(surface_legs), wxNullBitmap, wxT("Show surface surveys"));
1014    toolbar->AddCheckTool(menu_VIEW_SHOW_TUBES, wxT("Tubes"), wxBITMAP(tubes), wxNullBitmap, wxT("Show passage tubes"));
1015    toolbar->AddSeparator();
1016    toolbar->AddCheckTool(menu_PRES_FREWIND, wxT("Fast Rewind"), wxBITMAP(pres_frew), wxNullBitmap, wxT("Very Fast Rewind"));
1017    toolbar->AddCheckTool(menu_PRES_REWIND, wxT("Rewind"), wxBITMAP(pres_rew), wxNullBitmap, wxT("Fast Rewind"));
1018    toolbar->AddCheckTool(menu_PRES_REVERSE, wxT("Backwards"), wxBITMAP(pres_go_back), wxNullBitmap, wxT("Play Backwards"));
1019    toolbar->AddCheckTool(menu_PRES_PAUSE, wxT("Pause"), wxBITMAP(pres_pause), wxNullBitmap, wxT("Pause"));
1020    toolbar->AddCheckTool(menu_PRES_PLAY, wxT("Go"), wxBITMAP(pres_go), wxNullBitmap, wxT("Play"));
1021    toolbar->AddCheckTool(menu_PRES_FF, wxT("FF"), wxBITMAP(pres_ff), wxNullBitmap, wxT("Fast Forward"));
1022    toolbar->AddCheckTool(menu_PRES_FFF, wxT("Very FF"), wxBITMAP(pres_fff), wxNullBitmap, wxT("Very Fast Forward"));
1023    toolbar->AddTool(wxID_STOP, wxT("Stop"), wxBITMAP(pres_stop), wxT("Stop"));
1024
1025    toolbar->AddSeparator();
1026    m_FindBox = new wxTextCtrl(toolbar, textctrl_FIND, wxString(), wxDefaultPosition,
1027                               wxDefaultSize, wxTE_PROCESS_ENTER);
1028    toolbar->AddControl(m_FindBox);
1029    /* TRANSLATORS: "Find stations" button tooltip */
1030    toolbar->AddTool(wxID_FIND, wmsg(/*Find*/332), wxBITMAP(find)/*, "Search for station name"*/);
1031    /* TRANSLATORS: "Hide stations" button default tooltip */
1032    toolbar->AddTool(button_HIDE, wmsg(/*Hide*/333), wxBITMAP(hideresults)/*, "Hide search results"*/);
1033
1034    toolbar->Realize();
1035}
1036
1037void MainFrm::CreateSidePanel()
1038{
1039    m_Splitter = new AvenSplitterWindow(this);
1040
1041    m_Notebook = new wxNotebook(m_Splitter, 400, wxDefaultPosition,
1042                                wxDefaultSize,
1043                                wxBK_BOTTOM | wxBK_LEFT);
1044    m_Notebook->Show(false);
1045
1046    wxPanel * panel = new wxPanel(m_Notebook);
1047    m_Tree = new AvenTreeCtrl(this, panel);
1048
1049//    m_RegexpCheckBox = new wxCheckBox(find_panel, -1,
1050//                                    msg(/*Regular expression*/));
1051
1052    wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);
1053    panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2);
1054    panel->SetAutoLayout(true);
1055    panel->SetSizer(panel_sizer);
1056//    panel_sizer->SetSizeHints(panel);
1057
1058    m_Control = new GUIControl();
1059    m_Gfx = new GfxCore(this, m_Splitter, m_Control);
1060    m_Control->SetView(m_Gfx);
1061
1062    // Presentation panel:
1063    wxPanel * prespanel = new wxPanel(m_Notebook);
1064
1065    m_PresList = new AvenPresList(this, prespanel, m_Gfx);
1066
1067    wxBoxSizer *pres_panel_sizer = new wxBoxSizer(wxVERTICAL);
1068    pres_panel_sizer->Add(m_PresList, 1, wxALL | wxEXPAND, 2);
1069    prespanel->SetAutoLayout(true);
1070    prespanel->SetSizer(pres_panel_sizer);
1071
1072    // Overall tabbed structure:
1073    // FIXME: this assumes images are 15x15
1074    wxImageList* image_list = new wxImageList(15, 15);
1075    image_list->Add(wxBITMAP(survey_tree));
1076    image_list->Add(wxBITMAP(pres_tree));
1077    m_Notebook->SetImageList(image_list);
1078    /* TRANSLATORS: labels for tabbed side panel this is for the tab with the
1079     * tree hierarchy of survey station names */
1080    m_Notebook->AddPage(panel, wmsg(/*Surveys*/376), true, 0);
1081    m_Notebook->AddPage(prespanel, wmsg(/*Presentation*/377), false, 1);
1082
1083    m_Splitter->Initialize(m_Gfx);
1084}
1085
1086bool MainFrm::LoadData(const wxString& file, const wxString & prefix)
1087{
1088    // Load survey data from file, centre the dataset around the origin,
1089    // and prepare the data for drawing.
1090
1091#if 0
1092    wxStopWatch timer;
1093    timer.Start();
1094#endif
1095
1096    // Load the processed survey data.
1097    img* survey = img_open_survey(file.mb_str(), prefix.mb_str());
1098    if (!survey) {
1099        wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str());
1100        wxGetApp().ReportError(m);
1101        return false;
1102    }
1103
1104    m_IsExtendedElevation = survey->is_extended_elevation;
1105
1106    m_Tree->DeleteAllItems();
1107
1108    // Create a list of all the leg vertices, counting them and finding the
1109    // extent of the survey at the same time.
1110
1111    m_NumFixedPts = 0;
1112    m_NumExportedPts = 0;
1113    m_NumEntrances = 0;
1114    m_HasUndergroundLegs = false;
1115    m_HasSplays = false;
1116    m_HasSurfaceLegs = false;
1117    m_HasErrorInformation = false;
1118
1119    // FIXME: discard existing presentation? ask user about saving if we do!
1120
1121    // Delete any existing list entries.
1122    m_Labels.clear();
1123
1124    Double xmin = DBL_MAX;
1125    Double xmax = -DBL_MAX;
1126    Double ymin = DBL_MAX;
1127    Double ymax = -DBL_MAX;
1128    Double zmin = DBL_MAX;
1129    Double zmax = -DBL_MAX;
1130
1131    m_DepthMin = DBL_MAX;
1132    Double depthmax = -DBL_MAX;
1133
1134    m_DateMin = INT_MAX;
1135    int datemax = -1;
1136    complete_dateinfo = true;
1137
1138    traverses.clear();
1139    surface_traverses.clear();
1140    tubes.clear();
1141
1142    // Ultimately we probably want different types (subclasses perhaps?) for
1143    // underground and surface data, so we don't need to store LRUD for surface
1144    // stuff.
1145    traverse * current_traverse = NULL;
1146    traverse * current_surface_traverse = NULL;
1147    vector<XSect> * current_tube = NULL;
1148
1149    map<wxString, LabelInfo *> labelmap;
1150    list<LabelInfo*>::const_iterator last_mapped_label = m_Labels.begin();
1151
1152    int result;
1153    img_point prev_pt = {0,0,0};
1154    bool current_polyline_is_surface = false;
1155    bool current_polyline_is_splay = false;
1156    bool pending_move = false;
1157    // When a traverse is split between surface and underground, we split it
1158    // into contiguous traverses of each, but we need to track these so we can
1159    // assign the error statistics to all of them.  So we keep counts of how
1160    // many surface_traverses and traverses we've generated for the current
1161    // traverse.
1162    size_t n_traverses = 0;
1163    size_t n_surface_traverses = 0;
1164    do {
1165#if 0
1166        if (++items % 200 == 0) {
1167            long pos = ftell(survey->fh);
1168            int progress = int((double(pos) / double(file_size)) * 100.0);
1169            // SetProgress(progress);
1170        }
1171#endif
1172
1173        img_point pt;
1174        result = img_read_item(survey, &pt);
1175        switch (result) {
1176            case img_MOVE:
1177                n_traverses = n_surface_traverses = 0;
1178                pending_move = true;
1179                prev_pt = pt;
1180                break;
1181
1182            case img_LINE: {
1183                // Update survey extents.
1184                if (pt.x < xmin) xmin = pt.x;
1185                if (pt.x > xmax) xmax = pt.x;
1186                if (pt.y < ymin) ymin = pt.y;
1187                if (pt.y > ymax) ymax = pt.y;
1188                if (pt.z < zmin) zmin = pt.z;
1189                if (pt.z > zmax) zmax = pt.z;
1190
1191                int date = survey->days1;
1192                if (date != -1) {
1193                    date += (survey->days2 - date) / 2;
1194                    if (date < m_DateMin) m_DateMin = date;
1195                    if (date > datemax) datemax = date;
1196                } else {
1197                    complete_dateinfo = false;
1198                }
1199
1200                if (survey->flags & img_FLAG_SPLAY)
1201                    m_HasSplays = true;
1202                bool is_surface = (survey->flags & img_FLAG_SURFACE);
1203                bool is_splay = (survey->flags & img_FLAG_SPLAY);
1204                if (!is_surface) {
1205                    if (pt.z < m_DepthMin) m_DepthMin = pt.z;
1206                    if (pt.z > depthmax) depthmax = pt.z;
1207                }
1208                if (pending_move || current_polyline_is_surface != is_surface || current_polyline_is_splay != is_splay) {
1209                    if (!current_polyline_is_surface && current_traverse) {
1210                        //FixLRUD(*current_traverse);
1211                    }
1212
1213                    // Start new traverse (surface or underground).
1214                    if (is_surface) {
1215                        m_HasSurfaceLegs = true;
1216                        surface_traverses.push_back(traverse());
1217                        current_surface_traverse = &surface_traverses.back();
1218                        ++n_surface_traverses;
1219                    } else {
1220                        m_HasUndergroundLegs = true;
1221                        traverses.push_back(traverse());
1222                        current_traverse = &traverses.back();
1223                        current_traverse->isSplay = is_splay;
1224                        ++n_traverses;
1225                        // The previous point was at a surface->ug transition.
1226                        if (current_polyline_is_surface) {
1227                            if (prev_pt.z < m_DepthMin) m_DepthMin = prev_pt.z;
1228                            if (prev_pt.z > depthmax) depthmax = prev_pt.z;
1229                        }
1230                    }
1231
1232                    current_polyline_is_surface = is_surface;
1233                    current_polyline_is_splay = is_splay;
1234
1235                    if (pending_move) {
1236                        // Update survey extents.  We only need to do this if
1237                        // there's a pending move, since for a surface <->
1238                        // underground transition, we'll already have handled
1239                        // this point.
1240                        if (prev_pt.x < xmin) xmin = prev_pt.x;
1241                        if (prev_pt.x > xmax) xmax = prev_pt.x;
1242                        if (prev_pt.y < ymin) ymin = prev_pt.y;
1243                        if (prev_pt.y > ymax) ymax = prev_pt.y;
1244                        if (prev_pt.z < zmin) zmin = prev_pt.z;
1245                        if (prev_pt.z > zmax) zmax = prev_pt.z;
1246                    }
1247
1248                    if (is_surface) {
1249                        current_surface_traverse->push_back(PointInfo(prev_pt));
1250                    } else {
1251                        current_traverse->push_back(PointInfo(prev_pt));
1252                    }
1253                }
1254
1255                if (is_surface) {
1256                    current_surface_traverse->push_back(PointInfo(pt, date));
1257                } else {
1258                    current_traverse->push_back(PointInfo(pt, date));
1259                }
1260
1261                prev_pt = pt;
1262                pending_move = false;
1263                break;
1264            }
1265
1266            case img_LABEL: {
1267                wxString s(survey->label, wxConvUTF8);
1268                if (s.empty()) {
1269                    // If label isn't valid UTF-8 then this conversion will
1270                    // give an empty string.  In this case, assume that the
1271                    // label is CP1252 (the Microsoft superset of ISO8859-1).
1272                    static wxCSConv ConvCP1252(wxFONTENCODING_CP1252);
1273                    s = wxString(survey->label, ConvCP1252);
1274                    if (s.empty()) {
1275                        // Or if that doesn't work (ConvCP1252 doesn't like
1276                        // strings with some bytes in) let's just go for
1277                        // ISO8859-1.
1278                        s = wxString(survey->label, wxConvISO8859_1);
1279                    }
1280                }
1281                int flags = img2aven(survey->flags);
1282                LabelInfo* label = new LabelInfo(pt, s, flags);
1283                if (label->IsEntrance()) {
1284                    m_NumEntrances++;
1285                }
1286                if (label->IsFixedPt()) {
1287                    m_NumFixedPts++;
1288                }
1289                if (label->IsExportedPt()) {
1290                    m_NumExportedPts++;
1291                }
1292                m_Labels.push_back(label);
1293                break;
1294            }
1295
1296            case img_XSECT: {
1297                if (!current_tube) {
1298                    // Start new current_tube.
1299                    tubes.push_back(vector<XSect>());
1300                    current_tube = &tubes.back();
1301                }
1302
1303                LabelInfo * lab;
1304                wxString label(survey->label, wxConvUTF8);
1305                map<wxString, LabelInfo *>::const_iterator p;
1306                p = labelmap.find(label);
1307                if (p != labelmap.end()) {
1308                    lab = p->second;
1309                } else {
1310                    // Initialise labelmap lazily - we may have no
1311                    // cross-sections.
1312                    list<LabelInfo*>::const_iterator i;
1313                    if (labelmap.empty()) {
1314                        i = m_Labels.begin();
1315                    } else {
1316                        i = last_mapped_label;
1317                        ++i;
1318                    }
1319                    while (i != m_Labels.end() && (*i)->GetText() != label) {
1320                        labelmap[(*i)->GetText()] = *i;
1321                        ++i;
1322                    }
1323                    last_mapped_label = i;
1324                    if (i == m_Labels.end()) {
1325                        // Unattached cross-section - ignore for now.
1326                        printf("unattached cross-section\n");
1327                        if (current_tube->size() <= 1)
1328                            tubes.resize(tubes.size() - 1);
1329                        current_tube = NULL;
1330                        if (!m_Labels.empty())
1331                            --last_mapped_label;
1332                        break;
1333                    }
1334                    lab = *i;
1335                    labelmap[label] = lab;
1336                }
1337
1338                int date = survey->days1;
1339                if (date != -1) {
1340                    date += (survey->days2 - date) / 2;
1341                    if (date < m_DateMin) m_DateMin = date;
1342                    if (date > datemax) datemax = date;
1343                }
1344
1345                current_tube->push_back(XSect(*lab, date, survey->l, survey->r, survey->u, survey->d));
1346                break;
1347            }
1348
1349            case img_XSECT_END:
1350                // Finish off current_tube.
1351                // If there's only one cross-section in the tube, just
1352                // discard it for now.  FIXME: we should handle this
1353                // when we come to skinning the tubes.
1354                if (current_tube && current_tube->size() <= 1)
1355                    tubes.resize(tubes.size() - 1);
1356                current_tube = NULL;
1357                break;
1358
1359            case img_ERROR_INFO: {
1360                if (survey->E == 0.0) {
1361                    // Currently cavern doesn't spot all articulating traverses
1362                    // so we assume that any traverse with no error isn't part
1363                    // of a loop.  FIXME: fix cavern!
1364                    break;
1365                }
1366                m_HasErrorInformation = true;
1367                list<traverse>::reverse_iterator t;
1368                t = surface_traverses.rbegin();
1369                while (n_surface_traverses) {
1370                    assert(t != surface_traverses.rend());
1371                    t->n_legs = survey->n_legs;
1372                    t->length = survey->length;
1373                    t->E = survey->E;
1374                    t->H = survey->H;
1375                    t->V = survey->V;
1376                    --n_surface_traverses;
1377                    ++t;
1378                }
1379                t = traverses.rbegin();
1380                while (n_traverses) {
1381                    assert(t != traverses.rend());
1382                    t->n_legs = survey->n_legs;
1383                    t->length = survey->length;
1384                    t->E = survey->E;
1385                    t->H = survey->H;
1386                    t->V = survey->V;
1387                    --n_traverses;
1388                    ++t;
1389                }
1390                break;
1391            }
1392
1393            case img_BAD: {
1394                m_Labels.clear();
1395
1396                // FIXME: Do we need to reset all these? - Olly
1397                m_NumFixedPts = 0;
1398                m_NumExportedPts = 0;
1399                m_NumEntrances = 0;
1400                m_HasUndergroundLegs = false;
1401                m_HasSplays = false;
1402                m_HasSurfaceLegs = false;
1403
1404                img_close(survey);
1405
1406                wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str());
1407                wxGetApp().ReportError(m);
1408
1409                return false;
1410            }
1411
1412            default:
1413                break;
1414        }
1415    } while (result != img_STOP);
1416
1417    if (!current_polyline_is_surface && current_traverse) {
1418        //FixLRUD(*current_traverse);
1419    }
1420
1421    // Finish off current_tube.
1422    // If there's only one cross-section in the tube, just
1423    // discard it for now.  FIXME: we should handle this
1424    // when we come to skinning the tubes.
1425    if (current_tube && current_tube->size() <= 1)
1426        tubes.resize(tubes.size() - 1);
1427
1428    separator = survey->separator;
1429    m_Title = wxString(survey->title, wxConvUTF8);
1430    m_DateStamp_numeric = survey->datestamp_numeric;
1431    if (survey->cs) {
1432        m_cs_proj = survey->cs;
1433    } else {
1434        m_cs_proj = wxString();
1435    }
1436    if (strcmp(survey->datestamp, "?") == 0) {
1437        /* TRANSLATORS: used a processed survey with no processing date/time info */
1438        m_DateStamp = wmsg(/*Date and time not available.*/108);
1439    } else if (survey->datestamp[0] == '@') {
1440        const struct tm * tm = localtime(&m_DateStamp_numeric);
1441        char buf[256];
1442        /* TRANSLATORS: This is the date format string used to timestamp .3d
1443         * files internally.  Probably best to keep it the same for all
1444         * translations. */
1445        strftime(buf, 256, msg(/*%a,%Y.%m.%d %H:%M:%S %Z*/107), tm);
1446        m_DateStamp = wxString(buf, wxConvUTF8);
1447    }
1448    if (m_DateStamp.empty()) {
1449        m_DateStamp = wxString(survey->datestamp, wxConvUTF8);
1450    }
1451    img_close(survey);
1452
1453    // Check we've actually loaded some legs or stations!
1454    if (!m_HasUndergroundLegs && !m_HasSurfaceLegs && m_Labels.empty()) {
1455        wxString m = wxString::Format(wmsg(/*No survey data in 3d file “%s”*/202), file.c_str());
1456        wxGetApp().ReportError(m);
1457        return false;
1458    }
1459
1460    if (traverses.empty() && surface_traverses.empty()) {
1461        // No legs, so get survey extents from stations
1462        list<LabelInfo*>::const_iterator i;
1463        for (i = m_Labels.begin(); i != m_Labels.end(); ++i) {
1464            if ((*i)->GetX() < xmin) xmin = (*i)->GetX();
1465            if ((*i)->GetX() > xmax) xmax = (*i)->GetX();
1466            if ((*i)->GetY() < ymin) ymin = (*i)->GetY();
1467            if ((*i)->GetY() > ymax) ymax = (*i)->GetY();
1468            if ((*i)->GetZ() < zmin) zmin = (*i)->GetZ();
1469            if ((*i)->GetZ() > zmax) zmax = (*i)->GetZ();
1470        }
1471    }
1472
1473    m_Ext.assign(xmax - xmin, ymax - ymin, zmax - zmin);
1474
1475    if (datemax < m_DateMin) m_DateMin = datemax;
1476    m_DateExt = datemax - m_DateMin;
1477
1478    // Centre the dataset around the origin.
1479    CentreDataset(Vector3(xmin, ymin, zmin));
1480
1481    if (depthmax < m_DepthMin) {
1482        m_DepthMin = 0;
1483        m_DepthExt = 0;
1484    } else {
1485        m_DepthExt = depthmax - m_DepthMin;
1486        m_DepthMin -= m_Offsets.GetZ();
1487    }
1488
1489#if 0
1490    printf("time to load = %.3f\n", (double)timer.Time());
1491#endif
1492
1493    // Update window title.
1494    SetTitle(m_Title + " - "APP_NAME);
1495
1496    return true;
1497}
1498
1499#if 0
1500// Run along a newly read in traverse and make up plausible LRUD where
1501// it is missing.
1502void
1503MainFrm::FixLRUD(traverse & centreline)
1504{
1505    assert(centreline.size() > 1);
1506
1507    Double last_size = 0;
1508    vector<PointInfo>::iterator i = centreline.begin();
1509    while (i != centreline.end()) {
1510        // Get the coordinates of this vertex.
1511        Point & pt_v = *i++;
1512        Double size;
1513
1514        if (i != centreline.end()) {
1515            Double h = sqrd(i->GetX() - pt_v.GetX()) +
1516                       sqrd(i->GetY() - pt_v.GetY());
1517            Double v = sqrd(i->GetZ() - pt_v.GetZ());
1518            if (h + v > 30.0 * 30.0) {
1519                Double scale = 30.0 / sqrt(h + v);
1520                h *= scale;
1521                v *= scale;
1522            }
1523            size = sqrt(h + v / 9);
1524            size /= 4;
1525            if (i == centreline.begin() + 1) {
1526                // First segment.
1527                last_size = size;
1528            } else {
1529                // Intermediate segment.
1530                swap(size, last_size);
1531                size += last_size;
1532                size /= 2;
1533            }
1534        } else {
1535            // Last segment.
1536            size = last_size;
1537        }
1538
1539        Double & l = pt_v.l;
1540        Double & r = pt_v.r;
1541        Double & u = pt_v.u;
1542        Double & d = pt_v.d;
1543
1544        if (l == 0 && r == 0 && u == 0 && d == 0) {
1545            l = r = u = d = -size;
1546        } else {
1547            if (l < 0 && r < 0) {
1548                l = r = -size;
1549            } else if (l < 0) {
1550                l = -(2 * size - r);
1551                if (l >= 0) l = -0.01;
1552            } else if (r < 0) {
1553                r = -(2 * size - l);
1554                if (r >= 0) r = -0.01;
1555            }
1556            if (u < 0 && d < 0) {
1557                u = d = -size;
1558            } else if (u < 0) {
1559                u = -(2 * size - d);
1560                if (u >= 0) u = -0.01;
1561            } else if (d < 0) {
1562                d = -(2 * size - u);
1563                if (d >= 0) d = -0.01;
1564            }
1565        }
1566    }
1567}
1568#endif
1569
1570void MainFrm::FillTree()
1571{
1572    // Create the root of the tree.
1573    wxTreeItemId treeroot = m_Tree->AddRoot(wxFileNameFromPath(m_File));
1574
1575    // Fill the tree of stations and prefixes.
1576    stack<wxTreeItemId> previous_ids;
1577    wxString current_prefix;
1578    wxTreeItemId current_id = treeroot;
1579
1580    list<LabelInfo*>::iterator pos = m_Labels.begin();
1581    while (pos != m_Labels.end()) {
1582        LabelInfo* label = *pos++;
1583
1584        if (label->IsAnon()) continue;
1585
1586        // Determine the current prefix.
1587        wxString prefix = label->GetText().BeforeLast(separator);
1588
1589        // Determine if we're still on the same prefix.
1590        if (prefix == current_prefix) {
1591            // no need to fiddle with branches...
1592        }
1593        // If not, then see if we've descended to a new prefix.
1594        else if (prefix.length() > current_prefix.length() &&
1595                 prefix.StartsWith(current_prefix) &&
1596                 (prefix[current_prefix.length()] == separator ||
1597                  current_prefix.empty())) {
1598            // We have, so start as many new branches as required.
1599            int current_prefix_length = current_prefix.length();
1600            current_prefix = prefix;
1601            size_t next_dot = current_prefix_length;
1602            if (!next_dot) --next_dot;
1603            do {
1604                size_t prev_dot = next_dot + 1;
1605
1606                // Extract the next bit of prefix.
1607                next_dot = prefix.find(separator, prev_dot + 1);
1608
1609                wxString bit = prefix.substr(prev_dot, next_dot - prev_dot);
1610                assert(!bit.empty());
1611
1612                // Add the current tree ID to the stack.
1613                previous_ids.push(current_id);
1614
1615                // Append the new item to the tree and set this as the current branch.
1616                current_id = m_Tree->AppendItem(current_id, bit);
1617                m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot)));
1618            } while (next_dot != wxString::npos);
1619        }
1620        // Otherwise, we must have moved up, and possibly then down again.
1621        else {
1622            size_t count = 0;
1623            bool ascent_only = (prefix.length() < current_prefix.length() &&
1624                                current_prefix.StartsWith(prefix) &&
1625                                (current_prefix[prefix.length()] == separator ||
1626                                 prefix.empty()));
1627            if (!ascent_only) {
1628                // Find out how much of the current prefix and the new prefix
1629                // are the same.
1630                // Note that we require a match of a whole number of parts
1631                // between dots!
1632                size_t n = min(prefix.length(), current_prefix.length());
1633                size_t i;
1634                for (i = 0; i < n && prefix[i] == current_prefix[i]; ++i) {
1635                    if (prefix[i] == separator) count = i + 1;
1636                }
1637            } else {
1638                count = prefix.length() + 1;
1639            }
1640
1641            // Extract the part of the current prefix after the bit (if any)
1642            // which has matched.
1643            // This gives the prefixes to ascend over.
1644            wxString prefixes_ascended = current_prefix.substr(count);
1645
1646            // Count the number of prefixes to ascend over.
1647            int num_prefixes = prefixes_ascended.Freq(separator);
1648
1649            // Reverse up over these prefixes.
1650            for (int i = 1; i <= num_prefixes; i++) {
1651                previous_ids.pop();
1652            }
1653            current_id = previous_ids.top();
1654            previous_ids.pop();
1655
1656            if (!ascent_only) {
1657                // Add branches for this new part.
1658                size_t next_dot = count - 1;
1659                do {
1660                    size_t prev_dot = next_dot + 1;
1661
1662                    // Extract the next bit of prefix.
1663                    next_dot = prefix.find(separator, prev_dot + 1);
1664
1665                    wxString bit = prefix.substr(prev_dot, next_dot - prev_dot);
1666                    assert(!bit.empty());
1667
1668                    // Add the current tree ID to the stack.
1669                    previous_ids.push(current_id);
1670
1671                    // Append the new item to the tree and set this as the current branch.
1672                    current_id = m_Tree->AppendItem(current_id, bit);
1673                    m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot)));
1674                } while (next_dot != wxString::npos);
1675            }
1676
1677            current_prefix = prefix;
1678        }
1679
1680        // Now add the leaf.
1681        wxString bit = label->GetText().AfterLast(separator);
1682        assert(!bit.empty());
1683        wxTreeItemId id = m_Tree->AppendItem(current_id, bit);
1684        m_Tree->SetItemData(id, new TreeData(label));
1685        label->tree_id = id;
1686        // Set the colour for an item in the survey tree.
1687        if (label->IsEntrance()) {
1688            // Entrances are green (like entrance blobs).
1689            m_Tree->SetItemTextColour(id, wxColour(0, 255, 40));
1690        } else if (label->IsSurface()) {
1691            // Surface stations are dark green.
1692            m_Tree->SetItemTextColour(id, wxColour(49, 158, 79));
1693        }
1694    }
1695
1696    m_Tree->Expand(treeroot);
1697    m_Tree->SetEnabled();
1698}
1699
1700void MainFrm::CentreDataset(const Vector3 & vmin)
1701{
1702    // Centre the dataset around the origin.
1703
1704    m_Offsets = vmin + (m_Ext * 0.5);
1705
1706    list<traverse>::iterator t = traverses.begin();
1707    while (t != traverses.end()) {
1708        assert(t->size() > 1);
1709        vector<PointInfo>::iterator pos = t->begin();
1710        while (pos != t->end()) {
1711            Point & point = *pos++;
1712            point -= m_Offsets;
1713        }
1714        ++t;
1715    }
1716
1717    t = surface_traverses.begin();
1718    while (t != surface_traverses.end()) {
1719        assert(t->size() > 1);
1720        vector<PointInfo>::iterator pos = t->begin();
1721        while (pos != t->end()) {
1722            Point & point = *pos++;
1723            point -= m_Offsets;
1724        }
1725        ++t;
1726    }
1727
1728    list<vector<XSect> >::iterator i = tubes.begin();
1729    while (i != tubes.end()) {
1730        assert(i->size() > 1);
1731        vector<XSect>::iterator pos = i->begin();
1732        while (pos != i->end()) {
1733            Point & point = *pos++;
1734            point -= m_Offsets;
1735        }
1736        ++i;
1737    }
1738
1739    list<LabelInfo*>::iterator lpos = m_Labels.begin();
1740    while (lpos != m_Labels.end()) {
1741        Point & point = **lpos++;
1742        point -= m_Offsets;
1743    }
1744}
1745
1746void MainFrm::OnMRUFile(wxCommandEvent& event)
1747{
1748    wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1));
1749    if (!f.empty()) OpenFile(f);
1750}
1751
1752void MainFrm::AddToFileHistory(const wxString & file)
1753{
1754    if (wxIsAbsolutePath(file)) {
1755        m_history.AddFileToHistory(file);
1756    } else {
1757        wxString abs = wxGetCwd();
1758        abs += wxCONFIG_PATH_SEPARATOR;
1759        abs += file;
1760        m_history.AddFileToHistory(abs);
1761    }
1762    wxConfigBase *b = wxConfigBase::Get();
1763    m_history.Save(*b);
1764    b->Flush();
1765}
1766
1767void MainFrm::OpenFile(const wxString& file, const wxString& survey)
1768{
1769    wxBusyCursor hourglass;
1770
1771    // Check if this is an unprocessed survey data file.
1772    if (file.length() > 4 && file[file.length() - 4] == '.') {
1773        wxString ext(file, file.length() - 3, 3);
1774        ext.MakeLower();
1775        if (ext == wxT("svx") || ext == wxT("dat") || ext == wxT("mak")) {
1776            CavernLogWindow * log = new CavernLogWindow(this, m_Splitter);
1777            wxWindow * win = m_Splitter->GetWindow1();
1778            m_Splitter->ReplaceWindow(win, log);
1779            if (m_Splitter->GetWindow2() == NULL) {
1780                if (win != m_Gfx) win->Destroy();
1781            } else {
1782                if (m_Splitter->IsSplit()) m_Splitter->Unsplit();
1783            }
1784
1785            int result = log->process(file);
1786            if (result < 0) {
1787                // Error running cavern or processing data.
1788                return;
1789            }
1790
1791            AddToFileHistory(file);
1792            wxString file3d(file, 0, file.length() - 3);
1793            file3d.append(wxT("3d"));
1794            if (!LoadData(file3d, survey))
1795                return;
1796            if (result == 0) {
1797                InitialiseAfterLoad(file);
1798            }
1799            return;
1800        }
1801    }
1802
1803    if (!LoadData(file, survey))
1804        return;
1805    AddToFileHistory(file);
1806    InitialiseAfterLoad(file);
1807}
1808
1809void MainFrm::InitialiseAfterLoad(const wxString & file)
1810{
1811    if (m_SashPosition < 0) {
1812        // Calculate sane default width for side panel.
1813        int x;
1814        int y;
1815        GetClientSize(&x, &y);
1816        if (x < 600)
1817            x /= 3;
1818        else if (x < 1000)
1819            x = 200;
1820        else
1821            x /= 5;
1822        m_SashPosition = x;
1823    }
1824
1825    // Do this before we potentially delete the log window which may own the
1826    // wxString which parameter file refers to!
1827    bool same_file = (file == m_File);
1828    if (!same_file)
1829        m_File = file;
1830
1831    // Sort the labels ready for filling the tree.
1832    m_Labels.sort(LabelCmp(separator));
1833
1834    // Fill the tree of stations and prefixes.
1835    FillTree();
1836
1837    // Sort labels so that entrances are displayed in preference,
1838    // then fixed points, then exported points, then other points.
1839    //
1840    // Also sort by leaf name so that we'll tend to choose labels
1841    // from different surveys, rather than labels from surveys which
1842    // are earlier in the list.
1843    m_Labels.sort(LabelPlotCmp(separator));
1844
1845    if (!m_FindBox->GetValue().empty()) {
1846        // Highlight any stations matching the current search.
1847        DoFind();
1848    }
1849
1850    wxWindow * win = NULL;
1851    if (m_Splitter->GetWindow2() == NULL) {
1852        win = m_Splitter->GetWindow1();
1853        if (win == m_Gfx) win = NULL;
1854    }
1855
1856    if (!IsFullScreen()) {
1857        m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1858    } else {
1859        was_showing_sidepanel_before_fullscreen = true;
1860    }
1861
1862    m_Gfx->Initialise(same_file);
1863    if (!IsFullScreen()) {
1864        m_Notebook->Show(true);
1865    }
1866
1867    m_Gfx->Show(true);
1868    m_Gfx->SetFocus();
1869
1870    if (win) win->Destroy();
1871}
1872
1873//
1874//  UI event handlers
1875//
1876
1877// For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx".
1878#ifdef _WIN32
1879# define CASE(X)
1880#else
1881# define CASE(X) ";"X
1882#endif
1883
1884void MainFrm::OnOpen(wxCommandEvent&)
1885{
1886    AvenAllowOnTop ontop(this);
1887#ifdef __WXMOTIF__
1888    wxString filetypes = wxT("*.3d");
1889#else
1890    wxString filetypes;
1891    filetypes.Printf(wxT("%s|*.3d;*.svx;*.plt;*.plf;*.dat;*.mak;*.adj;*.sht;*.una;*.xyz"
1892                     CASE("*.3D;*.SVX;*.PLT;*.PLF;*.DAT;*.MAK;*.ADJ;*.SHT;*.UNA;*.XYZ")
1893                     "|%s|*.3d"CASE("*.3D")
1894                     "|%s|*.svx"CASE("*.SVX")
1895                     "|%s|*.plt;*.plf"CASE("*.PLT;*.PLF")
1896                     "|%s|*.dat;*.mak"CASE("*.DAT;*.MAK")
1897                     "|%s|*.adj;*.sht;*.una;*.xyz"CASE("*.ADJ;*.SHT;*.UNA;*.XYZ")
1898                     "|%s|%s"),
1899                     /* TRANSLATORS: Here "survey" is a "cave map" rather than
1900                      * list of questions - it should be translated to the
1901                      * terminology that cavers using the language would use.
1902                      */
1903                     wmsg(/*All survey files*/229).c_str(),
1904                     wmsg(/*Survex 3d files*/207).c_str(),
1905                     wmsg(/*Survex svx files*/329).c_str(),
1906                     /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1907                      * surveying package, so probably shouldn’t be translated
1908                      */
1909                     wmsg(/*Compass PLT files*/324).c_str(),
1910                     /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1911                      * surveying package, so probably shouldn’t be translated
1912                      */
1913                     wmsg(/*Compass DAT and MAK files*/330).c_str(),
1914                     /* TRANSLATORS: "CMAP" is Bob Thrun’s cave surveying
1915                      * package, so don’t translate it. */
1916                     wmsg(/*CMAP XYZ files*/325).c_str(),
1917                     wmsg(/*All files*/208).c_str(),
1918                     wxFileSelectorDefaultWildcardStr);
1919#endif
1920    /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
1921     * - it should be translated to the terminology that cavers using the
1922     * language would use.
1923     *
1924     * File->Open dialog: */
1925    wxFileDialog dlg(this, wmsg(/*Select a survey file to view*/206),
1926                     wxString(), wxString(),
1927                     filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1928    if (dlg.ShowModal() == wxID_OK) {
1929        OpenFile(dlg.GetPath());
1930    }
1931}
1932
1933void MainFrm::OnScreenshot(wxCommandEvent&)
1934{
1935    AvenAllowOnTop ontop(this);
1936    wxString baseleaf;
1937    wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
1938    /* TRANSLATORS: title of the save screenshot dialog */
1939    wxFileDialog dlg(this, wmsg(/*Save Screenshot*/321), wxString(),
1940                     baseleaf + wxT(".png"),
1941                     wxT("*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1942    if (dlg.ShowModal() == wxID_OK) {
1943        static bool png_handled = false;
1944        if (!png_handled) {
1945#if 0 // FIXME : enable this to allow other export formats...
1946            ::wxInitAllImageHandlers();
1947#else
1948            wxImage::AddHandler(new wxPNGHandler);
1949#endif
1950            png_handled = true;
1951        }
1952        if (!m_Gfx->SaveScreenshot(dlg.GetPath(), wxBITMAP_TYPE_PNG)) {
1953            wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), dlg.GetPath().c_str()));
1954        }
1955    }
1956}
1957
1958void MainFrm::OnScreenshotUpdate(wxUpdateUIEvent& event)
1959{
1960    event.Enable(!m_File.empty());
1961}
1962
1963void MainFrm::OnFilePreferences(wxCommandEvent&)
1964{
1965#ifdef PREFDLG
1966    m_PrefsDlg = new PrefsDlg(m_Gfx, this);
1967    m_PrefsDlg->Show(true);
1968#endif
1969}
1970
1971void MainFrm::OnPrint(wxCommandEvent&)
1972{
1973    m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj);
1974}
1975
1976void MainFrm::PrintAndExit()
1977{
1978    m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj, true);
1979}
1980
1981void MainFrm::OnPageSetup(wxCommandEvent&)
1982{
1983    wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData());
1984    if (dlg.ShowModal() == wxID_OK) {
1985        wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData());
1986    }
1987}
1988
1989void MainFrm::OnExport(wxCommandEvent&)
1990{
1991    m_Gfx->OnExport(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj);
1992}
1993
1994void MainFrm::OnQuit(wxCommandEvent&)
1995{
1996    if (m_PresList->Modified()) {
1997        AvenAllowOnTop ontop(this);
1998        // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1999        /* TRANSLATORS: and the question in that box */
2000        if (wxMessageBox(wmsg(/*The current presentation has been modified.  Abandon unsaved changes?*/327),
2001                         /* TRANSLATORS: title of message box */
2002                         wmsg(/*Modified Presentation*/326),
2003                         wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2004            return;
2005        }
2006    }
2007    wxConfigBase *b = wxConfigBase::Get();
2008    if (IsFullScreen()) {
2009        b->Write(wxT("width"), -2);
2010        b->DeleteEntry(wxT("height"));
2011    } else if (IsMaximized()) {
2012        b->Write(wxT("width"), -1);
2013        b->DeleteEntry(wxT("height"));
2014    } else {
2015        int width, height;
2016        GetSize(&width, &height);
2017        b->Write(wxT("width"), width);
2018        b->Write(wxT("height"), height);
2019    }
2020    b->Flush();
2021    exit(0);
2022}
2023
2024void MainFrm::OnClose(wxCloseEvent&)
2025{
2026    wxCommandEvent dummy;
2027    OnQuit(dummy);
2028}
2029
2030void MainFrm::OnAbout(wxCommandEvent&)
2031{
2032    AvenAllowOnTop ontop(this);
2033    AboutDlg dlg(this, icon_path);
2034    dlg.Centre();
2035    dlg.ShowModal();
2036}
2037
2038void MainFrm::UpdateStatusBar()
2039{
2040    if (!here_text.empty()) {
2041        GetStatusBar()->SetStatusText(here_text);
2042        GetStatusBar()->SetStatusText(dist_text, 1);
2043    } else if (!coords_text.empty()) {
2044        GetStatusBar()->SetStatusText(coords_text);
2045        GetStatusBar()->SetStatusText(distfree_text, 1);
2046    } else {
2047        GetStatusBar()->SetStatusText(wxString());
2048        GetStatusBar()->SetStatusText(wxString(), 1);
2049    }
2050}
2051
2052void MainFrm::ClearTreeSelection()
2053{
2054    m_Tree->UnselectAll();
2055    m_Gfx->SetThere();
2056    ShowInfo();
2057}
2058
2059void MainFrm::ClearCoords()
2060{
2061    if (!coords_text.empty()) {
2062        coords_text = wxString();
2063        UpdateStatusBar();
2064    }
2065}
2066
2067void MainFrm::SetCoords(const Vector3 &v)
2068{
2069    Double x = v.GetX();
2070    Double y = v.GetY();
2071    Double z = v.GetZ();
2072    int units;
2073    if (m_Gfx->GetMetric()) {
2074        units = /*m*/424;
2075    } else {
2076        x /= METRES_PER_FOOT;
2077        y /= METRES_PER_FOOT;
2078        z /= METRES_PER_FOOT;
2079        units = /*ft*/428;
2080    }
2081    /* TRANSLATORS: show coordinates (N = North or Northing, E = East or
2082     * Easting) */
2083    coords_text.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2084    coords_text += wxString::Format(wxT(", %s %.2f%s"),
2085                                    wmsg(/*Altitude*/335).c_str(),
2086                                    z, wmsg(units).c_str());
2087    distfree_text = wxString();
2088    UpdateStatusBar();
2089}
2090
2091const LabelInfo * MainFrm::GetTreeSelection() const {
2092    wxTreeItemData* sel_wx;
2093    if (!m_Tree->GetSelectionData(&sel_wx)) return NULL;
2094
2095    const TreeData* data = static_cast<const TreeData*>(sel_wx);
2096    if (!data->IsStation()) return NULL;
2097
2098    return data->GetLabel();
2099}
2100
2101void MainFrm::SetCoords(Double x, Double y, const LabelInfo * there)
2102{
2103    wxString & s = coords_text;
2104    if (m_Gfx->GetMetric()) {
2105        s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2106    } else {
2107        s.Printf(wmsg(/*%.2f E, %.2f N*/338),
2108                 x / METRES_PER_FOOT, y / METRES_PER_FOOT);
2109    }
2110
2111    wxString & t = distfree_text;
2112    t = wxString();
2113    if (m_Gfx->ShowingMeasuringLine() && there) {
2114        Vector3 delta(x - m_Offsets.GetX() - there->GetX(),
2115                      y - m_Offsets.GetY() - there->GetY(), 0);
2116        Double dh = sqrt(delta.GetX()*delta.GetX() + delta.GetY()*delta.GetY());
2117        Double brg = deg(atan2(delta.GetX(), delta.GetY()));
2118        if (brg < 0) brg += 360;
2119
2120        wxString from_str;
2121        /* TRANSLATORS: Used in Aven:
2122         * From <stationname>
2123         * H: 123.45m V: 234.56m
2124         * Dist: 456.78m  Brg: 200 */
2125        from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon());
2126        int brg_unit;
2127        if (m_Gfx->GetDegrees()) {
2128            brg_unit = /*°*/344;
2129        } else {
2130            brg *= 400.0 / 360.0;
2131            /* TRANSLATORS: alternative angle units (400 grad = 360 degrees =
2132             * full circle).  Try to make this as short as sensibly possible.
2133             *
2134             * E.g. in Italian and Spanish we use "g.cent." rather than
2135             * "gradi quattrocentesimali"/"grados centesimales" */
2136            brg_unit = /*grad*/345;
2137        }
2138
2139        int units;
2140        if (m_Gfx->GetMetric()) {
2141            units = /*m*/424;
2142        } else {
2143            dh /= METRES_PER_FOOT;
2144            units = /*ft*/428;
2145        }
2146        /* TRANSLATORS: "H" is short for "Horizontal", "Brg" for "Bearing" (as
2147         * in Compass bearing) */
2148        t.Printf(wmsg(/*%s: H %.2f%s, Brg %03d%s*/374),
2149                 from_str.c_str(), dh, wmsg(units).c_str(),
2150                 int(brg), wmsg(brg_unit).c_str());
2151    }
2152
2153    UpdateStatusBar();
2154}
2155
2156void MainFrm::SetAltitude(Double z, const LabelInfo * there)
2157{
2158    double alt = z;
2159    int units;
2160    if (m_Gfx->GetMetric()) {
2161        units = /*m*/424;
2162    } else {
2163        alt /= METRES_PER_FOOT;
2164        units = /*ft*/428;
2165    }
2166    coords_text.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
2167                       alt, wmsg(units).c_str());
2168
2169    wxString & t = distfree_text;
2170    t = wxString();
2171    if (m_Gfx->ShowingMeasuringLine() && there) {
2172        Double dz = z - m_Offsets.GetZ() - there->GetZ();
2173
2174        wxString from_str;
2175        from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon());
2176
2177        if (!m_Gfx->GetMetric()) {
2178            dz /= METRES_PER_FOOT;
2179        }
2180        // TRANSLATORS: "V" is short for "Vertical"
2181        t.Printf(wmsg(/*%s: V %.2f%s*/375), from_str.c_str(),
2182                 dz, wmsg(units).c_str());
2183    }
2184
2185    UpdateStatusBar();
2186}
2187
2188void MainFrm::ShowInfo(const LabelInfo *here, const LabelInfo *there)
2189{
2190    assert(m_Gfx);
2191
2192    if (!here) {
2193        m_Gfx->SetHere();
2194        m_Tree->SetHere(wxTreeItemId());
2195        // Don't clear "There" mark here.
2196        if (here_text.empty() && dist_text.empty()) return;
2197        here_text = wxString();
2198        dist_text = wxString();
2199        UpdateStatusBar();
2200        return;
2201    }
2202
2203    Vector3 v = *here + m_Offsets;
2204    wxString & s = here_text;
2205    Double x = v.GetX();
2206    Double y = v.GetY();
2207    Double z = v.GetZ();
2208    int units;
2209    if (m_Gfx->GetMetric()) {
2210        units = /*m*/424;
2211    } else {
2212        x /= METRES_PER_FOOT;
2213        y /= METRES_PER_FOOT;
2214        z /= METRES_PER_FOOT;
2215        units = /*ft*/428;
2216    }
2217    s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2218    s += wxString::Format(wxT(", %s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
2219                          z, wmsg(units).c_str());
2220    s += wxT(": ");
2221    s += here->name_or_anon();
2222    m_Gfx->SetHere(here);
2223    m_Tree->SetHere(here->tree_id);
2224
2225    if (m_Gfx->ShowingMeasuringLine() && there) {
2226        Vector3 delta = *here - *there;
2227
2228        Double d_horiz = sqrt(delta.GetX()*delta.GetX() +
2229                              delta.GetY()*delta.GetY());
2230        Double dr = delta.magnitude();
2231        Double dz = delta.GetZ();
2232
2233        Double brg = deg(atan2(delta.GetX(), delta.GetY()));
2234        if (brg < 0) brg += 360;
2235
2236        wxString from_str;
2237        from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon());
2238
2239        wxString hv_str;
2240        if (m_Gfx->GetMetric()) {
2241            units = /*m*/424;
2242        } else {
2243            d_horiz /= METRES_PER_FOOT;
2244            dr /= METRES_PER_FOOT;
2245            dz /= METRES_PER_FOOT;
2246            units = /*ft*/428;
2247        }
2248        wxString len_unit = wmsg(units);
2249        /* TRANSLATORS: "H" is short for "Horizontal", "V" for "Vertical" */
2250        hv_str.Printf(wmsg(/*H %.2f%s, V %.2f%s*/340),
2251                      d_horiz, len_unit.c_str(), dz, len_unit.c_str());
2252        int brg_unit;
2253        if (m_Gfx->GetDegrees()) {
2254            brg_unit = /*°*/344;
2255        } else {
2256            brg *= 400.0 / 360.0;
2257            brg_unit = /*grad*/345;
2258        }
2259        wxString & d = dist_text;
2260        /* TRANSLATORS: "Dist" is short for "Distance", "Brg" for "Bearing" (as
2261         * in Compass bearing) */
2262        d.Printf(wmsg(/*%s: %s, Dist %.2f%s, Brg %03d%s*/341),
2263                 from_str.c_str(), hv_str.c_str(),
2264                 dr, len_unit.c_str(), int(brg), wmsg(brg_unit).c_str());
2265    } else {
2266        dist_text = wxString();
2267        m_Gfx->SetThere();
2268    }
2269    UpdateStatusBar();
2270}
2271
2272void MainFrm::DisplayTreeInfo(const wxTreeItemData* item)
2273{
2274    const TreeData* data = static_cast<const TreeData*>(item);
2275    if (data && data->IsStation()) {
2276        m_Gfx->SetHereFromTree(data->GetLabel());
2277    } else {
2278        ShowInfo();
2279    }
2280}
2281
2282void MainFrm::TreeItemSelected(const wxTreeItemData* item, bool zoom)
2283{
2284    const TreeData* data = static_cast<const TreeData*>(item);
2285    if (data && data->IsStation()) {
2286        const LabelInfo* label = data->GetLabel();
2287        if (zoom) m_Gfx->CentreOn(*label);
2288        m_Gfx->SetThere(label);
2289        dist_text = wxString();
2290        // FIXME: Need to update dist_text (From ... etc)
2291        // But we don't currently know where "here" is at this point in the
2292        // code!
2293    } else {
2294        dist_text = wxString();
2295        m_Gfx->SetThere();
2296    }
2297    if (!data) {
2298        // Must be the root.
2299        m_FindBox->SetValue(wxString());
2300        if (zoom) {
2301            wxCommandEvent dummy;
2302            OnDefaults(dummy);
2303        }
2304    } else if (data && !data->IsStation()) {
2305        m_FindBox->SetValue(data->GetSurvey() + wxT(".*"));
2306        if (zoom) {
2307            wxCommandEvent dummy;
2308            OnGotoFound(dummy);
2309        }
2310    }
2311    UpdateStatusBar();
2312}
2313
2314void MainFrm::OnPresNew(wxCommandEvent&)
2315{
2316    if (m_PresList->Modified()) {
2317        AvenAllowOnTop ontop(this);
2318        // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
2319        if (wxMessageBox(wmsg(/*The current presentation has been modified.  Abandon unsaved changes?*/327),
2320                         wmsg(/*Modified Presentation*/326),
2321                         wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2322            return;
2323        }
2324    }
2325    m_PresList->New(m_File);
2326    if (!ShowingSidePanel()) ToggleSidePanel();
2327    // Select the presentation page in the notebook.
2328    m_Notebook->SetSelection(1);
2329}
2330
2331void MainFrm::OnPresOpen(wxCommandEvent&)
2332{
2333    AvenAllowOnTop ontop(this);
2334    if (m_PresList->Modified()) {
2335        // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
2336        if (wxMessageBox(wmsg(/*The current presentation has been modified.  Abandon unsaved changes?*/327),
2337                         wmsg(/*Modified Presentation*/326),
2338                         wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2339            return;
2340        }
2341    }
2342#ifdef __WXMOTIF__
2343    wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
2344                     wxT("*.fly"), wxFD_OPEN);
2345#else
2346    wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
2347                     wxString::Format(wxT("%s|*.fly|%s|%s"),
2348                               wmsg(/*Aven presentations*/320).c_str(),
2349                               wmsg(/*All files*/208).c_str(),
2350                               wxFileSelectorDefaultWildcardStr),
2351                     wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2352#endif
2353    if (dlg.ShowModal() == wxID_OK) {
2354        if (!m_PresList->Load(dlg.GetPath())) {
2355            return;
2356        }
2357        // FIXME : keep a history of loaded/saved presentations, like we do for
2358        // loaded surveys...
2359        // Select the presentation page in the notebook.
2360        m_Notebook->SetSelection(1);
2361    }
2362}
2363
2364void MainFrm::OnPresSave(wxCommandEvent&)
2365{
2366    m_PresList->Save(true);
2367}
2368
2369void MainFrm::OnPresSaveAs(wxCommandEvent&)
2370{
2371    m_PresList->Save(false);
2372}
2373
2374void MainFrm::OnPresMark(wxCommandEvent&)
2375{
2376    m_PresList->AddMark();
2377}
2378
2379void MainFrm::OnPresFRewind(wxCommandEvent&)
2380{
2381    m_Gfx->PlayPres(-100);
2382}
2383
2384void MainFrm::OnPresRewind(wxCommandEvent&)
2385{
2386    m_Gfx->PlayPres(-10);
2387}
2388
2389void MainFrm::OnPresReverse(wxCommandEvent&)
2390{
2391    m_Gfx->PlayPres(-1);
2392}
2393
2394void MainFrm::OnPresPlay(wxCommandEvent&)
2395{
2396    m_Gfx->PlayPres(1);
2397}
2398
2399void MainFrm::OnPresFF(wxCommandEvent&)
2400{
2401    m_Gfx->PlayPres(10);
2402}
2403
2404void MainFrm::OnPresFFF(wxCommandEvent&)
2405{
2406    m_Gfx->PlayPres(100);
2407}
2408
2409void MainFrm::OnPresPause(wxCommandEvent&)
2410{
2411    m_Gfx->PlayPres(0);
2412}
2413
2414void MainFrm::OnPresStop(wxCommandEvent&)
2415{
2416    m_Gfx->PlayPres(0, false);
2417}
2418
2419void MainFrm::OnPresExportMovie(wxCommandEvent&)
2420{
2421    AvenAllowOnTop ontop(this);
2422    // FIXME : Taking the leaf of the currently loaded presentation as the
2423    // default might make more sense?
2424    wxString baseleaf;
2425    wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
2426    wxFileDialog dlg(this, wmsg(/*Export Movie*/331), wxString(),
2427                     baseleaf + wxT(".mpg"),
2428                     wxT("MPEG|*.mpg|AVI|*.avi|QuickTime|*.mov|WMV|*.wmv;*.asf"),
2429                     wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2430    if (dlg.ShowModal() == wxID_OK) {
2431        // Error is reported by GfxCore.
2432        (void)m_Gfx->ExportMovie(dlg.GetPath());
2433    }
2434}
2435
2436PresentationMark MainFrm::GetPresMark(int which)
2437{
2438    return m_PresList->GetPresMark(which);
2439}
2440
2441//void MainFrm::OnFileOpenTerrainUpdate(wxUpdateUIEvent& event)
2442//{
2443//    event.Enable(!m_File.empty());
2444//}
2445
2446void MainFrm::OnPresNewUpdate(wxUpdateUIEvent& event)
2447{
2448    event.Enable(!m_File.empty());
2449}
2450
2451void MainFrm::OnPresOpenUpdate(wxUpdateUIEvent& event)
2452{
2453    event.Enable(!m_File.empty());
2454}
2455
2456void MainFrm::OnPresSaveUpdate(wxUpdateUIEvent& event)
2457{
2458    event.Enable(!m_PresList->Empty());
2459}
2460
2461void MainFrm::OnPresSaveAsUpdate(wxUpdateUIEvent& event)
2462{
2463    event.Enable(!m_PresList->Empty());
2464}
2465
2466void MainFrm::OnPresMarkUpdate(wxUpdateUIEvent& event)
2467{
2468    event.Enable(!m_File.empty());
2469}
2470
2471void MainFrm::OnPresFRewindUpdate(wxUpdateUIEvent& event)
2472{
2473    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2474    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() < -10);
2475}
2476
2477void MainFrm::OnPresRewindUpdate(wxUpdateUIEvent& event)
2478{
2479    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2480    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -10);
2481}
2482
2483void MainFrm::OnPresReverseUpdate(wxUpdateUIEvent& event)
2484{
2485    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2486    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -1);
2487}
2488
2489void MainFrm::OnPresPlayUpdate(wxUpdateUIEvent& event)
2490{
2491    event.Enable(!m_PresList->Empty());
2492    event.Check(m_Gfx && m_Gfx->GetPresentationMode() &&
2493                m_Gfx->GetPresentationSpeed() == 1);
2494}
2495
2496void MainFrm::OnPresFFUpdate(wxUpdateUIEvent& event)
2497{
2498    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2499    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 10);
2500}
2501
2502void MainFrm::OnPresFFFUpdate(wxUpdateUIEvent& event)
2503{
2504    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2505    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() > 10);
2506}
2507
2508void MainFrm::OnPresPauseUpdate(wxUpdateUIEvent& event)
2509{
2510    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2511    event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 0);
2512}
2513
2514void MainFrm::OnPresStopUpdate(wxUpdateUIEvent& event)
2515{
2516    event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2517}
2518
2519void MainFrm::OnPresExportMovieUpdate(wxUpdateUIEvent& event)
2520{
2521    event.Enable(!m_PresList->Empty());
2522}
2523
2524void MainFrm::OnFind(wxCommandEvent&)
2525{
2526    pending_find = true;
2527}
2528
2529void MainFrm::OnIdle(wxIdleEvent&)
2530{
2531    if (pending_find) {
2532        DoFind();
2533    }
2534}
2535
2536void MainFrm::DoFind()
2537{
2538    pending_find = false;
2539    wxBusyCursor hourglass;
2540    // Find stations specified by a string or regular expression pattern.
2541
2542    wxString pattern = m_FindBox->GetValue();
2543    if (pattern.empty()) {
2544        // Hide any search result highlights.
2545        list<LabelInfo*>::iterator pos = m_Labels.begin();
2546        while (pos != m_Labels.end()) {
2547            LabelInfo* label = *pos++;
2548            label->clear_flags(LFLAG_HIGHLIGHTED);
2549        }
2550        m_NumHighlighted = 0;
2551    } else {
2552        int re_flags = wxRE_NOSUB;
2553
2554        if (true /* case insensitive */) {
2555            re_flags |= wxRE_ICASE;
2556        }
2557
2558        bool substring = true;
2559        if (false /*m_RegexpCheckBox->GetValue()*/) {
2560            re_flags |= wxRE_EXTENDED;
2561        } else if (true /* simple glob-style */) {
2562            wxString pat;
2563            for (size_t i = 0; i < pattern.size(); i++) {
2564               wxChar ch = pattern[i];
2565               // ^ only special at start; $ at end.  But this is simpler...
2566               switch (ch) {
2567                case '^': case '$': case '.': case '[': case '\\':
2568                  pat += wxT('\\');
2569                  pat += ch;
2570                  break;
2571                case '*':
2572                  pat += wxT(".*");
2573                  substring = false;
2574                  break;
2575                case '?':
2576                  pat += wxT('.');
2577                  substring = false;
2578                  break;
2579                default:
2580                  pat += ch;
2581               }
2582            }
2583            pattern = pat;
2584            re_flags |= wxRE_BASIC;
2585        } else {
2586            wxString pat;
2587            for (size_t i = 0; i < pattern.size(); i++) {
2588               wxChar ch = pattern[i];
2589               // ^ only special at start; $ at end.  But this is simpler...
2590               switch (ch) {
2591                case '^': case '$': case '*': case '.': case '[': case '\\':
2592                  pat += wxT('\\');
2593               }
2594               pat += ch;
2595            }
2596            pattern = pat;
2597            re_flags |= wxRE_BASIC;
2598        }
2599
2600        if (!substring) {
2601            // FIXME "0u" required to avoid compilation error with g++-3.0
2602            if (pattern.empty() || pattern[0u] != '^') pattern = wxT('^') + pattern;
2603            // FIXME: this fails to cope with "\$" at the end of pattern...
2604            if (pattern[pattern.size() - 1] != '$') pattern += wxT('$');
2605        }
2606
2607        wxRegEx regex;
2608        if (!regex.Compile(pattern, re_flags)) {
2609            wxBell();
2610            return;
2611        }
2612
2613        int found = 0;
2614
2615        list<LabelInfo*>::iterator pos = m_Labels.begin();
2616        while (pos != m_Labels.end()) {
2617            LabelInfo* label = *pos++;
2618
2619            if (regex.Matches(label->GetText())) {
2620                label->set_flags(LFLAG_HIGHLIGHTED);
2621                ++found;
2622            } else {
2623                label->clear_flags(LFLAG_HIGHLIGHTED);
2624            }
2625        }
2626
2627        m_NumHighlighted = found;
2628
2629        // Re-sort so highlighted points get names in preference
2630        if (found) m_Labels.sort(LabelPlotCmp(separator));
2631    }
2632
2633    m_Gfx->UpdateBlobs();
2634    m_Gfx->ForceRefresh();
2635
2636    if (!m_NumHighlighted) {
2637        GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*No matches were found.*/328));
2638    } else {
2639        /* TRANSLATORS: "Hide stations" button tooltip when stations are found
2640         */
2641        GetToolBar()->SetToolShortHelp(button_HIDE, wxString::Format(wmsg(/*Hide %d found stations*/334).c_str(), m_NumHighlighted));
2642    }
2643}
2644
2645void MainFrm::OnGotoFound(wxCommandEvent&)
2646{
2647    if (!m_NumHighlighted) {
2648        wxGetApp().ReportError(wmsg(/*No matches were found.*/328));
2649        return;
2650    }
2651
2652    Double xmin = DBL_MAX;
2653    Double xmax = -DBL_MAX;
2654    Double ymin = DBL_MAX;
2655    Double ymax = -DBL_MAX;
2656    Double zmin = DBL_MAX;
2657    Double zmax = -DBL_MAX;
2658
2659    list<LabelInfo*>::iterator pos = m_Labels.begin();
2660    while (pos != m_Labels.end()) {
2661        LabelInfo* label = *pos++;
2662
2663        if (label->get_flags() & LFLAG_HIGHLIGHTED) {
2664            if (label->GetX() < xmin) xmin = label->GetX();
2665            if (label->GetX() > xmax) xmax = label->GetX();
2666            if (label->GetY() < ymin) ymin = label->GetY();
2667            if (label->GetY() > ymax) ymax = label->GetY();
2668            if (label->GetZ() < zmin) zmin = label->GetZ();
2669            if (label->GetZ() > zmax) zmax = label->GetZ();
2670        }
2671    }
2672
2673    m_Gfx->SetViewTo(xmin, xmax, ymin, ymax, zmin, zmax);
2674    m_Gfx->SetFocus();
2675}
2676
2677void MainFrm::OnHide(wxCommandEvent&)
2678{
2679    m_FindBox->SetValue(wxString());
2680    GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*Hide*/333));
2681}
2682
2683void MainFrm::OnHideUpdate(wxUpdateUIEvent& ui)
2684{
2685    ui.Enable(m_NumHighlighted != 0);
2686}
2687
2688void MainFrm::OnViewSidePanel(wxCommandEvent&)
2689{
2690    ToggleSidePanel();
2691}
2692
2693void MainFrm::ToggleSidePanel()
2694{
2695    // Toggle display of the side panel.
2696
2697    assert(m_Gfx);
2698
2699    if (m_Splitter->IsSplit()) {
2700        m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
2701        m_Splitter->Unsplit(m_Notebook);
2702    } else {
2703        m_Notebook->Show(true);
2704        m_Gfx->Show(true);
2705        m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
2706    }
2707}
2708
2709void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui)
2710{
2711    ui.Enable(!m_File.empty());
2712    ui.Check(ShowingSidePanel());
2713}
2714
2715bool MainFrm::ShowingSidePanel()
2716{
2717    return m_Splitter->IsSplit();
2718}
2719
2720void MainFrm::ViewFullScreen() {
2721#ifdef __WXMAC__
2722    // On OS X, wxWidgets doesn't currently hide the toolbar or statusbar in
2723    // full screen mode (last checked with 3.0.2), but it is easy to do
2724    // ourselves.
2725    if (!IsFullScreen()) {
2726        GetToolBar()->Hide();
2727        GetStatusBar()->Hide();
2728    }
2729#endif
2730
2731    ShowFullScreen(!IsFullScreen());
2732    fullscreen_showing_menus = false;
2733    if (IsFullScreen())
2734        was_showing_sidepanel_before_fullscreen = ShowingSidePanel();
2735    if (was_showing_sidepanel_before_fullscreen)
2736        ToggleSidePanel();
2737
2738#ifdef __WXMAC__
2739    if (!IsFullScreen()) {
2740        GetStatusBar()->Show();
2741        GetToolBar()->Show();
2742    }
2743#endif
2744}
2745
2746bool MainFrm::FullScreenModeShowingMenus() const
2747{
2748    return fullscreen_showing_menus;
2749}
2750
2751void MainFrm::FullScreenModeShowMenus(bool show)
2752{
2753    if (!IsFullScreen() || show == fullscreen_showing_menus)
2754        return;
2755    GetMenuBar()->Show(show);
2756    fullscreen_showing_menus = show;
2757}
Note: See TracBrowser for help on using the repository browser.