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