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