Don't process key presses with unexpected modifiers
[survex.git] / src / guicontrol.cc
blob22ddfa3c2645c9ced8c7419d1c4614d1ad99f51d
1 //
2 // guicontrol.cc
3 //
4 // Handlers for events relating to the display of a survey.
5 //
6 // Copyright (C) 2000-2002,2005 Mark R. Shinwell
7 // Copyright (C) 2001,2003,2004,2005,2006,2011,2012,2014,2015,2016 Olly Betts
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include "guicontrol.h"
29 #include "gfxcore.h"
30 #include <wx/confbase.h>
32 const int DISPLAY_SHIFT = 10;
33 const double FLYFREE_SHIFT = 0.2;
34 const double ROTATE_STEP = 2.0;
36 GUIControl::GUIControl()
37 : dragging(NO_DRAG)
39 m_View = NULL;
40 m_ReverseControls = false;
41 m_LastDrag = drag_NONE;
44 void GUIControl::SetView(GfxCore* view)
46 m_View = view;
49 bool GUIControl::MouseDown() const
51 return (dragging != NO_DRAG);
54 void GUIControl::HandleTilt(wxPoint point)
56 // Handle a mouse movement during tilt mode.
58 // wxGTK (at least) fails to update the cursor while dragging.
59 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
61 int dy = point.y - m_DragStart.y;
63 if (m_ReverseControls != m_View->GetPerspective()) dy = -dy;
65 m_View->TiltCave(Double(dy) * 0.36);
67 m_DragStart = point;
69 m_View->ForceRefresh();
72 void GUIControl::HandleTranslate(wxPoint point)
74 // Handle a mouse movement during translation mode.
76 // wxGTK (at least) fails to update the cursor while dragging.
77 m_View->UpdateCursor(GfxCore::CURSOR_DRAGGING_HAND);
79 int dx = point.x - m_DragStart.x;
80 int dy = point.y - m_DragStart.y;
82 if (m_ReverseControls) {
83 dx = -dx;
84 dy = -dy;
87 if (m_View->GetPerspective())
88 m_View->MoveViewer(0, -dy * .1, dx * .1);
89 else
90 m_View->TranslateCave(dx, dy);
92 m_DragStart = point;
95 void GUIControl::HandleScaleRotate(wxPoint point)
97 // Handle a mouse movement during scale/rotate mode.
99 // wxGTK (at least) fails to update the cursor while dragging.
100 m_View->UpdateCursor(GfxCore::CURSOR_ZOOM_ROTATE);
102 int dx, dy;
103 int threshold;
104 if (m_ScaleRotateLock == lock_NONE) {
105 // Dragging to scale or rotate but we've not decided which yet.
106 dx = point.x - m_DragRealStart.x;
107 dy = point.y - m_DragRealStart.y;
108 threshold = 8 * 8;
109 } else {
110 dx = point.x - m_DragStart.x;
111 dy = point.y - m_DragStart.y;
112 threshold = 5;
114 int dx2 = dx * dx;
115 int dy2 = dy * dy;
116 if (dx2 + dy2 < threshold) return;
118 switch (m_ScaleRotateLock) {
119 case lock_NONE:
120 if (dx2 > dy2) {
121 m_ScaleRotateLock = lock_ROTATE;
122 // m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
123 } else {
124 m_ScaleRotateLock = lock_SCALE;
125 // m_View->UpdateCursor(GfxCore::CURSOR_ZOOM);
127 break;
128 case lock_SCALE:
129 if (dx2 >= 8 * dy2) {
130 m_ScaleRotateLock = lock_ROTATE;
131 // m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
133 break;
134 case lock_ROTATE:
135 if (dy2 >= 8 * dx2) {
136 m_ScaleRotateLock = lock_SCALE;
137 // m_View->UpdateCursor(GfxCore::CURSOR_ZOOM);
139 break;
142 if (m_ScaleRotateLock == lock_ROTATE) {
143 dy = 0;
144 } else {
145 dx = 0;
148 if (m_ReverseControls) {
149 dx = -dx;
150 dy = -dy;
153 if (m_View->GetPerspective()) {
154 if (dy) m_View->MoveViewer(-dy * .1, 0, 0);
155 } else {
156 // up/down => scale.
157 if (dy) m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
158 // left/right => rotate.
159 if (dx) m_View->TurnCave(Double(dx) * -0.36);
160 if (dx || dy) m_View->ForceRefresh();
163 m_DragStart = point;
166 void GUIControl::HandleTiltRotate(wxPoint point)
168 // Handle a mouse movement during tilt/rotate mode.
169 if (m_View->IsExtendedElevation()) return;
171 // wxGTK (at least) fails to update the cursor while dragging.
172 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
174 int dx = point.x - m_DragStart.x;
175 int dy = point.y - m_DragStart.y;
177 if (m_ReverseControls != m_View->GetPerspective()) {
178 dx = -dx;
179 dy = -dy;
182 // left/right => rotate, up/down => tilt.
183 // Make tilt less sensitive than rotate as that feels better.
184 m_View->TurnCave(Double(dx) * -0.36);
185 m_View->TiltCave(Double(dy) * 0.18);
187 m_View->ForceRefresh();
189 m_DragStart = point;
192 void GUIControl::HandleRotate(wxPoint point)
194 // Handle a mouse movement during rotate mode.
195 if (m_View->IsExtendedElevation()) return;
197 // wxGTK (at least) fails to update the cursor while dragging.
198 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
200 int dx = point.x - m_DragStart.x;
201 int dy = point.y - m_DragStart.y;
203 if (m_ReverseControls != m_View->GetPerspective()) {
204 dx = -dx;
205 dy = -dy;
208 // left/right => rotate.
209 m_View->TurnCave(Double(dx) * -0.36);
211 m_View->ForceRefresh();
213 m_DragStart = point;
216 void GUIControl::RestoreCursor()
218 if (m_View->HereIsReal()) {
219 m_View->UpdateCursor(GfxCore::CURSOR_POINTING_HAND);
220 } else {
221 m_View->UpdateCursor(GfxCore::CURSOR_DEFAULT);
225 void GUIControl::HandleNonDrag(const wxPoint & point) {
226 if (m_View->IsFullScreen()) {
227 if (m_View->FullScreenModeShowingMenus()) {
228 if (point.y > 8)
229 m_View->FullScreenModeShowMenus(false);
230 } else {
231 if (point.y == 0) {
232 m_View->FullScreenModeShowMenus(true);
236 if (m_View->CheckHitTestGrid(point, false)) {
237 m_View->UpdateCursor(GfxCore::CURSOR_POINTING_HAND);
238 } else if (m_View->PointWithinScaleBar(point)) {
239 m_View->UpdateCursor(GfxCore::CURSOR_HORIZONTAL_RESIZE);
240 } else if (m_View->PointWithinCompass(point)) {
241 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
242 } else if (m_View->PointWithinClino(point)) {
243 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
244 } else {
245 RestoreCursor();
250 // Mouse event handling methods
253 void GUIControl::OnMouseMove(wxMouseEvent& event)
255 // Mouse motion event handler.
256 if (!m_View->HasData()) return;
258 // Ignore moves which don't change the position.
259 if (event.GetPosition() == m_DragStart) {
260 return;
263 static long timestamp = LONG_MIN;
264 if (dragging != NO_DRAG && m_ScaleRotateLock != lock_NONE &&
265 timestamp != LONG_MIN) {
266 // If no motion for a second, reset the direction lock.
267 if (event.GetTimestamp() - timestamp >= 1000) {
268 m_ScaleRotateLock = lock_NONE;
269 m_DragRealStart = m_DragStart;
270 RestoreCursor();
273 timestamp = event.GetTimestamp();
275 wxPoint point(event.GetPosition());
277 // Check hit-test grid (only if no buttons are pressed).
278 if (!event.LeftIsDown() && !event.MiddleIsDown() && !event.RightIsDown()) {
279 HandleNonDrag(point);
282 // Update coordinate display if in plan view,
283 // or altitude if in elevation view.
284 m_View->SetCoords(point);
286 switch (dragging) {
287 case LEFT_DRAG:
288 switch (m_LastDrag) {
289 case drag_COMPASS:
290 // Drag in heading indicator.
291 m_View->SetCompassFromPoint(point);
292 break;
293 case drag_ELEV:
294 // Drag in clinometer.
295 m_View->SetClinoFromPoint(point);
296 break;
297 case drag_SCALE:
298 m_View->SetScaleBarFromOffset(point.x - m_DragLast.x);
299 break;
300 case drag_MAIN:
301 if (event.ControlDown()) {
302 HandleTiltRotate(point);
303 } else {
304 HandleScaleRotate(point);
306 break;
307 case drag_ZOOM:
308 m_View->SetZoomBox(m_DragStart, point, !event.ShiftDown(), event.ControlDown());
309 break;
310 case drag_NONE:
311 // Shouldn't happen?! FIXME: assert or something.
312 break;
314 break;
315 case MIDDLE_DRAG:
316 HandleTilt(point);
317 break;
318 case RIGHT_DRAG:
319 HandleTranslate(point);
320 break;
321 case NO_DRAG:
322 break;
325 m_DragLast = point;
328 void GUIControl::OnLButtonDown(wxMouseEvent& event)
330 if (m_View->HasData()) {
331 m_DragStart = m_DragRealStart = event.GetPosition();
333 if (m_View->PointWithinCompass(m_DragStart)) {
334 m_LastDrag = drag_COMPASS;
335 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
336 } else if (m_View->PointWithinClino(m_DragStart)) {
337 m_LastDrag = drag_ELEV;
338 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
339 } else if (m_View->PointWithinScaleBar(m_DragStart)) {
340 m_LastDrag = drag_SCALE;
341 m_View->UpdateCursor(GfxCore::CURSOR_HORIZONTAL_RESIZE);
342 } else if (event.ShiftDown()) {
343 m_LastDrag = drag_ZOOM;
344 m_View->UpdateCursor(GfxCore::CURSOR_ZOOM);
345 } else {
346 if (event.ControlDown() && !m_View->IsExtendedElevation()) {
347 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
348 } else {
349 m_View->UpdateCursor(GfxCore::CURSOR_ZOOM_ROTATE);
352 m_LastDrag = drag_MAIN;
353 m_ScaleRotateLock = lock_NONE;
356 // We need to release and recapture for the cursor to update (noticed
357 // with wxGTK).
358 if (dragging != NO_DRAG) m_View->ReleaseMouse();
359 m_View->CaptureMouse();
361 dragging = LEFT_DRAG;
365 void GUIControl::OnLButtonUp(wxMouseEvent& event)
367 if (m_View->HasData()) {
368 if (dragging != LEFT_DRAG)
369 return;
371 if (event.MiddleIsDown()) {
372 if (m_LastDrag == drag_ZOOM)
373 m_View->UnsetZoomBox();
374 OnMButtonDown(event);
375 return;
378 if (event.RightIsDown()) {
379 if (m_LastDrag == drag_ZOOM)
380 m_View->UnsetZoomBox();
381 OnRButtonDown(event);
382 return;
385 if (m_LastDrag == drag_ZOOM) {
386 m_View->ZoomBoxGo();
389 m_View->ReleaseMouse();
391 m_LastDrag = drag_NONE;
392 dragging = NO_DRAG;
394 m_View->DragFinished();
396 if (event.GetPosition() == m_DragRealStart) {
397 // Just a "click"...
398 m_View->CheckHitTestGrid(m_DragStart, true);
399 RestoreCursor();
400 } else {
401 HandleNonDrag(event.GetPosition());
406 void GUIControl::OnMButtonDown(wxMouseEvent& event)
408 if (m_View->HasData() && !m_View->IsExtendedElevation()) {
409 m_DragStart = event.GetPosition();
411 m_View->UpdateCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
413 if (dragging != NO_DRAG) {
414 if (m_LastDrag == drag_ZOOM)
415 m_View->UnsetZoomBox();
416 // We need to release and recapture for the cursor to update
417 // (noticed with wxGTK).
418 m_View->ReleaseMouse();
420 m_View->CaptureMouse();
421 dragging = MIDDLE_DRAG;
425 void GUIControl::OnMButtonUp(wxMouseEvent& event)
427 if (m_View->HasData()) {
428 if (dragging != MIDDLE_DRAG)
429 return;
431 if (event.LeftIsDown()) {
432 OnLButtonDown(event);
433 return;
436 if (event.RightIsDown()) {
437 OnRButtonDown(event);
438 return;
441 dragging = NO_DRAG;
442 m_View->ReleaseMouse();
443 m_View->DragFinished();
445 RestoreCursor();
449 void GUIControl::OnRButtonDown(wxMouseEvent& event)
451 if (m_View->HasData()) {
452 if (m_View->HandleRClick(event.GetPosition()))
453 return;
455 m_DragStart = event.GetPosition();
457 m_View->UpdateCursor(GfxCore::CURSOR_DRAGGING_HAND);
459 if (dragging != NO_DRAG) {
460 if (m_LastDrag == drag_ZOOM)
461 m_View->UnsetZoomBox();
462 // We need to release and recapture for the cursor to update
463 // (noticed with wxGTK).
464 m_View->ReleaseMouse();
466 m_View->CaptureMouse();
467 dragging = RIGHT_DRAG;
471 void GUIControl::OnRButtonUp(wxMouseEvent& event)
473 if (dragging != RIGHT_DRAG)
474 return;
476 if (event.LeftIsDown()) {
477 OnLButtonDown(event);
478 return;
481 if (event.MiddleIsDown()) {
482 OnMButtonDown(event);
483 return;
486 m_LastDrag = drag_NONE;
487 m_View->ReleaseMouse();
489 dragging = NO_DRAG;
491 RestoreCursor();
493 m_View->DragFinished();
496 void GUIControl::OnMouseWheel(wxMouseEvent& event) {
497 int dy = event.GetWheelRotation();
498 if (m_View->GetPerspective()) {
499 m_View->MoveViewer(-dy, 0, 0);
500 } else {
501 m_View->SetScale(m_View->GetScale() * pow(1.06, -0.04 * dy));
502 m_View->ForceRefresh();
506 void GUIControl::OnDisplayOverlappingNames()
508 m_View->ToggleOverlappingNames();
511 void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
513 cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
514 cmd.Check(m_View->ShowingOverlappingNames());
517 void GUIControl::OnColourByDepth()
519 if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
520 m_View->SetColourBy(COLOUR_BY_NONE);
521 } else {
522 m_View->SetColourBy(COLOUR_BY_DEPTH);
526 void GUIControl::OnColourByDate()
528 if (m_View->ColouringBy() == COLOUR_BY_DATE) {
529 m_View->SetColourBy(COLOUR_BY_NONE);
530 } else {
531 m_View->SetColourBy(COLOUR_BY_DATE);
535 void GUIControl::OnColourByError()
537 if (m_View->ColouringBy() == COLOUR_BY_ERROR) {
538 m_View->SetColourBy(COLOUR_BY_NONE);
539 } else {
540 m_View->SetColourBy(COLOUR_BY_ERROR);
544 void GUIControl::OnColourByGradient()
546 if (m_View->ColouringBy() == COLOUR_BY_GRADIENT) {
547 m_View->SetColourBy(COLOUR_BY_NONE);
548 } else {
549 m_View->SetColourBy(COLOUR_BY_GRADIENT);
553 void GUIControl::OnColourByLength()
555 if (m_View->ColouringBy() == COLOUR_BY_LENGTH) {
556 m_View->SetColourBy(COLOUR_BY_NONE);
557 } else {
558 m_View->SetColourBy(COLOUR_BY_LENGTH);
562 void GUIControl::OnColourByUpdate(wxUpdateUIEvent& cmd)
564 cmd.Enable(m_View->HasData());
567 void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
569 cmd.Enable(m_View->HasData());
570 cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
573 void GUIControl::OnColourByDateUpdate(wxUpdateUIEvent& cmd)
575 cmd.Enable(m_View->HasData());
576 cmd.Check(m_View->ColouringBy() == COLOUR_BY_DATE);
579 void GUIControl::OnColourByErrorUpdate(wxUpdateUIEvent& cmd)
581 cmd.Enable(m_View->HasData());
582 cmd.Check(m_View->ColouringBy() == COLOUR_BY_ERROR);
585 void GUIControl::OnColourByGradientUpdate(wxUpdateUIEvent& cmd)
587 cmd.Enable(m_View->HasData());
588 cmd.Check(m_View->ColouringBy() == COLOUR_BY_GRADIENT);
591 void GUIControl::OnColourByLengthUpdate(wxUpdateUIEvent& cmd)
593 cmd.Enable(m_View->HasData());
594 cmd.Check(m_View->ColouringBy() == COLOUR_BY_LENGTH);
597 void GUIControl::OnShowCrosses()
599 m_View->ToggleCrosses();
602 void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
604 cmd.Enable(m_View->HasData());
605 cmd.Check(m_View->ShowingCrosses());
608 void GUIControl::OnShowStationNames()
610 m_View->ToggleStationNames();
613 void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
615 cmd.Enable(m_View->HasData());
616 cmd.Check(m_View->ShowingStationNames());
619 void GUIControl::OnShowSurveyLegs()
621 m_View->ToggleUndergroundLegs();
624 void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
626 cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs());
627 cmd.Check(m_View->ShowingUndergroundLegs());
630 void GUIControl::OnHideSplays()
632 m_View->SetSplaysMode(SPLAYS_HIDE);
635 void GUIControl::OnShowSplaysNormal()
637 m_View->SetSplaysMode(SPLAYS_SHOW_NORMAL);
640 void GUIControl::OnShowSplaysFaded()
642 m_View->SetSplaysMode(SPLAYS_SHOW_FADED);
645 void GUIControl::OnSplaysUpdate(wxUpdateUIEvent& cmd)
647 cmd.Enable(m_View->HasData() && m_View->HasSplays());
650 void GUIControl::OnHideSplaysUpdate(wxUpdateUIEvent& cmd)
652 cmd.Enable(m_View->HasData() && m_View->HasSplays());
653 cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_HIDE);
656 void GUIControl::OnShowSplaysNormalUpdate(wxUpdateUIEvent& cmd)
658 cmd.Enable(m_View->HasData() && m_View->HasSplays());
659 cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_SHOW_NORMAL);
662 void GUIControl::OnShowSplaysFadedUpdate(wxUpdateUIEvent& cmd)
664 cmd.Enable(m_View->HasData() && m_View->HasSplays());
665 cmd.Check(m_View->ShowingSplaysMode() == SPLAYS_SHOW_FADED);
668 void GUIControl::OnMoveEast()
670 m_View->TurnCaveTo(90.0);
671 m_View->ForceRefresh();
674 void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
676 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && m_View->GetCompassValue() != 90.0);
679 void GUIControl::OnMoveNorth()
681 m_View->TurnCaveTo(0.0);
682 m_View->ForceRefresh();
685 void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
687 cmd.Enable(m_View->HasData() && m_View->GetCompassValue() != 0.0);
690 void GUIControl::OnMoveSouth()
692 m_View->TurnCaveTo(180.0);
693 m_View->ForceRefresh();
696 void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
698 cmd.Enable(m_View->HasData() && m_View->GetCompassValue() != 180.0);
701 void GUIControl::OnMoveWest()
703 m_View->TurnCaveTo(270.0);
704 m_View->ForceRefresh();
707 void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
709 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && m_View->GetCompassValue() != 270.0);
712 void GUIControl::OnToggleRotation()
714 m_View->ToggleRotation();
717 void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
719 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
720 cmd.Check(m_View->HasData() && m_View->IsRotating());
723 void GUIControl::OnReverseControls()
725 m_ReverseControls = !m_ReverseControls;
728 void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
730 cmd.Enable(m_View->HasData());
731 cmd.Check(m_ReverseControls);
734 void GUIControl::OnReverseDirectionOfRotation()
736 m_View->ReverseRotation();
739 void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
741 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
744 void GUIControl::OnStepOnceAnticlockwise(bool accel)
746 if (m_View->GetPerspective()) {
747 m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
748 } else {
749 m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
751 m_View->ForceRefresh();
754 void GUIControl::OnStepOnceClockwise(bool accel)
756 if (m_View->GetPerspective()) {
757 m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
758 } else {
759 m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
761 m_View->ForceRefresh();
764 void GUIControl::OnDefaults()
766 m_View->Defaults();
769 void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
771 cmd.Enable(m_View->HasData());
774 void GUIControl::OnElevation()
776 // Switch to elevation view.
778 m_View->SwitchToElevation();
781 void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
783 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingElevation());
786 void GUIControl::OnHigherViewpoint(bool accel)
788 // Raise the viewpoint.
789 if (m_View->GetPerspective()) {
790 m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
791 } else {
792 m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
794 m_View->ForceRefresh();
797 void GUIControl::OnLowerViewpoint(bool accel)
799 // Lower the viewpoint.
800 if (m_View->GetPerspective()) {
801 m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
802 } else {
803 m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
805 m_View->ForceRefresh();
808 void GUIControl::OnPlan()
810 // Switch to plan view.
811 m_View->SwitchToPlan();
814 void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
816 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingPlan());
819 void GUIControl::OnShiftDisplayDown(bool accel)
821 if (m_View->GetPerspective())
822 m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
823 else
824 m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
827 void GUIControl::OnShiftDisplayLeft(bool accel)
829 if (m_View->GetPerspective())
830 m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
831 else
832 m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
835 void GUIControl::OnShiftDisplayRight(bool accel)
837 if (m_View->GetPerspective())
838 m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
839 else
840 m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
843 void GUIControl::OnShiftDisplayUp(bool accel)
845 if (m_View->GetPerspective())
846 m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
847 else
848 m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
851 void GUIControl::OnZoomIn(bool accel)
853 // Increase the scale.
855 if (m_View->GetPerspective()) {
856 m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
857 } else {
858 m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
859 m_View->ForceRefresh();
863 void GUIControl::OnZoomOut(bool accel)
865 // Decrease the scale.
867 if (m_View->GetPerspective()) {
868 m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
869 } else {
870 m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
871 m_View->ForceRefresh();
875 void GUIControl::OnToggleScalebar()
877 m_View->ToggleScaleBar();
880 void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
882 cmd.Enable(m_View->HasData());
883 cmd.Check(m_View->ShowingScaleBar());
886 void GUIControl::OnToggleColourKey()
888 m_View->ToggleColourKey();
891 void GUIControl::OnToggleColourKeyUpdate(wxUpdateUIEvent& cmd)
893 cmd.Enable(m_View->HasData() && m_View->ColouringBy() != COLOUR_BY_NONE);
894 cmd.Check(m_View->ShowingColourKey());
897 void GUIControl::OnViewCompass()
899 m_View->ToggleCompass();
902 void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
904 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
905 cmd.Check(m_View->ShowingCompass());
908 void GUIControl::OnViewClino()
910 m_View->ToggleClino();
913 void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
915 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
916 cmd.Check(m_View->ShowingClino());
919 void GUIControl::OnShowSurface()
921 m_View->ToggleSurfaceLegs();
924 void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
926 cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
927 cmd.Check(m_View->ShowingSurfaceLegs());
930 void GUIControl::OnShowEntrances()
932 m_View->ToggleEntrances();
935 void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
937 cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
938 cmd.Check(m_View->ShowingEntrances());
941 void GUIControl::OnShowFixedPts()
943 m_View->ToggleFixedPts();
946 void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
948 cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
949 cmd.Check(m_View->ShowingFixedPts());
952 void GUIControl::OnShowExportedPts()
954 m_View->ToggleExportedPts();
957 void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
959 cmd.Enable(m_View->HasData() && (m_View->GetNumExportedPts() > 0));
960 cmd.Check(m_View->ShowingExportedPts());
963 void GUIControl::OnViewGrid()
965 m_View->ToggleGrid();
968 void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
970 cmd.Enable(m_View->HasData());
971 cmd.Check(m_View->ShowingGrid());
974 void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
976 cmd.Enable(m_View->HasData());
979 void GUIControl::OnViewPerspective()
981 m_View->TogglePerspective();
982 // Force update of coordinate display.
983 if (m_View->GetPerspective()) {
984 m_View->MoveViewer(0, 0, 0);
985 } else {
986 m_View->ClearCoords();
990 void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
992 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
993 cmd.Check(m_View->GetPerspective());
996 void GUIControl::OnViewSmoothShading()
998 m_View->ToggleSmoothShading();
1001 void GUIControl::OnViewSmoothShadingUpdate(wxUpdateUIEvent& cmd)
1003 cmd.Enable(m_View->HasData());
1004 cmd.Check(m_View->GetSmoothShading());
1007 void GUIControl::OnViewTextured()
1009 m_View->ToggleTextured();
1012 void GUIControl::OnViewTexturedUpdate(wxUpdateUIEvent& cmd)
1014 cmd.Enable(m_View->HasData());
1015 cmd.Check(m_View->GetTextured());
1018 void GUIControl::OnViewFog()
1020 m_View->ToggleFog();
1023 void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
1025 cmd.Enable(m_View->HasData());
1026 cmd.Check(m_View->GetFog());
1029 void GUIControl::OnViewSmoothLines()
1031 m_View->ToggleAntiAlias();
1034 void GUIControl::OnViewSmoothLinesUpdate(wxUpdateUIEvent& cmd)
1036 cmd.Enable(m_View->HasData());
1037 cmd.Check(m_View->GetAntiAlias());
1040 void GUIControl::OnToggleMetric()
1042 m_View->ToggleMetric();
1044 wxConfigBase::Get()->Write(wxT("metric"), m_View->GetMetric());
1045 wxConfigBase::Get()->Flush();
1048 void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
1050 cmd.Enable(m_View->HasData());
1051 cmd.Check(m_View->GetMetric());
1054 void GUIControl::OnToggleDegrees()
1056 m_View->ToggleDegrees();
1058 wxConfigBase::Get()->Write(wxT("degrees"), m_View->GetDegrees());
1059 wxConfigBase::Get()->Flush();
1062 void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
1064 cmd.Enable(m_View->HasData());
1065 cmd.Check(m_View->GetDegrees());
1068 void GUIControl::OnTogglePercent()
1070 m_View->TogglePercent();
1072 wxConfigBase::Get()->Write(wxT("percent"), m_View->GetPercent());
1073 wxConfigBase::Get()->Flush();
1076 void GUIControl::OnTogglePercentUpdate(wxUpdateUIEvent& cmd)
1078 cmd.Enable(m_View->HasData());
1079 cmd.Check(m_View->GetPercent());
1082 void GUIControl::OnToggleTubes()
1084 m_View->ToggleTubes();
1087 void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
1089 cmd.Enable(m_View->HasData() && m_View->HasTubes());
1090 cmd.Check(m_View->GetTubes());
1093 void GUIControl::OnCancelDistLine()
1095 m_View->ClearTreeSelection();
1098 void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
1100 cmd.Enable(m_View->ShowingMeasuringLine());
1103 void GUIControl::OnKeyPress(wxKeyEvent &e)
1105 if (!m_View->HasData() ||
1106 (e.GetModifiers() &~ (wxMOD_CONTROL|wxMOD_SHIFT))) {
1107 // Pass on the event if there's no survey data, or if any modifier keys
1108 // other than Ctrl and Shift are pressed.
1109 e.Skip();
1110 return;
1113 // The changelog says this is meant to keep animation going while keys are
1114 // pressed, but that happens anyway (on linux at least - perhaps it helps
1115 // on windows?) FIXME : check!
1116 //bool refresh = m_View->Animate();
1118 switch (e.GetKeyCode()) {
1119 case '/': case '?':
1120 if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1121 OnLowerViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1122 break;
1123 case '\'': case '@': case '"': // both shifted forms - US and UK kbd
1124 if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1125 OnHigherViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1126 break;
1127 case 'C': case 'c':
1128 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1129 OnStepOnceAnticlockwise(e.GetModifiers() == wxMOD_SHIFT);
1130 break;
1131 case 'V': case 'v':
1132 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1133 OnStepOnceClockwise(e.GetModifiers() == wxMOD_SHIFT);
1134 break;
1135 case ']': case '}':
1136 OnZoomIn(e.GetModifiers() == wxMOD_SHIFT);
1137 break;
1138 case '[': case '{':
1139 OnZoomOut(e.GetModifiers() == wxMOD_SHIFT);
1140 break;
1141 case 'N': case 'n':
1142 OnMoveNorth();
1143 break;
1144 case 'S': case 's':
1145 OnMoveSouth();
1146 break;
1147 case 'E': case 'e':
1148 if (!m_View->IsExtendedElevation())
1149 OnMoveEast();
1150 break;
1151 case 'W': case 'w':
1152 if (!m_View->IsExtendedElevation())
1153 OnMoveWest();
1154 break;
1155 case 'Z': case 'z':
1156 if (!m_View->IsExtendedElevation())
1157 m_View->RotateFaster(e.GetModifiers() == wxMOD_SHIFT);
1158 break;
1159 case 'X': case 'x':
1160 if (!m_View->IsExtendedElevation())
1161 m_View->RotateSlower(e.GetModifiers() == wxMOD_SHIFT);
1162 break;
1163 case 'R': case 'r':
1164 if (!m_View->IsExtendedElevation())
1165 OnReverseDirectionOfRotation();
1166 break;
1167 case 'P': case 'p':
1168 if (!m_View->IsExtendedElevation() && !m_View->ShowingPlan())
1169 OnPlan();
1170 break;
1171 case 'L': case 'l':
1172 if (!m_View->IsExtendedElevation() && !m_View->ShowingElevation())
1173 OnElevation();
1174 break;
1175 case 'O': case 'o':
1176 OnDisplayOverlappingNames();
1177 break;
1178 case WXK_DELETE:
1179 if (e.GetModifiers() == 0)
1180 OnDefaults();
1181 break;
1182 case WXK_RETURN:
1183 if (e.GetModifiers() == 0) {
1184 // For compatibility with older versions.
1185 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1186 m_View->StartRotation();
1188 break;
1189 case WXK_SPACE:
1190 if (e.GetModifiers() == 0) {
1191 if (!m_View->IsExtendedElevation())
1192 OnToggleRotation();
1194 break;
1195 case WXK_LEFT:
1196 if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1197 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1198 OnStepOnceAnticlockwise(e.GetModifiers() == wxMOD_SHIFT);
1199 } else {
1200 OnShiftDisplayLeft(e.GetModifiers() == wxMOD_SHIFT);
1202 break;
1203 case WXK_RIGHT:
1204 if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1205 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1206 OnStepOnceClockwise(e.GetModifiers() == wxMOD_SHIFT);
1207 } else {
1208 OnShiftDisplayRight(e.GetModifiers() == wxMOD_SHIFT);
1210 break;
1211 case WXK_UP:
1212 if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1213 if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1214 OnHigherViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1215 } else {
1216 OnShiftDisplayUp(e.GetModifiers() == wxMOD_SHIFT);
1218 break;
1219 case WXK_DOWN:
1220 if ((e.GetModifiers() &~ wxMOD_SHIFT) == wxMOD_CONTROL) {
1221 if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1222 OnLowerViewpoint(e.GetModifiers() == wxMOD_SHIFT);
1223 } else {
1224 OnShiftDisplayDown(e.GetModifiers() == wxMOD_SHIFT);
1226 break;
1227 case WXK_ESCAPE:
1228 if (e.GetModifiers() == 0) {
1229 if (m_View->ShowingMeasuringLine()) {
1230 OnCancelDistLine();
1231 } else if (m_View->IsFullScreen()) {
1232 // Cancel full-screen mode on "Escape" if it isn't cancelling
1233 // the measuring line.
1234 m_View->FullScreenMode();
1237 break;
1238 case WXK_F2:
1239 if (e.GetModifiers() == 0)
1240 m_View->ToggleFatFinger();
1241 break;
1242 case WXK_F3:
1243 if (e.GetModifiers() == 0)
1244 m_View->ToggleHitTestDebug();
1245 break;
1246 case WXK_F4: {
1247 if (e.GetModifiers() == 0) {
1248 const wxChar * msg;
1249 #if wxDEBUG_LEVEL
1250 if (wxTheAssertHandler)
1251 wxTheAssertHandler = NULL;
1252 else
1253 wxSetDefaultAssertHandler();
1254 if (wxTheAssertHandler)
1255 msg = wxT("Assertions enabled");
1256 else
1257 msg = wxT("Assertions disabled");
1258 #else
1259 msg = wxT("wxWidgets was built without assertions");
1260 #endif
1261 wxMessageBox(msg, wxT("Aven Debug"), wxOK | wxICON_INFORMATION);
1263 break;
1265 case WXK_F5:
1266 if (e.GetModifiers() == 0) {
1267 m_View->InvalidateAllLists();
1268 m_View->ForceRefresh();
1270 break;
1271 case WXK_F6:
1272 if (e.GetModifiers() == 0)
1273 m_View->ToggleRenderStats();
1274 break;
1275 default:
1276 e.Skip();
1279 //if (refresh) m_View->ForceRefresh();
1282 void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1284 cmd.Check(m_View->IsFullScreen());
1287 void GUIControl::OnViewFullScreen()
1289 m_View->FullScreenMode();
1292 void GUIControl::OnViewBoundingBoxUpdate(wxUpdateUIEvent& cmd)
1294 cmd.Enable(m_View->HasData());
1295 cmd.Check(m_View->DisplayingBoundingBox());
1298 void GUIControl::OnViewBoundingBox()
1300 m_View->ToggleBoundingBox();
1303 void GUIControl::OnViewTerrainUpdate(wxUpdateUIEvent& cmd)
1305 cmd.Enable(m_View->HasTerrain());
1306 cmd.Check(m_View->DisplayingTerrain());
1309 void GUIControl::OnViewTerrain()
1311 m_View->ToggleTerrain();