source: git/src/guicontrol.cc@ ac3f376

RELEASE/1.1 RELEASE/1.2 debug-ci debug-ci-sanitisers faster-cavernlog log-select main stereo stereo-2025 walls-data walls-data-hanging-as-warning warn-only-for-hanging-survey
Last change on this file since ac3f376 was 570d62c3, checked in by Olly Betts <olly@…>, 20 years ago

Highlight "here" in the survey tree upon mouseover in the GfxCore pane.
Only show a ring at here when it's a station.
Only show the "hand" cursor when here is a station.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3276 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 26.3 KB
Line 
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 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.
13//
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.
18//
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22//
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "guicontrol.h"
29#include "gfxcore.h"
30#include <wx/confbase.h>
31
32const int DISPLAY_SHIFT = 10;
33const double FLYFREE_SHIFT = 0.2;
34const double ROTATE_STEP = 2.0;
35
36GUIControl::GUIControl()
37 : dragging(NO_DRAG)
38{
39 m_View = NULL;
40 m_ReverseControls = false;
41 m_LastDrag = drag_NONE;
42}
43
44GUIControl::~GUIControl()
45{
46 // no action
47}
48
49void GUIControl::SetView(GfxCore* view)
50{
51 m_View = view;
52}
53
54bool GUIControl::MouseDown() const
55{
56 return (dragging != NO_DRAG);
57}
58
59void GUIControl::HandleTilt(wxPoint point)
60{
61 // Handle a mouse movement during tilt mode.
62
63 // wxGTK (at least) fails to update the cursor while dragging.
64 m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
65
66 int dy = point.y - m_DragStart.y;
67
68 if (m_ReverseControls != m_View->GetPerspective()) dy = -dy;
69
70 m_View->TiltCave(Double(-dy) * 0.36);
71
72 m_DragStart = point;
73
74 m_View->ForceRefresh();
75}
76
77void GUIControl::HandleTranslate(wxPoint point)
78{
79 // Handle a mouse movement during translation mode.
80
81 // wxGTK (at least) fails to update the cursor while dragging.
82 m_View->SetCursor(GfxCore::CURSOR_DRAGGING_HAND);
83
84 int dx = point.x - m_DragStart.x;
85 int dy = point.y - m_DragStart.y;
86
87 if (m_ReverseControls) {
88 dx = -dx;
89 dy = -dy;
90 }
91
92 if (m_View->GetPerspective())
93 m_View->MoveViewer(0, -dy * .1, dx * .1);
94 else
95 m_View->TranslateCave(dx, dy);
96
97 m_DragStart = point;
98}
99
100void GUIControl::HandleScaleRotate(wxPoint point)
101{
102 // Handle a mouse movement during scale/rotate mode.
103
104 // wxGTK (at least) fails to update the cursor while dragging.
105 m_View->SetCursor(GfxCore::CURSOR_ZOOM_ROTATE);
106
107 int dx, dy;
108 int threshold;
109 if (m_ScaleRotateLock == NONE) {
110 // Dragging to scale or rotate but we've not decided which yet.
111 dx = point.x - m_DragRealStart.x;
112 dy = point.y - m_DragRealStart.y;
113 threshold = 8 * 8;
114 } else {
115 dx = point.x - m_DragStart.x;
116 dy = point.y - m_DragStart.y;
117 threshold = 5;
118 }
119 int dx2 = dx * dx;
120 int dy2 = dy * dy;
121 if (dx2 + dy2 < threshold) return;
122
123 switch (m_ScaleRotateLock) {
124 case NONE:
125 if (dx2 > dy2) {
126 m_ScaleRotateLock = ROTATE;
127// m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
128 } else {
129 m_ScaleRotateLock = SCALE;
130// m_View->SetCursor(GfxCore::CURSOR_ZOOM);
131 }
132 break;
133 case SCALE:
134 if (dx2 >= 8 * dy2) {
135 m_ScaleRotateLock = ROTATE;
136// m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
137 }
138 break;
139 case ROTATE:
140 if (dy2 >= 8 * dx2) {
141 m_ScaleRotateLock = SCALE;
142// m_View->SetCursor(GfxCore::CURSOR_ZOOM);
143 }
144 break;
145 }
146
147 if (m_ScaleRotateLock == ROTATE) {
148 dy = 0;
149 } else {
150 dx = 0;
151 }
152
153 if (m_ReverseControls) {
154 dx = -dx;
155 dy = -dy;
156 }
157
158 if (m_View->GetPerspective()) {
159 if (dy) m_View->MoveViewer(-dy * .1, 0, 0);
160 } else {
161 // up/down => scale.
162 if (dy) m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
163 // left/right => rotate.
164 if (dx) m_View->TurnCave(Double(dx) * -0.36);
165 if (dx || dy) m_View->ForceRefresh();
166 }
167
168 m_DragStart = point;
169}
170
171void GUIControl::HandleTiltRotate(wxPoint point)
172{
173 // Handle a mouse movement during tilt/rotate mode.
174 if (m_View->IsExtendedElevation()) return;
175
176 // wxGTK (at least) fails to update the cursor while dragging.
177 m_View->SetCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
178
179 int dx = point.x - m_DragStart.x;
180 int dy = point.y - m_DragStart.y;
181
182 if (m_ReverseControls != m_View->GetPerspective()) {
183 dx = -dx;
184 dy = -dy;
185 }
186
187 // left/right => rotate, up/down => tilt.
188 // Make tilt less sensitive than rotate as that feels better.
189 m_View->TurnCave(Double(dx) * -0.36);
190 m_View->TiltCave(Double(dy) * -0.18);
191
192 m_View->ForceRefresh();
193
194 m_DragStart = point;
195}
196
197void GUIControl::HandleRotate(wxPoint point)
198{
199 // Handle a mouse movement during rotate mode.
200 if (m_View->IsExtendedElevation()) return;
201
202 // wxGTK (at least) fails to update the cursor while dragging.
203 m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
204
205 int dx = point.x - m_DragStart.x;
206 int dy = point.y - m_DragStart.y;
207
208 if (m_ReverseControls != m_View->GetPerspective()) {
209 dx = -dx;
210 dy = -dy;
211 }
212
213 // left/right => rotate.
214 m_View->TurnCave(Double(dx) * -0.36);
215
216 m_View->ForceRefresh();
217
218 m_DragStart = point;
219}
220
221void GUIControl::RestoreCursor()
222{
223 if (m_View->HereIsReal()) {
224 m_View->SetCursor(GfxCore::CURSOR_POINTING_HAND);
225 } else {
226 m_View->SetCursor(GfxCore::CURSOR_DEFAULT);
227 }
228}
229
230void GUIControl::HandleNonDrag(const wxPoint & point) {
231 if (m_View->CheckHitTestGrid(point, false)) {
232 m_View->SetCursor(GfxCore::CURSOR_POINTING_HAND);
233 } else if (m_View->PointWithinScaleBar(point)) {
234 m_View->SetCursor(GfxCore::CURSOR_HORIZONTAL_RESIZE);
235 } else if (m_View->PointWithinCompass(point)) {
236 m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
237 } else if (m_View->PointWithinClino(point)) {
238 m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
239 } else {
240 RestoreCursor();
241 }
242}
243
244//
245// Mouse event handling methods
246//
247
248void GUIControl::OnMouseMove(wxMouseEvent& event)
249{
250 // Mouse motion event handler.
251 if (!m_View->HasData()) return;
252
253 // Ignore moves which don't change the position.
254 if (event.GetPosition() == m_DragStart) {
255 return;
256 }
257
258 static long timestamp = LONG_MIN;
259 if (dragging != NO_DRAG && m_ScaleRotateLock != NONE && timestamp != LONG_MIN) {
260 // If no motion for a second, reset the direction lock.
261 if (event.GetTimestamp() - timestamp >= 1000) {
262 m_ScaleRotateLock = NONE;
263 m_DragRealStart = m_DragStart;
264 RestoreCursor();
265 }
266 }
267 timestamp = event.GetTimestamp();
268
269 wxPoint point(event.GetPosition());
270
271 // Check hit-test grid (only if no buttons are pressed).
272 if (!event.LeftIsDown() && !event.MiddleIsDown() && !event.RightIsDown()) {
273 HandleNonDrag(point);
274 }
275
276 // Update coordinate display if in plan view,
277 // or altitude if in elevation view.
278 m_View->SetCoords(point);
279
280 switch (dragging) {
281 case LEFT_DRAG:
282 switch (m_LastDrag) {
283 case drag_COMPASS:
284 // Drag in heading indicator.
285 m_View->SetCompassFromPoint(point);
286 break;
287 case drag_ELEV:
288 // Drag in clinometer.
289 m_View->SetClinoFromPoint(point);
290 break;
291 case drag_SCALE:
292 m_View->SetScaleBarFromOffset(point.x - m_DragLast.x);
293 break;
294 case drag_MAIN:
295 if (event.ControlDown()) {
296 HandleTiltRotate(point);
297 } else {
298 HandleScaleRotate(point);
299 }
300 break;
301 case drag_NONE:
302 // Shouldn't happen?! FIXME: assert or something.
303 break;
304 }
305 break;
306 case MIDDLE_DRAG:
307 HandleTilt(point);
308 break;
309 case RIGHT_DRAG:
310 HandleTranslate(point);
311 break;
312 case NO_DRAG:
313 break;
314 }
315
316 m_DragLast = point;
317}
318
319void GUIControl::OnLButtonDown(wxMouseEvent& event)
320{
321 if (m_View->HasData()) {
322 dragging = LEFT_DRAG;
323
324 m_DragStart = m_DragRealStart = event.GetPosition();
325
326 if (m_View->PointWithinCompass(m_DragStart)) {
327 m_LastDrag = drag_COMPASS;
328 } else if (m_View->PointWithinClino(m_DragStart)) {
329 m_LastDrag = drag_ELEV;
330 } else if (m_View->PointWithinScaleBar(m_DragStart)) {
331 m_LastDrag = drag_SCALE;
332 } else {
333 if (event.ControlDown()) {
334 if (m_View->IsExtendedElevation()) {
335 dragging = NO_DRAG;
336 return;
337 }
338 m_View->SetCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
339 } else {
340 m_View->SetCursor(GfxCore::CURSOR_ZOOM_ROTATE);
341 }
342
343 m_LastDrag = drag_MAIN;
344 m_ScaleRotateLock = NONE;
345 }
346
347 m_View->CaptureMouse();
348 }
349}
350
351void GUIControl::OnLButtonUp(wxMouseEvent& event)
352{
353 if (m_View->HasData()) {
354 if (event.GetPosition() == m_DragRealStart) {
355 // Just a "click"...
356 m_View->CheckHitTestGrid(m_DragStart, true);
357 } else if (dragging == NO_DRAG) {
358 return;
359 }
360
361// m_View->RedrawIndicators();
362 m_View->ReleaseMouse();
363
364 m_LastDrag = drag_NONE;
365 dragging = NO_DRAG;
366
367 m_View->DragFinished();
368
369 if (event.GetPosition() == m_DragRealStart) {
370 RestoreCursor();
371 } else {
372 HandleNonDrag(event.GetPosition());
373 }
374 }
375}
376
377void GUIControl::OnMButtonDown(wxMouseEvent& event)
378{
379 if (m_View->HasData() && !m_View->IsExtendedElevation()) {
380 dragging = MIDDLE_DRAG;
381 m_DragStart = event.GetPosition();
382
383 m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
384
385 m_View->CaptureMouse();
386 }
387}
388
389void GUIControl::OnMButtonUp(wxMouseEvent&)
390{
391 if (m_View->HasData()) {
392 dragging = NO_DRAG;
393 m_View->ReleaseMouse();
394 m_View->DragFinished();
395
396 RestoreCursor();
397 }
398}
399
400void GUIControl::OnRButtonDown(wxMouseEvent& event)
401{
402 if (m_View->HasData()) {
403 m_DragStart = event.GetPosition();
404
405 dragging = RIGHT_DRAG;
406
407 m_View->SetCursor(GfxCore::CURSOR_DRAGGING_HAND);
408 m_View->CaptureMouse();
409 }
410}
411
412void GUIControl::OnRButtonUp(wxMouseEvent&)
413{
414 m_LastDrag = drag_NONE;
415 m_View->ReleaseMouse();
416
417 dragging = NO_DRAG;
418
419 RestoreCursor();
420
421 m_View->DragFinished();
422}
423
424void GUIControl::OnMouseWheel(wxMouseEvent& event) {
425 int dy = event.GetWheelRotation();
426 if (m_View->GetPerspective()) {
427 m_View->MoveViewer(-dy, 0, 0);
428 } else {
429 m_View->SetScale(m_View->GetScale() * pow(1.06, -0.04 * dy));
430 m_View->ForceRefresh();
431 }
432}
433
434void GUIControl::OnDisplayOverlappingNames()
435{
436 m_View->ToggleOverlappingNames();
437}
438
439void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
440{
441 cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
442 cmd.Check(m_View->ShowingOverlappingNames());
443}
444
445void GUIControl::OnColourByDepth()
446{
447 if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
448 m_View->SetColourBy(COLOUR_BY_NONE);
449 } else {
450 m_View->SetColourBy(COLOUR_BY_DEPTH);
451 }
452}
453
454void GUIControl::OnColourByDate()
455{
456 if (m_View->ColouringBy() == COLOUR_BY_DATE) {
457 m_View->SetColourBy(COLOUR_BY_NONE);
458 } else {
459 m_View->SetColourBy(COLOUR_BY_DATE);
460 }
461}
462
463void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
464{
465 cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs() && !m_View->IsFlat());
466 cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
467}
468
469void GUIControl::OnColourByDateUpdate(wxUpdateUIEvent& cmd)
470{
471 cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs() && m_View->HasRangeOfDates());
472 cmd.Check(m_View->ColouringBy() == COLOUR_BY_DATE);
473}
474
475void GUIControl::OnShowCrosses()
476{
477 m_View->ToggleCrosses();
478}
479
480void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
481{
482 cmd.Enable(m_View->HasData());
483 cmd.Check(m_View->ShowingCrosses());
484}
485
486void GUIControl::OnShowStationNames()
487{
488 m_View->ToggleStationNames();
489}
490
491void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
492{
493 cmd.Enable(m_View->HasData());
494 cmd.Check(m_View->ShowingStationNames());
495}
496
497void GUIControl::OnShowSurveyLegs()
498{
499 m_View->ToggleUndergroundLegs();
500}
501
502void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
503{
504 cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs());
505 cmd.Check(m_View->ShowingUndergroundLegs());
506}
507
508void GUIControl::OnMoveEast()
509{
510 m_View->TurnCaveTo(90.0);
511 m_View->ForceRefresh();
512}
513
514void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
515{
516 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
517}
518
519void GUIControl::OnMoveNorth()
520{
521 m_View->TurnCaveTo(0.0);
522 m_View->ForceRefresh();
523}
524
525void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
526{
527 cmd.Enable(m_View->HasData());
528}
529
530void GUIControl::OnMoveSouth()
531{
532 m_View->TurnCaveTo(180.0);
533 m_View->ForceRefresh();
534}
535
536void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
537{
538 cmd.Enable(m_View->HasData());
539}
540
541void GUIControl::OnMoveWest()
542{
543 m_View->TurnCaveTo(270.0);
544 m_View->ForceRefresh();
545}
546
547void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
548{
549 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
550}
551
552void GUIControl::OnToggleRotation()
553{
554 m_View->ToggleRotation();
555}
556
557void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
558{
559 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
560 cmd.Check(m_View->HasData() && m_View->IsRotating());
561}
562
563void GUIControl::OnReverseControls()
564{
565 m_ReverseControls = !m_ReverseControls;
566}
567
568void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
569{
570 cmd.Enable(m_View->HasData());
571 cmd.Check(m_ReverseControls);
572}
573
574void GUIControl::OnReverseDirectionOfRotation()
575{
576 m_View->ReverseRotation();
577}
578
579void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
580{
581 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
582}
583
584void GUIControl::OnSlowDown(bool accel)
585{
586 m_View->RotateSlower(accel);
587}
588
589void GUIControl::OnSlowDownUpdate(wxUpdateUIEvent& cmd)
590{
591 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
592}
593
594void GUIControl::OnSpeedUp(bool accel)
595{
596 m_View->RotateFaster(accel);
597}
598
599void GUIControl::OnSpeedUpUpdate(wxUpdateUIEvent& cmd)
600{
601 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
602}
603
604void GUIControl::OnStepOnceAnticlockwise(bool accel)
605{
606 if (m_View->GetPerspective()) {
607 m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
608 } else {
609 m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
610 }
611 m_View->ForceRefresh();
612}
613
614void GUIControl::OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent& cmd)
615{
616 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->IsRotating());
617}
618
619void GUIControl::OnStepOnceClockwise(bool accel)
620{
621 if (m_View->GetPerspective()) {
622 m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
623 } else {
624 m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
625 }
626 m_View->ForceRefresh();
627}
628
629void GUIControl::OnStepOnceClockwiseUpdate(wxUpdateUIEvent& cmd)
630{
631 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->IsRotating());
632}
633
634void GUIControl::OnDefaults()
635{
636 m_View->Defaults();
637}
638
639void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
640{
641 cmd.Enable(m_View->HasData());
642}
643
644void GUIControl::OnElevation()
645{
646 // Switch to elevation view.
647
648 m_View->SwitchToElevation();
649}
650
651void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
652{
653 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingElevation());
654}
655
656void GUIControl::OnHigherViewpoint(bool accel)
657{
658 // Raise the viewpoint.
659 if (m_View->GetPerspective()) {
660 m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
661 } else {
662 m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
663 }
664 m_View->ForceRefresh();
665}
666
667void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
668{
669 cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation());
670}
671
672void GUIControl::OnLowerViewpoint(bool accel)
673{
674 // Lower the viewpoint.
675 if (m_View->GetPerspective()) {
676 m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
677 } else {
678 m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
679 }
680 m_View->ForceRefresh();
681}
682
683void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
684{
685 cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation());
686}
687
688void GUIControl::OnPlan()
689{
690 // Switch to plan view.
691 m_View->SwitchToPlan();
692}
693
694void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
695{
696 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation() && !m_View->ShowingPlan());
697}
698
699void GUIControl::OnShiftDisplayDown(bool accel)
700{
701 if (m_View->GetPerspective())
702 m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
703 else
704 m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
705}
706
707void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
708{
709 cmd.Enable(m_View->HasData());
710}
711
712void GUIControl::OnShiftDisplayLeft(bool accel)
713{
714 if (m_View->GetPerspective())
715 m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
716 else
717 m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
718}
719
720void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
721{
722 cmd.Enable(m_View->HasData());
723}
724
725void GUIControl::OnShiftDisplayRight(bool accel)
726{
727 if (m_View->GetPerspective())
728 m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
729 else
730 m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
731}
732
733void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
734{
735 cmd.Enable(m_View->HasData());
736}
737
738void GUIControl::OnShiftDisplayUp(bool accel)
739{
740 if (m_View->GetPerspective())
741 m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
742 else
743 m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
744}
745
746void GUIControl::OnShiftDisplayUpUpdate(wxUpdateUIEvent& cmd)
747{
748 cmd.Enable(m_View->HasData());
749}
750
751void GUIControl::OnZoomIn(bool accel)
752{
753 // Increase the scale.
754
755 if (m_View->GetPerspective()) {
756 m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
757 } else {
758 m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
759 m_View->ForceRefresh();
760 }
761}
762
763void GUIControl::OnZoomInUpdate(wxUpdateUIEvent& cmd)
764{
765 cmd.Enable(m_View->HasData());
766}
767
768void GUIControl::OnZoomOut(bool accel)
769{
770 // Decrease the scale.
771
772 if (m_View->GetPerspective()) {
773 m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
774 } else {
775 m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
776 m_View->ForceRefresh();
777 }
778}
779
780void GUIControl::OnZoomOutUpdate(wxUpdateUIEvent& cmd)
781{
782 cmd.Enable(m_View->HasData());
783}
784
785void GUIControl::OnToggleScalebar()
786{
787 m_View->ToggleScaleBar();
788}
789
790void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
791{
792 cmd.Enable(m_View->HasData());
793 cmd.Check(m_View->ShowingScaleBar());
794}
795
796void GUIControl::OnToggleDepthbar() /* FIXME naming */
797{
798 m_View->ToggleDepthBar();
799}
800
801void GUIControl::OnToggleDepthbarUpdate(wxUpdateUIEvent& cmd)
802{
803 cmd.Enable(m_View->HasData() && m_View->ColouringBy() == COLOUR_BY_DEPTH);
804 cmd.Check(m_View->ShowingDepthBar());
805}
806
807void GUIControl::OnViewCompass()
808{
809 m_View->ToggleCompass();
810}
811
812void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
813{
814 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
815 cmd.Check(m_View->ShowingCompass());
816}
817
818void GUIControl::OnViewClino()
819{
820 m_View->ToggleClino();
821}
822
823void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
824{
825 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
826 cmd.Check(m_View->ShowingClino());
827}
828
829void GUIControl::OnShowSurface()
830{
831 m_View->ToggleSurfaceLegs();
832}
833
834void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
835{
836 cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
837 cmd.Check(m_View->ShowingSurfaceLegs());
838}
839
840void GUIControl::OnShowEntrances()
841{
842 m_View->ToggleEntrances();
843}
844
845void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
846{
847 cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
848 cmd.Check(m_View->ShowingEntrances());
849}
850
851void GUIControl::OnShowFixedPts()
852{
853 m_View->ToggleFixedPts();
854}
855
856void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
857{
858 cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
859 cmd.Check(m_View->ShowingFixedPts());
860}
861
862void GUIControl::OnShowExportedPts()
863{
864 m_View->ToggleExportedPts();
865}
866
867void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
868{
869 cmd.Enable(m_View->HasData() && (m_View->GetNumExportedPts() > 0));
870 cmd.Check(m_View->ShowingExportedPts());
871}
872
873void GUIControl::OnViewGrid()
874{
875 m_View->ToggleGrid();
876}
877
878void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
879{
880 cmd.Enable(m_View->HasData());
881 cmd.Check(m_View->ShowingGrid());
882}
883
884void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
885{
886 cmd.Enable(m_View->HasData());
887}
888
889void GUIControl::OnViewPerspective()
890{
891 m_View->TogglePerspective();
892 // Force update of coordinate display.
893 if (m_View->GetPerspective()) {
894 m_View->MoveViewer(0, 0, 0);
895 } else {
896 m_View->ClearCoords();
897 }
898}
899
900void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
901{
902 cmd.Enable(m_View->HasData() && !m_View->IsExtendedElevation());
903 cmd.Check(m_View->GetPerspective());
904}
905
906void GUIControl::OnViewSmoothShading()
907{
908 m_View->ToggleSmoothShading();
909}
910
911void GUIControl::OnViewSmoothShadingUpdate(wxUpdateUIEvent& cmd)
912{
913 cmd.Enable(m_View->HasData());
914 cmd.Check(m_View->GetSmoothShading());
915}
916
917void GUIControl::OnViewTextured()
918{
919 m_View->ToggleTextured();
920}
921
922void GUIControl::OnViewTexturedUpdate(wxUpdateUIEvent& cmd)
923{
924 cmd.Enable(m_View->HasData());
925 cmd.Check(m_View->GetTextured());
926}
927
928void GUIControl::OnViewFog()
929{
930 m_View->ToggleFog();
931}
932
933void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
934{
935 cmd.Enable(m_View->HasData());
936 cmd.Check(m_View->GetFog());
937}
938
939void GUIControl::OnViewSmoothLines()
940{
941 m_View->ToggleAntiAlias();
942}
943
944void GUIControl::OnViewSmoothLinesUpdate(wxUpdateUIEvent& cmd)
945{
946 cmd.Enable(m_View->HasData());
947 cmd.Check(m_View->GetAntiAlias());
948}
949
950void GUIControl::OnToggleMetric()
951{
952 m_View->ToggleMetric();
953
954 wxConfigBase::Get()->Write("metric", m_View->GetMetric());
955 wxConfigBase::Get()->Flush();
956}
957
958void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
959{
960 cmd.Enable(m_View->HasData());
961 cmd.Check(m_View->GetMetric());
962}
963
964void GUIControl::OnToggleDegrees()
965{
966 m_View->ToggleDegrees();
967
968 wxConfigBase::Get()->Write("degrees", m_View->GetDegrees());
969 wxConfigBase::Get()->Flush();
970}
971
972void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
973{
974 cmd.Enable(m_View->HasData());
975 cmd.Check(m_View->GetDegrees());
976}
977
978void GUIControl::OnToggleTubes()
979{
980 m_View->ToggleTubes();
981}
982
983void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
984{
985 cmd.Enable(m_View->HasData() && m_View->HasTubes());
986 cmd.Check(m_View->GetTubes());
987}
988
989void GUIControl::OnCancelDistLine()
990{
991 m_View->ClearTreeSelection();
992}
993
994void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
995{
996 cmd.Enable(m_View->ShowingMeasuringLine());
997}
998
999void GUIControl::OnKeyPress(wxKeyEvent &e)
1000{
1001 if (!m_View->HasData()) {
1002 e.Skip();
1003 return;
1004 }
1005
1006 // The changelog says this is meant to keep animation going while keys are
1007 // pressed, but that happens anyway (on linux at least - perhaps it helps
1008 // on windows?) FIXME : check!
1009 //bool refresh = m_View->Animate();
1010
1011 switch (e.m_keyCode) {
1012 case '/': case '?':
1013 if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1014 OnLowerViewpoint(e.m_shiftDown);
1015 break;
1016 case '\'': case '@': case '"': // both shifted forms - US and UK kbd
1017 if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1018 OnHigherViewpoint(e.m_shiftDown);
1019 break;
1020 case 'C': case 'c':
1021 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1022 OnStepOnceAnticlockwise(e.m_shiftDown);
1023 break;
1024 case 'V': case 'v':
1025 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1026 OnStepOnceClockwise(e.m_shiftDown);
1027 break;
1028 case ']': case '}':
1029 OnZoomIn(e.m_shiftDown);
1030 break;
1031 case '[': case '{':
1032 OnZoomOut(e.m_shiftDown);
1033 break;
1034 case 'N': case 'n':
1035 OnMoveNorth();
1036 break;
1037 case 'S': case 's':
1038 OnMoveSouth();
1039 break;
1040 case 'E': case 'e':
1041 if (!m_View->IsExtendedElevation())
1042 OnMoveEast();
1043 break;
1044 case 'W': case 'w':
1045 if (!m_View->IsExtendedElevation())
1046 OnMoveWest();
1047 break;
1048 case 'Z': case 'z':
1049 if (!m_View->IsExtendedElevation())
1050 OnSpeedUp(e.m_shiftDown);
1051 break;
1052 case 'X': case 'x':
1053 if (!m_View->IsExtendedElevation())
1054 OnSlowDown(e.m_shiftDown);
1055 break;
1056 case 'R': case 'r':
1057 if (!m_View->IsExtendedElevation())
1058 OnReverseDirectionOfRotation();
1059 break;
1060 case 'P': case 'p':
1061 if (!m_View->IsExtendedElevation() && !m_View->ShowingPlan())
1062 OnPlan();
1063 break;
1064 case 'L': case 'l':
1065 if (!m_View->IsExtendedElevation() && !m_View->ShowingElevation())
1066 OnElevation();
1067 break;
1068 case 'O': case 'o':
1069 OnDisplayOverlappingNames();
1070 break;
1071 case WXK_DELETE:
1072 OnDefaults();
1073 break;
1074 case WXK_RETURN:
1075 // For compatibility with older versions.
1076 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1077 m_View->StartRotation();
1078 break;
1079 case WXK_SPACE:
1080 if (!m_View->IsExtendedElevation())
1081 OnToggleRotation();
1082 break;
1083 case WXK_LEFT:
1084 if (e.m_controlDown) {
1085 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1086 OnStepOnceAnticlockwise(e.m_shiftDown);
1087 } else {
1088 OnShiftDisplayLeft(e.m_shiftDown);
1089 }
1090 break;
1091 case WXK_RIGHT:
1092 if (e.m_controlDown) {
1093 if (!m_View->IsExtendedElevation() && !m_View->IsRotating())
1094 OnStepOnceClockwise(e.m_shiftDown);
1095 } else {
1096 OnShiftDisplayRight(e.m_shiftDown);
1097 }
1098 break;
1099 case WXK_UP:
1100 if (e.m_controlDown) {
1101 if (m_View->CanRaiseViewpoint() && !m_View->IsExtendedElevation())
1102 OnHigherViewpoint(e.m_shiftDown);
1103 } else {
1104 OnShiftDisplayUp(e.m_shiftDown);
1105 }
1106 break;
1107 case WXK_DOWN:
1108 if (e.m_controlDown) {
1109 if (m_View->CanLowerViewpoint() && !m_View->IsExtendedElevation())
1110 OnLowerViewpoint(e.m_shiftDown);
1111 } else {
1112 OnShiftDisplayDown(e.m_shiftDown);
1113 }
1114 break;
1115 case WXK_ESCAPE:
1116 if (m_View->ShowingMeasuringLine()) {
1117 OnCancelDistLine();
1118 }
1119 break;
1120 default:
1121 e.Skip();
1122 }
1123
1124 //if (refresh) m_View->ForceRefresh();
1125}
1126
1127void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1128{
1129 cmd.Enable(m_View->HasData());
1130 cmd.Check(m_View->IsFullScreen());
1131}
1132
1133void GUIControl::OnViewFullScreen()
1134{
1135 m_View->FullScreenMode();
1136}
1137
1138void GUIControl::OnViewBoundingBoxUpdate(wxUpdateUIEvent& cmd)
1139{
1140 cmd.Enable(m_View->HasData());
1141 cmd.Check(m_View->DisplayingBoundingBox());
1142}
1143
1144void GUIControl::OnViewBoundingBox()
1145{
1146 m_View->ToggleBoundingBox();
1147}
Note: See TracBrowser for help on using the repository browser.