source: git/src/guicontrol.cc @ 142cb9a

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 142cb9a was 096e56c, checked in by Olly Betts <olly@…>, 20 years ago

whitespace changes

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

  • Property mode set to 100644
File size: 24.8 KB
RevLine 
[56da40e]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
[867a1141]7//  Copyright (C) 2001,2003,2004 Olly Betts
[56da40e]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
[cbfa50d]24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
[56da40e]28#include "guicontrol.h"
29#include "gfxcore.h"
30#include <wx/confbase.h>
31
[0c7bb77]32const int DISPLAY_SHIFT = 10;
[d6a5001]33const double FLYFREE_SHIFT = 0.2;
[e577f89]34const double ROTATE_STEP = 2.0;
[56da40e]35
36GUIControl::GUIControl()
37{
38    m_View = NULL;
39    m_DraggingLeft = false;
40    m_DraggingMiddle = false;
41    m_DraggingRight = false;
42    m_ReverseControls = false;
43    m_LastDrag = drag_NONE;
44}
45
46GUIControl::~GUIControl()
47{
48    // no action
49}
50
51void GUIControl::SetView(GfxCore* view)
52{
53    m_View = view;
54}
55
56bool GUIControl::MouseDown()
57{
58    return m_DraggingLeft || m_DraggingMiddle || m_DraggingRight;
59}
60
61void GUIControl::HandleTilt(wxPoint point)
62{
63    // Handle a mouse movement during tilt mode.
64    int dy = point.y - m_DragStart.y;
65
[d877aa2]66    if (m_ReverseControls != m_View->GetPerspective()) dy = -dy;
[56da40e]67
[e577f89]68    m_View->TiltCave(Double(-dy) * 0.36);
[56da40e]69
70    m_DragStart = point;
71
72    m_View->ForceRefresh();
73}
74
75void GUIControl::HandleTranslate(wxPoint point)
76{
77    // Handle a mouse movement during translation mode.
78    int dx = point.x - m_DragStart.x;
79    int dy = point.y - m_DragStart.y;
[096e56c]80
[56da40e]81    if (m_ReverseControls) {
82        dx = -dx;
83        dy = -dy;
84    }
85
[d877aa2]86    if (m_View->GetPerspective())
87        m_View->MoveViewer(0, -dy * .1, dx * .1);
88    else
89        m_View->TranslateCave(dx, dy);
90
[56da40e]91    m_DragStart = point;
92}
93
[dde4fe7]94void GUIControl::HandleScale(wxPoint point)
95{
96    // Handle a mouse movement during scale mode.
97
98    int dx = point.x - m_DragStart.x;
99    int dy = point.y - m_DragStart.y;
100
101    if (m_ReverseControls) {
102        dx = -dx;
103        dy = -dy;
104    }
105
[d877aa2]106    if (m_View->GetPerspective()) {
107        m_View->MoveViewer(-dy * .1, 0, 0);
108    } else {
109        m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
110        m_View->ForceRefresh();
111    }
[dde4fe7]112
113    m_DragStart = point;
114}
115
116void GUIControl::HandleTiltRotate(wxPoint point)
117{
118    // Handle a mouse movement during tilt/rotate mode.
119
120    int dx = point.x - m_DragStart.x;
121    int dy = point.y - m_DragStart.y;
122
[d877aa2]123    if (m_ReverseControls != m_View->GetPerspective()) {
[dde4fe7]124        dx = -dx;
125        dy = -dy;
126    }
127
[e577f89]128    // left/right => rotate, up/down => tilt.
129    // Make tilt less sensitive than rotate as that feels better.
130    m_View->TurnCave(m_View->CanRotate() ? (Double(dx) * -0.36) : 0.0);
131    m_View->TiltCave(Double(-dy) * 0.18);
[dde4fe7]132
133    m_View->ForceRefresh();
134
135    m_DragStart = point;
136}
137
138void GUIControl::HandleScaleRotate(wxPoint point)
[56da40e]139{
140    // Handle a mouse movement during scale/rotate mode.
141    int dx = point.x - m_DragStart.x;
142    int dy = point.y - m_DragStart.y;
143
144    if (m_ReverseControls) {
145        dx = -dx;
146        dy = -dy;
147    }
148
[e577f89]149    Double pan_angle = m_View->CanRotate() ? (Double(dx) * -0.36) : 0.0;
[56da40e]150
151    // left/right => rotate, up/down => scale
152    m_View->TurnCave(pan_angle);
153
[dde4fe7]154    m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
[56da40e]155
156#ifdef AVENGL
157    //glDeleteLists(m_Lists.grid, 1);
158    //    DrawGrid();
159#endif
160    m_View->ForceRefresh();
161
162    m_DragStart = point;
163}
164
[203d2a7]165void GUIControl::HandCursor()
166{
167    const wxCursor HAND_CURSOR(wxCURSOR_HAND);
168    m_View->SetCursor(HAND_CURSOR);
169}
170
171void GUIControl::RestoreCursor()
172{
173    if (m_View->ShowingMeasuringLine()) {
174        HandCursor();
[096e56c]175    } else {
[203d2a7]176        m_View->SetCursor(wxNullCursor);
177    }
178}
179
[56da40e]180//
181//  Mouse event handling methods
182//
183
184void GUIControl::OnMouseMove(wxMouseEvent& event)
185{
186    // Mouse motion event handler.
187    if (!m_View->HasData()) return;
188
189    wxPoint point = wxPoint(event.GetX(), event.GetY());
190
191    // Check hit-test grid (only if no buttons are pressed).
192    if (!event.LeftIsDown() && !event.MiddleIsDown() && !event.RightIsDown()) {
[203d2a7]193        if (m_View->CheckHitTestGrid(point, false)) {
194            HandCursor();
[096e56c]195        } else {
[203d2a7]196            if (m_View->ShowingScaleBar() &&
197                m_View->PointWithinScaleBar(point)) {
198
199                const wxCursor CURSOR(wxCURSOR_SIZEWE);
200                m_View->SetCursor(CURSOR);
[096e56c]201            } else {
[203d2a7]202                m_View->SetCursor(wxNullCursor);
203            }
204        }
[56da40e]205    }
206
[203d2a7]207    // Update coordinate display if in plan view,
208    // or altitude if in elevation view.
[56da40e]209    m_View->SetCoords(point);
210
211    if (!m_View->ChangingOrientation()) {
212        if (m_DraggingLeft) {
213            if (m_LastDrag == drag_NONE) {
[203d2a7]214                if (m_View->ShowingCompass() &&
215                    m_View->PointWithinCompass(point)) {
[56da40e]216                    m_LastDrag = drag_COMPASS;
[096e56c]217                } else if (m_View->ShowingClino() &&
[203d2a7]218                         m_View->PointWithinClino(point)) {
[56da40e]219                    m_LastDrag = drag_ELEV;
[096e56c]220                } else if (m_View->ShowingScaleBar() &&
[203d2a7]221                         m_View->PointWithinScaleBar(point)) {
[56da40e]222                    m_LastDrag = drag_SCALE;
223                }
224            }
225
226            if (m_LastDrag == drag_COMPASS) {
227                // drag in heading indicator
228                m_View->SetCompassFromPoint(point);
[096e56c]229            } else if (m_LastDrag == drag_ELEV) {
[56da40e]230                // drag in clinometer
231                m_View->SetClinoFromPoint(point);
[096e56c]232            } else if (m_LastDrag == drag_SCALE) {
[dde4fe7]233                // FIXME: check why there was a check here for x being inside
234                // the window
[56da40e]235                m_View->SetScaleBarFromOffset(point.x - m_DragLast.x);
[096e56c]236            } else if (m_LastDrag == drag_NONE || m_LastDrag == drag_MAIN) {
[56da40e]237                m_LastDrag = drag_MAIN;
[dde4fe7]238                if (event.ShiftDown()) {
239                    HandleScaleRotate(point);
[096e56c]240                } else {
[dde4fe7]241                    HandleTiltRotate(point);
242                }
[56da40e]243            }
[096e56c]244        } else if (m_DraggingMiddle) {
[dde4fe7]245            if (event.ShiftDown()) {
246                HandleTilt(point);
[096e56c]247            } else {
[dde4fe7]248                HandleScale(point);
249            }
[096e56c]250        } else if (m_DraggingRight) {
[56da40e]251            if ((m_LastDrag == drag_NONE && m_View->PointWithinScaleBar(point)) || m_LastDrag == drag_SCALE) {
252            /* FIXME
253                  if (point.x < 0) point.x = 0;
254                  if (point.y < 0) point.y = 0;
255                  if (point.x > m_XSize) point.x = m_XSize;
256                  if (point.y > m_YSize) point.y = m_YSize;
257                  m_LastDrag = drag_SCALE;
258                  int x_inside_bar = m_DragStart.x - m_ScaleBar.drag_start_offset_x;
259                  int y_inside_bar = m_YSize - m_ScaleBar.drag_start_offset_y - m_DragStart.y;
260                  m_ScaleBar.offset_x = point.x - x_inside_bar;
261                  m_ScaleBar.offset_y = (m_YSize - point.y) - y_inside_bar;
262                  m_View->ForceRefresh(); */
[096e56c]263            } else {
[56da40e]264                m_LastDrag = drag_MAIN;
265                HandleTranslate(point);
266            }
267        }
268    }
269
270    m_DragLast = point;
271}
272
273void GUIControl::OnLButtonDown(wxMouseEvent& event)
274{
275    if (m_View->HasData() && m_View->GetLock() != lock_POINT) {
276        m_DraggingLeft = true;
[096e56c]277
[56da40e]278        /* FIXME
279        m_ScaleBar.drag_start_offset_x = m_ScaleBar.offset_x;
280        m_ScaleBar.drag_start_offset_y = m_ScaleBar.offset_y; */
281
282        m_DragStart = m_DragRealStart = wxPoint(event.GetX(), event.GetY());
[096e56c]283
[203d2a7]284//        const wxCursor CURSOR(wxCURSOR_MAGNIFIER);
285//        m_View->SetCursor(CURSOR);
[56da40e]286        m_View->CaptureMouse();
287    }
288}
289
290void GUIControl::OnLButtonUp(wxMouseEvent& event)
291{
292    if (m_View->HasData() && m_View->GetLock() != lock_POINT) {
293        if (event.GetPosition() == m_DragRealStart) {
294            // just a "click"...
295            m_View->CheckHitTestGrid(m_DragStart, true);
296        }
297
[dde4fe7]298//      m_View->RedrawIndicators();
[56da40e]299        m_View->ReleaseMouse();
300
301        m_LastDrag = drag_NONE;
302        m_DraggingLeft = false;
303
304        m_View->DragFinished();
[096e56c]305
[203d2a7]306        RestoreCursor();
[56da40e]307    }
308}
309
310void GUIControl::OnMButtonDown(wxMouseEvent& event)
311{
312    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
313        m_DraggingMiddle = true;
314        m_DragStart = wxPoint(event.GetX(), event.GetY());
315
[dde4fe7]316        const wxCursor CURSOR(wxCURSOR_MAGNIFIER);
[203d2a7]317        m_View->SetCursor(CURSOR);
[56da40e]318        m_View->CaptureMouse();
319    }
320}
321
[cc2a5fc]322void GUIControl::OnMButtonUp(wxMouseEvent&)
[56da40e]323{
324    if (m_View->HasData() && m_View->GetLock() == lock_NONE) {
325        m_DraggingMiddle = false;
326        m_View->ReleaseMouse();
327        m_View->DragFinished();
[203d2a7]328
329        RestoreCursor();
[56da40e]330    }
331}
332
333void GUIControl::OnRButtonDown(wxMouseEvent& event)
334{
335    if (m_View->HasData()) {
336        m_DragStart = wxPoint(event.GetX(), event.GetY());
[096e56c]337
[56da40e]338/* FIXME        m_ScaleBar.drag_start_offset_x = m_ScaleBar.offset_x;
339        m_ScaleBar.drag_start_offset_y = m_ScaleBar.offset_y; */
340
341        m_DraggingRight = true;
342
[203d2a7]343      //  const wxCursor CURSOR(wxCURSOR_HAND);
344      //  m_View->SetCursor(CURSOR);
[56da40e]345        m_View->CaptureMouse();
346    }
347}
348
[cc2a5fc]349void GUIControl::OnRButtonUp(wxMouseEvent&)
[56da40e]350{
351    m_LastDrag = drag_NONE;
352    m_View->ReleaseMouse();
353
354    m_DraggingRight = false;
[096e56c]355
[203d2a7]356    RestoreCursor();
[096e56c]357
[56da40e]358    m_View->DragFinished();
359}
360
361void GUIControl::OnDisplayOverlappingNames()
362{
363    m_View->ToggleOverlappingNames();
364}
365
366void GUIControl::OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent& cmd)
367{
368    cmd.Enable(m_View->HasData() && m_View->ShowingStationNames());
369    cmd.Check(m_View->ShowingOverlappingNames());
370}
371
[da6c802]372void GUIControl::OnColourByDepth()
373{
374    if (m_View->ColouringBy() == COLOUR_BY_DEPTH) {
375        m_View->SetColourBy(COLOUR_BY_NONE);
376    } else {
377        m_View->SetColourBy(COLOUR_BY_DEPTH);
378    }
379}
380
381void GUIControl::OnColourByDepthUpdate(wxUpdateUIEvent& cmd)
382{
383    cmd.Enable(m_View->HasData() && m_View->HasUndergroundLegs());
384    cmd.Check(m_View->ColouringBy() == COLOUR_BY_DEPTH);
385}
386
[56da40e]387void GUIControl::OnShowCrosses()
388{
389    m_View->ToggleCrosses();
390}
391
392void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
393{
394    cmd.Enable(m_View->HasData());
395    cmd.Check(m_View->ShowingCrosses());
396}
397
398void GUIControl::OnShowStationNames()
399{
400    m_View->ToggleStationNames();
401}
402
403void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
404{
405    cmd.Enable(m_View->HasData());
406    cmd.Check(m_View->ShowingStationNames());
407}
408
409void GUIControl::OnShowSurveyLegs()
410{
411    m_View->ToggleUndergroundLegs();
412}
413
414void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
415{
416    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT && m_View->HasUndergroundLegs());
417    cmd.Check(m_View->ShowingUndergroundLegs());
418}
419
420void GUIControl::OnMoveEast()
421{
[e577f89]422    m_View->TurnCaveTo(90.0);
[56da40e]423    m_View->ForceRefresh();
424}
425
426void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
427{
428    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
429}
430
431void GUIControl::OnMoveNorth()
432{
433    m_View->TurnCaveTo(0.0);
434    m_View->ForceRefresh();
435}
436
437void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
438{
439    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
440}
441
442void GUIControl::OnMoveSouth()
443{
[e577f89]444    m_View->TurnCaveTo(180.0);
[56da40e]445    m_View->ForceRefresh();
446}
447
448void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
449{
450    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
451}
452
453void GUIControl::OnMoveWest()
454{
[e577f89]455    m_View->TurnCaveTo(270.0);
[56da40e]456    m_View->ForceRefresh();
457}
458
459void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
460{
461    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
462}
463
464void GUIControl::OnStartRotation()
465{
466    m_View->StartRotation();
467}
468
469void GUIControl::OnStartRotationUpdate(wxUpdateUIEvent& cmd)
470{
471    cmd.Enable(m_View->HasData() && !m_View->IsRotating() && m_View->CanRotate());
472}
473
474void GUIControl::OnToggleRotation()
475{
476    m_View->ToggleRotation();
477}
478
479void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
480{
481    cmd.Enable(m_View->HasData() && m_View->CanRotate());
482    cmd.Check(m_View->HasData() && m_View->IsRotating());
483}
484
485void GUIControl::OnStopRotation()
486{
487    m_View->StopRotation();
488}
489
490void GUIControl::OnStopRotationUpdate(wxUpdateUIEvent& cmd)
491{
492    cmd.Enable(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{
[d877aa2]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    }
[56da40e]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{
[d877aa2]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    }
[56da40e]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.
[d877aa2]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    }
[56da40e]596    m_View->ForceRefresh();
597}
598
599void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
600{
[0662b0b]601    cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE);
[56da40e]602}
603
604void GUIControl::OnLowerViewpoint(bool accel)
605{
606    // Lower the viewpoint.
[d877aa2]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    }
[d6a5001]612    m_View->ForceRefresh();
[56da40e]613}
614
615void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
616{
[0662b0b]617    cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE);
[56da40e]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{
[096e56c]633    if (m_View->GetPerspective())
[867a1141]634        m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
[d877aa2]635    else
636        m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
[56da40e]637}
638
639void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
640{
641    cmd.Enable(m_View->HasData());
642}
643
644void GUIControl::OnShiftDisplayLeft(bool accel)
645{
[096e56c]646    if (m_View->GetPerspective())
[867a1141]647        m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
[d877aa2]648    else
649        m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
[56da40e]650}
651
652void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
653{
654    cmd.Enable(m_View->HasData());
655}
656
657void GUIControl::OnShiftDisplayRight(bool accel)
658{
[096e56c]659    if (m_View->GetPerspective())
[867a1141]660        m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
[d877aa2]661    else
662        m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
[56da40e]663}
664
665void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
666{
667    cmd.Enable(m_View->HasData());
668}
669
670void GUIControl::OnShiftDisplayUp(bool accel)
671{
[096e56c]672    if (m_View->GetPerspective())
[867a1141]673        m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
[d877aa2]674    else
675        m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
[56da40e]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
[d877aa2]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    }
[56da40e]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
[d877aa2]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    }
[56da40e]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{
[da6c802]735    cmd.Enable(m_View->HasData() && !(m_View->GetLock() && lock_Z) &&
736               m_View->ColouringBy() == COLOUR_BY_DEPTH);
[56da40e]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{
[d877aa2]802    // FIXME enable only if we have timestamps...
803    cmd.Enable(m_View->HasData() /*&& (m_View->GetNumExportedPts() > 0)*/);
[56da40e]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());
[0580c6a]815    cmd.Check(m_View->ShowingGrid());
[56da40e]816}
817
818void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
819{
820    cmd.Enable(m_View->HasData());
821}
822
[6abab84]823void GUIControl::OnViewPerspective()
824{
825    m_View->TogglePerspective();
[d877aa2]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    }
[6abab84]832}
833
834void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
835{
836    cmd.Enable(m_View->HasData());
837    cmd.Check(m_View->GetPerspective());
838}
839
[a517825]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
[c60062d]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
[db452ae]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
[56da40e]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();
[096e56c]890
[56da40e]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());
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
[1690fa9]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();
[56da40e]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            if (m_View->CanRotate() && !m_View->IsRotating())
1003                OnStartRotation();
1004            break;
1005        case WXK_SPACE:
1006            if (m_View->IsRotating())
1007                OnStopRotation();
1008            break;
1009        case WXK_LEFT:
1010            if (e.m_controlDown) {
1011                if (m_View->CanRotate() && !m_View->IsRotating())
1012                    OnStepOnceAnticlockwise(e.m_shiftDown);
1013            } else {
1014                OnShiftDisplayLeft(e.m_shiftDown);
1015            }
1016            break;
1017        case WXK_RIGHT:
1018            if (e.m_controlDown) {
1019                if (m_View->CanRotate() && !m_View->IsRotating())
1020                    OnStepOnceClockwise(e.m_shiftDown);
1021            } else {
1022                OnShiftDisplayRight(e.m_shiftDown);
1023            }
1024            break;
1025        case WXK_UP:
1026            if (e.m_controlDown) {
1027                if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
1028                    OnHigherViewpoint(e.m_shiftDown);
1029            } else {
1030                OnShiftDisplayUp(e.m_shiftDown);
1031            }
1032            break;
1033        case WXK_DOWN:
1034            if (e.m_controlDown) {
1035                if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
1036                    OnLowerViewpoint(e.m_shiftDown);
1037            } else {
1038                OnShiftDisplayDown(e.m_shiftDown);
1039            }
1040            break;
1041        case WXK_ESCAPE:
1042            if (m_View->ShowingMeasuringLine()) {
1043                OnCancelDistLine();
1044            }
1045            break;
1046        default:
1047            e.Skip();
1048    }
[096e56c]1049
[1690fa9]1050    //if (refresh) m_View->ForceRefresh();
[56da40e]1051}
1052
[b13aee4]1053void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1054{
1055    cmd.Enable(m_View->HasData());
[fdfa926]1056    cmd.Check(m_View->IsFullScreen());
[b13aee4]1057}
1058
1059void GUIControl::OnViewFullScreen()
1060{
1061    m_View->FullScreenMode();
1062}
Note: See TracBrowser for help on using the repository browser.