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