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