source: git/src/guicontrol.cc @ 816ceb7

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

aven: Added perspective view option.

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

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