source: git/src/guicontrol.cc @ c60062d

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

Added depth fogging.

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

  • Property mode set to 100644
File size: 23.2 KB
Line 
1//
2//  guicontrol.cc
3//
4//  Handlers for events relating to the display of a survey.
5//
6//  Copyright (C) 2000-2002 Mark R. Shinwell
7//  Copyright (C) 2001-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 * M_PI / 180.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) dy = -dy;
67
68    m_View->TiltCave(Double(-dy) * M_PI / 500.0);
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#ifndef FLYFREE
87    m_View->TranslateCave(dx, dy);
88#else
89    m_View->MoveViewer(0, -dy, dx);
90#endif
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#ifndef FLYFREE
107    m_View->SetScale(m_View->GetScale() * pow(1.06, 0.08 * dy));
108    m_View->ForceRefresh();
109#else
110    m_View->MoveViewer(dy, 0, 0);
111#endif
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) {
124        dx = -dx;
125        dy = -dy;
126    }
127
128    // left/right => rotate, up/down => tilt
129    m_View->TurnCave(m_View->CanRotate() ?
130                     (Double(dx) * (M_PI / -500.0)) : 0.0);
131    m_View->TiltCave(Double(-dy) * M_PI / 1000.0);
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) * (-M_PI / 500.0)) : 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::OnShowCrosses()
386{
387    m_View->ToggleCrosses();
388}
389
390void GUIControl::OnShowCrossesUpdate(wxUpdateUIEvent& cmd)
391{
392    cmd.Enable(m_View->HasData());
393    cmd.Check(m_View->ShowingCrosses());
394}
395
396void GUIControl::OnShowStationNames()
397{
398    m_View->ToggleStationNames();
399}
400
401void GUIControl::OnShowStationNamesUpdate(wxUpdateUIEvent& cmd)
402{
403    cmd.Enable(m_View->HasData());
404    cmd.Check(m_View->ShowingStationNames());
405}
406
407void GUIControl::OnShowSurveyLegs()
408{
409    m_View->ToggleUndergroundLegs();
410}
411
412void GUIControl::OnShowSurveyLegsUpdate(wxUpdateUIEvent& cmd)
413{
414    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT && m_View->HasUndergroundLegs());
415    cmd.Check(m_View->ShowingUndergroundLegs());
416}
417
418void GUIControl::OnMoveEast()
419{
420    m_View->TurnCaveTo(M_PI_2);
421    m_View->ForceRefresh();
422}
423
424void GUIControl::OnMoveEastUpdate(wxUpdateUIEvent& cmd)
425{
426    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
427}
428
429void GUIControl::OnMoveNorth()
430{
431    m_View->TurnCaveTo(0.0);
432    m_View->ForceRefresh();
433}
434
435void GUIControl::OnMoveNorthUpdate(wxUpdateUIEvent& cmd)
436{
437    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
438}
439
440void GUIControl::OnMoveSouth()
441{
442    m_View->TurnCaveTo(M_PI);
443    m_View->ForceRefresh();
444}
445
446void GUIControl::OnMoveSouthUpdate(wxUpdateUIEvent& cmd)
447{
448    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_X));
449}
450
451void GUIControl::OnMoveWest()
452{
453    m_View->TurnCaveTo(M_PI * 1.5);
454    m_View->ForceRefresh();
455}
456
457void GUIControl::OnMoveWestUpdate(wxUpdateUIEvent& cmd)
458{
459    cmd.Enable(m_View->HasData() && !(m_View->GetLock() & lock_Y));
460}
461
462void GUIControl::OnStartRotation()
463{
464    m_View->StartRotation();
465}
466
467void GUIControl::OnStartRotationUpdate(wxUpdateUIEvent& cmd)
468{
469    cmd.Enable(m_View->HasData() && !m_View->IsRotating() && m_View->CanRotate());
470}
471
472void GUIControl::OnToggleRotation()
473{
474    m_View->ToggleRotation();
475}
476
477void GUIControl::OnToggleRotationUpdate(wxUpdateUIEvent& cmd)
478{
479    cmd.Enable(m_View->HasData() && m_View->CanRotate());
480    cmd.Check(m_View->HasData() && m_View->IsRotating());
481}
482
483void GUIControl::OnStopRotation()
484{
485    m_View->StopRotation();
486}
487
488void GUIControl::OnStopRotationUpdate(wxUpdateUIEvent& cmd)
489{
490    cmd.Enable(m_View->HasData() && m_View->IsRotating());
491}
492
493void GUIControl::OnReverseControls()
494{
495    m_ReverseControls = !m_ReverseControls;
496}
497
498void GUIControl::OnReverseControlsUpdate(wxUpdateUIEvent& cmd)
499{
500    cmd.Enable(m_View->HasData());
501    cmd.Check(m_ReverseControls);
502}
503
504void GUIControl::OnReverseDirectionOfRotation()
505{
506    m_View->ReverseRotation();
507}
508
509void GUIControl::OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent& cmd)
510{
511    cmd.Enable(m_View->HasData() && m_View->CanRotate());
512}
513
514void GUIControl::OnSlowDown(bool accel)
515{
516    m_View->RotateSlower(accel);
517}
518
519void GUIControl::OnSlowDownUpdate(wxUpdateUIEvent& cmd)
520{
521    cmd.Enable(m_View->HasData() && m_View->CanRotate());
522}
523
524void GUIControl::OnSpeedUp(bool accel)
525{
526    m_View->RotateFaster(accel);
527}
528
529void GUIControl::OnSpeedUpUpdate(wxUpdateUIEvent& cmd)
530{
531    cmd.Enable(m_View->HasData() && m_View->CanRotate());
532}
533
534void GUIControl::OnStepOnceAnticlockwise(bool accel)
535{
536    m_View->TurnCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
537    m_View->ForceRefresh();
538}
539
540void GUIControl::OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent& cmd)
541{
542    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
543}
544
545void GUIControl::OnStepOnceClockwise(bool accel)
546{
547    m_View->TurnCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
548    m_View->ForceRefresh();
549}
550
551void GUIControl::OnStepOnceClockwiseUpdate(wxUpdateUIEvent& cmd)
552{
553    cmd.Enable(m_View->HasData() && m_View->CanRotate() && !m_View->IsRotating());
554}
555
556void GUIControl::OnDefaults()
557{
558    m_View->Defaults();
559}
560
561void GUIControl::OnDefaultsUpdate(wxUpdateUIEvent& cmd)
562{
563    cmd.Enable(m_View->HasData());
564}
565
566void GUIControl::OnElevation()
567{
568    // Switch to elevation view.
569
570    m_View->SwitchToElevation();
571}
572
573void GUIControl::OnElevationUpdate(wxUpdateUIEvent& cmd)
574{
575    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingElevation());
576}
577
578void GUIControl::OnHigherViewpoint(bool accel)
579{
580    // Raise the viewpoint.
581    m_View->TiltCave(accel ? 5.0 * ROTATE_STEP : ROTATE_STEP);
582    m_View->ForceRefresh();
583}
584
585void GUIControl::OnHigherViewpointUpdate(wxUpdateUIEvent& cmd)
586{
587    cmd.Enable(m_View->HasData() && m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE);
588}
589
590void GUIControl::OnLowerViewpoint(bool accel)
591{
592    // Lower the viewpoint.
593    m_View->TiltCave(accel ? -5.0 * ROTATE_STEP : -ROTATE_STEP);
594    m_View->ForceRefresh();
595}
596
597void GUIControl::OnLowerViewpointUpdate(wxUpdateUIEvent& cmd)
598{
599    cmd.Enable(m_View->HasData() && m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE);
600}
601
602void GUIControl::OnPlan()
603{
604    // Switch to plan view.
605    m_View->SwitchToPlan();
606}
607
608void GUIControl::OnPlanUpdate(wxUpdateUIEvent& cmd)
609{
610    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE && !m_View->ShowingPlan());
611}
612
613void GUIControl::OnShiftDisplayDown(bool accel)
614{
615#ifndef FLYFREE
616    m_View->TranslateCave(0, accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT);
617#else
618    m_View->MoveViewer(0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0);
619#endif
620}
621
622void GUIControl::OnShiftDisplayDownUpdate(wxUpdateUIEvent& cmd)
623{
624    cmd.Enable(m_View->HasData());
625}
626
627void GUIControl::OnShiftDisplayLeft(bool accel)
628{
629#ifndef FLYFREE
630    m_View->TranslateCave(accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT, 0);
631#else
632    m_View->MoveViewer(0, 0, accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT);
633#endif
634}
635
636void GUIControl::OnShiftDisplayLeftUpdate(wxUpdateUIEvent& cmd)
637{
638    cmd.Enable(m_View->HasData());
639}
640
641void GUIControl::OnShiftDisplayRight(bool accel)
642{
643#ifndef FLYFREE
644    m_View->TranslateCave(accel ? 5 * DISPLAY_SHIFT : DISPLAY_SHIFT, 0);
645#else
646    m_View->MoveViewer(0, 0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT);
647#endif
648}
649
650void GUIControl::OnShiftDisplayRightUpdate(wxUpdateUIEvent& cmd)
651{
652    cmd.Enable(m_View->HasData());
653}
654
655void GUIControl::OnShiftDisplayUp(bool accel)
656{
657#ifndef FLYFREE
658    m_View->TranslateCave(0, accel ? -5 * DISPLAY_SHIFT : -DISPLAY_SHIFT);
659#else
660    m_View->MoveViewer(0, accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0);
661#endif
662}
663
664void GUIControl::OnShiftDisplayUpUpdate(wxUpdateUIEvent& cmd)
665{
666    cmd.Enable(m_View->HasData());
667}
668
669void GUIControl::OnZoomIn(bool accel)
670{
671    // Increase the scale.
672
673#ifndef FLYFREE
674    m_View->SetScale(m_View->GetScale() * (accel ? 1.1236 : 1.06));
675    m_View->ForceRefresh();
676#else
677    m_View->MoveViewer(accel ? 5 * FLYFREE_SHIFT : FLYFREE_SHIFT, 0, 0);
678#endif
679}
680
681void GUIControl::OnZoomInUpdate(wxUpdateUIEvent& cmd)
682{
683    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
684}
685
686void GUIControl::OnZoomOut(bool accel)
687{
688    // Decrease the scale.
689
690#ifndef FLYFREE
691    m_View->SetScale(m_View->GetScale() / (accel ? 1.1236 : 1.06));
692    m_View->ForceRefresh();
693#else
694    m_View->MoveViewer(accel ? -5 * FLYFREE_SHIFT : -FLYFREE_SHIFT, 0, 0);
695#endif
696}
697
698void GUIControl::OnZoomOutUpdate(wxUpdateUIEvent& cmd)
699{
700    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
701}
702
703void GUIControl::OnToggleScalebar()
704{
705    m_View->ToggleScaleBar();
706}
707
708void GUIControl::OnToggleScalebarUpdate(wxUpdateUIEvent& cmd)
709{
710    cmd.Enable(m_View->HasData() && m_View->GetLock() != lock_POINT);
711    cmd.Check(m_View->ShowingScaleBar());
712}
713
714void GUIControl::OnToggleDepthbar() /* FIXME naming */
715{
716    m_View->ToggleDepthBar();
717}
718
719void GUIControl::OnToggleDepthbarUpdate(wxUpdateUIEvent& cmd)
720{
721    cmd.Enable(m_View->HasData() && !(m_View->GetLock() && lock_Z));
722    cmd.Check(m_View->ShowingDepthBar());
723}
724
725void GUIControl::OnViewCompass()
726{
727    m_View->ToggleCompass();
728}
729
730void GUIControl::OnViewCompassUpdate(wxUpdateUIEvent& cmd)
731{
732    cmd.Enable(m_View->HasData() && m_View->CanRotate());
733    cmd.Check(m_View->ShowingCompass());
734}
735
736void GUIControl::OnViewClino()
737{
738    m_View->ToggleClino();
739}
740
741void GUIControl::OnViewClinoUpdate(wxUpdateUIEvent& cmd)
742{
743    cmd.Enable(m_View->HasData() && m_View->GetLock() == lock_NONE);
744    cmd.Check(m_View->ShowingClino());
745}
746
747void GUIControl::OnShowSurface()
748{
749    m_View->ToggleSurfaceLegs();
750}
751
752void GUIControl::OnShowSurfaceUpdate(wxUpdateUIEvent& cmd)
753{
754    cmd.Enable(m_View->HasData() && m_View->HasSurfaceLegs());
755    cmd.Check(m_View->ShowingSurfaceLegs());
756}
757
758void GUIControl::OnShowEntrances()
759{
760    m_View->ToggleEntrances();
761}
762
763void GUIControl::OnShowEntrancesUpdate(wxUpdateUIEvent& cmd)
764{
765    cmd.Enable(m_View->HasData() && (m_View->GetNumEntrances() > 0));
766    cmd.Check(m_View->ShowingEntrances());
767}
768
769void GUIControl::OnShowFixedPts()
770{
771    m_View->ToggleFixedPts();
772}
773
774void GUIControl::OnShowFixedPtsUpdate(wxUpdateUIEvent& cmd)
775{
776    cmd.Enable(m_View->HasData() && (m_View->GetNumFixedPts() > 0));
777    cmd.Check(m_View->ShowingFixedPts());
778}
779
780void GUIControl::OnShowExportedPts()
781{
782    m_View->ToggleExportedPts();
783}
784
785void GUIControl::OnShowExportedPtsUpdate(wxUpdateUIEvent& cmd)
786{
787    cmd.Enable(m_View->HasData() && (m_View->GetNumExportedPts() > 0));
788    cmd.Check(m_View->ShowingExportedPts());
789}
790
791void GUIControl::OnViewGrid()
792{
793    m_View->ToggleGrid();
794}
795
796void GUIControl::OnViewGridUpdate(wxUpdateUIEvent& cmd)
797{
798    cmd.Enable(m_View->HasData());
799}
800
801void GUIControl::OnIndicatorsUpdate(wxUpdateUIEvent& cmd)
802{
803    cmd.Enable(m_View->HasData());
804}
805
806void GUIControl::OnViewPerspective()
807{
808    m_View->TogglePerspective();
809}
810
811void GUIControl::OnViewPerspectiveUpdate(wxUpdateUIEvent& cmd)
812{
813    cmd.Enable(m_View->HasData());
814    cmd.Check(m_View->GetPerspective());
815}
816
817void GUIControl::OnViewFog()
818{
819    m_View->ToggleFog();
820}
821
822void GUIControl::OnViewFogUpdate(wxUpdateUIEvent& cmd)
823{
824    cmd.Enable(m_View->HasData());
825    cmd.Check(m_View->GetFog());
826}
827
828void GUIControl::OnToggleMetric()
829{
830    m_View->ToggleMetric();
831
832    wxConfigBase::Get()->Write("metric", m_View->GetMetric());
833    wxConfigBase::Get()->Flush();
834}
835
836void GUIControl::OnToggleMetricUpdate(wxUpdateUIEvent& cmd)
837{
838    cmd.Enable(m_View->HasData());
839    cmd.Check(m_View->GetMetric());
840}
841
842void GUIControl::OnToggleDegrees()
843{
844    m_View->ToggleDegrees();
845   
846    wxConfigBase::Get()->Write("degrees", m_View->GetDegrees());
847    wxConfigBase::Get()->Flush();
848}
849
850void GUIControl::OnToggleDegreesUpdate(wxUpdateUIEvent& cmd)
851{
852    cmd.Enable(m_View->HasData());
853    cmd.Check(m_View->GetDegrees());
854}
855
856void GUIControl::OnToggleTubes()
857{
858    m_View->ToggleTubes();
859}
860
861void GUIControl::OnToggleTubesUpdate(wxUpdateUIEvent& cmd)
862{
863    cmd.Enable(m_View->HasData());
864    cmd.Check(m_View->GetTubes());
865}
866
867void GUIControl::OnCancelDistLine()
868{
869    m_View->ClearTreeSelection();
870}
871
872void GUIControl::OnCancelDistLineUpdate(wxUpdateUIEvent& cmd)
873{
874    cmd.Enable(m_View->ShowingMeasuringLine());
875}
876
877void GUIControl::OnKeyPress(wxKeyEvent &e)
878{
879    if (!m_View->HasData()) {
880        e.Skip();
881        return;
882    }
883
884    // The changelog says this is meant to keep animation going while keys are
885    // pressed, but that happens anyway (on linux at least - perhaps it helps
886    // on windows?)  FIXME : check!
887    //bool refresh = m_View->Animate();
888
889    switch (e.m_keyCode) {
890        case '/': case '?':
891            if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
892                OnLowerViewpoint(e.m_shiftDown);
893            break;
894        case '\'': case '@': case '"': // both shifted forms - US and UK kbd
895            if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
896                OnHigherViewpoint(e.m_shiftDown);
897            break;
898        case 'C': case 'c':
899            if (m_View->CanRotate() && !m_View->IsRotating())
900                OnStepOnceAnticlockwise(e.m_shiftDown);
901            break;
902        case 'V': case 'v':
903            if (m_View->CanRotate() && !m_View->IsRotating())
904                OnStepOnceClockwise(e.m_shiftDown);
905            break;
906        case ']': case '}':
907            if (m_View->GetLock() != lock_POINT)
908                OnZoomIn(e.m_shiftDown);
909            break;
910        case '[': case '{':
911            if (m_View->GetLock() != lock_POINT)
912                OnZoomOut(e.m_shiftDown);
913            break;
914        case 'N': case 'n':
915            if (!(m_View->GetLock() & lock_X))
916                OnMoveNorth();
917            break;
918        case 'S': case 's':
919            if (!(m_View->GetLock() & lock_X))
920                OnMoveSouth();
921            break;
922        case 'E': case 'e':
923            if (!(m_View->GetLock() & lock_Y))
924                OnMoveEast();
925            break;
926        case 'W': case 'w':
927            if (!(m_View->GetLock() & lock_Y))
928                OnMoveWest();
929            break;
930        case 'Z': case 'z':
931            if (m_View->CanRotate())
932                OnSpeedUp(e.m_shiftDown);
933            break;
934        case 'X': case 'x':
935            if (m_View->CanRotate())
936                OnSlowDown(e.m_shiftDown);
937            break;
938        case 'R': case 'r':
939            if (m_View->CanRotate())
940                OnReverseDirectionOfRotation();
941            break;
942        case 'P': case 'p':
943            if (m_View->GetLock() == lock_NONE && !m_View->ShowingPlan())
944                OnPlan();
945            break;
946        case 'L': case 'l':
947            if (m_View->GetLock() == lock_NONE && !m_View->ShowingElevation())
948                OnElevation();
949            break;
950        case 'O': case 'o':
951            OnDisplayOverlappingNames();
952            break;
953        case WXK_DELETE:
954            OnDefaults();
955            break;
956        case WXK_RETURN:
957            if (m_View->CanRotate() && !m_View->IsRotating())
958                OnStartRotation();
959            break;
960        case WXK_SPACE:
961            if (m_View->IsRotating())
962                OnStopRotation();
963            break;
964        case WXK_LEFT:
965            if (e.m_controlDown) {
966                if (m_View->CanRotate() && !m_View->IsRotating())
967                    OnStepOnceAnticlockwise(e.m_shiftDown);
968            } else {
969                OnShiftDisplayLeft(e.m_shiftDown);
970            }
971            break;
972        case WXK_RIGHT:
973            if (e.m_controlDown) {
974                if (m_View->CanRotate() && !m_View->IsRotating())
975                    OnStepOnceClockwise(e.m_shiftDown);
976            } else {
977                OnShiftDisplayRight(e.m_shiftDown);
978            }
979            break;
980        case WXK_UP:
981            if (e.m_controlDown) {
982                if (m_View->CanRaiseViewpoint() && m_View->GetLock() == lock_NONE)
983                    OnHigherViewpoint(e.m_shiftDown);
984            } else {
985                OnShiftDisplayUp(e.m_shiftDown);
986            }
987            break;
988        case WXK_DOWN:
989            if (e.m_controlDown) {
990                if (m_View->CanLowerViewpoint() && m_View->GetLock() == lock_NONE)
991                    OnLowerViewpoint(e.m_shiftDown);
992            } else {
993                OnShiftDisplayDown(e.m_shiftDown);
994            }
995            break;
996        case WXK_ESCAPE:
997            if (m_View->ShowingMeasuringLine()) {
998                OnCancelDistLine();
999            }
1000            break;
1001        default:
1002            e.Skip();
1003    }
1004 
1005    //if (refresh) m_View->ForceRefresh();
1006}
1007
1008void GUIControl::OnViewFullScreenUpdate(wxUpdateUIEvent& cmd)
1009{
1010    cmd.Enable(m_View->HasData());
1011    cmd.Check(m_View->IsFullScreen());
1012}
1013
1014void GUIControl::OnViewFullScreen()
1015{
1016    m_View->FullScreenMode();
1017}
Note: See TracBrowser for help on using the repository browser.