4 // Main frame handling for Aven.
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
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
29 #include "cavernlog.h"
35 #include "img_hosted.h"
36 #include "namecompare.h"
41 #include <wx/confbase.h>
42 //#include <wx/filefn.h>
43 #include <wx/filename.h>
45 #include <wx/imaglist.h>
46 #include <wx/process.h>
48 #ifdef USING_GENERIC_TOOLBAR
49 # include <wx/sysopt.h>
61 #define TOOL(x) wxBitmap(wxT(#x), wxBITMAP_TYPE_PNG_RESOURCE)
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"
97 #define TOOL(x) wxBITMAP(x)
102 const static int img2aven_tab
[] = {
103 #include "img2aven.h"
109 flags
&= (sizeof(img2aven_tab
) / sizeof(img2aven_tab
[0]) - 1);
110 return img2aven_tab
[flags
];
113 class AvenSplitterWindow
: public wxSplitterWindow
{
117 explicit AvenSplitterWindow(MainFrm
*parent_
)
118 : wxSplitterWindow(parent_
, -1, wxDefaultPosition
, wxDefaultSize
,
124 void OnSplitterDClick(wxSplitterEvent
&) {
125 parent
->ToggleSidePanel();
129 DECLARE_EVENT_TABLE()
132 BEGIN_EVENT_TABLE(AvenSplitterWindow
, wxSplitterWindow
)
133 EVT_SPLITTER_DCLICK(-1, AvenSplitterWindow::OnSplitterDClick
)
136 class EditMarkDlg
: public wxDialog
{
137 wxTextCtrl
* easting
, * northing
, * altitude
;
138 wxTextCtrl
* angle
, * tilt_angle
, * scale
, * time
;
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
));
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
));
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
);
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
);
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
);
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
188 r5
->Add(new wxStaticText(this, 616, wmsg(/*Time: */279)), 0, wxALIGN_CENTRE_VERTICAL
);
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
);
201 buttons
->Add(ok
, 0, wxALL
, 8);
202 vert
->Add(buttons
, 0, wxALL
|wxALIGN_RIGHT
);
207 vert
->SetSizeHints(this);
209 PresentationMark
GetMark() const {
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] = '-';
220 return PresentationMark(v
, a
, t
, s
, T
);
224 DECLARE_EVENT_TABLE()
227 // Write a value without trailing zeros after the decimal point.
228 static void write_double(double d
, FILE * fh
) {
230 sprintf(buf
, "%.21f", d
);
231 char * p
= strchr(buf
, ',');
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
{
242 vector
<PresentationMark
> entries
;
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),
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
) {
267 } else if (current_item
> item
) {
270 entries
.erase(entries
.begin() + item
);
271 SetItemCount(entries
.size());
274 void OnDeleteAllItems(wxListEvent
&) {
276 SetItemCount(entries
.size());
277 filename
= wxString();
279 force_save_as
= true;
281 void OnListKeyDown(wxListEvent
& event
) {
282 switch (event
.GetKeyCode()) {
284 long item
= GetNextItem(-1, wxLIST_NEXT_ALL
,
285 wxLIST_STATE_SELECTED
);
288 // - 1 because the indices were shifted by DeleteItem()
289 item
= GetNextItem(item
- 1, wxLIST_NEXT_ALL
,
290 wxLIST_STATE_SELECTED
);
295 //printf("event.GetIndex() = %ld %d\n", event.GetIndex(), event.GetKeyCode());
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();
310 AddMark(item
, gfx
->GetView());
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()) {
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
]);
327 AddMark(current_item
);
331 // Already handled in OnListKeyDown.
333 case WXK_UP
: case WXK_DOWN
:
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());
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
];
354 case 0: v
= p
.GetX(); break;
355 case 1: v
= p
.GetY(); break;
356 case 2: v
= p
.GetZ(); break;
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;
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
);
372 wxString
ext(wxT("*.fly"));
374 wxString ext
= wmsg(/*Aven presentations*/320);
375 ext
+= wxT("|*.fly");
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;
384 FILE * fh_pres
= wxFopen(fnm
, wxT("w"));
386 wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file “%s”*/110), fnm
.c_str()));
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
);
394 write_double(p
.GetY(), fh_pres
);
396 write_double(p
.GetZ(), fh_pres
);
398 write_double(p
.angle
, fh_pres
);
400 write_double(p
.tilt_angle
, fh_pres
);
402 write_double(p
.scale
, fh_pres
);
405 write_double(p
.time
, fh_pres
);
412 force_save_as
= false;
414 void New(const wxString
&fnm
) {
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"));
424 m
.Printf(wmsg(/*Couldn’t open file “%s”*/24), fnm
.c_str());
425 wxGetApp().ReportError(m
);
430 while (!feof(fh_pres
)) {
433 while (i
< sizeof(buf
) - 1) {
434 int ch
= GETC(fh_pres
);
435 if (ch
== EOF
|| ch
== '\n' || ch
== '\r') break;
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
);
444 while ((p
= strchr(p
, '.'))) *p
++ = ',';
445 c
= sscanf(buf
, "%lf %lf %lf %lf %lf %lf %lf", &x
, &y
, &z
, &a
, &t
, &s
, &T
);
448 wxGetApp().ReportError(wxString::Format(wmsg(/*Error in format of presentation file “%s”*/323), fnm
.c_str()));
453 AddMark(item
, PresentationMark(Vector3(x
, y
, z
), a
, t
, s
, T
));
460 force_save_as
= false;
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
) {
469 } else if (which
== MARK_NEXT
) {
471 } else if (which
== MARK_PREV
) {
474 if (item
== -1 || item
== (long)entries
.size())
475 return PresentationMark();
476 if (item
!= current_item
) {
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
];
490 DECLARE_NO_COPY_CLASS(AvenPresList
)
491 DECLARE_EVENT_TABLE()
494 BEGIN_EVENT_TABLE(EditMarkDlg
, wxDialog
)
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
)
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
)
664 class LabelCmp
: public greater
<const LabelInfo
*> {
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
*> {
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();
680 wxString l1
= pt1
->GetText().AfterLast(separator
);
681 wxString l2
= pt2
->GetText().AfterLast(separator
);
682 n
= name_cmp(l1
, l2
, separator
);
684 // Prefer non-2-nodes...
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();
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
{
698 explicit DnDFile(MainFrm
*parent
) : m_Parent(parent
) { }
699 virtual bool OnDropFiles(wxCoord
, wxCoord
,
700 const wxArrayString
&filenames
);
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
715 wxGetApp().ReportError(wmsg(/*You may only view one 3d file at a time.*/336));
719 m_Parent
->OpenFile(filenames
[0]);
724 MainFrm::MainFrm(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
) :
725 wxFrame(NULL
, 101, title
, pos
, size
, wxDEFAULT_FRAME_STYLE
),
727 m_Gfx(NULL
), m_Log(NULL
),
728 m_NumEntrances(0), m_NumFixedPts(0), m_NumExportedPts(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)
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
));
742 SetIcon(wxICON(aven
));
745 #if wxCHECK_VERSION(3,1,0)
746 // Add a full screen button to the right upper corner of title bar under OS
748 EnableFullScreenView();
752 CreateStatusBar(2, wxST_SIZEGRIP
);
755 int widths
[2] = { -1 /* variable width */, -1 };
756 GetStatusBar()->SetStatusWidths(2, widths
);
758 #ifdef __X__ // wxMotif or wxX11
762 // X seems to require a forced resize.
763 SetSize(-1, -1, x
, y
);
766 #if wxUSE_DRAG_AND_DROP
767 SetDropTarget(new DnDFile(this));
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
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
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));
800 // On wxMac the "Quit" menu item will be moved elsewhere, so we suppress
802 filemenu
->AppendSeparator();
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"
808 filemenu
->Append(wxID_ABOUT
);
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
;
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();
895 viewmenu
-> Append(menu_VIEW_CANCEL_DIST_LINE
, wmsg(/*&Cancel Measuring Line\tEscape*/281));
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();
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.
919 viewmenu
->AppendCheckItem(menu_VIEW_FULLSCREEN
, wmsg(/*Full Screen &Mode\tF11*/356));
922 viewmenu
->AppendSeparator();
923 viewmenu
-> Append(wxID_PREFERENCES
, wmsg(/*&Preferences...*/347));
927 wxMenu
* ctlmenu
= new wxMenu
;
928 ctlmenu
->AppendCheckItem(menu_CTL_REVERSE
, wmsg(/*&Reverse Sense\tCtrl+R*/280));
929 ctlmenu
->AppendSeparator();
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
);
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));
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));
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));
970 menubar
->Append(ctlmenu
, wmsg(/*&Controls*/214));
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
975 menubar
->Append(presmenu
, wmsg(/*&Presentation*/216));
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));
987 void MainFrm::MakeToolBar()
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
);
1002 wxToolBar
* toolbar
= wxFrame::CreateToolBar();
1006 toolbar
->SetMargins(5, 5);
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"*/);
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
);
1062 m_Notebook
= new wxNotebook(m_Splitter
, 400, wxDefaultPosition
,
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.
1117 // Load the processed survey data.
1118 img
* survey
= img_open_survey(file
.utf8_str(), prefix
.utf8_str());
1120 wxString m
= wxString::Format(wmsg(img_error2msg(img_error())), file
.c_str());
1121 wxGetApp().ReportError(m
);
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.
1133 m_NumExportedPts
= 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.
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
;
1157 complete_dateinfo
= true;
1160 surface_traverses
.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
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();
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
1183 size_t n_traverses
= 0;
1184 size_t n_surface_traverses
= 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);
1195 result
= img_read_item(survey
, &pt
);
1198 n_traverses
= n_surface_traverses
= 0;
1199 pending_move
= true;
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
;
1214 date
+= (survey
->days2
- date
) / 2;
1215 if (date
< m_DateMin
) m_DateMin
= date
;
1216 if (date
> datemax
) datemax
= date
;
1218 complete_dateinfo
= false;
1221 if (survey
->flags
& img_FLAG_SPLAY
)
1223 bool is_surface
= (survey
->flags
& img_FLAG_SURFACE
);
1224 bool is_splay
= (survey
->flags
& img_FLAG_SPLAY
);
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).
1236 m_HasSurfaceLegs
= true;
1237 surface_traverses
.push_back(traverse());
1238 current_surface_traverse
= &surface_traverses
.back();
1239 ++n_surface_traverses
;
1241 m_HasUndergroundLegs
= true;
1242 traverses
.push_back(traverse());
1243 current_traverse
= &traverses
.back();
1244 current_traverse
->isSplay
= is_splay
;
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
;
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
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
;
1270 current_surface_traverse
->push_back(PointInfo(prev_pt
));
1272 current_traverse
->push_back(PointInfo(prev_pt
));
1277 current_surface_traverse
->push_back(PointInfo(pt
, date
));
1279 current_traverse
->push_back(PointInfo(pt
, date
));
1283 pending_move
= false;
1288 wxString
s(survey
->label
, wxConvUTF8
);
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
);
1296 // Or if that doesn't work (ConvCP1252 doesn't like
1297 // strings with some bytes in) let's just go for
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()) {
1307 if (label
->IsFixedPt()) {
1310 if (label
->IsExportedPt()) {
1313 m_Labels
.push_back(label
);
1318 if (!current_tube
) {
1319 // Start new current_tube.
1320 tubes
.push_back(vector
<XSect
>());
1321 current_tube
= &tubes
.back();
1325 wxString
label(survey
->label
, wxConvUTF8
);
1326 map
<wxString
, LabelInfo
*>::const_iterator p
;
1327 p
= labelmap
.find(label
);
1328 if (p
!= labelmap
.end()) {
1331 // Initialise labelmap lazily - we may have no
1333 list
<LabelInfo
*>::const_iterator i
;
1334 if (labelmap
.empty()) {
1335 i
= m_Labels
.begin();
1337 i
= last_mapped_label
;
1340 while (i
!= m_Labels
.end() && (*i
)->GetText() != label
) {
1341 labelmap
[(*i
)->GetText()] = *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
;
1356 labelmap
[label
] = lab
;
1359 int date
= survey
->days1
;
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
));
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
;
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!
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
;
1397 --n_surface_traverses
;
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
;
1417 // FIXME: Do we need to reset all these? - Olly
1419 m_NumExportedPts
= 0;
1421 m_HasUndergroundLegs
= false;
1422 m_HasSplays
= false;
1423 m_HasSurfaceLegs
= false;
1427 wxString m
= wxString::Format(wmsg(img_error2msg(img_error())), file
.c_str());
1428 wxGetApp().ReportError(m
);
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
;
1453 m_cs_proj
= wxString(survey
->cs
, wxConvUTF8
);
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
);
1463 /* TRANSLATORS: This is the date format string used to timestamp .3d
1464 * files internally. Probably best to keep it the same for all
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
);
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
);
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
) {
1506 m_DepthExt
= depthmax
- m_DepthMin
;
1507 m_DepthMin
-= m_Offsets
.GetZ();
1511 printf("time to load = %.3f\n", (double)timer
.Time());
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()) {
1524 root_name
+= prefix
;
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.
1542 m_FileProcessed
= file
;
1548 // Run along a newly read in traverse and make up plausible LRUD where
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
++;
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
);
1571 size
= sqrt(h
+ v
/ 9);
1573 if (i
== centreline
.begin() + 1) {
1577 // Intermediate segment.
1578 swap(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
;
1595 if (l
< 0 && r
< 0) {
1598 l
= -(2 * size
- r
);
1599 if (l
>= 0) l
= -0.01;
1601 r
= -(2 * size
- l
);
1602 if (r
>= 0) r
= -0.01;
1604 if (u
< 0 && d
< 0) {
1607 u
= -(2 * size
- d
);
1608 if (u
>= 0) u
= -0.01;
1610 d
= -(2 * size
- u
);
1611 if (d
>= 0) d
= -0.01;
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
;
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.
1671 bool ascent_only
= (prefix
.length() < current_prefix
.length() &&
1672 current_prefix
.StartsWith(prefix
) &&
1673 (current_prefix
[prefix
.length()] == separator
||
1676 // Find out how much of the current prefix and the new prefix
1678 // Note that we require a match of a whole number of parts
1680 size_t n
= min(prefix
.length(), current_prefix
.length());
1682 for (i
= 0; i
< n
&& prefix
[i
] == current_prefix
[i
]; ++i
) {
1683 if (prefix
[i
] == separator
) count
= i
+ 1;
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
++) {
1701 current_id
= previous_ids
.top();
1705 // Add branches for this new part.
1706 size_t next_dot
= count
- 1;
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
++;
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
++;
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
++;
1787 list
<LabelInfo
*>::iterator lpos
= m_Labels
.begin();
1788 while (lpos
!= m_Labels
.end()) {
1789 Point
& point
= **lpos
++;
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
);
1805 wxString abs
= wxGetCwd();
1806 abs
+= wxCONFIG_PATH_SEPARATOR
;
1808 m_history
.AddFileToHistory(abs
);
1810 wxConfigBase
*b
= wxConfigBase::Get();
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);
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
);
1828 if (m_Splitter
->GetWindow2() == NULL
) {
1829 if (win
!= m_Gfx
) win
->Destroy();
1831 if (m_Splitter
->IsSplit()) m_Splitter
->Unsplit();
1834 if (wxFileExists(file
)) AddToFileHistory(file
);
1836 // Log window will tell us to load file if it successfully completes.
1841 if (!LoadData(file
, survey
))
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.
1855 void MainFrm::InitialiseAfterLoad(const wxString
& file
, const wxString
& prefix
)
1857 if (m_SashPosition
< 0) {
1858 // Calculate sane default width for side panel.
1861 GetClientSize(&x
, &y
);
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
);
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
);
1887 was_showing_sidepanel_before_fullscreen
= true;
1890 m_Gfx
->Initialise(same_file
);
1893 // FIXME: check it actually is the log window!
1894 if (m_Log
&& m_Log
!= win
)
1900 if (!IsFullScreen()) {
1901 m_Notebook
->Show(true);
1908 void MainFrm::HideLog(wxWindow
* log_window
)
1910 if (!IsFullScreen()) {
1911 m_Splitter
->SplitVertically(m_Notebook
, m_Gfx
, m_SashPosition
);
1917 if (!IsFullScreen()) {
1918 m_Notebook
->Show(true);
1926 // UI event handlers
1929 // For Unix we want "*.svx;*.SVX" while for Windows we only want "*.svx".
1933 # define CASE(X) ";" X
1936 void MainFrm::OnOpen(wxCommandEvent
&)
1938 AvenAllowOnTop
ontop(this);
1940 wxString filetypes
= wxT("*.3d");
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")
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
);
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
&)
1993 if (m_cs_proj
.empty()) {
1994 wxMessageBox(wxT("No coordinate system specified in survey data"));
1999 wxString filetypes
= wxT("*.*");
2002 filetypes
.Printf(wxT("%s|*.bil;*.hgt;*.zip" CASE("*.BIL;*.HGT;*.ZIP")
2004 wmsg(/*Terrain files*/452).c_str(),
2005 wmsg(/*All files*/208).c_str(),
2006 wxFileSelectorDefaultWildcardStr
);
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
&)
2021 HideLog(m_Splitter
->GetWindow1());
2024 wxWindow
* win
= m_Splitter
->GetWindow1();
2025 m_Splitter
->ReplaceWindow(win
, m_Log
);
2027 if (m_Splitter
->IsSplit()) {
2028 m_SashPosition
= m_Splitter
->GetSashPosition(); // save width of panel
2029 m_Splitter
->Unsplit();
2036 void MainFrm::OnScreenshot(wxCommandEvent
&)
2038 AvenAllowOnTop
ontop(this);
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;
2048 #if 0 // FIXME : enable this to allow other export formats...
2049 ::wxInitAllImageHandlers();
2051 wxImage::AddHandler(new wxPNGHandler
);
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
&)
2069 m_PrefsDlg
= new PrefsDlg(m_Gfx
, this);
2070 m_PrefsDlg
->Show(true);
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);
2107 wxString
ext(wxT("*.3d"));
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");
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);
2129 cmd
+= escape_for_shell(output
, true);
2130 if (wxExecute(cmd
, wxEXEC_SYNC
) < 0) {
2132 m
.Printf(wmsg(/*Couldn’t run external command: “%s”*/17), cmd
.c_str());
2134 m
+= wxString(strerror(errno
), wxConvUTF8
);
2136 wxGetApp().ReportError(m
);
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
) {
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"));
2165 GetSize(&width
, &height
);
2166 b
->Write(wxT("width"), width
);
2167 b
->Write(wxT("height"), height
);
2173 void MainFrm::OnClose(wxCloseEvent
&)
2175 wxCommandEvent dummy
;
2179 void MainFrm::OnAbout(wxCommandEvent
&)
2181 AvenAllowOnTop
ontop(this);
2183 // GetIcon() returns an invalid wxIcon under OS X.
2184 AboutDlg
dlg(this, wxICON(aven
));
2186 AboutDlg
dlg(this, GetIcon());
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);
2201 GetStatusBar()->SetStatusText(wxString());
2202 GetStatusBar()->SetStatusText(wxString(), 1);
2206 void MainFrm::ClearTreeSelection()
2208 m_Tree
->UnselectAll();
2213 void MainFrm::ClearCoords()
2215 if (!coords_text
.empty()) {
2216 coords_text
= wxString();
2221 void MainFrm::SetCoords(const Vector3
&v
)
2223 Double x
= v
.GetX();
2224 Double y
= v
.GetY();
2225 Double z
= v
.GetZ();
2227 if (m_Gfx
->GetMetric()) {
2230 x
/= METRES_PER_FOOT
;
2231 y
/= METRES_PER_FOOT
;
2232 z
/= METRES_PER_FOOT
;
2235 /* TRANSLATORS: show coordinates (N = North or Northing, E = East or
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();
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
);
2261 s
.Printf(wmsg(/*%.2f E, %.2f N*/338),
2262 x
/ METRES_PER_FOOT
, y
/ METRES_PER_FOOT
);
2265 wxString
& t
= distfree_text
;
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;
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());
2281 if (m_Gfx
->GetDegrees()) {
2282 brg_unit
= /*°*/344;
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;
2294 if (m_Gfx
->GetMetric()) {
2297 dh
/= METRES_PER_FOOT
;
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());
2310 void MainFrm::SetAltitude(Double z
, const LabelInfo
* there
)
2314 if (m_Gfx
->GetMetric()) {
2317 alt
/= METRES_PER_FOOT
;
2320 coords_text
.Printf(wxT("%s %.2f%s"), wmsg(/*Altitude*/335).c_str(),
2321 alt
, wmsg(units
).c_str());
2323 wxString
& t
= distfree_text
;
2325 if (m_Gfx
->ShowingMeasuringLine() && there
) {
2326 Double dz
= z
- m_Offsets
.GetZ() - there
->GetZ();
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());
2342 void MainFrm::ShowInfo(const LabelInfo
*here
, const LabelInfo
*there
)
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();
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();
2363 if (m_Gfx
->GetMetric()) {
2366 x
/= METRES_PER_FOOT
;
2367 y
/= METRES_PER_FOOT
;
2368 z
/= METRES_PER_FOOT
;
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());
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;
2391 from_str
.Printf(wmsg(/*From %s*/339), there
->name_or_anon().c_str());
2394 if (m_Gfx
->GetMetric()) {
2397 d_horiz
/= METRES_PER_FOOT
;
2398 dr
/= METRES_PER_FOOT
;
2399 dz
/= METRES_PER_FOOT
;
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());
2407 if (m_Gfx
->GetDegrees()) {
2408 brg_unit
= /*°*/344;
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());
2420 dist_text
= wxString();
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());
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
2448 dist_text
= wxString();
2452 // Must be the root.
2453 m_FindBox
->SetValue(wxString());
2455 wxCommandEvent dummy
;
2458 } else if (data
&& !data
->IsStation()) {
2459 m_FindBox
->SetValue(data
->GetSurvey() + wxT(".*"));
2461 wxCommandEvent dummy
;
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
) {
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
) {
2497 wxFileDialog
dlg(this, wmsg(/*Select a presentation to open*/322), wxString(), wxString(),
2498 wxT("*.fly"), wxFD_OPEN
);
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
);
2507 if (dlg
.ShowModal() == wxID_OK
) {
2508 if (!m_PresList
->Load(dlg
.GetPath())) {
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
&)
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
&)
2568 void MainFrm::OnPresStop(wxCommandEvent
&)
2570 m_Gfx
->PlayPres(0, false);
2573 void MainFrm::OnPresExportMovie(wxCommandEvent
&)
2576 AvenAllowOnTop
ontop(this);
2577 // FIXME : Taking the leaf of the currently loaded presentation as the
2578 // default might make more sense?
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());
2590 wxGetApp().ReportError(wxT("Movie generation support code not present"));
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
;
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
))
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
&)
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;
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 */) {
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...
2745 case '^': case '$': case '.': case '[': case '\\':
2762 re_flags
|= wxRE_BASIC
;
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...
2769 case '^': case '$': case '*': case '.': case '[': case '\\':
2775 re_flags
|= wxRE_BASIC
;
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('$');
2786 if (!regex
.Compile(pattern
, re_flags
)) {
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
);
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));
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));
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
);
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
&)
2871 void MainFrm::ToggleSidePanel()
2873 // Toggle display of the side panel.
2877 if (m_Splitter
->IsSplit()) {
2878 m_SashPosition
= m_Splitter
->GetSashPosition(); // save width of panel
2879 m_Splitter
->Unsplit(m_Notebook
);
2881 m_Notebook
->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() {
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
2903 if (!IsFullScreen()) {
2904 GetToolBar()->Hide();
2905 GetStatusBar()->Hide();
2909 ShowFullScreen(!IsFullScreen());
2910 fullscreen_showing_menus
= false;
2912 was_showing_sidepanel_before_fullscreen
= ShowingSidePanel();
2913 if (was_showing_sidepanel_before_fullscreen
)
2917 if (!IsFullScreen()) {
2918 GetStatusBar()->Show();
2919 GetToolBar()->Show();
2920 #ifdef USING_GENERIC_TOOLBAR
2927 bool MainFrm::FullScreenModeShowingMenus() const
2929 return fullscreen_showing_menus
;
2932 void MainFrm::FullScreenModeShowMenus(bool show
)
2934 if (!IsFullScreen() || show
== fullscreen_showing_menus
)
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.
2943 GetMenuBar()->Show(show
);
2944 fullscreen_showing_menus
= show
;