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