Fix coding style
[survex.git] / src / mainfrm.cc
blobb79181d9476c1402749d03aab42c8f3dffeeebc9
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,2018 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 <vector>
58 // XPM files declare the array as static, but we also want it to be const too.
59 // This avoids a compiler warning, and also means the data can go in a
60 // read-only page and be shared between processes.
61 #define static static const
62 #ifndef __WXMSW__
63 #include "../lib/icons/aven.xpm"
64 #endif
65 #include "../lib/icons/log.xpm"
66 #include "../lib/icons/open.xpm"
67 #include "../lib/icons/open_pres.xpm"
68 #include "../lib/icons/rotation.xpm"
69 #include "../lib/icons/plan.xpm"
70 #include "../lib/icons/elevation.xpm"
71 #include "../lib/icons/defaults.xpm"
72 #include "../lib/icons/names.xpm"
73 #include "../lib/icons/crosses.xpm"
74 #include "../lib/icons/entrances.xpm"
75 #include "../lib/icons/fixed_pts.xpm"
76 #include "../lib/icons/exported_pts.xpm"
77 #include "../lib/icons/ug_legs.xpm"
78 #include "../lib/icons/surface_legs.xpm"
79 #include "../lib/icons/tubes.xpm"
80 #include "../lib/icons/solid_surface.xpm"
81 #include "../lib/icons/pres_frew.xpm"
82 #include "../lib/icons/pres_rew.xpm"
83 #include "../lib/icons/pres_go_back.xpm"
84 #include "../lib/icons/pres_pause.xpm"
85 #include "../lib/icons/pres_go.xpm"
86 #include "../lib/icons/pres_ff.xpm"
87 #include "../lib/icons/pres_fff.xpm"
88 #include "../lib/icons/pres_stop.xpm"
89 #include "../lib/icons/find.xpm"
90 #include "../lib/icons/hideresults.xpm"
91 #include "../lib/icons/survey_tree.xpm"
92 #include "../lib/icons/pres_tree.xpm"
93 #undef static
94 #ifdef __WXMSW__
95 # define TOOL(x) wxBitmap(x##_xpm)
96 #else
97 # define TOOL(x) wxBITMAP(x)
98 #endif
100 using namespace std;
102 class AvenSplitterWindow : public wxSplitterWindow {
103 MainFrm *parent;
105 public:
106 explicit AvenSplitterWindow(MainFrm *parent_)
107 : wxSplitterWindow(parent_, -1, wxDefaultPosition, wxDefaultSize,
108 wxSP_3DSASH),
109 parent(parent_)
113 void OnSplitterDClick(wxSplitterEvent &) {
114 parent->ToggleSidePanel();
117 private:
118 DECLARE_EVENT_TABLE()
121 BEGIN_EVENT_TABLE(AvenSplitterWindow, wxSplitterWindow)
122 EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick)
123 END_EVENT_TABLE()
125 class EditMarkDlg : public wxDialog {
126 wxTextCtrl * easting, * northing, * altitude;
127 wxTextCtrl * angle, * tilt_angle, * scale, * time;
128 public:
129 // TRANSLATORS: Title of dialog to edit a waypoint in a presentation.
130 EditMarkDlg(wxWindow* parent, const PresentationMark & p)
131 : wxDialog(parent, 500, wmsg(/*Edit Waypoint*/404))
133 easting = new wxTextCtrl(this, 601, wxString::Format(wxT("%.3f"), p.GetX()));
134 northing = new wxTextCtrl(this, 602, wxString::Format(wxT("%.3f"), p.GetY()));
135 altitude = new wxTextCtrl(this, 603, wxString::Format(wxT("%.3f"), p.GetZ()));
136 angle = new wxTextCtrl(this, 604, wxString::Format(wxT("%.3f"), p.angle));
137 tilt_angle = new wxTextCtrl(this, 605, wxString::Format(wxT("%.3f"), p.tilt_angle));
138 scale = new wxTextCtrl(this, 606, wxString::Format(wxT("%.3f"), p.scale));
139 if (p.time > 0.0) {
140 time = new wxTextCtrl(this, 607, wxString::Format(wxT("%.3f"), p.time));
141 } else if (p.time < 0.0) {
142 time = new wxTextCtrl(this, 607, wxString::Format(wxT("*%.3f"), -p.time));
143 } else {
144 time = new wxTextCtrl(this, 607, wxT("0"));
147 wxBoxSizer * coords = new wxBoxSizer(wxHORIZONTAL);
148 coords->Add(new wxStaticText(this, 610, wxT("(")), 0, wxALIGN_CENTRE_VERTICAL);
149 coords->Add(easting, 1);
150 coords->Add(new wxStaticText(this, 611, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
151 coords->Add(northing, 1);
152 coords->Add(new wxStaticText(this, 612, wxT(",")), 0, wxALIGN_CENTRE_VERTICAL);
153 coords->Add(altitude, 1);
154 coords->Add(new wxStaticText(this, 613, wxT(")")), 0, wxALIGN_CENTRE_VERTICAL);
155 wxBoxSizer* vert = new wxBoxSizer(wxVERTICAL);
156 vert->Add(coords, 0, wxALL, 8);
157 wxBoxSizer * r2 = new wxBoxSizer(wxHORIZONTAL);
158 r2->Add(new wxStaticText(this, 614, wmsg(/*Bearing*/259) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
159 r2->Add(angle);
160 vert->Add(r2, 0, wxALL, 8);
161 wxBoxSizer * r3 = new wxBoxSizer(wxHORIZONTAL);
162 r3->Add(new wxStaticText(this, 615, wmsg(/*Elevation*/118) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
163 r3->Add(tilt_angle);
164 vert->Add(r3, 0, wxALL, 8);
165 wxBoxSizer * r4 = new wxBoxSizer(wxHORIZONTAL);
166 r4->Add(new wxStaticText(this, 616, wmsg(/*Scale*/154) + wxT(": ")), 0, wxALIGN_CENTRE_VERTICAL);
167 r4->Add(scale);
168 /* TRANSLATORS: Note after "Scale" field in dialog to edit a waypoint
169 * in a presentation. */
170 r4->Add(new wxStaticText(this, 617, wmsg(/* (unused in perspective view)*/278)),
171 0, wxALIGN_CENTRE_VERTICAL);
172 vert->Add(r4, 0, wxALL, 8);
174 wxBoxSizer * r5 = new wxBoxSizer(wxHORIZONTAL);
175 /* TRANSLATORS: Field label in dialog to edit a waypoint in a
176 * presentation. */
177 r5->Add(new wxStaticText(this, 616, wmsg(/*Time: */279)), 0, wxALIGN_CENTRE_VERTICAL);
178 r5->Add(time);
179 /* TRANSLATORS: units+info after time field in dialog to edit a
180 * waypoint in a presentation. */
181 r5->Add(new wxStaticText(this, 617, wmsg(/* secs (0 = auto; *6 = 6 times auto)*/282)),
182 0, wxALIGN_CENTRE_VERTICAL);
183 vert->Add(r5, 0, wxALL, 8);
185 wxBoxSizer * buttons = new wxBoxSizer(wxHORIZONTAL);
186 wxButton* cancel = new wxButton(this, wxID_CANCEL);
187 buttons->Add(cancel, 0, wxALL, 8);
188 wxButton* ok = new wxButton(this, wxID_OK);
189 ok->SetDefault();
190 buttons->Add(ok, 0, wxALL, 8);
191 vert->Add(buttons, 0, wxALL|wxALIGN_RIGHT);
193 SetAutoLayout(true);
194 SetSizer(vert);
196 vert->SetSizeHints(this);
198 PresentationMark GetMark() const {
199 double a, t, s, T;
200 Vector3 v(wxAtof(easting->GetValue()),
201 wxAtof(northing->GetValue()),
202 wxAtof(altitude->GetValue()));
203 a = wxAtof(angle->GetValue());
204 t = wxAtof(tilt_angle->GetValue());
205 s = wxAtof(scale->GetValue());
206 wxString str = time->GetValue();
207 if (!str.empty() && str[0u] == '*') str[0u] = '-';
208 T = wxAtof(str);
209 return PresentationMark(v, a, t, s, T);
212 private:
213 DECLARE_EVENT_TABLE()
216 // Write a value without trailing zeros after the decimal point.
217 static void write_double(double d, FILE * fh) {
218 char buf[64];
219 sprintf(buf, "%.21f", d);
220 char * p = strchr(buf, ',');
221 if (p) *p = '.';
222 size_t l = strlen(buf);
223 while (l > 1 && buf[l - 1] == '0') --l;
224 if (l > 1 && buf[l - 1] == '.') --l;
225 fwrite(buf, l, 1, fh);
228 class AvenPresList : public wxListCtrl {
229 MainFrm * mainfrm;
230 GfxCore * gfx;
231 vector<PresentationMark> entries;
232 long current_item;
233 bool modified;
234 bool force_save_as;
235 wxString filename;
237 public:
238 AvenPresList(MainFrm * mainfrm_, wxWindow * parent, GfxCore * gfx_)
239 : wxListCtrl(parent, listctrl_PRES, wxDefaultPosition, wxDefaultSize,
240 wxLC_REPORT|wxLC_VIRTUAL),
241 mainfrm(mainfrm_), gfx(gfx_), current_item(-1), modified(false),
242 force_save_as(true)
244 InsertColumn(0, wmsg(/*Easting*/378));
245 InsertColumn(1, wmsg(/*Northing*/379));
246 InsertColumn(2, wmsg(/*Altitude*/335));
249 void OnBeginLabelEdit(wxListEvent& event) {
250 event.Veto(); // No editting allowed
252 void OnDeleteItem(wxListEvent& event) {
253 long item = event.GetIndex();
254 if (current_item == item) {
255 current_item = -1;
256 } else if (current_item > item) {
257 --current_item;
259 entries.erase(entries.begin() + item);
260 SetItemCount(entries.size());
261 modified = true;
263 void OnDeleteAllItems(wxListEvent&) {
264 entries.clear();
265 SetItemCount(entries.size());
266 filename = wxString();
267 modified = false;
268 force_save_as = true;
270 void OnListKeyDown(wxListEvent& event) {
271 switch (event.GetKeyCode()) {
272 case WXK_DELETE: {
273 long item = GetNextItem(-1, wxLIST_NEXT_ALL,
274 wxLIST_STATE_SELECTED);
275 while (item != -1) {
276 DeleteItem(item);
277 // - 1 because the indices were shifted by DeleteItem()
278 item = GetNextItem(item - 1, wxLIST_NEXT_ALL,
279 wxLIST_STATE_SELECTED);
281 break;
283 default:
284 //printf("event.GetIndex() = %ld %d\n", event.GetIndex(), event.GetKeyCode());
285 event.Skip();
288 void OnActivated(wxListEvent& event) {
289 // Jump to this view.
290 long item = event.GetIndex();
291 gfx->SetView(entries[item]);
293 void OnFocused(wxListEvent& event) {
294 current_item = event.GetIndex();
296 void OnRightClick(wxListEvent& event) {
297 long item = event.GetIndex();
298 if (item < 0) {
299 AddMark(item, gfx->GetView());
300 item = 0;
302 EditMarkDlg edit(mainfrm, entries[item]);
303 if (edit.ShowModal() == wxID_OK) {
304 entries[item] = edit.GetMark();
307 void OnChar(wxKeyEvent& event) {
308 switch (event.GetKeyCode()) {
309 case WXK_INSERT:
310 if (event.GetModifiers() == wxMOD_CONTROL) {
311 if (current_item != -1 &&
312 size_t(current_item) < entries.size()) {
313 AddMark(current_item, entries[current_item]);
315 } else {
316 AddMark(current_item);
318 break;
319 case WXK_DELETE:
320 // Already handled in OnListKeyDown.
321 break;
322 case WXK_UP: case WXK_DOWN:
323 event.Skip();
324 break;
325 default:
326 gfx->OnKeyPress(event);
329 void AddMark(long item = -1) {
330 AddMark(item, gfx->GetView());
332 void AddMark(long item, const PresentationMark & mark) {
333 if (item == -1) item = entries.size();
334 entries.insert(entries.begin() + item, mark);
335 SetItemCount(entries.size());
336 modified = true;
338 virtual wxString OnGetItemText(long item, long column) const {
339 if (item < 0 || item >= (long)entries.size()) return wxString();
340 const PresentationMark & p = entries[item];
341 double v;
342 switch (column) {
343 case 0: v = p.GetX(); break;
344 case 1: v = p.GetY(); break;
345 case 2: v = p.GetZ(); break;
346 #if 0
347 case 3: v = p.angle; break;
348 case 4: v = p.tilt_angle; break;
349 case 5: v = p.scale; break;
350 case 6: v = p.time; break;
351 #endif
352 default: return wxString();
354 return wxString::Format(wxT("%ld"), (long)v);
356 void Save(bool use_default_name) {
357 wxString fnm = filename;
358 if (!use_default_name || force_save_as) {
359 AvenAllowOnTop ontop(mainfrm);
360 #ifdef __WXMOTIF__
361 wxString ext(wxT("*.fly"));
362 #else
363 wxString ext = wmsg(/*Aven presentations*/320);
364 ext += wxT("|*.fly");
365 #endif
366 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
367 wxString(), fnm, ext,
368 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
369 if (dlg.ShowModal() != wxID_OK) return;
370 fnm = dlg.GetPath();
373 FILE * fh_pres = wxFopen(fnm, wxT("w"));
374 if (!fh_pres) {
375 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm.c_str()));
376 return;
378 vector<PresentationMark>::const_iterator i;
379 for (i = entries.begin(); i != entries.end(); ++i) {
380 const PresentationMark &p = *i;
381 write_double(p.GetX(), fh_pres);
382 PUTC(' ', fh_pres);
383 write_double(p.GetY(), fh_pres);
384 PUTC(' ', fh_pres);
385 write_double(p.GetZ(), fh_pres);
386 PUTC(' ', fh_pres);
387 write_double(p.angle, fh_pres);
388 PUTC(' ', fh_pres);
389 write_double(p.tilt_angle, fh_pres);
390 PUTC(' ', fh_pres);
391 write_double(p.scale, fh_pres);
392 if (p.time != 0.0) {
393 PUTC(' ', fh_pres);
394 write_double(p.time, fh_pres);
396 PUTC('\n', fh_pres);
398 fclose(fh_pres);
399 filename = fnm;
400 modified = false;
401 force_save_as = false;
403 void New(const wxString &fnm) {
404 DeleteAllItems();
405 wxFileName::SplitPath(fnm, NULL, NULL, &filename, NULL, wxPATH_NATIVE);
406 filename += wxT(".fly");
407 force_save_as = true;
409 bool Load(const wxString &fnm) {
410 FILE * fh_pres = wxFopen(fnm, wxT("r"));
411 if (!fh_pres) {
412 wxString m;
413 m.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm.c_str());
414 wxGetApp().ReportError(m);
415 return false;
417 DeleteAllItems();
418 long item = 0;
419 while (!feof(fh_pres)) {
420 char buf[4096];
421 size_t i = 0;
422 while (i < sizeof(buf) - 1) {
423 int ch = GETC(fh_pres);
424 if (ch == EOF || ch == '\n' || ch == '\r') break;
425 buf[i++] = ch;
427 if (i) {
428 buf[i] = 0;
429 double x, y, z, a, t, s, T;
430 int c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
431 if (c < 6) {
432 char *p = buf;
433 while ((p = strchr(p, '.'))) *p++ = ',';
434 c = sscanf(buf, "%lf %lf %lf %lf %lf %lf %lf", &x, &y, &z, &a, &t, &s, &T);
435 if (c < 6) {
436 DeleteAllItems();
437 wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm.c_str()));
438 return false;
441 if (c == 6) T = 0;
442 AddMark(item, PresentationMark(Vector3(x, y, z), a, t, s, T));
443 ++item;
446 fclose(fh_pres);
447 filename = fnm;
448 modified = false;
449 force_save_as = false;
450 return true;
452 bool Modified() const { return modified; }
453 bool Empty() const { return entries.empty(); }
454 PresentationMark GetPresMark(int which) {
455 long item = current_item;
456 if (which == MARK_FIRST) {
457 item = 0;
458 } else if (which == MARK_NEXT) {
459 ++item;
460 } else if (which == MARK_PREV) {
461 --item;
463 if (item == -1 || item == (long)entries.size())
464 return PresentationMark();
465 if (item != current_item) {
466 // Move the focus
467 if (current_item != -1) {
468 wxListCtrl::SetItemState(current_item, wxLIST_STATE_FOCUSED,
471 wxListCtrl::SetItemState(item, wxLIST_STATE_FOCUSED,
472 wxLIST_STATE_FOCUSED);
474 return entries[item];
477 private:
479 DECLARE_NO_COPY_CLASS(AvenPresList)
480 DECLARE_EVENT_TABLE()
483 BEGIN_EVENT_TABLE(EditMarkDlg, wxDialog)
484 END_EVENT_TABLE()
486 BEGIN_EVENT_TABLE(AvenPresList, wxListCtrl)
487 EVT_LIST_BEGIN_LABEL_EDIT(listctrl_PRES, AvenPresList::OnBeginLabelEdit)
488 EVT_LIST_DELETE_ITEM(listctrl_PRES, AvenPresList::OnDeleteItem)
489 EVT_LIST_DELETE_ALL_ITEMS(listctrl_PRES, AvenPresList::OnDeleteAllItems)
490 EVT_LIST_KEY_DOWN(listctrl_PRES, AvenPresList::OnListKeyDown)
491 EVT_LIST_ITEM_ACTIVATED(listctrl_PRES, AvenPresList::OnActivated)
492 EVT_LIST_ITEM_FOCUSED(listctrl_PRES, AvenPresList::OnFocused)
493 EVT_LIST_ITEM_RIGHT_CLICK(listctrl_PRES, AvenPresList::OnRightClick)
494 EVT_CHAR(AvenPresList::OnChar)
495 END_EVENT_TABLE()
497 BEGIN_EVENT_TABLE(MainFrm, wxFrame)
498 EVT_TEXT(textctrl_FIND, MainFrm::OnFind)
499 EVT_TEXT_ENTER(textctrl_FIND, MainFrm::OnGotoFound)
500 EVT_MENU(wxID_FIND, MainFrm::OnGotoFound)
501 EVT_MENU(button_HIDE, MainFrm::OnHide)
502 EVT_UPDATE_UI(button_HIDE, MainFrm::OnHideUpdate)
503 EVT_IDLE(MainFrm::OnIdle)
505 EVT_MENU(wxID_OPEN, MainFrm::OnOpen)
506 EVT_MENU(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrain)
507 EVT_MENU(menu_FILE_LOG, MainFrm::OnShowLog)
508 EVT_MENU(wxID_PRINT, MainFrm::OnPrint)
509 EVT_MENU(menu_FILE_PAGE_SETUP, MainFrm::OnPageSetup)
510 EVT_MENU(menu_FILE_SCREENSHOT, MainFrm::OnScreenshot)
511 // EVT_MENU(wxID_PREFERENCES, MainFrm::OnFilePreferences)
512 EVT_MENU(menu_FILE_EXPORT, MainFrm::OnExport)
513 EVT_MENU(menu_FILE_EXTEND, MainFrm::OnExtend)
514 EVT_MENU(wxID_EXIT, MainFrm::OnQuit)
515 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, MainFrm::OnMRUFile)
517 EVT_MENU(menu_PRES_NEW, MainFrm::OnPresNew)
518 EVT_MENU(menu_PRES_OPEN, MainFrm::OnPresOpen)
519 EVT_MENU(menu_PRES_SAVE, MainFrm::OnPresSave)
520 EVT_MENU(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAs)
521 EVT_MENU(menu_PRES_MARK, MainFrm::OnPresMark)
522 EVT_MENU(menu_PRES_FREWIND, MainFrm::OnPresFRewind)
523 EVT_MENU(menu_PRES_REWIND, MainFrm::OnPresRewind)
524 EVT_MENU(menu_PRES_REVERSE, MainFrm::OnPresReverse)
525 EVT_MENU(menu_PRES_PLAY, MainFrm::OnPresPlay)
526 EVT_MENU(menu_PRES_FF, MainFrm::OnPresFF)
527 EVT_MENU(menu_PRES_FFF, MainFrm::OnPresFFF)
528 EVT_MENU(menu_PRES_PAUSE, MainFrm::OnPresPause)
529 EVT_MENU(wxID_STOP, MainFrm::OnPresStop)
530 EVT_MENU(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovie)
532 EVT_UPDATE_UI(menu_PRES_NEW, MainFrm::OnPresNewUpdate)
533 EVT_UPDATE_UI(menu_PRES_OPEN, MainFrm::OnPresOpenUpdate)
534 EVT_UPDATE_UI(menu_PRES_SAVE, MainFrm::OnPresSaveUpdate)
535 EVT_UPDATE_UI(menu_PRES_SAVE_AS, MainFrm::OnPresSaveAsUpdate)
536 EVT_UPDATE_UI(menu_PRES_MARK, MainFrm::OnPresMarkUpdate)
537 EVT_UPDATE_UI(menu_PRES_FREWIND, MainFrm::OnPresFRewindUpdate)
538 EVT_UPDATE_UI(menu_PRES_REWIND, MainFrm::OnPresRewindUpdate)
539 EVT_UPDATE_UI(menu_PRES_REVERSE, MainFrm::OnPresReverseUpdate)
540 EVT_UPDATE_UI(menu_PRES_PLAY, MainFrm::OnPresPlayUpdate)
541 EVT_UPDATE_UI(menu_PRES_FF, MainFrm::OnPresFFUpdate)
542 EVT_UPDATE_UI(menu_PRES_FFF, MainFrm::OnPresFFFUpdate)
543 EVT_UPDATE_UI(menu_PRES_PAUSE, MainFrm::OnPresPauseUpdate)
544 EVT_UPDATE_UI(wxID_STOP, MainFrm::OnPresStopUpdate)
545 EVT_UPDATE_UI(menu_PRES_EXPORT_MOVIE, MainFrm::OnPresExportMovieUpdate)
547 EVT_CLOSE(MainFrm::OnClose)
548 EVT_SET_FOCUS(MainFrm::OnSetFocus)
550 EVT_MENU(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotation)
551 EVT_MENU(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotation)
552 EVT_MENU(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorth)
553 EVT_MENU(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEast)
554 EVT_MENU(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouth)
555 EVT_MENU(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWest)
556 EVT_MENU(menu_ORIENT_PLAN, MainFrm::OnPlan)
557 EVT_MENU(menu_ORIENT_ELEVATION, MainFrm::OnElevation)
558 EVT_MENU(menu_ORIENT_DEFAULTS, MainFrm::OnDefaults)
559 EVT_MENU(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegs)
560 EVT_MENU(menu_SPLAYS_HIDE, MainFrm::OnHideSplays)
561 EVT_MENU(menu_SPLAYS_SHOW_DASHED, MainFrm::OnShowSplaysDashed)
562 EVT_MENU(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFaded)
563 EVT_MENU(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormal)
564 EVT_MENU(menu_DUPES_HIDE, MainFrm::OnHideDupes)
565 EVT_MENU(menu_DUPES_SHOW_DASHED, MainFrm::OnShowDupesDashed)
566 EVT_MENU(menu_DUPES_SHOW_FADED, MainFrm::OnShowDupesFaded)
567 EVT_MENU(menu_DUPES_SHOW_NORMAL, MainFrm::OnShowDupesNormal)
568 EVT_MENU(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrosses)
569 EVT_MENU(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrances)
570 EVT_MENU(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPts)
571 EVT_MENU(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPts)
572 EVT_MENU(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNames)
573 EVT_MENU(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNames)
574 EVT_MENU(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepth)
575 EVT_MENU(menu_COLOUR_BY_DATE, MainFrm::OnColourByDate)
576 EVT_MENU(menu_COLOUR_BY_ERROR, MainFrm::OnColourByError)
577 EVT_MENU(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradient)
578 EVT_MENU(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLength)
579 EVT_MENU(menu_COLOUR_BY_SURVEY, MainFrm::OnColourBySurvey)
580 EVT_MENU(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurface)
581 EVT_MENU(menu_VIEW_GRID, MainFrm::OnViewGrid)
582 EVT_MENU(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBox)
583 EVT_MENU(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspective)
584 EVT_MENU(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShading)
585 EVT_MENU(menu_VIEW_TEXTURED, MainFrm::OnViewTextured)
586 EVT_MENU(menu_VIEW_FOG, MainFrm::OnViewFog)
587 EVT_MENU(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLines)
588 EVT_MENU(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreen)
589 EVT_MENU(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubes)
590 EVT_MENU(menu_VIEW_TERRAIN, MainFrm::OnViewTerrain)
591 EVT_MENU(menu_IND_COMPASS, MainFrm::OnViewCompass)
592 EVT_MENU(menu_IND_CLINO, MainFrm::OnViewClino)
593 EVT_MENU(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKey)
594 EVT_MENU(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebar)
595 EVT_MENU(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanel)
596 EVT_MENU(menu_CTL_METRIC, MainFrm::OnToggleMetric)
597 EVT_MENU(menu_CTL_DEGREES, MainFrm::OnToggleDegrees)
598 EVT_MENU(menu_CTL_PERCENT, MainFrm::OnTogglePercent)
599 EVT_MENU(menu_CTL_REVERSE, MainFrm::OnReverseControls)
600 EVT_MENU(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLine)
601 EVT_MENU(wxID_ABOUT, MainFrm::OnAbout)
603 EVT_UPDATE_UI(menu_FILE_OPEN_TERRAIN, MainFrm::OnOpenTerrainUpdate)
604 EVT_UPDATE_UI(menu_FILE_LOG, MainFrm::OnShowLogUpdate)
605 EVT_UPDATE_UI(wxID_PRINT, MainFrm::OnPrintUpdate)
606 EVT_UPDATE_UI(menu_FILE_SCREENSHOT, MainFrm::OnScreenshotUpdate)
607 EVT_UPDATE_UI(menu_FILE_EXPORT, MainFrm::OnExportUpdate)
608 EVT_UPDATE_UI(menu_FILE_EXTEND, MainFrm::OnExtendUpdate)
609 EVT_UPDATE_UI(menu_ROTATION_TOGGLE, MainFrm::OnToggleRotationUpdate)
610 EVT_UPDATE_UI(menu_ROTATION_REVERSE, MainFrm::OnReverseDirectionOfRotationUpdate)
611 EVT_UPDATE_UI(menu_ORIENT_MOVE_NORTH, MainFrm::OnMoveNorthUpdate)
612 EVT_UPDATE_UI(menu_ORIENT_MOVE_EAST, MainFrm::OnMoveEastUpdate)
613 EVT_UPDATE_UI(menu_ORIENT_MOVE_SOUTH, MainFrm::OnMoveSouthUpdate)
614 EVT_UPDATE_UI(menu_ORIENT_MOVE_WEST, MainFrm::OnMoveWestUpdate)
615 EVT_UPDATE_UI(menu_ORIENT_PLAN, MainFrm::OnPlanUpdate)
616 EVT_UPDATE_UI(menu_ORIENT_ELEVATION, MainFrm::OnElevationUpdate)
617 EVT_UPDATE_UI(menu_ORIENT_DEFAULTS, MainFrm::OnDefaultsUpdate)
618 EVT_UPDATE_UI(menu_VIEW_SHOW_LEGS, MainFrm::OnShowSurveyLegsUpdate)
619 EVT_UPDATE_UI(menu_VIEW_SPLAYS, MainFrm::OnSplaysUpdate)
620 EVT_UPDATE_UI(menu_SPLAYS_HIDE, MainFrm::OnHideSplaysUpdate)
621 EVT_UPDATE_UI(menu_SPLAYS_SHOW_DASHED, MainFrm::OnShowSplaysDashedUpdate)
622 EVT_UPDATE_UI(menu_SPLAYS_SHOW_FADED, MainFrm::OnShowSplaysFadedUpdate)
623 EVT_UPDATE_UI(menu_SPLAYS_SHOW_NORMAL, MainFrm::OnShowSplaysNormalUpdate)
624 EVT_UPDATE_UI(menu_VIEW_DUPES, MainFrm::OnDupesUpdate)
625 EVT_UPDATE_UI(menu_DUPES_HIDE, MainFrm::OnHideDupesUpdate)
626 EVT_UPDATE_UI(menu_DUPES_SHOW_DASHED, MainFrm::OnShowDupesDashedUpdate)
627 EVT_UPDATE_UI(menu_DUPES_SHOW_FADED, MainFrm::OnShowDupesFadedUpdate)
628 EVT_UPDATE_UI(menu_DUPES_SHOW_NORMAL, MainFrm::OnShowDupesNormalUpdate)
629 EVT_UPDATE_UI(menu_VIEW_SHOW_CROSSES, MainFrm::OnShowCrossesUpdate)
630 EVT_UPDATE_UI(menu_VIEW_SHOW_ENTRANCES, MainFrm::OnShowEntrancesUpdate)
631 EVT_UPDATE_UI(menu_VIEW_SHOW_FIXED_PTS, MainFrm::OnShowFixedPtsUpdate)
632 EVT_UPDATE_UI(menu_VIEW_SHOW_EXPORTED_PTS, MainFrm::OnShowExportedPtsUpdate)
633 EVT_UPDATE_UI(menu_VIEW_SHOW_NAMES, MainFrm::OnShowStationNamesUpdate)
634 EVT_UPDATE_UI(menu_VIEW_SHOW_SURFACE, MainFrm::OnShowSurfaceUpdate)
635 EVT_UPDATE_UI(menu_VIEW_SHOW_OVERLAPPING_NAMES, MainFrm::OnDisplayOverlappingNamesUpdate)
636 EVT_UPDATE_UI(menu_VIEW_COLOUR_BY, MainFrm::OnColourByUpdate)
637 EVT_UPDATE_UI(menu_COLOUR_BY_DEPTH, MainFrm::OnColourByDepthUpdate)
638 EVT_UPDATE_UI(menu_COLOUR_BY_DATE, MainFrm::OnColourByDateUpdate)
639 EVT_UPDATE_UI(menu_COLOUR_BY_ERROR, MainFrm::OnColourByErrorUpdate)
640 EVT_UPDATE_UI(menu_COLOUR_BY_GRADIENT, MainFrm::OnColourByGradientUpdate)
641 EVT_UPDATE_UI(menu_COLOUR_BY_LENGTH, MainFrm::OnColourByLengthUpdate)
642 EVT_UPDATE_UI(menu_COLOUR_BY_SURVEY, MainFrm::OnColourBySurveyUpdate)
643 EVT_UPDATE_UI(menu_VIEW_GRID, MainFrm::OnViewGridUpdate)
644 EVT_UPDATE_UI(menu_VIEW_BOUNDING_BOX, MainFrm::OnViewBoundingBoxUpdate)
645 EVT_UPDATE_UI(menu_VIEW_PERSPECTIVE, MainFrm::OnViewPerspectiveUpdate)
646 EVT_UPDATE_UI(menu_VIEW_SMOOTH_SHADING, MainFrm::OnViewSmoothShadingUpdate)
647 EVT_UPDATE_UI(menu_VIEW_TEXTURED, MainFrm::OnViewTexturedUpdate)
648 EVT_UPDATE_UI(menu_VIEW_FOG, MainFrm::OnViewFogUpdate)
649 EVT_UPDATE_UI(menu_VIEW_SMOOTH_LINES, MainFrm::OnViewSmoothLinesUpdate)
650 EVT_UPDATE_UI(menu_VIEW_FULLSCREEN, MainFrm::OnViewFullScreenUpdate)
651 EVT_UPDATE_UI(menu_VIEW_SHOW_TUBES, MainFrm::OnToggleTubesUpdate)
652 EVT_UPDATE_UI(menu_VIEW_TERRAIN, MainFrm::OnViewTerrainUpdate)
653 EVT_UPDATE_UI(menu_IND_COMPASS, MainFrm::OnViewCompassUpdate)
654 EVT_UPDATE_UI(menu_IND_CLINO, MainFrm::OnViewClinoUpdate)
655 EVT_UPDATE_UI(menu_IND_COLOUR_KEY, MainFrm::OnToggleColourKeyUpdate)
656 EVT_UPDATE_UI(menu_IND_SCALE_BAR, MainFrm::OnToggleScalebarUpdate)
657 EVT_UPDATE_UI(menu_CTL_INDICATORS, MainFrm::OnIndicatorsUpdate)
658 EVT_UPDATE_UI(menu_CTL_SIDE_PANEL, MainFrm::OnViewSidePanelUpdate)
659 EVT_UPDATE_UI(menu_CTL_REVERSE, MainFrm::OnReverseControlsUpdate)
660 EVT_UPDATE_UI(menu_CTL_CANCEL_DIST_LINE, MainFrm::OnCancelDistLineUpdate)
661 EVT_UPDATE_UI(menu_CTL_METRIC, MainFrm::OnToggleMetricUpdate)
662 EVT_UPDATE_UI(menu_CTL_DEGREES, MainFrm::OnToggleDegreesUpdate)
663 EVT_UPDATE_UI(menu_CTL_PERCENT, MainFrm::OnTogglePercentUpdate)
664 END_EVENT_TABLE()
666 class LabelCmp : public greater<const LabelInfo*> {
667 wxChar separator;
668 public:
669 explicit LabelCmp(wxChar separator_) : separator(separator_) {}
670 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
671 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
675 class LabelPlotCmp : public greater<const LabelInfo*> {
676 wxChar separator;
677 public:
678 explicit LabelPlotCmp(wxChar separator_) : separator(separator_) {}
679 bool operator()(const LabelInfo* pt1, const LabelInfo* pt2) {
680 int n = pt1->get_flags() - pt2->get_flags();
681 if (n) return n > 0;
682 wxString l1 = pt1->GetText().AfterLast(separator);
683 wxString l2 = pt2->GetText().AfterLast(separator);
684 n = name_cmp(l1, l2, separator);
685 if (n) return n < 0;
686 // Prefer non-2-nodes...
687 // FIXME; implement
688 // if leaf names are the same, prefer shorter labels as we can
689 // display more of them
690 n = pt1->GetText().length() - pt2->GetText().length();
691 if (n) return n < 0;
692 // make sure that we don't ever compare different labels as equal
693 return name_cmp(pt1->GetText(), pt2->GetText(), separator) < 0;
697 #if wxUSE_DRAG_AND_DROP
698 class DnDFile : public wxFileDropTarget {
699 public:
700 explicit DnDFile(MainFrm *parent) : m_Parent(parent) { }
701 virtual bool OnDropFiles(wxCoord, wxCoord,
702 const wxArrayString &filenames);
704 private:
705 MainFrm * m_Parent;
708 bool
709 DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
711 // Load a survey file by drag-and-drop.
712 assert(filenames.GetCount() > 0);
714 if (filenames.GetCount() != 1) {
715 /* TRANSLATORS: error if you try to drag multiple files to the aven
716 * window */
717 wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336));
718 return false;
721 m_Parent->OpenFile(filenames[0]);
722 return true;
724 #endif
726 MainFrm::MainFrm(const wxString& title, const wxPoint& pos, const wxSize& size) :
727 wxFrame(NULL, 101, title, pos, size, wxDEFAULT_FRAME_STYLE),
728 m_SashPosition(-1),
729 m_Gfx(NULL), m_Log(NULL),
730 pending_find(false), fullscreen_showing_menus(false)
731 #ifdef PREFDLG
732 , m_PrefsDlg(NULL)
733 #endif
735 #ifdef _WIN32
736 // The peculiar name is so that the icon is the first in the file
737 // (required by Microsoft Windows for this type of icon)
738 SetIcon(wxICON(AAA_aven));
739 #else
740 SetIcon(wxICON(aven));
741 #endif
743 #if wxCHECK_VERSION(3,1,0)
744 // Add a full screen button to the right upper corner of title bar under OS
745 // X 10.7 and later.
746 EnableFullScreenView();
747 #endif
748 CreateMenuBar();
749 MakeToolBar();
750 CreateStatusBar(2, wxST_SIZEGRIP);
751 CreateSidePanel();
753 int widths[2] = { -1 /* variable width */, -1 };
754 GetStatusBar()->SetStatusWidths(2, widths);
756 #ifdef __X__ // wxMotif or wxX11
757 int x;
758 int y;
759 GetSize(&x, &y);
760 // X seems to require a forced resize.
761 SetSize(-1, -1, x, y);
762 #endif
764 #if wxUSE_DRAG_AND_DROP
765 SetDropTarget(new DnDFile(this));
766 #endif
769 void MainFrm::CreateMenuBar()
771 // Create the menus and the menu bar.
773 wxMenu* filemenu = new wxMenu;
774 // wxID_OPEN stock label lacks the ellipses
775 /* TRANSLATORS: Aven menu items. An “&” goes before the letter of any
776 * accelerator key.
778 * The string "\t" separates the menu text and any accelerator key.
780 * "File" menu. The accelerators must be different within this group.
781 * c.f. 201, 380, 381. */
782 filemenu->Append(wxID_OPEN, wmsg(/*&Open...\tCtrl+O*/220));
783 /* TRANSLATORS: Open a "Terrain file" - i.e. a digital model of the
784 * terrain. */
785 filemenu->Append(menu_FILE_OPEN_TERRAIN, wmsg(/*Open &Terrain...*/453));
786 filemenu->AppendCheckItem(menu_FILE_LOG, wmsg(/*Show &Log*/144));
787 filemenu->AppendSeparator();
788 // wxID_PRINT stock label lacks the ellipses
789 filemenu->Append(wxID_PRINT, wmsg(/*&Print...\tCtrl+P*/380));
790 filemenu->Append(menu_FILE_PAGE_SETUP, wmsg(/*P&age Setup...*/381));
791 filemenu->AppendSeparator();
792 /* TRANSLATORS: In the "File" menu */
793 filemenu->Append(menu_FILE_SCREENSHOT, wmsg(/*&Screenshot...*/201));
794 filemenu->Append(menu_FILE_EXPORT, wmsg(/*&Export as...*/382));
795 /* TRANSLATORS: In the "File" menu - c.f. n:191 */
796 filemenu->Append(menu_FILE_EXTEND, wmsg(/*E&xtended Elevation...*/247));
797 #ifndef __WXMAC__
798 // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress
799 // this separator.
800 filemenu->AppendSeparator();
801 #else
802 // We suppress the "Help" menu under OS X as it would otherwise end up as
803 // an empty menu, but we need to add the "About" menu item somewhere. It
804 // really doesn't matter where as wxWidgets will move it to the "Apple"
805 // menu.
806 filemenu->Append(wxID_ABOUT);
807 #endif
808 filemenu->Append(wxID_EXIT);
810 m_history.UseMenu(filemenu);
811 m_history.Load(*wxConfigBase::Get());
813 wxMenu* rotmenu = new wxMenu;
814 /* TRANSLATORS: "Rotation" menu. The accelerators must be different within
815 * this group. Tickable menu item which toggles auto rotation.
816 * Please don't translate "Space" - that's the shortcut key to use which
817 * wxWidgets needs to parse and it should then handle translating.
819 rotmenu->AppendCheckItem(menu_ROTATION_TOGGLE, wmsg(/*Au&to-Rotate\tSpace*/231));
820 rotmenu->AppendSeparator();
821 rotmenu->Append(menu_ROTATION_REVERSE, wmsg(/*&Reverse Direction*/234));
823 wxMenu* orientmenu = new wxMenu;
824 orientmenu->Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240));
825 orientmenu->Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241));
826 orientmenu->Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242));
827 orientmenu->Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243));
828 orientmenu->AppendSeparator();
829 orientmenu->Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248));
830 orientmenu->Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249));
831 orientmenu->AppendSeparator();
832 orientmenu->Append(menu_ORIENT_DEFAULTS, wmsg(/*Restore De&fault View*/254));
834 wxMenu* presmenu = new wxMenu;
835 presmenu->Append(menu_PRES_NEW, wmsg(/*&New Presentation*/311));
836 presmenu->Append(menu_PRES_OPEN, wmsg(/*&Open Presentation...*/312));
837 presmenu->Append(menu_PRES_SAVE, wmsg(/*&Save Presentation*/313));
838 presmenu->Append(menu_PRES_SAVE_AS, wmsg(/*Sa&ve Presentation As...*/314));
839 presmenu->AppendSeparator();
840 /* TRANSLATORS: "Mark" as in "Mark this position" */
841 presmenu->Append(menu_PRES_MARK, wmsg(/*&Mark*/315));
842 /* TRANSLATORS: "Play" as in "Play back a recording" */
843 presmenu->AppendCheckItem(menu_PRES_PLAY, wmsg(/*Pla&y*/316));
844 presmenu->Append(menu_PRES_EXPORT_MOVIE, wmsg(/*&Export as Movie...*/317));
846 wxMenu* viewmenu = new wxMenu;
847 #ifndef PREFDLG
848 /* TRANSLATORS: Items in the "View" menu: */
849 viewmenu->AppendCheckItem(menu_VIEW_SHOW_NAMES, wmsg(/*Station &Names\tCtrl+N*/270));
850 /* TRANSLATORS: Toggles drawing of 3D passages */
851 viewmenu->AppendCheckItem(menu_VIEW_SHOW_TUBES, wmsg(/*Passage &Tubes\tCtrl+T*/346));
852 /* TRANSLATORS: Toggles drawing the surface of the Earth */
853 viewmenu->AppendCheckItem(menu_VIEW_TERRAIN, wmsg(/*Terr&ain*/449));
854 viewmenu->AppendCheckItem(menu_VIEW_SHOW_CROSSES, wmsg(/*&Crosses\tCtrl+X*/271));
855 viewmenu->AppendCheckItem(menu_VIEW_GRID, wmsg(/*&Grid\tCtrl+G*/297));
856 viewmenu->AppendCheckItem(menu_VIEW_BOUNDING_BOX, wmsg(/*&Bounding Box\tCtrl+B*/318));
857 viewmenu->AppendSeparator();
858 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
859 * "survey stations". */
860 viewmenu->AppendCheckItem(menu_VIEW_SHOW_LEGS, wmsg(/*&Underground Survey Legs\tCtrl+L*/272));
861 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
862 * "survey stations". */
863 viewmenu->AppendCheckItem(menu_VIEW_SHOW_SURFACE, wmsg(/*&Surface Survey Legs\tCtrl+F*/291));
865 wxMenu* splaymenu = new wxMenu;
866 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
867 * this is selected, such legs are not shown. */
868 splaymenu->AppendCheckItem(menu_SPLAYS_HIDE, wmsg(/*&Hide*/407));
869 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
870 * this is selected, aven will show such legs with dashed lines. */
871 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_DASHED, wmsg(/*&Dashed*/250));
872 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
873 * this is selected, aven will show such legs with less bright colours. */
874 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_FADED, wmsg(/*&Fade*/408));
875 /* TRANSLATORS: Item in the "Splay Legs" and "Duplicate Legs" submenus - if
876 * this is selected, such legs are shown the same as other legs. */
877 splaymenu->AppendCheckItem(menu_SPLAYS_SHOW_NORMAL, wmsg(/*&Show*/409));
878 viewmenu->Append(menu_VIEW_SPLAYS, wmsg(/*Spla&y Legs*/406), splaymenu);
880 wxMenu* dupemenu = new wxMenu;
881 dupemenu->AppendCheckItem(menu_DUPES_HIDE, wmsg(/*&Hide*/407));
882 dupemenu->AppendCheckItem(menu_DUPES_SHOW_DASHED, wmsg(/*&Dashed*/250));
883 dupemenu->AppendCheckItem(menu_DUPES_SHOW_FADED, wmsg(/*&Fade*/408));
884 dupemenu->AppendCheckItem(menu_DUPES_SHOW_NORMAL, wmsg(/*&Show*/409));
885 viewmenu->Append(menu_VIEW_DUPES, wmsg(/*&Duplicate Legs*/251), dupemenu);
887 viewmenu->AppendSeparator();
888 viewmenu->AppendCheckItem(menu_VIEW_SHOW_OVERLAPPING_NAMES, wmsg(/*&Overlapping Names*/273));
890 wxMenu* colourbymenu = new wxMenu;
891 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292));
892 colourbymenu->AppendCheckItem(menu_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293));
893 colourbymenu->AppendCheckItem(menu_COLOUR_BY_ERROR, wmsg(/*Colour by &Error*/289));
894 colourbymenu->AppendCheckItem(menu_COLOUR_BY_GRADIENT, wmsg(/*Colour by &Gradient*/85));
895 colourbymenu->AppendCheckItem(menu_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82));
896 colourbymenu->AppendCheckItem(menu_COLOUR_BY_SURVEY, wmsg(/*Colour by &Survey*/448));
898 viewmenu->Append(menu_VIEW_COLOUR_BY, wmsg(/*Co&lour by*/450), colourbymenu);
900 viewmenu->AppendSeparator();
901 viewmenu->AppendCheckItem(menu_VIEW_SHOW_ENTRANCES, wmsg(/*Highlight &Entrances*/294));
902 viewmenu->AppendCheckItem(menu_VIEW_SHOW_FIXED_PTS, wmsg(/*Highlight &Fixed Points*/295));
903 viewmenu->AppendCheckItem(menu_VIEW_SHOW_EXPORTED_PTS, wmsg(/*Highlight E&xported Points*/296));
904 viewmenu->AppendSeparator();
905 #else
906 /* TRANSLATORS: Please don't translate "Escape" - that's the shortcut key
907 * to use which wxWidgets needs to parse and it should then handle
908 * translating.
910 viewmenu-> Append(menu_VIEW_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
911 #endif
912 viewmenu->AppendCheckItem(menu_VIEW_PERSPECTIVE, wmsg(/*&Perspective*/237));
913 // FIXME: enable this viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_SHADING, wmsg(/*&Smooth Shading*/?!?);
914 viewmenu->AppendCheckItem(menu_VIEW_TEXTURED, wmsg(/*Textured &Walls*/238));
915 /* TRANSLATORS: Toggles OpenGL "Depth Fogging" - feel free to translate
916 * using that term instead if it gives a better translation which most
917 * users will understand. */
918 viewmenu->AppendCheckItem(menu_VIEW_FOG, wmsg(/*Fade Distant Ob&jects*/239));
919 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
920 * "survey stations". */
921 viewmenu->AppendCheckItem(menu_VIEW_SMOOTH_LINES, wmsg(/*Smoot&hed Survey Legs*/298));
922 viewmenu->AppendSeparator();
923 #ifdef __WXMAC__
924 // F11 on OS X is used by the desktop (for speaker volume and/or window
925 // navigation). The standard OS X shortcut for full screen mode is
926 // Ctrl-Command-F which in wxWidgets terms is RawCtrl+Ctrl+F.
927 wxString wxmac_fullscreen = wmsg(/*Full Screen &Mode\tF11*/356);
928 wxmac_fullscreen.Replace(wxT("\tF11"), wxT("\tRawCtrl+Ctrl+F"), false);
929 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wxmac_fullscreen);
930 // FIXME: On OS X, the standard wording here is "Enter Full Screen" and
931 // "Exit Full Screen", depending whether we are in full screen mode or not,
932 // and this isn't a checked menu item.
933 #else
934 viewmenu->AppendCheckItem(menu_VIEW_FULLSCREEN, wmsg(/*Full Screen &Mode\tF11*/356));
935 #endif
936 #ifdef PREFDLG
937 viewmenu->AppendSeparator();
938 viewmenu-> Append(wxID_PREFERENCES, wmsg(/*&Preferences...*/347));
939 #endif
941 #ifndef PREFDLG
942 wxMenu* ctlmenu = new wxMenu;
943 ctlmenu->AppendCheckItem(menu_CTL_REVERSE, wmsg(/*&Reverse Sense\tCtrl+R*/280));
944 ctlmenu->AppendSeparator();
945 #ifdef __WXGTK__
946 // wxGTK (at least with GTK+ v2.24), if we specify a short-cut here then
947 // the key handler isn't called, so we can't exit full screen mode on
948 // Escape. wxGTK doesn't actually show the "Escape" shortcut text in the
949 // menu item, so removing it doesn't make any visual difference, and doing
950 // so allows Escape to still cancel the measuring line, but also serve to
951 // exit full screen mode if no measuring line is shown.
952 wxString wxgtk_cancelline = wmsg(/*&Cancel Measuring Line\tEscape*/281);
953 wxgtk_cancelline.Replace(wxT("\tEscape"), wxT(""), false);
954 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wxgtk_cancelline);
955 #else
956 // With wxMac and wxMSW, we can have the short-cut on the menu and still
957 // have Escape handled by the key handler to exit full screen mode.
958 ctlmenu->Append(menu_CTL_CANCEL_DIST_LINE, wmsg(/*&Cancel Measuring Line\tEscape*/281));
959 #endif
960 ctlmenu->AppendSeparator();
961 wxMenu* indmenu = new wxMenu;
962 indmenu->AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Compass*/274));
963 indmenu->AppendCheckItem(menu_IND_CLINO, wmsg(/*C&linometer*/275));
964 /* TRANSLATORS: The "Colour Key" is the thing in aven showing which colour
965 * corresponds to which depth, date, survey closure error, etc. */
966 indmenu->AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*Colour &Key*/276));
967 indmenu->AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Scale Bar*/277));
968 ctlmenu->Append(menu_CTL_INDICATORS, wmsg(/*&Indicators*/299), indmenu);
969 ctlmenu->AppendCheckItem(menu_CTL_SIDE_PANEL, wmsg(/*&Side Panel*/337));
970 ctlmenu->AppendSeparator();
971 ctlmenu->AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342));
972 ctlmenu->AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343));
973 ctlmenu->AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430));
974 #endif
976 wxMenuBar* menubar = new wxMenuBar();
977 /* TRANSLATORS: Aven menu titles. An “&” goes before the letter of any
978 * accelerator key. The accelerators must be different within this group
980 menubar->Append(filemenu, wmsg(/*&File*/210));
981 menubar->Append(rotmenu, wmsg(/*&Rotation*/211));
982 menubar->Append(orientmenu, wmsg(/*&Orientation*/212));
983 menubar->Append(viewmenu, wmsg(/*&View*/213));
984 #ifndef PREFDLG
985 menubar->Append(ctlmenu, wmsg(/*&Controls*/214));
986 #endif
987 // TRANSLATORS: "Presentation" in the sense of a talk with a slideshow -
988 // the items in this menu allow the user to animate between preset
989 // views.
990 menubar->Append(presmenu, wmsg(/*&Presentation*/216));
991 #ifndef __WXMAC__
992 // On wxMac the "About" menu item will be moved elsewhere, so we suppress
993 // this menu since it will then be empty.
994 wxMenu* helpmenu = new wxMenu;
995 helpmenu->Append(wxID_ABOUT);
997 menubar->Append(helpmenu, wmsg(/*&Help*/215));
998 #endif
999 SetMenuBar(menubar);
1002 void MainFrm::MakeToolBar()
1004 // Make the toolbar.
1006 #ifdef USING_GENERIC_TOOLBAR
1007 // This OS-X-specific code is only needed to stop the toolbar icons getting
1008 // scaled up, which just makes them look nasty and fuzzy. Once we have
1009 // larger versions of the icons, we can drop this code.
1010 wxSystemOptions::SetOption(wxT("mac.toolbar.no-native"), 1);
1011 wxToolBar* toolbar = new wxToolBar(this, wxID_ANY, wxDefaultPosition,
1012 wxDefaultSize, wxNO_BORDER|wxTB_FLAT|wxTB_NODIVIDER|wxTB_NOALIGN);
1013 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
1014 sizer->Add(toolbar, 0, wxEXPAND);
1015 SetSizer(sizer);
1016 #else
1017 wxToolBar* toolbar = wxFrame::CreateToolBar();
1018 #endif
1020 #ifndef __WXGTK20__
1021 toolbar->SetMargins(5, 5);
1022 #endif
1024 // FIXME: TRANSLATE tooltips
1025 toolbar->AddTool(wxID_OPEN, wxT("Open"), TOOL(open), wxT("Open a survey file for viewing"));
1026 toolbar->AddTool(menu_PRES_OPEN, wxT("Open presentation"), TOOL(open_pres), wxT("Open a presentation"));
1027 toolbar->AddCheckTool(menu_FILE_LOG, wxT("View log"), TOOL(log), wxNullBitmap, wxT("View log from processing survey data"));
1028 toolbar->AddSeparator();
1029 toolbar->AddCheckTool(menu_ROTATION_TOGGLE, wxT("Toggle rotation"), TOOL(rotation), wxNullBitmap, wxT("Toggle rotation"));
1030 toolbar->AddTool(menu_ORIENT_PLAN, wxT("Plan"), TOOL(plan), wxT("Switch to plan view"));
1031 toolbar->AddTool(menu_ORIENT_ELEVATION, wxT("Elevation"), TOOL(elevation), wxT("Switch to elevation view"));
1032 toolbar->AddTool(menu_ORIENT_DEFAULTS, wxT("Default view"), TOOL(defaults), wxT("Restore default view"));
1033 toolbar->AddSeparator();
1034 toolbar->AddCheckTool(menu_VIEW_SHOW_NAMES, wxT("Names"), TOOL(names), wxNullBitmap, wxT("Show station names"));
1035 toolbar->AddCheckTool(menu_VIEW_SHOW_CROSSES, wxT("Crosses"), TOOL(crosses), wxNullBitmap, wxT("Show crosses on stations"));
1036 toolbar->AddCheckTool(menu_VIEW_SHOW_ENTRANCES, wxT("Entrances"), TOOL(entrances), wxNullBitmap, wxT("Highlight entrances"));
1037 toolbar->AddCheckTool(menu_VIEW_SHOW_FIXED_PTS, wxT("Fixed points"), TOOL(fixed_pts), wxNullBitmap, wxT("Highlight fixed points"));
1038 toolbar->AddCheckTool(menu_VIEW_SHOW_EXPORTED_PTS, wxT("Exported points"), TOOL(exported_pts), wxNullBitmap, wxT("Highlight exported stations"));
1039 toolbar->AddSeparator();
1040 toolbar->AddCheckTool(menu_VIEW_SHOW_LEGS, wxT("Underground legs"), TOOL(ug_legs), wxNullBitmap, wxT("Show underground surveys"));
1041 toolbar->AddCheckTool(menu_VIEW_SHOW_SURFACE, wxT("Surface legs"), TOOL(surface_legs), wxNullBitmap, wxT("Show surface surveys"));
1042 toolbar->AddCheckTool(menu_VIEW_SHOW_TUBES, wxT("Tubes"), TOOL(tubes), wxNullBitmap, wxT("Show passage tubes"));
1043 toolbar->AddCheckTool(menu_VIEW_TERRAIN, wxT("Terrain"), TOOL(solid_surface), wxNullBitmap, wxT("Show terrain"));
1044 toolbar->AddSeparator();
1045 toolbar->AddCheckTool(menu_PRES_FREWIND, wxT("Fast Rewind"), TOOL(pres_frew), wxNullBitmap, wxT("Very Fast Rewind"));
1046 toolbar->AddCheckTool(menu_PRES_REWIND, wxT("Rewind"), TOOL(pres_rew), wxNullBitmap, wxT("Fast Rewind"));
1047 toolbar->AddCheckTool(menu_PRES_REVERSE, wxT("Backwards"), TOOL(pres_go_back), wxNullBitmap, wxT("Play Backwards"));
1048 toolbar->AddCheckTool(menu_PRES_PAUSE, wxT("Pause"), TOOL(pres_pause), wxNullBitmap, wxT("Pause"));
1049 toolbar->AddCheckTool(menu_PRES_PLAY, wxT("Go"), TOOL(pres_go), wxNullBitmap, wxT("Play"));
1050 toolbar->AddCheckTool(menu_PRES_FF, wxT("FF"), TOOL(pres_ff), wxNullBitmap, wxT("Fast Forward"));
1051 toolbar->AddCheckTool(menu_PRES_FFF, wxT("Very FF"), TOOL(pres_fff), wxNullBitmap, wxT("Very Fast Forward"));
1052 toolbar->AddTool(wxID_STOP, wxT("Stop"), TOOL(pres_stop), wxT("Stop"));
1054 toolbar->AddSeparator();
1055 m_FindBox = new wxTextCtrl(toolbar, textctrl_FIND, wxString(), wxDefaultPosition,
1056 wxDefaultSize, wxTE_PROCESS_ENTER);
1057 toolbar->AddControl(m_FindBox);
1058 /* TRANSLATORS: "Find stations" button tooltip */
1059 toolbar->AddTool(wxID_FIND, wmsg(/*Find*/332), TOOL(find)/*, "Search for station name"*/);
1060 /* TRANSLATORS: "Hide stations" button default tooltip */
1061 toolbar->AddTool(button_HIDE, wmsg(/*Hide*/333), TOOL(hideresults)/*, "Hide search results"*/);
1063 toolbar->Realize();
1066 void MainFrm::CreateSidePanel()
1068 m_Splitter = new AvenSplitterWindow(this);
1069 #ifdef USING_GENERIC_TOOLBAR
1070 // This OS-X-specific code is only needed to stop the toolbar icons getting
1071 // scaled up, which just makes them look nasty and fuzzy. Once we have
1072 // larger versions of the icons, we can drop this code.
1073 GetSizer()->Add(m_Splitter, 1, wxEXPAND);
1074 Layout();
1075 #endif
1077 m_Notebook = new wxNotebook(m_Splitter, 400, wxDefaultPosition,
1078 wxDefaultSize,
1079 wxBK_BOTTOM | wxBK_LEFT);
1080 m_Notebook->Show(false);
1082 wxPanel * panel = new wxPanel(m_Notebook);
1083 m_Tree = new AvenTreeCtrl(this, panel);
1085 // m_RegexpCheckBox = new wxCheckBox(find_panel, -1,
1086 // msg(/*Regular expression*/));
1088 wxBoxSizer *panel_sizer = new wxBoxSizer(wxVERTICAL);
1089 panel_sizer->Add(m_Tree, 1, wxALL | wxEXPAND, 2);
1090 panel->SetAutoLayout(true);
1091 panel->SetSizer(panel_sizer);
1092 // panel_sizer->SetSizeHints(panel);
1094 m_Control = new GUIControl();
1095 m_Gfx = new GfxCore(this, m_Splitter, m_Control);
1096 m_Control->SetView(m_Gfx);
1098 // Presentation panel:
1099 wxPanel * prespanel = new wxPanel(m_Notebook);
1101 m_PresList = new AvenPresList(this, prespanel, m_Gfx);
1103 wxBoxSizer *pres_panel_sizer = new wxBoxSizer(wxVERTICAL);
1104 pres_panel_sizer->Add(m_PresList, 1, wxALL | wxEXPAND, 2);
1105 prespanel->SetAutoLayout(true);
1106 prespanel->SetSizer(pres_panel_sizer);
1108 // Overall tabbed structure:
1109 // FIXME: this assumes images are 15x15
1110 wxImageList* image_list = new wxImageList(15, 15);
1111 image_list->Add(TOOL(survey_tree));
1112 image_list->Add(TOOL(pres_tree));
1113 m_Notebook->SetImageList(image_list);
1114 /* TRANSLATORS: labels for tabbed side panel this is for the tab with the
1115 * tree hierarchy of survey station names */
1116 m_Notebook->AddPage(panel, wmsg(/*Surveys*/376), true, 0);
1117 m_Notebook->AddPage(prespanel, wmsg(/*Presentation*/377), false, 1);
1119 m_Splitter->Initialize(m_Gfx);
1122 bool MainFrm::LoadData(const wxString& file, const wxString& prefix)
1124 // Load survey data from file, centre the dataset around the origin,
1125 // and prepare the data for drawing.
1127 #if 0
1128 wxStopWatch timer;
1129 timer.Start();
1130 #endif
1132 int err_msg_code = Model::Load(file, prefix);
1133 if (err_msg_code) {
1134 wxString m = wxString::Format(wmsg(err_msg_code), file.c_str());
1135 wxGetApp().ReportError(m);
1136 return false;
1139 // Update window title.
1140 SetTitle(GetSurveyTitle() + " - " APP_NAME);
1142 // Sort the labels ready for filling the tree.
1143 m_Labels.sort(LabelCmp(GetSeparator()));
1145 // Fill the tree of stations and prefixes.
1146 wxString root_name = wxFileNameFromPath(file);
1147 if (!prefix.empty()) {
1148 root_name += " (";
1149 root_name += prefix;
1150 root_name += ")";
1152 m_Tree->FillTree(root_name);
1154 // Sort labels so that entrances are displayed in preference,
1155 // then fixed points, then exported points, then other points.
1157 // Also sort by leaf name so that we'll tend to choose labels
1158 // from different surveys, rather than labels from surveys which
1159 // are earlier in the list.
1160 m_Labels.sort(LabelPlotCmp(GetSeparator()));
1162 if (!m_FindBox->GetValue().empty()) {
1163 // Highlight any stations matching the current search.
1164 DoFind();
1167 m_FileProcessed = file;
1169 return true;
1172 #if 0
1173 // Run along a newly read in traverse and make up plausible LRUD where
1174 // it is missing.
1175 void
1176 MainFrm::FixLRUD(traverse & centreline)
1178 assert(centreline.size() > 1);
1180 Double last_size = 0;
1181 vector<PointInfo>::iterator i = centreline.begin();
1182 while (i != centreline.end()) {
1183 // Get the coordinates of this vertex.
1184 Point & pt_v = *i++;
1185 Double size;
1187 if (i != centreline.end()) {
1188 Double h = sqrd(i->GetX() - pt_v.GetX()) +
1189 sqrd(i->GetY() - pt_v.GetY());
1190 Double v = sqrd(i->GetZ() - pt_v.GetZ());
1191 if (h + v > 30.0 * 30.0) {
1192 Double scale = 30.0 / sqrt(h + v);
1193 h *= scale;
1194 v *= scale;
1196 size = sqrt(h + v / 9);
1197 size /= 4;
1198 if (i == centreline.begin() + 1) {
1199 // First segment.
1200 last_size = size;
1201 } else {
1202 // Intermediate segment.
1203 swap(size, last_size);
1204 size += last_size;
1205 size /= 2;
1207 } else {
1208 // Last segment.
1209 size = last_size;
1212 Double & l = pt_v.l;
1213 Double & r = pt_v.r;
1214 Double & u = pt_v.u;
1215 Double & d = pt_v.d;
1217 if (l == 0 && r == 0 && u == 0 && d == 0) {
1218 l = r = u = d = -size;
1219 } else {
1220 if (l < 0 && r < 0) {
1221 l = r = -size;
1222 } else if (l < 0) {
1223 l = -(2 * size - r);
1224 if (l >= 0) l = -0.01;
1225 } else if (r < 0) {
1226 r = -(2 * size - l);
1227 if (r >= 0) r = -0.01;
1229 if (u < 0 && d < 0) {
1230 u = d = -size;
1231 } else if (u < 0) {
1232 u = -(2 * size - d);
1233 if (u >= 0) u = -0.01;
1234 } else if (d < 0) {
1235 d = -(2 * size - u);
1236 if (d >= 0) d = -0.01;
1241 #endif
1243 void MainFrm::OnMRUFile(wxCommandEvent& event)
1245 wxString f(m_history.GetHistoryFile(event.GetId() - wxID_FILE1));
1246 if (!f.empty()) OpenFile(f);
1249 void MainFrm::AddToFileHistory(const wxString & file)
1251 if (wxIsAbsolutePath(file)) {
1252 m_history.AddFileToHistory(file);
1253 } else {
1254 wxString abs = wxGetCwd();
1255 abs += wxCONFIG_PATH_SEPARATOR;
1256 abs += file;
1257 m_history.AddFileToHistory(abs);
1259 wxConfigBase *b = wxConfigBase::Get();
1260 m_history.Save(*b);
1261 b->Flush();
1264 void MainFrm::OpenFile(const wxString& file, const wxString& survey)
1266 wxBusyCursor hourglass;
1268 // Check if this is an unprocessed survey data file.
1269 if (file.length() > 4 && file[file.length() - 4] == '.') {
1270 wxString ext(file, file.length() - 3, 3);
1271 ext.MakeLower();
1272 if (ext == wxT("svx") || ext == wxT("dat") || ext == wxT("mak")) {
1273 CavernLogWindow * log = new CavernLogWindow(this, survey, m_Splitter);
1274 wxWindow * win = m_Splitter->GetWindow1();
1275 m_Splitter->ReplaceWindow(win, log);
1276 win->Show(false);
1277 if (m_Splitter->GetWindow2() == NULL) {
1278 if (win != m_Gfx) win->Destroy();
1279 } else {
1280 if (m_Splitter->IsSplit()) m_Splitter->Unsplit();
1283 if (wxFileExists(file)) AddToFileHistory(file);
1284 log->process(file);
1285 // Log window will tell us to load file if it successfully completes.
1286 return;
1290 if (!LoadData(file, survey))
1291 return;
1292 AddToFileHistory(file);
1293 InitialiseAfterLoad(file, survey);
1295 // If aven is showing the log for a .svx file and you load a .3d file, then
1296 // at this point m_Log will be the log window for the .svx file, so destroy
1297 // it - it should never legitimately be set if we get here.
1298 if (m_Log) {
1299 m_Log->Destroy();
1300 m_Log = NULL;
1304 void MainFrm::InitialiseAfterLoad(const wxString & file, const wxString & prefix)
1306 if (m_SashPosition < 0) {
1307 // Calculate sane default width for side panel.
1308 int x;
1309 int y;
1310 GetClientSize(&x, &y);
1311 if (x < 600)
1312 x /= 3;
1313 else if (x < 1000)
1314 x = 200;
1315 else
1316 x /= 5;
1317 m_SashPosition = x;
1320 // Do this before we potentially delete the log window which may own the
1321 // wxString which parameter file refers to!
1322 bool same_file = (file == m_File);
1323 if (!same_file)
1324 m_File = file;
1325 m_Survey = prefix;
1327 wxWindow * win = NULL;
1328 if (m_Splitter->GetWindow2() == NULL) {
1329 win = m_Splitter->GetWindow1();
1330 if (win == m_Gfx) win = NULL;
1333 if (!IsFullScreen()) {
1334 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1335 } else {
1336 was_showing_sidepanel_before_fullscreen = true;
1339 m_Gfx->Initialise(same_file);
1341 if (win) {
1342 // FIXME: check it actually is the log window!
1343 if (m_Log && m_Log != win)
1344 m_Log->Destroy();
1345 m_Log = win;
1346 m_Log->Show(false);
1349 if (!IsFullScreen()) {
1350 m_Notebook->Show(true);
1353 m_Gfx->Show(true);
1354 m_Gfx->SetFocus();
1357 void MainFrm::HideLog(wxWindow * log_window)
1359 if (!IsFullScreen()) {
1360 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
1363 m_Log = log_window;
1364 m_Log->Show(false);
1366 if (!IsFullScreen()) {
1367 m_Notebook->Show(true);
1370 m_Gfx->Show(true);
1371 m_Gfx->SetFocus();
1375 // UI event handlers
1378 // For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx".
1379 #ifdef _WIN32
1380 # define CASE(X)
1381 #else
1382 # define CASE(X) ";" X
1383 #endif
1385 void MainFrm::OnOpen(wxCommandEvent&)
1387 AvenAllowOnTop ontop(this);
1388 #ifdef __WXMOTIF__
1389 wxString filetypes = wxT("*.3d");
1390 #else
1391 wxString filetypes;
1392 filetypes.Printf(wxT("%s|*.3d;*.svx;*.plt;*.plf;*.dat;*.mak;*.adj;*.sht;*.una;*.xyz"
1393 CASE("*.3D;*.SVX;*.PLT;*.PLF;*.DAT;*.MAK;*.ADJ;*.SHT;*.UNA;*.XYZ")
1394 "|%s|*.3d" CASE("*.3D")
1395 "|%s|*.svx" CASE("*.SVX")
1396 "|%s|*.plt;*.plf" CASE("*.PLT;*.PLF")
1397 "|%s|*.dat;*.mak" CASE("*.DAT;*.MAK")
1398 "|%s|*.adj;*.sht;*.una;*.xyz" CASE("*.ADJ;*.SHT;*.UNA;*.XYZ")
1399 "|%s|%s"),
1400 /* TRANSLATORS: Here "survey" is a "cave map" rather than
1401 * list of questions - it should be translated to the
1402 * terminology that cavers using the language would use.
1404 wmsg(/*All survey files*/229).c_str(),
1405 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
1406 * file extension, so neither should be translated. */
1407 wmsg(/*Survex 3d files*/207).c_str(),
1408 /* TRANSLATORS: Survex is the name of the software, and "svx" refers to a
1409 * file extension, so neither should be translated. */
1410 wmsg(/*Survex svx files*/329).c_str(),
1411 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1412 * surveying package, so probably shouldn’t be translated
1414 wmsg(/*Compass PLT files*/324).c_str(),
1415 /* TRANSLATORS: "Compass" as in Larry Fish’s cave
1416 * surveying package, so should not be translated
1418 wmsg(/*Compass DAT and MAK files*/330).c_str(),
1419 /* TRANSLATORS: "CMAP" is Bob Thrun’s cave surveying
1420 * package, so don’t translate it. */
1421 wmsg(/*CMAP XYZ files*/325).c_str(),
1422 wmsg(/*All files*/208).c_str(),
1423 wxFileSelectorDefaultWildcardStr);
1424 #endif
1425 /* TRANSLATORS: Here "survey" is a "cave map" rather than list of questions
1426 * - it should be translated to the terminology that cavers using the
1427 * language would use.
1429 * File->Open dialog: */
1430 wxFileDialog dlg(this, wmsg(/*Select a survey file to view*/206),
1431 wxString(), wxString(),
1432 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1433 if (dlg.ShowModal() == wxID_OK) {
1434 OpenFile(dlg.GetPath());
1438 void MainFrm::OnOpenTerrain(wxCommandEvent&)
1440 if (!m_Gfx) return;
1442 if (GetCSProj().empty()) {
1443 wxMessageBox(wxT("No coordinate system specified in survey data"));
1444 return;
1447 #ifdef __WXMOTIF__
1448 wxString filetypes = wxT("*.*");
1449 #else
1450 wxString filetypes;
1451 filetypes.Printf(wxT("%s|*.bil;*.hgt;*.zip" CASE("*.BIL;*.HGT;*.ZIP")
1452 "|%s|%s"),
1453 wmsg(/*Terrain files*/452).c_str(),
1454 wmsg(/*All files*/208).c_str(),
1455 wxFileSelectorDefaultWildcardStr);
1456 #endif
1457 /* TRANSLATORS: "Terrain file" being a digital model of the terrain (e.g. a
1458 * grid of height values). */
1459 wxFileDialog dlg(this, wmsg(/*Select a terrain file to view*/451),
1460 wxString(), wxString(),
1461 filetypes, wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1462 if (dlg.ShowModal() == wxID_OK && m_Gfx->LoadDEM(dlg.GetPath())) {
1463 if (!m_Gfx->DisplayingTerrain()) m_Gfx->ToggleTerrain();
1467 void MainFrm::OnShowLog(wxCommandEvent&)
1469 if (!m_Log) {
1470 HideLog(m_Splitter->GetWindow1());
1471 return;
1473 wxWindow * win = m_Splitter->GetWindow1();
1474 m_Splitter->ReplaceWindow(win, m_Log);
1475 win->Show(false);
1476 if (m_Splitter->IsSplit()) {
1477 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
1478 m_Splitter->Unsplit();
1480 m_Log->Show(true);
1481 m_Log->SetFocus();
1482 m_Log = NULL;
1485 void MainFrm::OnScreenshot(wxCommandEvent&)
1487 AvenAllowOnTop ontop(this);
1488 wxString baseleaf;
1489 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
1490 /* TRANSLATORS: title of the save screenshot dialog */
1491 wxFileDialog dlg(this, wmsg(/*Save Screenshot*/321), wxString(),
1492 baseleaf + wxT(".png"),
1493 wxT("*.png"), wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1494 if (dlg.ShowModal() == wxID_OK) {
1495 static bool png_handled = false;
1496 if (!png_handled) {
1497 #if 0 // FIXME : enable this to allow other export formats...
1498 ::wxInitAllImageHandlers();
1499 #else
1500 wxImage::AddHandler(new wxPNGHandler);
1501 #endif
1502 png_handled = true;
1504 if (!m_Gfx->SaveScreenshot(dlg.GetPath(), wxBITMAP_TYPE_PNG)) {
1505 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), dlg.GetPath().c_str()));
1510 void MainFrm::OnScreenshotUpdate(wxUpdateUIEvent& event)
1512 event.Enable(!m_File.empty());
1515 void MainFrm::OnFilePreferences(wxCommandEvent&)
1517 #ifdef PREFDLG
1518 m_PrefsDlg = new PrefsDlg(m_Gfx, this);
1519 m_PrefsDlg->Show(true);
1520 #endif
1523 void MainFrm::OnPrint(wxCommandEvent&)
1525 m_Gfx->OnPrint(m_File, GetSurveyTitle(), GetDateString());
1528 void MainFrm::PrintAndExit()
1530 m_Gfx->OnPrint(m_File, GetSurveyTitle(), GetDateString(), true);
1533 void MainFrm::OnPageSetup(wxCommandEvent&)
1535 wxPageSetupDialog dlg(this, wxGetApp().GetPageSetupDialogData());
1536 if (dlg.ShowModal() == wxID_OK) {
1537 wxGetApp().SetPageSetupDialogData(dlg.GetPageSetupData());
1541 void MainFrm::OnExport(wxCommandEvent&)
1543 m_Gfx->OnExport(m_File, GetSurveyTitle(), GetDateString());
1546 void MainFrm::OnExtend(wxCommandEvent&)
1548 wxString output = m_Survey;
1549 if (output.empty()) {
1550 wxFileName::SplitPath(m_File, NULL, NULL, &output, NULL, wxPATH_NATIVE);
1552 output += wxT("_extend.3d");
1554 AvenAllowOnTop ontop(this);
1555 #ifdef __WXMOTIF__
1556 wxString ext(wxT("*.3d"));
1557 #else
1558 /* TRANSLATORS: Survex is the name of the software, and "3d" refers to a
1559 * file extension, so neither should be translated. */
1560 wxString ext = wmsg(/*Survex 3d files*/207);
1561 ext += wxT("|*.3d");
1562 #endif
1563 wxFileDialog dlg(this, wmsg(/*Select an output filename*/319),
1564 wxString(), output, ext,
1565 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
1566 if (dlg.ShowModal() != wxID_OK) return;
1567 output = dlg.GetPath();
1569 wxString cmd = get_command_path(L"extend");
1570 cmd = escape_for_shell(cmd, false);
1571 if (!m_Survey.empty()) {
1572 cmd += wxT(" --survey=");
1573 cmd += escape_for_shell(m_Survey, false);
1575 cmd += wxT(" --show-breaks ");
1576 cmd += escape_for_shell(m_FileProcessed, true);
1577 cmd += wxT(" ");
1578 cmd += escape_for_shell(output, true);
1579 if (wxExecute(cmd, wxEXEC_SYNC) < 0) {
1580 wxString m;
1581 m.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd.c_str());
1582 m += wxT(" (");
1583 m += wxString(strerror(errno), wxConvUTF8);
1584 m += wxT(')');
1585 wxGetApp().ReportError(m);
1586 return;
1588 if (LoadData(output, wxString()))
1589 InitialiseAfterLoad(output, wxString());
1592 void MainFrm::OnQuit(wxCommandEvent&)
1594 if (m_PresList->Modified()) {
1595 AvenAllowOnTop ontop(this);
1596 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1597 /* TRANSLATORS: and the question in that box */
1598 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1599 /* TRANSLATORS: title of message box */
1600 wmsg(/*Modified Presentation*/326),
1601 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1602 return;
1605 wxConfigBase *b = wxConfigBase::Get();
1606 if (IsFullScreen()) {
1607 b->Write(wxT("width"), -2);
1608 b->DeleteEntry(wxT("height"));
1609 } else if (IsMaximized()) {
1610 b->Write(wxT("width"), -1);
1611 b->DeleteEntry(wxT("height"));
1612 } else {
1613 int width, height;
1614 GetSize(&width, &height);
1615 b->Write(wxT("width"), width);
1616 b->Write(wxT("height"), height);
1618 b->Flush();
1619 exit(0);
1622 void MainFrm::OnClose(wxCloseEvent&)
1624 wxCommandEvent dummy;
1625 OnQuit(dummy);
1628 void MainFrm::OnAbout(wxCommandEvent&)
1630 AvenAllowOnTop ontop(this);
1631 #ifdef __WXMAC__
1632 // GetIcon() returns an invalid wxIcon under OS X.
1633 AboutDlg dlg(this, wxICON(aven));
1634 #else
1635 AboutDlg dlg(this, GetIcon());
1636 #endif
1637 dlg.Centre();
1638 dlg.ShowModal();
1641 void MainFrm::UpdateStatusBar()
1643 if (!here_text.empty()) {
1644 GetStatusBar()->SetStatusText(here_text);
1645 GetStatusBar()->SetStatusText(dist_text, 1);
1646 } else if (!coords_text.empty()) {
1647 GetStatusBar()->SetStatusText(coords_text);
1648 GetStatusBar()->SetStatusText(distfree_text, 1);
1649 } else {
1650 GetStatusBar()->SetStatusText(wxString());
1651 GetStatusBar()->SetStatusText(wxString(), 1);
1655 void MainFrm::ClearTreeSelection()
1657 m_Tree->UnselectAll();
1658 m_Gfx->SetThere();
1659 ShowInfo();
1662 void MainFrm::ClearCoords()
1664 if (!coords_text.empty()) {
1665 coords_text = wxString();
1666 UpdateStatusBar();
1670 void MainFrm::SetCoords(const Vector3 &v)
1672 Double x = v.GetX();
1673 Double y = v.GetY();
1674 Double z = v.GetZ();
1675 int units;
1676 if (m_Gfx->GetMetric()) {
1677 units = /*m*/424;
1678 } else {
1679 x /= METRES_PER_FOOT;
1680 y /= METRES_PER_FOOT;
1681 z /= METRES_PER_FOOT;
1682 units = /*ft*/428;
1684 /* TRANSLATORS: show coordinates (N = North or Northing, E = East or
1685 * Easting) */
1686 coords_text.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1687 coords_text += wxString::Format(wxT(", %s %.2f%s"),
1688 wmsg(/*Altitude*/335).c_str(),
1689 z, wmsg(units).c_str());
1690 distfree_text = wxString();
1691 UpdateStatusBar();
1694 const LabelInfo * MainFrm::GetTreeSelection() const {
1695 wxTreeItemData* sel_wx;
1696 if (!m_Tree->GetSelectionData(&sel_wx)) return NULL;
1698 const TreeData* data = static_cast<const TreeData*>(sel_wx);
1699 if (!data->IsStation()) return NULL;
1701 return data->GetLabel();
1704 void MainFrm::SetCoords(Double x, Double y, const LabelInfo * there)
1706 wxString & s = coords_text;
1707 if (m_Gfx->GetMetric()) {
1708 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1709 } else {
1710 s.Printf(wmsg(/*%.2f E, %.2f N*/338),
1711 x / METRES_PER_FOOT, y / METRES_PER_FOOT);
1714 wxString & t = distfree_text;
1715 t = wxString();
1716 if (m_Gfx->ShowingMeasuringLine() && there) {
1717 auto offset = GetOffset();
1718 Vector3 delta(x - offset.GetX() - there->GetX(),
1719 y - offset.GetY() - there->GetY(), 0);
1720 Double dh = sqrt(delta.GetX()*delta.GetX() + delta.GetY()*delta.GetY());
1721 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
1722 if (brg < 0) brg += 360;
1724 wxString from_str;
1725 /* TRANSLATORS: Used in Aven:
1726 * From <stationname>: H 12.24m, Brg 234.5°
1728 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1729 int brg_unit;
1730 if (m_Gfx->GetDegrees()) {
1731 brg_unit = /*°*/344;
1732 } else {
1733 brg *= 400.0 / 360.0;
1734 brg_unit = /*ᵍ*/345;
1737 int units;
1738 if (m_Gfx->GetMetric()) {
1739 units = /*m*/424;
1740 } else {
1741 dh /= METRES_PER_FOOT;
1742 units = /*ft*/428;
1744 /* TRANSLATORS: "H" is short for "Horizontal", "Brg" for "Bearing" (as
1745 * in Compass bearing) */
1746 t.Printf(wmsg(/*%s: H %.2f%s, Brg %03.1f%s*/374),
1747 from_str.c_str(), dh, wmsg(units).c_str(),
1748 brg, wmsg(brg_unit).c_str());
1751 UpdateStatusBar();
1754 void MainFrm::SetAltitude(Double z, const LabelInfo * there)
1756 double alt = z;
1757 int units;
1758 if (m_Gfx->GetMetric()) {
1759 units = /*m*/424;
1760 } else {
1761 alt /= METRES_PER_FOOT;
1762 units = /*ft*/428;
1764 coords_text.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
1765 alt, wmsg(units).c_str());
1767 wxString & t = distfree_text;
1768 t = wxString();
1769 if (m_Gfx->ShowingMeasuringLine() && there) {
1770 Double dz = z - GetOffset().GetZ() - there->GetZ();
1772 wxString from_str;
1773 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1775 if (!m_Gfx->GetMetric()) {
1776 dz /= METRES_PER_FOOT;
1778 // TRANSLATORS: "V" is short for "Vertical"
1779 t.Printf(wmsg(/*%s: V %.2f%s*/375), from_str.c_str(),
1780 dz, wmsg(units).c_str());
1783 UpdateStatusBar();
1786 void MainFrm::ShowInfo(const LabelInfo *here, const LabelInfo *there)
1788 assert(m_Gfx);
1790 if (!here) {
1791 m_Gfx->SetHere();
1792 m_Tree->SetHere(wxTreeItemId());
1793 // Don't clear "There" mark here.
1794 if (here_text.empty() && dist_text.empty()) return;
1795 here_text = wxString();
1796 dist_text = wxString();
1797 UpdateStatusBar();
1798 return;
1801 Vector3 v = *here + GetOffset();
1802 wxString & s = here_text;
1803 Double x = v.GetX();
1804 Double y = v.GetY();
1805 Double z = v.GetZ();
1806 int units;
1807 if (m_Gfx->GetMetric()) {
1808 units = /*m*/424;
1809 } else {
1810 x /= METRES_PER_FOOT;
1811 y /= METRES_PER_FOOT;
1812 z /= METRES_PER_FOOT;
1813 units = /*ft*/428;
1815 s.Printf(wmsg(/*%.2f E, %.2f N*/338), x, y);
1816 s += wxString::Format(wxT(", %s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
1817 z, wmsg(units).c_str());
1818 s += wxT(": ");
1819 s += here->name_or_anon();
1820 m_Gfx->SetHere(here);
1821 m_Tree->SetHere(here->tree_id);
1823 if (m_Gfx->ShowingMeasuringLine() && there) {
1824 Vector3 delta = *here - *there;
1826 Double d_horiz = sqrt(delta.GetX()*delta.GetX() +
1827 delta.GetY()*delta.GetY());
1828 Double dr = delta.magnitude();
1829 Double dz = delta.GetZ();
1831 Double brg = deg(atan2(delta.GetX(), delta.GetY()));
1832 if (brg < 0) brg += 360;
1834 Double grd = deg(atan2(delta.GetZ(), d_horiz));
1836 wxString from_str;
1837 from_str.Printf(wmsg(/*From %s*/339), there->name_or_anon().c_str());
1839 wxString hv_str;
1840 if (m_Gfx->GetMetric()) {
1841 units = /*m*/424;
1842 } else {
1843 d_horiz /= METRES_PER_FOOT;
1844 dr /= METRES_PER_FOOT;
1845 dz /= METRES_PER_FOOT;
1846 units = /*ft*/428;
1848 wxString len_unit = wmsg(units);
1849 /* TRANSLATORS: "H" is short for "Horizontal", "V" for "Vertical" */
1850 hv_str.Printf(wmsg(/*H %.2f%s, V %.2f%s*/340),
1851 d_horiz, len_unit.c_str(), dz, len_unit.c_str());
1852 int brg_unit;
1853 if (m_Gfx->GetDegrees()) {
1854 brg_unit = /*°*/344;
1855 } else {
1856 brg *= 400.0 / 360.0;
1857 brg_unit = /*ᵍ*/345;
1859 int grd_unit;
1860 wxString grd_str;
1861 if (m_Gfx->GetPercent()) {
1862 if (grd > 89.99) {
1863 grd = 1000000;
1864 } else if (grd < -89.99) {
1865 grd = -1000000;
1866 } else {
1867 grd = int(100 * tan(rad(grd)));
1869 if (grd > 99999 || grd < -99999) {
1870 grd_str = grd > 0 ? wxT("+") : wxT("-");
1871 /* TRANSLATORS: infinity symbol - used for the percentage gradient on
1872 * vertical angles. */
1873 grd_str += wmsg(/*∞*/431);
1875 grd_unit = /*%*/96;
1876 } else if (m_Gfx->GetDegrees()) {
1877 grd_unit = /*°*/344;
1878 } else {
1879 grd *= 400.0 / 360.0;
1880 grd_unit = /*ᵍ*/345;
1882 if (grd_str.empty()) {
1883 grd_str.Printf(wxT("%+02.1f%s"), grd, wmsg(grd_unit).c_str());
1886 wxString & d = dist_text;
1887 /* TRANSLATORS: "Dist" is short for "Distance", "Brg" for "Bearing" (as
1888 * in Compass bearing) and "Grd" for "Gradient" (the slope angle
1889 * measured by the clino) */
1890 d.Printf(wmsg(/*%s: %s, Dist %.2f%s, Brg %03.1f%s, Grd %s*/341),
1891 from_str.c_str(), hv_str.c_str(),
1892 dr, len_unit.c_str(),
1893 brg, wmsg(brg_unit).c_str(),
1894 grd_str.c_str());
1895 } else {
1896 dist_text = wxString();
1897 m_Gfx->SetThere();
1899 UpdateStatusBar();
1902 void MainFrm::DisplayTreeInfo(const wxTreeItemData* item)
1904 const TreeData* data = static_cast<const TreeData*>(item);
1905 if (data) {
1906 if (data->IsStation()) {
1907 m_Gfx->SetHereFromTree(data->GetLabel());
1908 } else {
1909 m_Gfx->SetHereSurvey(data->GetSurvey());
1910 ShowInfo();
1912 return;
1914 m_Gfx->SetHereSurvey(wxString());
1915 ShowInfo();
1918 void MainFrm::TreeItemSelected(const wxTreeItemData* item)
1920 const TreeData* data = static_cast<const TreeData*>(item);
1921 if (data && data->IsStation()) {
1922 const LabelInfo* label = data->GetLabel();
1923 if (m_Gfx->GetThere() == label) {
1924 m_Gfx->CentreOn(*label);
1925 } else {
1926 m_Gfx->SetThere(label);
1928 dist_text = wxString();
1929 // FIXME: Need to update dist_text (From ... etc)
1930 // But we don't currently know where "here" is at this point in the
1931 // code!
1932 } else {
1933 dist_text = wxString();
1934 m_Gfx->SetThere();
1935 if (!data) {
1936 // Must be the root.
1937 wxCommandEvent dummy;
1938 OnDefaults(dummy);
1939 } else {
1940 m_Gfx->ZoomToSurvey(data->GetSurvey());
1943 UpdateStatusBar();
1946 void MainFrm::OnPresNew(wxCommandEvent&)
1948 if (m_PresList->Modified()) {
1949 AvenAllowOnTop ontop(this);
1950 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1951 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1952 wmsg(/*Modified Presentation*/326),
1953 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1954 return;
1957 m_PresList->New(m_File);
1958 if (!ShowingSidePanel()) ToggleSidePanel();
1959 // Select the presentation page in the notebook.
1960 m_Notebook->SetSelection(1);
1963 void MainFrm::OnPresOpen(wxCommandEvent&)
1965 AvenAllowOnTop ontop(this);
1966 if (m_PresList->Modified()) {
1967 // FIXME: better to ask "Do you want to save your changes?" and offer [Save] [Discard] [Cancel]
1968 if (wxMessageBox(wmsg(/*The current presentation has been modified. Abandon unsaved changes?*/327),
1969 wmsg(/*Modified Presentation*/326),
1970 wxOK|wxCANCEL|wxICON_QUESTION) == wxCANCEL) {
1971 return;
1974 #ifdef __WXMOTIF__
1975 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
1976 wxT("*.fly"), wxFD_OPEN);
1977 #else
1978 wxFileDialog dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
1979 wxString::Format(wxT("%s|*.fly|%s|%s"),
1980 wmsg(/*Aven presentations*/320).c_str(),
1981 wmsg(/*All files*/208).c_str(),
1982 wxFileSelectorDefaultWildcardStr),
1983 wxFD_OPEN|wxFD_FILE_MUST_EXIST);
1984 #endif
1985 if (dlg.ShowModal() == wxID_OK) {
1986 if (!m_PresList->Load(dlg.GetPath())) {
1987 return;
1989 // FIXME : keep a history of loaded/saved presentations, like we do for
1990 // loaded surveys...
1991 // Select the presentation page in the notebook.
1992 m_Notebook->SetSelection(1);
1996 void MainFrm::OnPresSave(wxCommandEvent&)
1998 m_PresList->Save(true);
2001 void MainFrm::OnPresSaveAs(wxCommandEvent&)
2003 m_PresList->Save(false);
2006 void MainFrm::OnPresMark(wxCommandEvent&)
2008 m_PresList->AddMark();
2011 void MainFrm::OnPresFRewind(wxCommandEvent&)
2013 m_Gfx->PlayPres(-100);
2016 void MainFrm::OnPresRewind(wxCommandEvent&)
2018 m_Gfx->PlayPres(-10);
2021 void MainFrm::OnPresReverse(wxCommandEvent&)
2023 m_Gfx->PlayPres(-1);
2026 void MainFrm::OnPresPlay(wxCommandEvent&)
2028 m_Gfx->PlayPres(1);
2031 void MainFrm::OnPresFF(wxCommandEvent&)
2033 m_Gfx->PlayPres(10);
2036 void MainFrm::OnPresFFF(wxCommandEvent&)
2038 m_Gfx->PlayPres(100);
2041 void MainFrm::OnPresPause(wxCommandEvent&)
2043 m_Gfx->PlayPres(0);
2046 void MainFrm::OnPresStop(wxCommandEvent&)
2048 m_Gfx->PlayPres(0, false);
2051 void MainFrm::OnPresExportMovie(wxCommandEvent&)
2053 #ifdef WITH_LIBAV
2054 AvenAllowOnTop ontop(this);
2055 // FIXME : Taking the leaf of the currently loaded presentation as the
2056 // default might make more sense?
2057 wxString baseleaf;
2058 wxFileName::SplitPath(m_File, NULL, NULL, &baseleaf, NULL, wxPATH_NATIVE);
2059 wxFileDialog dlg(this, wmsg(/*Export Movie*/331), wxString(),
2060 baseleaf + wxT(".mp4"),
2061 wxT("MPEG|*.mp4|OGG|*.ogv|AVI|*.avi|QuickTime|*.mov|WMV|*.wmv;*.asf"),
2062 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
2063 if (dlg.ShowModal() == wxID_OK) {
2064 // Error is reported by GfxCore.
2065 (void)m_Gfx->ExportMovie(dlg.GetPath());
2067 #else
2068 wxGetApp().ReportError(wxT("Movie generation support code not present"));
2069 #endif
2072 PresentationMark MainFrm::GetPresMark(int which)
2074 return m_PresList->GetPresMark(which);
2077 void MainFrm::RestrictTo(const wxString & survey)
2079 // The station names will change, so clear the current search.
2080 wxCommandEvent dummy;
2081 OnHide(dummy);
2083 wxString new_prefix;
2084 if (!survey.empty()) {
2085 if (!m_Survey.empty()) {
2086 new_prefix = m_Survey;
2087 new_prefix += GetSeparator();
2089 new_prefix += survey;
2091 // Reload the processed data rather rather than potentially reprocessing.
2092 if (!LoadData(m_FileProcessed, new_prefix))
2093 return;
2094 InitialiseAfterLoad(m_File, new_prefix);
2097 void MainFrm::OnOpenTerrainUpdate(wxUpdateUIEvent& event)
2099 event.Enable(!m_File.empty());
2102 void MainFrm::OnPresNewUpdate(wxUpdateUIEvent& event)
2104 event.Enable(!m_File.empty());
2107 void MainFrm::OnPresOpenUpdate(wxUpdateUIEvent& event)
2109 event.Enable(!m_File.empty());
2112 void MainFrm::OnPresSaveUpdate(wxUpdateUIEvent& event)
2114 event.Enable(!m_PresList->Empty());
2117 void MainFrm::OnPresSaveAsUpdate(wxUpdateUIEvent& event)
2119 event.Enable(!m_PresList->Empty());
2122 void MainFrm::OnPresMarkUpdate(wxUpdateUIEvent& event)
2124 event.Enable(!m_File.empty());
2127 void MainFrm::OnPresFRewindUpdate(wxUpdateUIEvent& event)
2129 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2130 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() < -10);
2133 void MainFrm::OnPresRewindUpdate(wxUpdateUIEvent& event)
2135 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2136 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -10);
2139 void MainFrm::OnPresReverseUpdate(wxUpdateUIEvent& event)
2141 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2142 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == -1);
2145 void MainFrm::OnPresPlayUpdate(wxUpdateUIEvent& event)
2147 event.Enable(!m_PresList->Empty());
2148 event.Check(m_Gfx && m_Gfx->GetPresentationMode() &&
2149 m_Gfx->GetPresentationSpeed() == 1);
2152 void MainFrm::OnPresFFUpdate(wxUpdateUIEvent& event)
2154 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2155 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 10);
2158 void MainFrm::OnPresFFFUpdate(wxUpdateUIEvent& event)
2160 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2161 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() > 10);
2164 void MainFrm::OnPresPauseUpdate(wxUpdateUIEvent& event)
2166 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2167 event.Check(m_Gfx && m_Gfx->GetPresentationSpeed() == 0);
2170 void MainFrm::OnPresStopUpdate(wxUpdateUIEvent& event)
2172 event.Enable(m_Gfx && m_Gfx->GetPresentationMode());
2175 void MainFrm::OnPresExportMovieUpdate(wxUpdateUIEvent& event)
2177 event.Enable(!m_PresList->Empty());
2180 void MainFrm::OnFind(wxCommandEvent&)
2182 pending_find = true;
2185 void MainFrm::OnIdle(wxIdleEvent&)
2187 if (pending_find) {
2188 DoFind();
2192 void MainFrm::DoFind()
2194 pending_find = false;
2195 wxBusyCursor hourglass;
2196 // Find stations specified by a string or regular expression pattern.
2198 wxString pattern = m_FindBox->GetValue();
2199 if (pattern.empty()) {
2200 // Hide any search result highlights.
2201 list<LabelInfo*>::iterator pos = m_Labels.begin();
2202 while (pos != m_Labels.end()) {
2203 LabelInfo* label = *pos++;
2204 label->clear_flags(LFLAG_HIGHLIGHTED);
2206 m_NumHighlighted = 0;
2207 } else {
2208 int re_flags = wxRE_NOSUB;
2210 if (true /* case insensitive */) {
2211 re_flags |= wxRE_ICASE;
2214 bool substring = true;
2215 if (false /*m_RegexpCheckBox->GetValue()*/) {
2216 re_flags |= wxRE_EXTENDED;
2217 } else if (true /* simple glob-style */) {
2218 wxString pat;
2219 for (size_t i = 0; i < pattern.size(); i++) {
2220 wxChar ch = pattern[i];
2221 // ^ only special at start; $ at end. But this is simpler...
2222 switch (ch) {
2223 case '^': case '$': case '.': case '[': case '\\':
2224 pat += wxT('\\');
2225 pat += ch;
2226 break;
2227 case '*':
2228 pat += wxT(".*");
2229 substring = false;
2230 break;
2231 case '?':
2232 pat += wxT('.');
2233 substring = false;
2234 break;
2235 default:
2236 pat += ch;
2239 pattern = pat;
2240 re_flags |= wxRE_BASIC;
2241 } else {
2242 wxString pat;
2243 for (size_t i = 0; i < pattern.size(); i++) {
2244 wxChar ch = pattern[i];
2245 // ^ only special at start; $ at end. But this is simpler...
2246 switch (ch) {
2247 case '^': case '$': case '*': case '.': case '[': case '\\':
2248 pat += wxT('\\');
2250 pat += ch;
2252 pattern = pat;
2253 re_flags |= wxRE_BASIC;
2256 if (!substring) {
2257 // FIXME "0u" required to avoid compilation error with g++-3.0
2258 if (pattern.empty() || pattern[0u] != '^') pattern = wxT('^') + pattern;
2259 // FIXME: this fails to cope with "\$" at the end of pattern...
2260 if (pattern[pattern.size() - 1] != '$') pattern += wxT('$');
2263 wxRegEx regex;
2264 if (!regex.Compile(pattern, re_flags)) {
2265 wxBell();
2266 return;
2269 int found = 0;
2271 list<LabelInfo*>::iterator pos = m_Labels.begin();
2272 while (pos != m_Labels.end()) {
2273 LabelInfo* label = *pos++;
2275 if (regex.Matches(label->GetText())) {
2276 label->set_flags(LFLAG_HIGHLIGHTED);
2277 ++found;
2278 } else {
2279 label->clear_flags(LFLAG_HIGHLIGHTED);
2283 m_NumHighlighted = found;
2285 // Re-sort so highlighted points get names in preference
2286 if (found) m_Labels.sort(LabelPlotCmp(GetSeparator()));
2289 m_Gfx->UpdateBlobs();
2290 m_Gfx->ForceRefresh();
2292 if (!m_NumHighlighted) {
2293 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*No matches were found.*/328));
2294 } else {
2295 /* TRANSLATORS: "Hide stations" button tooltip when stations are found
2297 GetToolBar()->SetToolShortHelp(button_HIDE, wxString::Format(wmsg(/*Hide %d found stations*/334).c_str(), m_NumHighlighted));
2301 void MainFrm::OnGotoFound(wxCommandEvent&)
2303 if (!m_NumHighlighted) {
2304 wxGetApp().ReportError(wmsg(/*No matches were found.*/328));
2305 return;
2308 Double xmin = DBL_MAX;
2309 Double xmax = -DBL_MAX;
2310 Double ymin = DBL_MAX;
2311 Double ymax = -DBL_MAX;
2312 Double zmin = DBL_MAX;
2313 Double zmax = -DBL_MAX;
2315 list<LabelInfo*>::iterator pos = m_Labels.begin();
2316 while (pos != m_Labels.end()) {
2317 LabelInfo* label = *pos++;
2319 if (label->get_flags() & LFLAG_HIGHLIGHTED) {
2320 if (label->GetX() < xmin) xmin = label->GetX();
2321 if (label->GetX() > xmax) xmax = label->GetX();
2322 if (label->GetY() < ymin) ymin = label->GetY();
2323 if (label->GetY() > ymax) ymax = label->GetY();
2324 if (label->GetZ() < zmin) zmin = label->GetZ();
2325 if (label->GetZ() > zmax) zmax = label->GetZ();
2329 m_Gfx->SetViewTo(xmin, xmax, ymin, ymax, zmin, zmax);
2330 m_Gfx->SetFocus();
2333 void MainFrm::OnHide(wxCommandEvent&)
2335 m_FindBox->SetValue(wxString());
2336 GetToolBar()->SetToolShortHelp(button_HIDE, wmsg(/*Hide*/333));
2339 void MainFrm::OnHideUpdate(wxUpdateUIEvent& ui)
2341 ui.Enable(m_NumHighlighted != 0);
2344 void MainFrm::OnViewSidePanel(wxCommandEvent&)
2346 ToggleSidePanel();
2349 void MainFrm::ToggleSidePanel()
2351 // Toggle display of the side panel.
2353 assert(m_Gfx);
2355 if (m_Splitter->IsSplit()) {
2356 m_SashPosition = m_Splitter->GetSashPosition(); // save width of panel
2357 m_Splitter->Unsplit(m_Notebook);
2358 } else {
2359 m_Notebook->Show(true);
2360 m_Gfx->Show(true);
2361 m_Splitter->SplitVertically(m_Notebook, m_Gfx, m_SashPosition);
2365 void MainFrm::OnViewSidePanelUpdate(wxUpdateUIEvent& ui)
2367 ui.Enable(!m_File.empty());
2368 ui.Check(ShowingSidePanel());
2371 bool MainFrm::ShowingSidePanel()
2373 return m_Splitter->IsSplit();
2376 void MainFrm::ViewFullScreen() {
2377 #ifdef __WXMAC__
2378 // On OS X, wxWidgets doesn't currently hide the toolbar or statusbar in
2379 // full screen mode (last checked with 3.0.2), but it is easy to do
2380 // ourselves.
2381 if (!IsFullScreen()) {
2382 GetToolBar()->Hide();
2383 GetStatusBar()->Hide();
2385 #endif
2387 ShowFullScreen(!IsFullScreen());
2388 fullscreen_showing_menus = false;
2389 if (IsFullScreen())
2390 was_showing_sidepanel_before_fullscreen = ShowingSidePanel();
2391 if (was_showing_sidepanel_before_fullscreen)
2392 ToggleSidePanel();
2394 #ifdef __WXMAC__
2395 if (!IsFullScreen()) {
2396 GetStatusBar()->Show();
2397 GetToolBar()->Show();
2398 #ifdef USING_GENERIC_TOOLBAR
2399 Layout();
2400 #endif
2402 #endif
2405 bool MainFrm::FullScreenModeShowingMenus() const
2407 return fullscreen_showing_menus;
2410 void MainFrm::FullScreenModeShowMenus(bool show)
2412 if (!IsFullScreen() || show == fullscreen_showing_menus)
2413 return;
2414 #ifdef __WXMAC__
2415 // On OS X, enabling the menu bar while in full
2416 // screen mode doesn't have any effect, so instead
2417 // make moving the mouse to the top of the screen
2418 // drop us out of full screen mode for now.
2419 ViewFullScreen();
2420 #else
2421 GetMenuBar()->Show(show);
2422 fullscreen_showing_menus = show;
2423 #endif