source: git/src/guicontrol.cc @ d12e71f

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 d12e71f was a517825, checked in by Olly Betts <olly@…>, 21 years ago

Added textured walls option.

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

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