Add support for errors with a range of columns
[survex.git] / src / mainfrm.cc
blobcce493bc24d3222f55b5eb1ea3f52ffdc0787b9a
1 //
2 // mainfrm.cc
3 //
4 // Main frame handling for Aven.
5 //
6 // Copyright (C) 2000-2002,2005,2006 Mark R. Shinwell
7 // Copyright (C) 2001-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016 Olly Betts
8 // Copyright (C) 2005 Martin Green
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
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.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #include "cavernlog.h"
30 #include "mainfrm.h"
31 #include "aven.h"
32 #include "aboutdlg.h"
34 #include "message.h"
35 #include "img_hosted.h"
36 #include "namecompare.h"
37 #include "printing.h"
38 #include "filename.h"
39 #include "useful.h"
41 #include <wx/confbase.h>
42 //#include <wx/filefn.h>
43 #include <wx/filename.h>
44 #include <wx/image.h>
45 #include <wx/imaglist.h>
46 #include <wx/process.h>
47 #include <wx/regex.h>
48 #ifdef USING_GENERIC_TOOLBAR
49 # include <wx/sysopt.h>
50 #endif
52 #include <cerrno>
53 #include <cstdlib>
54 #include <float.h>
55 #include <functional>
56 #include <map>
57 #include <stack>
58 #include <vector>
60 #ifdef __WXMSW__
61 #define TOOL(x) wxBitmap(wxT(#x), wxBITMAP_TYPE_PNG_RESOURCE)
62 #else
63 // XPM files declare the array as static, but we also want it to be const too.
64 // This avoids a compiler warning, and also means the data can go in a
65 // read-only page and be shared between processes.
66 #define static static const
67 #include "../lib/icons/aven.xpm"
68 #include "../lib/icons/log.xpm"
69 #include "../lib/icons/open.xpm"
70 #include "../lib/icons/open_pres.xpm"
71 #include "../lib/icons/rotation.xpm"
72 #include "../lib/icons/plan.xpm"
73 #include "../lib/icons/elevation.xpm"
74 #include "../lib/icons/defaults.xpm"
75 #include "../lib/icons/names.xpm"
76 #include "../lib/icons/crosses.xpm"
77 #include "../lib/icons/entrances.xpm"
78 #include "../lib/icons/fixed_pts.xpm"
79 #include "../lib/icons/exported_pts.xpm"
80 #include "../lib/icons/ug_legs.xpm"
81 #include "../lib/icons/surface_legs.xpm"
82 #include "../lib/icons/tubes.xpm"
83 #include "../lib/icons/solid_surface.xpm"
84 #include "../lib/icons/pres_frew.xpm"
85 #include "../lib/icons/pres_rew.xpm"
86 #include "../lib/icons/pres_go_back.xpm"
87 #include "../lib/icons/pres_pause.xpm"
88 #include "../lib/icons/pres_go.xpm"
89 #include "../lib/icons/pres_ff.xpm"
90 #include "../lib/icons/pres_fff.xpm"
91 #include "../lib/icons/pres_stop.xpm"
92 #include "../lib/icons/find.xpm"
93 #include "../lib/icons/hideresults.xpm"
94 #include "../lib/icons/survey_tree.xpm"
95 #include "../lib/icons/pres_tree.xpm"
96 #undef static
97 #define TOOL(x) wxBITMAP(x)
98 #endif
100 using namespace std;
102 const static int img2aven_tab[] = {
103 #include "img2aven.h"
106 inline int
107 img2aven(int flags)
109 flags &= (sizeof(img2aven_tab) / sizeof(img2aven_tab[0]) - 1);
110 return img2aven_tab[flags];
113 class AvenSplitterWindow : public wxSplitterWindow {
114 MainFrm *parent;
116 public:
117 explicit AvenSplitterWindow(MainFrm *parent_)
118 : wxSplitterWindow(parent_, -1, wxDefaultPosition, wxDefaultSize,
119 wxSP_3DSASH),
120 parent(parent_)
124 void OnSplitterDClick(wxSplitterEvent &) {
125 parent->ToggleSidePanel();
128 private:
129 DECLARE_EVENT_TABLE()
132 BEGIN_EVENT_TABLE(AvenSplitterWindow, wxSplitterWindow)
133 EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick)
134 END_EVENT_TABLE()
136 class EditMarkDlg : public wxDialog {
137 wxTextCtrl * easting, * northing, * altitude;
138 wxTextCtrl * angle, * tilt_angle, * scale, * time;
139 public:
140 // TRANSLATORS: Title of dialog to edit a waypoint in a presentation.
141 EditMarkDlg(wxWindow* parent, const PresentationMark & p)
142 : wxDialog(parent, 500, wmsg(/*Edit Waypoint*/404))
144 easting = new wxTextCtrl(this, 601, wxString::Format(wxT("%.3f"), p.GetX()));
145 northing = new wxTextCtrl(this, 602, wxString::Format(wxT("%.3f"), p.GetY()));
146 altitude = new wxTextCtrl(this, 603, wxString::Format(wxT("%.3f"), p.GetZ()));
147 angle = new wxTextCtrl(this, 604, wxString::Format(wxT("%.3f"), p.angle));
148 tilt_angle = new wxTextCtrl(this, 605, wxString::Format(wxT("%.3f"), p.tilt_angle));
149 scale = new wxTextCtrl(this, 606, wxString::Format(wxT("%.3f"), p.scale));
150 if (p.time > 0.0) {
151 time = new wxTextCtrl(this, 607, wxString::Format(wxT("%.3f"), p.time));
152 } else if (p.time < 0.0) {
153 time = new wxTextCtrl(this, 607, wxString::Format(wxT("*%.3f"), -p.time));
154 } else {
155 time = new wxTextCtrl(this, 607, wxT("0"));
158 wxBoxSizer * coords = new wxBoxSizer(wxHORIZONTAL);
159 coords->Add(new wxStaticText(this, 610, wxT("(")), 0, wxALIGN_CENTRE_VERTICAL);
160 coords->Add(easting, 1);
161 coords->Add(new wxStaticText(this, 611, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
162 coords->Add(northing, 1);
163 coords->Add(new wxStaticText(this, 612, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
164 coords->Add(altitude, 1);
165 coords->Add(new wxStaticText(this, 613, wxT(")")), 0, wxALIGN_CENTRE_VERTICAL);
166 wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL);
167 vert->Add(coords, 0, wxALL, 8);
168 wxBoxSizer * r2 = new wxBoxSizer(wxHORIZONTAL);
169 r2->Add(new wxStaticText(this, 614, wmsg(/*Bearing*/259) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
170 r2->Add(angle);
171 vert->Add(r2, 0, wxALL, 8);
172 wxBoxSizer * r3 = new wxBoxSizer(wxHORIZONTAL);
173 r3->Add(new wxStaticText(this, 615, wmsg(/*Elevation*/118) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
174 r3->Add(tilt_angle);
175 vert->Add(r3, 0, wxALL, 8);
176 wxBoxSizer * r4 = new wxBoxSizer(wxHORIZONTAL);
177 r4->Add(new wxStaticText(this, 616, wmsg(/*Scale*/154) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
178 r4->Add(scale);
179 /* TRANSLATORS: Note after "Scale" field in dialog to edit a waypoint
180 * in a presentation. */
181 r4->Add(new wxStaticText(this, 617, wmsg(/* (unused in perspective view)*/278)),
182 0, wxALIGN_CENTRE_VERTICAL);
183 vert->Add(r4, 0, wxALL, 8);
185 wxBoxSizer * r5 = new wxBoxSizer(wxHORIZONTAL);
186 /* TRANSLATORS: Field label in dialog to edit a waypoint in a
187 * presentation. */
188 r5->Add(new wxStaticText(this, 616, wmsg(/*Time: */279)), 0, wxALIGN_CENTRE_VERTICAL);
189 r5->Add(time);
190 /* TRANSLATORS: units+info after time field in dialog to edit a
191 * waypoint in a presentation. */
192 r5->Add(new wxStaticText(this, 617, wmsg(/* secs (0 = auto; *6 = 6 times auto)*/282)),
193 0, wxALIGN_CENTRE_VERTICAL);
194 vert->Add(r5, 0, wxALL, 8);
196 wxBoxSizer * buttons = new wxBoxSizer(wxHORIZONTAL);
197 wxButton* cancel = new wxButton(this, wxID_CANCEL);
198 buttons->Add(cancel, 0, wxALL, 8);
199 wxButton* ok = new wxButton(this, wxID_OK);
200 ok->SetDefault();
201 buttons->Add(ok, 0, wxALL, 8);
202 vert->Add(buttons, 0, wxALL|wxALIGN_RIGHT);
204 SetAutoLayout(true);
205 SetSizer(vert);
207 vert->SetSizeHints(this);
209 PresentationMark GetMark() const {
210 double a, t, s, T;
211 Vector3 v(wxAtof(easting->GetValue()),
212 wxAtof(northing->GetValue()),
213 wxAtof(altitude->GetValue()));
214 a = wxAtof(angle->GetValue());
215 t = wxAtof(tilt_angle->GetValue());
216 s = wxAtof(scale->GetValue());
217 wxString str = time->GetValue();
218 if (!str.empty() && str[0u] == '*') str[0u] = '-';
219 T = wxAtof(str);
220 return PresentationMark(v, a, t, s, T);
223 private:
224 DECLARE_EVENT_TABLE()
227 // Write a value without trailing zeros after the decimal point.
228 static void write_double(double d, FILE * fh) {
229 char buf[64];
230 sprintf(buf, "%.21f", d);
231 char * p = strchr(buf, ',');
232 if (p) *p = '.';
233 size_t l = strlen(buf);
234 while (l > 1 && buf[l - 1] == '0') --l;
235 if (l > 1 && buf[l - 1] == '.') --l;
236 fwrite(buf, l, 1, fh);
239 class AvenPresList : public wxListCtrl {
240 MainFrm * mainfrm;
241 GfxCore * gfx;
242 vector<PresentationMark> entries;
243 long current_item;
244 bool modified;
245 bool force_save_as;
246 wxString filename;
248 public:
249 AvenPresList(MainFrm * mainfrm_, wxWindow * parent, GfxCore * gfx_)
250 : wxListCtrl(parent, listctrl_PRES, wxDefaultPosition, wxDefaultSize,
251 wxLC_REPORT|wxLC_VIRTUAL),
252 mainfrm(mainfrm_), gfx(gfx_), current_item(-1), modified(false),
253 force_save_as(true)
255 InsertColumn(0, wmsg(/*Easting*/378));
256 InsertColumn(1, wmsg(/*Northing*/379));
257 InsertColumn(2, wmsg(/*Altitude*/335));
260 void OnBeginLabelEdit(wxListEvent& event) {
261 event.Veto(); // No editting allowed
263 void OnDeleteItem(wxListEvent& event) {
264 long item = event.GetIndex();
265 if (current_item == item) {
266 current_item = -1;
267 } else if (current_item > item) {
268 --current_item;
270 entries.erase(entries.begin() + item);
271 SetItemCount(entries.size());
272 modified = true;
274 void OnDeleteAllItems(wxListEvent&) {
275 entries.clear();
276 SetItemCount(entries.size());
277 filename = wxString();
278 modified = false;
279 force_save_as = true;
281 void OnListKeyDown(wxListEvent& event) {
282 switch (event.GetKeyCode()) {
283 case WXK_DELETE: {
284 long item = GetNextItem(-1, wxLIST_NEXT_ALL,
285 wxLIST_STATE_SELECTED);
286 while (item != -1) {
287 DeleteItem(item);
288 // - 1 because the indices were shifted by DeleteItem()
289 item = GetNextItem(item - 1, wxLIST_NEXT_ALL,
290 wxLIST_STATE_SELECTED);
292 break;
294 default:
295 //printf("event.GetIndex() = %ld %d\n", event.GetIndex(), event.GetKeyCode());
296 event.Skip();
299 void OnActivated(wxListEvent& event) {
300 // Jump to this view.
301 long item = event.GetIndex();
302 gfx->SetView(entries[item]);
304 void OnFocused(wxListEvent& event) {
305 current_item = event.GetIndex();
307 void OnRightClick(wxListEvent& event) {
308 long item = event.GetIndex();
309 if (item < 0) {
310 AddMark(item, gfx->GetView());
311 item = 0;
313 EditMarkDlg edit(mainfrm, entries[item]);
314 if (edit.ShowModal() == wxID_OK) {
315 entries[item] = edit.GetMark();
318 void OnChar(wxKeyEvent& event) {
319 switch (event.GetKeyCode()) {
320 case WXK_INSERT:
321 if (event.GetModifiers() == wxMOD_CONTROL) {
322 if (current_item != -1 &&
323 size_t(current_item) < entries.size()) {
324 AddMark(current_item, entries[current_item]);
326 } else {
327 AddMark(current_item);
329 break;
330 case WXK_DELETE:
331 // Already handled in OnListKeyDown.
332 break;
333 case WXK_UP: case WXK_DOWN:
334 event.Skip();
335 break;
336 default:
337 gfx->OnKeyPress(event);
340 void AddMark(long item = -1) {
341 AddMark(item, gfx->GetView());
343 void AddMark(long item, const PresentationMark & mark) {
344 if (item == -1) item = entries.size();
345 entries.insert(entries.begin() + item, mark);
346 SetItemCount(entries.size());
347 modified = true;
349 virtual wxString OnGetItemText(long item, long column) const {
350 if (item < 0 || item >= (long)entries.size()) return wxString();
351 const PresentationMark & p = entries[item];
352 double v;
353 switch (column) {
354 case 0: v = p.GetX(); break;
355 case 1: v = p.GetY(); break;
356 case 2: v = p.GetZ(); break;
357 #if 0
358 case 3: v = p.angle; break;
359 case 4: v = p.tilt_angle; break;
360 case 5: v = p.scale; break;
361 case 6: v = p.time; break;
362 #endif
363 default: return wxString();
365 return wxString::Format(wxT("%ld"), (long)v);
367 void Save(bool use_default_name) {
368 wxString fnm = filename;
369 if (!use_default_name || force_save_as) {
370 AvenAllowOnTop ontop(mainfrm);
371 #ifdef __WXMOTIF__
372 wxString ext(wxT("*.fly"));
373 #else
374 wxString ext = wmsg(/*Aven presentations*/320);
375 ext += wxT("|*.fly");
376 #endif
377 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
378 wxString(), fnm, ext,
379 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
380 if (dlg.ShowModal() != wxID_OK) return;
381 fnm = dlg.GetPath();
384 FILE * fh_pres = wxFopen(fnm, wxT("w"));
385 if (!fh_pres) {
386 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm.c_str()));
387 return;
389 vector<PresentationMark>::const_iterator i;
390 for (i = entries.begin(); i != entries.end(); ++i) {
391 const PresentationMark &p = *i;
392 write_double(p.GetX(), fh_pres);
393 PUTC(' ', fh_pres);
394 write_double(p.GetY(), fh_pres);
395 PUTC(' ', fh_pres);
396 write_double(p.GetZ(), fh_pres);
397 PUTC(' ', fh_pres);
398 write_double(p.angle, fh_pres);
399 PUTC(' ', fh_pres);
400 write_double(p.tilt_angle, fh_pres);
401 PUTC(' ', fh_pres);
402 write_double(p.scale, fh_pres);
403 if (p.time != 0.0) {
404 PUTC(' ', fh_pres);
405 write_double(p.time, fh_pres);
407 PUTC('\n', fh_pres);
409 fclose(fh_pres);
410 filename = fnm;
411 modified = false;
412 force_save_as = false;
414 void New(const wxString &fnm) {
415 DeleteAllItems();
416 wxFileName::SplitPath(fnm, NULL, NULL, &filename, NULL, wxPATH_NATIVE);
417 filename += wxT(".fly");
418 force_save_as = true;
420 bool Load(const wxString &fnm) {
421 FILE * fh_pres = wxFopen(fnm, wxT("r"));
422 if (!fh_pres) {
423 wxString m;
424 m.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm.c_str());
425 wxGetApp().ReportError(m);
426 return false;
428 DeleteAllItems();
429 long item = 0;
430 while (!feof(fh_pres)) {
431 char buf[4096];
432 size_t i = 0;
433 while (i < sizeof(buf) - 1) {
434 int ch = GETC(fh_pres);
435 if (ch == EOF || ch == '\n' || ch == '\r') break;
436 buf[i++] = ch;
438 if (i) {
439 buf[i] = 0;
440 double x, y, z, a, t, s, T;
441 int c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
442 if (c < 6) {
443 char *p = buf;
444 while ((p = strchr(p, '.'))) *p++ = ',';
445 c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
446 if (c < 6) {
447 DeleteAllItems();
448 wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm.c_str()));
449 return false;
452 if (c == 6) T = 0;
453 AddMark(item, PresentationMark(Vector3(x, y, z), a, t, s, T));
454 ++item;
457 fclose(fh_pres);
458 filename = fnm;
459 modified = false;
460 force_save_as = false;
461 return true;
463 bool Modified() const { return modified; }
464 bool Empty() const { return entries.empty(); }
465 PresentationMark GetPresMark(int which) {
466 long item = current_item;
467 if (which == MARK_FIRST) {
468 item = 0;
469 } else if (which == MARK_NEXT) {
470 ++item;
471 } else if (which == MARK_PREV) {
472 --item;
474 if (item == -1 || item == (long)entries.size())
475 return PresentationMark();
476 if (item != current_item) {
477 // Move the focus
478 if (current_item != -1) {
479 wxListCtrl::SetItemState(current_item, wxLIST_STATE_FOCUSED,
482 wxListCtrl::SetItemState(item, wxLIST_STATE_FOCUSED,
483 wxLIST_STATE_FOCUSED);
485 return entries[item];
488 private:
490 DECLARE_NO_COPY_CLASS(AvenPresList)
491 DECLARE_EVENT_TABLE()
494 BEGIN_EVENT_TABLE(EditMarkDlg, wxDialog)
495 END_EVENT_TABLE()
497 BEGIN_EVENT_TABLE(AvenPresList, wxListCtrl)
498 EVT_LIST_BEGIN_LABEL_EDIT(listctrl_PRES, AvenPresList::OnBeginLabelEdit)
499 EVT_LIST_DELETE_ITEM(listctrl_PRES, AvenPresList::OnDeleteItem)
500 EVT_LIST_DELETE_ALL_ITEMS(listctrl_PRES, AvenPresList::OnDeleteAllItems)
501 EVT_LIST_KEY_DOWN(listctrl_PRES, AvenPresList::OnListKeyDown)
502 EVT_LIST_ITEM_ACTIVATED(listctrl_PRES, AvenPresList::OnActivated)
503 EVT_LIST_ITEM_FOCUSED(listctrl_PRES, AvenPresList::OnFocused)
504 EVT_LIST_ITEM_RIGHT_CLICK(listctrl_PRES, AvenPresList::OnRightClick)
505 EVT_CHAR(AvenPresList::OnChar)
506 END_EVENT_TABLE()
508 BEGIN_EVENT_TABLE(MainFrm, wxFrame)
509 EVT_TEXT(textctrl_FIND, MainFrm::OnFind)
510 EVT_TEXT_ENTER(textctrl_FIND, MainFrm::OnGotoFound)
511 EVT_MENU(wxID_FIND, MainFrm::OnGotoFound)
512 EVT_MENU(button_HIDE, MainFrm::OnHide)
513 EVT_UPDATE_UI(button_HIDE, MainFrm::OnHideUpdate)
514 EVT_IDLE(MainFrm::OnIdle)
516 EVT_MENU(wxID_OPEN, MainFrm::OnOpen)
517 EVT_MENU(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrain)
518 EVT_MENU(menu_FILE_LOG, MainFrm::OnShowLog)
519 EVT_MENU(wxID_PRINT, MainFrm::OnPrint)
520 EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup)
521 EVT_MENU(menu_FILE_SCREENSHOT, MainFrm::OnScreenshot)
522 // EVT_MENU(wxID_PREFERENCES, MainFrm::OnFilePreferences)
523 EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport)
524 EVT_MENU(menu_FILE_EXTEND, MainFrm::OnExtend)
525 EVT_MENU(wxID_EXIT, MainFrm::OnQuit)
526 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile)
528 EVT_MENU(menu_PRES_NEW, MainFrm::OnPresNew)
529 EVT_MENU(menu_PRES_OPEN, MainFrm::OnPresOpen)
530 EVT_MENU(menu_PRES_SAVE, MainFrm::OnPresSave)
531 EVT_MENU(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAs)
532 EVT_MENU(menu_PRES_MARK, MainFrm::OnPresMark)
533 EVT_MENU(menu_PRES_FREWIND, MainFrm::OnPresFRewind)
534 EVT_MENU(menu_PRES_REWIND, MainFrm::OnPresRewind)
535 EVT_MENU(menu_PRES_REVERSE, MainFrm::OnPresReverse)
536 EVT_MENU(menu_PRES_PLAY, MainFrm::OnPresPlay)
537 EVT_MENU(menu_PRES_FF, MainFrm::OnPresFF)
538 EVT_MENU(menu_PRES_FFF, MainFrm::OnPresFFF)
539 EVT_MENU(menu_PRES_PAUSE, MainFrm::OnPresPause)
540 EVT_MENU(wxID_STOP, MainFrm::OnPresStop)
541 EVT_MENU(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovie)
543 EVT_UPDATE_UI(menu_PRES_NEW, MainFrm::OnPresNewUpdate)
544 EVT_UPDATE_UI(menu_PRES_OPEN, MainFrm::OnPresOpenUpdate)
545 EVT_UPDATE_UI(menu_PRES_SAVE, MainFrm::OnPresSaveUpdate)
546 EVT_UPDATE_UI(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAsUpdate)
547 EVT_UPDATE_UI(menu_PRES_MARK, MainFrm::OnPresMarkUpdate)
548 EVT_UPDATE_UI(menu_PRES_FREWIND, MainFrm::OnPresFRewindUpdate)
549 EVT_UPDATE_UI(menu_PRES_REWIND, MainFrm::OnPresRewindUpdate)
550 EVT_UPDATE_UI(menu_PRES_REVERSE, MainFrm::OnPresReverseUpdate)
551 EVT_UPDATE_UI(menu_PRES_PLAY, MainFrm::OnPresPlayUpdate)
552 EVT_UPDATE_UI(menu_PRES_FF, MainFrm::OnPresFFUpdate)
553 EVT_UPDATE_UI(menu_PRES_FFF, MainFrm::OnPresFFFUpdate)
554 EVT_UPDATE_UI(menu_PRES_PAUSE, MainFrm::OnPresPauseUpdate)
555 EVT_UPDATE_UI(wxID_STOP, MainFrm::OnPresStopUpdate)
556 EVT_UPDATE_UI(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovieUpdate)
558 EVT_CLOSE(MainFrm::OnClose)
559 EVT_SET_FOCUS(MainFrm::OnSetFocus)
561 EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation)
562 EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation)
563 EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth)
564 EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast)
565 EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth)
566 EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest)
567 EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan)
568 EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation)
569 EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults)
570 EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs)
571 EVT_MENU(menu_SPLAYS_HIDE, MainFrm::OnHideSplays)
572 EVT_MENU(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormal)
573 EVT_MENU(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFaded)
574 EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses)
575 EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances)
576 EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts)
577 EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts)
578 EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames)
579 EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames)
580 EVT_MENU(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepth)
581 EVT_MENU(menu_COLOUR_BY_DATE, MainFrm::OnColourByDate)
582 EVT_MENU(menu_COLOUR_BY_ERROR, MainFrm::OnColourByError)
583 EVT_MENU(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradient)
584 EVT_MENU(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLength)
585 EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
586 EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
587 EVT_MENU(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBox)
588 EVT_MENU(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspective)
589 EVT_MENU(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShading)
590 EVT_MENU(menu_VIEW_TEXTURED, MainFrm::OnViewTextured)
591 EVT_MENU(menu_VIEW_FOG, MainFrm::OnViewFog)
592 EVT_MENU(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLines)
593 EVT_MENU(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreen)
594 EVT_MENU(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubes)
595 EVT_MENU(menu_VIEW_TERRAIN, MainFrm::OnViewTerrain)
596 EVT_MENU(menu_IND_COMPASS, MainFrm::OnViewCompass)
597 EVT_MENU(menu_IND_CLINO, MainFrm::OnViewClino)
598 EVT_MENU(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKey)
599 EVT_MENU(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebar)
600 EVT_MENU(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanel)
601 EVT_MENU(menu_CTL_METRIC, MainFrm::OnToggleMetric)
602 EVT_MENU(menu_CTL_DEGREES, MainFrm::OnToggleDegrees)
603 EVT_MENU(menu_CTL_PERCENT, MainFrm::OnTogglePercent)
604 EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls)
605 EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine)
606 EVT_MENU(wxID_ABOUT, MainFrm::OnAbout)
608 EVT_UPDATE_UI(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrainUpdate)
609 EVT_UPDATE_UI(menu_FILE_LOG, MainFrm::OnShowLogUpdate)
610 EVT_UPDATE_UI(wxID_PRINT, MainFrm::OnPrintUpdate)
611 EVT_UPDATE_UI(menu_FILE_SCREENSHOT, MainFrm::OnScreenshotUpdate)
612 EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate)
613 EVT_UPDATE_UI(menu_FILE_EXTEND, MainFrm::OnExtendUpdate)
614 EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate)
615 EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate)
616 EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate)
617 EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate)
618 EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate)
619 EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate)
620 EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate)
621 EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate)
622 EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate)
623 EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate)
624 EVT_UPDATE_UI(menu_VIEW_SPLAYS, MainFrm::OnSplaysUpdate)
625 EVT_UPDATE_UI(menu_SPLAYS_HIDE, MainFrm::OnHideSplaysUpdate)
626 EVT_UPDATE_UI(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormalUpdate)
627 EVT_UPDATE_UI(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFadedUpdate)
628 EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate)
629 EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate)
630 EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate)
631 EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate)
632 EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate)
633 EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate)
634 EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate)
635 EVT_UPDATE_UI(menu_VIEW_COLOUR_BY, MainFrm::OnColourByUpdate)
636 EVT_UPDATE_UI(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepthUpdate)
637 EVT_UPDATE_UI(menu_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
638 EVT_UPDATE_UI(menu_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
639 EVT_UPDATE_UI(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradientUpdate)
640 EVT_UPDATE_UI(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate)
641 EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
642 EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate)
643 EVT_UPDATE_UI(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspectiveUpdate)
644 EVT_UPDATE_UI(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShadingUpdate)
645 EVT_UPDATE_UI(menu_VIEW_TEXTURED, MainFrm::OnViewTexturedUpdate)
646 EVT_UPDATE_UI(menu_VIEW_FOG, MainFrm::OnViewFogUpdate)
647 EVT_UPDATE_UI(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLinesUpdate)
648 EVT_UPDATE_UI(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreenUpdate)
649 EVT_UPDATE_UI(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubesUpdate)
650 EVT_UPDATE_UI(menu_VIEW_TERRAIN, MainFrm::OnViewTerrainUpdate)
651 EVT_UPDATE_UI(menu_IND_COMPASS, MainFrm::OnViewCompassUpdate)
652 EVT_UPDATE_UI(menu_IND_CLINO, MainFrm::OnViewClinoUpdate)
653 EVT_UPDATE_UI(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKeyUpdate)
654 EVT_UPDATE_UI(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebarUpdate)
655 EVT_UPDATE_UI(menu_CTL_INDICATORS, MainFrm::OnIndicatorsUpdate)
656 EVT_UPDATE_UI(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate)
657 EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate)
658 EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate)
659 EVT_UPDATE_UI(menu_CTL_METRIC, MainFrm::OnToggleMetricUpdate)
660 EVT_UPDATE_UI(menu_CTL_DEGREES, MainFrm::OnToggleDegreesUpdate)
661 EVT_UPDATE_UI(menu_CTL_PERCENT, MainFrm::OnTogglePercentUpdate)
662 END_EVENT_TABLE()
664 class LabelCmp : public greater<const LabelInfo*> {
665 wxChar separator;
666 public:
667 explicit LabelCmp(wxChar separator_) : separator(separator_) {}
668 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
669 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
673 class LabelPlotCmp : public greater<const LabelInfo*> {
674 wxChar separator;
675 public:
676 explicit LabelPlotCmp(wxChar separator_) : separator(separator_) {}
677 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
678 int n = pt1->get_flags() - pt2->get_flags();
679 if (n) return n > 0;
680 wxString l1 = pt1->GetText().AfterLast(separator);
681 wxString l2 = pt2->GetText().AfterLast(separator);
682 n = name_cmp(l1, l2, separator);
683 if (n) return n < 0;
684 // Prefer non-2-nodes...
685 // FIXME; implement
686 // if leaf names are the same, prefer shorter labels as we can
687 // display more of them
688 n = pt1->GetText().length() - pt2->GetText().length();
689 if (n) return n < 0;
690 // make sure that we don't ever compare different labels as equal
691 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
695 #if wxUSE_DRAG_AND_DROP
696 class DnDFile : public wxFileDropTarget {
697 public:
698 explicit DnDFile(MainFrm *parent) : m_Parent(parent) { }
699 virtual bool OnDropFiles(wxCoord, wxCoord,
700 const wxArrayString &filenames);
702 private:
703 MainFrm * m_Parent;
706 bool
707 DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
709 // Load a survey file by drag-and-drop.
710 assert(filenames.GetCount() > 0);
712 if (filenames.GetCount() != 1) {
713 /* TRANSLATORS: error if you try to drag multiple files to the aven
714 * window */
715 wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336));
716 return false;
719 m_Parent->OpenFile(filenames[0]);
720 return true;
722 #endif
724 MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) :
725 wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE),
726 m_SashPosition(-1),
727 m_Gfx(NULL), m_Log(NULL),
728 m_NumEntrances(0), m_NumFixedPts(0), m_NumExportedPts(0),
729 m_NumHighlighted(0),
730 m_HasUndergroundLegs(false), m_HasSplays(false), m_HasSurfaceLegs(false),
731 m_HasErrorInformation(false), m_IsExtendedElevation(false),
732 pending_find(false), fullscreen_showing_menus(false)
733 #ifdef PREFDLG
734 , m_PrefsDlg(NULL)
735 #endif
737 #ifdef _WIN32
738 // The peculiar name is so that the icon is the first in the file
739 // (required by Microsoft Windows for this type of icon)
740 SetIcon(wxICON(AAA_aven));
741 #else
742 SetIcon(wxICON(aven));
743 #endif
745 #if wxCHECK_VERSION(3,1,0)
746 // Add a full screen button to the right upper corner of title bar under OS
747 // X 10.7 and later.
748 EnableFullScreenView();
749 #endif
750 CreateMenuBar();
751 MakeToolBar();
752 CreateStatusBar(2, wxST_SIZEGRIP);
753 CreateSidePanel();
755 int widths[2] = { -1 /* variable width */, -1 };
756 GetStatusBar()->SetStatusWidths(2, widths);
758 #ifdef __X__ // wxMotif or wxX11
759 int x;
760 int y;
761 GetSize(&x, &y);
762 // X seems to require a forced resize.
763 SetSize(-1, -1, x, y);
764 #endif
766 #if wxUSE_DRAG_AND_DROP
767 SetDropTarget(new DnDFile(this));
768 #endif
771 void MainFrm::CreateMenuBar()
773 // Create the menus and the menu bar.
775 wxMenu* filemenu = new wxMenu;
776 // wxID_OPEN stock label lacks the ellipses
777 /* TRANSLATORS: Aven menu items. An “&” goes before the letter of any
778 * accelerator key.
780 * The string "\t" separates the menu text and any accelerator key.
782 * "File" menu. The accelerators must be different within this group.
783 * c.f. 201, 380, 381. */
784 filemenu->Append(wxID_OPEN, wmsg(/*&Open...\tCtrl+O*/220));
785 /* TRANSLATORS: Open a "Terrain file" - i.e. a digital model of the
786 * terrain. */
787 filemenu->Append(menu_FILE_OPEN_TERRAIN, wmsg(/*Open &Terrain...*/453));
788 filemenu->AppendCheckItem(menu_FILE_LOG, wmsg(/*Show &Log*/144));
789 filemenu->AppendSeparator();
790 // wxID_PRINT stock label lacks the ellipses
791 filemenu->Append(wxID_PRINT, wmsg(/*&Print...\tCtrl+P*/380));
792 filemenu->Append(menu_FILE_PAGE_SETUP, wmsg(/*P&age Setup...*/381));
793 filemenu->AppendSeparator();
794 /* TRANSLATORS: In the "File" menu */
795 filemenu->Append(menu_FILE_SCREENSHOT, wmsg(/*&Screenshot...*/201));
796 filemenu->Append(menu_FILE_EXPORT, wmsg(/*&Export as...*/382));
797 /* TRANSLATORS: In the "File" menu - c.f. n:191 */
798 filemenu->Append(menu_FILE_EXTEND, wmsg(/*E&xtended Elevation...*/247));
799 #ifndef __WXMAC__
800 // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress
801 // this separator.
802 filemenu->AppendSeparator();
803 #else
804 // We suppress the "Help" menu under OS X as it would otherwise end up as
805 // an empty menu, but we need to add the "About" menu item somewhere. It
806 // really doesn't matter where as wxWidgets will move it to the "Apple"
807 // menu.
808 filemenu->Append(wxID_ABOUT);
809 #endif
810 filemenu->Append(wxID_EXIT);
812 m_history.UseMenu(filemenu);
813 m_history.Load(*wxConfigBase::Get());
815 wxMenu* rotmenu = new wxMenu;
816 /* TRANSLATORS: "Rotation" menu. The accelerators must be different within
817 * this group. Tickable menu item which toggles auto rotation */
818 rotmenu->AppendCheckItem(menu_ROTATION_TOGGLE, wmsg(/*Au&to-Rotate\tSpace*/231));
819 rotmenu->AppendSeparator();
820 rotmenu->Append(menu_ROTATION_REVERSE, wmsg(/*&Reverse Direction*/234));
822 wxMenu* orientmenu = new wxMenu;
823 orientmenu->Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240));
824 orientmenu->Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241));
825 orientmenu->Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242));
826 orientmenu->Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243));
827 orientmenu->AppendSeparator();
828 orientmenu->Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248));
829 orientmenu->Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249));
830 orientmenu->AppendSeparator();
831 orientmenu->Append(menu_ORIENT_DEFAULTS, wmsg(/*Restore De&fault View*/254));
833 wxMenu* presmenu = new wxMenu;
834 presmenu->Append(menu_PRES_NEW, wmsg(/*&New Presentation*/311));
835 presmenu->Append(menu_PRES_OPEN, wmsg(/*&Open Presentation...*/312));
836 presmenu->Append(menu_PRES_SAVE, wmsg(/*&Save Presentation*/313));
837 presmenu->Append(menu_PRES_SAVE_AS, wmsg(/*Sa&ve Presentation As...*/314));
838 presmenu->AppendSeparator();
839 /* TRANSLATORS: "Mark" as in "Mark this position" */
840 presmenu->Append(menu_PRES_MARK, wmsg(/*&Mark*/315));
841 /* TRANSLATORS: "Play" as in "Play back a recording" */
842 presmenu->AppendCheckItem(menu_PRES_PLAY, wmsg(/*Pla&y*/316));
843 presmenu->Append(menu_PRES_EXPORT_MOVIE, wmsg(/*&Export as Movie...*/317));
845 wxMenu* viewmenu = new wxMenu;
846 #ifndef PREFDLG
847 /* TRANSLATORS: Items in the "View" menu: */
848 viewmenu->AppendCheckItem(menu_VIEW_SHOW_NAMES, wmsg(/*Station &Names\tCtrl+N*/270));
849 /* TRANSLATORS: Toggles drawing of 3D passages */
850 viewmenu->AppendCheckItem(menu_VIEW_SHOW_TUBES, wmsg(/*Passage &Tubes\tCtrl+T*/346));
851 /* TRANSLATORS: Toggles drawing the surface of the Earth */
852 viewmenu->AppendCheckItem(menu_VIEW_TERRAIN, wmsg(/*Terr&ain*/449));
853 viewmenu->AppendCheckItem(menu_VIEW_SHOW_CROSSES, wmsg(/*&Crosses\tCtrl+X*/271));
854 viewmenu->AppendCheckItem(menu_VIEW_GRID, wmsg(/*&Grid\tCtrl+G*/297));
855 viewmenu->AppendCheckItem(menu_VIEW_BOUNDING_BOX, wmsg(/*&Bounding Box\tCtrl+B*/318));
856 viewmenu->AppendSeparator();
857 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
858 * "survey stations". */
859 viewmenu->AppendCheckItem(menu_VIEW_SHOW_LEGS, wmsg(/*&Underground Survey Legs\tCtrl+L*/272));
860 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
861 * "survey stations". */
862 viewmenu->AppendCheckItem(menu_VIEW_SHOW_SURFACE, wmsg(/*&Surface Survey Legs\tCtrl+F*/291));
864 wxMenu* splaymenu = new wxMenu;
865 /* TRANSLATORS: Item in the "Splay Legs" submenu - if this is selected,
866 * splay legs are not shown. */
867 splaymenu->AppendCheckItem(menu_SPLAYS_HIDE, wmsg(/*&Hide*/407));
868 /* TRANSLATORS: Item in the "Splay Legs" submenu - if this is selected,
869 * aven will show splay legs with less bright colours (rather than the
870 * same as other legs "Show" or not shown "Hide"). */
871 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_FADED, wmsg(/*&Fade*/408));
872 /* TRANSLATORS: Item in the "Splay Legs" submenu - if this is selected,
873 * splay legs are shown the same as other legs. */
874 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_NORMAL, wmsg(/*&Show*/409));
875 viewmenu->Append(menu_VIEW_SPLAYS, wmsg(/*Spla&y Legs*/406), splaymenu);
877 viewmenu->AppendSeparator();
878 viewmenu->AppendCheckItem(menu_VIEW_SHOW_OVERLAPPING_NAMES, wmsg(/*&Overlapping Names*/273));
880 wxMenu* colourbymenu = new wxMenu;
881 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292));
882 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
883 colourbymenu->AppendCheckItem(menu_COLOUR_BY_ERROR, wmsg(/*Colour by &Error*/289));
884 colourbymenu->AppendCheckItem(menu_COLOUR_BY_GRADIENT, wmsg(/*Colour by &Gradient*/85));
885 colourbymenu->AppendCheckItem(menu_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
887 viewmenu->Append(menu_VIEW_COLOUR_BY, wmsg(/*Co&lour by*/450), colourbymenu);
889 viewmenu->AppendSeparator();
890 viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294));
891 viewmenu->AppendCheckItem(menu_VIEW_SHOW_FIXED_PTS, wmsg(/*Highlight &Fixed Points*/295));
892 viewmenu->AppendCheckItem(menu_VIEW_SHOW_EXPORTED_PTS, wmsg(/*Highlight E&xported Points*/296));
893 viewmenu->AppendSeparator();
894 #else
895 viewmenu-> Append(menu_VIEW_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
896 #endif
897 viewmenu->AppendCheckItem(menu_VIEW_PERSPECTIVE, wmsg(/*&Perspective*/237));
898 // FIXME: enable this viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_SHADING, wmsg(/*&Smooth Shading*/?!?);
899 viewmenu->AppendCheckItem(menu_VIEW_TEXTURED, wmsg(/*Textured &Walls*/238));
900 /* TRANSLATORS: Toggles OpenGL "Depth Fogging" - feel free to translate
901 * using that term instead if it gives a better translation which most
902 * users will understand. */
903 viewmenu->AppendCheckItem(menu_VIEW_FOG, wmsg(/*Fade Distant Ob&jects*/239));
904 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
905 * "survey stations". */
906 viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_LINES, wmsg(/*Smoot&hed Survey Legs*/298));
907 viewmenu->AppendSeparator();
908 #ifdef __WXMAC__
909 // F11 on OS X is used by the desktop (for speaker volume and/or window
910 // navigation). The standard OS X shortcut for full screen mode is
911 // Ctrl-Command-F which in wxWidgets terms is RawCtrl+Ctrl+F.
912 wxString wxmac_fullscreen = wmsg(/*Full Screen &Mode\tF11*/356);
913 wxmac_fullscreen.Replace(wxT("\tF11"), wxT("\tRawCtrl+Ctrl+F"), false);
914 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wxmac_fullscreen);
915 // FIXME: On OS X, the standard wording here is "Enter Full Screen" and
916 // "Exit Full Screen", depending whether we are in full screen mode or not,
917 // and this isn't a checked menu item.
918 #else
919 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wmsg(/*Full Screen &Mode\tF11*/356));
920 #endif
921 #ifdef PREFDLG
922 viewmenu->AppendSeparator();
923 viewmenu-> Append(wxID_PREFERENCES, wmsg(/*&Preferences...*/347));
924 #endif
926 #ifndef PREFDLG
927 wxMenu* ctlmenu = new wxMenu;
928 ctlmenu->AppendCheckItem(menu_CTL_REVERSE, wmsg(/*&Reverse Sense\tCtrl+R*/280));
929 ctlmenu->AppendSeparator();
930 #ifdef __WXGTK__
931 // wxGTK (at least with GTK+ v2.24), if we specify a short-cut here then
932 // the key handler isn't called, so we can't exit full screen mode on
933 // Escape. wxGTK doesn't actually show the "Escape" shortcut text in the
934 // menu item, so removing it doesn't make any visual difference, and doing
935 // so allows Escape to still cancel the measuring line, but also serve to
936 // exit full screen mode if no measuring line is shown.
937 wxString wxgtk_cancelline = wmsg(/*&Cancel Measuring Line\tEscape*/281);
938 wxgtk_cancelline.Replace(wxT("\tEscape"), wxT(""), false);
939 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wxgtk_cancelline);
940 #else
941 // With wxMac and wxMSW, we can have the short-cut on the menu and still
942 // have Escape handled by the key handler to exit full screen mode.
943 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
944 #endif
945 ctlmenu->AppendSeparator();
946 wxMenu* indmenu = new wxMenu;
947 indmenu->AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Compass*/274));
948 indmenu->AppendCheckItem(menu_IND_CLINO, wmsg(/*C&linometer*/275));
949 /* TRANSLATORS: The "Colour Key" is the thing in aven showing which colour
950 * corresponds to which depth, date, survey closure error, etc. */
951 indmenu->AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*Colour &Key*/276));
952 indmenu->AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Scale Bar*/277));
953 ctlmenu->Append(menu_CTL_INDICATORS, wmsg(/*&Indicators*/299), indmenu);
954 ctlmenu->AppendCheckItem(menu_CTL_SIDE_PANEL, wmsg(/*&Side Panel*/337));
955 ctlmenu->AppendSeparator();
956 ctlmenu->AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342));
957 ctlmenu->AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343));
958 ctlmenu->AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430));
959 #endif
961 wxMenuBar* menubar = new wxMenuBar();
962 /* TRANSLATORS: Aven menu titles. An “&” goes before the letter of any
963 * accelerator key. The accelerators must be different within this group
965 menubar->Append(filemenu, wmsg(/*&File*/210));
966 menubar->Append(rotmenu, wmsg(/*&Rotation*/211));
967 menubar->Append(orientmenu, wmsg(/*&Orientation*/212));
968 menubar->Append(viewmenu, wmsg(/*&View*/213));
969 #ifndef PREFDLG
970 menubar->Append(ctlmenu, wmsg(/*&Controls*/214));
971 #endif
972 // TRANSLATORS: "Presentation" in the sense of a talk with a slideshow -
973 // the items in this menu allow the user to animate between preset
974 // views.
975 menubar->Append(presmenu, wmsg(/*&Presentation*/216));
976 #ifndef __WXMAC__
977 // On wxMac the "About" menu item will be moved elsewhere, so we suppress
978 // this menu since it will then be empty.
979 wxMenu* helpmenu = new wxMenu;
980 helpmenu->Append(wxID_ABOUT);
982 menubar->Append(helpmenu, wmsg(/*&Help*/215));
983 #endif
984 SetMenuBar(menubar);
987 void MainFrm::MakeToolBar()
989 // Make the toolbar.
991 #ifdef USING_GENERIC_TOOLBAR
992 // This OS-X-specific code is only needed to stop the toolbar icons getting
993 // scaled up, which just makes them look nasty and fuzzy. Once we have
994 // larger versions of the icons, we can drop this code.
995 wxSystemOptions::SetOption(wxT("mac.toolbar.no-native"), 1);
996 wxToolBar* toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
997 wxDefaultSize, wxNO_BORDER|wxTB_FLAT|wxTB_NODIVIDER|wxTB_NOALIGN);
998 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
999 sizer->Add(toolbar, 0, wxEXPAND);
1000 SetSizer(sizer);
1001 #else
1002 wxToolBar* toolbar = wxFrame::CreateToolBar();
1003 #endif
1005 #ifndef __WXGTK20__
1006 toolbar->SetMargins(5, 5);
1007 #endif
1009 // FIXME: TRANSLATE tooltips
1010 toolbar->AddTool(wxID_OPEN, wxT("Open"), TOOL(open), wxT("Open a survey file for viewing"));
1011 toolbar->AddTool(menu_PRES_OPEN, wxT("Open presentation"), TOOL(open_pres), wxT("Open a presentation"));
1012 toolbar->AddCheckTool(menu_FILE_LOG, wxT("View log"), TOOL(log), wxNullBitmap, wxT("View log from processing survey data"));
1013 toolbar->AddSeparator();
1014 toolbar->AddCheckTool(menu_ROTATION_TOGGLE, wxT("Toggle rotation"), TOOL(rotation), wxNullBitmap, wxT("Toggle rotation"));
1015 toolbar->AddTool(menu_ORIENT_PLAN, wxT("Plan"), TOOL(plan), wxT("Switch to plan view"));
1016 toolbar->AddTool(menu_ORIENT_ELEVATION, wxT("Elevation"), TOOL(elevation), wxT("Switch to elevation view"));
1017 toolbar->AddTool(menu_ORIENT_DEFAULTS, wxT("Default view"), TOOL(defaults), wxT("Restore default view"));
1018 toolbar->AddSeparator();
1019 toolbar->AddCheckTool(menu_VIEW_SHOW_NAMES, wxT("Names"), TOOL(names), wxNullBitmap, wxT("Show station names"));
1020 toolbar->AddCheckTool(menu_VIEW_SHOW_CROSSES, wxT("Crosses"), TOOL(crosses), wxNullBitmap, wxT("Show crosses on stations"));
1021 toolbar->AddCheckTool(menu_VIEW_SHOW_ENTRANCES, wxT("Entrances"), TOOL(entrances), wxNullBitmap, wxT("Highlight entrances"));
1022 toolbar->AddCheckTool(menu_VIEW_SHOW_FIXED_PTS, wxT("Fixed points"), TOOL(fixed_pts), wxNullBitmap, wxT("Highlight fixed points"));
1023 toolbar->AddCheckTool(menu_VIEW_SHOW_EXPORTED_PTS, wxT("Exported points"), TOOL(exported_pts), wxNullBitmap, wxT("Highlight exported stations"));
1024 toolbar->AddSeparator();
1025 toolbar->AddCheckTool(menu_VIEW_SHOW_LEGS, wxT("Underground legs"), TOOL(ug_legs), wxNullBitmap, wxT("Show underground surveys"));
1026 toolbar->AddCheckTool(menu_VIEW_SHOW_SURFACE, wxT("Surface legs"), TOOL(surface_legs), wxNullBitmap, wxT("Show surface surveys"));
1027 toolbar->AddCheckTool(menu_VIEW_SHOW_TUBES, wxT("Tubes"), TOOL(tubes), wxNullBitmap, wxT("Show passage tubes"));
1028 toolbar->AddCheckTool(menu_VIEW_TERRAIN, wxT("Terrain"), TOOL(solid_surface), wxNullBitmap, wxT("Show terrain"));
1029 toolbar->AddSeparator();
1030 toolbar->AddCheckTool(menu_PRES_FREWIND, wxT("Fast Rewind"), TOOL(pres_frew), wxNullBitmap, wxT("Very Fast Rewind"));
1031 toolbar->AddCheckTool(menu_PRES_REWIND, wxT("Rewind"), TOOL(pres_rew), wxNullBitmap, wxT("Fast Rewind"));
1032 toolbar->AddCheckTool(menu_PRES_REVERSE, wxT("Backwards"), TOOL(pres_go_back), wxNullBitmap, wxT("Play Backwards"));
1033 toolbar->AddCheckTool(menu_PRES_PAUSE, wxT("Pause"), TOOL(pres_pause), wxNullBitmap, wxT("Pause"));
1034 toolbar->AddCheckTool(menu_PRES_PLAY, wxT("Go"), TOOL(pres_go), wxNullBitmap, wxT("Play"));
1035 toolbar->AddCheckTool(menu_PRES_FF, wxT("FF"), TOOL(pres_ff), wxNullBitmap, wxT("Fast Forward"));
1036 toolbar->AddCheckTool(menu_PRES_FFF, wxT("Very FF"), TOOL(pres_fff), wxNullBitmap, wxT("Very Fast Forward"));
1037 toolbar->AddTool(wxID_STOP, wxT("Stop"), TOOL(pres_stop), wxT("Stop"));
1039 toolbar->AddSeparator();
1040 m_FindBox = new wxTextCtrl(toolbar, textctrl_FIND, wxString(), wxDefaultPosition,
1041 wxDefaultSize, wxTE_PROCESS_ENTER);
1042 toolbar->AddControl(m_FindBox);
1043 /* TRANSLATORS: "Find stations" button tooltip */
1044 toolbar->AddTool(wxID_FIND, wmsg(/*Find*/332), TOOL(find)/*, "Search for station name"*/);
1045 /* TRANSLATORS: "Hide stations" button default tooltip */
1046 toolbar->AddTool(button_HIDE, wmsg(/*Hide*/333), TOOL(hideresults)/*, "Hide search results"*/);
1048 toolbar->Realize();
1051 void MainFrm::CreateSidePanel()
1053 m_Splitter = new AvenSplitterWindow(this);
1054 #ifdef USING_GENERIC_TOOLBAR
1055 // This OS-X-specific code is only needed to stop the toolbar icons getting
1056 // scaled up, which just makes them look nasty and fuzzy. Once we have
1057 // larger versions of the icons, we can drop this code.
1058 GetSizer()->Add(m_Splitter, 1, wxEXPAND);
1059 Layout();
1060 #endif
1062 m_Notebook = new wxNotebook(m_Splitter, 400, wxDefaultPosition,
1063 wxDefaultSize,
1064 wxBK_BOTTOM | wxBK_LEFT);
1065 m_Notebook->Show(false);
1067 wxPanel * panel = new wxPanel(m_Notebook);
1068 m_Tree = new AvenTreeCtrl(this, panel);
1070 // m_RegexpCheckBox = new wxCheckBox(find_panel, -1,
1071 // msg(/*Regular expression*/));
1073 wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);
1074 panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2);
1075 panel->SetAutoLayout(true);
1076 panel->SetSizer(panel_sizer);
1077 // panel_sizer->SetSizeHints(panel);
1079 m_Control = new GUIControl();
1080 m_Gfx = new GfxCore(this, m_Splitter, m_Control);
1081 m_Control->SetView(m_Gfx);
1083 // Presentation panel:
1084 wxPanel * prespanel = new wxPanel(m_Notebook);
1086 m_PresList = new AvenPresList(this, prespanel, m_Gfx);
1088 wxBoxSizer *pres_panel_sizer = new wxBoxSizer(wxVERTICAL);
1089 pres_panel_sizer->Add(m_PresList, 1, wxALL | wxEXPAND, 2);
1090 prespanel->SetAutoLayout(true);
1091 prespanel->SetSizer(pres_panel_sizer);
1093 // Overall tabbed structure:
1094 // FIXME: this assumes images are 15x15
1095 wxImageList* image_list = new wxImageList(15, 15);
1096 image_list->Add(TOOL(survey_tree));
1097 image_list->Add(TOOL(pres_tree));
1098 m_Notebook->SetImageList(image_list);
1099 /* TRANSLATORS: labels for tabbed side panel this is for the tab with the
1100 * tree hierarchy of survey station names */
1101 m_Notebook->AddPage(panel, wmsg(/*Surveys*/376), true, 0);
1102 m_Notebook->AddPage(prespanel, wmsg(/*Presentation*/377), false, 1);
1104 m_Splitter->Initialize(m_Gfx);
1107 bool MainFrm::LoadData(const wxString& file, const wxString & prefix)
1109 // Load survey data from file, centre the dataset around the origin,
1110 // and prepare the data for drawing.
1112 #if 0
1113 wxStopWatch timer;
1114 timer.Start();
1115 #endif
1117 // Load the processed survey data.
1118 img* survey = img_open_survey(file.utf8_str(), prefix.utf8_str());
1119 if (!survey) {
1120 wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str());
1121 wxGetApp().ReportError(m);
1122 return false;
1125 m_IsExtendedElevation = survey->is_extended_elevation;
1127 m_Tree->DeleteAllItems();
1129 // Create a list of all the leg vertices, counting them and finding the
1130 // extent of the survey at the same time.
1132 m_NumFixedPts = 0;
1133 m_NumExportedPts = 0;
1134 m_NumEntrances = 0;
1135 m_HasUndergroundLegs = false;
1136 m_HasSplays = false;
1137 m_HasSurfaceLegs = false;
1138 m_HasErrorInformation = false;
1140 // FIXME: discard existing presentation? ask user about saving if we do!
1142 // Delete any existing list entries.
1143 m_Labels.clear();
1145 Double xmin = DBL_MAX;
1146 Double xmax = -DBL_MAX;
1147 Double ymin = DBL_MAX;
1148 Double ymax = -DBL_MAX;
1149 Double zmin = DBL_MAX;
1150 Double zmax = -DBL_MAX;
1152 m_DepthMin = DBL_MAX;
1153 Double depthmax = -DBL_MAX;
1155 m_DateMin = INT_MAX;
1156 int datemax = -1;
1157 complete_dateinfo = true;
1159 traverses.clear();
1160 surface_traverses.clear();
1161 tubes.clear();
1163 // Ultimately we probably want different types (subclasses perhaps?) for
1164 // underground and surface data, so we don't need to store LRUD for surface
1165 // stuff.
1166 traverse * current_traverse = NULL;
1167 traverse * current_surface_traverse = NULL;
1168 vector<XSect> * current_tube = NULL;
1170 map<wxString, LabelInfo *> labelmap;
1171 list<LabelInfo*>::const_iterator last_mapped_label = m_Labels.begin();
1173 int result;
1174 img_point prev_pt = {0,0,0};
1175 bool current_polyline_is_surface = false;
1176 bool current_polyline_is_splay = false;
1177 bool pending_move = false;
1178 // When a traverse is split between surface and underground, we split it
1179 // into contiguous traverses of each, but we need to track these so we can
1180 // assign the error statistics to all of them. So we keep counts of how
1181 // many surface_traverses and traverses we've generated for the current
1182 // traverse.
1183 size_t n_traverses = 0;
1184 size_t n_surface_traverses = 0;
1185 do {
1186 #if 0
1187 if (++items % 200 == 0) {
1188 long pos = ftell(survey->fh);
1189 int progress = int((double(pos) / double(file_size)) * 100.0);
1190 // SetProgress(progress);
1192 #endif
1194 img_point pt;
1195 result = img_read_item(survey, &pt);
1196 switch (result) {
1197 case img_MOVE:
1198 n_traverses = n_surface_traverses = 0;
1199 pending_move = true;
1200 prev_pt = pt;
1201 break;
1203 case img_LINE: {
1204 // Update survey extents.
1205 if (pt.x < xmin) xmin = pt.x;
1206 if (pt.x > xmax) xmax = pt.x;
1207 if (pt.y < ymin) ymin = pt.y;
1208 if (pt.y > ymax) ymax = pt.y;
1209 if (pt.z < zmin) zmin = pt.z;
1210 if (pt.z > zmax) zmax = pt.z;
1212 int date = survey->days1;
1213 if (date != -1) {
1214 date += (survey->days2 - date) / 2;
1215 if (date < m_DateMin) m_DateMin = date;
1216 if (date > datemax) datemax = date;
1217 } else {
1218 complete_dateinfo = false;
1221 if (survey->flags & img_FLAG_SPLAY)
1222 m_HasSplays = true;
1223 bool is_surface = (survey->flags & img_FLAG_SURFACE);
1224 bool is_splay = (survey->flags & img_FLAG_SPLAY);
1225 if (!is_surface) {
1226 if (pt.z < m_DepthMin) m_DepthMin = pt.z;
1227 if (pt.z > depthmax) depthmax = pt.z;
1229 if (pending_move || current_polyline_is_surface != is_surface || current_polyline_is_splay != is_splay) {
1230 if (!current_polyline_is_surface && current_traverse) {
1231 //FixLRUD(*current_traverse);
1234 // Start new traverse (surface or underground).
1235 if (is_surface) {
1236 m_HasSurfaceLegs = true;
1237 surface_traverses.push_back(traverse());
1238 current_surface_traverse = &surface_traverses.back();
1239 ++n_surface_traverses;
1240 } else {
1241 m_HasUndergroundLegs = true;
1242 traverses.push_back(traverse());
1243 current_traverse = &traverses.back();
1244 current_traverse->isSplay = is_splay;
1245 ++n_traverses;
1246 // The previous point was at a surface->ug transition.
1247 if (current_polyline_is_surface) {
1248 if (prev_pt.z < m_DepthMin) m_DepthMin = prev_pt.z;
1249 if (prev_pt.z > depthmax) depthmax = prev_pt.z;
1253 current_polyline_is_surface = is_surface;
1254 current_polyline_is_splay = is_splay;
1256 if (pending_move) {
1257 // Update survey extents. We only need to do this if
1258 // there's a pending move, since for a surface <->
1259 // underground transition, we'll already have handled
1260 // this point.
1261 if (prev_pt.x < xmin) xmin = prev_pt.x;
1262 if (prev_pt.x > xmax) xmax = prev_pt.x;
1263 if (prev_pt.y < ymin) ymin = prev_pt.y;
1264 if (prev_pt.y > ymax) ymax = prev_pt.y;
1265 if (prev_pt.z < zmin) zmin = prev_pt.z;
1266 if (prev_pt.z > zmax) zmax = prev_pt.z;
1269 if (is_surface) {
1270 current_surface_traverse->push_back(PointInfo(prev_pt));
1271 } else {
1272 current_traverse->push_back(PointInfo(prev_pt));
1276 if (is_surface) {
1277 current_surface_traverse->push_back(PointInfo(pt, date));
1278 } else {
1279 current_traverse->push_back(PointInfo(pt, date));
1282 prev_pt = pt;
1283 pending_move = false;
1284 break;
1287 case img_LABEL: {
1288 wxString s(survey->label, wxConvUTF8);
1289 if (s.empty()) {
1290 // If label isn't valid UTF-8 then this conversion will
1291 // give an empty string. In this case, assume that the
1292 // label is CP1252 (the Microsoft superset of ISO8859-1).
1293 static wxCSConv ConvCP1252(wxFONTENCODING_CP1252);
1294 s = wxString(survey->label, ConvCP1252);
1295 if (s.empty()) {
1296 // Or if that doesn't work (ConvCP1252 doesn't like
1297 // strings with some bytes in) let's just go for
1298 // ISO8859-1.
1299 s = wxString(survey->label, wxConvISO8859_1);
1302 int flags = img2aven(survey->flags);
1303 LabelInfo* label = new LabelInfo(pt, s, flags);
1304 if (label->IsEntrance()) {
1305 m_NumEntrances++;
1307 if (label->IsFixedPt()) {
1308 m_NumFixedPts++;
1310 if (label->IsExportedPt()) {
1311 m_NumExportedPts++;
1313 m_Labels.push_back(label);
1314 break;
1317 case img_XSECT: {
1318 if (!current_tube) {
1319 // Start new current_tube.
1320 tubes.push_back(vector<XSect>());
1321 current_tube = &tubes.back();
1324 LabelInfo * lab;
1325 wxString label(survey->label, wxConvUTF8);
1326 map<wxString, LabelInfo *>::const_iterator p;
1327 p = labelmap.find(label);
1328 if (p != labelmap.end()) {
1329 lab = p->second;
1330 } else {
1331 // Initialise labelmap lazily - we may have no
1332 // cross-sections.
1333 list<LabelInfo*>::const_iterator i;
1334 if (labelmap.empty()) {
1335 i = m_Labels.begin();
1336 } else {
1337 i = last_mapped_label;
1338 ++i;
1340 while (i != m_Labels.end() && (*i)->GetText() != label) {
1341 labelmap[(*i)->GetText()] = *i;
1342 ++i;
1344 last_mapped_label = i;
1345 if (i == m_Labels.end()) {
1346 // Unattached cross-section - ignore for now.
1347 printf("unattached cross-section\n");
1348 if (current_tube->size() <= 1)
1349 tubes.resize(tubes.size() - 1);
1350 current_tube = NULL;
1351 if (!m_Labels.empty())
1352 --last_mapped_label;
1353 break;
1355 lab = *i;
1356 labelmap[label] = lab;
1359 int date = survey->days1;
1360 if (date != -1) {
1361 date += (survey->days2 - date) / 2;
1362 if (date < m_DateMin) m_DateMin = date;
1363 if (date > datemax) datemax = date;
1366 current_tube->push_back(XSect(*lab, date, survey->l, survey->r, survey->u, survey->d));
1367 break;
1370 case img_XSECT_END:
1371 // Finish off current_tube.
1372 // If there's only one cross-section in the tube, just
1373 // discard it for now. FIXME: we should handle this
1374 // when we come to skinning the tubes.
1375 if (current_tube && current_tube->size() <= 1)
1376 tubes.resize(tubes.size() - 1);
1377 current_tube = NULL;
1378 break;
1380 case img_ERROR_INFO: {
1381 if (survey->E == 0.0) {
1382 // Currently cavern doesn't spot all articulating traverses
1383 // so we assume that any traverse with no error isn't part
1384 // of a loop. FIXME: fix cavern!
1385 break;
1387 m_HasErrorInformation = true;
1388 list<traverse>::reverse_iterator t;
1389 t = surface_traverses.rbegin();
1390 while (n_surface_traverses) {
1391 assert(t != surface_traverses.rend());
1392 t->n_legs = survey->n_legs;
1393 t->length = survey->length;
1394 t->E = survey->E;
1395 t->H = survey->H;
1396 t->V = survey->V;
1397 --n_surface_traverses;
1398 ++t;
1400 t = traverses.rbegin();
1401 while (n_traverses) {
1402 assert(t != traverses.rend());
1403 t->n_legs = survey->n_legs;
1404 t->length = survey->length;
1405 t->E = survey->E;
1406 t->H = survey->H;
1407 t->V = survey->V;
1408 --n_traverses;
1409 ++t;
1411 break;
1414 case img_BAD: {
1415 m_Labels.clear();
1417 // FIXME: Do we need to reset all these? - Olly
1418 m_NumFixedPts = 0;
1419 m_NumExportedPts = 0;
1420 m_NumEntrances = 0;
1421 m_HasUndergroundLegs = false;
1422 m_HasSplays = false;
1423 m_HasSurfaceLegs = false;
1425 img_close(survey);
1427 wxString m = wxString::Format(wmsg(img_error2msg(img_error())), file.c_str());
1428 wxGetApp().ReportError(m);
1430 return false;
1433 default:
1434 break;
1436 } while (result != img_STOP);
1438 if (!current_polyline_is_surface && current_traverse) {
1439 //FixLRUD(*current_traverse);
1442 // Finish off current_tube.
1443 // If there's only one cross-section in the tube, just
1444 // discard it for now. FIXME: we should handle this
1445 // when we come to skinning the tubes.
1446 if (current_tube && current_tube->size() <= 1)
1447 tubes.resize(tubes.size() - 1);
1449 separator = survey->separator;
1450 m_Title = wxString(survey->title, wxConvUTF8);
1451 m_DateStamp_numeric = survey->datestamp_numeric;
1452 if (survey->cs) {
1453 m_cs_proj = wxString(survey->cs, wxConvUTF8);
1454 } else {
1455 m_cs_proj = wxString();
1457 if (strcmp(survey->datestamp, "?") == 0) {
1458 /* TRANSLATORS: used a processed survey with no processing date/time info */
1459 m_DateStamp = wmsg(/*Date and time not available.*/108);
1460 } else if (survey->datestamp[0] == '@') {
1461 const struct tm * tm = localtime(&m_DateStamp_numeric);
1462 char buf[256];
1463 /* TRANSLATORS: This is the date format string used to timestamp .3d
1464 * files internally. Probably best to keep it the same for all
1465 * translations. */
1466 strftime(buf, 256, msg(/*%a,%Y.%m.%d %H:%M:%S %Z*/107), tm);
1467 m_DateStamp = wxString(buf, wxConvUTF8);
1469 if (m_DateStamp.empty()) {
1470 m_DateStamp = wxString(survey->datestamp, wxConvUTF8);
1472 img_close(survey);
1474 // Check we've actually loaded some legs or stations!
1475 if (!m_HasUndergroundLegs && !m_HasSurfaceLegs && m_Labels.empty()) {
1476 wxString m = wxString::Format(wmsg(/*No survey data in 3d file “%s”*/202), file.c_str());
1477 wxGetApp().ReportError(m);
1478 return false;
1481 if (traverses.empty() && surface_traverses.empty()) {
1482 // No legs, so get survey extents from stations
1483 list<LabelInfo*>::const_iterator i;
1484 for (i = m_Labels.begin(); i != m_Labels.end(); ++i) {
1485 if ((*i)->GetX() < xmin) xmin = (*i)->GetX();
1486 if ((*i)->GetX() > xmax) xmax = (*i)->GetX();
1487 if ((*i)->GetY() < ymin) ymin = (*i)->GetY();
1488 if ((*i)->GetY() > ymax) ymax = (*i)->GetY();
1489 if ((*i)->GetZ() < zmin) zmin = (*i)->GetZ();
1490 if ((*i)->GetZ() > zmax) zmax = (*i)->GetZ();
1494 m_Ext.assign(xmax - xmin, ymax - ymin, zmax - zmin);
1496 if (datemax < m_DateMin) m_DateMin = datemax;
1497 m_DateExt = datemax - m_DateMin;
1499 // Centre the dataset around the origin.
1500 CentreDataset(Vector3(xmin, ymin, zmin));
1502 if (depthmax < m_DepthMin) {
1503 m_DepthMin = 0;
1504 m_DepthExt = 0;
1505 } else {
1506 m_DepthExt = depthmax - m_DepthMin;
1507 m_DepthMin -= m_Offsets.GetZ();
1510 #if 0
1511 printf("time to load = %.3f\n", (double)timer.Time());
1512 #endif
1514 // Update window title.
1515 SetTitle(m_Title + " - " APP_NAME);
1517 // Sort the labels ready for filling the tree.
1518 m_Labels.sort(LabelCmp(separator));
1520 // Fill the tree of stations and prefixes.
1521 wxString root_name = wxFileNameFromPath(file);
1522 if (!prefix.empty()) {
1523 root_name += " (";
1524 root_name += prefix;
1525 root_name += ")";
1527 FillTree(root_name);
1529 // Sort labels so that entrances are displayed in preference,
1530 // then fixed points, then exported points, then other points.
1532 // Also sort by leaf name so that we'll tend to choose labels
1533 // from different surveys, rather than labels from surveys which
1534 // are earlier in the list.
1535 m_Labels.sort(LabelPlotCmp(separator));
1537 if (!m_FindBox->GetValue().empty()) {
1538 // Highlight any stations matching the current search.
1539 DoFind();
1542 m_FileProcessed = file;
1544 return true;
1547 #if 0
1548 // Run along a newly read in traverse and make up plausible LRUD where
1549 // it is missing.
1550 void
1551 MainFrm::FixLRUD(traverse & centreline)
1553 assert(centreline.size() > 1);
1555 Double last_size = 0;
1556 vector<PointInfo>::iterator i = centreline.begin();
1557 while (i != centreline.end()) {
1558 // Get the coordinates of this vertex.
1559 Point & pt_v = *i++;
1560 Double size;
1562 if (i != centreline.end()) {
1563 Double h = sqrd(i->GetX() - pt_v.GetX()) +
1564 sqrd(i->GetY() - pt_v.GetY());
1565 Double v = sqrd(i->GetZ() - pt_v.GetZ());
1566 if (h + v > 30.0 * 30.0) {
1567 Double scale = 30.0 / sqrt(h + v);
1568 h *= scale;
1569 v *= scale;
1571 size = sqrt(h + v / 9);
1572 size /= 4;
1573 if (i == centreline.begin() + 1) {
1574 // First segment.
1575 last_size = size;
1576 } else {
1577 // Intermediate segment.
1578 swap(size, last_size);
1579 size += last_size;
1580 size /= 2;
1582 } else {
1583 // Last segment.
1584 size = last_size;
1587 Double & l = pt_v.l;
1588 Double & r = pt_v.r;
1589 Double & u = pt_v.u;
1590 Double & d = pt_v.d;
1592 if (l == 0 && r == 0 && u == 0 && d == 0) {
1593 l = r = u = d = -size;
1594 } else {
1595 if (l < 0 && r < 0) {
1596 l = r = -size;
1597 } else if (l < 0) {
1598 l = -(2 * size - r);
1599 if (l >= 0) l = -0.01;
1600 } else if (r < 0) {
1601 r = -(2 * size - l);
1602 if (r >= 0) r = -0.01;
1604 if (u < 0 && d < 0) {
1605 u = d = -size;
1606 } else if (u < 0) {
1607 u = -(2 * size - d);
1608 if (u >= 0) u = -0.01;
1609 } else if (d < 0) {
1610 d = -(2 * size - u);
1611 if (d >= 0) d = -0.01;
1616 #endif
1618 void MainFrm::FillTree(const wxString & root_name)
1620 // Create the root of the tree.
1621 wxTreeItemId treeroot = m_Tree->AddRoot(root_name);
1623 // Fill the tree of stations and prefixes.
1624 stack<wxTreeItemId> previous_ids;
1625 wxString current_prefix;
1626 wxTreeItemId current_id = treeroot;
1628 list<LabelInfo*>::iterator pos = m_Labels.begin();
1629 while (pos != m_Labels.end()) {
1630 LabelInfo* label = *pos++;
1632 if (label->IsAnon()) continue;
1634 // Determine the current prefix.
1635 wxString prefix = label->GetText().BeforeLast(separator);
1637 // Determine if we're still on the same prefix.
1638 if (prefix == current_prefix) {
1639 // no need to fiddle with branches...
1641 // If not, then see if we've descended to a new prefix.
1642 else if (prefix.length() > current_prefix.length() &&
1643 prefix.StartsWith(current_prefix) &&
1644 (prefix[current_prefix.length()] == separator ||
1645 current_prefix.empty())) {
1646 // We have, so start as many new branches as required.
1647 int current_prefix_length = current_prefix.length();
1648 current_prefix = prefix;
1649 size_t next_dot = current_prefix_length;
1650 if (!next_dot) --next_dot;
1651 do {
1652 size_t prev_dot = next_dot + 1;
1654 // Extract the next bit of prefix.
1655 next_dot = prefix.find(separator, prev_dot + 1);
1657 wxString bit = prefix.substr(prev_dot, next_dot - prev_dot);
1658 assert(!bit.empty());
1660 // Add the current tree ID to the stack.
1661 previous_ids.push(current_id);
1663 // Append the new item to the tree and set this as the current branch.
1664 current_id = m_Tree->AppendItem(current_id, bit);
1665 m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot)));
1666 } while (next_dot != wxString::npos);
1668 // Otherwise, we must have moved up, and possibly then down again.
1669 else {
1670 size_t count = 0;
1671 bool ascent_only = (prefix.length() < current_prefix.length() &&
1672 current_prefix.StartsWith(prefix) &&
1673 (current_prefix[prefix.length()] == separator ||
1674 prefix.empty()));
1675 if (!ascent_only) {
1676 // Find out how much of the current prefix and the new prefix
1677 // are the same.
1678 // Note that we require a match of a whole number of parts
1679 // between dots!
1680 size_t n = min(prefix.length(), current_prefix.length());
1681 size_t i;
1682 for (i = 0; i < n && prefix[i] == current_prefix[i]; ++i) {
1683 if (prefix[i] == separator) count = i + 1;
1685 } else {
1686 count = prefix.length() + 1;
1689 // Extract the part of the current prefix after the bit (if any)
1690 // which has matched.
1691 // This gives the prefixes to ascend over.
1692 wxString prefixes_ascended = current_prefix.substr(count);
1694 // Count the number of prefixes to ascend over.
1695 int num_prefixes = prefixes_ascended.Freq(separator);
1697 // Reverse up over these prefixes.
1698 for (int i = 1; i <= num_prefixes; i++) {
1699 previous_ids.pop();
1701 current_id = previous_ids.top();
1702 previous_ids.pop();
1704 if (!ascent_only) {
1705 // Add branches for this new part.
1706 size_t next_dot = count - 1;
1707 do {
1708 size_t prev_dot = next_dot + 1;
1710 // Extract the next bit of prefix.
1711 next_dot = prefix.find(separator, prev_dot + 1);
1713 wxString bit = prefix.substr(prev_dot, next_dot - prev_dot);
1714 assert(!bit.empty());
1716 // Add the current tree ID to the stack.
1717 previous_ids.push(current_id);
1719 // Append the new item to the tree and set this as the current branch.
1720 current_id = m_Tree->AppendItem(current_id, bit);
1721 m_Tree->SetItemData(current_id, new TreeData(prefix.substr(0, next_dot)));
1722 } while (next_dot != wxString::npos);
1725 current_prefix = prefix;
1728 // Now add the leaf.
1729 wxString bit = label->GetText().AfterLast(separator);
1730 assert(!bit.empty());
1731 wxTreeItemId id = m_Tree->AppendItem(current_id, bit);
1732 m_Tree->SetItemData(id, new TreeData(label));
1733 label->tree_id = id;
1734 // Set the colour for an item in the survey tree.
1735 if (label->IsEntrance()) {
1736 // Entrances are green (like entrance blobs).
1737 m_Tree->SetItemTextColour(id, wxColour(0, 255, 40));
1738 } else if (label->IsSurface()) {
1739 // Surface stations are dark green.
1740 m_Tree->SetItemTextColour(id, wxColour(49, 158, 79));
1744 m_Tree->Expand(treeroot);
1745 m_Tree->SetEnabled();
1748 void MainFrm::CentreDataset(const Vector3 & vmin)
1750 // Centre the dataset around the origin.
1752 m_Offsets = vmin + (m_Ext * 0.5);
1754 list<traverse>::iterator t = traverses.begin();
1755 while (t != traverses.end()) {
1756 assert(t->size() > 1);
1757 vector<PointInfo>::iterator pos = t->begin();
1758 while (pos != t->end()) {
1759 Point & point = *pos++;
1760 point -= m_Offsets;
1762 ++t;
1765 t = surface_traverses.begin();
1766 while (t != surface_traverses.end()) {
1767 assert(t->size() > 1);
1768 vector<PointInfo>::iterator pos = t->begin();
1769 while (pos != t->end()) {
1770 Point & point = *pos++;
1771 point -= m_Offsets;
1773 ++t;
1776 list<vector<XSect> >::iterator i = tubes.begin();
1777 while (i != tubes.end()) {
1778 assert(i->size() > 1);
1779 vector<XSect>::iterator pos = i->begin();
1780 while (pos != i->end()) {
1781 Point & point = *pos++;
1782 point -= m_Offsets;
1784 ++i;
1787 list<LabelInfo*>::iterator lpos = m_Labels.begin();
1788 while (lpos != m_Labels.end()) {
1789 Point & point = **lpos++;
1790 point -= m_Offsets;
1794 void MainFrm::OnMRUFile(wxCommandEvent& event)
1796 wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1));
1797 if (!f.empty()) OpenFile(f);
1800 void MainFrm::AddToFileHistory(const wxString & file)
1802 if (wxIsAbsolutePath(file)) {
1803 m_history.AddFileToHistory(file);
1804 } else {
1805 wxString abs = wxGetCwd();
1806 abs += wxCONFIG_PATH_SEPARATOR;
1807 abs += file;
1808 m_history.AddFileToHistory(abs);
1810 wxConfigBase *b = wxConfigBase::Get();
1811 m_history.Save(*b);
1812 b->Flush();
1815 void MainFrm::OpenFile(const wxString& file, const wxString& survey)
1817 wxBusyCursor hourglass;
1819 // Check if this is an unprocessed survey data file.
1820 if (file.length() > 4 && file[file.length() - 4] == '.') {
1821 wxString ext(file, file.length() - 3, 3);
1822 ext.MakeLower();
1823 if (ext == wxT("svx") || ext == wxT("dat") || ext == wxT("mak")) {
1824 CavernLogWindow * log = new CavernLogWindow(this, survey, m_Splitter);
1825 wxWindow * win = m_Splitter->GetWindow1();
1826 m_Splitter->ReplaceWindow(win, log);
1827 win->Show(false);
1828 if (m_Splitter->GetWindow2() == NULL) {
1829 if (win != m_Gfx) win->Destroy();
1830 } else {
1831 if (m_Splitter->IsSplit()) m_Splitter->Unsplit();
1834 if (wxFileExists(file)) AddToFileHistory(file);
1835 log->process(file);
1836 // Log window will tell us to load file if it successfully completes.
1837 return;
1841 if (!LoadData(file, survey))
1842 return;
1843 AddToFileHistory(file);
1844 InitialiseAfterLoad(file, survey);
1846 // If aven is showing the log for a .svx file and you load a .3d file, then
1847 // at this point m_Log will be the log window for the .svx file, so destroy
1848 // it - it should never legitimately be set if we get here.
1849 if (m_Log) {
1850 m_Log->Destroy();
1851 m_Log = NULL;
1855 void MainFrm::InitialiseAfterLoad(const wxString & file, const wxString & prefix)
1857 if (m_SashPosition < 0) {
1858 // Calculate sane default width for side panel.
1859 int x;
1860 int y;
1861 GetClientSize(&x, &y);
1862 if (x < 600)
1863 x /= 3;
1864 else if (x < 1000)
1865 x = 200;
1866 else
1867 x /= 5;
1868 m_SashPosition = x;
1871 // Do this before we potentially delete the log window which may own the
1872 // wxString which parameter file refers to!
1873 bool same_file = (file == m_File);
1874 if (!same_file)
1875 m_File = file;
1876 m_Survey = prefix;
1878 wxWindow * win = NULL;
1879 if (m_Splitter->GetWindow2() == NULL) {
1880 win = m_Splitter->GetWindow1();
1881 if (win == m_Gfx) win = NULL;
1884 if (!IsFullScreen()) {
1885 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1886 } else {
1887 was_showing_sidepanel_before_fullscreen = true;
1890 m_Gfx->Initialise(same_file);
1892 if (win) {
1893 // FIXME: check it actually is the log window!
1894 if (m_Log && m_Log != win)
1895 m_Log->Destroy();
1896 m_Log = win;
1897 m_Log->Show(false);
1900 if (!IsFullScreen()) {
1901 m_Notebook->Show(true);
1904 m_Gfx->Show(true);
1905 m_Gfx->SetFocus();
1908 void MainFrm::HideLog(wxWindow * log_window)
1910 if (!IsFullScreen()) {
1911 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1914 m_Log = log_window;
1915 m_Log->Show(false);
1917 if (!IsFullScreen()) {
1918 m_Notebook->Show(true);
1921 m_Gfx->Show(true);
1922 m_Gfx->SetFocus();
1926 // UI event handlers
1929 // For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx".
1930 #ifdef _WIN32
1931 # define CASE(X)
1932 #else
1933 # define CASE(X) ";" X
1934 #endif
1936 void MainFrm::OnOpen(wxCommandEvent&)
1938 AvenAllowOnTop ontop(this);
1939 #ifdef __WXMOTIF__
1940 wxString filetypes = wxT("*.3d");
1941 #else
1942 wxString filetypes;
1943 filetypes.Printf(wxT("%s|*.3d;*.svx;*.plt;*.plf;*.dat;*.mak;*.adj;*.sht;*.una;*.xyz"
1944 CASE("*.3D;*.SVX;*.PLT;*.PLF;*.DAT;*.MAK;*.ADJ;*.SHT;*.UNA;*.XYZ")
1945 "|%s|*.3d" CASE("*.3D")
1946 "|%s|*.svx" CASE("*.SVX")
1947 "|%s|*.plt;*.plf" CASE("*.PLT;*.PLF")
1948 "|%s|*.dat;*.mak" CASE("*.DAT;*.MAK")
1949 "|%s|*.adj;*.sht;*.una;*.xyz" CASE("*.ADJ;*.SHT;*.UNA;*.XYZ")
1950 "|%s|%s"),
1951 /* TRANSLATORS: Here "survey" is a "cave map" rather than
1952 * list of questions - it should be translated to the
1953 * terminology that cavers using the language would use.
1955 wmsg(/*All survey files*/229).c_str(),
1956 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
1957 * file extension, so neither should be translated. */
1958 wmsg(/*Survex 3d files*/207).c_str(),
1959 /* TRANSLATORS: Survex is the name of the software, and "svx" refers to a
1960 * file extension, so neither should be translated. */
1961 wmsg(/*Survex svx files*/329).c_str(),
1962 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1963 * surveying package, so probably shouldn’t be translated
1965 wmsg(/*Compass PLT files*/324).c_str(),
1966 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1967 * surveying package, so should not be translated
1969 wmsg(/*Compass DAT and MAK files*/330).c_str(),
1970 /* TRANSLATORS: "CMAP" is Bob Thrun’s cave surveying
1971 * package, so don’t translate it. */
1972 wmsg(/*CMAP XYZ files*/325).c_str(),
1973 wmsg(/*All files*/208).c_str(),
1974 wxFileSelectorDefaultWildcardStr);
1975 #endif
1976 /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
1977 * - it should be translated to the terminology that cavers using the
1978 * language would use.
1980 * File->Open dialog: */
1981 wxFileDialog dlg(this, wmsg(/*Select a survey file to view*/206),
1982 wxString(), wxString(),
1983 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1984 if (dlg.ShowModal() == wxID_OK) {
1985 OpenFile(dlg.GetPath());
1989 void MainFrm::OnOpenTerrain(wxCommandEvent&)
1991 if (!m_Gfx) return;
1993 if (m_cs_proj.empty()) {
1994 wxMessageBox(wxT("No coordinate system specified in survey data"));
1995 return;
1998 #ifdef __WXMOTIF__
1999 wxString filetypes = wxT("*.*");
2000 #else
2001 wxString filetypes;
2002 filetypes.Printf(wxT("%s|*.bil;*.hgt;*.zip" CASE("*.BIL;*.HGT;*.ZIP")
2003 "|%s|%s"),
2004 wmsg(/*Terrain files*/452).c_str(),
2005 wmsg(/*All files*/208).c_str(),
2006 wxFileSelectorDefaultWildcardStr);
2007 #endif
2008 /* TRANSLATORS: "Terrain file" being a digital model of the terrain (e.g. a
2009 * grid of height values). */
2010 wxFileDialog dlg(this, wmsg(/*Select a terrain file to view*/451),
2011 wxString(), wxString(),
2012 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2013 if (dlg.ShowModal() == wxID_OK && m_Gfx->LoadDEM(dlg.GetPath())) {
2014 if (!m_Gfx->DisplayingTerrain()) m_Gfx->ToggleTerrain();
2018 void MainFrm::OnShowLog(wxCommandEvent&)
2020 if (!m_Log) {
2021 HideLog(m_Splitter->GetWindow1());
2022 return;
2024 wxWindow * win = m_Splitter->GetWindow1();
2025 m_Splitter->ReplaceWindow(win, m_Log);
2026 win->Show(false);
2027 if (m_Splitter->IsSplit()) {
2028 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
2029 m_Splitter->Unsplit();
2031 m_Log->Show(true);
2032 m_Log->SetFocus();
2033 m_Log = NULL;
2036 void MainFrm::OnScreenshot(wxCommandEvent&)
2038 AvenAllowOnTop ontop(this);
2039 wxString baseleaf;
2040 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
2041 /* TRANSLATORS: title of the save screenshot dialog */
2042 wxFileDialog dlg(this, wmsg(/*Save Screenshot*/321), wxString(),
2043 baseleaf + wxT(".png"),
2044 wxT("*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2045 if (dlg.ShowModal() == wxID_OK) {
2046 static bool png_handled = false;
2047 if (!png_handled) {
2048 #if 0 // FIXME : enable this to allow other export formats...
2049 ::wxInitAllImageHandlers();
2050 #else
2051 wxImage::AddHandler(new wxPNGHandler);
2052 #endif
2053 png_handled = true;
2055 if (!m_Gfx->SaveScreenshot(dlg.GetPath(), wxBITMAP_TYPE_PNG)) {
2056 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), dlg.GetPath().c_str()));
2061 void MainFrm::OnScreenshotUpdate(wxUpdateUIEvent& event)
2063 event.Enable(!m_File.empty());
2066 void MainFrm::OnFilePreferences(wxCommandEvent&)
2068 #ifdef PREFDLG
2069 m_PrefsDlg = new PrefsDlg(m_Gfx, this);
2070 m_PrefsDlg->Show(true);
2071 #endif
2074 void MainFrm::OnPrint(wxCommandEvent&)
2076 m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj);
2079 void MainFrm::PrintAndExit()
2081 m_Gfx->OnPrint(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj, true);
2084 void MainFrm::OnPageSetup(wxCommandEvent&)
2086 wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData());
2087 if (dlg.ShowModal() == wxID_OK) {
2088 wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData());
2092 void MainFrm::OnExport(wxCommandEvent&)
2094 m_Gfx->OnExport(m_File, m_Title, m_DateStamp, m_DateStamp_numeric, m_cs_proj);
2097 void MainFrm::OnExtend(wxCommandEvent&)
2099 wxString output = m_Survey;
2100 if (output.empty()) {
2101 wxFileName::SplitPath(m_File, NULL, NULL, &output, NULL, wxPATH_NATIVE);
2103 output += wxT("_extend.3d");
2105 AvenAllowOnTop ontop(this);
2106 #ifdef __WXMOTIF__
2107 wxString ext(wxT("*.3d"));
2108 #else
2109 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
2110 * file extension, so neither should be translated. */
2111 wxString ext = wmsg(/*Survex 3d files*/207);
2112 ext += wxT("|*.3d");
2113 #endif
2114 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
2115 wxString(), output, ext,
2116 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2117 if (dlg.ShowModal() != wxID_OK) return;
2118 output = dlg.GetPath();
2120 wxString cmd = get_command_path(L"extend");
2121 cmd = escape_for_shell(cmd, false);
2122 if (!m_Survey.empty()) {
2123 cmd += wxT(" --survey=");
2124 cmd += escape_for_shell(m_Survey, false);
2126 cmd += wxT(" --show-breaks ");
2127 cmd += escape_for_shell(m_FileProcessed, true);
2128 cmd += wxT(" ");
2129 cmd += escape_for_shell(output, true);
2130 if (wxExecute(cmd, wxEXEC_SYNC) < 0) {
2131 wxString m;
2132 m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str());
2133 m += wxT(" (");
2134 m += wxString(strerror(errno), wxConvUTF8);
2135 m += wxT(')');
2136 wxGetApp().ReportError(m);
2137 return;
2139 if (LoadData(output, wxString()))
2140 InitialiseAfterLoad(output, wxString());
2143 void MainFrm::OnQuit(wxCommandEvent&)
2145 if (m_PresList->Modified()) {
2146 AvenAllowOnTop ontop(this);
2147 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
2148 /* TRANSLATORS: and the question in that box */
2149 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
2150 /* TRANSLATORS: title of message box */
2151 wmsg(/*Modified Presentation*/326),
2152 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2153 return;
2156 wxConfigBase *b = wxConfigBase::Get();
2157 if (IsFullScreen()) {
2158 b->Write(wxT("width"), -2);
2159 b->DeleteEntry(wxT("height"));
2160 } else if (IsMaximized()) {
2161 b->Write(wxT("width"), -1);
2162 b->DeleteEntry(wxT("height"));
2163 } else {
2164 int width, height;
2165 GetSize(&width, &height);
2166 b->Write(wxT("width"), width);
2167 b->Write(wxT("height"), height);
2169 b->Flush();
2170 exit(0);
2173 void MainFrm::OnClose(wxCloseEvent&)
2175 wxCommandEvent dummy;
2176 OnQuit(dummy);
2179 void MainFrm::OnAbout(wxCommandEvent&)
2181 AvenAllowOnTop ontop(this);
2182 #ifdef __WXMAC__
2183 // GetIcon() returns an invalid wxIcon under OS X.
2184 AboutDlg dlg(this, wxICON(aven));
2185 #else
2186 AboutDlg dlg(this, GetIcon());
2187 #endif
2188 dlg.Centre();
2189 dlg.ShowModal();
2192 void MainFrm::UpdateStatusBar()
2194 if (!here_text.empty()) {
2195 GetStatusBar()->SetStatusText(here_text);
2196 GetStatusBar()->SetStatusText(dist_text, 1);
2197 } else if (!coords_text.empty()) {
2198 GetStatusBar()->SetStatusText(coords_text);
2199 GetStatusBar()->SetStatusText(distfree_text, 1);
2200 } else {
2201 GetStatusBar()->SetStatusText(wxString());
2202 GetStatusBar()->SetStatusText(wxString(), 1);
2206 void MainFrm::ClearTreeSelection()
2208 m_Tree->UnselectAll();
2209 m_Gfx->SetThere();
2210 ShowInfo();
2213 void MainFrm::ClearCoords()
2215 if (!coords_text.empty()) {
2216 coords_text = wxString();
2217 UpdateStatusBar();
2221 void MainFrm::SetCoords(const Vector3 &v)
2223 Double x = v.GetX();
2224 Double y = v.GetY();
2225 Double z = v.GetZ();
2226 int units;
2227 if (m_Gfx->GetMetric()) {
2228 units = /*m*/424;
2229 } else {
2230 x /= METRES_PER_FOOT;
2231 y /= METRES_PER_FOOT;
2232 z /= METRES_PER_FOOT;
2233 units = /*ft*/428;
2235 /* TRANSLATORS: show coordinates (N = North or Northing, E = East or
2236 * Easting) */
2237 coords_text.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2238 coords_text += wxString::Format(wxT(", %s %.2f%s"),
2239 wmsg(/*Altitude*/335).c_str(),
2240 z, wmsg(units).c_str());
2241 distfree_text = wxString();
2242 UpdateStatusBar();
2245 const LabelInfo * MainFrm::GetTreeSelection() const {
2246 wxTreeItemData* sel_wx;
2247 if (!m_Tree->GetSelectionData(&sel_wx)) return NULL;
2249 const TreeData* data = static_cast<const TreeData*>(sel_wx);
2250 if (!data->IsStation()) return NULL;
2252 return data->GetLabel();
2255 void MainFrm::SetCoords(Double x, Double y, const LabelInfo * there)
2257 wxString & s = coords_text;
2258 if (m_Gfx->GetMetric()) {
2259 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2260 } else {
2261 s.Printf(wmsg(/*%.2f E, %.2f N*/338),
2262 x / METRES_PER_FOOT, y / METRES_PER_FOOT);
2265 wxString & t = distfree_text;
2266 t = wxString();
2267 if (m_Gfx->ShowingMeasuringLine() && there) {
2268 Vector3 delta(x - m_Offsets.GetX() - there->GetX(),
2269 y - m_Offsets.GetY() - there->GetY(), 0);
2270 Double dh = sqrt(delta.GetX()*delta.GetX() + delta.GetY()*delta.GetY());
2271 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
2272 if (brg < 0) brg += 360;
2274 wxString from_str;
2275 /* TRANSLATORS: Used in Aven:
2276 * From <stationname>
2277 * H: 123.45m V: 234.56m
2278 * Dist: 456.78m Brg: 200 */
2279 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
2280 int brg_unit;
2281 if (m_Gfx->GetDegrees()) {
2282 brg_unit = /*°*/344;
2283 } else {
2284 brg *= 400.0 / 360.0;
2285 /* TRANSLATORS: alternative angle units (400 grad = 360 degrees =
2286 * full circle). Try to make this as short as sensibly possible.
2288 * E.g. in Italian and Spanish we use "g.cent." rather than
2289 * "gradi quattrocentesimali"/"grados centesimales" */
2290 brg_unit = /*grad*/345;
2293 int units;
2294 if (m_Gfx->GetMetric()) {
2295 units = /*m*/424;
2296 } else {
2297 dh /= METRES_PER_FOOT;
2298 units = /*ft*/428;
2300 /* TRANSLATORS: "H" is short for "Horizontal", "Brg" for "Bearing" (as
2301 * in Compass bearing) */
2302 t.Printf(wmsg(/*%s: H %.2f%s, Brg %03d%s*/374),
2303 from_str.c_str(), dh, wmsg(units).c_str(),
2304 int(brg), wmsg(brg_unit).c_str());
2307 UpdateStatusBar();
2310 void MainFrm::SetAltitude(Double z, const LabelInfo * there)
2312 double alt = z;
2313 int units;
2314 if (m_Gfx->GetMetric()) {
2315 units = /*m*/424;
2316 } else {
2317 alt /= METRES_PER_FOOT;
2318 units = /*ft*/428;
2320 coords_text.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
2321 alt, wmsg(units).c_str());
2323 wxString & t = distfree_text;
2324 t = wxString();
2325 if (m_Gfx->ShowingMeasuringLine() && there) {
2326 Double dz = z - m_Offsets.GetZ() - there->GetZ();
2328 wxString from_str;
2329 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
2331 if (!m_Gfx->GetMetric()) {
2332 dz /= METRES_PER_FOOT;
2334 // TRANSLATORS: "V" is short for "Vertical"
2335 t.Printf(wmsg(/*%s: V %.2f%s*/375), from_str.c_str(),
2336 dz, wmsg(units).c_str());
2339 UpdateStatusBar();
2342 void MainFrm::ShowInfo(const LabelInfo *here, const LabelInfo *there)
2344 assert(m_Gfx);
2346 if (!here) {
2347 m_Gfx->SetHere();
2348 m_Tree->SetHere(wxTreeItemId());
2349 // Don't clear "There" mark here.
2350 if (here_text.empty() && dist_text.empty()) return;
2351 here_text = wxString();
2352 dist_text = wxString();
2353 UpdateStatusBar();
2354 return;
2357 Vector3 v = *here + m_Offsets;
2358 wxString & s = here_text;
2359 Double x = v.GetX();
2360 Double y = v.GetY();
2361 Double z = v.GetZ();
2362 int units;
2363 if (m_Gfx->GetMetric()) {
2364 units = /*m*/424;
2365 } else {
2366 x /= METRES_PER_FOOT;
2367 y /= METRES_PER_FOOT;
2368 z /= METRES_PER_FOOT;
2369 units = /*ft*/428;
2371 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
2372 s += wxString::Format(wxT(", %s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
2373 z, wmsg(units).c_str());
2374 s += wxT(": ");
2375 s += here->name_or_anon();
2376 m_Gfx->SetHere(here);
2377 m_Tree->SetHere(here->tree_id);
2379 if (m_Gfx->ShowingMeasuringLine() && there) {
2380 Vector3 delta = *here - *there;
2382 Double d_horiz = sqrt(delta.GetX()*delta.GetX() +
2383 delta.GetY()*delta.GetY());
2384 Double dr = delta.magnitude();
2385 Double dz = delta.GetZ();
2387 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
2388 if (brg < 0) brg += 360;
2390 wxString from_str;
2391 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
2393 wxString hv_str;
2394 if (m_Gfx->GetMetric()) {
2395 units = /*m*/424;
2396 } else {
2397 d_horiz /= METRES_PER_FOOT;
2398 dr /= METRES_PER_FOOT;
2399 dz /= METRES_PER_FOOT;
2400 units = /*ft*/428;
2402 wxString len_unit = wmsg(units);
2403 /* TRANSLATORS: "H" is short for "Horizontal", "V" for "Vertical" */
2404 hv_str.Printf(wmsg(/*H %.2f%s, V %.2f%s*/340),
2405 d_horiz, len_unit.c_str(), dz, len_unit.c_str());
2406 int brg_unit;
2407 if (m_Gfx->GetDegrees()) {
2408 brg_unit = /*°*/344;
2409 } else {
2410 brg *= 400.0 / 360.0;
2411 brg_unit = /*grad*/345;
2413 wxString & d = dist_text;
2414 /* TRANSLATORS: "Dist" is short for "Distance", "Brg" for "Bearing" (as
2415 * in Compass bearing) */
2416 d.Printf(wmsg(/*%s: %s, Dist %.2f%s, Brg %03d%s*/341),
2417 from_str.c_str(), hv_str.c_str(),
2418 dr, len_unit.c_str(), int(brg), wmsg(brg_unit).c_str());
2419 } else {
2420 dist_text = wxString();
2421 m_Gfx->SetThere();
2423 UpdateStatusBar();
2426 void MainFrm::DisplayTreeInfo(const wxTreeItemData* item)
2428 const TreeData* data = static_cast<const TreeData*>(item);
2429 if (data && data->IsStation()) {
2430 m_Gfx->SetHereFromTree(data->GetLabel());
2431 } else {
2432 ShowInfo();
2436 void MainFrm::TreeItemSelected(const wxTreeItemData* item, bool zoom)
2438 const TreeData* data = static_cast<const TreeData*>(item);
2439 if (data && data->IsStation()) {
2440 const LabelInfo* label = data->GetLabel();
2441 if (zoom) m_Gfx->CentreOn(*label);
2442 m_Gfx->SetThere(label);
2443 dist_text = wxString();
2444 // FIXME: Need to update dist_text (From ... etc)
2445 // But we don't currently know where "here" is at this point in the
2446 // code!
2447 } else {
2448 dist_text = wxString();
2449 m_Gfx->SetThere();
2451 if (!data) {
2452 // Must be the root.
2453 m_FindBox->SetValue(wxString());
2454 if (zoom) {
2455 wxCommandEvent dummy;
2456 OnDefaults(dummy);
2458 } else if (data && !data->IsStation()) {
2459 m_FindBox->SetValue(data->GetSurvey() + wxT(".*"));
2460 if (zoom) {
2461 wxCommandEvent dummy;
2462 OnGotoFound(dummy);
2465 UpdateStatusBar();
2468 void MainFrm::OnPresNew(wxCommandEvent&)
2470 if (m_PresList->Modified()) {
2471 AvenAllowOnTop ontop(this);
2472 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
2473 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
2474 wmsg(/*Modified Presentation*/326),
2475 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2476 return;
2479 m_PresList->New(m_File);
2480 if (!ShowingSidePanel()) ToggleSidePanel();
2481 // Select the presentation page in the notebook.
2482 m_Notebook->SetSelection(1);
2485 void MainFrm::OnPresOpen(wxCommandEvent&)
2487 AvenAllowOnTop ontop(this);
2488 if (m_PresList->Modified()) {
2489 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
2490 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
2491 wmsg(/*Modified Presentation*/326),
2492 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
2493 return;
2496 #ifdef __WXMOTIF__
2497 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
2498 wxT("*.fly"), wxFD_OPEN);
2499 #else
2500 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
2501 wxString::Format(wxT("%s|*.fly|%s|%s"),
2502 wmsg(/*Aven presentations*/320).c_str(),
2503 wmsg(/*All files*/208).c_str(),
2504 wxFileSelectorDefaultWildcardStr),
2505 wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2506 #endif
2507 if (dlg.ShowModal() == wxID_OK) {
2508 if (!m_PresList->Load(dlg.GetPath())) {
2509 return;
2511 // FIXME : keep a history of loaded/saved presentations, like we do for
2512 // loaded surveys...
2513 // Select the presentation page in the notebook.
2514 m_Notebook->SetSelection(1);
2518 void MainFrm::OnPresSave(wxCommandEvent&)
2520 m_PresList->Save(true);
2523 void MainFrm::OnPresSaveAs(wxCommandEvent&)
2525 m_PresList->Save(false);
2528 void MainFrm::OnPresMark(wxCommandEvent&)
2530 m_PresList->AddMark();
2533 void MainFrm::OnPresFRewind(wxCommandEvent&)
2535 m_Gfx->PlayPres(-100);
2538 void MainFrm::OnPresRewind(wxCommandEvent&)
2540 m_Gfx->PlayPres(-10);
2543 void MainFrm::OnPresReverse(wxCommandEvent&)
2545 m_Gfx->PlayPres(-1);
2548 void MainFrm::OnPresPlay(wxCommandEvent&)
2550 m_Gfx->PlayPres(1);
2553 void MainFrm::OnPresFF(wxCommandEvent&)
2555 m_Gfx->PlayPres(10);
2558 void MainFrm::OnPresFFF(wxCommandEvent&)
2560 m_Gfx->PlayPres(100);
2563 void MainFrm::OnPresPause(wxCommandEvent&)
2565 m_Gfx->PlayPres(0);
2568 void MainFrm::OnPresStop(wxCommandEvent&)
2570 m_Gfx->PlayPres(0, false);
2573 void MainFrm::OnPresExportMovie(wxCommandEvent&)
2575 #ifdef WITH_LIBAV
2576 AvenAllowOnTop ontop(this);
2577 // FIXME : Taking the leaf of the currently loaded presentation as the
2578 // default might make more sense?
2579 wxString baseleaf;
2580 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
2581 wxFileDialog dlg(this, wmsg(/*Export Movie*/331), wxString(),
2582 baseleaf + wxT(".mpg"),
2583 wxT("MPEG|*.mpg|AVI|*.avi|QuickTime|*.mov|WMV|*.wmv;*.asf"),
2584 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2585 if (dlg.ShowModal() == wxID_OK) {
2586 // Error is reported by GfxCore.
2587 (void)m_Gfx->ExportMovie(dlg.GetPath());
2589 #else
2590 wxGetApp().ReportError(wxT("Movie generation support code not present"));
2591 #endif
2594 PresentationMark MainFrm::GetPresMark(int which)
2596 return m_PresList->GetPresMark(which);
2599 void MainFrm::RestrictTo(const wxString & survey)
2601 // The station names will change, so clear the current search.
2602 wxCommandEvent dummy;
2603 OnHide(dummy);
2605 wxString new_prefix;
2606 if (!survey.empty()) {
2607 if (!m_Survey.empty()) {
2608 new_prefix = m_Survey;
2609 new_prefix += separator;
2611 new_prefix += survey;
2613 // Reload the processed data rather rather than potentially reprocessing.
2614 if (!LoadData(m_FileProcessed, new_prefix))
2615 return;
2616 InitialiseAfterLoad(m_File, new_prefix);
2619 void MainFrm::OnOpenTerrainUpdate(wxUpdateUIEvent& event)
2621 event.Enable(!m_File.empty());
2624 void MainFrm::OnPresNewUpdate(wxUpdateUIEvent& event)
2626 event.Enable(!m_File.empty());
2629 void MainFrm::OnPresOpenUpdate(wxUpdateUIEvent& event)
2631 event.Enable(!m_File.empty());
2634 void MainFrm::OnPresSaveUpdate(wxUpdateUIEvent& event)
2636 event.Enable(!m_PresList->Empty());
2639 void MainFrm::OnPresSaveAsUpdate(wxUpdateUIEvent& event)
2641 event.Enable(!m_PresList->Empty());
2644 void MainFrm::OnPresMarkUpdate(wxUpdateUIEvent& event)
2646 event.Enable(!m_File.empty());
2649 void MainFrm::OnPresFRewindUpdate(wxUpdateUIEvent& event)
2651 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2652 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() < -10);
2655 void MainFrm::OnPresRewindUpdate(wxUpdateUIEvent& event)
2657 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2658 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -10);
2661 void MainFrm::OnPresReverseUpdate(wxUpdateUIEvent& event)
2663 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2664 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -1);
2667 void MainFrm::OnPresPlayUpdate(wxUpdateUIEvent& event)
2669 event.Enable(!m_PresList->Empty());
2670 event.Check(m_Gfx && m_Gfx->GetPresentationMode() &&
2671 m_Gfx->GetPresentationSpeed() == 1);
2674 void MainFrm::OnPresFFUpdate(wxUpdateUIEvent& event)
2676 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2677 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 10);
2680 void MainFrm::OnPresFFFUpdate(wxUpdateUIEvent& event)
2682 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2683 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() > 10);
2686 void MainFrm::OnPresPauseUpdate(wxUpdateUIEvent& event)
2688 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2689 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 0);
2692 void MainFrm::OnPresStopUpdate(wxUpdateUIEvent& event)
2694 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2697 void MainFrm::OnPresExportMovieUpdate(wxUpdateUIEvent& event)
2699 event.Enable(!m_PresList->Empty());
2702 void MainFrm::OnFind(wxCommandEvent&)
2704 pending_find = true;
2707 void MainFrm::OnIdle(wxIdleEvent&)
2709 if (pending_find) {
2710 DoFind();
2714 void MainFrm::DoFind()
2716 pending_find = false;
2717 wxBusyCursor hourglass;
2718 // Find stations specified by a string or regular expression pattern.
2720 wxString pattern = m_FindBox->GetValue();
2721 if (pattern.empty()) {
2722 // Hide any search result highlights.
2723 list<LabelInfo*>::iterator pos = m_Labels.begin();
2724 while (pos != m_Labels.end()) {
2725 LabelInfo* label = *pos++;
2726 label->clear_flags(LFLAG_HIGHLIGHTED);
2728 m_NumHighlighted = 0;
2729 } else {
2730 int re_flags = wxRE_NOSUB;
2732 if (true /* case insensitive */) {
2733 re_flags |= wxRE_ICASE;
2736 bool substring = true;
2737 if (false /*m_RegexpCheckBox->GetValue()*/) {
2738 re_flags |= wxRE_EXTENDED;
2739 } else if (true /* simple glob-style */) {
2740 wxString pat;
2741 for (size_t i = 0; i < pattern.size(); i++) {
2742 wxChar ch = pattern[i];
2743 // ^ only special at start; $ at end. But this is simpler...
2744 switch (ch) {
2745 case '^': case '$': case '.': case '[': case '\\':
2746 pat += wxT('\\');
2747 pat += ch;
2748 break;
2749 case '*':
2750 pat += wxT(".*");
2751 substring = false;
2752 break;
2753 case '?':
2754 pat += wxT('.');
2755 substring = false;
2756 break;
2757 default:
2758 pat += ch;
2761 pattern = pat;
2762 re_flags |= wxRE_BASIC;
2763 } else {
2764 wxString pat;
2765 for (size_t i = 0; i < pattern.size(); i++) {
2766 wxChar ch = pattern[i];
2767 // ^ only special at start; $ at end. But this is simpler...
2768 switch (ch) {
2769 case '^': case '$': case '*': case '.': case '[': case '\\':
2770 pat += wxT('\\');
2772 pat += ch;
2774 pattern = pat;
2775 re_flags |= wxRE_BASIC;
2778 if (!substring) {
2779 // FIXME "0u" required to avoid compilation error with g++-3.0
2780 if (pattern.empty() || pattern[0u] != '^') pattern = wxT('^') + pattern;
2781 // FIXME: this fails to cope with "\$" at the end of pattern...
2782 if (pattern[pattern.size() - 1] != '$') pattern += wxT('$');
2785 wxRegEx regex;
2786 if (!regex.Compile(pattern, re_flags)) {
2787 wxBell();
2788 return;
2791 int found = 0;
2793 list<LabelInfo*>::iterator pos = m_Labels.begin();
2794 while (pos != m_Labels.end()) {
2795 LabelInfo* label = *pos++;
2797 if (regex.Matches(label->GetText())) {
2798 label->set_flags(LFLAG_HIGHLIGHTED);
2799 ++found;
2800 } else {
2801 label->clear_flags(LFLAG_HIGHLIGHTED);
2805 m_NumHighlighted = found;
2807 // Re-sort so highlighted points get names in preference
2808 if (found) m_Labels.sort(LabelPlotCmp(separator));
2811 m_Gfx->UpdateBlobs();
2812 m_Gfx->ForceRefresh();
2814 if (!m_NumHighlighted) {
2815 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*No matches were found.*/328));
2816 } else {
2817 /* TRANSLATORS: "Hide stations" button tooltip when stations are found
2819 GetToolBar()->SetToolShortHelp(button_HIDE, wxString::Format(wmsg(/*Hide %d found stations*/334).c_str(), m_NumHighlighted));
2823 void MainFrm::OnGotoFound(wxCommandEvent&)
2825 if (!m_NumHighlighted) {
2826 wxGetApp().ReportError(wmsg(/*No matches were found.*/328));
2827 return;
2830 Double xmin = DBL_MAX;
2831 Double xmax = -DBL_MAX;
2832 Double ymin = DBL_MAX;
2833 Double ymax = -DBL_MAX;
2834 Double zmin = DBL_MAX;
2835 Double zmax = -DBL_MAX;
2837 list<LabelInfo*>::iterator pos = m_Labels.begin();
2838 while (pos != m_Labels.end()) {
2839 LabelInfo* label = *pos++;
2841 if (label->get_flags() & LFLAG_HIGHLIGHTED) {
2842 if (label->GetX() < xmin) xmin = label->GetX();
2843 if (label->GetX() > xmax) xmax = label->GetX();
2844 if (label->GetY() < ymin) ymin = label->GetY();
2845 if (label->GetY() > ymax) ymax = label->GetY();
2846 if (label->GetZ() < zmin) zmin = label->GetZ();
2847 if (label->GetZ() > zmax) zmax = label->GetZ();
2851 m_Gfx->SetViewTo(xmin, xmax, ymin, ymax, zmin, zmax);
2852 m_Gfx->SetFocus();
2855 void MainFrm::OnHide(wxCommandEvent&)
2857 m_FindBox->SetValue(wxString());
2858 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*Hide*/333));
2861 void MainFrm::OnHideUpdate(wxUpdateUIEvent& ui)
2863 ui.Enable(m_NumHighlighted != 0);
2866 void MainFrm::OnViewSidePanel(wxCommandEvent&)
2868 ToggleSidePanel();
2871 void MainFrm::ToggleSidePanel()
2873 // Toggle display of the side panel.
2875 assert(m_Gfx);
2877 if (m_Splitter->IsSplit()) {
2878 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
2879 m_Splitter->Unsplit(m_Notebook);
2880 } else {
2881 m_Notebook->Show(true);
2882 m_Gfx->Show(true);
2883 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
2887 void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui)
2889 ui.Enable(!m_File.empty());
2890 ui.Check(ShowingSidePanel());
2893 bool MainFrm::ShowingSidePanel()
2895 return m_Splitter->IsSplit();
2898 void MainFrm::ViewFullScreen() {
2899 #ifdef __WXMAC__
2900 // On OS X, wxWidgets doesn't currently hide the toolbar or statusbar in
2901 // full screen mode (last checked with 3.0.2), but it is easy to do
2902 // ourselves.
2903 if (!IsFullScreen()) {
2904 GetToolBar()->Hide();
2905 GetStatusBar()->Hide();
2907 #endif
2909 ShowFullScreen(!IsFullScreen());
2910 fullscreen_showing_menus = false;
2911 if (IsFullScreen())
2912 was_showing_sidepanel_before_fullscreen = ShowingSidePanel();
2913 if (was_showing_sidepanel_before_fullscreen)
2914 ToggleSidePanel();
2916 #ifdef __WXMAC__
2917 if (!IsFullScreen()) {
2918 GetStatusBar()->Show();
2919 GetToolBar()->Show();
2920 #ifdef USING_GENERIC_TOOLBAR
2921 Layout();
2922 #endif
2924 #endif
2927 bool MainFrm::FullScreenModeShowingMenus() const
2929 return fullscreen_showing_menus;
2932 void MainFrm::FullScreenModeShowMenus(bool show)
2934 if (!IsFullScreen() || show == fullscreen_showing_menus)
2935 return;
2936 #ifdef __WXMAC__
2937 // On OS X, enabling the menu bar while in full
2938 // screen mode doesn't have any effect, so instead
2939 // make moving the mouse to the top of the screen
2940 // drop us out of full screen mode for now.
2941 ViewFullScreen();
2942 #else
2943 GetMenuBar()->Show(show);
2944 fullscreen_showing_menus = show;
2945 #endif