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