source: git/src/guicontrol.cc @ 2431dea

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 2431dea was d4650b3, checked in by Olly Betts <olly@…>, 19 years ago

Added colour by date!

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

  • Property mode set to 100644
File size: 24.7 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 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            if (event.ControlDown()) {
270                if (m_View->GetLock() != lock_NONE) {
271                    dragging = NO_DRAG;
272                    return;
273                }
274                m_View->SetCursor(GfxCore::CURSOR_ROTATE_EITHER_WAY);
275            } else {
276                m_View->SetCursor(GfxCore::CURSOR_ZOOM);
277            }
278
279            m_LastDrag = drag_MAIN;
280        }
281
282        m_View->CaptureMouse();
283    }
284}
285
286void GUIControl::OnLButtonUp(wxMouseEvent& event)
287{
288    if (m_View->HasData() && m_View->GetLock() != lock_POINT) {
289        if (event.GetPosition() == m_DragRealStart) {
290            // Just a "click"...
291            m_View->CheckHitTestGrid(m_DragStart, true);
292        } else if (dragging == NO_DRAG) {
293            return;
294        }
295
296//      m_View->RedrawIndicators();
297        m_View->ReleaseMouse();
298
299        m_LastDrag = drag_NONE;
300        dragging = NO_DRAG;
301
302        m_View->DragFinished();
303
304        RestoreCursor();
305    }
306}
307
308void GUIControl::OnMButtonDown(wxMouseEvent& event)
309{
310    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
311        dragging = MIDDLE_DRAG;
312        m_DragStart = wxPoint(event.GetX(), event.GetY());
313
314        if (event.ControlDown()) {
315            m_View->SetCursor(GfxCore::CURSOR_ROTATE_VERTICALLY);
316        } else {
317            m_View->SetCursor(GfxCore::CURSOR_ROTATE_HORIZONTALLY);
318        }
319
320        m_View->CaptureMouse();
321    }
322}
323
324void GUIControl::OnMButtonUp(wxMouseEvent&)
325{
326    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
327        dragging = NO_DRAG;
328        m_View->ReleaseMouse();
329        m_View->DragFinished();
330
331        RestoreCursor();
332    }
333}
334
335void GUIControl::OnRButtonDown(wxMouseEvent& event)
336{
337    if (m_View->HasData()) {
338        m_DragStart = wxPoint(event.GetX(), event.GetY());
339
340        dragging = RIGHT_DRAG;
341
342        m_View->SetCursor(GfxCore::CURSOR_DRAGGING_HAND);
343        m_View->CaptureMouse();
344    }
345}
346
347void GUIControl::OnRButtonUp(wxMouseEvent&)
348{
349    m_LastDrag = drag_NONE;
350    m_View->ReleaseMouse();
351
352    dragging = NO_DRAG;
353
354    RestoreCursor();
355
356    m_View->DragFinished();
357}
358
359void GUIControl::OnMouseWheel(wxMouseEvent& event) {
360    if (m_View->GetLock() == lock_NONE) {
361        m_View->TiltCave(event.GetWheelRotation() / 12.0);
362        m_View->ForceRefresh();
363    }
364}
365
366void GUIControl::OnDisplayOverlappingNames()
367{
368    m_View->ToggleOverlappingNames();
369}
370
371void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
372{
373    cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
374    cmd.Check(m_View->ShowingOverlappingNames());
375}
376
377void GUIControl::OnColourByDepth()
378{
379    if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
380        m_View->SetColourBy(COLOUR_BY_NONE);
381    } else {
382        m_View->SetColourBy(COLOUR_BY_DEPTH);
383    }
384}
385
386void GUIControl::OnColourByDate()
387{
388    if (m_View->ColouringBy() == COLOUR_BY_DATE) {
389        m_View->SetColourBy(COLOUR_BY_NONE);
390    } else {
391        m_View->SetColourBy(COLOUR_BY_DATE);
392    }
393}
394
395void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
396{
397    cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs() && !m_View->IsFlat());
398    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
399}
400
401void GUIControl::OnColourByDateUpdate(wxUpdateUIEvent& cmd)
402{
403    cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs() && m_View->HasRangeOfDates());
404    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DATE);
405}
406
407void GUIControl::OnShowCrosses()
408{
409    m_View->ToggleCrosses();
410}
411
412void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
413{
414    cmd.Enable(m_View->HasData());
415    cmd.Check(m_View->ShowingCrosses());
416}
417
418void GUIControl::OnShowStationNames()
419{
420    m_View->ToggleStationNames();
421}
422
423void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
424{
425    cmd.Enable(m_View->HasData());
426    cmd.Check(m_View->ShowingStationNames());
427}
428
429void GUIControl::OnShowSurveyLegs()
430{
431    m_View->ToggleUndergroundLegs();
432}
433
434void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
435{
436    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT && m_View->HasUndergroundLegs());
437    cmd.Check(m_View->ShowingUndergroundLegs());
438}
439
440void GUIControl::OnMoveEast()
441{
442    m_View->TurnCaveTo(90.0);
443    m_View->ForceRefresh();
444}
445
446void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
447{
448    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
449}
450
451void GUIControl::OnMoveNorth()
452{
453    m_View->TurnCaveTo(0.0);
454    m_View->ForceRefresh();
455}
456
457void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
458{
459    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
460}
461
462void GUIControl::OnMoveSouth()
463{
464    m_View->TurnCaveTo(180.0);
465    m_View->ForceRefresh();
466}
467
468void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
469{
470    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
471}
472
473void GUIControl::OnMoveWest()
474{
475    m_View->TurnCaveTo(270.0);
476    m_View->ForceRefresh();
477}
478
479void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
480{
481    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
482}
483
484void GUIControl::OnToggleRotation()
485{
486    m_View->ToggleRotation();
487}
488
489void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
490{
491    cmd.Enable(m_View->HasData() && m_View->CanRotate());
492    cmd.Check(m_View->HasData() && m_View->IsRotating());
493}
494
495void GUIControl::OnReverseControls()
496{
497    m_ReverseControls = !m_ReverseControls;
498}
499
500void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
501{
502    cmd.Enable(m_View->HasData());
503    cmd.Check(m_ReverseControls);
504}
505
506void GUIControl::OnReverseDirectionOfRotation()
507{
508    m_View->ReverseRotation();
509}
510
511void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
512{
513    cmd.Enable(m_View->HasData() && m_View->CanRotate());
514}
515
516void GUIControl::OnSlowDown(bool accel)
517{
518    m_View->RotateSlower(accel);
519}
520
521void GUIControl::OnSlowDownUpdate(wxUpdateUIEvent& cmd)
522{
523    cmd.Enable(m_View->HasData() && m_View->CanRotate());
524}
525
526void GUIControl::OnSpeedUp(bool accel)
527{
528    m_View->RotateFaster(accel);
529}
530
531void GUIControl::OnSpeedUpUpdate(wxUpdateUIEvent& cmd)
532{
533    cmd.Enable(m_View->HasData() && m_View->CanRotate());
534}
535
536void GUIControl::OnStepOnceAnticlockwise(bool accel)
537{
538    if (m_View->GetPerspective()) {
539        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
540    } else {
541        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
542    }
543    m_View->ForceRefresh();
544}
545
546void GUIControl::OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent& cmd)
547{
548    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
549}
550
551void GUIControl::OnStepOnceClockwise(bool accel)
552{
553    if (m_View->GetPerspective()) {
554        m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
555    } else {
556        m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
557    }
558    m_View->ForceRefresh();
559}
560
561void GUIControl::OnStepOnceClockwiseUpdate(wxUpdateUIEvent& cmd)
562{
563    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
564}
565
566void GUIControl::OnDefaults()
567{
568    m_View->Defaults();
569}
570
571void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
572{
573    cmd.Enable(m_View->HasData());
574}
575
576void GUIControl::OnElevation()
577{
578    // Switch to elevation view.
579
580    m_View->SwitchToElevation();
581}
582
583void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
584{
585    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingElevation());
586}
587
588void GUIControl::OnHigherViewpoint(bool accel)
589{
590    // Raise the viewpoint.
591    if (m_View->GetPerspective()) {
592        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
593    } else {
594        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
595    }
596    m_View->ForceRefresh();
597}
598
599void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
600{
601    cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE);
602}
603
604void GUIControl::OnLowerViewpoint(bool accel)
605{
606    // Lower the viewpoint.
607    if (m_View->GetPerspective()) {
608        m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
609    } else {
610        m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
611    }
612    m_View->ForceRefresh();
613}
614
615void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
616{
617    cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE);
618}
619
620void GUIControl::OnPlan()
621{
622    // Switch to plan view.
623    m_View->SwitchToPlan();
624}
625
626void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
627{
628    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingPlan());
629}
630
631void GUIControl::OnShiftDisplayDown(bool accel)
632{
633    if (m_View->GetPerspective())
634        m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
635    else
636        m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
637}
638
639void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
640{
641    cmd.Enable(m_View->HasData());
642}
643
644void GUIControl::OnShiftDisplayLeft(bool accel)
645{
646    if (m_View->GetPerspective())
647        m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
648    else
649        m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
650}
651
652void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
653{
654    cmd.Enable(m_View->HasData());
655}
656
657void GUIControl::OnShiftDisplayRight(bool accel)
658{
659    if (m_View->GetPerspective())
660        m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
661    else
662        m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
663}
664
665void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
666{
667    cmd.Enable(m_View->HasData());
668}
669
670void GUIControl::OnShiftDisplayUp(bool accel)
671{
672    if (m_View->GetPerspective())
673        m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
674    else
675        m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
676}
677
678void GUIControl::OnShiftDisplayUpUpdate(wxUpdateUIEvent& cmd)
679{
680    cmd.Enable(m_View->HasData());
681}
682
683void GUIControl::OnZoomIn(bool accel)
684{
685    // Increase the scale.
686
687    if (m_View->GetPerspective()) {
688        m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
689    } else {
690        m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
691        m_View->ForceRefresh();
692    }
693}
694
695void GUIControl::OnZoomInUpdate(wxUpdateUIEvent& cmd)
696{
697    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
698}
699
700void GUIControl::OnZoomOut(bool accel)
701{
702    // Decrease the scale.
703
704    if (m_View->GetPerspective()) {
705        m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
706    } else {
707        m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
708        m_View->ForceRefresh();
709    }
710}
711
712void GUIControl::OnZoomOutUpdate(wxUpdateUIEvent& cmd)
713{
714    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
715}
716
717void GUIControl::OnToggleScalebar()
718{
719    m_View->ToggleScaleBar();
720}
721
722void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
723{
724    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
725    cmd.Check(m_View->ShowingScaleBar());
726}
727
728void GUIControl::OnToggleDepthbar() /* FIXME naming */
729{
730    m_View->ToggleDepthBar();
731}
732
733void GUIControl::OnToggleDepthbarUpdate(wxUpdateUIEvent& cmd)
734{
735    cmd.Enable(m_View->HasData() && !(m_View->GetLock() && lock_Z) &&
736               m_View->ColouringBy() == COLOUR_BY_DEPTH);
737    cmd.Check(m_View->ShowingDepthBar());
738}
739
740void GUIControl::OnViewCompass()
741{
742    m_View->ToggleCompass();
743}
744
745void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
746{
747    cmd.Enable(m_View->HasData() && m_View->CanRotate());
748    cmd.Check(m_View->ShowingCompass());
749}
750
751void GUIControl::OnViewClino()
752{
753    m_View->ToggleClino();
754}
755
756void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
757{
758    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE);
759    cmd.Check(m_View->ShowingClino());
760}
761
762void GUIControl::OnShowSurface()
763{
764    m_View->ToggleSurfaceLegs();
765}
766
767void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
768{
769    cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
770    cmd.Check(m_View->ShowingSurfaceLegs());
771}
772
773void GUIControl::OnShowEntrances()
774{
775    m_View->ToggleEntrances();
776}
777
778void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
779{
780    cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
781    cmd.Check(m_View->ShowingEntrances());
782}
783
784void GUIControl::OnShowFixedPts()
785{
786    m_View->ToggleFixedPts();
787}
788
789void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
790{
791    cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
792    cmd.Check(m_View->ShowingFixedPts());
793}
794
795void GUIControl::OnShowExportedPts()
796{
797    m_View->ToggleExportedPts();
798}
799
800void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
801{
802    // FIXME enable only if we have timestamps...
803    cmd.Enable(m_View->HasData() /*&& (m_View->GetNumExportedPts() > 0)*/);
804    cmd.Check(m_View->ShowingExportedPts());
805}
806
807void GUIControl::OnViewGrid()
808{
809    m_View->ToggleGrid();
810}
811
812void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
813{
814    cmd.Enable(m_View->HasData());
815    cmd.Check(m_View->ShowingGrid());
816}
817
818void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
819{
820    cmd.Enable(m_View->HasData());
821}
822
823void GUIControl::OnViewPerspective()
824{
825    m_View->TogglePerspective();
826    // Force update of coordinate display.
827    if (m_View->GetPerspective()) {
828        m_View->MoveViewer(0, 0, 0);
829    } else {
830        m_View->ClearCoords();
831    }
832}
833
834void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
835{
836    cmd.Enable(m_View->HasData());
837    cmd.Check(m_View->GetPerspective());
838}
839
840void GUIControl::OnViewTextured()
841{
842    m_View->ToggleTextured();
843}
844
845void GUIControl::OnViewTexturedUpdate(wxUpdateUIEvent& cmd)
846{
847    cmd.Enable(m_View->HasData());
848    cmd.Check(m_View->GetTextured());
849}
850
851void GUIControl::OnViewFog()
852{
853    m_View->ToggleFog();
854}
855
856void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
857{
858    cmd.Enable(m_View->HasData());
859    cmd.Check(m_View->GetFog());
860}
861
862void GUIControl::OnViewSmoothLines()
863{
864    m_View->ToggleAntiAlias();
865}
866
867void GUIControl::OnViewSmoothLinesUpdate(wxUpdateUIEvent& cmd)
868{
869    cmd.Enable(m_View->HasData());
870    cmd.Check(m_View->GetAntiAlias());
871}
872
873void GUIControl::OnToggleMetric()
874{
875    m_View->ToggleMetric();
876
877    wxConfigBase::Get()->Write("metric", m_View->GetMetric());
878    wxConfigBase::Get()->Flush();
879}
880
881void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
882{
883    cmd.Enable(m_View->HasData());
884    cmd.Check(m_View->GetMetric());
885}
886
887void GUIControl::OnToggleDegrees()
888{
889    m_View->ToggleDegrees();
890
891    wxConfigBase::Get()->Write("degrees", m_View->GetDegrees());
892    wxConfigBase::Get()->Flush();
893}
894
895void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
896{
897    cmd.Enable(m_View->HasData());
898    cmd.Check(m_View->GetDegrees());
899}
900
901void GUIControl::OnToggleTubes()
902{
903    m_View->ToggleTubes();
904}
905
906void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
907{
908    cmd.Enable(m_View->HasData() && m_View->HasTubes());
909    cmd.Check(m_View->GetTubes());
910}
911
912void GUIControl::OnCancelDistLine()
913{
914    m_View->ClearTreeSelection();
915}
916
917void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
918{
919    cmd.Enable(m_View->ShowingMeasuringLine());
920}
921
922void GUIControl::OnKeyPress(wxKeyEvent &e)
923{
924    if (!m_View->HasData()) {
925        e.Skip();
926        return;
927    }
928
929    // The changelog says this is meant to keep animation going while keys are
930    // pressed, but that happens anyway (on linux at least - perhaps it helps
931    // on windows?)  FIXME : check!
932    //bool refresh = m_View->Animate();
933
934    switch (e.m_keyCode) {
935        case '/': case '?':
936            if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
937                OnLowerViewpoint(e.m_shiftDown);
938            break;
939        case '\'': case '@': case '"': // both shifted forms - US and UK kbd
940            if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
941                OnHigherViewpoint(e.m_shiftDown);
942            break;
943        case 'C': case 'c':
944            if (m_View->CanRotate() && !m_View->IsRotating())
945                OnStepOnceAnticlockwise(e.m_shiftDown);
946            break;
947        case 'V': case 'v':
948            if (m_View->CanRotate() && !m_View->IsRotating())
949                OnStepOnceClockwise(e.m_shiftDown);
950            break;
951        case ']': case '}':
952            if (m_View->GetLock() != lock_POINT)
953                OnZoomIn(e.m_shiftDown);
954            break;
955        case '[': case '{':
956            if (m_View->GetLock() != lock_POINT)
957                OnZoomOut(e.m_shiftDown);
958            break;
959        case 'N': case 'n':
960            if (!(m_View->GetLock() & lock_X))
961                OnMoveNorth();
962            break;
963        case 'S': case 's':
964            if (!(m_View->GetLock() & lock_X))
965                OnMoveSouth();
966            break;
967        case 'E': case 'e':
968            if (!(m_View->GetLock() & lock_Y))
969                OnMoveEast();
970            break;
971        case 'W': case 'w':
972            if (!(m_View->GetLock() & lock_Y))
973                OnMoveWest();
974            break;
975        case 'Z': case 'z':
976            if (m_View->CanRotate())
977                OnSpeedUp(e.m_shiftDown);
978            break;
979        case 'X': case 'x':
980            if (m_View->CanRotate())
981                OnSlowDown(e.m_shiftDown);
982            break;
983        case 'R': case 'r':
984            if (m_View->CanRotate())
985                OnReverseDirectionOfRotation();
986            break;
987        case 'P': case 'p':
988            if (m_View->GetLock() == lock_NONE && !m_View->ShowingPlan())
989                OnPlan();
990            break;
991        case 'L': case 'l':
992            if (m_View->GetLock() == lock_NONE && !m_View->ShowingElevation())
993                OnElevation();
994            break;
995        case 'O': case 'o':
996            OnDisplayOverlappingNames();
997            break;
998        case WXK_DELETE:
999            OnDefaults();
1000            break;
1001        case WXK_RETURN:
1002            // For compatibility with older versions.
1003            if (m_View->CanRotate() && !m_View->IsRotating())
1004                m_View->StartRotation();
1005            break;
1006        case WXK_SPACE:
1007            if (m_View->CanRotate())
1008                OnToggleRotation();
1009            break;
1010        case WXK_LEFT:
1011            if (e.m_controlDown) {
1012                if (m_View->CanRotate() && !m_View->IsRotating())
1013                    OnStepOnceAnticlockwise(e.m_shiftDown);
1014            } else {
1015                OnShiftDisplayLeft(e.m_shiftDown);
1016            }
1017            break;
1018        case WXK_RIGHT:
1019            if (e.m_controlDown) {
1020                if (m_View->CanRotate() && !m_View->IsRotating())
1021                    OnStepOnceClockwise(e.m_shiftDown);
1022            } else {
1023                OnShiftDisplayRight(e.m_shiftDown);
1024            }
1025            break;
1026        case WXK_UP:
1027            if (e.m_controlDown) {
1028                if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
1029                    OnHigherViewpoint(e.m_shiftDown);
1030            } else {
1031                OnShiftDisplayUp(e.m_shiftDown);
1032            }
1033            break;
1034        case WXK_DOWN:
1035            if (e.m_controlDown) {
1036                if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
1037                    OnLowerViewpoint(e.m_shiftDown);
1038            } else {
1039                OnShiftDisplayDown(e.m_shiftDown);
1040            }
1041            break;
1042        case WXK_ESCAPE:
1043            if (m_View->ShowingMeasuringLine()) {
1044                OnCancelDistLine();
1045            }
1046            break;
1047        default:
1048            e.Skip();
1049    }
1050
1051    //if (refresh) m_View->ForceRefresh();
1052}
1053
1054void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1055{
1056    cmd.Enable(m_View->HasData());
1057    cmd.Check(m_View->IsFullScreen());
1058}
1059
1060void GUIControl::OnViewFullScreen()
1061{
1062    m_View->FullScreenMode();
1063}
1064
1065void GUIControl::OnViewBoundingBoxUpdate(wxUpdateUIEvent& cmd)
1066{
1067    cmd.Enable(m_View->HasData());
1068    cmd.Check(m_View->DisplayingBoundingBox());
1069}
1070
1071void GUIControl::OnViewBoundingBox()
1072{
1073    m_View->ToggleBoundingBox();
1074}
Note: See TracBrowser for help on using the repository browser.