source: git/src/mainfrm.cc @ b4f28e0

line_contentsstereotravis-osx 1.2.17-amended
Last change on this file since b4f28e0 was b4f28e0, checked in by Olly Betts <olly@…>, 5 years ago

lib/icons/Makefile.am,lib/icons/xpm2png,src/mainfrm.cc: Fix display
of icons for toolbar and notebook under WXMSW.

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