source: git/src/mainfrm.cc @ a616825

RELEASE/1.0RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since a616825 was a616825, checked in by Olly Betts <olly@…>, 19 years ago

Make more messages translatable

git-svn-id: file:///home/survex-svn/survex/trunk@3132 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 46.6 KB
RevLine 
[5809313]1//
[156dc16]2//  mainfrm.cc
[5809313]3//
4//  Main frame handling for Aven.
5//
[5e2710c]6//  Copyright (C) 2000-2002 Mark R. Shinwell
[301bbc1]7//  Copyright (C) 2001-2003,2004,2005 Olly Betts
[f4b1dae]8//  Copyright (C) 2004 Philip Underwood
[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
22//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23//
24
[17aa816]25#ifdef HAVE_CONFIG_H
26#include <config.h>
27#endif
28
[5809313]29#include "mainfrm.h"
30#include "aven.h"
[6e65d9e]31#include "aboutdlg.h"
[706b033]32
[93c3f97]33#include "message.h"
[706b033]34#include "img.h"
[156dc16]35#include "namecmp.h"
[09d50cc]36#include "printwx.h"
[d8a725c]37#include "filename.h"
[706b033]38
[2d9ed8ad]39#include <wx/confbase.h>
[02a7912]40#include <wx/regex.h>
[3d64f9e]41
[5809313]42#include <float.h>
[7a9dd2d]43#include <functional>
[156dc16]44#include <stack>
[0c76ad9]45
[d8a725c]46using namespace std;
47
[3d64f9e]48const int NUM_DEPTH_COLOURS = 13; // up to 13
[137bf99]49
[30e3301]50#include "avenpal.h"
[137bf99]51
[b1de3e0]52class AvenSplitterWindow : public wxSplitterWindow {
53    MainFrm *parent;
54
55    public:
56        AvenSplitterWindow(MainFrm *parent_)
[2dfd768]57            : wxSplitterWindow(parent_, -1, wxDefaultPosition, wxDefaultSize,
58                               wxSP_3D | wxSP_LIVE_UPDATE),
59              parent(parent_)
60        {
[b1de3e0]61        }
62
63        void OnSplitterDClick(wxSplitterEvent &e) {
[ffe057b]64#if wxCHECK_VERSION(2,3,0)
[fa2cd10]65            e.Veto();
[ea7b0d0]66#endif
[ffe057b]67#if defined(__UNIX__) && !wxCHECK_VERSION(2,3,5)
[fa2cd10]68            parent->m_SashPosition = GetSashPosition(); // save width of panel
69            // Calling Unsplit from OnSplitterDClick() doesn't work in debian
70            // wxGtk 2.3.3.2 (which calls itself 2.3.4) - it does work from CVS
71            // prior to the actual 2.3.4 though - FIXME: monitor this
72            // situation...
73            SetSashPosition(0);
74#else
[b1de3e0]75            parent->ToggleSidePanel();
[fa2cd10]76#endif
[b1de3e0]77        }
[c19a1ff]78
[b1de3e0]79    private:
80        DECLARE_EVENT_TABLE()
81};
82
83BEGIN_EVENT_TABLE(AvenSplitterWindow, wxSplitterWindow)
[fbcd4b5]84    // The wx docs say "EVT_SPLITTER_DOUBLECLICKED" but the wx headers say
85    // "EVT_SPLITTER_DCLICK" (wx docs corrected to agree with headers in 2.3)
[b1de3e0]86#ifdef EVT_SPLITTER_DOUBLECLICKED
87    EVT_SPLITTER_DOUBLECLICKED(-1, AvenSplitterWindow::OnSplitterDClick)
88#else
89    EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick)
90#endif
91END_EVENT_TABLE()
92
[137bf99]93BEGIN_EVENT_TABLE(MainFrm, wxFrame)
[2a02de2]94    EVT_BUTTON(button_FIND, MainFrm::OnFind)
95    EVT_BUTTON(button_HIDE, MainFrm::OnHide)
96
[137bf99]97    EVT_MENU(menu_FILE_OPEN, MainFrm::OnOpen)
[09d50cc]98    EVT_MENU(menu_FILE_PRINT, MainFrm::OnPrint)
99    EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup)
[d8a725c]100    EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport)
[137bf99]101    EVT_MENU(menu_FILE_QUIT, MainFrm::OnQuit)
[732b9b0]102    EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile)
[137bf99]103
104    EVT_CLOSE(MainFrm::OnClose)
[4b1fc48]105    EVT_SET_FOCUS(MainFrm::OnSetFocus)
[137bf99]106
107    EVT_MENU(menu_ROTATION_START, MainFrm::OnStartRotation)
[7ebc3d1]108    EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation)
[137bf99]109    EVT_MENU(menu_ROTATION_STOP, MainFrm::OnStopRotation)
110    EVT_MENU(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUp)
111    EVT_MENU(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDown)
112    EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation)
113    EVT_MENU(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceAnticlockwise)
114    EVT_MENU(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceClockwise)
115    EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth)
116    EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast)
117    EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth)
118    EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest)
119    EVT_MENU(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeft)
120    EVT_MENU(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRight)
121    EVT_MENU(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUp)
122    EVT_MENU(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDown)
123    EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan)
124    EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation)
125    EVT_MENU(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpoint)
126    EVT_MENU(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpoint)
127    EVT_MENU(menu_ORIENT_ZOOM_IN, MainFrm::OnZoomIn)
128    EVT_MENU(menu_ORIENT_ZOOM_OUT, MainFrm::OnZoomOut)
129    EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults)
130    EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs)
131    EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses)
[fe444b8]132    EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances)
133    EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts)
134    EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts)
[137bf99]135    EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames)
136    EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames)
137    EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
138    EVT_MENU(menu_VIEW_SURFACE_DEPTH, MainFrm::OnShowSurfaceDepth)
139    EVT_MENU(menu_VIEW_SURFACE_DASHED, MainFrm::OnShowSurfaceDashed)
140    EVT_MENU(menu_VIEW_COMPASS, MainFrm::OnViewCompass)
141    EVT_MENU(menu_VIEW_CLINO, MainFrm::OnViewClino)
[c1cf79d]142    EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
[137bf99]143    EVT_MENU(menu_VIEW_DEPTH_BAR, MainFrm::OnToggleDepthbar)
144    EVT_MENU(menu_VIEW_SCALE_BAR, MainFrm::OnToggleScalebar)
[9059368]145    EVT_MENU(menu_VIEW_SIDE_PANEL, MainFrm::OnViewSidePanel)
[7a89dc2]146    EVT_MENU(menu_VIEW_METRIC, MainFrm::OnToggleMetric)
147    EVT_MENU(menu_VIEW_DEGREES, MainFrm::OnToggleDegrees)
[137bf99]148    EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls)
[1fd2edb]149    EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine)
[a87b1f7]150    EVT_MENU(menu_HELP_ABOUT, MainFrm::OnAbout)
[137bf99]151
[1064451]152    EVT_UPDATE_UI(menu_FILE_PRINT, MainFrm::OnPrintUpdate)
[d8a725c]153    EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate)
[137bf99]154    EVT_UPDATE_UI(menu_ROTATION_START, MainFrm::OnStartRotationUpdate)
[546a6f3]155    EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate)
[137bf99]156    EVT_UPDATE_UI(menu_ROTATION_STOP, MainFrm::OnStopRotationUpdate)
157    EVT_UPDATE_UI(menu_ROTATION_SPEED_UP, MainFrm::OnSpeedUpUpdate)
158    EVT_UPDATE_UI(menu_ROTATION_SLOW_DOWN, MainFrm::OnSlowDownUpdate)
159    EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate)
160    EVT_UPDATE_UI(menu_ROTATION_STEP_CCW, MainFrm::OnStepOnceAnticlockwiseUpdate)
161    EVT_UPDATE_UI(menu_ROTATION_STEP_CW, MainFrm::OnStepOnceClockwiseUpdate)
162    EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate)
163    EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate)
164    EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate)
165    EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate)
166    EVT_UPDATE_UI(menu_ORIENT_SHIFT_LEFT, MainFrm::OnShiftDisplayLeftUpdate)
167    EVT_UPDATE_UI(menu_ORIENT_SHIFT_RIGHT, MainFrm::OnShiftDisplayRightUpdate)
168    EVT_UPDATE_UI(menu_ORIENT_SHIFT_UP, MainFrm::OnShiftDisplayUpUpdate)
169    EVT_UPDATE_UI(menu_ORIENT_SHIFT_DOWN, MainFrm::OnShiftDisplayDownUpdate)
170    EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate)
171    EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate)
172    EVT_UPDATE_UI(menu_ORIENT_HIGHER_VP, MainFrm::OnHigherViewpointUpdate)
173    EVT_UPDATE_UI(menu_ORIENT_LOWER_VP, MainFrm::OnLowerViewpointUpdate)
174    EVT_UPDATE_UI(menu_ORIENT_ZOOM_IN, MainFrm::OnZoomInUpdate)
175    EVT_UPDATE_UI(menu_ORIENT_ZOOM_OUT, MainFrm::OnZoomOutUpdate)
176    EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate)
177    EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate)
178    EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate)
[fe444b8]179    EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate)
180    EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate)
181    EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate)
[137bf99]182    EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate)
183    EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate)
184    EVT_UPDATE_UI(menu_VIEW_SURFACE_DEPTH, MainFrm::OnShowSurfaceDepthUpdate)
185    EVT_UPDATE_UI(menu_VIEW_SURFACE_DASHED, MainFrm::OnShowSurfaceDashedUpdate)
186    EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate)
187    EVT_UPDATE_UI(menu_VIEW_COMPASS, MainFrm::OnViewCompassUpdate)
188    EVT_UPDATE_UI(menu_VIEW_CLINO, MainFrm::OnViewClinoUpdate)
189    EVT_UPDATE_UI(menu_VIEW_DEPTH_BAR, MainFrm::OnToggleDepthbarUpdate)
190    EVT_UPDATE_UI(menu_VIEW_SCALE_BAR, MainFrm::OnToggleScalebarUpdate)
[c1cf79d]191    EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
[e3513a5]192    EVT_UPDATE_UI(menu_VIEW_INDICATORS, MainFrm::OnIndicatorsUpdate)
[9059368]193    EVT_UPDATE_UI(menu_VIEW_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate)
[137bf99]194    EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate)
[1fd2edb]195    EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate)
[7a89dc2]196    EVT_UPDATE_UI(menu_VIEW_METRIC, MainFrm::OnToggleMetricUpdate)
197    EVT_UPDATE_UI(menu_VIEW_DEGREES, MainFrm::OnToggleDegreesUpdate)
[5809313]198END_EVENT_TABLE()
199
[7a9dd2d]200class LabelCmp : public greater<const LabelInfo*> {
[9f9c05e]201    int separator;
[156dc16]202public:
[9f9c05e]203    LabelCmp(int separator_) : separator(separator_) {}
[156dc16]204    bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
[9f9c05e]205        return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
[156dc16]206    }
207};
208
[7a9dd2d]209class LabelPlotCmp : public greater<const LabelInfo*> {
[9f9c05e]210    int separator;
[291ca5d]211public:
[9f9c05e]212    LabelPlotCmp(int separator_) : separator(separator_) {}
[291ca5d]213    bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
[fa42426]214        int n = pt1->flags - pt2->flags;
[291ca5d]215        if (n) return n > 0;
[b451f1c]216        wxString l1 = pt1->text.AfterLast(separator);
217        wxString l2 = pt2->text.AfterLast(separator);
218        n = name_cmp(l1, l2, separator);
219        if (n) return n < 0;
[5e2710c]220        // Prefer non-2-nodes...
221        // FIXME; implement
[b451f1c]222        // if leaf names are the same, prefer shorter labels as we can
223        // display more of them
224        n = pt1->text.length() - pt2->text.length();
225        if (n) return n < 0;
[5e2710c]226        // make sure that we don't ever compare different labels as equal
[b451f1c]227        return name_cmp(pt1->text, pt2->text, separator) < 0;
[291ca5d]228    }
229};
230
[f6fe808]231#if wxUSE_DRAG_AND_DROP
[5901b62]232class DnDFile : public wxFileDropTarget {
233    public:
234        DnDFile(MainFrm *parent) : m_Parent(parent) { }
235        virtual bool OnDropFiles(wxCoord, wxCoord,
236                        const wxArrayString &filenames);
237
238    private:
239        MainFrm * m_Parent;
240};
241
242bool
243DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
244{
245    // Load a survey file by drag-and-drop.
246    assert(filenames.GetCount() > 0);
247
248    if (filenames.GetCount() != 1) {
249        wxGetApp().ReportError(msg(/*You may only view one 3d file at a time.*/336));
250        return FALSE;
251    }
[421b7d2]252
[5901b62]253    m_Parent->OpenFile(filenames[0]);
254    return TRUE;
255}
[f6fe808]256#endif
[5901b62]257
[137bf99]258MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) :
[3b58f55]259    wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE),
[2c30188]260    m_Gfx(NULL), m_NumEntrances(0), m_NumFixedPts(0), m_NumExportedPts(0)
[5809313]261{
[90a3cd5]262    icon_path = msg_cfgpth();
263    icon_path += wxCONFIG_PATH_SEPARATOR;
264    icon_path += "icons";
265    icon_path += wxCONFIG_PATH_SEPARATOR;
266
[cfd6c44]267#ifdef _WIN32
[003d953]268    // The peculiar name is so that the icon is the first in the file
[b1de3e0]269    // (required by Microsoft Windows for this type of icon)
[398f23d]270    SetIcon(wxIcon("aaaaaAven"));
[90a3cd5]271#else
272    SetIcon(wxIcon(icon_path + "aven.png", wxBITMAP_TYPE_PNG));
[cfd6c44]273#endif
274
[9d3d8cc]275    InitialisePensAndBrushes();
276    CreateMenuBar();
277    CreateToolBar();
278    CreateSidePanel();
279
[c464728]280#ifdef __X__ // wxMotif or wxX11
[9d3d8cc]281    int x;
282    int y;
283    GetSize(&x, &y);
284    // X seems to require a forced resize.
285    SetSize(-1, -1, x, y);
286#endif
287
[0edb0d0]288#if wxUSE_DRAG_AND_DROP
[5901b62]289    SetDropTarget(new DnDFile(this));
[f6fe808]290#endif
[9d3d8cc]291}
292
293MainFrm::~MainFrm()
294{
295    ClearPointLists();
296    delete[] m_Points;
[ce1e5ac]297    delete[] m_Pens;
298    delete[] m_Brushes;
[9d3d8cc]299}
300
301void MainFrm::InitialisePensAndBrushes()
302{
[ce1e5ac]303    m_Points = new list<PointInfo*>[NUM_DEPTH_COLOURS + 1];
304    m_Pens = new wxPen[NUM_DEPTH_COLOURS + 1];
305    m_Brushes = new wxBrush[NUM_DEPTH_COLOURS + 1];
306    for (int pen = 0; pen < NUM_DEPTH_COLOURS + 1; ++pen) {
[421b7d2]307        m_Pens[pen].SetColour(REDS[pen], GREENS[pen], BLUES[pen]);
308        m_Brushes[pen].SetColour(REDS[pen], GREENS[pen], BLUES[pen]);
[137bf99]309    }
[9d3d8cc]310}
311
312void MainFrm::CreateMenuBar()
313{
314    // Create the menus and the menu bar.
[137bf99]315
316    wxMenu* filemenu = new wxMenu;
[003d953]317    filemenu->Append(menu_FILE_OPEN, GetTabMsg(/*@Open...##Ctrl+O*/220));
[137bf99]318    filemenu->AppendSeparator();
[09d50cc]319    filemenu->Append(menu_FILE_PRINT, GetTabMsg(/*@Print...##Ctrl+P*/380));
320    filemenu->Append(menu_FILE_PAGE_SETUP, GetTabMsg(/*P@age Setup...*/381));
321    filemenu->AppendSeparator();
[a616825]322    filemenu->Append(menu_FILE_EXPORT, GetTabMsg(/*@Export as...*/382));
[d8a725c]323    filemenu->AppendSeparator();
[4b126a8]324    filemenu->Append(menu_FILE_QUIT, GetTabMsg(/*@Quit##Ctrl+Q*/221));
[137bf99]325
[cf8c84b]326    m_history.UseMenu(filemenu);
327    m_history.Load(*wxConfigBase::Get());
328
[137bf99]329    wxMenu* rotmenu = new wxMenu;
[003d953]330    rotmenu->Append(menu_ROTATION_START, GetTabMsg(/*@Start Rotation##Return*/230));
331    rotmenu->Append(menu_ROTATION_STOP, GetTabMsg(/*S@top Rotation##Space*/231));
[137bf99]332    rotmenu->AppendSeparator();
[026ae3c]333    rotmenu->Append(menu_ROTATION_SPEED_UP, GetTabMsg(/*Speed @Up*/232));
[c40038a]334    rotmenu->Append(menu_ROTATION_SLOW_DOWN, GetTabMsg(/*Slow @Down*/233));
[137bf99]335    rotmenu->AppendSeparator();
[026ae3c]336    rotmenu->Append(menu_ROTATION_REVERSE, GetTabMsg(/*@Reverse Direction*/234));
[137bf99]337    rotmenu->AppendSeparator();
[4b1fc48]338    rotmenu->Append(menu_ROTATION_STEP_CCW, GetTabMsg(/*Step Once @Anticlockwise*/235));
339    rotmenu->Append(menu_ROTATION_STEP_CW, GetTabMsg(/*Step Once @Clockwise*/236));
[137bf99]340
341    wxMenu* orientmenu = new wxMenu;
[026ae3c]342    orientmenu->Append(menu_ORIENT_MOVE_NORTH, GetTabMsg(/*View @North*/240));
343    orientmenu->Append(menu_ORIENT_MOVE_EAST, GetTabMsg(/*View @East*/241));
344    orientmenu->Append(menu_ORIENT_MOVE_SOUTH, GetTabMsg(/*View @South*/242));
345    orientmenu->Append(menu_ORIENT_MOVE_WEST, GetTabMsg(/*View @West*/243));
[137bf99]346    orientmenu->AppendSeparator();
[4b1fc48]347    orientmenu->Append(menu_ORIENT_SHIFT_LEFT, GetTabMsg(/*Shift Survey @Left*/244));
348    orientmenu->Append(menu_ORIENT_SHIFT_RIGHT, GetTabMsg(/*Shift Survey @Right*/245));
349    orientmenu->Append(menu_ORIENT_SHIFT_UP, GetTabMsg(/*Shift Survey @Up*/246));
350    orientmenu->Append(menu_ORIENT_SHIFT_DOWN, GetTabMsg(/*Shift Survey @Down*/247));
[137bf99]351    orientmenu->AppendSeparator();
[026ae3c]352    orientmenu->Append(menu_ORIENT_PLAN, GetTabMsg(/*@Plan View*/248));
[c40038a]353    orientmenu->Append(menu_ORIENT_ELEVATION, GetTabMsg(/*Ele@vation*/249));
[137bf99]354    orientmenu->AppendSeparator();
[4b1fc48]355    orientmenu->Append(menu_ORIENT_HIGHER_VP, GetTabMsg(/*@Higher Viewpoint*/250));
[46cb98f]356    orientmenu->Append(menu_ORIENT_LOWER_VP, GetTabMsg(/*L@ower Viewpoint*/251));
[137bf99]357    orientmenu->AppendSeparator();
[003d953]358    orientmenu->Append(menu_ORIENT_ZOOM_IN, GetTabMsg(/*@Zoom In##]*/252));
359    orientmenu->Append(menu_ORIENT_ZOOM_OUT, GetTabMsg(/*Zoo@m Out##[*/253));
[137bf99]360    orientmenu->AppendSeparator();
[70775b9]361    orientmenu->Append(menu_ORIENT_DEFAULTS, GetTabMsg(/*Restore De@fault Settings*/254));
[137bf99]362
363    wxMenu* viewmenu = new wxMenu;
[003d953]364    viewmenu->Append(menu_VIEW_SHOW_NAMES, GetTabMsg(/*Station @Names##Ctrl+N*/270), "", true);
365    viewmenu->Append(menu_VIEW_SHOW_CROSSES, GetTabMsg(/*@Crosses##Ctrl+X*/271), "", true);
366    viewmenu->Append(menu_VIEW_GRID, GetTabMsg(/*@Grid##Ctrl+G*/297), "", true);
[137bf99]367    viewmenu->AppendSeparator();
[8ac4406]368    viewmenu->Append(menu_VIEW_SHOW_LEGS, GetTabMsg(/*@Underground Survey Legs##Ctrl+L*/272), "", true);
369    viewmenu->Append(menu_VIEW_SHOW_SURFACE, GetTabMsg(/*@Surface Survey Legs##Ctrl+F*/291), "", true);
[137bf99]370    viewmenu->AppendSeparator();
[c40038a]371    viewmenu->Append(menu_VIEW_SURFACE_DEPTH, GetTabMsg(/*@Altitude Colouring on Surface Surveys*/292), "", true);
[8ac4406]372    viewmenu->Append(menu_VIEW_SURFACE_DASHED, GetTabMsg(/*@Dashed Surface Surveys*/293), "", true);
[137bf99]373    viewmenu->AppendSeparator();
[026ae3c]374    viewmenu->Append(menu_VIEW_SHOW_OVERLAPPING_NAMES, GetTabMsg(/*@Overlapping Names*/273), "", true);
[137bf99]375    viewmenu->AppendSeparator();
[003d953]376    viewmenu->Append(menu_VIEW_SHOW_ENTRANCES, GetTabMsg(/*Highlight @Entrances*/294), "", true);
[8ac4406]377    viewmenu->Append(menu_VIEW_SHOW_FIXED_PTS, GetTabMsg(/*Highlight @Fixed Points*/295), "", true);
378    viewmenu->Append(menu_VIEW_SHOW_EXPORTED_PTS, GetTabMsg(/*Highlight E@xported Points*/296), "", true);
[3d3924d]379
[137bf99]380    wxMenu* ctlmenu = new wxMenu;
[003d953]381    ctlmenu->Append(menu_CTL_REVERSE, GetTabMsg(/*@Reverse Sense##Ctrl+R*/280), "", true);
[1fd2edb]382    ctlmenu->AppendSeparator();
[ac0a709]383    ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, GetTabMsg(/*@Cancel Measuring Line##Escape*/281));
[8ac4406]384    ctlmenu->AppendSeparator();
385    wxMenu* indmenu = new wxMenu;
386    indmenu->Append(menu_VIEW_COMPASS, GetTabMsg(/*@Compass*/274), "", true);
387    indmenu->Append(menu_VIEW_CLINO, GetTabMsg(/*C@linometer*/275), "", true);
388    indmenu->Append(menu_VIEW_DEPTH_BAR, GetTabMsg(/*@Depth Bar*/276), "", true);
389    indmenu->Append(menu_VIEW_SCALE_BAR, GetTabMsg(/*@Scale Bar*/277), "", true);
390    ctlmenu->Append(menu_VIEW_INDICATORS, GetTabMsg(/*@Indicators*/299), indmenu);
391    ctlmenu->Append(menu_VIEW_SIDE_PANEL, GetTabMsg(/*@Side Panel*/337), "", true);
392    ctlmenu->AppendSeparator();
393    ctlmenu->Append(menu_VIEW_METRIC, GetTabMsg(/*@Metric*/342), "", true);
394    ctlmenu->Append(menu_VIEW_DEGREES, GetTabMsg(/*@Degrees*/343), "", true);
[137bf99]395
396    wxMenu* helpmenu = new wxMenu;
[c40038a]397    helpmenu->Append(menu_HELP_ABOUT, GetTabMsg(/*@About...*/290));
[137bf99]398
399    wxMenuBar* menubar = new wxMenuBar(wxMB_DOCKABLE);
400    menubar->Append(filemenu, GetTabMsg(/*@File*/210));
401    menubar->Append(rotmenu, GetTabMsg(/*@Rotation*/211));
402    menubar->Append(orientmenu, GetTabMsg(/*@Orientation*/212));
403    menubar->Append(viewmenu, GetTabMsg(/*@View*/213));
404    menubar->Append(ctlmenu, GetTabMsg(/*@Controls*/214));
405    menubar->Append(helpmenu, GetTabMsg(/*@Help*/215));
406    SetMenuBar(menubar);
[9d3d8cc]407}
[137bf99]408
[90a3cd5]409// ICON must be a literal string.
410#define TOOLBAR_BITMAP(ICON) wxBitmap(icon_path + ICON".png", wxBITMAP_TYPE_PNG)
411
[9d3d8cc]412void MainFrm::CreateToolBar()
413{
414    // Create the toolbar.
[137bf99]415
[9d3d8cc]416    wxToolBar* toolbar = wxFrame::CreateToolBar();
[137bf99]417
[168df28]418#ifndef __WXGTK20__
[ed8d930]419    toolbar->SetMargins(5, 5);
420#endif
421
[90a3cd5]422    toolbar->AddTool(menu_FILE_OPEN, TOOLBAR_BITMAP("open"), "Open a 3D file for viewing");
[2d9ed8ad]423    toolbar->AddSeparator();
[90a3cd5]424    toolbar->AddTool(menu_ROTATION_TOGGLE, TOOLBAR_BITMAP("rotation"),
[003d953]425                     wxNullBitmap, true, -1, -1, NULL, "Toggle rotation");
[2d9ed8ad]426    toolbar->AddSeparator();
[90a3cd5]427    toolbar->AddTool(menu_ORIENT_PLAN, TOOLBAR_BITMAP("plan"), "Switch to plan view");
428    toolbar->AddTool(menu_ORIENT_ELEVATION, TOOLBAR_BITMAP("elevation"), "Switch to elevation view");
[2d9ed8ad]429    toolbar->AddSeparator();
[90a3cd5]430    toolbar->AddTool(menu_ORIENT_DEFAULTS, TOOLBAR_BITMAP("defaults"), "Restore default view");
[2d9ed8ad]431    toolbar->AddSeparator();
[90a3cd5]432    toolbar->AddTool(menu_VIEW_SHOW_NAMES, TOOLBAR_BITMAP("names"), wxNullBitmap, true,
[421b7d2]433                     -1, -1, NULL, "Show station names");
[90a3cd5]434    toolbar->AddTool(menu_VIEW_SHOW_CROSSES, TOOLBAR_BITMAP("crosses"), wxNullBitmap, true,
[421b7d2]435                     -1, -1, NULL, "Show crosses on stations");
[90a3cd5]436    toolbar->AddTool(menu_VIEW_SHOW_ENTRANCES, TOOLBAR_BITMAP("entrances"), wxNullBitmap, true,
[421b7d2]437                     -1, -1, NULL, "Highlight entrances");
[90a3cd5]438    toolbar->AddTool(menu_VIEW_SHOW_FIXED_PTS, TOOLBAR_BITMAP("fixed-pts"), wxNullBitmap, true,
[421b7d2]439                     -1, -1, NULL, "Highlight fixed points");
[90a3cd5]440    toolbar->AddTool(menu_VIEW_SHOW_EXPORTED_PTS, TOOLBAR_BITMAP("exported-pts"), wxNullBitmap, true,
[421b7d2]441                     -1, -1, NULL, "Highlight exported stations");
[2d9ed8ad]442    toolbar->AddSeparator();
[90a3cd5]443    toolbar->AddTool(menu_VIEW_SHOW_LEGS, TOOLBAR_BITMAP("ug-legs"), wxNullBitmap, true,
[421b7d2]444                     -1, -1, NULL, "Show underground surveys");
[90a3cd5]445    toolbar->AddTool(menu_VIEW_SHOW_SURFACE, TOOLBAR_BITMAP("surface-legs"), wxNullBitmap, true,
[421b7d2]446                     -1, -1, NULL, "Show surface surveys");
[2d9ed8ad]447    toolbar->AddSeparator();
[3d3924d]448
[2d9ed8ad]449    toolbar->Realize();
[9d3d8cc]450}
[2d9ed8ad]451
[9d3d8cc]452void MainFrm::CreateSidePanel()
453{
[b1de3e0]454    m_Splitter = new AvenSplitterWindow(this);
[421b7d2]455
[156dc16]456    m_Panel = new wxPanel(m_Splitter);
457    m_Tree = new AvenTreeCtrl(this, m_Panel);
[2c30188]458    wxPanel *find_panel = new wxPanel(m_Panel);
[e9b97eb]459    m_Panel->Show(false);
[156dc16]460
[2c30188]461    m_FindBox = new wxTextCtrl(find_panel, -1, "");
462    wxButton *find_button, *hide_button;
463    find_button = new wxButton(find_panel, button_FIND, msg(/*Find*/332));
464    find_button->SetDefault();
465    find_panel->SetDefaultItem(find_button);
466    hide_button = new wxButton(find_panel, button_HIDE, msg(/*Hide*/333));
467    m_RegexpCheckBox = new wxCheckBox(find_panel, -1,
[421b7d2]468                                      msg(/*Regular expression*/334));
[2c30188]469    m_Coords = new wxStaticText(find_panel, -1, "");
470    m_StnCoords = new wxStaticText(find_panel, -1, "");
471    //  m_MousePtr = new wxStaticText(find_panel, -1, "Mouse coordinates");
472    m_StnName = new wxStaticText(find_panel, -1, "");
473    m_StnAlt = new wxStaticText(find_panel, -1, "");
474    m_Dist1 = new wxStaticText(find_panel, -1, "");
475    m_Dist2 = new wxStaticText(find_panel, -1, "");
476    m_Dist3 = new wxStaticText(find_panel, -1, "");
477    m_Found = new wxStaticText(find_panel, -1, "");
478
479    wxBoxSizer *find_button_sizer = new wxBoxSizer(wxHORIZONTAL);
480    find_button_sizer->Add(m_FindBox, 1, wxALL, 2);
[0c76ad9]481#ifdef _WIN32
[2c30188]482    find_button_sizer->Add(find_button, 0, wxALL, 2);
[0c76ad9]483#else
484    // GTK+ (and probably Motif) default buttons have a thick external
485    // border we need to allow for
[2c30188]486    find_button_sizer->Add(find_button, 0, wxALL, 4);
[0c76ad9]487#endif
[01faa28]488
[2c30188]489    wxBoxSizer *hide_button_sizer = new wxBoxSizer(wxHORIZONTAL);
490    hide_button_sizer->Add(m_Found, 1, wxALL, 2);
[c8aff97]491#ifdef _WIN32
[2c30188]492    hide_button_sizer->Add(hide_button, 0, wxALL, 2);
[c8aff97]493#else
[2c30188]494    hide_button_sizer->Add(hide_button, 0, wxALL, 4);
[c8aff97]495#endif
[156dc16]496
[2c30188]497    wxBoxSizer *find_sizer = new wxBoxSizer(wxVERTICAL);
498    find_sizer->Add(find_button_sizer, 0, wxALL | wxEXPAND, 2);
499    find_sizer->Add(hide_button_sizer, 0, wxALL | wxEXPAND, 2);
500    find_sizer->Add(m_RegexpCheckBox, 0, wxALL | wxEXPAND, 2);
501    find_sizer->Add(10, 5, 0, wxALL | wxEXPAND, 2);
502    //   find_sizer->Add(m_MousePtr, 0, wxALL | wxEXPAND, 2);
503    find_sizer->Add(m_Coords, 0, wxALL | wxEXPAND, 2);
504    find_sizer->Add(10, 5, 0, wxALL | wxEXPAND, 2);
505    find_sizer->Add(m_StnName, 0, wxALL | wxEXPAND, 2);
506    find_sizer->Add(m_StnCoords, 0, wxALL | wxEXPAND, 2);
507    find_sizer->Add(m_StnAlt, 0, wxALL | wxEXPAND, 2);
508    find_sizer->Add(10, 5, 0, wxALL | wxEXPAND, 2);
509    find_sizer->Add(m_Dist1, 0, wxALL | wxEXPAND, 2);
510    find_sizer->Add(m_Dist2, 0, wxALL | wxEXPAND, 2);
511    find_sizer->Add(m_Dist3, 0, wxALL | wxEXPAND, 2);
512
513    find_panel->SetAutoLayout(true);
514    find_panel->SetSizer(find_sizer);
515    find_sizer->Fit(find_panel);
516    find_sizer->SetSizeHints(find_panel);
517
518    wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);
519    panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2);
520    panel_sizer->Add(find_panel, 0, wxALL | wxEXPAND, 2);
[156dc16]521    m_Panel->SetAutoLayout(true);
[2c30188]522    m_Panel->SetSizer(panel_sizer);
523//    panel_sizer->Fit(m_Panel);
524//    panel_sizer->SetSizeHints(m_Panel);
[156dc16]525
526    m_Gfx = new GfxCore(this, m_Splitter);
527
[e9b97eb]528    m_Splitter->Initialize(m_Gfx);
[068b4f2]529}
[137bf99]530
531void MainFrm::ClearPointLists()
[5809313]532{
[137bf99]533    // Free memory occupied by the contents of the point and label lists.
[5809313]534
[137bf99]535    for (int band = 0; band < NUM_DEPTH_COLOURS + 1; band++) {
[421b7d2]536        list<PointInfo*>::iterator pos = m_Points[band].begin();
537        list<PointInfo*>::iterator end = m_Points[band].end();
538        while (pos != end) {
539            PointInfo* point = *pos++;
540            delete point;
541        }
542        m_Points[band].clear();
[137bf99]543    }
[a06eb11]544
[137bf99]545    list<LabelInfo*>::iterator pos = m_Labels.begin();
546    while (pos != m_Labels.end()) {
[421b7d2]547        LabelInfo* label = *pos++;
548        delete label;
[137bf99]549    }
550    m_Labels.clear();
[5809313]551}
[573f4e9]552
[1d0cd97]553bool MainFrm::LoadData(const wxString& file, wxString prefix)
[573f4e9]554{
[137bf99]555    // Load survey data from file, centre the dataset around the origin,
556    // chop legs such that no legs cross depth colour boundaries and prepare
557    // the data for drawing.
558
[c9427d2]559#if 0
560    wxStopWatch timer;
561    timer.Start();
562#endif
[137bf99]563
[168df28]564    // Load the survey data.
565
[5b2b04f]566    img* survey = img_open_survey(file, prefix.c_str());
[137bf99]567    if (!survey) {
[421b7d2]568        wxString m = wxString::Format(msg(img_error()), file.c_str());
569        wxGetApp().ReportError(m);
570        return false;
[137bf99]571    }
[1d0cd97]572
[76d0b1e]573    m_File = survey->filename_opened;
[156dc16]574
[9f176bd]575    m_Tree->DeleteAllItems();
576
[1d0cd97]577    // Create a list of all the leg vertices, counting them and finding the
578    // extent of the survey at the same time.
579
580    m_NumLegs = 0;
581    m_NumPoints = 0;
582    m_NumExtraLegs = 0;
583    m_NumCrosses = 0;
584    m_NumFixedPts = 0;
585    m_NumExportedPts = 0;
586    m_NumEntrances = 0;
587
588    // Delete any existing list entries.
589    ClearPointLists();
590
591    Double xmin = DBL_MAX;
592    Double xmax = -DBL_MAX;
593    Double ymin = DBL_MAX;
594    Double ymax = -DBL_MAX;
595    m_ZMin = DBL_MAX;
596    Double zmax = -DBL_MAX;
597
598    list<PointInfo*> points;
599
600    int result;
601    do {
[421b7d2]602        img_point pt;
603        result = img_read_item(survey, &pt);
604        switch (result) {
605            case img_MOVE:
606            case img_LINE:
607            {
608                m_NumPoints++;
609
610                // Update survey extents.
611                if (pt.x < xmin) xmin = pt.x;
612                if (pt.x > xmax) xmax = pt.x;
613                if (pt.y < ymin) ymin = pt.y;
614                if (pt.y > ymax) ymax = pt.y;
615                if (pt.z < m_ZMin) m_ZMin = pt.z;
616                if (pt.z > zmax) zmax = pt.z;
617
618                PointInfo* info = new PointInfo;
619                info->x = pt.x;
620                info->y = pt.y;
621                info->z = pt.z;
622
623                if (result == img_LINE) {
624                    // Set flags to say this is a line rather than a move
625                    m_NumLegs++;
626                    info->isLine = true;
627                    info->isSurface = (survey->flags & img_FLAG_SURFACE);
628                } else {
629                    info->isLine = false;
630                }
631
[c19a1ff]632                // Add this point to the list.
[421b7d2]633                points.push_back(info);
634                break;
635            }
636
[da4ddfe]637            case img_LABEL: {
[421b7d2]638                LabelInfo* label = new LabelInfo;
639                label->text = survey->label;
640                label->x = pt.x;
641                label->y = pt.y;
642                label->z = pt.z;
[fa42426]643                if (survey->flags & img_SFLAG_ENTRANCE) {
644                    survey->flags ^= (img_SFLAG_ENTRANCE | LFLAG_ENTRANCE);
645                }
[421b7d2]646                label->flags = survey->flags;
647                if (label->IsEntrance()) {
648                    m_NumEntrances++;
649                }
650                if (label->IsFixedPt()) {
651                    m_NumFixedPts++;
652                }
653                if (label->IsExportedPt()) {
654                    m_NumExportedPts++;
655                }
656                m_Labels.push_back(label);
657                m_NumCrosses++;
658
659                break;
660            }
661
[da4ddfe]662            case img_BAD: {
[421b7d2]663                m_Labels.clear();
664
665                // FIXME: Do we need to reset all these? - Olly
666                m_NumLegs = 0;
667                m_NumPoints = 0;
668                m_NumExtraLegs = 0;
669                m_NumCrosses = 0;
670                m_NumFixedPts = 0;
671                m_NumExportedPts = 0;
672                m_NumEntrances = 0;
673
674                m_ZMin = DBL_MAX;
675
676                img_close(survey);
677
678                wxString m = wxString::Format(msg(img_error()), file.c_str());
679                wxGetApp().ReportError(m);
[dc1a546]680
[421b7d2]681                return false;
682            }
683
684            default:
685                break;
686        }
[1d0cd97]687    } while (result != img_STOP);
[c1cf79d]688
[9f9c05e]689    separator = survey->separator;
[09d50cc]690    m_Title = survey->title;
691    m_DateStamp = survey->datestamp;
[1d0cd97]692    img_close(survey);
[137bf99]693
[1d0cd97]694    // Check we've actually loaded some legs or stations!
695    if (m_NumLegs == 0 && m_Labels.empty()) {
[421b7d2]696        wxString m = wxString::Format(msg(/*No survey data in 3d file `%s'*/202), file.c_str());
697        wxGetApp().ReportError(m);
698        return false;
[1d0cd97]699    }
[137bf99]700
[1d0cd97]701    if (points.empty()) {
[421b7d2]702        // No legs, so get survey extents from stations
703        list<LabelInfo*>::const_iterator i;
704        for (i = m_Labels.begin(); i != m_Labels.end(); ++i) {
705            if ((*i)->x < xmin) xmin = (*i)->x;
706            if ((*i)->x > xmax) xmax = (*i)->x;
707            if ((*i)->y < ymin) ymin = (*i)->y;
708            if ((*i)->y > ymax) ymax = (*i)->y;
709            if ((*i)->z < m_ZMin) m_ZMin = (*i)->z;
710            if ((*i)->z > zmax) zmax = (*i)->z;
711        }
[1d0cd97]712    } else {
[421b7d2]713        // Delete any trailing move.
714        PointInfo* pt = points.back();
715        if (!pt->isLine) {
716            m_NumPoints--;
717            points.pop_back();
718            delete pt;
719        }
[137bf99]720    }
721
[1d0cd97]722    m_XExt = xmax - xmin;
723    m_YExt = ymax - ymin;
724    m_ZExt = zmax - m_ZMin;
725
726    // FIXME -- temporary bodge
727    m_XMin = xmin;
728    m_YMin = ymin;
729
[156dc16]730    // Sort the labels.
[9f9c05e]731    m_Labels.sort(LabelCmp(separator));
[156dc16]732
733    // Fill the tree of stations and prefixes.
734    FillTree();
735
[291ca5d]736    // Sort labels so that entrances are displayed in preference,
737    // then fixed points, then exported points, then other points.
[50ada97]738    //
[291ca5d]739    // Also sort by leaf name so that we'll tend to choose labels
740    // from different surveys, rather than labels from surveys which
741    // are earlier in the list.
[9f9c05e]742    m_Labels.sort(LabelPlotCmp(separator));
[291ca5d]743
[1d0cd97]744    // Sort out depth colouring boundaries (before centering dataset!)
745    SortIntoDepthBands(points);
746
747    // Centre the dataset around the origin.
748    CentreDataset(xmin, ymin, m_ZMin);
749
[c9427d2]750#if 0
751    printf("time to load = %.3f\n", (double)timer.Time());
752#endif
753
[1d0cd97]754    // Update window title.
[76d0b1e]755    SetTitle(wxString(APP_NAME" - [") + m_File + wxString("]"));
[1d0cd97]756
757    return true;
[f626e1f]758}
759
[156dc16]760void MainFrm::FillTree()
761{
[168df28]762    // Create the root of the tree.
763    wxTreeItemId treeroot = m_Tree->AddRoot(wxFileNameFromPath(m_File));
[156dc16]764
[168df28]765    // Fill the tree of stations and prefixes.
[156dc16]766    stack<wxTreeItemId> previous_ids;
767    wxString current_prefix = "";
[168df28]768    wxTreeItemId current_id = treeroot;
[156dc16]769
[246426e]770    list<LabelInfo*>::iterator pos = m_Labels.begin();
[156dc16]771    while (pos != m_Labels.end()) {
[421b7d2]772        LabelInfo* label = *pos++;
[156dc16]773
[421b7d2]774        // Determine the current prefix.
[9f9c05e]775        wxString prefix = label->GetText().BeforeLast(separator);
[9d3d8cc]776
[421b7d2]777        // Determine if we're still on the same prefix.
778        if (prefix == current_prefix) {
779            // no need to fiddle with branches...
780        }
781        // If not, then see if we've descended to a new prefix.
[168df28]782        else if (prefix.length() > current_prefix.length() &&
[003d953]783                 prefix.StartsWith(current_prefix) &&
[168df28]784                 (prefix[current_prefix.length()] == separator ||
[003d953]785                  current_prefix == "")) {
[421b7d2]786            // We have, so start as many new branches as required.
[168df28]787            int current_prefix_length = current_prefix.length();
[421b7d2]788            current_prefix = prefix;
789            if (current_prefix_length != 0) {
790                prefix = prefix.Mid(current_prefix_length + 1);
791            }
792            int next_dot;
793            do {
794                // Extract the next bit of prefix.
[9f9c05e]795                next_dot = prefix.Find(separator);
[421b7d2]796
797                wxString bit = next_dot == -1 ? prefix : prefix.Left(next_dot);
798                assert(bit != "");
799
800                // Add the current tree ID to the stack.
801                previous_ids.push(current_id);
802
803                // Append the new item to the tree and set this as the current branch.
804                current_id = m_Tree->AppendItem(current_id, bit);
805                m_Tree->SetItemData(current_id, new TreeData(NULL));
806                prefix = prefix.Mid(next_dot + 1);
807            } while (next_dot != -1);
808        }
809        // Otherwise, we must have moved up, and possibly then down again.
810        else {
[dc8d2eb]811            size_t count = 0;
[168df28]812            bool ascent_only = (prefix.length() < current_prefix.length() &&
[421b7d2]813                                current_prefix.StartsWith(prefix) &&
[168df28]814                                (current_prefix[prefix.length()] == separator ||
[9f9c05e]815                                 prefix == ""));
[421b7d2]816            if (!ascent_only) {
[7d9e02b]817                // Find out how much of the current prefix and the new prefix
818                // are the same.
819                // Note that we require a match of a whole number of parts
820                // between dots!
[2dfd768]821                for (size_t i = 0; prefix[i] == current_prefix[i]; ++i) {
822                    if (prefix[i] == separator) count = i + 1;
[421b7d2]823                }
[2dfd768]824            } else {
[168df28]825                count = prefix.length() + 1;
[421b7d2]826            }
827
[7d9e02b]828            // Extract the part of the current prefix after the bit (if any)
829            // which has matched.
[421b7d2]830            // This gives the prefixes to ascend over.
831            wxString prefixes_ascended = current_prefix.Mid(count);
832
833            // Count the number of prefixes to ascend over.
[9f9c05e]834            int num_prefixes = prefixes_ascended.Freq(separator);
[421b7d2]835
836            // Reverse up over these prefixes.
837            for (int i = 1; i <= num_prefixes; i++) {
838                previous_ids.pop();
839            }
[8734409]840            current_id = previous_ids.top();
841            previous_ids.pop();
[421b7d2]842
843            if (!ascent_only) {
844                // Now extract the bit of new prefix.
845                wxString new_prefix = prefix.Mid(count);
846
847                // Add branches for this new part.
[da4ddfe]848                while (true) {
[421b7d2]849                    // Extract the next bit of prefix.
[9f9c05e]850                    int next_dot = new_prefix.Find(separator);
[421b7d2]851
[8734409]852                    wxString bit;
853                    if (next_dot == -1) {
854                        bit = new_prefix;
855                    } else {
856                        bit = new_prefix.Left(next_dot);
857                    }
[421b7d2]858
859                    // Add the current tree ID to the stack.
860                    previous_ids.push(current_id);
861
[7d9e02b]862                    // Append the new item to the tree and set this as the
863                    // current branch.
[421b7d2]864                    current_id = m_Tree->AppendItem(current_id, bit);
865                    m_Tree->SetItemData(current_id, new TreeData(NULL));
866
[8734409]867                    if (next_dot == -1) break;
[421b7d2]868
869                    new_prefix = new_prefix.Mid(next_dot + 1);
870                }
871            }
872
873            current_prefix = prefix;
874        }
875
876        // Now add the leaf.
[9f9c05e]877        wxString bit = label->GetText().AfterLast(separator);
[421b7d2]878        assert(bit != "");
879        wxTreeItemId id = m_Tree->AppendItem(current_id, bit);
880        m_Tree->SetItemData(id, new TreeData(label));
[168df28]881        label->tree_id = id;
882        // Set the colour for an item in the survey tree.
883        if (label->IsEntrance()) {
884            // Entrances are green (like entrance blobs).
885            m_Tree->SetItemTextColour(id, wxColour(0, 255, 0));
886        } else if (label->IsSurface()) {
887            // Surface stations are dark green.
888            m_Tree->SetItemTextColour(id, wxColour(49, 158, 79));
889        }
[156dc16]890    }
[168df28]891
892    m_Tree->Expand(treeroot);
893    m_Tree->SetEnabled();
[156dc16]894}
895
[6dde19f]896void MainFrm::SelectTreeItem(LabelInfo* label)
897{
898    m_Tree->SelectItem(label->tree_id);
899}
900
[c6d95d8]901void MainFrm::CentreDataset(Double xmin, Double ymin, Double zmin)
[f626e1f]902{
[137bf99]903    // Centre the dataset around the origin.
[7640091]904
[168df28]905    Double xoff = xmin + (m_XExt / 2.0);
906    Double yoff = ymin + (m_YExt / 2.0);
907    Double zoff = zmin + (m_ZExt / 2.0);
908    m_Offsets.set(xoff, yoff, zoff);
[421b7d2]909
[137bf99]910    for (int band = 0; band < NUM_DEPTH_COLOURS + 1; band++) {
[421b7d2]911        list<PointInfo*>::iterator pos = m_Points[band].begin();
912        list<PointInfo*>::iterator end = m_Points[band].end();
913        while (pos != end) {
914            PointInfo* point = *pos++;
915            point->x -= xoff;
916            point->y -= yoff;
917            point->z -= zoff;
918        }
[137bf99]919    }
[7640091]920
[c19a1ff]921    list<LabelInfo*>::iterator lpos = m_Labels.begin();
922    while (lpos != m_Labels.end()) {
923        LabelInfo* label = *lpos++;
[421b7d2]924        label->x -= xoff;
925        label->y -= yoff;
926        label->z -= zoff;
[137bf99]927    }
928}
929
[c6d95d8]930int MainFrm::GetDepthColour(Double z)
[137bf99]931{
932    // Return the (0-based) depth colour band index for a z-coordinate.
[8734409]933    return int(((z - m_ZMin) / (m_ZExt == 0.0 ? 1.0 : m_ZExt)) * (NUM_DEPTH_COLOURS - 1));
[137bf99]934}
935
[c6d95d8]936Double MainFrm::GetDepthBoundaryBetweenBands(int a, int b)
[137bf99]937{
938    // Return the z-coordinate of the depth colour boundary between
939    // two adjacent depth colour bands (specified by 0-based indices).
940
941    assert((a == b - 1) || (a == b + 1));
942
943    int band = (a > b) ? a : b; // boundary N lies on the bottom of band N.
944    return m_ZMin + (m_ZExt * band / (NUM_DEPTH_COLOURS - 1));
[573f4e9]945}
[a87b1f7]946
[c6d95d8]947void MainFrm::IntersectLineWithPlane(Double x0, Double y0, Double z0,
[421b7d2]948                                     Double x1, Double y1, Double z1,
949                                     Double z, Double& x, Double& y)
[a87b1f7]950{
[7d9e02b]951    // Find the intersection point of the line (x0, y0, z0) -> (x1, y1, z1)
952    // with the plane parallel to the xy-plane with z-axis intersection z.
[8734409]953    assert(z1 - z0 != 0.0);
[137bf99]954
[c6d95d8]955    Double t = (z - z0) / (z1 - z0);
[32d9bbc]956    // FIXME: this assertion fails on Windows - haven't investigated but I
[f17e9ee5]957    // suspect it'll be crap rounding:
958    // assert(0.0 <= t && t <= 1.0);
[cc6857f]959
960    x = x0 + t * (x1 - x0);
961    y = y0 + t * (y1 - y0);
[a87b1f7]962}
[8bac36d6]963
[137bf99]964void MainFrm::SortIntoDepthBands(list<PointInfo*>& points)
[8bac36d6]965{
[137bf99]966    // Split legs which cross depth colouring boundaries and classify all
967    // points into the correct depth bands.
968
969    list<PointInfo*>::iterator pos = points.begin();
970    PointInfo* prev_point = NULL;
971    while (pos != points.end()) {
[421b7d2]972        PointInfo* point = *pos++;
973        assert(point);
974
975        // If this is a leg, then check if it intersects a depth
976        // colour boundary.
[8734409]977        if (point->isLine) {
978            assert(prev_point);
[421b7d2]979            int col1 = GetDepthColour(prev_point->z);
980            int col2 = GetDepthColour(point->z);
981            if (col1 != col2) {
982                // The leg does cross at least one boundary, so split it as
983                // many times as required...
984                int inc = (col1 > col2) ? -1 : 1;
985                for (int band = col1; band != col2; band += inc) {
986                    int next_band = band + inc;
987
[7d9e02b]988                    // Determine the z-coordinate of the boundary being
989                    // intersected.
[421b7d2]990                    Double split_at_z = GetDepthBoundaryBetweenBands(band, next_band);
991                    Double split_at_x, split_at_y;
992
993                    // Find the coordinates of the intersection point.
994                    IntersectLineWithPlane(prev_point->x, prev_point->y, prev_point->z,
995                                           point->x, point->y, point->z,
996                                           split_at_z, split_at_x, split_at_y);
997
998                    // Create a new leg only as far as this point.
999                    PointInfo* info = new PointInfo;
1000                    info->x = split_at_x;
1001                    info->y = split_at_y;
1002                    info->z = split_at_z;
1003                    info->isLine = true;
1004                    info->isSurface = point->isSurface;
1005                    m_Points[band].push_back(info);
1006
1007                    // Create a move to this point in the next band.
1008                    info = new PointInfo;
1009                    info->x = split_at_x;
1010                    info->y = split_at_y;
1011                    info->z = split_at_z;
1012                    info->isLine = false;
1013                    info->isSurface = point->isSurface;
1014                    m_Points[next_band].push_back(info);
1015
1016                    m_NumExtraLegs++;
1017                    m_NumPoints += 2;
1018                }
1019            }
1020
1021            // Add the last point of the (possibly split) leg.
1022            m_Points[col2].push_back(point);
1023        }
1024        else {
[7d9e02b]1025            // The first point, a surface point, or another move: put it in the
1026            // correct list according to depth.
[421b7d2]1027            int band = GetDepthColour(point->z);
1028            m_Points[band].push_back(point);
1029        }
1030
1031        prev_point = point;
[137bf99]1032    }
1033}
[10fd434]1034
[732b9b0]1035void MainFrm::OnMRUFile(wxCommandEvent& event)
1036{
1037    wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1));
1038    if (!f.empty()) OpenFile(f);
1039}
1040
[ce3ce72]1041void MainFrm::OpenFile(const wxString& file, wxString survey, bool delay)
[137bf99]1042{
[4b1fc48]1043    wxBusyCursor hourglass;
[1d0cd97]1044    if (LoadData(file, survey)) {
[76d0b1e]1045        if (wxIsAbsolutePath(m_File)) {
1046            m_history.AddFileToHistory(m_File);
[eb5b48df]1047        } else {
[76d0b1e]1048            wxString abs = wxGetCwd() + wxString(FNM_SEP_LEV) + m_File;
[eb5b48df]1049            m_history.AddFileToHistory(abs);
1050        }
1051        wxConfigBase *b = wxConfigBase::Get();
1052        m_history.Save(*b);
1053        b->Flush();
1054
[421b7d2]1055        int x;
1056        int y;
[c464728]1057        GetClientSize(&x, &y);
[01faa28]1058        if (x < 600)
1059            x /= 3;
1060        else if (x < 1000)
1061            x = 200;
1062        else
1063            x /= 5;
[421b7d2]1064
1065        m_Splitter->SplitVertically(m_Panel, m_Gfx, x);
[c464728]1066        m_SashPosition = x; // Save width of panel.
1067
1068        if (delay) {
1069            m_Gfx->InitialiseOnNextResize();
1070        } else {
1071            m_Gfx->Initialise();
1072        }
1073        m_Panel->Show(true);
[b1de3e0]1074
[431c41c]1075        m_Gfx->SetFocus();
[8000d8f]1076    }
1077}
1078
[137bf99]1079//
1080//  UI event handlers
1081//
1082
[496a208]1083#undef FILEDIALOG_MULTIGLOBS
[1d95dde]1084// MS Windows supports "*.abc;*.def" natively; wxGtk supports them as of 2.3
[ffe057b]1085#if defined(_WIN32) || wxCHECK_VERSION(2,3,0)
[496a208]1086# define FILEDIALOG_MULTIGLOBS
1087#endif
1088
[137bf99]1089void MainFrm::OnOpen(wxCommandEvent&)
1090{
1091#ifdef __WXMOTIF__
[c40038a]1092    wxFileDialog dlg (this, wxString(msg(/*Select a 3d file to view*/206)), "", "",
[421b7d2]1093                      "*.3d", wxOPEN);
[137bf99]1094#else
[c19a1ff]1095    wxFileDialog dlg(this, wxString(msg(/*Select a 3d file to view*/206)), "", "",
[41ac0c3]1096                     wxString::Format("%s|*.3d"
[496a208]1097#ifdef FILEDIALOG_MULTIGLOBS
[41ac0c3]1098                                      ";*.3D"
[d16db18]1099#endif
[0eab709]1100#ifdef FILEDIALOG_MULTIGLOBS
[41ac0c3]1101                                      "|%s|*.plt;*.plf"
[d16db18]1102#ifndef _WIN32
[41ac0c3]1103                                      ";*.PLT;*.PLF"
[496a208]1104#endif
1105#else
[41ac0c3]1106                                      "|%s|*.pl?" // not ideal...
[d16db18]1107#endif
[0eab709]1108                                      "|%s|*.xyz"
[496a208]1109#ifdef FILEDIALOG_MULTIGLOBS
[d16db18]1110#ifndef _WIN32
[41ac0c3]1111                                      ";*.XYZ"
[496a208]1112#endif
[d16db18]1113#endif
[41ac0c3]1114                                      "|%s|%s",
1115                                      msg(/*Survex 3d files*/207),
[c19a1ff]1116                                      msg(/*Compass PLT files*/324),
1117                                      msg(/*CMAP XYZ files*/325),
[41ac0c3]1118                                      msg(/*All files*/208),
1119                                      wxFileSelectorDefaultWildcardStr),
1120                     wxOPEN);
[137bf99]1121#endif
1122    if (dlg.ShowModal() == wxID_OK) {
[421b7d2]1123        OpenFile(dlg.GetPath());
[137bf99]1124    }
1125}
1126
[09d50cc]1127void MainFrm::OnPrint(wxCommandEvent&)
1128{
1129    m_Gfx->OnPrint(m_File, m_Title, m_DateStamp);
1130}
1131
1132void MainFrm::OnPageSetup(wxCommandEvent&)
1133{
[168df28]1134    wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData());
1135    if (dlg.ShowModal() == wxID_OK) {
1136        wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData());
1137    }
[09d50cc]1138}
1139
[d8a725c]1140void MainFrm::OnExport(wxCommandEvent&)
1141{
1142    char *baseleaf = baseleaf_from_fnm(m_File.c_str());
1143    wxFileDialog dlg(this, wxString("Export as:"), "",
[7224b9f]1144                     wxString(baseleaf),
[301bbc1]1145                     "DXF files|*.dxf|SVG files|*.svg|Sketch files|*.sk|EPS files|*.eps|Compass PLT for use with Carto|*.plt",
[d8a725c]1146                     wxSAVE|wxOVERWRITE_PROMPT);
1147    free(baseleaf);
1148    if (dlg.ShowModal() == wxID_OK) {
[7224b9f]1149        wxString fnm = dlg.GetPath();
[301bbc1]1150        if (!m_Gfx->OnExport(fnm, m_Title)) {
[58753b1c]1151            wxGetApp().ReportError(wxString::Format("Couldn't write file `%s'", fnm.c_str()));
[d8a725c]1152        }
1153    }
1154}
1155
[137bf99]1156void MainFrm::OnQuit(wxCommandEvent&)
1157{
1158    exit(0);
1159}
1160
1161void MainFrm::OnClose(wxCloseEvent&)
1162{
1163    exit(0);
1164}
1165
1166void MainFrm::OnAbout(wxCommandEvent&)
1167{
[ad83822]1168    AboutDlg dlg(this, icon_path);
[de3de7b]1169    dlg.Centre();
1170    dlg.ShowModal();
[137bf99]1171}
[c6d95d8]1172
[003d953]1173void MainFrm::GetColour(int band, Double& r, Double& g, Double& b) const
[c6d95d8]1174{
1175    assert(band >= 0 && band < NUM_DEPTH_COLOURS);
1176    r = Double(REDS[band]) / 255.0;
1177    g = Double(GREENS[band]) / 255.0;
1178    b = Double(BLUES[band]) / 255.0;
1179}
[156dc16]1180
[1fd2edb]1181void MainFrm::ClearTreeSelection()
1182{
1183    m_Tree->UnselectAll();
[19026f3]1184    m_Gfx->SetThere();
[1fd2edb]1185}
1186
[156dc16]1187void MainFrm::ClearCoords()
1188{
[5901b62]1189    m_Coords->SetLabel("");
[156dc16]1190}
1191
1192void MainFrm::SetCoords(Double x, Double y)
1193{
[168df28]1194    wxString s;
[7a89dc2]1195    if (m_Gfx->m_Metric) {
[168df28]1196        s.Printf(msg(/*  %d E, %d N*/338), int(x), int(y));
[7a89dc2]1197    } else {
[168df28]1198        s.Printf(msg(/*  %d E, %d N*/338),
1199                 int(x / METRES_PER_FOOT), int(y / METRES_PER_FOOT));
[7a89dc2]1200    }
[168df28]1201    m_Coords->SetLabel(s);
[156dc16]1202}
1203
[7a89dc2]1204void MainFrm::SetAltitude(Double z)
[156dc16]1205{
[168df28]1206    wxString s;
[7a89dc2]1207    if (m_Gfx->m_Metric) {
[168df28]1208        s.Printf("  %s %dm", msg(/*Altitude*/335), int(z));
[7a89dc2]1209    } else {
[168df28]1210        s.Printf("  %s %dft", msg(/*Altitude*/335), int(z / METRES_PER_FOOT));
[7a89dc2]1211    }
[168df28]1212    m_Coords->SetLabel(s);
[7a89dc2]1213}
[421b7d2]1214
[8734409]1215void MainFrm::ShowInfo(const LabelInfo *label)
[7a89dc2]1216{
1217    assert(m_Gfx);
[246426e]1218
[7a89dc2]1219    wxString str;
1220    if (m_Gfx->m_Metric) {
[7d9e02b]1221        str.Printf(msg(/*  %d E, %d N*/338),
[168df28]1222                   int(label->x + m_Offsets.getX()),
1223                   int(label->y + m_Offsets.getY()));
[7a89dc2]1224    } else {
1225        str.Printf(msg(/*  %d E, %d N*/338),
[168df28]1226                   int((label->x + m_Offsets.getX()) / METRES_PER_FOOT),
1227                   int((label->y + m_Offsets.getY()) / METRES_PER_FOOT));
[7a89dc2]1228    }
1229    m_StnCoords->SetLabel(str);
1230    m_StnName->SetLabel(label->text);
1231
1232    if (m_Gfx->m_Metric) {
[421b7d2]1233        str.Printf("  %s %dm", msg(/*Altitude*/335),
[168df28]1234                   int(label->z + m_Offsets.getZ()));
[7a89dc2]1235    } else {
1236        str.Printf("  %s %dft", msg(/*Altitude*/335),
[168df28]1237                   int((label->z + m_Offsets.getZ()) / METRES_PER_FOOT));
[7a89dc2]1238    }
1239    m_StnAlt->SetLabel(str);
1240    m_Gfx->SetHere(label->x, label->y, label->z);
1241
1242    wxTreeItemData* sel_wx;
1243    bool sel = m_Tree->GetSelectionData(&sel_wx);
1244    if (sel) {
1245        TreeData *data = (TreeData*) sel_wx;
1246
1247        if (data->IsStation()) {
[8734409]1248            const LabelInfo* label2 = data->GetLabel();
[7a89dc2]1249            assert(label2);
1250
1251            Double x0 = label2->x;
1252            Double x1 = label->x;
1253            Double dx = x1 - x0;
1254            Double y0 = label2->y;
1255            Double y1 = label->y;
1256            Double dy = y1 - y0;
1257            Double z0 = label2->z;
1258            Double z1 = label->z;
1259            Double dz = z1 - z0;
1260
1261            Double d_horiz = sqrt(dx*dx + dy*dy);
1262            Double dr = sqrt(dx*dx + dy*dy + dz*dz);
1263
[168df28]1264            Double brg = deg(atan2(dx, dy));
[838fb1b]1265            if (brg < 0) brg += 360;
[421b7d2]1266
[7a89dc2]1267            str.Printf(msg(/*From %s*/339), label2->text.c_str());
1268            m_Dist1->SetLabel(str);
1269            if (m_Gfx->m_Metric) {
1270                str.Printf(msg(/*  H %d%s, V %d%s*/340),
1271                           int(d_horiz), "m",
1272                           int(dz), "m");
[421b7d2]1273            } else {
[7a89dc2]1274                str.Printf(msg(/*  H %d%s, V %d%s*/340),
[838fb1b]1275                           int(d_horiz / METRES_PER_FOOT), "ft",
1276                           int(dz / METRES_PER_FOOT), "ft");
[6d109e5]1277            }
[7a89dc2]1278            m_Dist2->SetLabel(str);
1279            wxString brg_unit;
1280            if (m_Gfx->m_Degrees) {
1281                brg_unit = msg(/*&deg;*/344);
1282            } else {
1283                brg *= 400.0 / 360.0;
1284                brg_unit = msg(/*grad*/345);
1285            }
1286            if (m_Gfx->m_Metric) {
[c40038a]1287                str.Printf(msg(/*  Dist %d%s, Brg %03d%s*/341),
[7a89dc2]1288                           int(dr), "m", int(brg), brg_unit.c_str());
1289            } else {
[c40038a]1290                str.Printf(msg(/*  Dist %d%s, Brg %03d%s*/341),
[7a89dc2]1291                           int(dr / METRES_PER_FOOT), "ft", int(brg),
1292                           brg_unit.c_str());
1293            }
1294            m_Dist3->SetLabel(str);
1295            m_Gfx->SetThere(x0, y0, z0);
1296        } else {
1297            m_Gfx->SetThere(); // FIXME: not in SetMouseOverStation version?
[421b7d2]1298        }
[156dc16]1299    }
[7a89dc2]1300}
1301
[8734409]1302void MainFrm::DisplayTreeInfo(const wxTreeItemData* item)
[7a89dc2]1303{
[8734409]1304    const TreeData* data = static_cast<const TreeData*>(item);
[168df28]1305    if (data && data->IsStation()) {
1306        const LabelInfo * l = data->GetLabel();
1307        ShowInfo(l);
1308        m_Gfx->SetHere(l->x, l->y, l->z);
1309    } else {
1310        m_StnName->SetLabel("");
1311        m_StnCoords->SetLabel("");
1312        m_StnAlt->SetLabel("");
1313        m_Gfx->SetHere();
1314        m_Dist1->SetLabel("");
1315        m_Dist2->SetLabel("");
1316        m_Dist3->SetLabel("");
1317        m_Gfx->SetHere();
[156dc16]1318    }
1319}
1320
1321void MainFrm::TreeItemSelected(wxTreeItemData* item)
1322{
1323    TreeData* data = (TreeData*) item;
[421b7d2]1324
[156dc16]1325    if (data && data->IsStation()) {
[8734409]1326        const LabelInfo* label = data->GetLabel();
[421b7d2]1327        m_Gfx->CentreOn(label->x, label->y, label->z);
[6009a17]1328        m_Gfx->SetThere(label->x, label->y, label->z);
1329    } else {
1330        m_Gfx->SetThere();
[156dc16]1331    }
1332
1333    m_Dist1->SetLabel("");
1334    m_Dist2->SetLabel("");
1335    m_Dist3->SetLabel("");
1336}
1337
[2dfd768]1338void MainFrm::OnFind(wxCommandEvent&)
[2a02de2]1339{
[e98af57]1340    wxBusyCursor hourglass;
[9d3d8cc]1341    // Find stations specified by a string or regular expression.
1342
[02a7912]1343    wxString pattern = m_FindBox->GetValue();
1344    int re_flags = wxRE_NOSUB;
[c8aff97]1345
1346    if (true /* case insensitive */) {
[02a7912]1347        re_flags |= wxRE_ICASE;
[c8aff97]1348    }
[4e0b0e9]1349
[246426e]1350    bool substring = true;
[c8aff97]1351    if (m_RegexpCheckBox->GetValue()) {
[02a7912]1352        re_flags |= wxRE_EXTENDED;
[c8aff97]1353    } else if (false /* simple glob-style */) {
[421b7d2]1354        wxString pat;
[02a7912]1355        for (size_t i = 0; i < pattern.size(); i++) {
1356           char ch = pattern[i];
[c8aff97]1357           // ^ only special at start; $ at end.  But this is simpler...
1358           switch (ch) {
1359            case '^': case '$': case '.': case '[': case '\\':
1360              pat += '\\';
1361              pat += ch;
1362              break;
1363            case '*':
1364              pat += ".*";
[246426e]1365              substring = false;
[c8aff97]1366              break;
1367            case '?':
1368              pat += '.';
[246426e]1369              substring = false;
[421b7d2]1370              break;
[c8aff97]1371            default:
1372              pat += ch;
1373           }
1374        }
[02a7912]1375        pattern = pat;
1376        re_flags |= wxRE_BASIC;
[0c76ad9]1377    } else {
[421b7d2]1378        wxString pat;
[02a7912]1379        for (size_t i = 0; i < pattern.size(); i++) {
1380           char ch = pattern[i];
[0c76ad9]1381           // ^ only special at start; $ at end.  But this is simpler...
1382           switch (ch) {
1383            case '^': case '$': case '*': case '.': case '[': case '\\':
1384              pat += '\\';
1385           }
1386           pat += ch;
1387        }
[02a7912]1388        pattern = pat;
1389        re_flags |= wxRE_BASIC;
[0c76ad9]1390    }
1391
[246426e]1392    if (!substring) {
[dc8d2eb]1393        // FIXME "0u" required to avoid compilation error with g++-3.0
[02a7912]1394        if (pattern.empty() || pattern[0u] != '^') pattern = '^' + pattern;
[246426e]1395        // FIXME: this fails to cope with "\$" at the end of pattern...
[c19a1ff]1396        if (pattern[pattern.size() - 1] != '$') pattern += '$';
[c8aff97]1397    }
[421b7d2]1398
[02a7912]1399    wxRegEx regex;
1400    if (!regex.Compile(pattern, re_flags)) {
1401        wxString m;
1402        m.Printf(msg(/*Invalid regular expression: %s*/404), pattern.c_str());
1403        wxGetApp().ReportError(m);
[0c76ad9]1404        return;
[2a02de2]1405    }
1406
1407    list<LabelInfo*>::iterator pos = m_Labels.begin();
1408
[0c76ad9]1409    int found = 0;
[2a02de2]1410    while (pos != m_Labels.end()) {
[421b7d2]1411        LabelInfo* label = *pos++;
1412
[02a7912]1413        if (regex.Matches(label->text)) {
[fa42426]1414            label->flags |= LFLAG_HIGHLIGHTED;
[0c76ad9]1415            found++;
[fa42426]1416        } else {
1417            label->flags &= ~LFLAG_HIGHLIGHTED;
[0c76ad9]1418        }
[2a02de2]1419    }
1420
[421b7d2]1421    m_Found->SetLabel(wxString::Format(msg(/*%d found*/331), found));
[3dee384]1422#ifdef _WIN32
[e5d0812]1423    m_Found->Refresh(); // FIXME
[3dee384]1424#endif
[fa42426]1425    // Re-sort so highlighted points get names in preference
[9f9c05e]1426    if (found) m_Labels.sort(LabelPlotCmp(separator));
[fa42426]1427    m_Gfx->ForceRefresh();
[9d3d8cc]1428
[421b7d2]1429#if 0
[9d3d8cc]1430    if (!found) {
[421b7d2]1431        wxGetApp().ReportError(msg(/*No matches were found.*/328));
[9d3d8cc]1432    }
[c8aff97]1433#endif
[3d3924d]1434
1435    m_Gfx->SetFocus();
[2a02de2]1436}
1437
[2dfd768]1438void MainFrm::OnHide(wxCommandEvent&)
[2a02de2]1439{
1440    // Hide any search result highlights.
[01faa28]1441    m_Found->SetLabel("");
[fa42426]1442    list<LabelInfo*>::iterator pos = m_Labels.begin();
1443    while (pos != m_Labels.end()) {
1444        LabelInfo* label = *pos++;
1445        label->flags &= ~LFLAG_HIGHLIGHTED;
1446    }
1447    m_Gfx->ForceRefresh();
[2a02de2]1448}
[39e460c9]1449
1450void MainFrm::SetMouseOverStation(LabelInfo* label)
1451{
[dfe4454c]1452    if (label) {
[7a89dc2]1453        ShowInfo(label);
1454    } else {
[421b7d2]1455        m_StnName->SetLabel("");
1456        m_StnCoords->SetLabel("");
1457        m_StnAlt->SetLabel("");
1458        m_Gfx->SetHere();
1459        m_Dist1->SetLabel("");
1460        m_Dist2->SetLabel("");
1461        m_Dist3->SetLabel("");
[39e460c9]1462    }
1463}
[9059368]1464
1465void MainFrm::OnViewSidePanel(wxCommandEvent&)
[b1de3e0]1466{
1467    ToggleSidePanel();
1468}
1469
1470void MainFrm::ToggleSidePanel()
[9059368]1471{
1472    // Toggle display of the side panel.
1473
1474    assert(m_Gfx);
1475
1476    if (m_Splitter->IsSplit()) {
[421b7d2]1477        m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
1478        m_Splitter->Unsplit(m_Panel);
[fa2cd10]1479    } else {
[421b7d2]1480        m_Panel->Show(true);
[b1de3e0]1481        m_Gfx->Show(true);
[421b7d2]1482        m_Splitter->SplitVertically(m_Panel, m_Gfx, m_SashPosition);
[9059368]1483    }
1484}
1485
1486void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui)
1487{
[f48d6949]1488    ui.Enable(!m_File.empty());
[9059368]1489    ui.Check(m_Splitter->IsSplit());
1490}
Note: See TracBrowser for help on using the repository browser.