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