[5809313] | 1 | // |
---|
[156dc16] | 2 | // gfxcore.cc |
---|
[5809313] | 3 | // |
---|
[33b2094] | 4 | // Core drawing code for Aven. |
---|
[5809313] | 5 | // |
---|
[b72f4b5] | 6 | // Copyright (C) 2000-2003,2005,2006 Mark R. Shinwell |
---|
[60adbce] | 7 | // Copyright (C) 2001-2003,2004,2005,2006,2007,2010,2011,2012,2014,2015 Olly Betts |
---|
[887c26e] | 8 | // Copyright (C) 2005 Martin Green |
---|
[5809313] | 9 | // |
---|
| 10 | // This program is free software; you can redistribute it and/or modify |
---|
| 11 | // it under the terms of the GNU General Public License as published by |
---|
| 12 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 13 | // (at your option) any later version. |
---|
| 14 | // |
---|
| 15 | // This program is distributed in the hope that it will be useful, |
---|
| 16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | // GNU General Public License for more details. |
---|
| 19 | // |
---|
| 20 | // You should have received a copy of the GNU General Public License |
---|
| 21 | // along with this program; if not, write to the Free Software |
---|
[5940815] | 22 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[5809313] | 23 | // |
---|
| 24 | |
---|
[cbfa50d] | 25 | #ifdef HAVE_CONFIG_H |
---|
| 26 | #include <config.h> |
---|
| 27 | #endif |
---|
| 28 | |
---|
[892a40c] | 29 | #include <assert.h> |
---|
[7aa15c0] | 30 | #include <float.h> |
---|
| 31 | |
---|
[7a89dc2] | 32 | #include "aven.h" |
---|
[1ee204e] | 33 | #include "date.h" |
---|
[112f80c] | 34 | #include "filename.h" |
---|
[5809313] | 35 | #include "gfxcore.h" |
---|
[137bf99] | 36 | #include "mainfrm.h" |
---|
[93c3f97] | 37 | #include "message.h" |
---|
[7a89dc2] | 38 | #include "useful.h" |
---|
[4283d6f] | 39 | #include "printing.h" |
---|
[5876fcb] | 40 | #include "guicontrol.h" |
---|
[6a4cdcb6] | 41 | #include "moviemaker.h" |
---|
[8000d8f] | 42 | |
---|
| 43 | #include <wx/confbase.h> |
---|
[be98901] | 44 | #include <wx/wfstream.h> |
---|
[8000d8f] | 45 | #include <wx/image.h> |
---|
[be98901] | 46 | #include <wx/zipstrm.h> |
---|
[5809313] | 47 | |
---|
[22b0a8f] | 48 | #include <proj_api.h> |
---|
| 49 | |
---|
[9df33bc] | 50 | const unsigned long DEFAULT_HGT_DIM = 3601; |
---|
| 51 | const unsigned long DEFAULT_HGT_SIZE = sqrd(DEFAULT_HGT_DIM) * 2; |
---|
| 52 | |
---|
[3d00693] | 53 | // Values for m_SwitchingTo |
---|
| 54 | #define PLAN 1 |
---|
| 55 | #define ELEVATION 2 |
---|
[3ddd351] | 56 | #define NORTH 3 |
---|
| 57 | #define EAST 4 |
---|
| 58 | #define SOUTH 5 |
---|
| 59 | #define WEST 6 |
---|
[3d00693] | 60 | |
---|
[c61aa79] | 61 | // Any error value higher than this is clamped to this. |
---|
| 62 | #define MAX_ERROR 12.0 |
---|
| 63 | |
---|
[af50685] | 64 | // Any length greater than pow(10, LOG_LEN_MAX) will be clamped to this. |
---|
| 65 | const Double LOG_LEN_MAX = 1.5; |
---|
| 66 | |
---|
[86cdcf2] | 67 | // How many bins per letter height to use when working out non-overlapping |
---|
| 68 | // labels. |
---|
| 69 | const unsigned int QUANTISE_FACTOR = 2; |
---|
| 70 | |
---|
[0e69efe] | 71 | #include "avenpal.h" |
---|
| 72 | |
---|
[6606406] | 73 | static const int INDICATOR_BOX_SIZE = 60; |
---|
[c300a04] | 74 | static const int INDICATOR_GAP = 2; |
---|
[6606406] | 75 | static const int INDICATOR_MARGIN = 5; |
---|
| 76 | static const int INDICATOR_OFFSET_X = 15; |
---|
[c300a04] | 77 | static const int INDICATOR_OFFSET_Y = 15; |
---|
[fe665c4] | 78 | static const int INDICATOR_RADIUS = INDICATOR_BOX_SIZE / 2 - INDICATOR_MARGIN; |
---|
[62da267] | 79 | static const int KEY_OFFSET_X = 10; |
---|
| 80 | static const int KEY_OFFSET_Y = 10; |
---|
| 81 | static const int KEY_EXTRA_LEFT_MARGIN = 2; |
---|
| 82 | static const int KEY_BLOCK_WIDTH = 20; |
---|
| 83 | static const int KEY_BLOCK_HEIGHT = 16; |
---|
[b56df45] | 84 | static const int TICK_LENGTH = 4; |
---|
[42adb19] | 85 | static const int SCALE_BAR_OFFSET_X = 15; |
---|
| 86 | static const int SCALE_BAR_OFFSET_Y = 12; |
---|
| 87 | static const int SCALE_BAR_HEIGHT = 12; |
---|
[aa048c3] | 88 | |
---|
| 89 | static const gla_colour TEXT_COLOUR = col_GREEN; |
---|
| 90 | static const gla_colour HERE_COLOUR = col_WHITE; |
---|
| 91 | static const gla_colour NAME_COLOUR = col_GREEN; |
---|
[dd6af8b] | 92 | static const gla_colour SEL_COLOUR = col_WHITE; |
---|
[33b2094] | 93 | |
---|
[0b0520c] | 94 | // Number of entries across and down the hit-test grid: |
---|
[39e460c9] | 95 | #define HITTEST_SIZE 20 |
---|
| 96 | |
---|
[395c3f8] | 97 | // How close the pointer needs to be to a station to be considered: |
---|
| 98 | #define MEASURE_THRESHOLD 7 |
---|
| 99 | |
---|
[dde4fe7] | 100 | // vector for lighting angle |
---|
| 101 | static const Vector3 light(.577, .577, .577); |
---|
| 102 | |
---|
[9071cf5] | 103 | BEGIN_EVENT_TABLE(GfxCore, GLACanvas) |
---|
[5809313] | 104 | EVT_PAINT(GfxCore::OnPaint) |
---|
| 105 | EVT_LEFT_DOWN(GfxCore::OnLButtonDown) |
---|
| 106 | EVT_LEFT_UP(GfxCore::OnLButtonUp) |
---|
| 107 | EVT_MIDDLE_DOWN(GfxCore::OnMButtonDown) |
---|
| 108 | EVT_MIDDLE_UP(GfxCore::OnMButtonUp) |
---|
| 109 | EVT_RIGHT_DOWN(GfxCore::OnRButtonDown) |
---|
| 110 | EVT_RIGHT_UP(GfxCore::OnRButtonUp) |
---|
[34d8d1a] | 111 | EVT_MOUSEWHEEL(GfxCore::OnMouseWheel) |
---|
[5809313] | 112 | EVT_MOTION(GfxCore::OnMouseMove) |
---|
[887c26e] | 113 | EVT_LEAVE_WINDOW(GfxCore::OnLeaveWindow) |
---|
[5809313] | 114 | EVT_SIZE(GfxCore::OnSize) |
---|
[a8e9fde] | 115 | EVT_IDLE(GfxCore::OnIdle) |
---|
[4b1fc48] | 116 | EVT_CHAR(GfxCore::OnKeyPress) |
---|
[5809313] | 117 | END_EVENT_TABLE() |
---|
| 118 | |
---|
[5876fcb] | 119 | GfxCore::GfxCore(MainFrm* parent, wxWindow* parent_win, GUIControl* control) : |
---|
[88707e0b] | 120 | GLACanvas(parent_win, 100), |
---|
| 121 | m_Scale(0.0), |
---|
| 122 | m_ScaleBarWidth(0), |
---|
| 123 | m_Control(control), |
---|
| 124 | m_LabelGrid(NULL), |
---|
| 125 | m_Parent(parent), |
---|
| 126 | m_DoneFirstShow(false), |
---|
| 127 | m_TiltAngle(0.0), |
---|
| 128 | m_PanAngle(0.0), |
---|
| 129 | m_Rotating(false), |
---|
| 130 | m_RotationStep(0.0), |
---|
| 131 | m_SwitchingTo(0), |
---|
| 132 | m_Crosses(false), |
---|
| 133 | m_Legs(true), |
---|
[8666fc7] | 134 | m_Splays(SPLAYS_SHOW_FADED), |
---|
[88707e0b] | 135 | m_Names(false), |
---|
| 136 | m_Scalebar(true), |
---|
[97ea48d] | 137 | m_ColourKey(true), |
---|
[88707e0b] | 138 | m_OverlappingNames(false), |
---|
| 139 | m_Compass(true), |
---|
| 140 | m_Clino(true), |
---|
| 141 | m_Tubes(false), |
---|
| 142 | m_ColourBy(COLOUR_BY_DEPTH), |
---|
| 143 | m_HaveData(false), |
---|
[22b0a8f] | 144 | m_HaveTerrain(true), |
---|
[88707e0b] | 145 | m_MouseOutsideCompass(false), |
---|
| 146 | m_MouseOutsideElev(false), |
---|
| 147 | m_Surface(false), |
---|
| 148 | m_Entrances(false), |
---|
| 149 | m_FixedPts(false), |
---|
| 150 | m_ExportedPts(false), |
---|
| 151 | m_Grid(false), |
---|
| 152 | m_BoundingBox(false), |
---|
[4938bcd] | 153 | m_Terrain(false), |
---|
[88707e0b] | 154 | m_Degrees(false), |
---|
| 155 | m_Metric(false), |
---|
[d171c0c] | 156 | m_Percent(false), |
---|
[7171240] | 157 | m_HitTestDebug(false), |
---|
[11169cb] | 158 | m_RenderStats(false), |
---|
[7171240] | 159 | m_PointGrid(NULL), |
---|
[88707e0b] | 160 | m_HitTestGridValid(false), |
---|
[381ae6e] | 161 | m_here(NULL), |
---|
| 162 | m_there(NULL), |
---|
[88707e0b] | 163 | presentation_mode(0), |
---|
| 164 | pres_reverse(false), |
---|
| 165 | pres_speed(0.0), |
---|
[75d4a2b] | 166 | movie(NULL), |
---|
[d96c95c] | 167 | current_cursor(GfxCore::CURSOR_DEFAULT), |
---|
[6388423] | 168 | sqrd_measure_threshold(sqrd(MEASURE_THRESHOLD)), |
---|
[9df33bc] | 169 | dem(NULL), |
---|
[11169cb] | 170 | last_time(0), |
---|
[6388423] | 171 | n_tris(0) |
---|
[5809313] | 172 | { |
---|
[da6c802] | 173 | AddQuad = &GfxCore::AddQuadrilateralDepth; |
---|
| 174 | AddPoly = &GfxCore::AddPolylineDepth; |
---|
[5627cbb] | 175 | wxConfigBase::Get()->Read(wxT("metric"), &m_Metric, true); |
---|
| 176 | wxConfigBase::Get()->Read(wxT("degrees"), &m_Degrees, true); |
---|
[82277dd] | 177 | wxConfigBase::Get()->Read(wxT("percent"), &m_Percent, false); |
---|
[5809313] | 178 | |
---|
[97ea48d] | 179 | for (int pen = 0; pen < NUM_COLOUR_BANDS + 1; ++pen) { |
---|
[4a1cede] | 180 | m_Pens[pen].SetColour(REDS[pen] / 255.0, |
---|
[0e69efe] | 181 | GREENS[pen] / 255.0, |
---|
| 182 | BLUES[pen] / 255.0); |
---|
| 183 | } |
---|
[5455bb2] | 184 | |
---|
| 185 | timer.Start(); |
---|
[5809313] | 186 | } |
---|
| 187 | |
---|
| 188 | GfxCore::~GfxCore() |
---|
| 189 | { |
---|
| 190 | TryToFreeArrays(); |
---|
[156dc16] | 191 | |
---|
[39e460c9] | 192 | delete[] m_PointGrid; |
---|
[5809313] | 193 | } |
---|
| 194 | |
---|
| 195 | void GfxCore::TryToFreeArrays() |
---|
| 196 | { |
---|
| 197 | // Free up any memory allocated for arrays. |
---|
[81f1266] | 198 | delete[] m_LabelGrid; |
---|
| 199 | m_LabelGrid = NULL; |
---|
[5809313] | 200 | } |
---|
| 201 | |
---|
| 202 | // |
---|
| 203 | // Initialisation methods |
---|
| 204 | // |
---|
| 205 | |
---|
[0c6bf5e8] | 206 | void GfxCore::Initialise(bool same_file) |
---|
[5809313] | 207 | { |
---|
| 208 | // Initialise the view from the parent holding the survey data. |
---|
| 209 | |
---|
| 210 | TryToFreeArrays(); |
---|
| 211 | |
---|
[33b2094] | 212 | m_DoneFirstShow = false; |
---|
| 213 | |
---|
[dfe4454c] | 214 | m_HitTestGridValid = false; |
---|
[381ae6e] | 215 | m_here = NULL; |
---|
| 216 | m_there = NULL; |
---|
[dfe4454c] | 217 | |
---|
[d35144d] | 218 | m_MouseOutsideCompass = m_MouseOutsideElev = false; |
---|
| 219 | |
---|
[0c6bf5e8] | 220 | if (!same_file) { |
---|
| 221 | // Apply default parameters unless reloading the same file. |
---|
| 222 | DefaultParameters(); |
---|
| 223 | |
---|
| 224 | // Set the initial scale. |
---|
| 225 | SetScale(1.0); |
---|
| 226 | } |
---|
[9eb58d0] | 227 | |
---|
| 228 | m_HaveData = true; |
---|
[936a197] | 229 | |
---|
[92cf7a8] | 230 | // Clear any cached OpenGL lists which depend on the data. |
---|
| 231 | InvalidateList(LIST_SCALE_BAR); |
---|
| 232 | InvalidateList(LIST_DEPTH_KEY); |
---|
| 233 | InvalidateList(LIST_DATE_KEY); |
---|
| 234 | InvalidateList(LIST_ERROR_KEY); |
---|
[cc9e2c65] | 235 | InvalidateList(LIST_GRADIENT_KEY); |
---|
[af50685] | 236 | InvalidateList(LIST_LENGTH_KEY); |
---|
[92cf7a8] | 237 | InvalidateList(LIST_UNDERGROUND_LEGS); |
---|
| 238 | InvalidateList(LIST_TUBES); |
---|
| 239 | InvalidateList(LIST_SURFACE_LEGS); |
---|
| 240 | InvalidateList(LIST_BLOBS); |
---|
| 241 | InvalidateList(LIST_CROSSES); |
---|
| 242 | InvalidateList(LIST_GRID); |
---|
| 243 | InvalidateList(LIST_SHADOW); |
---|
[22b0a8f] | 244 | InvalidateList(LIST_TERRAIN); |
---|
[92cf7a8] | 245 | |
---|
[936a197] | 246 | ForceRefresh(); |
---|
[9eb58d0] | 247 | } |
---|
| 248 | |
---|
| 249 | void GfxCore::FirstShow() |
---|
| 250 | { |
---|
| 251 | GLACanvas::FirstShow(); |
---|
| 252 | |
---|
[8bd480e] | 253 | const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR); |
---|
[86cdcf2] | 254 | list<LabelInfo*>::iterator pos = m_Parent->GetLabelsNC(); |
---|
| 255 | while (pos != m_Parent->GetLabelsNCEnd()) { |
---|
| 256 | LabelInfo* label = *pos++; |
---|
| 257 | // Calculate and set the label width for use when plotting |
---|
| 258 | // none-overlapping labels. |
---|
| 259 | int ext_x; |
---|
| 260 | GLACanvas::GetTextExtent(label->GetText(), &ext_x, NULL); |
---|
[5a24583] | 261 | label->set_width(unsigned(ext_x) / quantise + 1); |
---|
[86cdcf2] | 262 | } |
---|
| 263 | |
---|
[c5fc8eb] | 264 | // Set diameter of the viewing volume. |
---|
[29f2e7d] | 265 | double diameter = sqrt(sqrd(m_Parent->GetXExtent()) + |
---|
[c5fc8eb] | 266 | sqrd(m_Parent->GetYExtent()) + |
---|
[29f2e7d] | 267 | sqrd(m_Parent->GetZExtent())); |
---|
| 268 | // Allow for terrain. |
---|
| 269 | SetVolumeDiameter(max(1000.0 * 2, diameter * 2)); |
---|
[9eb58d0] | 270 | |
---|
[5809313] | 271 | m_DoneFirstShow = true; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | // |
---|
| 275 | // Recalculating methods |
---|
| 276 | // |
---|
| 277 | |
---|
[cd6ea75] | 278 | void GfxCore::SetScale(Double scale) |
---|
[5047c53] | 279 | { |
---|
[8b0d57f] | 280 | if (scale < 0.05) { |
---|
| 281 | scale = 0.05; |
---|
[70acad9] | 282 | } else if (scale > GetVolumeDiameter()) { |
---|
| 283 | scale = GetVolumeDiameter(); |
---|
[5047c53] | 284 | } |
---|
| 285 | |
---|
[5b7164d] | 286 | m_Scale = scale; |
---|
[00a68e0] | 287 | m_HitTestGridValid = false; |
---|
[381ae6e] | 288 | if (m_here && m_here == &temp_here) SetHere(); |
---|
[33b2094] | 289 | |
---|
| 290 | GLACanvas::SetScale(scale); |
---|
[d9b3270] | 291 | } |
---|
| 292 | |
---|
[f433fda] | 293 | bool GfxCore::HasUndergroundLegs() const |
---|
| 294 | { |
---|
| 295 | return m_Parent->HasUndergroundLegs(); |
---|
| 296 | } |
---|
| 297 | |
---|
[5fe7292] | 298 | bool GfxCore::HasSplays() const |
---|
| 299 | { |
---|
| 300 | return m_Parent->HasSplays(); |
---|
| 301 | } |
---|
| 302 | |
---|
[f433fda] | 303 | bool GfxCore::HasSurfaceLegs() const |
---|
| 304 | { |
---|
| 305 | return m_Parent->HasSurfaceLegs(); |
---|
| 306 | } |
---|
| 307 | |
---|
[50e8979] | 308 | bool GfxCore::HasTubes() const |
---|
| 309 | { |
---|
| 310 | return m_Parent->HasTubes(); |
---|
| 311 | } |
---|
| 312 | |
---|
[d9b3270] | 313 | void GfxCore::UpdateBlobs() |
---|
| 314 | { |
---|
[d2fcc9b] | 315 | InvalidateList(LIST_BLOBS); |
---|
[33b2094] | 316 | } |
---|
| 317 | |
---|
[cd6ea75] | 318 | // |
---|
[5876fcb] | 319 | // Event handlers |
---|
[cd6ea75] | 320 | // |
---|
[5047c53] | 321 | |
---|
[41f7a27] | 322 | void GfxCore::OnLeaveWindow(wxMouseEvent&) { |
---|
[887c26e] | 323 | SetHere(); |
---|
| 324 | ClearCoords(); |
---|
| 325 | } |
---|
| 326 | |
---|
[5876fcb] | 327 | void GfxCore::OnIdle(wxIdleEvent& event) |
---|
| 328 | { |
---|
| 329 | // Handle an idle event. |
---|
[5455bb2] | 330 | if (Animating()) { |
---|
| 331 | Animate(); |
---|
| 332 | // If still animating, we want more idle events. |
---|
| 333 | if (Animating()) |
---|
| 334 | event.RequestMore(); |
---|
[11169cb] | 335 | } else { |
---|
| 336 | // If we're idle, don't show a bogus FPS next time we render. |
---|
| 337 | last_time = 0; |
---|
[b72f4b5] | 338 | } |
---|
[5809313] | 339 | } |
---|
| 340 | |
---|
[b4fe9fb] | 341 | void GfxCore::OnPaint(wxPaintEvent&) |
---|
[5809313] | 342 | { |
---|
| 343 | // Redraw the window. |
---|
[b462168] | 344 | |
---|
| 345 | // Get a graphics context. |
---|
[1b12b82] | 346 | wxPaintDC dc(this); |
---|
[5809313] | 347 | |
---|
[815eab2] | 348 | if (m_HaveData) { |
---|
[01d91fd] | 349 | // Make sure we're initialised. |
---|
| 350 | bool first_time = !m_DoneFirstShow; |
---|
| 351 | if (first_time) { |
---|
| 352 | FirstShow(); |
---|
| 353 | } |
---|
| 354 | |
---|
[58dfdd21] | 355 | StartDrawing(); |
---|
| 356 | |
---|
| 357 | // Clear the background. |
---|
| 358 | Clear(); |
---|
| 359 | |
---|
[429465a] | 360 | // Set up model transformation matrix. |
---|
| 361 | SetDataTransform(); |
---|
| 362 | |
---|
| 363 | if (m_Legs || m_Tubes) { |
---|
| 364 | if (m_Tubes) { |
---|
[d67450e] | 365 | EnableSmoothPolygons(true); // FIXME: allow false for wireframe view |
---|
[d2fcc9b] | 366 | DrawList(LIST_TUBES); |
---|
[429465a] | 367 | DisableSmoothPolygons(); |
---|
| 368 | } |
---|
[e4d40792] | 369 | |
---|
[50e8979] | 370 | // Draw the underground legs. Do this last so that anti-aliasing |
---|
[e4d40792] | 371 | // works over polygons. |
---|
| 372 | SetColour(col_GREEN); |
---|
[d2fcc9b] | 373 | DrawList(LIST_UNDERGROUND_LEGS); |
---|
[429465a] | 374 | } |
---|
[33b2094] | 375 | |
---|
[429465a] | 376 | if (m_Surface) { |
---|
| 377 | // Draw the surface legs. |
---|
[d2fcc9b] | 378 | DrawList(LIST_SURFACE_LEGS); |
---|
[429465a] | 379 | } |
---|
[bbc22ca] | 380 | |
---|
[f4c5932] | 381 | if (m_BoundingBox) { |
---|
| 382 | DrawShadowedBoundingBox(); |
---|
| 383 | } |
---|
[429465a] | 384 | if (m_Grid) { |
---|
| 385 | // Draw the grid. |
---|
[37d7084] | 386 | DrawList(LIST_GRID); |
---|
[429465a] | 387 | } |
---|
[b13aee4] | 388 | |
---|
[d347a2c] | 389 | if (m_Terrain) { |
---|
[11fe902] | 390 | // We don't want to be able to see the terrain through itself, so |
---|
| 391 | // do a "Z-prepass" - plot the terrain once only updating the |
---|
| 392 | // Z-buffer, then again with Z-clipping only plotting where the |
---|
| 393 | // depth matches the value in the Z-buffer. |
---|
| 394 | DrawListZPrepass(LIST_TERRAIN); |
---|
[d347a2c] | 395 | } |
---|
| 396 | |
---|
[d2cc100] | 397 | DrawList(LIST_BLOBS); |
---|
| 398 | |
---|
[86fe6e4] | 399 | if (m_Crosses) { |
---|
| 400 | DrawList(LIST_CROSSES); |
---|
| 401 | } |
---|
| 402 | |
---|
[429465a] | 403 | SetIndicatorTransform(); |
---|
| 404 | |
---|
[6adffadf] | 405 | // Draw station names. |
---|
| 406 | if (m_Names /*&& !m_Control->MouseDown() && !Animating()*/) { |
---|
| 407 | SetColour(NAME_COLOUR); |
---|
| 408 | |
---|
| 409 | if (m_OverlappingNames) { |
---|
| 410 | SimpleDrawNames(); |
---|
| 411 | } else { |
---|
| 412 | NattyDrawNames(); |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | |
---|
[5e0b3a13] | 416 | if (m_HitTestDebug) { |
---|
| 417 | // Show the hit test grid bucket sizes... |
---|
| 418 | SetColour(m_HitTestGridValid ? col_LIGHT_GREY : col_DARK_GREY); |
---|
[7171240] | 419 | if (m_PointGrid) { |
---|
| 420 | for (int i = 0; i != HITTEST_SIZE; ++i) { |
---|
| 421 | int x = (GetXSize() + 1) * i / HITTEST_SIZE + 2; |
---|
| 422 | for (int j = 0; j != HITTEST_SIZE; ++j) { |
---|
| 423 | int square = i + j * HITTEST_SIZE; |
---|
[a49a023] | 424 | unsigned long bucket_size = m_PointGrid[square].size(); |
---|
[7171240] | 425 | if (bucket_size) { |
---|
| 426 | int y = (GetYSize() + 1) * (HITTEST_SIZE - 1 - j) / HITTEST_SIZE; |
---|
[7b9b700] | 427 | DrawIndicatorText(x, y, wxString::Format(wxT("%lu"), bucket_size)); |
---|
[7171240] | 428 | } |
---|
[5e0b3a13] | 429 | } |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | EnableDashedLines(); |
---|
| 434 | BeginLines(); |
---|
| 435 | for (int i = 0; i != HITTEST_SIZE; ++i) { |
---|
| 436 | int x = (GetXSize() + 1) * i / HITTEST_SIZE; |
---|
| 437 | PlaceIndicatorVertex(x, 0); |
---|
| 438 | PlaceIndicatorVertex(x, GetYSize()); |
---|
| 439 | } |
---|
| 440 | for (int j = 0; j != HITTEST_SIZE; ++j) { |
---|
| 441 | int y = (GetYSize() + 1) * (HITTEST_SIZE - 1 - j) / HITTEST_SIZE; |
---|
| 442 | PlaceIndicatorVertex(0, y); |
---|
| 443 | PlaceIndicatorVertex(GetXSize(), y); |
---|
| 444 | } |
---|
| 445 | EndLines(); |
---|
| 446 | DisableDashedLines(); |
---|
| 447 | } |
---|
| 448 | |
---|
[11169cb] | 449 | long now = timer.Time(); |
---|
| 450 | if (m_RenderStats) { |
---|
| 451 | // Show stats about rendering. |
---|
| 452 | SetColour(col_TURQUOISE); |
---|
| 453 | int y = GetYSize() - GetFontSize(); |
---|
| 454 | if (last_time != 0.0) { |
---|
| 455 | // timer.Time() measure in milliseconds. |
---|
| 456 | double fps = 1000.0 / (now - last_time); |
---|
| 457 | DrawIndicatorText(1, y, wxString::Format(wxT("FPS:% 5.1f"), fps)); |
---|
| 458 | } |
---|
| 459 | y -= GetFontSize(); |
---|
| 460 | DrawIndicatorText(1, y, wxString::Format(wxT("▲:%lu"), (unsigned long)n_tris)); |
---|
| 461 | } |
---|
| 462 | last_time = now; |
---|
| 463 | |
---|
[c091027] | 464 | // Draw indicators. |
---|
| 465 | // |
---|
| 466 | // There's no advantage in generating an OpenGL list for the |
---|
| 467 | // indicators since they change with almost every redraw (and |
---|
| 468 | // sometimes several times between redraws). This way we avoid |
---|
| 469 | // the need to track when to update the indicator OpenGL list, |
---|
| 470 | // and also avoid indicator update bugs when we don't quite get this |
---|
| 471 | // right... |
---|
| 472 | DrawIndicators(); |
---|
| 473 | |
---|
[dd6af8b] | 474 | if (zoombox.active()) { |
---|
| 475 | SetColour(SEL_COLOUR); |
---|
| 476 | EnableDashedLines(); |
---|
| 477 | BeginPolyline(); |
---|
| 478 | glaCoord Y = GetYSize(); |
---|
| 479 | PlaceIndicatorVertex(zoombox.x1, Y - zoombox.y1); |
---|
| 480 | PlaceIndicatorVertex(zoombox.x1, Y - zoombox.y2); |
---|
| 481 | PlaceIndicatorVertex(zoombox.x2, Y - zoombox.y2); |
---|
| 482 | PlaceIndicatorVertex(zoombox.x2, Y - zoombox.y1); |
---|
| 483 | PlaceIndicatorVertex(zoombox.x1, Y - zoombox.y1); |
---|
| 484 | EndPolyline(); |
---|
| 485 | DisableDashedLines(); |
---|
| 486 | } else if (MeasuringLineActive()) { |
---|
[429465a] | 487 | // Draw "here" and "there". |
---|
[f6d8375] | 488 | double hx, hy; |
---|
[aa048c3] | 489 | SetColour(HERE_COLOUR); |
---|
[381ae6e] | 490 | if (m_here) { |
---|
[f6d8375] | 491 | double dummy; |
---|
[381ae6e] | 492 | Transform(*m_here, &hx, &hy, &dummy); |
---|
| 493 | if (m_here != &temp_here) DrawRing(hx, hy); |
---|
[429465a] | 494 | } |
---|
[381ae6e] | 495 | if (m_there) { |
---|
[f6d8375] | 496 | double tx, ty; |
---|
| 497 | double dummy; |
---|
[381ae6e] | 498 | Transform(*m_there, &tx, &ty, &dummy); |
---|
| 499 | if (m_here) { |
---|
[429465a] | 500 | BeginLines(); |
---|
| 501 | PlaceIndicatorVertex(hx, hy); |
---|
| 502 | PlaceIndicatorVertex(tx, ty); |
---|
[42d23c5] | 503 | EndLines(); |
---|
[429465a] | 504 | } |
---|
[e633bb1] | 505 | BeginBlobs(); |
---|
[81aea4e] | 506 | DrawBlob(tx, ty); |
---|
[e633bb1] | 507 | EndBlobs(); |
---|
[429465a] | 508 | } |
---|
| 509 | } |
---|
[f433fda] | 510 | |
---|
[58dfdd21] | 511 | FinishDrawing(); |
---|
[5997ffd] | 512 | } else { |
---|
| 513 | dc.SetBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWFRAME)); |
---|
| 514 | dc.Clear(); |
---|
[58dfdd21] | 515 | } |
---|
[5809313] | 516 | } |
---|
| 517 | |
---|
[f4c5932] | 518 | void GfxCore::DrawBoundingBox() |
---|
| 519 | { |
---|
[d67450e] | 520 | const Vector3 v = 0.5 * m_Parent->GetExtent(); |
---|
[f4c5932] | 521 | |
---|
| 522 | SetColour(col_BLUE); |
---|
| 523 | EnableDashedLines(); |
---|
| 524 | BeginPolyline(); |
---|
[d67450e] | 525 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 526 | PlaceVertex(-v.GetX(), v.GetY(), v.GetZ()); |
---|
| 527 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 528 | PlaceVertex(v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 529 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
[f4c5932] | 530 | EndPolyline(); |
---|
| 531 | BeginPolyline(); |
---|
[d67450e] | 532 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 533 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 534 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 535 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 536 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 537 | EndPolyline(); |
---|
| 538 | BeginLines(); |
---|
[d67450e] | 539 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 540 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 541 | PlaceVertex(-v.GetX(), v.GetY(), v.GetZ()); |
---|
| 542 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 543 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 544 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 545 | PlaceVertex(v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 546 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 547 | EndLines(); |
---|
| 548 | DisableDashedLines(); |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | void GfxCore::DrawShadowedBoundingBox() |
---|
| 552 | { |
---|
[d67450e] | 553 | const Vector3 v = 0.5 * m_Parent->GetExtent(); |
---|
[f4c5932] | 554 | |
---|
[f7dae86] | 555 | DrawBoundingBox(); |
---|
| 556 | |
---|
[f9ca87c] | 557 | PolygonOffset(true); |
---|
[f4c5932] | 558 | SetColour(col_DARK_GREY); |
---|
| 559 | BeginQuadrilaterals(); |
---|
[d67450e] | 560 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 561 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 562 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 563 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 564 | EndQuadrilaterals(); |
---|
[f9ca87c] | 565 | PolygonOffset(false); |
---|
[f4c5932] | 566 | |
---|
[d2fcc9b] | 567 | DrawList(LIST_SHADOW); |
---|
[f4c5932] | 568 | } |
---|
| 569 | |
---|
[c1cf79d] | 570 | void GfxCore::DrawGrid() |
---|
| 571 | { |
---|
| 572 | // Draw the grid. |
---|
[156dc16] | 573 | SetColour(col_RED); |
---|
[c1cf79d] | 574 | |
---|
| 575 | // Calculate the extent of the survey, in metres across the screen plane. |
---|
[b81eee2] | 576 | Double m_across_screen = SurveyUnitsAcrossViewport(); |
---|
[c1cf79d] | 577 | // Calculate the length of the scale bar in metres. |
---|
| 578 | //--move this elsewhere |
---|
[c6d95d8] | 579 | Double size_snap = pow(10.0, floor(log10(0.75 * m_across_screen))); |
---|
| 580 | Double t = m_across_screen * 0.75 / size_snap; |
---|
[c1cf79d] | 581 | if (t >= 5.0) { |
---|
[429465a] | 582 | size_snap *= 5.0; |
---|
[c1cf79d] | 583 | } |
---|
| 584 | else if (t >= 2.0) { |
---|
[429465a] | 585 | size_snap *= 2.0; |
---|
[c1cf79d] | 586 | } |
---|
| 587 | |
---|
[d67450e] | 588 | Double grid_size = size_snap * 0.1; |
---|
[c6d95d8] | 589 | Double edge = grid_size * 2.0; |
---|
[d67450e] | 590 | Double grid_z = -m_Parent->GetZExtent() * 0.5 - grid_size; |
---|
| 591 | Double left = -m_Parent->GetXExtent() * 0.5 - edge; |
---|
| 592 | Double right = m_Parent->GetXExtent() * 0.5 + edge; |
---|
| 593 | Double bottom = -m_Parent->GetYExtent() * 0.5 - edge; |
---|
| 594 | Double top = m_Parent->GetYExtent() * 0.5 + edge; |
---|
[c1cf79d] | 595 | int count_x = (int) ceil((right - left) / grid_size); |
---|
| 596 | int count_y = (int) ceil((top - bottom) / grid_size); |
---|
[c6d95d8] | 597 | Double actual_right = left + count_x*grid_size; |
---|
| 598 | Double actual_top = bottom + count_y*grid_size; |
---|
[c1cf79d] | 599 | |
---|
[b81eee2] | 600 | BeginLines(); |
---|
| 601 | |
---|
[c1cf79d] | 602 | for (int xc = 0; xc <= count_x; xc++) { |
---|
[429465a] | 603 | Double x = left + xc*grid_size; |
---|
[f433fda] | 604 | |
---|
[b81eee2] | 605 | PlaceVertex(x, bottom, grid_z); |
---|
| 606 | PlaceVertex(x, actual_top, grid_z); |
---|
[c1cf79d] | 607 | } |
---|
| 608 | |
---|
| 609 | for (int yc = 0; yc <= count_y; yc++) { |
---|
[429465a] | 610 | Double y = bottom + yc*grid_size; |
---|
[b81eee2] | 611 | PlaceVertex(left, y, grid_z); |
---|
| 612 | PlaceVertex(actual_right, y, grid_z); |
---|
[c1cf79d] | 613 | } |
---|
[b81eee2] | 614 | |
---|
| 615 | EndLines(); |
---|
[c1cf79d] | 616 | } |
---|
| 617 | |
---|
[1eeb55a] | 618 | int GfxCore::GetClinoOffset() const |
---|
[c300a04] | 619 | { |
---|
[2a26b45] | 620 | int result = INDICATOR_OFFSET_X; |
---|
| 621 | if (m_Compass) { |
---|
| 622 | result += 6 + GetCompassWidth() + INDICATOR_GAP; |
---|
| 623 | } |
---|
| 624 | return result; |
---|
[c300a04] | 625 | } |
---|
| 626 | |
---|
[fe665c4] | 627 | void GfxCore::DrawTick(int angle_cw) |
---|
[6606406] | 628 | { |
---|
[fe665c4] | 629 | const Double theta = rad(angle_cw); |
---|
| 630 | const wxCoord length1 = INDICATOR_RADIUS; |
---|
| 631 | const wxCoord length0 = length1 + TICK_LENGTH; |
---|
| 632 | wxCoord x0 = wxCoord(length0 * sin(theta)); |
---|
| 633 | wxCoord y0 = wxCoord(length0 * cos(theta)); |
---|
| 634 | wxCoord x1 = wxCoord(length1 * sin(theta)); |
---|
| 635 | wxCoord y1 = wxCoord(length1 * cos(theta)); |
---|
[6606406] | 636 | |
---|
[fe665c4] | 637 | PlaceIndicatorVertex(x0, y0); |
---|
| 638 | PlaceIndicatorVertex(x1, y1); |
---|
[6606406] | 639 | } |
---|
| 640 | |
---|
[d67450e] | 641 | void GfxCore::DrawArrow(gla_colour col1, gla_colour col2) { |
---|
| 642 | Vector3 p1(0, INDICATOR_RADIUS, 0); |
---|
| 643 | Vector3 p2(INDICATOR_RADIUS/2, INDICATOR_RADIUS*-.866025404, 0); // 150deg |
---|
| 644 | Vector3 p3(-INDICATOR_RADIUS/2, INDICATOR_RADIUS*-.866025404, 0); // 210deg |
---|
| 645 | Vector3 pc(0, 0, 0); |
---|
| 646 | |
---|
| 647 | DrawTriangle(col_LIGHT_GREY, col1, p2, p1, pc); |
---|
| 648 | DrawTriangle(col_LIGHT_GREY, col2, p3, p1, pc); |
---|
| 649 | } |
---|
| 650 | |
---|
[fe665c4] | 651 | void GfxCore::DrawCompass() { |
---|
| 652 | // Ticks. |
---|
| 653 | BeginLines(); |
---|
| 654 | for (int angle = 315; angle > 0; angle -= 45) { |
---|
| 655 | DrawTick(angle); |
---|
| 656 | } |
---|
| 657 | SetColour(col_GREEN); |
---|
| 658 | DrawTick(0); |
---|
| 659 | EndLines(); |
---|
| 660 | |
---|
| 661 | // Compass background. |
---|
| 662 | DrawCircle(col_LIGHT_GREY_2, col_GREY, 0, 0, INDICATOR_RADIUS); |
---|
[6606406] | 663 | |
---|
[fe665c4] | 664 | // Compass arrow. |
---|
[d67450e] | 665 | DrawArrow(col_INDICATOR_1, col_INDICATOR_2); |
---|
[6606406] | 666 | } |
---|
| 667 | |
---|
[fe665c4] | 668 | // Draw the non-rotating background to the clino. |
---|
| 669 | void GfxCore::DrawClinoBack() { |
---|
| 670 | BeginLines(); |
---|
| 671 | for (int angle = 0; angle <= 180; angle += 90) { |
---|
| 672 | DrawTick(angle); |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | SetColour(col_GREY); |
---|
| 676 | PlaceIndicatorVertex(0, INDICATOR_RADIUS); |
---|
| 677 | PlaceIndicatorVertex(0, -INDICATOR_RADIUS); |
---|
| 678 | PlaceIndicatorVertex(0, 0); |
---|
| 679 | PlaceIndicatorVertex(INDICATOR_RADIUS, 0); |
---|
[b56df45] | 680 | |
---|
[fe665c4] | 681 | EndLines(); |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | void GfxCore::DrawClino() { |
---|
| 685 | // Ticks. |
---|
| 686 | SetColour(col_GREEN); |
---|
[33b2094] | 687 | BeginLines(); |
---|
[fe665c4] | 688 | DrawTick(0); |
---|
[33b2094] | 689 | EndLines(); |
---|
[fe665c4] | 690 | |
---|
| 691 | // Clino background. |
---|
| 692 | DrawSemicircle(col_LIGHT_GREY_2, col_GREY, 0, 0, INDICATOR_RADIUS, 0); |
---|
| 693 | |
---|
| 694 | // Elevation arrow. |
---|
[d67450e] | 695 | DrawArrow(col_INDICATOR_2, col_INDICATOR_1); |
---|
[b56df45] | 696 | } |
---|
| 697 | |
---|
[6606406] | 698 | void GfxCore::Draw2dIndicators() |
---|
| 699 | { |
---|
[76dd228] | 700 | // Draw the compass and elevation indicators. |
---|
| 701 | |
---|
| 702 | const int centre_y = INDICATOR_BOX_SIZE / 2 + INDICATOR_OFFSET_Y; |
---|
| 703 | |
---|
[fe665c4] | 704 | const int comp_centre_x = GetCompassXPosition(); |
---|
[6606406] | 705 | |
---|
[eef68f9] | 706 | if (m_Compass && !m_Parent->IsExtendedElevation()) { |
---|
[fe665c4] | 707 | // If the user is dragging the compass with the pointer outside the |
---|
| 708 | // compass, we snap to 45 degree multiples, and the ticks go white. |
---|
[76dd228] | 709 | SetColour(m_MouseOutsideCompass ? col_WHITE : col_LIGHT_GREY_2); |
---|
[fe665c4] | 710 | DrawList2D(LIST_COMPASS, comp_centre_x, centre_y, -m_PanAngle); |
---|
[c300a04] | 711 | } |
---|
[76dd228] | 712 | |
---|
[fe665c4] | 713 | const int elev_centre_x = GetClinoXPosition(); |
---|
[76dd228] | 714 | |
---|
[eef68f9] | 715 | if (m_Clino) { |
---|
[fe665c4] | 716 | // If the user is dragging the clino with the pointer outside the |
---|
| 717 | // clino, we snap to 90 degree multiples, and the ticks go white. |
---|
| 718 | SetColour(m_MouseOutsideElev ? col_WHITE : col_LIGHT_GREY_2); |
---|
| 719 | DrawList2D(LIST_CLINO_BACK, elev_centre_x, centre_y, 0); |
---|
[7a57dc7] | 720 | DrawList2D(LIST_CLINO, elev_centre_x, centre_y, 90 - m_TiltAngle); |
---|
[c300a04] | 721 | } |
---|
[6606406] | 722 | |
---|
[aa048c3] | 723 | SetColour(TEXT_COLOUR); |
---|
[6606406] | 724 | |
---|
[21958ec] | 725 | static int triple_zero_width = 0; |
---|
| 726 | static int height = 0; |
---|
| 727 | if (!triple_zero_width) { |
---|
[5627cbb] | 728 | GetTextExtent(wxT("000"), &triple_zero_width, &height); |
---|
[21958ec] | 729 | } |
---|
| 730 | const int y_off = INDICATOR_OFFSET_Y + INDICATOR_BOX_SIZE + height / 2; |
---|
[421b7d2] | 731 | |
---|
[eef68f9] | 732 | if (m_Compass && !m_Parent->IsExtendedElevation()) { |
---|
[21958ec] | 733 | wxString str; |
---|
| 734 | int value; |
---|
[d171c0c] | 735 | int brg_unit; |
---|
[429465a] | 736 | if (m_Degrees) { |
---|
[21958ec] | 737 | value = int(m_PanAngle); |
---|
[736f7df] | 738 | /* TRANSLATORS: degree symbol - probably should be translated to |
---|
| 739 | * itself. */ |
---|
[d171c0c] | 740 | brg_unit = /*°*/344; |
---|
[429465a] | 741 | } else { |
---|
[21958ec] | 742 | value = int(m_PanAngle * 200.0 / 180.0); |
---|
[736f7df] | 743 | /* TRANSLATORS: symbol for grad (400 grad = 360 degrees = full |
---|
| 744 | * circle). */ |
---|
[d171c0c] | 745 | brg_unit = /*ᵍ*/76; |
---|
[f433fda] | 746 | } |
---|
[5627cbb] | 747 | str.Printf(wxT("%03d"), value); |
---|
[d171c0c] | 748 | str += wmsg(brg_unit); |
---|
[21958ec] | 749 | DrawIndicatorText(comp_centre_x - triple_zero_width / 2, y_off, str); |
---|
| 750 | |
---|
[1c507cf] | 751 | // TRANSLATORS: Used in aven above the compass indicator at the lower |
---|
| 752 | // right of the display, with a bearing below "Facing". This indicates the |
---|
| 753 | // direction the viewer is "facing" in. |
---|
| 754 | // |
---|
| 755 | // Try to keep this translation short - ideally at most 10 characters - |
---|
| 756 | // as otherwise the compass and clino will be moved further apart to |
---|
| 757 | // make room. */ |
---|
[5627cbb] | 758 | str = wmsg(/*Facing*/203); |
---|
[21958ec] | 759 | int w; |
---|
[d92d282] | 760 | GetTextExtent(str, &w, NULL); |
---|
[21958ec] | 761 | DrawIndicatorText(comp_centre_x - w / 2, y_off + height, str); |
---|
[c300a04] | 762 | } |
---|
| 763 | |
---|
[eef68f9] | 764 | if (m_Clino) { |
---|
[c13d121f] | 765 | if (m_TiltAngle == -90.0) { |
---|
| 766 | // TRANSLATORS: Label used for "clino" in Aven when the view is |
---|
| 767 | // from directly above. |
---|
[1c507cf] | 768 | // |
---|
| 769 | // Try to keep this translation short - ideally at most 10 |
---|
| 770 | // characters - as otherwise the compass and clino will be moved |
---|
| 771 | // further apart to make room. */ |
---|
[c13d121f] | 772 | wxString str = wmsg(/*Plan*/432); |
---|
| 773 | static int width = 0; |
---|
| 774 | if (!width) { |
---|
| 775 | GetTextExtent(str, &width, NULL); |
---|
[d171c0c] | 776 | } |
---|
[c13d121f] | 777 | int x = elev_centre_x - width / 2; |
---|
| 778 | DrawIndicatorText(x, y_off + height / 2, str); |
---|
| 779 | } else if (m_TiltAngle == 90.0) { |
---|
| 780 | // TRANSLATORS: Label used for "clino" in Aven when the view is |
---|
| 781 | // from directly below. |
---|
[1c507cf] | 782 | // |
---|
| 783 | // Try to keep this translation short - ideally at most 10 |
---|
| 784 | // characters - as otherwise the compass and clino will be moved |
---|
| 785 | // further apart to make room. */ |
---|
[c13d121f] | 786 | wxString str = wmsg(/*Kiwi Plan*/433); |
---|
| 787 | static int width = 0; |
---|
| 788 | if (!width) { |
---|
| 789 | GetTextExtent(str, &width, NULL); |
---|
[d171c0c] | 790 | } |
---|
[c13d121f] | 791 | int x = elev_centre_x - width / 2; |
---|
| 792 | DrawIndicatorText(x, y_off + height / 2, str); |
---|
| 793 | } else { |
---|
| 794 | int angle; |
---|
| 795 | wxString str; |
---|
| 796 | int width; |
---|
| 797 | int unit; |
---|
| 798 | if (m_Percent) { |
---|
| 799 | static int zero_width = 0; |
---|
| 800 | if (!zero_width) { |
---|
| 801 | GetTextExtent(wxT("0"), &zero_width, NULL); |
---|
| 802 | } |
---|
| 803 | width = zero_width; |
---|
| 804 | if (m_TiltAngle > 89.99) { |
---|
| 805 | angle = 1000000; |
---|
| 806 | } else if (m_TiltAngle < -89.99) { |
---|
| 807 | angle = -1000000; |
---|
| 808 | } else { |
---|
| 809 | angle = int(100 * tan(rad(m_TiltAngle))); |
---|
| 810 | } |
---|
| 811 | if (angle > 99999 || angle < -99999) { |
---|
| 812 | str = angle > 0 ? wxT("+") : wxT("-"); |
---|
[0b8c321] | 813 | /* TRANSLATORS: infinity symbol - used for the percentage gradient on |
---|
[feefc6a] | 814 | * vertical angles. */ |
---|
[c13d121f] | 815 | str += wmsg(/*∞*/431); |
---|
| 816 | } else { |
---|
| 817 | str = angle ? wxString::Format(wxT("%+03d"), angle) : wxT("0"); |
---|
| 818 | } |
---|
[feefc6a] | 819 | /* TRANSLATORS: symbol for percentage gradient (100% = 45 |
---|
| 820 | * degrees = 50 grad). */ |
---|
[c13d121f] | 821 | unit = /*%*/96; |
---|
| 822 | } else if (m_Degrees) { |
---|
| 823 | static int zero_zero_width = 0; |
---|
| 824 | if (!zero_zero_width) { |
---|
| 825 | GetTextExtent(wxT("00"), &zero_zero_width, NULL); |
---|
| 826 | } |
---|
| 827 | width = zero_zero_width; |
---|
| 828 | angle = int(m_TiltAngle); |
---|
| 829 | str = angle ? wxString::Format(wxT("%+03d"), angle) : wxT("00"); |
---|
| 830 | unit = /*°*/344; |
---|
[d171c0c] | 831 | } else { |
---|
[c13d121f] | 832 | width = triple_zero_width; |
---|
| 833 | angle = int(m_TiltAngle * 200.0 / 180.0); |
---|
| 834 | str = angle ? wxString::Format(wxT("%+04d"), angle) : wxT("000"); |
---|
| 835 | unit = /*ᵍ*/76; |
---|
[21958ec] | 836 | } |
---|
| 837 | |
---|
[c13d121f] | 838 | int sign_offset = 0; |
---|
| 839 | if (unit == /*%*/96) { |
---|
| 840 | // Right align % since the width changes so much. |
---|
| 841 | GetTextExtent(str, &sign_offset, NULL); |
---|
| 842 | sign_offset -= width; |
---|
| 843 | } else if (angle < 0) { |
---|
| 844 | // Adjust horizontal position so the left of the first digit is |
---|
| 845 | // always in the same place. |
---|
| 846 | static int minus_width = 0; |
---|
| 847 | if (!minus_width) { |
---|
| 848 | GetTextExtent(wxT("-"), &minus_width, NULL); |
---|
| 849 | } |
---|
| 850 | sign_offset = minus_width; |
---|
| 851 | } else if (angle > 0) { |
---|
| 852 | // Adjust horizontal position so the left of the first digit is |
---|
| 853 | // always in the same place. |
---|
| 854 | static int plus_width = 0; |
---|
| 855 | if (!plus_width) { |
---|
| 856 | GetTextExtent(wxT("+"), &plus_width, NULL); |
---|
| 857 | } |
---|
| 858 | sign_offset = plus_width; |
---|
[21958ec] | 859 | } |
---|
[d171c0c] | 860 | |
---|
[c13d121f] | 861 | str += wmsg(unit); |
---|
| 862 | DrawIndicatorText(elev_centre_x - sign_offset - width / 2, y_off, str); |
---|
[21958ec] | 863 | |
---|
[1c507cf] | 864 | // TRANSLATORS: Label used for "clino" in Aven when the view is |
---|
| 865 | // neither from directly above nor from directly below. It is |
---|
| 866 | // also used in the dialog for editing a marked position in a |
---|
| 867 | // presentation. |
---|
| 868 | // |
---|
| 869 | // Try to keep this translation short - ideally at most 10 |
---|
| 870 | // characters - as otherwise the compass and clino will be moved |
---|
| 871 | // further apart to make room. */ |
---|
[c13d121f] | 872 | str = wmsg(/*Elevation*/118); |
---|
| 873 | static int elevation_width = 0; |
---|
| 874 | if (!elevation_width) { |
---|
| 875 | GetTextExtent(str, &elevation_width, NULL); |
---|
| 876 | } |
---|
| 877 | int x = elev_centre_x - elevation_width / 2; |
---|
| 878 | DrawIndicatorText(x, y_off + height, str); |
---|
[d171c0c] | 879 | } |
---|
[c300a04] | 880 | } |
---|
[5809313] | 881 | } |
---|
| 882 | |
---|
| 883 | void GfxCore::NattyDrawNames() |
---|
| 884 | { |
---|
[84cab34] | 885 | // Draw station names, without overlapping. |
---|
[f433fda] | 886 | |
---|
[d92d282] | 887 | const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR); |
---|
[90430f2] | 888 | const unsigned int quantised_x = GetXSize() / quantise; |
---|
| 889 | const unsigned int quantised_y = GetYSize() / quantise; |
---|
[84cab34] | 890 | const size_t buffer_size = quantised_x * quantised_y; |
---|
[f433fda] | 891 | |
---|
[69463a0] | 892 | if (!m_LabelGrid) m_LabelGrid = new char[buffer_size]; |
---|
[5809313] | 893 | |
---|
[33b2094] | 894 | memset((void*) m_LabelGrid, 0, buffer_size); |
---|
[156dc16] | 895 | |
---|
[33b2094] | 896 | list<LabelInfo*>::const_iterator label = m_Parent->GetLabels(); |
---|
[36c3285] | 897 | for ( ; label != m_Parent->GetLabelsEnd(); ++label) { |
---|
[ece003f] | 898 | if (!((m_Surface && (*label)->IsSurface()) || |
---|
| 899 | (m_Legs && (*label)->IsUnderground()) || |
---|
| 900 | (!(*label)->IsSurface() && !(*label)->IsUnderground()))) { |
---|
| 901 | // if this station isn't to be displayed, skip to the next |
---|
| 902 | // (last case is for stns with no legs attached) |
---|
| 903 | continue; |
---|
| 904 | } |
---|
| 905 | |
---|
[f6d8375] | 906 | double x, y, z; |
---|
[f433fda] | 907 | |
---|
[d67450e] | 908 | Transform(**label, &x, &y, &z); |
---|
[36c3285] | 909 | // Check if the label is behind us (in perspective view). |
---|
[d92d282] | 910 | if (z <= 0.0 || z >= 1.0) continue; |
---|
[421b7d2] | 911 | |
---|
[1eeb55a] | 912 | // Apply a small shift so that translating the view doesn't make which |
---|
| 913 | // labels are displayed change as the resulting twinkling effect is |
---|
| 914 | // distracting. |
---|
[f6d8375] | 915 | double tx, ty, tz; |
---|
[d67450e] | 916 | Transform(Vector3(), &tx, &ty, &tz); |
---|
[429465a] | 917 | tx -= floor(tx / quantise) * quantise; |
---|
| 918 | ty -= floor(ty / quantise) * quantise; |
---|
[5809313] | 919 | |
---|
[f12e8cc] | 920 | tx = x - tx; |
---|
| 921 | if (tx < 0) continue; |
---|
| 922 | |
---|
| 923 | ty = y - ty; |
---|
| 924 | if (ty < 0) continue; |
---|
[421b7d2] | 925 | |
---|
[f12e8cc] | 926 | unsigned int iy = unsigned(ty) / quantise; |
---|
[d92d282] | 927 | if (iy >= quantised_y) continue; |
---|
[5a24583] | 928 | unsigned int width = (*label)->get_width(); |
---|
[f12e8cc] | 929 | unsigned int ix = unsigned(tx) / quantise; |
---|
| 930 | if (ix + width >= quantised_x) continue; |
---|
[33b2094] | 931 | |
---|
[f12e8cc] | 932 | char * test = m_LabelGrid + ix + iy * quantised_x; |
---|
[d92d282] | 933 | if (memchr(test, 1, width)) continue; |
---|
[33b2094] | 934 | |
---|
[8bd480e] | 935 | x += 3; |
---|
| 936 | y -= GetFontSize() / 2; |
---|
[d92d282] | 937 | DrawIndicatorText((int)x, (int)y, (*label)->GetText()); |
---|
| 938 | |
---|
| 939 | if (iy > QUANTISE_FACTOR) iy = QUANTISE_FACTOR; |
---|
| 940 | test -= quantised_x * iy; |
---|
[f12e8cc] | 941 | iy += 4; |
---|
| 942 | while (--iy && test < m_LabelGrid + buffer_size) { |
---|
[d92d282] | 943 | memset(test, 1, width); |
---|
| 944 | test += quantised_x; |
---|
[429465a] | 945 | } |
---|
[84cab34] | 946 | } |
---|
[5809313] | 947 | } |
---|
| 948 | |
---|
| 949 | void GfxCore::SimpleDrawNames() |
---|
| 950 | { |
---|
[a8aedf4] | 951 | // Draw all station names, without worrying about overlaps |
---|
[d5de678] | 952 | list<LabelInfo*>::const_iterator label = m_Parent->GetLabels(); |
---|
[01d91fd] | 953 | for ( ; label != m_Parent->GetLabelsEnd(); ++label) { |
---|
[ece003f] | 954 | if (!((m_Surface && (*label)->IsSurface()) || |
---|
| 955 | (m_Legs && (*label)->IsUnderground()) || |
---|
| 956 | (!(*label)->IsSurface() && !(*label)->IsUnderground()))) { |
---|
| 957 | // if this station isn't to be displayed, skip to the next |
---|
| 958 | // (last case is for stns with no legs attached) |
---|
| 959 | continue; |
---|
| 960 | } |
---|
| 961 | |
---|
[f6d8375] | 962 | double x, y, z; |
---|
[d67450e] | 963 | Transform(**label, &x, &y, &z); |
---|
[d92d282] | 964 | |
---|
| 965 | // Check if the label is behind us (in perspective view). |
---|
| 966 | if (z <= 0) continue; |
---|
| 967 | |
---|
[8bd480e] | 968 | x += 3; |
---|
| 969 | y -= GetFontSize() / 2; |
---|
[d92d282] | 970 | DrawIndicatorText((int)x, (int)y, (*label)->GetText()); |
---|
[84cab34] | 971 | } |
---|
[5809313] | 972 | } |
---|
| 973 | |
---|
[825bdff] | 974 | void GfxCore::DrawColourKey(int num_bands, const wxString & other, const wxString & units) |
---|
[5809313] | 975 | { |
---|
[7cdb1c3] | 976 | int total_block_height = |
---|
[62da267] | 977 | KEY_BLOCK_HEIGHT * (num_bands == 1 ? num_bands : num_bands - 1); |
---|
| 978 | if (!other.empty()) total_block_height += KEY_BLOCK_HEIGHT * 2; |
---|
[825bdff] | 979 | if (!units.empty()) total_block_height += KEY_BLOCK_HEIGHT; |
---|
[5809313] | 980 | |
---|
[3585243] | 981 | const int bottom = -total_block_height; |
---|
[a74b014] | 982 | |
---|
[d4650b3] | 983 | int size = 0; |
---|
[7cdb1c3] | 984 | if (!other.empty()) GetTextExtent(other, &size, NULL); |
---|
[d4650b3] | 985 | int band; |
---|
[2043961] | 986 | for (band = 0; band < num_bands; ++band) { |
---|
[a74b014] | 987 | int x; |
---|
[7cdb1c3] | 988 | GetTextExtent(key_legends[band], &x, NULL); |
---|
[d4650b3] | 989 | if (x > size) size = x; |
---|
| 990 | } |
---|
| 991 | |
---|
[3585243] | 992 | int left = -KEY_BLOCK_WIDTH - size; |
---|
[d4650b3] | 993 | |
---|
[fcc3741] | 994 | key_lowerleft[m_ColourBy].x = left - KEY_EXTRA_LEFT_MARGIN; |
---|
| 995 | key_lowerleft[m_ColourBy].y = bottom; |
---|
[d4650b3] | 996 | |
---|
[d43fa84] | 997 | int y = bottom; |
---|
[825bdff] | 998 | if (!units.empty()) y += KEY_BLOCK_HEIGHT; |
---|
[a74b014] | 999 | |
---|
[7cdb1c3] | 1000 | if (!other.empty()) { |
---|
[a74b014] | 1001 | DrawShadedRectangle(GetSurfacePen(), GetSurfacePen(), left, y, |
---|
[62da267] | 1002 | KEY_BLOCK_WIDTH, KEY_BLOCK_HEIGHT); |
---|
[2779338f] | 1003 | SetColour(col_BLACK); |
---|
| 1004 | BeginPolyline(); |
---|
| 1005 | PlaceIndicatorVertex(left, y); |
---|
| 1006 | PlaceIndicatorVertex(left + KEY_BLOCK_WIDTH, y); |
---|
| 1007 | PlaceIndicatorVertex(left + KEY_BLOCK_WIDTH, y + KEY_BLOCK_HEIGHT); |
---|
| 1008 | PlaceIndicatorVertex(left, y + KEY_BLOCK_HEIGHT); |
---|
| 1009 | PlaceIndicatorVertex(left, y); |
---|
| 1010 | EndPolyline(); |
---|
[62da267] | 1011 | y += KEY_BLOCK_HEIGHT * 2; |
---|
[a74b014] | 1012 | } |
---|
| 1013 | |
---|
[2779338f] | 1014 | int start = y; |
---|
[2043961] | 1015 | if (num_bands == 1) { |
---|
| 1016 | DrawShadedRectangle(GetPen(0), GetPen(0), left, y, |
---|
[62da267] | 1017 | KEY_BLOCK_WIDTH, KEY_BLOCK_HEIGHT); |
---|
[2779338f] | 1018 | y += KEY_BLOCK_HEIGHT; |
---|
[2043961] | 1019 | } else { |
---|
| 1020 | for (band = 0; band < num_bands - 1; ++band) { |
---|
| 1021 | DrawShadedRectangle(GetPen(band), GetPen(band + 1), left, y, |
---|
[62da267] | 1022 | KEY_BLOCK_WIDTH, KEY_BLOCK_HEIGHT); |
---|
| 1023 | y += KEY_BLOCK_HEIGHT; |
---|
[2043961] | 1024 | } |
---|
[d4650b3] | 1025 | } |
---|
| 1026 | |
---|
[2779338f] | 1027 | SetColour(col_BLACK); |
---|
| 1028 | BeginPolyline(); |
---|
| 1029 | PlaceIndicatorVertex(left, y); |
---|
| 1030 | PlaceIndicatorVertex(left + KEY_BLOCK_WIDTH, y); |
---|
| 1031 | PlaceIndicatorVertex(left + KEY_BLOCK_WIDTH, start); |
---|
| 1032 | PlaceIndicatorVertex(left, start); |
---|
| 1033 | PlaceIndicatorVertex(left, y); |
---|
| 1034 | EndPolyline(); |
---|
| 1035 | |
---|
[825bdff] | 1036 | SetColour(TEXT_COLOUR); |
---|
| 1037 | |
---|
| 1038 | y = bottom; |
---|
| 1039 | if (!units.empty()) { |
---|
| 1040 | GetTextExtent(units, &size, NULL); |
---|
| 1041 | DrawIndicatorText(left + (KEY_BLOCK_WIDTH - size) / 2, y, units); |
---|
| 1042 | y += KEY_BLOCK_HEIGHT; |
---|
| 1043 | } |
---|
| 1044 | y -= GetFontSize() / 2; |
---|
[62da267] | 1045 | left += KEY_BLOCK_WIDTH + 5; |
---|
[d4650b3] | 1046 | |
---|
[7cdb1c3] | 1047 | if (!other.empty()) { |
---|
[62da267] | 1048 | y += KEY_BLOCK_HEIGHT / 2; |
---|
[7cdb1c3] | 1049 | DrawIndicatorText(left, y, other); |
---|
[62da267] | 1050 | y += KEY_BLOCK_HEIGHT * 2 - KEY_BLOCK_HEIGHT / 2; |
---|
[a74b014] | 1051 | } |
---|
| 1052 | |
---|
[2043961] | 1053 | if (num_bands == 1) { |
---|
[62da267] | 1054 | y += KEY_BLOCK_HEIGHT / 2; |
---|
[7cdb1c3] | 1055 | DrawIndicatorText(left, y, key_legends[0]); |
---|
[2043961] | 1056 | } else { |
---|
[62c5fc6] | 1057 | for (band = 0; band < num_bands; ++band) { |
---|
[7cdb1c3] | 1058 | DrawIndicatorText(left, y, key_legends[band]); |
---|
[62da267] | 1059 | y += KEY_BLOCK_HEIGHT; |
---|
[2043961] | 1060 | } |
---|
[d4650b3] | 1061 | } |
---|
| 1062 | } |
---|
| 1063 | |
---|
[e2ea75a] | 1064 | void GfxCore::DrawDepthKey() |
---|
[c61aa79] | 1065 | { |
---|
[62c5fc6] | 1066 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
[825bdff] | 1067 | int num_bands = 1; |
---|
| 1068 | int sf = 0; |
---|
| 1069 | if (z_ext > 0.0) { |
---|
[62c5fc6] | 1070 | num_bands = GetNumColourBands(); |
---|
[825bdff] | 1071 | Double z_range = z_ext; |
---|
| 1072 | if (!m_Metric) z_range /= METRES_PER_FOOT; |
---|
| 1073 | sf = max(0, 1 - (int)floor(log10(z_range))); |
---|
[62c5fc6] | 1074 | } |
---|
| 1075 | |
---|
[825bdff] | 1076 | Double z_min = m_Parent->GetDepthMin() + m_Parent->GetOffset().GetZ(); |
---|
| 1077 | for (int band = 0; band < num_bands; ++band) { |
---|
| 1078 | Double z = z_min; |
---|
[62c5fc6] | 1079 | if (band) |
---|
| 1080 | z += z_ext * band / (num_bands - 1); |
---|
[825bdff] | 1081 | |
---|
| 1082 | if (!m_Metric) |
---|
| 1083 | z /= METRES_PER_FOOT; |
---|
| 1084 | |
---|
| 1085 | key_legends[band].Printf(wxT("%.*f"), sf, z); |
---|
[c61aa79] | 1086 | } |
---|
| 1087 | |
---|
[ccb83b7] | 1088 | DrawColourKey(num_bands, wxString(), wmsg(m_Metric ? /*m*/424: /*ft*/428)); |
---|
[7cdb1c3] | 1089 | } |
---|
[a74b014] | 1090 | |
---|
[e2ea75a] | 1091 | void GfxCore::DrawDateKey() |
---|
[7cdb1c3] | 1092 | { |
---|
| 1093 | int num_bands; |
---|
[62c5fc6] | 1094 | if (!HasDateInformation()) { |
---|
| 1095 | num_bands = 0; |
---|
[7cdb1c3] | 1096 | } else { |
---|
[62c5fc6] | 1097 | int date_ext = m_Parent->GetDateExtent(); |
---|
| 1098 | if (date_ext == 0) { |
---|
| 1099 | num_bands = 1; |
---|
| 1100 | } else { |
---|
| 1101 | num_bands = GetNumColourBands(); |
---|
| 1102 | } |
---|
| 1103 | for (int band = 0; band < num_bands; ++band) { |
---|
| 1104 | int y, m, d; |
---|
| 1105 | int days = m_Parent->GetDateMin(); |
---|
| 1106 | if (band) |
---|
| 1107 | days += date_ext * band / (num_bands - 1); |
---|
| 1108 | ymd_from_days_since_1900(days, &y, &m, &d); |
---|
| 1109 | key_legends[band].Printf(wxT("%04d-%02d-%02d"), y, m, d); |
---|
| 1110 | } |
---|
[7cdb1c3] | 1111 | } |
---|
[62c5fc6] | 1112 | |
---|
[7cdb1c3] | 1113 | wxString other; |
---|
| 1114 | if (!m_Parent->HasCompleteDateInfo()) { |
---|
[736f7df] | 1115 | /* TRANSLATORS: Used in the "colour key" for "colour by date" if there |
---|
[0b8c321] | 1116 | * are surveys without date information. Try to keep this fairly short. |
---|
| 1117 | */ |
---|
[7cdb1c3] | 1118 | other = wmsg(/*Undated*/221); |
---|
[c61aa79] | 1119 | } |
---|
| 1120 | |
---|
[825bdff] | 1121 | DrawColourKey(num_bands, other, wxString()); |
---|
[7cdb1c3] | 1122 | } |
---|
[a74b014] | 1123 | |
---|
[e2ea75a] | 1124 | void GfxCore::DrawErrorKey() |
---|
[7cdb1c3] | 1125 | { |
---|
[62c5fc6] | 1126 | int num_bands; |
---|
| 1127 | if (HasErrorInformation()) { |
---|
| 1128 | // Use fixed colours for each error factor so it's directly visually |
---|
| 1129 | // comparable between surveys. |
---|
| 1130 | num_bands = GetNumColourBands(); |
---|
| 1131 | for (int band = 0; band < num_bands; ++band) { |
---|
| 1132 | double E = MAX_ERROR * band / (num_bands - 1); |
---|
| 1133 | key_legends[band].Printf(wxT("%.2f"), E); |
---|
| 1134 | } |
---|
| 1135 | } else { |
---|
| 1136 | num_bands = 0; |
---|
[c61aa79] | 1137 | } |
---|
| 1138 | |
---|
[7cdb1c3] | 1139 | // Always show the "Not in loop" legend for now (FIXME). |
---|
[736f7df] | 1140 | /* TRANSLATORS: Used in the "colour key" for "colour by error" for surveys |
---|
[0b8c321] | 1141 | * which aren’t part of a loop and so have no error information. Try to keep |
---|
| 1142 | * this fairly short. */ |
---|
[825bdff] | 1143 | DrawColourKey(num_bands, wmsg(/*Not in loop*/290), wxString()); |
---|
[ac537e9] | 1144 | } |
---|
| 1145 | |
---|
[cc9e2c65] | 1146 | void GfxCore::DrawGradientKey() |
---|
| 1147 | { |
---|
| 1148 | int num_bands; |
---|
| 1149 | // Use fixed colours for each gradient so it's directly visually comparable |
---|
| 1150 | // between surveys. |
---|
| 1151 | num_bands = GetNumColourBands(); |
---|
| 1152 | wxString units = wmsg(m_Degrees ? /*°*/344 : /*ᵍ*/76); |
---|
| 1153 | for (int band = 0; band < num_bands; ++band) { |
---|
| 1154 | double gradient = double(band) / (num_bands - 1); |
---|
| 1155 | if (m_Degrees) { |
---|
| 1156 | gradient *= 90.0; |
---|
| 1157 | } else { |
---|
| 1158 | gradient *= 100.0; |
---|
| 1159 | } |
---|
| 1160 | key_legends[band].Printf(wxT("%.f%s"), gradient, units); |
---|
| 1161 | } |
---|
| 1162 | |
---|
| 1163 | DrawColourKey(num_bands, wxString(), wxString()); |
---|
| 1164 | } |
---|
| 1165 | |
---|
[af50685] | 1166 | void GfxCore::DrawLengthKey() |
---|
| 1167 | { |
---|
| 1168 | int num_bands; |
---|
| 1169 | // Use fixed colours for each length so it's directly visually comparable |
---|
| 1170 | // between surveys. |
---|
| 1171 | num_bands = GetNumColourBands(); |
---|
| 1172 | for (int band = 0; band < num_bands; ++band) { |
---|
| 1173 | double len = pow(10, LOG_LEN_MAX * band / (num_bands - 1)); |
---|
| 1174 | if (!m_Metric) { |
---|
| 1175 | len /= METRES_PER_FOOT; |
---|
| 1176 | } |
---|
[355809f] | 1177 | key_legends[band].Printf(wxT("%.1f"), len); |
---|
[af50685] | 1178 | } |
---|
| 1179 | |
---|
[355809f] | 1180 | DrawColourKey(num_bands, wxString(), wmsg(m_Metric ? /*m*/424: /*ft*/428)); |
---|
[af50685] | 1181 | } |
---|
| 1182 | |
---|
[9c37beb] | 1183 | void GfxCore::DrawScaleBar() |
---|
[5809313] | 1184 | { |
---|
[84cab34] | 1185 | // Draw the scalebar. |
---|
[eef68f9] | 1186 | if (GetPerspective()) return; |
---|
[5809313] | 1187 | |
---|
[37bc1f5] | 1188 | // Calculate how many metres of survey are currently displayed across the |
---|
| 1189 | // screen. |
---|
[087bc72] | 1190 | Double across_screen = SurveyUnitsAcrossViewport(); |
---|
[156dc16] | 1191 | |
---|
[90430f2] | 1192 | double f = double(GetClinoXPosition() - INDICATOR_BOX_SIZE / 2 - SCALE_BAR_OFFSET_X) / GetXSize(); |
---|
[5f50488] | 1193 | if (f > 0.75) { |
---|
| 1194 | f = 0.75; |
---|
| 1195 | } else if (f < 0.5) { |
---|
| 1196 | // Stop it getting squeezed to nothing. |
---|
| 1197 | // FIXME: In this case we should probably move the compass and clino up |
---|
| 1198 | // to make room rather than letting stuff overlap. |
---|
| 1199 | f = 0.5; |
---|
| 1200 | } |
---|
| 1201 | |
---|
[087bc72] | 1202 | // Convert to imperial measurements if required. |
---|
[7a89dc2] | 1203 | Double multiplier = 1.0; |
---|
| 1204 | if (!m_Metric) { |
---|
[429465a] | 1205 | across_screen /= METRES_PER_FOOT; |
---|
| 1206 | multiplier = METRES_PER_FOOT; |
---|
[5f50488] | 1207 | if (across_screen >= 5280.0 / f) { |
---|
[429465a] | 1208 | across_screen /= 5280.0; |
---|
| 1209 | multiplier *= 5280.0; |
---|
| 1210 | } |
---|
[7a89dc2] | 1211 | } |
---|
[5757725] | 1212 | |
---|
[7a89dc2] | 1213 | // Calculate the length of the scale bar. |
---|
[5f50488] | 1214 | Double size_snap = pow(10.0, floor(log10(f * across_screen))); |
---|
| 1215 | Double t = across_screen * f / size_snap; |
---|
[98860c5] | 1216 | if (t >= 5.0) { |
---|
[429465a] | 1217 | size_snap *= 5.0; |
---|
[7a89dc2] | 1218 | } else if (t >= 2.0) { |
---|
[429465a] | 1219 | size_snap *= 2.0; |
---|
[98860c5] | 1220 | } |
---|
| 1221 | |
---|
[7a89dc2] | 1222 | if (!m_Metric) size_snap *= multiplier; |
---|
| 1223 | |
---|
[84cab34] | 1224 | // Actual size of the thing in pixels: |
---|
[90430f2] | 1225 | int size = int((size_snap / SurveyUnitsAcrossViewport()) * GetXSize()); |
---|
[e2c1671] | 1226 | m_ScaleBarWidth = size; |
---|
[421b7d2] | 1227 | |
---|
[5809313] | 1228 | // Draw it... |
---|
[e2c1671] | 1229 | const int end_y = SCALE_BAR_OFFSET_Y + SCALE_BAR_HEIGHT; |
---|
[5809313] | 1230 | int interval = size / 10; |
---|
| 1231 | |
---|
[aa048c3] | 1232 | gla_colour col = col_WHITE; |
---|
[5809313] | 1233 | for (int ix = 0; ix < 10; ix++) { |
---|
[e2c1671] | 1234 | int x = SCALE_BAR_OFFSET_X + int(ix * ((Double) size / 10.0)); |
---|
[421b7d2] | 1235 | |
---|
[e2c1671] | 1236 | DrawRectangle(col, col, x, end_y, interval + 2, SCALE_BAR_HEIGHT); |
---|
[421b7d2] | 1237 | |
---|
[aa048c3] | 1238 | col = (col == col_WHITE) ? col_GREY : col_WHITE; |
---|
[5809313] | 1239 | } |
---|
| 1240 | |
---|
[84cab34] | 1241 | // Add labels. |
---|
[825bdff] | 1242 | wxString str; |
---|
[ccb83b7] | 1243 | int units; |
---|
[825bdff] | 1244 | if (m_Metric) { |
---|
[ccb83b7] | 1245 | Double km = size_snap * 1e-3; |
---|
| 1246 | if (km >= 1.0) { |
---|
| 1247 | size_snap = km; |
---|
[736f7df] | 1248 | /* TRANSLATORS: abbreviation for "kilometres" (unit of length), |
---|
| 1249 | * used e.g. "5km". |
---|
| 1250 | * |
---|
| 1251 | * If there should be a space between the number and this, include |
---|
| 1252 | * one in the translation. */ |
---|
[ccb83b7] | 1253 | units = /*km*/423; |
---|
[825bdff] | 1254 | } else if (size_snap >= 1.0) { |
---|
[736f7df] | 1255 | /* TRANSLATORS: abbreviation for "metres" (unit of length), used |
---|
| 1256 | * e.g. "10m". |
---|
| 1257 | * |
---|
| 1258 | * If there should be a space between the number and this, include |
---|
| 1259 | * one in the translation. */ |
---|
[ccb83b7] | 1260 | units = /*m*/424; |
---|
[825bdff] | 1261 | } else { |
---|
[ccb83b7] | 1262 | size_snap *= 1e2; |
---|
[736f7df] | 1263 | /* TRANSLATORS: abbreviation for "centimetres" (unit of length), |
---|
| 1264 | * used e.g. "50cm". |
---|
| 1265 | * |
---|
| 1266 | * If there should be a space between the number and this, include |
---|
| 1267 | * one in the translation. */ |
---|
[ccb83b7] | 1268 | units = /*cm*/425; |
---|
[825bdff] | 1269 | } |
---|
| 1270 | } else { |
---|
| 1271 | size_snap /= METRES_PER_FOOT; |
---|
| 1272 | Double miles = size_snap / 5280.0; |
---|
[ccb83b7] | 1273 | if (miles >= 1.0) { |
---|
| 1274 | size_snap = miles; |
---|
| 1275 | if (size_snap >= 2.0) { |
---|
[736f7df] | 1276 | /* TRANSLATORS: abbreviation for "miles" (unit of length, |
---|
| 1277 | * plural), used e.g. "2 miles". |
---|
| 1278 | * |
---|
| 1279 | * If there should be a space between the number and this, |
---|
| 1280 | * include one in the translation. */ |
---|
[ccb83b7] | 1281 | units = /* miles*/426; |
---|
[825bdff] | 1282 | } else { |
---|
[736f7df] | 1283 | /* TRANSLATORS: abbreviation for "mile" (unit of length, |
---|
| 1284 | * singular), used e.g. "1 mile". |
---|
| 1285 | * |
---|
| 1286 | * If there should be a space between the number and this, |
---|
| 1287 | * include one in the translation. */ |
---|
[ccb83b7] | 1288 | units = /* mile*/427; |
---|
[825bdff] | 1289 | } |
---|
[ccb83b7] | 1290 | } else if (size_snap >= 1.0) { |
---|
[736f7df] | 1291 | /* TRANSLATORS: abbreviation for "feet" (unit of length), used e.g. |
---|
| 1292 | * as "10ft". |
---|
| 1293 | * |
---|
| 1294 | * If there should be a space between the number and this, include |
---|
| 1295 | * one in the translation. */ |
---|
[ccb83b7] | 1296 | units = /*ft*/428; |
---|
| 1297 | } else { |
---|
| 1298 | size_snap *= 12.0; |
---|
[736f7df] | 1299 | /* TRANSLATORS: abbreviation for "inches" (unit of length), used |
---|
| 1300 | * e.g. as "6in". |
---|
| 1301 | * |
---|
| 1302 | * If there should be a space between the number and this, include |
---|
| 1303 | * one in the translation. */ |
---|
[ccb83b7] | 1304 | units = /*in*/429; |
---|
[825bdff] | 1305 | } |
---|
| 1306 | } |
---|
[ccb83b7] | 1307 | if (size_snap >= 1.0) { |
---|
| 1308 | str.Printf(wxT("%.f%s"), size_snap, wmsg(units).c_str()); |
---|
| 1309 | } else { |
---|
| 1310 | int sf = -(int)floor(log10(size_snap)); |
---|
| 1311 | str.Printf(wxT("%.*f%s"), sf, size_snap, wmsg(units).c_str()); |
---|
| 1312 | } |
---|
[84cab34] | 1313 | |
---|
[1eeb55a] | 1314 | int text_width, text_height; |
---|
[56da40e] | 1315 | GetTextExtent(str, &text_width, &text_height); |
---|
[8bd480e] | 1316 | const int text_y = end_y - text_height + 1; |
---|
| 1317 | SetColour(TEXT_COLOUR); |
---|
[5627cbb] | 1318 | DrawIndicatorText(SCALE_BAR_OFFSET_X, text_y, wxT("0")); |
---|
[8bd480e] | 1319 | DrawIndicatorText(SCALE_BAR_OFFSET_X + size - text_width, text_y, str); |
---|
[5809313] | 1320 | } |
---|
[56da40e] | 1321 | |
---|
[2072157] | 1322 | bool GfxCore::CheckHitTestGrid(const wxPoint& point, bool centre) |
---|
[2effbf1] | 1323 | { |
---|
[0874c07e] | 1324 | if (Animating()) return false; |
---|
| 1325 | |
---|
[90430f2] | 1326 | if (point.x < 0 || point.x >= GetXSize() || |
---|
| 1327 | point.y < 0 || point.y >= GetYSize()) { |
---|
[429465a] | 1328 | return false; |
---|
[137e31b] | 1329 | } |
---|
[421b7d2] | 1330 | |
---|
[156f645] | 1331 | SetDataTransform(); |
---|
[00a68e0] | 1332 | |
---|
[69463a0] | 1333 | if (!m_HitTestGridValid) CreateHitTestGrid(); |
---|
[fa42426] | 1334 | |
---|
[0b0520c] | 1335 | int grid_x = point.x * HITTEST_SIZE / (GetXSize() + 1); |
---|
| 1336 | int grid_y = point.y * HITTEST_SIZE / (GetYSize() + 1); |
---|
[137e31b] | 1337 | |
---|
[fa42426] | 1338 | LabelInfo *best = NULL; |
---|
[d96c95c] | 1339 | int dist_sqrd = sqrd_measure_threshold; |
---|
[2effbf1] | 1340 | int square = grid_x + grid_y * HITTEST_SIZE; |
---|
[fa42426] | 1341 | list<LabelInfo*>::iterator iter = m_PointGrid[square].begin(); |
---|
[00a68e0] | 1342 | |
---|
[fa42426] | 1343 | while (iter != m_PointGrid[square].end()) { |
---|
[429465a] | 1344 | LabelInfo *pt = *iter++; |
---|
[fa42426] | 1345 | |
---|
[f6d8375] | 1346 | double cx, cy, cz; |
---|
[00a68e0] | 1347 | |
---|
[d67450e] | 1348 | Transform(*pt, &cx, &cy, &cz); |
---|
[00a68e0] | 1349 | |
---|
[90430f2] | 1350 | cy = GetYSize() - cy; |
---|
[00a68e0] | 1351 | |
---|
[429465a] | 1352 | int dx = point.x - int(cx); |
---|
| 1353 | int ds = dx * dx; |
---|
| 1354 | if (ds >= dist_sqrd) continue; |
---|
| 1355 | int dy = point.y - int(cy); |
---|
[fa42426] | 1356 | |
---|
[429465a] | 1357 | ds += dy * dy; |
---|
| 1358 | if (ds >= dist_sqrd) continue; |
---|
[f433fda] | 1359 | |
---|
[429465a] | 1360 | dist_sqrd = ds; |
---|
| 1361 | best = pt; |
---|
[f433fda] | 1362 | |
---|
[429465a] | 1363 | if (ds == 0) break; |
---|
[2effbf1] | 1364 | } |
---|
[f433fda] | 1365 | |
---|
[fa42426] | 1366 | if (best) { |
---|
[381ae6e] | 1367 | m_Parent->ShowInfo(best, m_there); |
---|
[429465a] | 1368 | if (centre) { |
---|
[e67ed1b] | 1369 | // FIXME: allow Ctrl-Click to not set there or something? |
---|
[82c3731] | 1370 | CentreOn(*best); |
---|
[90430f2] | 1371 | WarpPointer(GetXSize() / 2, GetYSize() / 2); |
---|
[381ae6e] | 1372 | SetThere(best); |
---|
[429465a] | 1373 | m_Parent->SelectTreeItem(best); |
---|
| 1374 | } |
---|
[e67ed1b] | 1375 | } else { |
---|
| 1376 | // Left-clicking not on a survey cancels the measuring line. |
---|
[0633bcc] | 1377 | if (centre) { |
---|
| 1378 | ClearTreeSelection(); |
---|
| 1379 | } else { |
---|
[381ae6e] | 1380 | m_Parent->ShowInfo(best, m_there); |
---|
[f6d8375] | 1381 | double x, y, z; |
---|
[90430f2] | 1382 | ReverseTransform(point.x, GetYSize() - point.y, &x, &y, &z); |
---|
[381ae6e] | 1383 | temp_here.assign(Vector3(x, y, z)); |
---|
| 1384 | SetHere(&temp_here); |
---|
[0633bcc] | 1385 | } |
---|
[2effbf1] | 1386 | } |
---|
[203d2a7] | 1387 | |
---|
| 1388 | return best; |
---|
[2effbf1] | 1389 | } |
---|
| 1390 | |
---|
[5876fcb] | 1391 | void GfxCore::OnSize(wxSizeEvent& event) |
---|
[5809313] | 1392 | { |
---|
[5876fcb] | 1393 | // Handle a change in window size. |
---|
| 1394 | wxSize size = event.GetSize(); |
---|
[5809313] | 1395 | |
---|
[78beaf1] | 1396 | if (size.GetWidth() <= 0 || size.GetHeight() <= 0) { |
---|
[0580c6a] | 1397 | // Before things are fully initialised, we sometimes get a bogus |
---|
| 1398 | // resize message... |
---|
[6ef8bd73] | 1399 | // FIXME have changes in MainFrm cured this? It still happens with |
---|
[880b954] | 1400 | // 1.0.32 and wxGTK 2.5.2 (load a file from the command line). |
---|
| 1401 | // With 1.1.6 and wxGTK 2.4.2 we only get negative sizes if MainFrm |
---|
[78beaf1] | 1402 | // is resized such that the GfxCore window isn't visible. |
---|
| 1403 | //printf("OnSize(%d,%d)\n", size.GetWidth(), size.GetHeight()); |
---|
[0580c6a] | 1404 | return; |
---|
| 1405 | } |
---|
[b72f4b5] | 1406 | |
---|
[9071cf5] | 1407 | event.Skip(); |
---|
[39e460c9] | 1408 | |
---|
[5876fcb] | 1409 | if (m_DoneFirstShow) { |
---|
[81f1266] | 1410 | TryToFreeArrays(); |
---|
[6ebc0ce] | 1411 | |
---|
[69463a0] | 1412 | m_HitTestGridValid = false; |
---|
[33b2094] | 1413 | |
---|
[d67450e] | 1414 | ForceRefresh(); |
---|
[5809313] | 1415 | } |
---|
| 1416 | } |
---|
| 1417 | |
---|
[de7a879] | 1418 | void GfxCore::DefaultParameters() |
---|
[5809313] | 1419 | { |
---|
[33b2094] | 1420 | // Set default viewing parameters. |
---|
[b462168] | 1421 | |
---|
[f433fda] | 1422 | m_Surface = false; |
---|
| 1423 | if (!m_Parent->HasUndergroundLegs()) { |
---|
| 1424 | if (m_Parent->HasSurfaceLegs()) { |
---|
| 1425 | // If there are surface legs, but no underground legs, turn |
---|
| 1426 | // surface surveys on. |
---|
| 1427 | m_Surface = true; |
---|
| 1428 | } else { |
---|
| 1429 | // If there are no legs (e.g. after loading a .pos file), turn |
---|
| 1430 | // crosses on. |
---|
| 1431 | m_Crosses = true; |
---|
| 1432 | } |
---|
[b462168] | 1433 | } |
---|
| 1434 | |
---|
[714daae] | 1435 | m_PanAngle = 0.0; |
---|
[eef68f9] | 1436 | if (m_Parent->IsExtendedElevation()) { |
---|
| 1437 | m_TiltAngle = 0.0; |
---|
| 1438 | } else { |
---|
[7a57dc7] | 1439 | m_TiltAngle = -90.0; |
---|
[b462168] | 1440 | } |
---|
[714daae] | 1441 | |
---|
[08253d9] | 1442 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[d67450e] | 1443 | SetTranslation(Vector3()); |
---|
[33b2094] | 1444 | |
---|
[e577f89] | 1445 | m_RotationStep = 30.0; |
---|
[5809313] | 1446 | m_Rotating = false; |
---|
[3d00693] | 1447 | m_SwitchingTo = 0; |
---|
[fe444b8] | 1448 | m_Entrances = false; |
---|
| 1449 | m_FixedPts = false; |
---|
| 1450 | m_ExportedPts = false; |
---|
[c1cf79d] | 1451 | m_Grid = false; |
---|
[f4c5932] | 1452 | m_BoundingBox = false; |
---|
[33b2094] | 1453 | m_Tubes = false; |
---|
[1eeb55a] | 1454 | if (GetPerspective()) TogglePerspective(); |
---|
[de7a879] | 1455 | } |
---|
[5809313] | 1456 | |
---|
[de7a879] | 1457 | void GfxCore::Defaults() |
---|
| 1458 | { |
---|
| 1459 | // Restore default scale, rotation and translation parameters. |
---|
| 1460 | DefaultParameters(); |
---|
[8b0d57f] | 1461 | SetScale(1.0); |
---|
[ba358fc] | 1462 | |
---|
| 1463 | // Invalidate all the cached lists. |
---|
| 1464 | GLACanvas::FirstShow(); |
---|
| 1465 | |
---|
[fa42426] | 1466 | ForceRefresh(); |
---|
[5809313] | 1467 | } |
---|
[84cab34] | 1468 | |
---|
[5455bb2] | 1469 | void GfxCore::Animate() |
---|
[5809313] | 1470 | { |
---|
[2a3d328] | 1471 | // Don't show pointer coordinates while animating. |
---|
[4b031c0] | 1472 | // FIXME : only do this when we *START* animating! Use a static copy |
---|
| 1473 | // of the value of "Animating()" last time we were here to track this? |
---|
| 1474 | // MainFrm now checks if we're trying to clear already cleared labels |
---|
| 1475 | // and just returns, but it might be simpler to check here! |
---|
[2a3d328] | 1476 | ClearCoords(); |
---|
[381ae6e] | 1477 | m_Parent->ShowInfo(); |
---|
[5809313] | 1478 | |
---|
[5455bb2] | 1479 | long t; |
---|
[75d4a2b] | 1480 | if (movie) { |
---|
[aea4f8b] | 1481 | ReadPixels(movie->GetWidth(), movie->GetHeight(), movie->GetBuffer()); |
---|
[98fd937] | 1482 | if (!movie->AddFrame()) { |
---|
| 1483 | wxGetApp().ReportError(wxString(movie->get_error_string(), wxConvUTF8)); |
---|
| 1484 | delete movie; |
---|
| 1485 | movie = NULL; |
---|
| 1486 | presentation_mode = 0; |
---|
[5455bb2] | 1487 | return; |
---|
[98fd937] | 1488 | } |
---|
[5455bb2] | 1489 | t = 1000 / 25; // 25 frames per second |
---|
[6a4cdcb6] | 1490 | } else { |
---|
[5455bb2] | 1491 | static long t_prev = 0; |
---|
| 1492 | t = timer.Time(); |
---|
| 1493 | // Avoid redrawing twice in the same frame. |
---|
[ff1601e] | 1494 | long delta_t = (t_prev == 0 ? 1000 / MAX_FRAMERATE : t - t_prev); |
---|
| 1495 | if (delta_t < 1000 / MAX_FRAMERATE) |
---|
[6987d2a] | 1496 | return; |
---|
[5455bb2] | 1497 | t_prev = t; |
---|
[6987d2a] | 1498 | if (presentation_mode == PLAYING && pres_speed != 0.0) |
---|
| 1499 | t = delta_t; |
---|
[6a4cdcb6] | 1500 | } |
---|
[5809313] | 1501 | |
---|
[128fac4] | 1502 | if (presentation_mode == PLAYING && pres_speed != 0.0) { |
---|
[6987d2a] | 1503 | // FIXME: It would probably be better to work relative to the time we |
---|
| 1504 | // passed the last mark, but that's complicated by the speed |
---|
| 1505 | // potentially changing (or even the direction of playback reversing) |
---|
| 1506 | // at any point during playback. |
---|
| 1507 | Double tick = t * 0.001 * fabs(pres_speed); |
---|
| 1508 | while (tick >= next_mark_time) { |
---|
| 1509 | tick -= next_mark_time; |
---|
[128fac4] | 1510 | this_mark_total = 0; |
---|
[58dfdd21] | 1511 | PresentationMark prev_mark = next_mark; |
---|
[e577f89] | 1512 | if (prev_mark.angle < 0) prev_mark.angle += 360.0; |
---|
| 1513 | else if (prev_mark.angle >= 360.0) prev_mark.angle -= 360.0; |
---|
[128fac4] | 1514 | if (pres_reverse) |
---|
| 1515 | next_mark = m_Parent->GetPresMark(MARK_PREV); |
---|
| 1516 | else |
---|
| 1517 | next_mark = m_Parent->GetPresMark(MARK_NEXT); |
---|
[1690fa9] | 1518 | if (!next_mark.is_valid()) { |
---|
[128fac4] | 1519 | SetView(prev_mark); |
---|
[1690fa9] | 1520 | presentation_mode = 0; |
---|
[387babf] | 1521 | if (movie && !movie->Close()) { |
---|
[98fd937] | 1522 | wxGetApp().ReportError(wxString(movie->get_error_string(), wxConvUTF8)); |
---|
| 1523 | } |
---|
[81f1266] | 1524 | delete movie; |
---|
| 1525 | movie = NULL; |
---|
[1690fa9] | 1526 | break; |
---|
| 1527 | } |
---|
[58dfdd21] | 1528 | |
---|
[128fac4] | 1529 | double tmp = (pres_reverse ? prev_mark.time : next_mark.time); |
---|
| 1530 | if (tmp > 0) { |
---|
| 1531 | next_mark_time = tmp; |
---|
[58dfdd21] | 1532 | } else { |
---|
[d67450e] | 1533 | double d = (next_mark - prev_mark).magnitude(); |
---|
[49ce5b0] | 1534 | // FIXME: should ignore component of d which is unseen in |
---|
| 1535 | // non-perspective mode? |
---|
[8674eea] | 1536 | next_mark_time = sqrd(d / 30.0); |
---|
[49ce5b0] | 1537 | double a = next_mark.angle - prev_mark.angle; |
---|
| 1538 | if (a > 180.0) { |
---|
| 1539 | next_mark.angle -= 360.0; |
---|
| 1540 | a = 360.0 - a; |
---|
| 1541 | } else if (a < -180.0) { |
---|
| 1542 | next_mark.angle += 360.0; |
---|
| 1543 | a += 360.0; |
---|
| 1544 | } else { |
---|
| 1545 | a = fabs(a); |
---|
| 1546 | } |
---|
| 1547 | next_mark_time += sqrd(a / 60.0); |
---|
| 1548 | double ta = fabs(next_mark.tilt_angle - prev_mark.tilt_angle); |
---|
| 1549 | next_mark_time += sqrd(ta / 60.0); |
---|
| 1550 | double s = fabs(log(next_mark.scale) - log(prev_mark.scale)); |
---|
[8674eea] | 1551 | next_mark_time += sqrd(s / 2.0); |
---|
[49ce5b0] | 1552 | next_mark_time = sqrt(next_mark_time); |
---|
[8674eea] | 1553 | // was: next_mark_time = max(max(d / 30, s / 2), max(a, ta) / 60); |
---|
[49ce5b0] | 1554 | //printf("*** %.6f from (\nd: %.6f\ns: %.6f\na: %.6f\nt: %.6f )\n", |
---|
[8674eea] | 1555 | // next_mark_time, d/30.0, s/2.0, a/60.0, ta/60.0); |
---|
| 1556 | if (tmp < 0) next_mark_time /= -tmp; |
---|
[58dfdd21] | 1557 | } |
---|
[1690fa9] | 1558 | } |
---|
| 1559 | |
---|
| 1560 | if (presentation_mode) { |
---|
| 1561 | // Advance position towards next_mark |
---|
[6987d2a] | 1562 | double p = tick / next_mark_time; |
---|
[1690fa9] | 1563 | double q = 1 - p; |
---|
| 1564 | PresentationMark here = GetView(); |
---|
[d877aa2] | 1565 | if (next_mark.angle < 0) { |
---|
[e577f89] | 1566 | if (here.angle >= next_mark.angle + 360.0) |
---|
| 1567 | here.angle -= 360.0; |
---|
| 1568 | } else if (next_mark.angle >= 360.0) { |
---|
| 1569 | if (here.angle <= next_mark.angle - 360.0) |
---|
| 1570 | here.angle += 360.0; |
---|
[d877aa2] | 1571 | } |
---|
[8674eea] | 1572 | here.assign(q * here + p * next_mark); |
---|
[1690fa9] | 1573 | here.angle = q * here.angle + p * next_mark.angle; |
---|
[e577f89] | 1574 | if (here.angle < 0) here.angle += 360.0; |
---|
| 1575 | else if (here.angle >= 360.0) here.angle -= 360.0; |
---|
[1690fa9] | 1576 | here.tilt_angle = q * here.tilt_angle + p * next_mark.tilt_angle; |
---|
[58dfdd21] | 1577 | here.scale = exp(q * log(here.scale) + p * log(next_mark.scale)); |
---|
[1690fa9] | 1578 | SetView(here); |
---|
[6987d2a] | 1579 | this_mark_total += tick; |
---|
| 1580 | next_mark_time -= tick; |
---|
[1690fa9] | 1581 | } |
---|
[6987d2a] | 1582 | |
---|
| 1583 | ForceRefresh(); |
---|
| 1584 | return; |
---|
[1690fa9] | 1585 | } |
---|
| 1586 | |
---|
[5876fcb] | 1587 | // When rotating... |
---|
| 1588 | if (m_Rotating) { |
---|
[5455bb2] | 1589 | Double step = base_pan + (t - base_pan_time) * 1e-3 * m_RotationStep - m_PanAngle; |
---|
| 1590 | TurnCave(step); |
---|
[5876fcb] | 1591 | } |
---|
[5809313] | 1592 | |
---|
[5876fcb] | 1593 | if (m_SwitchingTo == PLAN) { |
---|
[429465a] | 1594 | // When switching to plan view... |
---|
[5455bb2] | 1595 | Double step = base_tilt - (t - base_tilt_time) * 1e-3 * 90.0 - m_TiltAngle; |
---|
| 1596 | TiltCave(step); |
---|
[7a57dc7] | 1597 | if (m_TiltAngle == -90.0) { |
---|
[429465a] | 1598 | m_SwitchingTo = 0; |
---|
| 1599 | } |
---|
[1690fa9] | 1600 | } else if (m_SwitchingTo == ELEVATION) { |
---|
[429465a] | 1601 | // When switching to elevation view... |
---|
[5455bb2] | 1602 | Double step; |
---|
| 1603 | if (m_TiltAngle > 0.0) { |
---|
| 1604 | step = base_tilt - (t - base_tilt_time) * 1e-3 * 90.0 - m_TiltAngle; |
---|
[7a57dc7] | 1605 | } else { |
---|
[5455bb2] | 1606 | step = base_tilt + (t - base_tilt_time) * 1e-3 * 90.0 - m_TiltAngle; |
---|
[429465a] | 1607 | } |
---|
[5455bb2] | 1608 | if (fabs(step) >= fabs(m_TiltAngle)) { |
---|
[3ddd351] | 1609 | m_SwitchingTo = 0; |
---|
[5455bb2] | 1610 | step = -m_TiltAngle; |
---|
| 1611 | } |
---|
| 1612 | TiltCave(step); |
---|
| 1613 | } else if (m_SwitchingTo) { |
---|
| 1614 | // Rotate the shortest way around to the destination angle. If we're |
---|
| 1615 | // 180 off, we favour turning anticlockwise, as auto-rotation does by |
---|
| 1616 | // default. |
---|
| 1617 | Double target = (m_SwitchingTo - NORTH) * 90; |
---|
| 1618 | Double diff = target - m_PanAngle; |
---|
| 1619 | diff = fmod(diff, 360); |
---|
| 1620 | if (diff <= -180) |
---|
| 1621 | diff += 360; |
---|
| 1622 | else if (diff > 180) |
---|
| 1623 | diff -= 360; |
---|
| 1624 | if (m_RotationStep < 0 && diff == 180.0) |
---|
| 1625 | diff = -180.0; |
---|
| 1626 | Double step = base_pan - m_PanAngle; |
---|
| 1627 | Double delta = (t - base_pan_time) * 1e-3 * fabs(m_RotationStep); |
---|
| 1628 | if (diff > 0) { |
---|
| 1629 | step += delta; |
---|
[3ddd351] | 1630 | } else { |
---|
[5455bb2] | 1631 | step -= delta; |
---|
[3ddd351] | 1632 | } |
---|
[5455bb2] | 1633 | step = fmod(step, 360); |
---|
| 1634 | if (step <= -180) |
---|
| 1635 | step += 360; |
---|
| 1636 | else if (step > 180) |
---|
| 1637 | step -= 360; |
---|
| 1638 | if (fabs(step) >= fabs(diff)) { |
---|
| 1639 | m_SwitchingTo = 0; |
---|
| 1640 | step = diff; |
---|
| 1641 | } |
---|
| 1642 | TurnCave(step); |
---|
[5876fcb] | 1643 | } |
---|
[5809313] | 1644 | |
---|
[5455bb2] | 1645 | ForceRefresh(); |
---|
[5809313] | 1646 | } |
---|
[84cab34] | 1647 | |
---|
[0580c6a] | 1648 | // How much to allow around the box - this is because of the ring shape |
---|
| 1649 | // at one end of the line. |
---|
| 1650 | static const int HIGHLIGHTED_PT_SIZE = 2; // FIXME: tie in to blob and ring size |
---|
| 1651 | #define MARGIN (HIGHLIGHTED_PT_SIZE * 2 + 1) |
---|
[381ae6e] | 1652 | void GfxCore::RefreshLine(const Point *a, const Point *b, const Point *c) |
---|
[7a89dc2] | 1653 | { |
---|
[0f86024] | 1654 | #ifdef __WXMSW__ |
---|
| 1655 | (void)a; |
---|
| 1656 | (void)b; |
---|
| 1657 | (void)c; |
---|
| 1658 | // FIXME: We get odd redraw artifacts if we just update the line, and |
---|
| 1659 | // redrawing the whole scene doesn't actually seem to be measurably |
---|
| 1660 | // slower. That may not be true with software rendering though... |
---|
| 1661 | ForceRefresh(); |
---|
| 1662 | #else |
---|
[06d367d] | 1663 | // Best of all might be to copy the window contents before we draw the |
---|
| 1664 | // line, then replace each time we redraw. |
---|
[796d7bf] | 1665 | |
---|
[5876fcb] | 1666 | // Calculate the minimum rectangle which includes the old and new |
---|
| 1667 | // measuring lines to minimise the redraw time |
---|
| 1668 | int l = INT_MAX, r = INT_MIN, u = INT_MIN, d = INT_MAX; |
---|
[f6d8375] | 1669 | double X, Y, Z; |
---|
[381ae6e] | 1670 | if (a) { |
---|
| 1671 | if (!Transform(*a, &X, &Y, &Z)) { |
---|
[796d7bf] | 1672 | printf("oops\n"); |
---|
| 1673 | } else { |
---|
| 1674 | int x = int(X); |
---|
[90430f2] | 1675 | int y = GetYSize() - 1 - int(Y); |
---|
[1c448e1] | 1676 | l = x; |
---|
| 1677 | r = x; |
---|
| 1678 | u = y; |
---|
| 1679 | d = y; |
---|
[796d7bf] | 1680 | } |
---|
[5876fcb] | 1681 | } |
---|
[381ae6e] | 1682 | if (b) { |
---|
| 1683 | if (!Transform(*b, &X, &Y, &Z)) { |
---|
[796d7bf] | 1684 | printf("oops\n"); |
---|
| 1685 | } else { |
---|
| 1686 | int x = int(X); |
---|
[90430f2] | 1687 | int y = GetYSize() - 1 - int(Y); |
---|
[1c448e1] | 1688 | l = min(l, x); |
---|
| 1689 | r = max(r, x); |
---|
| 1690 | u = max(u, y); |
---|
| 1691 | d = min(d, y); |
---|
[796d7bf] | 1692 | } |
---|
[5876fcb] | 1693 | } |
---|
[381ae6e] | 1694 | if (c) { |
---|
| 1695 | if (!Transform(*c, &X, &Y, &Z)) { |
---|
[796d7bf] | 1696 | printf("oops\n"); |
---|
| 1697 | } else { |
---|
| 1698 | int x = int(X); |
---|
[90430f2] | 1699 | int y = GetYSize() - 1 - int(Y); |
---|
[1c448e1] | 1700 | l = min(l, x); |
---|
| 1701 | r = max(r, x); |
---|
| 1702 | u = max(u, y); |
---|
| 1703 | d = min(d, y); |
---|
[796d7bf] | 1704 | } |
---|
[5876fcb] | 1705 | } |
---|
[1c448e1] | 1706 | l -= MARGIN; |
---|
| 1707 | r += MARGIN; |
---|
| 1708 | u += MARGIN; |
---|
| 1709 | d -= MARGIN; |
---|
[0ca8fe0] | 1710 | RefreshRect(wxRect(l, d, r - l, u - d), false); |
---|
[0f86024] | 1711 | #endif |
---|
[7a89dc2] | 1712 | } |
---|
| 1713 | |
---|
[381ae6e] | 1714 | void GfxCore::SetHereFromTree(const LabelInfo * p) |
---|
| 1715 | { |
---|
| 1716 | SetHere(p); |
---|
| 1717 | m_Parent->ShowInfo(m_here, m_there); |
---|
| 1718 | } |
---|
| 1719 | |
---|
[5876fcb] | 1720 | void GfxCore::SetHere() |
---|
[7a89dc2] | 1721 | { |
---|
[381ae6e] | 1722 | if (!m_here) return; |
---|
[6b061db] | 1723 | bool line_active = MeasuringLineActive(); |
---|
[381ae6e] | 1724 | const LabelInfo * old = m_here; |
---|
| 1725 | m_here = NULL; |
---|
[6b061db] | 1726 | if (line_active || MeasuringLineActive()) |
---|
| 1727 | RefreshLine(old, m_there, m_here); |
---|
[7a89dc2] | 1728 | } |
---|
| 1729 | |
---|
[381ae6e] | 1730 | void GfxCore::SetHere(const LabelInfo *p) |
---|
[c6d95d8] | 1731 | { |
---|
[6b061db] | 1732 | bool line_active = MeasuringLineActive(); |
---|
[381ae6e] | 1733 | const LabelInfo * old = m_here; |
---|
[82c3731] | 1734 | m_here = p; |
---|
[6b061db] | 1735 | if (line_active || MeasuringLineActive()) |
---|
| 1736 | RefreshLine(old, m_there, m_here); |
---|
[156dc16] | 1737 | } |
---|
| 1738 | |
---|
[5876fcb] | 1739 | void GfxCore::SetThere() |
---|
[156dc16] | 1740 | { |
---|
[381ae6e] | 1741 | if (!m_there) return; |
---|
| 1742 | const LabelInfo * old = m_there; |
---|
| 1743 | m_there = NULL; |
---|
[0580c6a] | 1744 | RefreshLine(m_here, old, m_there); |
---|
[156dc16] | 1745 | } |
---|
| 1746 | |
---|
[381ae6e] | 1747 | void GfxCore::SetThere(const LabelInfo * p) |
---|
[156dc16] | 1748 | { |
---|
[381ae6e] | 1749 | const LabelInfo * old = m_there; |
---|
[82c3731] | 1750 | m_there = p; |
---|
[0580c6a] | 1751 | RefreshLine(m_here, old, m_there); |
---|
[156dc16] | 1752 | } |
---|
| 1753 | |
---|
[5876fcb] | 1754 | void GfxCore::CreateHitTestGrid() |
---|
[156dc16] | 1755 | { |
---|
[7171240] | 1756 | if (!m_PointGrid) { |
---|
| 1757 | // Initialise hit-test grid. |
---|
| 1758 | m_PointGrid = new list<LabelInfo*>[HITTEST_SIZE * HITTEST_SIZE]; |
---|
| 1759 | } else { |
---|
| 1760 | // Clear hit-test grid. |
---|
| 1761 | for (int i = 0; i < HITTEST_SIZE * HITTEST_SIZE; i++) { |
---|
| 1762 | m_PointGrid[i].clear(); |
---|
| 1763 | } |
---|
[5876fcb] | 1764 | } |
---|
[156dc16] | 1765 | |
---|
[5876fcb] | 1766 | // Fill the grid. |
---|
| 1767 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 1768 | list<LabelInfo*>::const_iterator end = m_Parent->GetLabelsEnd(); |
---|
| 1769 | while (pos != end) { |
---|
[429465a] | 1770 | LabelInfo* label = *pos++; |
---|
[33b2094] | 1771 | |
---|
[429465a] | 1772 | if (!((m_Surface && label->IsSurface()) || |
---|
[dc42b8e] | 1773 | (m_Legs && label->IsUnderground()) || |
---|
| 1774 | (!label->IsSurface() && !label->IsUnderground()))) { |
---|
| 1775 | // if this station isn't to be displayed, skip to the next |
---|
| 1776 | // (last case is for stns with no legs attached) |
---|
[429465a] | 1777 | continue; |
---|
| 1778 | } |
---|
[33b2094] | 1779 | |
---|
[429465a] | 1780 | // Calculate screen coordinates. |
---|
[f6d8375] | 1781 | double cx, cy, cz; |
---|
[d67450e] | 1782 | Transform(*label, &cx, &cy, &cz); |
---|
[90430f2] | 1783 | if (cx < 0 || cx >= GetXSize()) continue; |
---|
| 1784 | if (cy < 0 || cy >= GetYSize()) continue; |
---|
[33b2094] | 1785 | |
---|
[90430f2] | 1786 | cy = GetYSize() - cy; |
---|
[00a68e0] | 1787 | |
---|
[429465a] | 1788 | // On-screen, so add to hit-test grid... |
---|
[0b0520c] | 1789 | int grid_x = int(cx * HITTEST_SIZE / (GetXSize() + 1)); |
---|
| 1790 | int grid_y = int(cy * HITTEST_SIZE / (GetYSize() + 1)); |
---|
[33b2094] | 1791 | |
---|
[429465a] | 1792 | m_PointGrid[grid_x + grid_y * HITTEST_SIZE].push_back(label); |
---|
[33b2094] | 1793 | } |
---|
| 1794 | |
---|
[00a68e0] | 1795 | m_HitTestGridValid = true; |
---|
[33b2094] | 1796 | } |
---|
[c6d95d8] | 1797 | |
---|
[2a02de2] | 1798 | // |
---|
[5876fcb] | 1799 | // Methods for controlling the orientation of the survey |
---|
[2a02de2] | 1800 | // |
---|
| 1801 | |
---|
[5876fcb] | 1802 | void GfxCore::TurnCave(Double angle) |
---|
[156dc16] | 1803 | { |
---|
[5876fcb] | 1804 | // Turn the cave around its z-axis by a given angle. |
---|
[156dc16] | 1805 | |
---|
[5876fcb] | 1806 | m_PanAngle += angle; |
---|
[5a7597a] | 1807 | // Wrap to range [0, 360): |
---|
| 1808 | m_PanAngle = fmod(m_PanAngle, 360.0); |
---|
| 1809 | if (m_PanAngle < 0.0) { |
---|
[e577f89] | 1810 | m_PanAngle += 360.0; |
---|
[156dc16] | 1811 | } |
---|
[33b2094] | 1812 | |
---|
[00a68e0] | 1813 | m_HitTestGridValid = false; |
---|
[381ae6e] | 1814 | if (m_here && m_here == &temp_here) SetHere(); |
---|
[00a68e0] | 1815 | |
---|
[08253d9] | 1816 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[156dc16] | 1817 | } |
---|
| 1818 | |
---|
[5876fcb] | 1819 | void GfxCore::TurnCaveTo(Double angle) |
---|
[d80805e] | 1820 | { |
---|
[5455bb2] | 1821 | if (m_Rotating) { |
---|
| 1822 | // If we're rotating, jump to the specified angle. |
---|
| 1823 | TurnCave(angle - m_PanAngle); |
---|
| 1824 | SetPanBase(); |
---|
| 1825 | return; |
---|
| 1826 | } |
---|
| 1827 | |
---|
[3ddd351] | 1828 | int new_switching_to = ((int)angle) / 90 + NORTH; |
---|
| 1829 | if (new_switching_to == m_SwitchingTo) { |
---|
| 1830 | // A second order to switch takes us there right away |
---|
| 1831 | TurnCave(angle - m_PanAngle); |
---|
| 1832 | m_SwitchingTo = 0; |
---|
| 1833 | ForceRefresh(); |
---|
| 1834 | } else { |
---|
[5455bb2] | 1835 | SetPanBase(); |
---|
[3ddd351] | 1836 | m_SwitchingTo = new_switching_to; |
---|
| 1837 | } |
---|
[d80805e] | 1838 | } |
---|
| 1839 | |
---|
[5876fcb] | 1840 | void GfxCore::TiltCave(Double tilt_angle) |
---|
[156dc16] | 1841 | { |
---|
[5876fcb] | 1842 | // Tilt the cave by a given angle. |
---|
[e577f89] | 1843 | if (m_TiltAngle + tilt_angle > 90.0) { |
---|
[08253d9] | 1844 | m_TiltAngle = 90.0; |
---|
[e577f89] | 1845 | } else if (m_TiltAngle + tilt_angle < -90.0) { |
---|
[08253d9] | 1846 | m_TiltAngle = -90.0; |
---|
| 1847 | } else { |
---|
| 1848 | m_TiltAngle += tilt_angle; |
---|
[d80805e] | 1849 | } |
---|
| 1850 | |
---|
[00a68e0] | 1851 | m_HitTestGridValid = false; |
---|
[381ae6e] | 1852 | if (m_here && m_here == &temp_here) SetHere(); |
---|
[00a68e0] | 1853 | |
---|
[08253d9] | 1854 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[5ffa439] | 1855 | } |
---|
| 1856 | |
---|
[5876fcb] | 1857 | void GfxCore::TranslateCave(int dx, int dy) |
---|
[5ffa439] | 1858 | { |
---|
[33b2094] | 1859 | AddTranslationScreenCoordinates(dx, dy); |
---|
[00a68e0] | 1860 | m_HitTestGridValid = false; |
---|
| 1861 | |
---|
[381ae6e] | 1862 | if (m_here && m_here == &temp_here) SetHere(); |
---|
[c00c6713] | 1863 | |
---|
[33b2094] | 1864 | ForceRefresh(); |
---|
| 1865 | } |
---|
[5876fcb] | 1866 | |
---|
[33b2094] | 1867 | void GfxCore::DragFinished() |
---|
| 1868 | { |
---|
[76dd228] | 1869 | m_MouseOutsideCompass = m_MouseOutsideElev = false; |
---|
[5876fcb] | 1870 | ForceRefresh(); |
---|
[2173dbd] | 1871 | } |
---|
| 1872 | |
---|
[d877aa2] | 1873 | void GfxCore::ClearCoords() |
---|
| 1874 | { |
---|
| 1875 | m_Parent->ClearCoords(); |
---|
| 1876 | } |
---|
| 1877 | |
---|
[5876fcb] | 1878 | void GfxCore::SetCoords(wxPoint point) |
---|
[fd6e0d5] | 1879 | { |
---|
[0874c07e] | 1880 | // We can't work out 2D coordinates from a perspective view, and it |
---|
| 1881 | // doesn't really make sense to show coordinates while we're animating. |
---|
| 1882 | if (GetPerspective() || Animating()) return; |
---|
[0a811ab] | 1883 | |
---|
[5876fcb] | 1884 | // Update the coordinate or altitude display, given the (x, y) position in |
---|
| 1885 | // window coordinates. The relevant display is updated depending on |
---|
| 1886 | // whether we're in plan or elevation view. |
---|
| 1887 | |
---|
[f6d8375] | 1888 | double cx, cy, cz; |
---|
[5876fcb] | 1889 | |
---|
[a2b3d62] | 1890 | SetDataTransform(); |
---|
[90430f2] | 1891 | ReverseTransform(point.x, GetYSize() - 1 - point.y, &cx, &cy, &cz); |
---|
[5876fcb] | 1892 | |
---|
[0633bcc] | 1893 | if (ShowingPlan()) { |
---|
[d67450e] | 1894 | m_Parent->SetCoords(cx + m_Parent->GetOffset().GetX(), |
---|
[381ae6e] | 1895 | cy + m_Parent->GetOffset().GetY(), |
---|
| 1896 | m_there); |
---|
[0633bcc] | 1897 | } else if (ShowingElevation()) { |
---|
[381ae6e] | 1898 | m_Parent->SetAltitude(cz + m_Parent->GetOffset().GetZ(), |
---|
| 1899 | m_there); |
---|
[d479c15] | 1900 | } else { |
---|
[429465a] | 1901 | m_Parent->ClearCoords(); |
---|
[a2b3d62] | 1902 | } |
---|
[fd6e0d5] | 1903 | } |
---|
| 1904 | |
---|
[2a26b45] | 1905 | int GfxCore::GetCompassWidth() const |
---|
| 1906 | { |
---|
| 1907 | static int result = 0; |
---|
| 1908 | if (result == 0) { |
---|
| 1909 | result = INDICATOR_BOX_SIZE; |
---|
| 1910 | int width; |
---|
| 1911 | const wxString & msg = wmsg(/*Facing*/203); |
---|
| 1912 | GetTextExtent(msg, &width, NULL); |
---|
| 1913 | if (width > result) result = width; |
---|
| 1914 | } |
---|
| 1915 | return result; |
---|
| 1916 | } |
---|
| 1917 | |
---|
| 1918 | int GfxCore::GetClinoWidth() const |
---|
| 1919 | { |
---|
| 1920 | static int result = 0; |
---|
| 1921 | if (result == 0) { |
---|
| 1922 | result = INDICATOR_BOX_SIZE; |
---|
| 1923 | int width; |
---|
| 1924 | const wxString & msg1 = wmsg(/*Plan*/432); |
---|
| 1925 | GetTextExtent(msg1, &width, NULL); |
---|
| 1926 | if (width > result) result = width; |
---|
| 1927 | const wxString & msg2 = wmsg(/*Kiwi Plan*/433); |
---|
| 1928 | GetTextExtent(msg2, &width, NULL); |
---|
| 1929 | if (width > result) result = width; |
---|
| 1930 | const wxString & msg3 = wmsg(/*Elevation*/118); |
---|
| 1931 | GetTextExtent(msg3, &width, NULL); |
---|
| 1932 | if (width > result) result = width; |
---|
| 1933 | } |
---|
| 1934 | return result; |
---|
| 1935 | } |
---|
| 1936 | |
---|
[1eeb55a] | 1937 | int GfxCore::GetCompassXPosition() const |
---|
[1fd2edb] | 1938 | { |
---|
[f433fda] | 1939 | // Return the x-coordinate of the centre of the compass in window |
---|
| 1940 | // coordinates. |
---|
[2a26b45] | 1941 | return GetXSize() - INDICATOR_OFFSET_X - GetCompassWidth() / 2; |
---|
[1fd2edb] | 1942 | } |
---|
| 1943 | |
---|
[1eeb55a] | 1944 | int GfxCore::GetClinoXPosition() const |
---|
[1fd2edb] | 1945 | { |
---|
[f433fda] | 1946 | // Return the x-coordinate of the centre of the compass in window |
---|
| 1947 | // coordinates. |
---|
[2a26b45] | 1948 | return GetXSize() - GetClinoOffset() - GetClinoWidth() / 2; |
---|
[1fd2edb] | 1949 | } |
---|
| 1950 | |
---|
[1eeb55a] | 1951 | int GfxCore::GetIndicatorYPosition() const |
---|
[dfe4454c] | 1952 | { |
---|
[f433fda] | 1953 | // Return the y-coordinate of the centre of the indicators in window |
---|
| 1954 | // coordinates. |
---|
[90430f2] | 1955 | return GetYSize() - INDICATOR_OFFSET_Y - INDICATOR_BOX_SIZE / 2; |
---|
[5876fcb] | 1956 | } |
---|
[fa42426] | 1957 | |
---|
[1eeb55a] | 1958 | int GfxCore::GetIndicatorRadius() const |
---|
[5876fcb] | 1959 | { |
---|
| 1960 | // Return the radius of each indicator. |
---|
[1eeb55a] | 1961 | return (INDICATOR_BOX_SIZE - INDICATOR_MARGIN * 2) / 2; |
---|
[5876fcb] | 1962 | } |
---|
[dfe4454c] | 1963 | |
---|
[14acdae] | 1964 | bool GfxCore::PointWithinCompass(wxPoint point) const |
---|
[5876fcb] | 1965 | { |
---|
[f433fda] | 1966 | // Determine whether a point (in window coordinates) lies within the |
---|
| 1967 | // compass. |
---|
[e2c1671] | 1968 | if (!ShowingCompass()) return false; |
---|
| 1969 | |
---|
[33b2094] | 1970 | glaCoord dx = point.x - GetCompassXPosition(); |
---|
| 1971 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1972 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 1973 | |
---|
[5876fcb] | 1974 | return (dx * dx + dy * dy <= radius * radius); |
---|
| 1975 | } |
---|
[fa42426] | 1976 | |
---|
[14acdae] | 1977 | bool GfxCore::PointWithinClino(wxPoint point) const |
---|
[5876fcb] | 1978 | { |
---|
| 1979 | // Determine whether a point (in window coordinates) lies within the clino. |
---|
[e2c1671] | 1980 | if (!ShowingClino()) return false; |
---|
| 1981 | |
---|
[33b2094] | 1982 | glaCoord dx = point.x - GetClinoXPosition(); |
---|
| 1983 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1984 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 1985 | |
---|
[5876fcb] | 1986 | return (dx * dx + dy * dy <= radius * radius); |
---|
[dfe4454c] | 1987 | } |
---|
[8000d8f] | 1988 | |
---|
[14acdae] | 1989 | bool GfxCore::PointWithinScaleBar(wxPoint point) const |
---|
[5876fcb] | 1990 | { |
---|
[e2c1671] | 1991 | // Determine whether a point (in window coordinates) lies within the scale |
---|
| 1992 | // bar. |
---|
| 1993 | if (!ShowingScaleBar()) return false; |
---|
[8000d8f] | 1994 | |
---|
[e2c1671] | 1995 | return (point.x >= SCALE_BAR_OFFSET_X && |
---|
| 1996 | point.x <= SCALE_BAR_OFFSET_X + m_ScaleBarWidth && |
---|
[90430f2] | 1997 | point.y <= GetYSize() - SCALE_BAR_OFFSET_Y - SCALE_BAR_HEIGHT && |
---|
| 1998 | point.y >= GetYSize() - SCALE_BAR_OFFSET_Y - SCALE_BAR_HEIGHT*2); |
---|
[5876fcb] | 1999 | } |
---|
[8000d8f] | 2000 | |
---|
[d43fa84] | 2001 | bool GfxCore::PointWithinColourKey(wxPoint point) const |
---|
| 2002 | { |
---|
| 2003 | // Determine whether a point (in window coordinates) lies within the key. |
---|
[62da267] | 2004 | point.x -= GetXSize() - KEY_OFFSET_X; |
---|
| 2005 | point.y = KEY_OFFSET_Y - point.y; |
---|
[fcc3741] | 2006 | return (point.x >= key_lowerleft[m_ColourBy].x && point.x <= 0 && |
---|
| 2007 | point.y >= key_lowerleft[m_ColourBy].y && point.y <= 0); |
---|
[d43fa84] | 2008 | } |
---|
| 2009 | |
---|
[5876fcb] | 2010 | void GfxCore::SetCompassFromPoint(wxPoint point) |
---|
[8000d8f] | 2011 | { |
---|
[d877aa2] | 2012 | // Given a point in window coordinates, set the heading of the survey. If |
---|
| 2013 | // the point is outside the compass, it snaps to 45 degree intervals; |
---|
| 2014 | // otherwise it operates as normal. |
---|
[8000d8f] | 2015 | |
---|
[5876fcb] | 2016 | wxCoord dx = point.x - GetCompassXPosition(); |
---|
| 2017 | wxCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 2018 | wxCoord radius = GetIndicatorRadius(); |
---|
[7aa15c0] | 2019 | |
---|
[0580c6a] | 2020 | double angle = deg(atan2(double(dx), double(dy))) - 180.0; |
---|
[5876fcb] | 2021 | if (dx * dx + dy * dy <= radius * radius) { |
---|
[3ddd351] | 2022 | TurnCave(angle - m_PanAngle); |
---|
[429465a] | 2023 | m_MouseOutsideCompass = false; |
---|
[e577f89] | 2024 | } else { |
---|
[3ddd351] | 2025 | TurnCave(int(angle / 45.0) * 45.0 - m_PanAngle); |
---|
[429465a] | 2026 | m_MouseOutsideCompass = true; |
---|
[7aa15c0] | 2027 | } |
---|
[8000d8f] | 2028 | |
---|
[5876fcb] | 2029 | ForceRefresh(); |
---|
| 2030 | } |
---|
| 2031 | |
---|
| 2032 | void GfxCore::SetClinoFromPoint(wxPoint point) |
---|
| 2033 | { |
---|
[d877aa2] | 2034 | // Given a point in window coordinates, set the elevation of the survey. |
---|
| 2035 | // If the point is outside the clino, it snaps to 90 degree intervals; |
---|
| 2036 | // otherwise it operates as normal. |
---|
[8000d8f] | 2037 | |
---|
[33b2094] | 2038 | glaCoord dx = point.x - GetClinoXPosition(); |
---|
| 2039 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 2040 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 2041 | |
---|
[5876fcb] | 2042 | if (dx >= 0 && dx * dx + dy * dy <= radius * radius) { |
---|
[7a57dc7] | 2043 | TiltCave(-deg(atan2(double(dy), double(dx))) - m_TiltAngle); |
---|
[429465a] | 2044 | m_MouseOutsideElev = false; |
---|
[e577f89] | 2045 | } else if (dy >= INDICATOR_MARGIN) { |
---|
[7a57dc7] | 2046 | TiltCave(-90.0 - m_TiltAngle); |
---|
[429465a] | 2047 | m_MouseOutsideElev = true; |
---|
[e577f89] | 2048 | } else if (dy <= -INDICATOR_MARGIN) { |
---|
[7a57dc7] | 2049 | TiltCave(90.0 - m_TiltAngle); |
---|
[429465a] | 2050 | m_MouseOutsideElev = true; |
---|
[e577f89] | 2051 | } else { |
---|
[429465a] | 2052 | TiltCave(-m_TiltAngle); |
---|
| 2053 | m_MouseOutsideElev = true; |
---|
[5876fcb] | 2054 | } |
---|
[8000d8f] | 2055 | |
---|
[5876fcb] | 2056 | ForceRefresh(); |
---|
[8000d8f] | 2057 | } |
---|
| 2058 | |
---|
[5876fcb] | 2059 | void GfxCore::SetScaleBarFromOffset(wxCoord dx) |
---|
[8000d8f] | 2060 | { |
---|
[5876fcb] | 2061 | // Set the scale of the survey, given an offset as to how much the mouse has |
---|
| 2062 | // been dragged over the scalebar since the last scale change. |
---|
[8000d8f] | 2063 | |
---|
[5b7164d] | 2064 | SetScale((m_ScaleBarWidth + dx) * m_Scale / m_ScaleBarWidth); |
---|
[5876fcb] | 2065 | ForceRefresh(); |
---|
| 2066 | } |
---|
[8000d8f] | 2067 | |
---|
[5876fcb] | 2068 | void GfxCore::RedrawIndicators() |
---|
| 2069 | { |
---|
| 2070 | // Redraw the compass and clino indicators. |
---|
[8000d8f] | 2071 | |
---|
[2a26b45] | 2072 | int total_width = GetCompassWidth() + INDICATOR_GAP + GetClinoWidth(); |
---|
| 2073 | RefreshRect(wxRect(GetXSize() - INDICATOR_OFFSET_X - total_width, |
---|
[e24b7fb] | 2074 | GetYSize() - INDICATOR_OFFSET_Y - INDICATOR_BOX_SIZE, |
---|
[2a26b45] | 2075 | total_width, |
---|
[e24b7fb] | 2076 | INDICATOR_BOX_SIZE), false); |
---|
[8000d8f] | 2077 | } |
---|
| 2078 | |
---|
[5876fcb] | 2079 | void GfxCore::StartRotation() |
---|
[8000d8f] | 2080 | { |
---|
[5876fcb] | 2081 | // Start the survey rotating. |
---|
[f433fda] | 2082 | |
---|
[5455bb2] | 2083 | if (m_SwitchingTo >= NORTH) |
---|
| 2084 | m_SwitchingTo = 0; |
---|
[5876fcb] | 2085 | m_Rotating = true; |
---|
[5455bb2] | 2086 | SetPanBase(); |
---|
[5876fcb] | 2087 | } |
---|
[8000d8f] | 2088 | |
---|
[5876fcb] | 2089 | void GfxCore::ToggleRotation() |
---|
| 2090 | { |
---|
| 2091 | // Toggle the survey rotation on/off. |
---|
[f433fda] | 2092 | |
---|
[5876fcb] | 2093 | if (m_Rotating) { |
---|
[2a3d328] | 2094 | StopRotation(); |
---|
| 2095 | } else { |
---|
| 2096 | StartRotation(); |
---|
[5876fcb] | 2097 | } |
---|
| 2098 | } |
---|
[8000d8f] | 2099 | |
---|
[5876fcb] | 2100 | void GfxCore::StopRotation() |
---|
| 2101 | { |
---|
| 2102 | // Stop the survey rotating. |
---|
[8000d8f] | 2103 | |
---|
[5876fcb] | 2104 | m_Rotating = false; |
---|
[33b2094] | 2105 | ForceRefresh(); |
---|
[5876fcb] | 2106 | } |
---|
[8000d8f] | 2107 | |
---|
[eef68f9] | 2108 | bool GfxCore::IsExtendedElevation() const |
---|
[5876fcb] | 2109 | { |
---|
[eef68f9] | 2110 | return m_Parent->IsExtendedElevation(); |
---|
[5876fcb] | 2111 | } |
---|
[8000d8f] | 2112 | |
---|
[5876fcb] | 2113 | void GfxCore::ReverseRotation() |
---|
| 2114 | { |
---|
| 2115 | // Reverse the direction of rotation. |
---|
[8000d8f] | 2116 | |
---|
[5876fcb] | 2117 | m_RotationStep = -m_RotationStep; |
---|
[5455bb2] | 2118 | if (m_Rotating) |
---|
| 2119 | SetPanBase(); |
---|
[5876fcb] | 2120 | } |
---|
[8000d8f] | 2121 | |
---|
[5876fcb] | 2122 | void GfxCore::RotateSlower(bool accel) |
---|
| 2123 | { |
---|
| 2124 | // Decrease the speed of rotation, optionally by an increased amount. |
---|
[5455bb2] | 2125 | if (fabs(m_RotationStep) == 1.0) |
---|
| 2126 | return; |
---|
[8000d8f] | 2127 | |
---|
[5455bb2] | 2128 | m_RotationStep *= accel ? (1 / 1.44) : (1 / 1.2); |
---|
| 2129 | |
---|
| 2130 | if (fabs(m_RotationStep) < 1.0) { |
---|
| 2131 | m_RotationStep = (m_RotationStep > 0 ? 1.0 : -1.0); |
---|
[1690fa9] | 2132 | } |
---|
[5455bb2] | 2133 | if (m_Rotating) |
---|
| 2134 | SetPanBase(); |
---|
[8000d8f] | 2135 | } |
---|
| 2136 | |
---|
[5876fcb] | 2137 | void GfxCore::RotateFaster(bool accel) |
---|
| 2138 | { |
---|
| 2139 | // Increase the speed of rotation, optionally by an increased amount. |
---|
[5455bb2] | 2140 | if (fabs(m_RotationStep) == 180.0) |
---|
| 2141 | return; |
---|
[5876fcb] | 2142 | |
---|
| 2143 | m_RotationStep *= accel ? 1.44 : 1.2; |
---|
[5455bb2] | 2144 | if (fabs(m_RotationStep) > 180.0) { |
---|
| 2145 | m_RotationStep = (m_RotationStep > 0 ? 180.0 : -180.0); |
---|
[1690fa9] | 2146 | } |
---|
[5455bb2] | 2147 | if (m_Rotating) |
---|
| 2148 | SetPanBase(); |
---|
[5876fcb] | 2149 | } |
---|
[8000d8f] | 2150 | |
---|
[5876fcb] | 2151 | void GfxCore::SwitchToElevation() |
---|
[8000d8f] | 2152 | { |
---|
[5876fcb] | 2153 | // Perform an animated switch to elevation view. |
---|
[8000d8f] | 2154 | |
---|
[5455bb2] | 2155 | if (m_SwitchingTo != ELEVATION) { |
---|
| 2156 | SetTiltBase(); |
---|
| 2157 | m_SwitchingTo = ELEVATION; |
---|
| 2158 | } else { |
---|
| 2159 | // A second order to switch takes us there right away |
---|
| 2160 | TiltCave(-m_TiltAngle); |
---|
| 2161 | m_SwitchingTo = 0; |
---|
| 2162 | ForceRefresh(); |
---|
[5876fcb] | 2163 | } |
---|
[8000d8f] | 2164 | } |
---|
| 2165 | |
---|
[5876fcb] | 2166 | void GfxCore::SwitchToPlan() |
---|
[8000d8f] | 2167 | { |
---|
[5876fcb] | 2168 | // Perform an animated switch to plan view. |
---|
[8000d8f] | 2169 | |
---|
[5455bb2] | 2170 | if (m_SwitchingTo != PLAN) { |
---|
| 2171 | SetTiltBase(); |
---|
| 2172 | m_SwitchingTo = PLAN; |
---|
| 2173 | } else { |
---|
| 2174 | // A second order to switch takes us there right away |
---|
| 2175 | TiltCave(-90.0 - m_TiltAngle); |
---|
| 2176 | m_SwitchingTo = 0; |
---|
| 2177 | ForceRefresh(); |
---|
[8000d8f] | 2178 | } |
---|
[5876fcb] | 2179 | } |
---|
[8000d8f] | 2180 | |
---|
[d1628e8e] | 2181 | void GfxCore::SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax) |
---|
| 2182 | { |
---|
| 2183 | |
---|
| 2184 | SetTranslation(-Vector3((xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2)); |
---|
[d0f5918] | 2185 | Double scale = HUGE_VAL; |
---|
[d1628e8e] | 2186 | const Vector3 ext = m_Parent->GetExtent(); |
---|
| 2187 | if (xmax > xmin) { |
---|
| 2188 | Double s = ext.GetX() / (xmax - xmin); |
---|
| 2189 | if (s < scale) scale = s; |
---|
| 2190 | } |
---|
| 2191 | if (ymax > ymin) { |
---|
| 2192 | Double s = ext.GetY() / (ymax - ymin); |
---|
| 2193 | if (s < scale) scale = s; |
---|
| 2194 | } |
---|
| 2195 | if (!ShowingPlan() && zmax > zmin) { |
---|
| 2196 | Double s = ext.GetZ() / (zmax - zmin); |
---|
| 2197 | if (s < scale) scale = s; |
---|
| 2198 | } |
---|
[d0f5918] | 2199 | if (scale != HUGE_VAL) SetScale(scale); |
---|
[d1628e8e] | 2200 | ForceRefresh(); |
---|
| 2201 | } |
---|
| 2202 | |
---|
[14acdae] | 2203 | bool GfxCore::CanRaiseViewpoint() const |
---|
[5876fcb] | 2204 | { |
---|
| 2205 | // Determine if the survey can be viewed from a higher angle of elevation. |
---|
[f433fda] | 2206 | |
---|
[7a57dc7] | 2207 | return GetPerspective() ? (m_TiltAngle < 90.0) : (m_TiltAngle > -90.0); |
---|
[8000d8f] | 2208 | } |
---|
| 2209 | |
---|
[14acdae] | 2210 | bool GfxCore::CanLowerViewpoint() const |
---|
[2effbf1] | 2211 | { |
---|
[5876fcb] | 2212 | // Determine if the survey can be viewed from a lower angle of elevation. |
---|
[2effbf1] | 2213 | |
---|
[7a57dc7] | 2214 | return GetPerspective() ? (m_TiltAngle > -90.0) : (m_TiltAngle < 90.0); |
---|
[5876fcb] | 2215 | } |
---|
[2effbf1] | 2216 | |
---|
[78c67a6] | 2217 | bool GfxCore::HasDepth() const |
---|
[bd21214] | 2218 | { |
---|
[78c67a6] | 2219 | return m_Parent->GetDepthExtent() == 0.0; |
---|
[bd21214] | 2220 | } |
---|
| 2221 | |
---|
[843ee7b] | 2222 | bool GfxCore::HasErrorInformation() const |
---|
[d4650b3] | 2223 | { |
---|
[843ee7b] | 2224 | return m_Parent->HasErrorInformation(); |
---|
[d4650b3] | 2225 | } |
---|
| 2226 | |
---|
[843ee7b] | 2227 | bool GfxCore::HasDateInformation() const |
---|
[c61aa79] | 2228 | { |
---|
[843ee7b] | 2229 | return m_Parent->GetDateMin() >= 0; |
---|
[c61aa79] | 2230 | } |
---|
| 2231 | |
---|
[14acdae] | 2232 | bool GfxCore::ShowingPlan() const |
---|
[5876fcb] | 2233 | { |
---|
| 2234 | // Determine if the survey is in plan view. |
---|
[f433fda] | 2235 | |
---|
[7a57dc7] | 2236 | return (m_TiltAngle == -90.0); |
---|
[2effbf1] | 2237 | } |
---|
| 2238 | |
---|
[14acdae] | 2239 | bool GfxCore::ShowingElevation() const |
---|
[8000d8f] | 2240 | { |
---|
[5876fcb] | 2241 | // Determine if the survey is in elevation view. |
---|
[f433fda] | 2242 | |
---|
[5876fcb] | 2243 | return (m_TiltAngle == 0.0); |
---|
[8000d8f] | 2244 | } |
---|
| 2245 | |
---|
[14acdae] | 2246 | bool GfxCore::ShowingMeasuringLine() const |
---|
[8000d8f] | 2247 | { |
---|
[0afefe6] | 2248 | // Determine if the measuring line is being shown. Only check if "there" |
---|
| 2249 | // is valid, since that means the measuring line anchor is out. |
---|
[f433fda] | 2250 | |
---|
[381ae6e] | 2251 | return m_there; |
---|
[8000d8f] | 2252 | } |
---|
| 2253 | |
---|
[eff44b9] | 2254 | void GfxCore::ToggleFlag(bool* flag, int update) |
---|
[5876fcb] | 2255 | { |
---|
| 2256 | *flag = !*flag; |
---|
[6747314] | 2257 | if (update == UPDATE_BLOBS) { |
---|
[eff44b9] | 2258 | UpdateBlobs(); |
---|
[ef1870d] | 2259 | } else if (update == UPDATE_BLOBS_AND_CROSSES) { |
---|
| 2260 | UpdateBlobs(); |
---|
| 2261 | InvalidateList(LIST_CROSSES); |
---|
[de43be7] | 2262 | m_HitTestGridValid = false; |
---|
[6cd6bbe] | 2263 | } |
---|
[eff44b9] | 2264 | ForceRefresh(); |
---|
[5876fcb] | 2265 | } |
---|
[93744a5] | 2266 | |
---|
[14acdae] | 2267 | int GfxCore::GetNumEntrances() const |
---|
[4b1fc48] | 2268 | { |
---|
[5876fcb] | 2269 | return m_Parent->GetNumEntrances(); |
---|
| 2270 | } |
---|
[bd7a61b] | 2271 | |
---|
[14acdae] | 2272 | int GfxCore::GetNumFixedPts() const |
---|
[5876fcb] | 2273 | { |
---|
| 2274 | return m_Parent->GetNumFixedPts(); |
---|
| 2275 | } |
---|
[7757a4ed] | 2276 | |
---|
[14acdae] | 2277 | int GfxCore::GetNumExportedPts() const |
---|
[5876fcb] | 2278 | { |
---|
| 2279 | return m_Parent->GetNumExportedPts(); |
---|
| 2280 | } |
---|
| 2281 | |
---|
[622460e] | 2282 | void GfxCore::ToggleTerrain() |
---|
| 2283 | { |
---|
| 2284 | ToggleFlag(&m_Terrain); |
---|
| 2285 | if (m_Terrain && !dem) { |
---|
| 2286 | wxCommandEvent dummy; |
---|
| 2287 | m_Parent->OnOpenTerrain(dummy); |
---|
| 2288 | } |
---|
| 2289 | } |
---|
| 2290 | |
---|
[d96c95c] | 2291 | void GfxCore::ToggleFatFinger() |
---|
| 2292 | { |
---|
| 2293 | if (sqrd_measure_threshold == sqrd(MEASURE_THRESHOLD)) { |
---|
| 2294 | sqrd_measure_threshold = sqrd(5 * MEASURE_THRESHOLD); |
---|
[7b9b700] | 2295 | wxMessageBox(wxT("Fat finger enabled"), wxT("Aven Debug"), wxOK | wxICON_INFORMATION); |
---|
[d96c95c] | 2296 | } else { |
---|
| 2297 | sqrd_measure_threshold = sqrd(MEASURE_THRESHOLD); |
---|
[7b9b700] | 2298 | wxMessageBox(wxT("Fat finger disabled"), wxT("Aven Debug"), wxOK | wxICON_INFORMATION); |
---|
[d96c95c] | 2299 | } |
---|
| 2300 | } |
---|
| 2301 | |
---|
[5876fcb] | 2302 | void GfxCore::ClearTreeSelection() |
---|
| 2303 | { |
---|
| 2304 | m_Parent->ClearTreeSelection(); |
---|
| 2305 | } |
---|
| 2306 | |
---|
[82c3731] | 2307 | void GfxCore::CentreOn(const Point &p) |
---|
[5876fcb] | 2308 | { |
---|
[d67450e] | 2309 | SetTranslation(-p); |
---|
[00a68e0] | 2310 | m_HitTestGridValid = false; |
---|
[f433fda] | 2311 | |
---|
[5876fcb] | 2312 | ForceRefresh(); |
---|
[4b1fc48] | 2313 | } |
---|
[5876fcb] | 2314 | |
---|
[33b2094] | 2315 | void GfxCore::ForceRefresh() |
---|
| 2316 | { |
---|
| 2317 | Refresh(false); |
---|
| 2318 | } |
---|
| 2319 | |
---|
[d2fcc9b] | 2320 | void GfxCore::GenerateList(unsigned int l) |
---|
[33b2094] | 2321 | { |
---|
[9eb58d0] | 2322 | assert(m_HaveData); |
---|
[3ddcad8] | 2323 | |
---|
[d2fcc9b] | 2324 | switch (l) { |
---|
[fe665c4] | 2325 | case LIST_COMPASS: |
---|
| 2326 | DrawCompass(); |
---|
| 2327 | break; |
---|
| 2328 | case LIST_CLINO: |
---|
| 2329 | DrawClino(); |
---|
| 2330 | break; |
---|
| 2331 | case LIST_CLINO_BACK: |
---|
| 2332 | DrawClinoBack(); |
---|
| 2333 | break; |
---|
[9c37beb] | 2334 | case LIST_SCALE_BAR: |
---|
| 2335 | DrawScaleBar(); |
---|
| 2336 | break; |
---|
[e2ea75a] | 2337 | case LIST_DEPTH_KEY: |
---|
| 2338 | DrawDepthKey(); |
---|
[252d759] | 2339 | break; |
---|
[e2ea75a] | 2340 | case LIST_DATE_KEY: |
---|
| 2341 | DrawDateKey(); |
---|
[d4650b3] | 2342 | break; |
---|
[e2ea75a] | 2343 | case LIST_ERROR_KEY: |
---|
| 2344 | DrawErrorKey(); |
---|
[c61aa79] | 2345 | break; |
---|
[cc9e2c65] | 2346 | case LIST_GRADIENT_KEY: |
---|
| 2347 | DrawGradientKey(); |
---|
| 2348 | break; |
---|
[af50685] | 2349 | case LIST_LENGTH_KEY: |
---|
| 2350 | DrawLengthKey(); |
---|
| 2351 | break; |
---|
[d2fcc9b] | 2352 | case LIST_UNDERGROUND_LEGS: |
---|
| 2353 | GenerateDisplayList(); |
---|
| 2354 | break; |
---|
| 2355 | case LIST_TUBES: |
---|
| 2356 | GenerateDisplayListTubes(); |
---|
| 2357 | break; |
---|
| 2358 | case LIST_SURFACE_LEGS: |
---|
| 2359 | GenerateDisplayListSurface(); |
---|
| 2360 | break; |
---|
[86fe6e4] | 2361 | case LIST_BLOBS: |
---|
| 2362 | GenerateBlobsDisplayList(); |
---|
[37d7084] | 2363 | break; |
---|
[86fe6e4] | 2364 | case LIST_CROSSES: { |
---|
| 2365 | BeginCrosses(); |
---|
| 2366 | SetColour(col_LIGHT_GREY); |
---|
| 2367 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 2368 | while (pos != m_Parent->GetLabelsEnd()) { |
---|
| 2369 | const LabelInfo* label = *pos++; |
---|
| 2370 | |
---|
| 2371 | if ((m_Surface && label->IsSurface()) || |
---|
| 2372 | (m_Legs && label->IsUnderground()) || |
---|
| 2373 | (!label->IsSurface() && !label->IsUnderground())) { |
---|
| 2374 | // Check if this station should be displayed |
---|
| 2375 | // (last case is for stns with no legs attached) |
---|
| 2376 | DrawCross(label->GetX(), label->GetY(), label->GetZ()); |
---|
| 2377 | } |
---|
| 2378 | } |
---|
| 2379 | EndCrosses(); |
---|
| 2380 | break; |
---|
| 2381 | } |
---|
[37d7084] | 2382 | case LIST_GRID: |
---|
| 2383 | DrawGrid(); |
---|
[d2fcc9b] | 2384 | break; |
---|
[86fe6e4] | 2385 | case LIST_SHADOW: |
---|
| 2386 | GenerateDisplayListShadow(); |
---|
[d2fcc9b] | 2387 | break; |
---|
[6388423] | 2388 | case LIST_TERRAIN: |
---|
| 2389 | DrawTerrain(); |
---|
[22b0a8f] | 2390 | break; |
---|
[d2fcc9b] | 2391 | default: |
---|
| 2392 | assert(false); |
---|
| 2393 | break; |
---|
| 2394 | } |
---|
| 2395 | } |
---|
| 2396 | |
---|
[d67450e] | 2397 | void GfxCore::ToggleSmoothShading() |
---|
| 2398 | { |
---|
| 2399 | GLACanvas::ToggleSmoothShading(); |
---|
| 2400 | InvalidateList(LIST_TUBES); |
---|
| 2401 | ForceRefresh(); |
---|
| 2402 | } |
---|
| 2403 | |
---|
[d2fcc9b] | 2404 | void GfxCore::GenerateDisplayList() |
---|
| 2405 | { |
---|
| 2406 | // Generate the display list for the underground legs. |
---|
[c61aa79] | 2407 | list<traverse>::const_iterator trav = m_Parent->traverses_begin(); |
---|
| 2408 | list<traverse>::const_iterator tend = m_Parent->traverses_end(); |
---|
[8666fc7] | 2409 | |
---|
[ad661cc] | 2410 | if (m_Splays == SPLAYS_SHOW_FADED) { |
---|
[bd77a6a] | 2411 | SetAlpha(0.4); |
---|
[ad661cc] | 2412 | while (trav != tend) { |
---|
| 2413 | if ((*trav).isSplay) |
---|
| 2414 | (this->*AddPoly)(*trav); |
---|
| 2415 | ++trav; |
---|
| 2416 | } |
---|
[4a1cede] | 2417 | SetAlpha(1.0); |
---|
[ad661cc] | 2418 | trav = m_Parent->traverses_begin(); |
---|
[8666fc7] | 2419 | } |
---|
| 2420 | |
---|
[3ddcad8] | 2421 | while (trav != tend) { |
---|
[ad661cc] | 2422 | if (m_Splays == SPLAYS_SHOW_NORMAL || !(*trav).isSplay) |
---|
[8666fc7] | 2423 | (this->*AddPoly)(*trav); |
---|
[3ddcad8] | 2424 | ++trav; |
---|
| 2425 | } |
---|
[33b2094] | 2426 | } |
---|
| 2427 | |
---|
[9eb58d0] | 2428 | void GfxCore::GenerateDisplayListTubes() |
---|
[33b2094] | 2429 | { |
---|
[9eb58d0] | 2430 | // Generate the display list for the tubes. |
---|
[fc68ad5] | 2431 | list<vector<XSect> >::iterator trav = m_Parent->tubes_begin(); |
---|
| 2432 | list<vector<XSect> >::iterator tend = m_Parent->tubes_end(); |
---|
[3ddcad8] | 2433 | while (trav != tend) { |
---|
| 2434 | SkinPassage(*trav); |
---|
| 2435 | ++trav; |
---|
| 2436 | } |
---|
[9eb58d0] | 2437 | } |
---|
[33b2094] | 2438 | |
---|
[9eb58d0] | 2439 | void GfxCore::GenerateDisplayListSurface() |
---|
| 2440 | { |
---|
| 2441 | // Generate the display list for the surface legs. |
---|
[3ddcad8] | 2442 | EnableDashedLines(); |
---|
[c61aa79] | 2443 | list<traverse>::const_iterator trav = m_Parent->surface_traverses_begin(); |
---|
| 2444 | list<traverse>::const_iterator tend = m_Parent->surface_traverses_end(); |
---|
[3ddcad8] | 2445 | while (trav != tend) { |
---|
[c61aa79] | 2446 | if (m_ColourBy == COLOUR_BY_ERROR) { |
---|
| 2447 | AddPolylineError(*trav); |
---|
| 2448 | } else { |
---|
| 2449 | AddPolyline(*trav); |
---|
| 2450 | } |
---|
[3ddcad8] | 2451 | ++trav; |
---|
| 2452 | } |
---|
| 2453 | DisableDashedLines(); |
---|
[d9b3270] | 2454 | } |
---|
[33b2094] | 2455 | |
---|
[37d7084] | 2456 | void GfxCore::GenerateDisplayListShadow() |
---|
[f4c5932] | 2457 | { |
---|
| 2458 | SetColour(col_BLACK); |
---|
[c61aa79] | 2459 | list<traverse>::const_iterator trav = m_Parent->traverses_begin(); |
---|
| 2460 | list<traverse>::const_iterator tend = m_Parent->traverses_end(); |
---|
[f4c5932] | 2461 | while (trav != tend) { |
---|
| 2462 | AddPolylineShadow(*trav); |
---|
| 2463 | ++trav; |
---|
| 2464 | } |
---|
| 2465 | } |
---|
| 2466 | |
---|
[112f80c] | 2467 | void |
---|
| 2468 | GfxCore::parse_hgt_filename(const wxString & lc_name) |
---|
| 2469 | { |
---|
| 2470 | char * leaf = leaf_from_fnm(lc_name.mb_str()); |
---|
| 2471 | const char * p = leaf; |
---|
| 2472 | char * q; |
---|
| 2473 | char dirn = *p++; |
---|
| 2474 | o_y = strtoul(p, &q, 10); |
---|
| 2475 | p = q; |
---|
| 2476 | if (dirn == 's') |
---|
| 2477 | o_y = -o_y; |
---|
| 2478 | ++o_y; |
---|
| 2479 | dirn = *p++; |
---|
| 2480 | o_x = strtoul(p, &q, 10); |
---|
| 2481 | if (dirn == 'w') |
---|
| 2482 | o_x = -o_x; |
---|
| 2483 | bigendian = true; |
---|
| 2484 | nodata_value = -32768; |
---|
| 2485 | osfree(leaf); |
---|
| 2486 | } |
---|
| 2487 | |
---|
| 2488 | size_t |
---|
| 2489 | GfxCore::parse_hdr(wxInputStream & is, unsigned long & skipbytes) |
---|
| 2490 | { |
---|
| 2491 | unsigned long nbits; |
---|
| 2492 | while (!is.Eof()) { |
---|
| 2493 | wxString line; |
---|
| 2494 | int ch; |
---|
| 2495 | while ((ch = is.GetC()) != wxEOF) { |
---|
| 2496 | if (ch == '\n' || ch == '\r') break; |
---|
| 2497 | line += wxChar(ch); |
---|
| 2498 | } |
---|
[6388423] | 2499 | #define CHECK(X, COND) \ |
---|
[1c55fb5] | 2500 | } else if (line.StartsWith(wxT(X " "))) { \ |
---|
[6388423] | 2501 | size_t v = line.find_first_not_of(wxT(' '), sizeof(X)); \ |
---|
| 2502 | if (v == line.npos || !(COND)) { \ |
---|
[1c55fb5] | 2503 | err += wxT("Unexpected value for " X); \ |
---|
[5314a0e] | 2504 | } |
---|
[112f80c] | 2505 | wxString err; |
---|
| 2506 | unsigned long dummy; |
---|
| 2507 | if (false) { |
---|
| 2508 | // I = little-endian; M = big-endian |
---|
| 2509 | CHECK("BYTEORDER", (bigendian = (line[v] == 'M')) || line[v] == 'I') |
---|
| 2510 | CHECK("LAYOUT", line.substr(v) == wxT("BIL")) |
---|
| 2511 | CHECK("NROWS", line.substr(v).ToCULong(&dem_width)) |
---|
| 2512 | CHECK("NCOLS", line.substr(v).ToCULong(&dem_height)) |
---|
| 2513 | CHECK("NBANDS", line.substr(v).ToCULong(&dummy) && dummy == 1) |
---|
| 2514 | CHECK("NBITS", line.substr(v).ToCULong(&nbits) && nbits == 16) |
---|
| 2515 | //: BANDROWBYTES 7202 |
---|
| 2516 | //: TOTALROWBYTES 7202 |
---|
| 2517 | // PIXELTYPE is a GDAL extension, so may not be present. |
---|
| 2518 | CHECK("PIXELTYPE", line.substr(v) == wxT("SIGNEDINT")) |
---|
| 2519 | CHECK("ULXMAP", line.substr(v).ToCDouble(&o_x)) |
---|
| 2520 | CHECK("ULYMAP", line.substr(v).ToCDouble(&o_y)) |
---|
| 2521 | CHECK("XDIM", line.substr(v).ToCDouble(&step_x)) |
---|
| 2522 | CHECK("YDIM", line.substr(v).ToCDouble(&step_y)) |
---|
| 2523 | CHECK("NODATA", line.substr(v).ToCLong(&nodata_value)) |
---|
| 2524 | CHECK("SKIPBYTES", line.substr(v).ToCULong(&skipbytes)) |
---|
| 2525 | } |
---|
| 2526 | if (!err.empty()) { |
---|
| 2527 | wxMessageBox(err); |
---|
[6388423] | 2528 | } |
---|
[c2fa50c] | 2529 | } |
---|
[112f80c] | 2530 | return ((nbits + 7) / 8) * dem_width * dem_height; |
---|
| 2531 | } |
---|
[c2fa50c] | 2532 | |
---|
[112f80c] | 2533 | bool |
---|
| 2534 | GfxCore::read_bil(wxInputStream & is, size_t size, unsigned long skipbytes) |
---|
| 2535 | { |
---|
| 2536 | bool know_size = true; |
---|
| 2537 | if (!size) { |
---|
| 2538 | // If the stream doesn't know its size, GetSize() returns 0. |
---|
| 2539 | size = is.GetSize(); |
---|
| 2540 | if (!size) { |
---|
| 2541 | size = DEFAULT_HGT_SIZE; |
---|
| 2542 | know_size = false; |
---|
| 2543 | } |
---|
[c2fa50c] | 2544 | } |
---|
| 2545 | dem = new unsigned short[size / 2]; |
---|
| 2546 | if (skipbytes) { |
---|
[112f80c] | 2547 | if (is.SeekI(skipbytes, wxFromStart) == ::wxInvalidOffset) { |
---|
[c2fa50c] | 2548 | while (skipbytes) { |
---|
| 2549 | unsigned long to_read = skipbytes; |
---|
| 2550 | if (size < to_read) to_read = size; |
---|
[112f80c] | 2551 | is.Read(reinterpret_cast<char *>(dem), to_read); |
---|
| 2552 | size_t c = is.LastRead(); |
---|
[c2fa50c] | 2553 | if (c == 0) { |
---|
| 2554 | wxMessageBox(wxT("Failed to skip terrain data header")); |
---|
| 2555 | break; |
---|
[bfb3ab0] | 2556 | } |
---|
[c2fa50c] | 2557 | skipbytes -= c; |
---|
[bfb3ab0] | 2558 | } |
---|
[5314a0e] | 2559 | } |
---|
[c2fa50c] | 2560 | } |
---|
[bfb3ab0] | 2561 | |
---|
[6388423] | 2562 | #if wxCHECK_VERSION(2,9,5) |
---|
[112f80c] | 2563 | if (!is.ReadAll(dem, size)) { |
---|
| 2564 | if (know_size) { |
---|
| 2565 | // FIXME: On __WXMSW__ currently we fail to |
---|
| 2566 | // read any data from files in zips. |
---|
| 2567 | delete [] dem; |
---|
| 2568 | dem = NULL; |
---|
| 2569 | wxMessageBox(wxT("Failed to read terrain data")); |
---|
| 2570 | return false; |
---|
[c2fa50c] | 2571 | } |
---|
[112f80c] | 2572 | size = is.LastRead(); |
---|
[c2fa50c] | 2573 | } |
---|
| 2574 | #else |
---|
| 2575 | char * p = reinterpret_cast<char *>(dem); |
---|
| 2576 | while (size) { |
---|
[112f80c] | 2577 | is.Read(p, size); |
---|
| 2578 | size_t c = is.LastRead(); |
---|
[c2fa50c] | 2579 | if (c == 0) { |
---|
[112f80c] | 2580 | if (!know_size) { |
---|
[c2fa50c] | 2581 | size = DEFAULT_HGT_SIZE - size; |
---|
[112f80c] | 2582 | if (size) |
---|
[c2fa50c] | 2583 | break; |
---|
[9df33bc] | 2584 | } |
---|
[112f80c] | 2585 | delete [] dem; |
---|
| 2586 | dem = NULL; |
---|
[5314a0e] | 2587 | wxMessageBox(wxT("Failed to read terrain data")); |
---|
[f60efe4] | 2588 | return false; |
---|
[6388423] | 2589 | } |
---|
[c2fa50c] | 2590 | p += c; |
---|
| 2591 | size -= c; |
---|
| 2592 | } |
---|
[5314a0e] | 2593 | #endif |
---|
[112f80c] | 2594 | |
---|
| 2595 | if (dem_width == 0 && dem_height == 0) { |
---|
| 2596 | dem_width = dem_height = sqrt(size / 2); |
---|
| 2597 | if (dem_width * dem_height * 2 != size) { |
---|
| 2598 | delete [] dem; |
---|
| 2599 | dem = NULL; |
---|
| 2600 | wxMessageBox(wxT("HGT format data doesn't form a square")); |
---|
| 2601 | return false; |
---|
| 2602 | } |
---|
| 2603 | step_x = step_y = 1.0 / dem_width; |
---|
| 2604 | } |
---|
| 2605 | |
---|
| 2606 | return true; |
---|
| 2607 | } |
---|
| 2608 | |
---|
| 2609 | bool GfxCore::LoadDEM(const wxString & file) |
---|
| 2610 | { |
---|
| 2611 | if (m_Parent->m_cs_proj.empty()) { |
---|
| 2612 | wxMessageBox(wxT("No coordinate system specified in survey data")); |
---|
| 2613 | return false; |
---|
| 2614 | } |
---|
| 2615 | |
---|
| 2616 | delete [] dem; |
---|
| 2617 | dem = NULL; |
---|
| 2618 | |
---|
| 2619 | size_t size = 0; |
---|
| 2620 | // Default is to not skip any bytes. |
---|
| 2621 | unsigned long skipbytes = 0; |
---|
| 2622 | // For .hgt files, default to using filesize to determine. |
---|
| 2623 | dem_width = dem_height = 0; |
---|
| 2624 | // ESRI say "The default byte order is the same as that of the host machine |
---|
| 2625 | // executing the software", but that's stupid so we default to |
---|
| 2626 | // little-endian. |
---|
| 2627 | bigendian = false; |
---|
| 2628 | |
---|
[522fb4c] | 2629 | wxFileInputStream fs(file); |
---|
| 2630 | if (!fs.IsOk()) { |
---|
[112f80c] | 2631 | wxMessageBox(wxT("Failed to open DEM file")); |
---|
| 2632 | return false; |
---|
[6388423] | 2633 | } |
---|
[c2fa50c] | 2634 | |
---|
[112f80c] | 2635 | const wxString & lc_file = file.Lower(); |
---|
| 2636 | if (lc_file.EndsWith(wxT(".hgt"))) { |
---|
| 2637 | parse_hgt_filename(lc_file); |
---|
| 2638 | read_bil(fs, size, skipbytes); |
---|
| 2639 | } else if (lc_file.EndsWith(wxT(".bil"))) { |
---|
| 2640 | wxString hdr_file = file; |
---|
| 2641 | hdr_file.replace(file.size() - 4, 4, wxT(".hdr")); |
---|
[522fb4c] | 2642 | wxFileInputStream hdr_is(hdr_file); |
---|
| 2643 | if (!hdr_is.IsOk()) { |
---|
[112f80c] | 2644 | wxMessageBox(wxT("Failed to open HDR file '") + hdr_file + wxT("'")); |
---|
| 2645 | return false; |
---|
| 2646 | } |
---|
| 2647 | size = parse_hdr(hdr_is, skipbytes); |
---|
| 2648 | read_bil(fs, size, skipbytes); |
---|
| 2649 | } else if (lc_file.EndsWith(wxT(".zip"))) { |
---|
| 2650 | wxZipEntry * ze_data = NULL; |
---|
| 2651 | wxZipInputStream zs(fs); |
---|
| 2652 | wxZipEntry * ze; |
---|
| 2653 | while ((ze = zs.GetNextEntry()) != NULL) { |
---|
| 2654 | if (!ze->IsDir()) { |
---|
| 2655 | const wxString & lc_name = ze->GetName().Lower(); |
---|
| 2656 | if (!ze_data && lc_name.EndsWith(wxT(".hgt"))) { |
---|
| 2657 | // SRTM .hgt files are raw binary data, with the filename |
---|
| 2658 | // encoding the coordinates. |
---|
| 2659 | parse_hgt_filename(lc_name); |
---|
| 2660 | read_bil(zs, size, skipbytes); |
---|
| 2661 | delete ze; |
---|
| 2662 | break; |
---|
| 2663 | } |
---|
| 2664 | |
---|
| 2665 | if (!ze_data && lc_name.EndsWith(wxT(".bil"))) { |
---|
| 2666 | if (size) { |
---|
| 2667 | read_bil(zs, size, skipbytes); |
---|
| 2668 | break; |
---|
| 2669 | } |
---|
| 2670 | ze_data = ze; |
---|
| 2671 | continue; |
---|
| 2672 | } |
---|
| 2673 | |
---|
| 2674 | if (lc_name.EndsWith(wxT(".hdr"))) { |
---|
| 2675 | size = parse_hdr(zs, skipbytes); |
---|
| 2676 | if (ze_data) { |
---|
| 2677 | if (!zs.OpenEntry(*ze_data)) { |
---|
| 2678 | wxMessageBox(wxT("Couldn't read DEM data from .zip file")); |
---|
| 2679 | break; |
---|
| 2680 | } |
---|
| 2681 | read_bil(zs, size, skipbytes); |
---|
| 2682 | } |
---|
| 2683 | } else if (lc_name.EndsWith(wxT(".prj"))) { |
---|
| 2684 | //FIXME: check this matches the datum string we use |
---|
| 2685 | //Projection GEOGRAPHIC |
---|
| 2686 | //Datum WGS84 |
---|
| 2687 | //Zunits METERS |
---|
| 2688 | //Units DD |
---|
| 2689 | //Spheroid WGS84 |
---|
| 2690 | //Xshift 0.0000000000 |
---|
| 2691 | //Yshift 0.0000000000 |
---|
| 2692 | //Parameters |
---|
| 2693 | } |
---|
| 2694 | } |
---|
| 2695 | delete ze; |
---|
| 2696 | } |
---|
| 2697 | delete ze_data; |
---|
| 2698 | } |
---|
| 2699 | |
---|
| 2700 | if (!dem) { |
---|
| 2701 | return false; |
---|
| 2702 | } |
---|
[622460e] | 2703 | |
---|
| 2704 | InvalidateList(LIST_TERRAIN); |
---|
[74869a7] | 2705 | ForceRefresh(); |
---|
[5314a0e] | 2706 | return true; |
---|
| 2707 | } |
---|
| 2708 | |
---|
| 2709 | void GfxCore::DrawTerrainTriangle(const Vector3 & a, const Vector3 & b, const Vector3 & c) |
---|
| 2710 | { |
---|
| 2711 | Vector3 n = (b - a) * (c - a); |
---|
| 2712 | n.normalise(); |
---|
| 2713 | Double factor = dot(n, light) * .95 + .05; |
---|
| 2714 | SetColour(col_WHITE, factor); |
---|
| 2715 | PlaceVertex(a); |
---|
| 2716 | PlaceVertex(b); |
---|
| 2717 | PlaceVertex(c); |
---|
| 2718 | ++n_tris; |
---|
| 2719 | } |
---|
| 2720 | |
---|
| 2721 | void GfxCore::DrawTerrain() |
---|
| 2722 | { |
---|
[622460e] | 2723 | if (!dem) return; |
---|
| 2724 | |
---|
[c26455e] | 2725 | wxBusyCursor hourglass; |
---|
| 2726 | |
---|
[6388423] | 2727 | // Draw terrain to twice the extent, or at least 1km. |
---|
| 2728 | double r_sqrd = sqrd(max(m_Parent->GetExtent().magnitude(), 1000.0)); |
---|
| 2729 | #define WGS84_DATUM_STRING "+proj=longlat +ellps=WGS84 +datum=WGS84" |
---|
| 2730 | static projPJ pj_in = pj_init_plus(WGS84_DATUM_STRING); |
---|
| 2731 | if (!pj_in) { |
---|
[9df33bc] | 2732 | ToggleTerrain(); |
---|
| 2733 | error(/*Failed to initialise input coordinate system “%s”*/287, WGS84_DATUM_STRING); |
---|
| 2734 | return; |
---|
[6388423] | 2735 | } |
---|
| 2736 | static projPJ pj_out = pj_init_plus(m_Parent->m_cs_proj.c_str()); |
---|
| 2737 | if (!pj_out) { |
---|
[9df33bc] | 2738 | ToggleTerrain(); |
---|
| 2739 | error(/*Failed to initialise output coordinate system “%s”*/288, (const char *)m_Parent->m_cs_proj.c_str()); |
---|
| 2740 | return; |
---|
[6388423] | 2741 | } |
---|
| 2742 | n_tris = 0; |
---|
| 2743 | SetAlpha(0.3); |
---|
| 2744 | BeginTriangles(); |
---|
| 2745 | const Vector3 & off = m_Parent->GetOffset(); |
---|
[5314a0e] | 2746 | vector<Vector3> prevcol(dem_height + 1); |
---|
| 2747 | for (size_t x = 0; x < dem_width; ++x) { |
---|
[6388423] | 2748 | double X_ = (o_x + x * step_x) * DEG_TO_RAD; |
---|
| 2749 | Vector3 prev; |
---|
[5314a0e] | 2750 | for (size_t y = 0; y < dem_height; ++y) { |
---|
[9df33bc] | 2751 | unsigned short elev = dem[x + y * dem_width]; |
---|
[194503c] | 2752 | #ifdef WORDS_BIGENDIAN |
---|
[9df33bc] | 2753 | const bool MACHINE_BIGENDIAN = true; |
---|
| 2754 | #else |
---|
| 2755 | const bool MACHINE_BIGENDIAN = false; |
---|
| 2756 | #endif |
---|
| 2757 | if (bigendian != MACHINE_BIGENDIAN) { |
---|
| 2758 | #if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408) |
---|
| 2759 | elev = __builtin_bswap16(elev); |
---|
| 2760 | #else |
---|
| 2761 | elev = (elev >> 8) | (elev << 8); |
---|
[194503c] | 2762 | #endif |
---|
[9df33bc] | 2763 | } |
---|
[194503c] | 2764 | double Z = (short)elev; |
---|
[6388423] | 2765 | Vector3 pt; |
---|
| 2766 | if (Z == nodata_value) { |
---|
| 2767 | pt = Vector3(DBL_MAX, DBL_MAX, DBL_MAX); |
---|
| 2768 | } else { |
---|
| 2769 | double X = X_; |
---|
| 2770 | double Y = (o_y - y * step_y) * DEG_TO_RAD; |
---|
| 2771 | pj_transform(pj_in, pj_out, 1, 1, &X, &Y, &Z); |
---|
| 2772 | pt = Vector3(X, Y, Z) - off; |
---|
| 2773 | double dist_2 = sqrd(pt.GetX()) + sqrd(pt.GetY()); |
---|
| 2774 | if (dist_2 > r_sqrd) { |
---|
| 2775 | pt = Vector3(DBL_MAX, DBL_MAX, DBL_MAX); |
---|
| 2776 | } |
---|
| 2777 | } |
---|
| 2778 | if (x > 0 && y > 0) { |
---|
| 2779 | const Vector3 & a = prevcol[y - 1]; |
---|
| 2780 | const Vector3 & b = prevcol[y]; |
---|
| 2781 | // If all points are valid, split the quadrilateral into |
---|
| 2782 | // triangles along the shorter 3D diagonal, which typically |
---|
| 2783 | // looks better: |
---|
| 2784 | // |
---|
| 2785 | // -----> |
---|
| 2786 | // prev---a x prev---a |
---|
| 2787 | // | |P /| |\ S| |
---|
| 2788 | // y | | / | or | \ | |
---|
| 2789 | // V | / | | \ | |
---|
| 2790 | // |/ Q| |R \| |
---|
| 2791 | // b----pt b----pt |
---|
| 2792 | // |
---|
| 2793 | // FORWARD BACKWARD |
---|
| 2794 | enum { NONE = 0, P = 1, Q = 2, R = 4, S = 8, ALL = P|Q|R|S }; |
---|
| 2795 | int valid = |
---|
| 2796 | ((prev.GetZ() != DBL_MAX)) | |
---|
| 2797 | ((a.GetZ() != DBL_MAX) << 1) | |
---|
| 2798 | ((b.GetZ() != DBL_MAX) << 2) | |
---|
| 2799 | ((pt.GetZ() != DBL_MAX) << 3); |
---|
| 2800 | static const int tris_map[16] = { |
---|
| 2801 | NONE, // nothing valid |
---|
| 2802 | NONE, // prev |
---|
| 2803 | NONE, // a |
---|
| 2804 | NONE, // a, prev |
---|
| 2805 | NONE, // b |
---|
| 2806 | NONE, // b, prev |
---|
| 2807 | NONE, // b, a |
---|
| 2808 | P, // b, a, prev |
---|
| 2809 | NONE, // pt |
---|
| 2810 | NONE, // pt, prev |
---|
| 2811 | NONE, // pt, a |
---|
| 2812 | S, // pt, a, prev |
---|
| 2813 | NONE, // pt, b |
---|
| 2814 | R, // pt, b, prev |
---|
| 2815 | Q, // pt, b, a |
---|
| 2816 | ALL, // pt, b, a, prev |
---|
| 2817 | }; |
---|
| 2818 | int tris = tris_map[valid]; |
---|
| 2819 | if (tris == ALL) { |
---|
| 2820 | // All points valid. |
---|
| 2821 | if ((a - b).magnitude() < (prev - pt).magnitude()) { |
---|
| 2822 | tris = P | Q; |
---|
| 2823 | } else { |
---|
| 2824 | tris = R | S; |
---|
| 2825 | } |
---|
| 2826 | } |
---|
| 2827 | if (tris & P) |
---|
| 2828 | DrawTerrainTriangle(a, prev, b); |
---|
| 2829 | if (tris & Q) |
---|
| 2830 | DrawTerrainTriangle(a, b, pt); |
---|
| 2831 | if (tris & R) |
---|
| 2832 | DrawTerrainTriangle(pt, prev, b); |
---|
| 2833 | if (tris & S) |
---|
| 2834 | DrawTerrainTriangle(a, prev, pt); |
---|
| 2835 | } |
---|
| 2836 | prev = prevcol[y]; |
---|
| 2837 | prevcol[y].assign(pt); |
---|
| 2838 | } |
---|
| 2839 | } |
---|
| 2840 | EndTriangles(); |
---|
| 2841 | SetAlpha(1.0); |
---|
| 2842 | } |
---|
| 2843 | |
---|
[d2fcc9b] | 2844 | // Plot blobs. |
---|
[d9b3270] | 2845 | void GfxCore::GenerateBlobsDisplayList() |
---|
| 2846 | { |
---|
[e633bb1] | 2847 | if (!(m_Entrances || m_FixedPts || m_ExportedPts || |
---|
| 2848 | m_Parent->GetNumHighlightedPts())) |
---|
| 2849 | return; |
---|
[429465a] | 2850 | |
---|
[e633bb1] | 2851 | // Plot blobs. |
---|
| 2852 | gla_colour prev_col = col_BLACK; // not a colour used for blobs |
---|
| 2853 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 2854 | BeginBlobs(); |
---|
| 2855 | while (pos != m_Parent->GetLabelsEnd()) { |
---|
[429465a] | 2856 | const LabelInfo* label = *pos++; |
---|
| 2857 | |
---|
| 2858 | // When more than one flag is set on a point: |
---|
| 2859 | // search results take priority over entrance highlighting |
---|
| 2860 | // which takes priority over fixed point |
---|
| 2861 | // highlighting, which in turn takes priority over exported |
---|
| 2862 | // point highlighting. |
---|
| 2863 | |
---|
| 2864 | if (!((m_Surface && label->IsSurface()) || |
---|
| 2865 | (m_Legs && label->IsUnderground()) || |
---|
| 2866 | (!label->IsSurface() && !label->IsUnderground()))) { |
---|
| 2867 | // if this station isn't to be displayed, skip to the next |
---|
| 2868 | // (last case is for stns with no legs attached) |
---|
| 2869 | continue; |
---|
| 2870 | } |
---|
| 2871 | |
---|
[e633bb1] | 2872 | gla_colour col; |
---|
| 2873 | |
---|
[429465a] | 2874 | if (label->IsHighLighted()) { |
---|
| 2875 | col = col_YELLOW; |
---|
| 2876 | } else if (m_Entrances && label->IsEntrance()) { |
---|
| 2877 | col = col_GREEN; |
---|
| 2878 | } else if (m_FixedPts && label->IsFixedPt()) { |
---|
| 2879 | col = col_RED; |
---|
| 2880 | } else if (m_ExportedPts && label->IsExportedPt()) { |
---|
| 2881 | col = col_TURQUOISE; |
---|
| 2882 | } else { |
---|
| 2883 | continue; |
---|
| 2884 | } |
---|
| 2885 | |
---|
[e633bb1] | 2886 | // Stations are sorted by blob type, so colour changes are infrequent. |
---|
| 2887 | if (col != prev_col) { |
---|
[aa048c3] | 2888 | SetColour(col); |
---|
[e633bb1] | 2889 | prev_col = col; |
---|
[429465a] | 2890 | } |
---|
[e633bb1] | 2891 | DrawBlob(label->GetX(), label->GetY(), label->GetZ()); |
---|
[d9b3270] | 2892 | } |
---|
[e633bb1] | 2893 | EndBlobs(); |
---|
[33b2094] | 2894 | } |
---|
| 2895 | |
---|
[6747314] | 2896 | void GfxCore::DrawIndicators() |
---|
[33b2094] | 2897 | { |
---|
[97ea48d] | 2898 | // Draw colour key. |
---|
| 2899 | if (m_ColourKey) { |
---|
[47c62d04] | 2900 | drawing_list key_list = LIST_LIMIT_; |
---|
| 2901 | switch (m_ColourBy) { |
---|
| 2902 | case COLOUR_BY_DEPTH: |
---|
| 2903 | key_list = LIST_DEPTH_KEY; break; |
---|
| 2904 | case COLOUR_BY_DATE: |
---|
| 2905 | key_list = LIST_DATE_KEY; break; |
---|
| 2906 | case COLOUR_BY_ERROR: |
---|
| 2907 | key_list = LIST_ERROR_KEY; break; |
---|
[cc9e2c65] | 2908 | case COLOUR_BY_GRADIENT: |
---|
| 2909 | key_list = LIST_GRADIENT_KEY; break; |
---|
[47c62d04] | 2910 | case COLOUR_BY_LENGTH: |
---|
| 2911 | key_list = LIST_LENGTH_KEY; break; |
---|
| 2912 | } |
---|
| 2913 | if (key_list != LIST_LIMIT_) { |
---|
| 2914 | DrawList2D(key_list, GetXSize() - KEY_OFFSET_X, |
---|
[af50685] | 2915 | GetYSize() - KEY_OFFSET_Y, 0); |
---|
[1b164a0] | 2916 | } |
---|
[33b2094] | 2917 | } |
---|
[56da40e] | 2918 | |
---|
[203d2a7] | 2919 | // Draw compass or elevation/heading indicators. |
---|
[eef68f9] | 2920 | if (m_Compass || m_Clino) { |
---|
| 2921 | if (!m_Parent->IsExtendedElevation()) Draw2dIndicators(); |
---|
[203d2a7] | 2922 | } |
---|
[f433fda] | 2923 | |
---|
[56da40e] | 2924 | // Draw scalebar. |
---|
| 2925 | if (m_Scalebar) { |
---|
[9c37beb] | 2926 | DrawList2D(LIST_SCALE_BAR, 0, 0, 0); |
---|
[56da40e] | 2927 | } |
---|
[33b2094] | 2928 | } |
---|
| 2929 | |
---|
[f336ab9] | 2930 | void GfxCore::PlaceVertexWithColour(const Vector3 & v, |
---|
| 2931 | glaTexCoord tex_x, glaTexCoord tex_y, |
---|
[b839829] | 2932 | Double factor) |
---|
[f383708] | 2933 | { |
---|
[d1ce9bd] | 2934 | SetColour(col_WHITE, factor); |
---|
[b839829] | 2935 | PlaceVertex(v, tex_x, tex_y); |
---|
[da6c802] | 2936 | } |
---|
[f433fda] | 2937 | |
---|
[b839829] | 2938 | void GfxCore::SetDepthColour(Double z, Double factor) { |
---|
[da6c802] | 2939 | // Set the drawing colour based on the altitude. |
---|
[78c67a6] | 2940 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
[f383708] | 2941 | |
---|
[b839829] | 2942 | z -= m_Parent->GetDepthMin(); |
---|
[f383708] | 2943 | // points arising from tubes may be slightly outside the limits... |
---|
[78c67a6] | 2944 | if (z < 0) z = 0; |
---|
| 2945 | if (z > z_ext) z = z_ext; |
---|
[a6f081c] | 2946 | |
---|
[2a9d2fa] | 2947 | if (z == 0) { |
---|
| 2948 | SetColour(GetPen(0), factor); |
---|
| 2949 | return; |
---|
| 2950 | } |
---|
| 2951 | |
---|
| 2952 | assert(z_ext > 0.0); |
---|
[78c67a6] | 2953 | Double how_far = z / z_ext; |
---|
[f383708] | 2954 | assert(how_far >= 0.0); |
---|
| 2955 | assert(how_far <= 1.0); |
---|
| 2956 | |
---|
[97ea48d] | 2957 | int band = int(floor(how_far * (GetNumColourBands() - 1))); |
---|
[0e69efe] | 2958 | GLAPen pen1 = GetPen(band); |
---|
[97ea48d] | 2959 | if (band < GetNumColourBands() - 1) { |
---|
[d4650b3] | 2960 | const GLAPen& pen2 = GetPen(band + 1); |
---|
[f433fda] | 2961 | |
---|
[97ea48d] | 2962 | Double interval = z_ext / (GetNumColourBands() - 1); |
---|
[78c67a6] | 2963 | Double into_band = z / interval - band; |
---|
[f433fda] | 2964 | |
---|
[d4650b3] | 2965 | // printf("%g z_offset=%g interval=%g band=%d\n", into_band, |
---|
| 2966 | // z_offset, interval, band); |
---|
| 2967 | // FIXME: why do we need to clamp here? Is it because the walls can |
---|
| 2968 | // extend further up/down than the centre-line? |
---|
| 2969 | if (into_band < 0.0) into_band = 0.0; |
---|
| 2970 | if (into_band > 1.0) into_band = 1.0; |
---|
| 2971 | assert(into_band >= 0.0); |
---|
| 2972 | assert(into_band <= 1.0); |
---|
[f433fda] | 2973 | |
---|
[d4650b3] | 2974 | pen1.Interpolate(pen2, into_band); |
---|
| 2975 | } |
---|
[aa048c3] | 2976 | SetColour(pen1, factor); |
---|
[b839829] | 2977 | } |
---|
[f383708] | 2978 | |
---|
[b839829] | 2979 | void GfxCore::PlaceVertexWithDepthColour(const Vector3 &v, Double factor) |
---|
| 2980 | { |
---|
| 2981 | SetDepthColour(v.GetZ(), factor); |
---|
[d67450e] | 2982 | PlaceVertex(v); |
---|
[f383708] | 2983 | } |
---|
| 2984 | |
---|
[b839829] | 2985 | void GfxCore::PlaceVertexWithDepthColour(const Vector3 &v, |
---|
[f336ab9] | 2986 | glaTexCoord tex_x, glaTexCoord tex_y, |
---|
[b839829] | 2987 | Double factor) |
---|
| 2988 | { |
---|
| 2989 | SetDepthColour(v.GetZ(), factor); |
---|
| 2990 | PlaceVertex(v, tex_x, tex_y); |
---|
| 2991 | } |
---|
| 2992 | |
---|
[82f584f] | 2993 | void GfxCore::SplitLineAcrossBands(int band, int band2, |
---|
[4a0e6b35] | 2994 | const Vector3 &p, const Vector3 &q, |
---|
[82f584f] | 2995 | Double factor) |
---|
[b5d64e6] | 2996 | { |
---|
[4a0e6b35] | 2997 | const int step = (band < band2) ? 1 : -1; |
---|
[b5d64e6] | 2998 | for (int i = band; i != band2; i += step) { |
---|
[4a0e6b35] | 2999 | const Double z = GetDepthBoundaryBetweenBands(i, i + step); |
---|
| 3000 | |
---|
| 3001 | // Find the intersection point of the line p -> q |
---|
| 3002 | // with the plane parallel to the xy-plane with z-axis intersection z. |
---|
[d67450e] | 3003 | assert(q.GetZ() - p.GetZ() != 0.0); |
---|
[4a0e6b35] | 3004 | |
---|
[d67450e] | 3005 | const Double t = (z - p.GetZ()) / (q.GetZ() - p.GetZ()); |
---|
[4a0e6b35] | 3006 | // assert(0.0 <= t && t <= 1.0); FIXME: rounding problems! |
---|
| 3007 | |
---|
[d67450e] | 3008 | const Double x = p.GetX() + t * (q.GetX() - p.GetX()); |
---|
| 3009 | const Double y = p.GetY() + t * (q.GetY() - p.GetY()); |
---|
[4a0e6b35] | 3010 | |
---|
[d67450e] | 3011 | PlaceVertexWithDepthColour(Vector3(x, y, z), factor); |
---|
[b5d64e6] | 3012 | } |
---|
| 3013 | } |
---|
| 3014 | |
---|
[14acdae] | 3015 | int GfxCore::GetDepthColour(Double z) const |
---|
[b5d64e6] | 3016 | { |
---|
[82f584f] | 3017 | // Return the (0-based) depth colour band index for a z-coordinate. |
---|
[78c67a6] | 3018 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
| 3019 | z -= m_Parent->GetDepthMin(); |
---|
[2ba3882] | 3020 | // We seem to get rounding differences causing z to sometimes be slightly |
---|
[0a2aab8] | 3021 | // less than GetDepthMin() here, and it can certainly be true for passage |
---|
| 3022 | // tubes, so just clamp the value to 0. |
---|
[2ba3882] | 3023 | if (z <= 0) return 0; |
---|
[6027220] | 3024 | // We seem to get rounding differences causing z to sometimes exceed z_ext |
---|
[0a2aab8] | 3025 | // by a small amount here (see: http://trac.survex.com/ticket/26) and it |
---|
| 3026 | // can certainly be true for passage tubes, so just clamp the value. |
---|
| 3027 | if (z >= z_ext) return GetNumColourBands() - 1; |
---|
[97ea48d] | 3028 | return int(z / z_ext * (GetNumColourBands() - 1)); |
---|
[b5d64e6] | 3029 | } |
---|
| 3030 | |
---|
[14acdae] | 3031 | Double GfxCore::GetDepthBoundaryBetweenBands(int a, int b) const |
---|
[b5d64e6] | 3032 | { |
---|
[82f584f] | 3033 | // Return the z-coordinate of the depth colour boundary between |
---|
| 3034 | // two adjacent depth colour bands (specified by 0-based indices). |
---|
| 3035 | |
---|
| 3036 | assert((a == b - 1) || (a == b + 1)); |
---|
[97ea48d] | 3037 | if (GetNumColourBands() == 1) return 0; |
---|
[82f584f] | 3038 | |
---|
| 3039 | int band = (a > b) ? a : b; // boundary N lies on the bottom of band N. |
---|
[78c67a6] | 3040 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
[2a9d2fa] | 3041 | return (z_ext * band / (GetNumColourBands() - 1)) + m_Parent->GetDepthMin(); |
---|
[b5d64e6] | 3042 | } |
---|
| 3043 | |
---|
[c61aa79] | 3044 | void GfxCore::AddPolyline(const traverse & centreline) |
---|
[da6c802] | 3045 | { |
---|
| 3046 | BeginPolyline(); |
---|
[d1ce9bd] | 3047 | SetColour(col_WHITE); |
---|
[d4650b3] | 3048 | vector<PointInfo>::const_iterator i = centreline.begin(); |
---|
[d67450e] | 3049 | PlaceVertex(*i); |
---|
[da6c802] | 3050 | ++i; |
---|
| 3051 | while (i != centreline.end()) { |
---|
[d67450e] | 3052 | PlaceVertex(*i); |
---|
[da6c802] | 3053 | ++i; |
---|
| 3054 | } |
---|
| 3055 | EndPolyline(); |
---|
| 3056 | } |
---|
[2a3d328] | 3057 | |
---|
[c61aa79] | 3058 | void GfxCore::AddPolylineShadow(const traverse & centreline) |
---|
[f4c5932] | 3059 | { |
---|
| 3060 | BeginPolyline(); |
---|
[78c67a6] | 3061 | const double z = -0.5 * m_Parent->GetZExtent(); |
---|
[d4650b3] | 3062 | vector<PointInfo>::const_iterator i = centreline.begin(); |
---|
[78c67a6] | 3063 | PlaceVertex(i->GetX(), i->GetY(), z); |
---|
[f4c5932] | 3064 | ++i; |
---|
| 3065 | while (i != centreline.end()) { |
---|
[78c67a6] | 3066 | PlaceVertex(i->GetX(), i->GetY(), z); |
---|
[f4c5932] | 3067 | ++i; |
---|
| 3068 | } |
---|
| 3069 | EndPolyline(); |
---|
| 3070 | } |
---|
| 3071 | |
---|
[c61aa79] | 3072 | void GfxCore::AddPolylineDepth(const traverse & centreline) |
---|
[da6c802] | 3073 | { |
---|
| 3074 | BeginPolyline(); |
---|
[d4650b3] | 3075 | vector<PointInfo>::const_iterator i, prev_i; |
---|
[da6c802] | 3076 | i = centreline.begin(); |
---|
[ee7af72] | 3077 | int band0 = GetDepthColour(i->GetZ()); |
---|
[d67450e] | 3078 | PlaceVertexWithDepthColour(*i); |
---|
[da6c802] | 3079 | prev_i = i; |
---|
| 3080 | ++i; |
---|
| 3081 | while (i != centreline.end()) { |
---|
[ee7af72] | 3082 | int band = GetDepthColour(i->GetZ()); |
---|
[da6c802] | 3083 | if (band != band0) { |
---|
[d67450e] | 3084 | SplitLineAcrossBands(band0, band, *prev_i, *i); |
---|
[da6c802] | 3085 | band0 = band; |
---|
| 3086 | } |
---|
[d67450e] | 3087 | PlaceVertexWithDepthColour(*i); |
---|
[da6c802] | 3088 | prev_i = i; |
---|
| 3089 | ++i; |
---|
| 3090 | } |
---|
| 3091 | EndPolyline(); |
---|
| 3092 | } |
---|
| 3093 | |
---|
[f433fda] | 3094 | void GfxCore::AddQuadrilateral(const Vector3 &a, const Vector3 &b, |
---|
[14acdae] | 3095 | const Vector3 &c, const Vector3 &d) |
---|
[da6c802] | 3096 | { |
---|
| 3097 | Vector3 normal = (a - c) * (d - b); |
---|
| 3098 | normal.normalise(); |
---|
| 3099 | Double factor = dot(normal, light) * .3 + .7; |
---|
[f336ab9] | 3100 | glaTexCoord w(ceil(((b - a).magnitude() + (d - c).magnitude()) * .5)); |
---|
| 3101 | glaTexCoord h(ceil(((b - c).magnitude() + (d - a).magnitude()) * .5)); |
---|
[9b57c71b] | 3102 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
[da6c802] | 3103 | BeginQuadrilaterals(); |
---|
[b839829] | 3104 | PlaceVertexWithColour(a, 0, 0, factor); |
---|
| 3105 | PlaceVertexWithColour(b, w, 0, factor); |
---|
| 3106 | PlaceVertexWithColour(c, w, h, factor); |
---|
| 3107 | PlaceVertexWithColour(d, 0, h, factor); |
---|
[da6c802] | 3108 | EndQuadrilaterals(); |
---|
| 3109 | } |
---|
| 3110 | |
---|
| 3111 | void GfxCore::AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b, |
---|
| 3112 | const Vector3 &c, const Vector3 &d) |
---|
[2b02270] | 3113 | { |
---|
| 3114 | Vector3 normal = (a - c) * (d - b); |
---|
| 3115 | normal.normalise(); |
---|
| 3116 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 3117 | int a_band, b_band, c_band, d_band; |
---|
[d67450e] | 3118 | a_band = GetDepthColour(a.GetZ()); |
---|
[97ea48d] | 3119 | a_band = min(max(a_band, 0), GetNumColourBands()); |
---|
[d67450e] | 3120 | b_band = GetDepthColour(b.GetZ()); |
---|
[97ea48d] | 3121 | b_band = min(max(b_band, 0), GetNumColourBands()); |
---|
[d67450e] | 3122 | c_band = GetDepthColour(c.GetZ()); |
---|
[97ea48d] | 3123 | c_band = min(max(c_band, 0), GetNumColourBands()); |
---|
[d67450e] | 3124 | d_band = GetDepthColour(d.GetZ()); |
---|
[97ea48d] | 3125 | d_band = min(max(d_band, 0), GetNumColourBands()); |
---|
[97fb83a] | 3126 | // All this splitting is incorrect - we need to make a separate polygon |
---|
| 3127 | // for each depth band... |
---|
[f336ab9] | 3128 | glaTexCoord w(ceil(((b - a).magnitude() + (d - c).magnitude()) * .5)); |
---|
| 3129 | glaTexCoord h(ceil(((b - c).magnitude() + (d - a).magnitude()) * .5)); |
---|
[b5d64e6] | 3130 | BeginPolygon(); |
---|
[d67450e] | 3131 | //// PlaceNormal(normal); |
---|
[b839829] | 3132 | PlaceVertexWithDepthColour(a, 0, 0, factor); |
---|
[2b02270] | 3133 | if (a_band != b_band) { |
---|
[b5d64e6] | 3134 | SplitLineAcrossBands(a_band, b_band, a, b, factor); |
---|
[2b02270] | 3135 | } |
---|
[b839829] | 3136 | PlaceVertexWithDepthColour(b, w, 0, factor); |
---|
[2b02270] | 3137 | if (b_band != c_band) { |
---|
[b5d64e6] | 3138 | SplitLineAcrossBands(b_band, c_band, b, c, factor); |
---|
[2b02270] | 3139 | } |
---|
[b839829] | 3140 | PlaceVertexWithDepthColour(c, w, h, factor); |
---|
[2b02270] | 3141 | if (c_band != d_band) { |
---|
[b5d64e6] | 3142 | SplitLineAcrossBands(c_band, d_band, c, d, factor); |
---|
[2b02270] | 3143 | } |
---|
[b839829] | 3144 | PlaceVertexWithDepthColour(d, 0, h, factor); |
---|
[2b02270] | 3145 | if (d_band != a_band) { |
---|
[b5d64e6] | 3146 | SplitLineAcrossBands(d_band, a_band, d, a, factor); |
---|
[2b02270] | 3147 | } |
---|
[b5d64e6] | 3148 | EndPolygon(); |
---|
[2b02270] | 3149 | } |
---|
| 3150 | |
---|
[1ee204e] | 3151 | void GfxCore::SetColourFromDate(int date, Double factor) |
---|
[d4650b3] | 3152 | { |
---|
| 3153 | // Set the drawing colour based on a date. |
---|
| 3154 | |
---|
[1ee204e] | 3155 | if (date == -1) { |
---|
[2043961] | 3156 | // Undated. |
---|
[d1ce9bd] | 3157 | SetColour(col_WHITE, factor); |
---|
[d4650b3] | 3158 | return; |
---|
| 3159 | } |
---|
| 3160 | |
---|
[1ee204e] | 3161 | int date_offset = date - m_Parent->GetDateMin(); |
---|
[2043961] | 3162 | if (date_offset == 0) { |
---|
| 3163 | // Earliest date - handle as a special case for the single date case. |
---|
| 3164 | SetColour(GetPen(0), factor); |
---|
| 3165 | return; |
---|
| 3166 | } |
---|
[d4650b3] | 3167 | |
---|
[2043961] | 3168 | int date_ext = m_Parent->GetDateExtent(); |
---|
[d4650b3] | 3169 | Double how_far = (Double)date_offset / date_ext; |
---|
| 3170 | assert(how_far >= 0.0); |
---|
| 3171 | assert(how_far <= 1.0); |
---|
[371f9ed] | 3172 | SetColourFrom01(how_far, factor); |
---|
[d4650b3] | 3173 | } |
---|
| 3174 | |
---|
[c61aa79] | 3175 | void GfxCore::AddPolylineDate(const traverse & centreline) |
---|
[d4650b3] | 3176 | { |
---|
| 3177 | BeginPolyline(); |
---|
| 3178 | vector<PointInfo>::const_iterator i, prev_i; |
---|
| 3179 | i = centreline.begin(); |
---|
[1ee204e] | 3180 | int date = i->GetDate(); |
---|
[d4650b3] | 3181 | SetColourFromDate(date, 1.0); |
---|
[d67450e] | 3182 | PlaceVertex(*i); |
---|
[d4650b3] | 3183 | prev_i = i; |
---|
| 3184 | while (++i != centreline.end()) { |
---|
[1ee204e] | 3185 | int newdate = i->GetDate(); |
---|
[d4650b3] | 3186 | if (newdate != date) { |
---|
| 3187 | EndPolyline(); |
---|
| 3188 | BeginPolyline(); |
---|
| 3189 | date = newdate; |
---|
| 3190 | SetColourFromDate(date, 1.0); |
---|
[d67450e] | 3191 | PlaceVertex(*prev_i); |
---|
[d4650b3] | 3192 | } |
---|
[d67450e] | 3193 | PlaceVertex(*i); |
---|
[d4650b3] | 3194 | prev_i = i; |
---|
| 3195 | } |
---|
| 3196 | EndPolyline(); |
---|
| 3197 | } |
---|
| 3198 | |
---|
[1ee204e] | 3199 | static int static_date_hack; // FIXME |
---|
[d4650b3] | 3200 | |
---|
| 3201 | void GfxCore::AddQuadrilateralDate(const Vector3 &a, const Vector3 &b, |
---|
| 3202 | const Vector3 &c, const Vector3 &d) |
---|
| 3203 | { |
---|
| 3204 | Vector3 normal = (a - c) * (d - b); |
---|
| 3205 | normal.normalise(); |
---|
| 3206 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 3207 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 3208 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 3209 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
[b839829] | 3210 | BeginQuadrilaterals(); |
---|
[d67450e] | 3211 | //// PlaceNormal(normal); |
---|
[d4650b3] | 3212 | SetColourFromDate(static_date_hack, factor); |
---|
[b839829] | 3213 | PlaceVertex(a, 0, 0); |
---|
| 3214 | PlaceVertex(b, w, 0); |
---|
| 3215 | PlaceVertex(c, w, h); |
---|
| 3216 | PlaceVertex(d, 0, h); |
---|
| 3217 | EndQuadrilaterals(); |
---|
[d4650b3] | 3218 | } |
---|
| 3219 | |
---|
[c61aa79] | 3220 | static double static_E_hack; // FIXME |
---|
| 3221 | |
---|
| 3222 | void GfxCore::SetColourFromError(double E, Double factor) |
---|
| 3223 | { |
---|
| 3224 | // Set the drawing colour based on an error value. |
---|
| 3225 | |
---|
| 3226 | if (E < 0) { |
---|
[d1ce9bd] | 3227 | SetColour(col_WHITE, factor); |
---|
[c61aa79] | 3228 | return; |
---|
| 3229 | } |
---|
| 3230 | |
---|
| 3231 | Double how_far = E / MAX_ERROR; |
---|
| 3232 | assert(how_far >= 0.0); |
---|
| 3233 | if (how_far > 1.0) how_far = 1.0; |
---|
[371f9ed] | 3234 | SetColourFrom01(how_far, factor); |
---|
[c61aa79] | 3235 | } |
---|
| 3236 | |
---|
| 3237 | void GfxCore::AddQuadrilateralError(const Vector3 &a, const Vector3 &b, |
---|
| 3238 | const Vector3 &c, const Vector3 &d) |
---|
| 3239 | { |
---|
| 3240 | Vector3 normal = (a - c) * (d - b); |
---|
| 3241 | normal.normalise(); |
---|
| 3242 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 3243 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 3244 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 3245 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
[b839829] | 3246 | BeginQuadrilaterals(); |
---|
[c61aa79] | 3247 | //// PlaceNormal(normal); |
---|
| 3248 | SetColourFromError(static_E_hack, factor); |
---|
[b839829] | 3249 | PlaceVertex(a, 0, 0); |
---|
| 3250 | PlaceVertex(b, w, 0); |
---|
| 3251 | PlaceVertex(c, w, h); |
---|
| 3252 | PlaceVertex(d, 0, h); |
---|
| 3253 | EndQuadrilaterals(); |
---|
[c61aa79] | 3254 | } |
---|
| 3255 | |
---|
| 3256 | void GfxCore::AddPolylineError(const traverse & centreline) |
---|
| 3257 | { |
---|
| 3258 | BeginPolyline(); |
---|
| 3259 | SetColourFromError(centreline.E, 1.0); |
---|
| 3260 | vector<PointInfo>::const_iterator i; |
---|
| 3261 | for(i = centreline.begin(); i != centreline.end(); ++i) { |
---|
| 3262 | PlaceVertex(*i); |
---|
| 3263 | } |
---|
| 3264 | EndPolyline(); |
---|
| 3265 | } |
---|
| 3266 | |
---|
[cc9e2c65] | 3267 | // gradient is in *radians*. |
---|
| 3268 | void GfxCore::SetColourFromGradient(double gradient, Double factor) |
---|
| 3269 | { |
---|
| 3270 | // Set the drawing colour based on the gradient of the leg. |
---|
| 3271 | |
---|
| 3272 | const Double GRADIENT_MAX = M_PI_2; |
---|
| 3273 | gradient = fabs(gradient); |
---|
| 3274 | Double how_far = gradient / GRADIENT_MAX; |
---|
| 3275 | SetColourFrom01(how_far, factor); |
---|
| 3276 | } |
---|
| 3277 | |
---|
| 3278 | void GfxCore::AddPolylineGradient(const traverse & centreline) |
---|
| 3279 | { |
---|
| 3280 | vector<PointInfo>::const_iterator i, prev_i; |
---|
| 3281 | i = centreline.begin(); |
---|
| 3282 | prev_i = i; |
---|
| 3283 | while (++i != centreline.end()) { |
---|
| 3284 | BeginPolyline(); |
---|
| 3285 | SetColourFromGradient((*i - *prev_i).gradient(), 1.0); |
---|
| 3286 | PlaceVertex(*prev_i); |
---|
| 3287 | PlaceVertex(*i); |
---|
| 3288 | prev_i = i; |
---|
| 3289 | EndPolyline(); |
---|
| 3290 | } |
---|
| 3291 | } |
---|
| 3292 | |
---|
| 3293 | static double static_gradient_hack; // FIXME |
---|
| 3294 | |
---|
| 3295 | void GfxCore::AddQuadrilateralGradient(const Vector3 &a, const Vector3 &b, |
---|
| 3296 | const Vector3 &c, const Vector3 &d) |
---|
| 3297 | { |
---|
| 3298 | Vector3 normal = (a - c) * (d - b); |
---|
| 3299 | normal.normalise(); |
---|
| 3300 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 3301 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 3302 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 3303 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
| 3304 | BeginQuadrilaterals(); |
---|
| 3305 | //// PlaceNormal(normal); |
---|
| 3306 | SetColourFromGradient(static_gradient_hack, factor); |
---|
| 3307 | PlaceVertex(a, 0, 0); |
---|
| 3308 | PlaceVertex(b, w, 0); |
---|
| 3309 | PlaceVertex(c, w, h); |
---|
| 3310 | PlaceVertex(d, 0, h); |
---|
| 3311 | EndQuadrilaterals(); |
---|
| 3312 | } |
---|
| 3313 | |
---|
[af50685] | 3314 | void GfxCore::SetColourFromLength(double length, Double factor) |
---|
| 3315 | { |
---|
| 3316 | // Set the drawing colour based on log(length_of_leg). |
---|
| 3317 | |
---|
| 3318 | Double log_len = log10(length); |
---|
| 3319 | Double how_far = log_len / LOG_LEN_MAX; |
---|
| 3320 | how_far = max(how_far, 0.0); |
---|
| 3321 | how_far = min(how_far, 1.0); |
---|
[371f9ed] | 3322 | SetColourFrom01(how_far, factor); |
---|
| 3323 | } |
---|
[af50685] | 3324 | |
---|
[371f9ed] | 3325 | void GfxCore::SetColourFrom01(double how_far, Double factor) |
---|
| 3326 | { |
---|
| 3327 | double b; |
---|
| 3328 | double into_band = modf(how_far * (GetNumColourBands() - 1), &b); |
---|
| 3329 | int band(b); |
---|
[af50685] | 3330 | GLAPen pen1 = GetPen(band); |
---|
[371f9ed] | 3331 | // With 24bit colour, interpolating by less than this can have no effect. |
---|
| 3332 | if (into_band >= 1.0 / 512.0) { |
---|
[af50685] | 3333 | const GLAPen& pen2 = GetPen(band + 1); |
---|
| 3334 | pen1.Interpolate(pen2, into_band); |
---|
| 3335 | } |
---|
| 3336 | SetColour(pen1, factor); |
---|
| 3337 | } |
---|
| 3338 | |
---|
| 3339 | void GfxCore::AddPolylineLength(const traverse & centreline) |
---|
| 3340 | { |
---|
| 3341 | vector<PointInfo>::const_iterator i, prev_i; |
---|
| 3342 | i = centreline.begin(); |
---|
| 3343 | prev_i = i; |
---|
| 3344 | while (++i != centreline.end()) { |
---|
| 3345 | BeginPolyline(); |
---|
[5afbd60] | 3346 | SetColourFromLength((*i - *prev_i).magnitude(), 1.0); |
---|
[af50685] | 3347 | PlaceVertex(*prev_i); |
---|
| 3348 | PlaceVertex(*i); |
---|
| 3349 | prev_i = i; |
---|
| 3350 | EndPolyline(); |
---|
| 3351 | } |
---|
| 3352 | } |
---|
| 3353 | |
---|
| 3354 | static double static_length_hack; // FIXME |
---|
| 3355 | |
---|
| 3356 | void GfxCore::AddQuadrilateralLength(const Vector3 &a, const Vector3 &b, |
---|
| 3357 | const Vector3 &c, const Vector3 &d) |
---|
| 3358 | { |
---|
| 3359 | Vector3 normal = (a - c) * (d - b); |
---|
| 3360 | normal.normalise(); |
---|
| 3361 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 3362 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 3363 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 3364 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
| 3365 | BeginQuadrilaterals(); |
---|
| 3366 | //// PlaceNormal(normal); |
---|
| 3367 | SetColourFromLength(static_length_hack, factor); |
---|
| 3368 | PlaceVertex(a, 0, 0); |
---|
| 3369 | PlaceVertex(b, w, 0); |
---|
| 3370 | PlaceVertex(c, w, h); |
---|
| 3371 | PlaceVertex(d, 0, h); |
---|
| 3372 | EndQuadrilaterals(); |
---|
| 3373 | } |
---|
| 3374 | |
---|
[da6c802] | 3375 | void |
---|
[384534c] | 3376 | GfxCore::SkinPassage(vector<XSect> & centreline, bool draw) |
---|
[3ddcad8] | 3377 | { |
---|
[b3852b5] | 3378 | assert(centreline.size() > 1); |
---|
[3ddcad8] | 3379 | Vector3 U[4]; |
---|
[ee05463] | 3380 | XSect prev_pt_v; |
---|
[3ddcad8] | 3381 | Vector3 last_right(1.0, 0.0, 0.0); |
---|
| 3382 | |
---|
[c61aa79] | 3383 | // FIXME: it's not simple to set the colour of a tube based on error... |
---|
| 3384 | // static_E_hack = something... |
---|
[fc68ad5] | 3385 | vector<XSect>::iterator i = centreline.begin(); |
---|
[ee05463] | 3386 | vector<XSect>::size_type segment = 0; |
---|
[3ddcad8] | 3387 | while (i != centreline.end()) { |
---|
| 3388 | // get the coordinates of this vertex |
---|
[fc68ad5] | 3389 | XSect & pt_v = *i++; |
---|
[3ddcad8] | 3390 | |
---|
| 3391 | double z_pitch_adjust = 0.0; |
---|
| 3392 | bool cover_end = false; |
---|
| 3393 | |
---|
| 3394 | Vector3 right, up; |
---|
| 3395 | |
---|
| 3396 | const Vector3 up_v(0.0, 0.0, 1.0); |
---|
| 3397 | |
---|
| 3398 | if (segment == 0) { |
---|
| 3399 | assert(i != centreline.end()); |
---|
| 3400 | // first segment |
---|
| 3401 | |
---|
| 3402 | // get the coordinates of the next vertex |
---|
[ee05463] | 3403 | const XSect & next_pt_v = *i; |
---|
[3ddcad8] | 3404 | |
---|
| 3405 | // calculate vector from this pt to the next one |
---|
[d67450e] | 3406 | Vector3 leg_v = next_pt_v - pt_v; |
---|
[3ddcad8] | 3407 | |
---|
| 3408 | // obtain a vector in the LRUD plane |
---|
| 3409 | right = leg_v * up_v; |
---|
| 3410 | if (right.magnitude() == 0) { |
---|
| 3411 | right = last_right; |
---|
| 3412 | // Obtain a second vector in the LRUD plane, |
---|
| 3413 | // perpendicular to the first. |
---|
[760ad29d] | 3414 | //up = right * leg_v; |
---|
| 3415 | up = up_v; |
---|
[3ddcad8] | 3416 | } else { |
---|
| 3417 | last_right = right; |
---|
| 3418 | up = up_v; |
---|
[da6c802] | 3419 | } |
---|
| 3420 | |
---|
[3ddcad8] | 3421 | cover_end = true; |
---|
[d4650b3] | 3422 | static_date_hack = next_pt_v.GetDate(); |
---|
[3ddcad8] | 3423 | } else if (segment + 1 == centreline.size()) { |
---|
| 3424 | // last segment |
---|
| 3425 | |
---|
| 3426 | // Calculate vector from the previous pt to this one. |
---|
[d67450e] | 3427 | Vector3 leg_v = pt_v - prev_pt_v; |
---|
[3ddcad8] | 3428 | |
---|
| 3429 | // Obtain a horizontal vector in the LRUD plane. |
---|
| 3430 | right = leg_v * up_v; |
---|
| 3431 | if (right.magnitude() == 0) { |
---|
[d67450e] | 3432 | right = Vector3(last_right.GetX(), last_right.GetY(), 0.0); |
---|
[3ddcad8] | 3433 | // Obtain a second vector in the LRUD plane, |
---|
| 3434 | // perpendicular to the first. |
---|
[760ad29d] | 3435 | //up = right * leg_v; |
---|
| 3436 | up = up_v; |
---|
[3ddcad8] | 3437 | } else { |
---|
| 3438 | last_right = right; |
---|
| 3439 | up = up_v; |
---|
| 3440 | } |
---|
[da6c802] | 3441 | |
---|
[3ddcad8] | 3442 | cover_end = true; |
---|
[d4650b3] | 3443 | static_date_hack = pt_v.GetDate(); |
---|
[3ddcad8] | 3444 | } else { |
---|
| 3445 | assert(i != centreline.end()); |
---|
| 3446 | // Intermediate segment. |
---|
| 3447 | |
---|
| 3448 | // Get the coordinates of the next vertex. |
---|
[ee05463] | 3449 | const XSect & next_pt_v = *i; |
---|
[3ddcad8] | 3450 | |
---|
| 3451 | // Calculate vectors from this vertex to the |
---|
| 3452 | // next vertex, and from the previous vertex to |
---|
| 3453 | // this one. |
---|
[d67450e] | 3454 | Vector3 leg1_v = pt_v - prev_pt_v; |
---|
| 3455 | Vector3 leg2_v = next_pt_v - pt_v; |
---|
[3ddcad8] | 3456 | |
---|
| 3457 | // Obtain horizontal vectors perpendicular to |
---|
| 3458 | // both legs, then normalise and average to get |
---|
| 3459 | // a horizontal bisector. |
---|
| 3460 | Vector3 r1 = leg1_v * up_v; |
---|
| 3461 | Vector3 r2 = leg2_v * up_v; |
---|
| 3462 | r1.normalise(); |
---|
| 3463 | r2.normalise(); |
---|
| 3464 | right = r1 + r2; |
---|
| 3465 | if (right.magnitude() == 0) { |
---|
| 3466 | // This is the "mid-pitch" case... |
---|
| 3467 | right = last_right; |
---|
| 3468 | } |
---|
| 3469 | if (r1.magnitude() == 0) { |
---|
| 3470 | Vector3 n = leg1_v; |
---|
| 3471 | n.normalise(); |
---|
[d67450e] | 3472 | z_pitch_adjust = n.GetZ(); |
---|
| 3473 | //up = Vector3(0, 0, leg1_v.GetZ()); |
---|
[760ad29d] | 3474 | //up = right * up; |
---|
| 3475 | up = up_v; |
---|
[3ddcad8] | 3476 | |
---|
| 3477 | // Rotate pitch section to minimise the |
---|
| 3478 | // "tortional stress" - FIXME: use |
---|
| 3479 | // triangles instead of rectangles? |
---|
| 3480 | int shift = 0; |
---|
| 3481 | Double maxdotp = 0; |
---|
| 3482 | |
---|
| 3483 | // Scale to unit vectors in the LRUD plane. |
---|
| 3484 | right.normalise(); |
---|
| 3485 | up.normalise(); |
---|
| 3486 | Vector3 vec = up - right; |
---|
| 3487 | for (int orient = 0; orient <= 3; ++orient) { |
---|
[d67450e] | 3488 | Vector3 tmp = U[orient] - prev_pt_v; |
---|
[3ddcad8] | 3489 | tmp.normalise(); |
---|
| 3490 | Double dotp = dot(vec, tmp); |
---|
| 3491 | if (dotp > maxdotp) { |
---|
| 3492 | maxdotp = dotp; |
---|
| 3493 | shift = orient; |
---|
| 3494 | } |
---|
| 3495 | } |
---|
| 3496 | if (shift) { |
---|
| 3497 | if (shift != 2) { |
---|
| 3498 | Vector3 temp(U[0]); |
---|
[b3852b5] | 3499 | U[0] = U[shift]; |
---|
| 3500 | U[shift] = U[2]; |
---|
| 3501 | U[2] = U[shift ^ 2]; |
---|
| 3502 | U[shift ^ 2] = temp; |
---|
[ee7af72] | 3503 | } else { |
---|
[3ddcad8] | 3504 | swap(U[0], U[2]); |
---|
| 3505 | swap(U[1], U[3]); |
---|
[ee7af72] | 3506 | } |
---|
[3ddcad8] | 3507 | } |
---|
| 3508 | #if 0 |
---|
| 3509 | // Check that the above code actually permuted |
---|
| 3510 | // the vertices correctly. |
---|
| 3511 | shift = 0; |
---|
| 3512 | maxdotp = 0; |
---|
[b3852b5] | 3513 | for (int j = 0; j <= 3; ++j) { |
---|
[d67450e] | 3514 | Vector3 tmp = U[j] - prev_pt_v; |
---|
[3ddcad8] | 3515 | tmp.normalise(); |
---|
| 3516 | Double dotp = dot(vec, tmp); |
---|
| 3517 | if (dotp > maxdotp) { |
---|
| 3518 | maxdotp = dotp + 1e-6; // Add small tolerance to stop 45 degree offset cases being flagged... |
---|
[b3852b5] | 3519 | shift = j; |
---|
[da6c802] | 3520 | } |
---|
[3ddcad8] | 3521 | } |
---|
| 3522 | if (shift) { |
---|
| 3523 | printf("New shift = %d!\n", shift); |
---|
| 3524 | shift = 0; |
---|
| 3525 | maxdotp = 0; |
---|
[b3852b5] | 3526 | for (int j = 0; j <= 3; ++j) { |
---|
[d67450e] | 3527 | Vector3 tmp = U[j] - prev_pt_v; |
---|
[3ddcad8] | 3528 | tmp.normalise(); |
---|
| 3529 | Double dotp = dot(vec, tmp); |
---|
[b3852b5] | 3530 | printf(" %d : %.8f\n", j, dotp); |
---|
[da6c802] | 3531 | } |
---|
| 3532 | } |
---|
[3ddcad8] | 3533 | #endif |
---|
| 3534 | } else if (r2.magnitude() == 0) { |
---|
| 3535 | Vector3 n = leg2_v; |
---|
| 3536 | n.normalise(); |
---|
[d67450e] | 3537 | z_pitch_adjust = n.GetZ(); |
---|
| 3538 | //up = Vector3(0, 0, leg2_v.GetZ()); |
---|
[760ad29d] | 3539 | //up = right * up; |
---|
| 3540 | up = up_v; |
---|
[3ddcad8] | 3541 | } else { |
---|
| 3542 | up = up_v; |
---|
[da6c802] | 3543 | } |
---|
[3ddcad8] | 3544 | last_right = right; |
---|
[d4650b3] | 3545 | static_date_hack = pt_v.GetDate(); |
---|
[da6c802] | 3546 | } |
---|
| 3547 | |
---|
[3ddcad8] | 3548 | // Scale to unit vectors in the LRUD plane. |
---|
| 3549 | right.normalise(); |
---|
| 3550 | up.normalise(); |
---|
[33b2094] | 3551 | |
---|
[3ddcad8] | 3552 | if (z_pitch_adjust != 0) up += Vector3(0, 0, fabs(z_pitch_adjust)); |
---|
[ce2f3ce] | 3553 | |
---|
[57a3cd4] | 3554 | Double l = fabs(pt_v.GetL()); |
---|
| 3555 | Double r = fabs(pt_v.GetR()); |
---|
| 3556 | Double u = fabs(pt_v.GetU()); |
---|
| 3557 | Double d = fabs(pt_v.GetD()); |
---|
[3ddcad8] | 3558 | |
---|
| 3559 | // Produce coordinates of the corners of the LRUD "plane". |
---|
| 3560 | Vector3 v[4]; |
---|
[d67450e] | 3561 | v[0] = pt_v - right * l + up * u; |
---|
| 3562 | v[1] = pt_v + right * r + up * u; |
---|
| 3563 | v[2] = pt_v + right * r - up * d; |
---|
| 3564 | v[3] = pt_v - right * l - up * d; |
---|
[3ddcad8] | 3565 | |
---|
[384534c] | 3566 | if (draw) { |
---|
[cc9e2c65] | 3567 | const Vector3 & delta = pt_v - prev_pt_v; |
---|
| 3568 | static_length_hack = delta.magnitude(); |
---|
| 3569 | static_gradient_hack = delta.gradient(); |
---|
[384534c] | 3570 | if (segment > 0) { |
---|
| 3571 | (this->*AddQuad)(v[0], v[1], U[1], U[0]); |
---|
| 3572 | (this->*AddQuad)(v[2], v[3], U[3], U[2]); |
---|
| 3573 | (this->*AddQuad)(v[1], v[2], U[2], U[1]); |
---|
| 3574 | (this->*AddQuad)(v[3], v[0], U[0], U[3]); |
---|
| 3575 | } |
---|
[9eb58d0] | 3576 | |
---|
[384534c] | 3577 | if (cover_end) { |
---|
| 3578 | (this->*AddQuad)(v[3], v[2], v[1], v[0]); |
---|
| 3579 | } |
---|
[3ddcad8] | 3580 | } |
---|
[9eb58d0] | 3581 | |
---|
[3ddcad8] | 3582 | prev_pt_v = pt_v; |
---|
| 3583 | U[0] = v[0]; |
---|
| 3584 | U[1] = v[1]; |
---|
| 3585 | U[2] = v[2]; |
---|
| 3586 | U[3] = v[3]; |
---|
[9eb58d0] | 3587 | |
---|
[fc68ad5] | 3588 | pt_v.set_right_bearing(deg(atan2(right.GetY(), right.GetX()))); |
---|
| 3589 | |
---|
[3ddcad8] | 3590 | ++segment; |
---|
| 3591 | } |
---|
[33b2094] | 3592 | } |
---|
[b13aee4] | 3593 | |
---|
| 3594 | void GfxCore::FullScreenMode() |
---|
| 3595 | { |
---|
[ea940373] | 3596 | m_Parent->ViewFullScreen(); |
---|
[b13aee4] | 3597 | } |
---|
[fdfa926] | 3598 | |
---|
| 3599 | bool GfxCore::IsFullScreen() const |
---|
| 3600 | { |
---|
| 3601 | return m_Parent->IsFullScreen(); |
---|
| 3602 | } |
---|
[1690fa9] | 3603 | |
---|
[b75a37d] | 3604 | bool GfxCore::FullScreenModeShowingMenus() const |
---|
| 3605 | { |
---|
| 3606 | return m_Parent->FullScreenModeShowingMenus(); |
---|
| 3607 | } |
---|
| 3608 | |
---|
| 3609 | void GfxCore::FullScreenModeShowMenus(bool show) |
---|
| 3610 | { |
---|
| 3611 | m_Parent->FullScreenModeShowMenus(show); |
---|
| 3612 | } |
---|
| 3613 | |
---|
[46361bc] | 3614 | void |
---|
| 3615 | GfxCore::MoveViewer(double forward, double up, double right) |
---|
| 3616 | { |
---|
[e577f89] | 3617 | double cT = cos(rad(m_TiltAngle)); |
---|
| 3618 | double sT = sin(rad(m_TiltAngle)); |
---|
| 3619 | double cP = cos(rad(m_PanAngle)); |
---|
| 3620 | double sP = sin(rad(m_PanAngle)); |
---|
[7a57dc7] | 3621 | Vector3 v_forward(cT * sP, cT * cP, sT); |
---|
| 3622 | Vector3 v_up(sT * sP, sT * cP, -cT); |
---|
[867a1141] | 3623 | Vector3 v_right(-cP, sP, 0); |
---|
[d4a5aaf] | 3624 | assert(fabs(dot(v_forward, v_up)) < 1e-6); |
---|
| 3625 | assert(fabs(dot(v_forward, v_right)) < 1e-6); |
---|
| 3626 | assert(fabs(dot(v_right, v_up)) < 1e-6); |
---|
[46361bc] | 3627 | Vector3 move = v_forward * forward + v_up * up + v_right * right; |
---|
[d67450e] | 3628 | AddTranslation(-move); |
---|
[d877aa2] | 3629 | // Show current position. |
---|
[d67450e] | 3630 | m_Parent->SetCoords(m_Parent->GetOffset() - GetTranslation()); |
---|
[46361bc] | 3631 | ForceRefresh(); |
---|
| 3632 | } |
---|
| 3633 | |
---|
[1690fa9] | 3634 | PresentationMark GfxCore::GetView() const |
---|
| 3635 | { |
---|
[d67450e] | 3636 | return PresentationMark(GetTranslation() + m_Parent->GetOffset(), |
---|
[7a57dc7] | 3637 | m_PanAngle, -m_TiltAngle, m_Scale); |
---|
[1690fa9] | 3638 | } |
---|
| 3639 | |
---|
| 3640 | void GfxCore::SetView(const PresentationMark & p) |
---|
| 3641 | { |
---|
| 3642 | m_SwitchingTo = 0; |
---|
[d67450e] | 3643 | SetTranslation(p - m_Parent->GetOffset()); |
---|
[1690fa9] | 3644 | m_PanAngle = p.angle; |
---|
[7a57dc7] | 3645 | m_TiltAngle = -p.tilt_angle; // FIXME: nasty reversed sense (and above) |
---|
[08253d9] | 3646 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[1690fa9] | 3647 | SetScale(p.scale); |
---|
| 3648 | ForceRefresh(); |
---|
| 3649 | } |
---|
| 3650 | |
---|
[128fac4] | 3651 | void GfxCore::PlayPres(double speed, bool change_speed) { |
---|
| 3652 | if (!change_speed || presentation_mode == 0) { |
---|
| 3653 | if (speed == 0.0) { |
---|
| 3654 | presentation_mode = 0; |
---|
| 3655 | return; |
---|
| 3656 | } |
---|
| 3657 | presentation_mode = PLAYING; |
---|
| 3658 | next_mark = m_Parent->GetPresMark(MARK_FIRST); |
---|
| 3659 | SetView(next_mark); |
---|
| 3660 | next_mark_time = 0; // There already! |
---|
| 3661 | this_mark_total = 0; |
---|
| 3662 | pres_reverse = (speed < 0); |
---|
| 3663 | } |
---|
| 3664 | |
---|
[d67450e] | 3665 | if (change_speed) pres_speed = speed; |
---|
| 3666 | |
---|
[128fac4] | 3667 | if (speed != 0.0) { |
---|
| 3668 | bool new_pres_reverse = (speed < 0); |
---|
| 3669 | if (new_pres_reverse != pres_reverse) { |
---|
| 3670 | pres_reverse = new_pres_reverse; |
---|
| 3671 | if (pres_reverse) { |
---|
| 3672 | next_mark = m_Parent->GetPresMark(MARK_PREV); |
---|
| 3673 | } else { |
---|
| 3674 | next_mark = m_Parent->GetPresMark(MARK_NEXT); |
---|
| 3675 | } |
---|
| 3676 | swap(this_mark_total, next_mark_time); |
---|
| 3677 | } |
---|
| 3678 | } |
---|
[1690fa9] | 3679 | } |
---|
[6a4cdcb6] | 3680 | |
---|
[da6c802] | 3681 | void GfxCore::SetColourBy(int colour_by) { |
---|
| 3682 | m_ColourBy = colour_by; |
---|
| 3683 | switch (colour_by) { |
---|
| 3684 | case COLOUR_BY_DEPTH: |
---|
| 3685 | AddQuad = &GfxCore::AddQuadrilateralDepth; |
---|
| 3686 | AddPoly = &GfxCore::AddPolylineDepth; |
---|
| 3687 | break; |
---|
[d4650b3] | 3688 | case COLOUR_BY_DATE: |
---|
| 3689 | AddQuad = &GfxCore::AddQuadrilateralDate; |
---|
| 3690 | AddPoly = &GfxCore::AddPolylineDate; |
---|
| 3691 | break; |
---|
[c61aa79] | 3692 | case COLOUR_BY_ERROR: |
---|
| 3693 | AddQuad = &GfxCore::AddQuadrilateralError; |
---|
| 3694 | AddPoly = &GfxCore::AddPolylineError; |
---|
| 3695 | break; |
---|
[cc9e2c65] | 3696 | case COLOUR_BY_GRADIENT: |
---|
| 3697 | AddQuad = &GfxCore::AddQuadrilateralGradient; |
---|
| 3698 | AddPoly = &GfxCore::AddPolylineGradient; |
---|
| 3699 | break; |
---|
[af50685] | 3700 | case COLOUR_BY_LENGTH: |
---|
| 3701 | AddQuad = &GfxCore::AddQuadrilateralLength; |
---|
| 3702 | AddPoly = &GfxCore::AddPolylineLength; |
---|
| 3703 | break; |
---|
[da6c802] | 3704 | default: // case COLOUR_BY_NONE: |
---|
| 3705 | AddQuad = &GfxCore::AddQuadrilateral; |
---|
| 3706 | AddPoly = &GfxCore::AddPolyline; |
---|
| 3707 | break; |
---|
| 3708 | } |
---|
| 3709 | |
---|
[d2fcc9b] | 3710 | InvalidateList(LIST_UNDERGROUND_LEGS); |
---|
[c61aa79] | 3711 | InvalidateList(LIST_SURFACE_LEGS); |
---|
[d2fcc9b] | 3712 | InvalidateList(LIST_TUBES); |
---|
[da6c802] | 3713 | |
---|
| 3714 | ForceRefresh(); |
---|
| 3715 | } |
---|
| 3716 | |
---|
[6a4cdcb6] | 3717 | bool GfxCore::ExportMovie(const wxString & fnm) |
---|
| 3718 | { |
---|
| 3719 | int width; |
---|
| 3720 | int height; |
---|
| 3721 | GetSize(&width, &height); |
---|
[028829f] | 3722 | // Round up to next multiple of 2 (required by ffmpeg). |
---|
| 3723 | width += (width & 1); |
---|
[6a4cdcb6] | 3724 | height += (height & 1); |
---|
| 3725 | |
---|
[75d4a2b] | 3726 | movie = new MovieMaker(); |
---|
[6a4cdcb6] | 3727 | |
---|
[98a3786] | 3728 | // FIXME: This should really use fn_str() - currently we probably can't |
---|
| 3729 | // save to a Unicode path on wxmsw. |
---|
[75d4a2b] | 3730 | if (!movie->Open(fnm.mb_str(), width, height)) { |
---|
[091069f] | 3731 | wxGetApp().ReportError(wxString(movie->get_error_string(), wxConvUTF8)); |
---|
[75d4a2b] | 3732 | delete movie; |
---|
[81f1266] | 3733 | movie = NULL; |
---|
[6a4cdcb6] | 3734 | return false; |
---|
| 3735 | } |
---|
[f433fda] | 3736 | |
---|
[d10d369] | 3737 | PlayPres(1); |
---|
[6a4cdcb6] | 3738 | return true; |
---|
| 3739 | } |
---|
[223f1ad] | 3740 | |
---|
[ce403f1] | 3741 | void |
---|
| 3742 | GfxCore::OnPrint(const wxString &filename, const wxString &title, |
---|
[4ed8154] | 3743 | const wxString &datestamp, time_t datestamp_numeric, |
---|
[6d3938b] | 3744 | const wxString &cs_proj, |
---|
[4ed8154] | 3745 | bool close_after_print) |
---|
[ce403f1] | 3746 | { |
---|
| 3747 | svxPrintDlg * p; |
---|
[6d3938b] | 3748 | p = new svxPrintDlg(m_Parent, filename, title, cs_proj, |
---|
[f10cf8f] | 3749 | datestamp, datestamp_numeric, |
---|
[ce403f1] | 3750 | m_PanAngle, m_TiltAngle, |
---|
[5624403] | 3751 | m_Names, m_Crosses, m_Legs, m_Surface, m_Tubes, |
---|
[fdea415] | 3752 | m_Entrances, m_FixedPts, m_ExportedPts, |
---|
[4ed8154] | 3753 | true, close_after_print); |
---|
[6d1bc83] | 3754 | p->Show(true); |
---|
[ce403f1] | 3755 | } |
---|
| 3756 | |
---|
[5940815] | 3757 | void |
---|
[70462c8] | 3758 | GfxCore::OnExport(const wxString &filename, const wxString &title, |
---|
[6d3938b] | 3759 | const wxString &datestamp, time_t datestamp_numeric, |
---|
| 3760 | const wxString &cs_proj) |
---|
[223f1ad] | 3761 | { |
---|
[384534c] | 3762 | // Fill in "right_bearing" for each cross-section. |
---|
| 3763 | list<vector<XSect> >::iterator trav = m_Parent->tubes_begin(); |
---|
| 3764 | list<vector<XSect> >::iterator tend = m_Parent->tubes_end(); |
---|
| 3765 | while (trav != tend) { |
---|
| 3766 | SkinPassage(*trav, false); |
---|
| 3767 | ++trav; |
---|
| 3768 | } |
---|
| 3769 | |
---|
[5940815] | 3770 | svxPrintDlg * p; |
---|
[6d3938b] | 3771 | p = new svxPrintDlg(m_Parent, filename, title, cs_proj, |
---|
[f10cf8f] | 3772 | datestamp, datestamp_numeric, |
---|
[5940815] | 3773 | m_PanAngle, m_TiltAngle, |
---|
[5624403] | 3774 | m_Names, m_Crosses, m_Legs, m_Surface, m_Tubes, |
---|
[fdea415] | 3775 | m_Entrances, m_FixedPts, m_ExportedPts, |
---|
[5940815] | 3776 | false); |
---|
[6d1bc83] | 3777 | p->Show(true); |
---|
[223f1ad] | 3778 | } |
---|
[e2c1671] | 3779 | |
---|
| 3780 | static wxCursor |
---|
| 3781 | make_cursor(const unsigned char * bits, const unsigned char * mask, |
---|
| 3782 | int hotx, int hoty) |
---|
| 3783 | { |
---|
[b72f4b5] | 3784 | #if defined __WXMSW__ || defined __WXMAC__ |
---|
[60adbce] | 3785 | # ifdef __WXMAC__ |
---|
| 3786 | // The default Mac cursor is black with a white edge, so |
---|
| 3787 | // invert our custom cursors to match. |
---|
| 3788 | char b[128]; |
---|
| 3789 | for (int i = 0; i < 128; ++i) |
---|
| 3790 | b[i] = bits[i] ^ 0xff; |
---|
| 3791 | # else |
---|
| 3792 | const char * b = reinterpret_cast<const char *>(bits); |
---|
| 3793 | # endif |
---|
| 3794 | wxBitmap cursor_bitmap(b, 32, 32); |
---|
[7f3fe6d] | 3795 | wxBitmap mask_bitmap(reinterpret_cast<const char *>(mask), 32, 32); |
---|
[4dc4384] | 3796 | cursor_bitmap.SetMask(new wxMask(mask_bitmap, *wxWHITE)); |
---|
[e2c1671] | 3797 | wxImage cursor_image = cursor_bitmap.ConvertToImage(); |
---|
| 3798 | cursor_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotx); |
---|
| 3799 | cursor_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hoty); |
---|
[7f3fe6d] | 3800 | return wxCursor(cursor_image); |
---|
[e2c1671] | 3801 | #else |
---|
| 3802 | return wxCursor((const char *)bits, 32, 32, hotx, hoty, |
---|
[4dc4384] | 3803 | (const char *)mask, wxBLACK, wxWHITE); |
---|
[e2c1671] | 3804 | #endif |
---|
| 3805 | } |
---|
| 3806 | |
---|
| 3807 | const |
---|
| 3808 | #include "hand.xbm" |
---|
| 3809 | const |
---|
| 3810 | #include "handmask.xbm" |
---|
| 3811 | |
---|
| 3812 | const |
---|
| 3813 | #include "brotate.xbm" |
---|
| 3814 | const |
---|
| 3815 | #include "brotatemask.xbm" |
---|
| 3816 | |
---|
| 3817 | const |
---|
| 3818 | #include "vrotate.xbm" |
---|
| 3819 | const |
---|
| 3820 | #include "vrotatemask.xbm" |
---|
| 3821 | |
---|
| 3822 | const |
---|
| 3823 | #include "rotate.xbm" |
---|
| 3824 | const |
---|
| 3825 | #include "rotatemask.xbm" |
---|
| 3826 | |
---|
[ecf2d23] | 3827 | const |
---|
| 3828 | #include "rotatezoom.xbm" |
---|
| 3829 | const |
---|
| 3830 | #include "rotatezoommask.xbm" |
---|
| 3831 | |
---|
[e2c1671] | 3832 | void |
---|
[242cb07] | 3833 | GfxCore::UpdateCursor(GfxCore::cursor new_cursor) |
---|
[e2c1671] | 3834 | { |
---|
| 3835 | // Check if we're already showing that cursor. |
---|
| 3836 | if (current_cursor == new_cursor) return; |
---|
| 3837 | |
---|
| 3838 | current_cursor = new_cursor; |
---|
| 3839 | switch (current_cursor) { |
---|
| 3840 | case GfxCore::CURSOR_DEFAULT: |
---|
| 3841 | GLACanvas::SetCursor(wxNullCursor); |
---|
| 3842 | break; |
---|
| 3843 | case GfxCore::CURSOR_POINTING_HAND: |
---|
| 3844 | GLACanvas::SetCursor(wxCursor(wxCURSOR_HAND)); |
---|
| 3845 | break; |
---|
| 3846 | case GfxCore::CURSOR_DRAGGING_HAND: |
---|
| 3847 | GLACanvas::SetCursor(make_cursor(hand_bits, handmask_bits, 12, 18)); |
---|
| 3848 | break; |
---|
| 3849 | case GfxCore::CURSOR_HORIZONTAL_RESIZE: |
---|
| 3850 | GLACanvas::SetCursor(wxCursor(wxCURSOR_SIZEWE)); |
---|
| 3851 | break; |
---|
| 3852 | case GfxCore::CURSOR_ROTATE_HORIZONTALLY: |
---|
| 3853 | GLACanvas::SetCursor(make_cursor(rotate_bits, rotatemask_bits, 15, 15)); |
---|
| 3854 | break; |
---|
| 3855 | case GfxCore::CURSOR_ROTATE_VERTICALLY: |
---|
| 3856 | GLACanvas::SetCursor(make_cursor(vrotate_bits, vrotatemask_bits, 15, 15)); |
---|
| 3857 | break; |
---|
| 3858 | case GfxCore::CURSOR_ROTATE_EITHER_WAY: |
---|
| 3859 | GLACanvas::SetCursor(make_cursor(brotate_bits, brotatemask_bits, 15, 15)); |
---|
| 3860 | break; |
---|
| 3861 | case GfxCore::CURSOR_ZOOM: |
---|
| 3862 | GLACanvas::SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); |
---|
| 3863 | break; |
---|
[ecf2d23] | 3864 | case GfxCore::CURSOR_ZOOM_ROTATE: |
---|
| 3865 | GLACanvas::SetCursor(make_cursor(rotatezoom_bits, rotatezoommask_bits, 15, 15)); |
---|
| 3866 | break; |
---|
[e2c1671] | 3867 | } |
---|
| 3868 | } |
---|
[6b061db] | 3869 | |
---|
| 3870 | bool GfxCore::MeasuringLineActive() const |
---|
| 3871 | { |
---|
| 3872 | if (Animating()) return false; |
---|
[381ae6e] | 3873 | return HereIsReal() || m_there; |
---|
[6b061db] | 3874 | } |
---|
[acdb8aa] | 3875 | |
---|
| 3876 | bool GfxCore::HandleRClick(wxPoint point) |
---|
| 3877 | { |
---|
| 3878 | if (PointWithinCompass(point)) { |
---|
| 3879 | // Pop up menu. |
---|
| 3880 | wxMenu menu; |
---|
[736f7df] | 3881 | /* TRANSLATORS: View *looking* North */ |
---|
[055bfc58] | 3882 | menu.Append(menu_ORIENT_MOVE_NORTH, wmsg(/*View &North*/240)); |
---|
[736f7df] | 3883 | /* TRANSLATORS: View *looking* East */ |
---|
[055bfc58] | 3884 | menu.Append(menu_ORIENT_MOVE_EAST, wmsg(/*View &East*/241)); |
---|
[736f7df] | 3885 | /* TRANSLATORS: View *looking* South */ |
---|
[055bfc58] | 3886 | menu.Append(menu_ORIENT_MOVE_SOUTH, wmsg(/*View &South*/242)); |
---|
[736f7df] | 3887 | /* TRANSLATORS: View *looking* West */ |
---|
[055bfc58] | 3888 | menu.Append(menu_ORIENT_MOVE_WEST, wmsg(/*View &West*/243)); |
---|
| 3889 | menu.AppendSeparator(); |
---|
[736f7df] | 3890 | /* TRANSLATORS: Menu item which turns off the "north arrow" in aven. */ |
---|
[4d2301e] | 3891 | menu.AppendCheckItem(menu_IND_COMPASS, wmsg(/*&Hide Compass*/387)); |
---|
[0b8c321] | 3892 | /* TRANSLATORS: tickable menu item in View menu. |
---|
| 3893 | * |
---|
| 3894 | * Degrees are the angular measurement where there are 360 in a full |
---|
| 3895 | * circle. */ |
---|
[acdb8aa] | 3896 | menu.AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343)); |
---|
[ee3e284] | 3897 | menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&wxEvtHandler::ProcessEvent, NULL, m_Parent->GetEventHandler()); |
---|
[acdb8aa] | 3898 | PopupMenu(&menu); |
---|
| 3899 | return true; |
---|
| 3900 | } |
---|
| 3901 | |
---|
| 3902 | if (PointWithinClino(point)) { |
---|
| 3903 | // Pop up menu. |
---|
| 3904 | wxMenu menu; |
---|
[055bfc58] | 3905 | menu.Append(menu_ORIENT_PLAN, wmsg(/*&Plan View*/248)); |
---|
| 3906 | menu.Append(menu_ORIENT_ELEVATION, wmsg(/*Ele&vation*/249)); |
---|
| 3907 | menu.AppendSeparator(); |
---|
[736f7df] | 3908 | /* TRANSLATORS: Menu item which turns off the tilt indicator in aven. */ |
---|
[acdb8aa] | 3909 | menu.AppendCheckItem(menu_IND_CLINO, wmsg(/*&Hide Clino*/384)); |
---|
[736f7df] | 3910 | /* TRANSLATORS: tickable menu item in View menu. |
---|
| 3911 | * |
---|
| 3912 | * Degrees are the angular measurement where there are 360 in a full |
---|
| 3913 | * circle. */ |
---|
[acdb8aa] | 3914 | menu.AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343)); |
---|
[736f7df] | 3915 | /* TRANSLATORS: tickable menu item in View menu. |
---|
| 3916 | * |
---|
| 3917 | * Show the tilt of the survey as a percentage gradient (100% = 45 |
---|
| 3918 | * degrees = 50 grad). */ |
---|
[d171c0c] | 3919 | menu.AppendCheckItem(menu_CTL_PERCENT, wmsg(/*&Percent*/430)); |
---|
[ee3e284] | 3920 | menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&wxEvtHandler::ProcessEvent, NULL, m_Parent->GetEventHandler()); |
---|
| 3921 | PopupMenu(&menu); |
---|
[acdb8aa] | 3922 | return true; |
---|
| 3923 | } |
---|
| 3924 | |
---|
| 3925 | if (PointWithinScaleBar(point)) { |
---|
| 3926 | // Pop up menu. |
---|
| 3927 | wxMenu menu; |
---|
[736f7df] | 3928 | /* TRANSLATORS: Menu item which turns off the scale bar in aven. */ |
---|
[acdb8aa] | 3929 | menu.AppendCheckItem(menu_IND_SCALE_BAR, wmsg(/*&Hide scale bar*/385)); |
---|
[0b8c321] | 3930 | /* TRANSLATORS: tickable menu item in View menu. |
---|
| 3931 | * |
---|
| 3932 | * "Metric" here means metres, km, etc (rather than feet, miles, etc) |
---|
| 3933 | */ |
---|
[acdb8aa] | 3934 | menu.AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342)); |
---|
[ee3e284] | 3935 | menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&wxEvtHandler::ProcessEvent, NULL, m_Parent->GetEventHandler()); |
---|
[acdb8aa] | 3936 | PopupMenu(&menu); |
---|
| 3937 | return true; |
---|
| 3938 | } |
---|
| 3939 | |
---|
| 3940 | if (PointWithinColourKey(point)) { |
---|
| 3941 | // Pop up menu. |
---|
| 3942 | wxMenu menu; |
---|
[46beda0] | 3943 | menu.AppendCheckItem(menu_COLOUR_BY_DEPTH, wmsg(/*Colour by &Depth*/292)); |
---|
| 3944 | menu.AppendCheckItem(menu_COLOUR_BY_DATE, wmsg(/*Colour by D&ate*/293)); |
---|
| 3945 | menu.AppendCheckItem(menu_COLOUR_BY_ERROR, wmsg(/*Colour by &Error*/289)); |
---|
| 3946 | menu.AppendCheckItem(menu_COLOUR_BY_GRADIENT, wmsg(/*Colour by &Gradient*/85)); |
---|
| 3947 | menu.AppendCheckItem(menu_COLOUR_BY_LENGTH, wmsg(/*Colour by &Length*/82)); |
---|
[d43fa84] | 3948 | menu.AppendSeparator(); |
---|
[736f7df] | 3949 | /* TRANSLATORS: Menu item which turns off the colour key. |
---|
| 3950 | * The "Colour Key" is the thing in aven showing which colour |
---|
| 3951 | * corresponds to which depth, date, survey closure error, etc. */ |
---|
[97ea48d] | 3952 | menu.AppendCheckItem(menu_IND_COLOUR_KEY, wmsg(/*&Hide colour key*/386)); |
---|
[391af6a] | 3953 | if (m_ColourBy == COLOUR_BY_DEPTH || m_ColourBy == COLOUR_BY_LENGTH) |
---|
[d43fa84] | 3954 | menu.AppendCheckItem(menu_CTL_METRIC, wmsg(/*&Metric*/342)); |
---|
[cc9e2c65] | 3955 | else if (m_ColourBy == COLOUR_BY_GRADIENT) |
---|
| 3956 | menu.AppendCheckItem(menu_CTL_DEGREES, wmsg(/*&Degrees*/343)); |
---|
[ee3e284] | 3957 | menu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction)&wxEvtHandler::ProcessEvent, NULL, m_Parent->GetEventHandler()); |
---|
[acdb8aa] | 3958 | PopupMenu(&menu); |
---|
| 3959 | return true; |
---|
| 3960 | } |
---|
| 3961 | |
---|
| 3962 | return false; |
---|
| 3963 | } |
---|
[dd6af8b] | 3964 | |
---|
| 3965 | void GfxCore::SetZoomBox(wxPoint p1, wxPoint p2, bool centred, bool aspect) |
---|
| 3966 | { |
---|
| 3967 | if (centred) { |
---|
| 3968 | p1.x = p2.x + (p1.x - p2.x) * 2; |
---|
| 3969 | p1.y = p2.y + (p1.y - p2.y) * 2; |
---|
| 3970 | } |
---|
| 3971 | if (aspect) { |
---|
| 3972 | #if 0 // FIXME: This needs more work. |
---|
| 3973 | int sx = GetXSize(); |
---|
| 3974 | int sy = GetYSize(); |
---|
| 3975 | int dx = p1.x - p2.x; |
---|
| 3976 | int dy = p1.y - p2.y; |
---|
| 3977 | int dy_new = dx * sy / sx; |
---|
| 3978 | if (abs(dy_new) >= abs(dy)) { |
---|
| 3979 | p1.y += (dy_new - dy) / 2; |
---|
| 3980 | p2.y -= (dy_new - dy) / 2; |
---|
| 3981 | } else { |
---|
| 3982 | int dx_new = dy * sx / sy; |
---|
| 3983 | p1.x += (dx_new - dx) / 2; |
---|
| 3984 | p2.x -= (dx_new - dx) / 2; |
---|
| 3985 | } |
---|
| 3986 | #endif |
---|
| 3987 | } |
---|
| 3988 | zoombox.set(p1, p2); |
---|
| 3989 | ForceRefresh(); |
---|
| 3990 | } |
---|
| 3991 | |
---|
| 3992 | void GfxCore::ZoomBoxGo() |
---|
| 3993 | { |
---|
| 3994 | if (!zoombox.active()) return; |
---|
| 3995 | |
---|
| 3996 | int width = GetXSize(); |
---|
| 3997 | int height = GetYSize(); |
---|
| 3998 | |
---|
| 3999 | TranslateCave(-0.5 * (zoombox.x1 + zoombox.x2 - width), |
---|
| 4000 | -0.5 * (zoombox.y1 + zoombox.y2 - height)); |
---|
| 4001 | int box_w = abs(zoombox.x1 - zoombox.x2); |
---|
| 4002 | int box_h = abs(zoombox.y1 - zoombox.y2); |
---|
| 4003 | |
---|
| 4004 | double factor = min(double(width) / box_w, double(height) / box_h); |
---|
| 4005 | |
---|
| 4006 | zoombox.unset(); |
---|
| 4007 | |
---|
| 4008 | SetScale(GetScale() * factor); |
---|
| 4009 | } |
---|