source: git/src/guicontrol.cc @ 69ea543

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereowalls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 69ea543 was e2c1671, checked in by Olly Betts <olly@…>, 19 years ago

Added cursors for each different mouse action to help the user learn what each
does.

Add cursors for the "compass" and "clino" as well as the scalebar to suggest
to the user that they can be dragged to change the view.

Made mousewheel twice as sensitive.

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

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