source: git/src/mainfrm.cc @ d7b53e3

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since d7b53e3 was d7b53e3, checked in by Olly Betts <olly@…>, 9 years ago

lib/icons/Makefile.am,lib/icons/log.xpm,lib/survex.pot,src/: Add a
menu item and toolbar button to show the cavern log window if the
currently shown survey data was processed by aven. Reported by
Hugh St Lawrence in #47, and by Dave Clucas and others previously on
the list.

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