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