[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 |
---|
[08253d9] | 7 | // Copyright (C) 2001-2003,2004,2005,2006,2007 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" |
---|
[5809313] | 33 | #include "gfxcore.h" |
---|
[137bf99] | 34 | #include "mainfrm.h" |
---|
[93c3f97] | 35 | #include "message.h" |
---|
[7a89dc2] | 36 | #include "useful.h" |
---|
[ce403f1] | 37 | #include "printwx.h" |
---|
[5876fcb] | 38 | #include "guicontrol.h" |
---|
[6a4cdcb6] | 39 | #include "moviemaker.h" |
---|
[8000d8f] | 40 | |
---|
| 41 | #include <wx/confbase.h> |
---|
| 42 | #include <wx/image.h> |
---|
[5809313] | 43 | |
---|
[db4b33c] | 44 | #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
---|
[003d953] | 45 | #define MAX3(a, b, c) ((a) > (b) ? MAX(a, c) : MAX(b, c)) |
---|
[5809313] | 46 | |
---|
[3d00693] | 47 | // Values for m_SwitchingTo |
---|
| 48 | #define PLAN 1 |
---|
| 49 | #define ELEVATION 2 |
---|
[3ddd351] | 50 | #define NORTH 3 |
---|
| 51 | #define EAST 4 |
---|
| 52 | #define SOUTH 5 |
---|
| 53 | #define WEST 6 |
---|
[3d00693] | 54 | |
---|
[c61aa79] | 55 | // Any error value higher than this is clamped to this. |
---|
| 56 | #define MAX_ERROR 12.0 |
---|
| 57 | |
---|
[86cdcf2] | 58 | // How many bins per letter height to use when working out non-overlapping |
---|
| 59 | // labels. |
---|
| 60 | const unsigned int QUANTISE_FACTOR = 2; |
---|
| 61 | |
---|
[2c22bf8] | 62 | const int NUM_DEPTH_COLOURS = 13; |
---|
| 63 | |
---|
[0e69efe] | 64 | #include "avenpal.h" |
---|
| 65 | |
---|
[6606406] | 66 | static const int COMPASS_OFFSET_X = 60; |
---|
| 67 | static const int COMPASS_OFFSET_Y = 80; |
---|
| 68 | static const int INDICATOR_BOX_SIZE = 60; |
---|
[c300a04] | 69 | static const int INDICATOR_GAP = 2; |
---|
[6606406] | 70 | static const int INDICATOR_MARGIN = 5; |
---|
| 71 | static const int INDICATOR_OFFSET_X = 15; |
---|
[c300a04] | 72 | static const int INDICATOR_OFFSET_Y = 15; |
---|
[fe665c4] | 73 | static const int INDICATOR_RADIUS = INDICATOR_BOX_SIZE / 2 - INDICATOR_MARGIN; |
---|
[dde4fe7] | 74 | static const int CLINO_OFFSET_X = 6 + INDICATOR_OFFSET_X + |
---|
[429465a] | 75 | INDICATOR_BOX_SIZE + INDICATOR_GAP; |
---|
[42adb19] | 76 | static const int DEPTH_BAR_OFFSET_X = 16; |
---|
| 77 | static const int DEPTH_BAR_EXTRA_LEFT_MARGIN = 2; |
---|
[c300a04] | 78 | static const int DEPTH_BAR_BLOCK_WIDTH = 20; |
---|
| 79 | static const int DEPTH_BAR_BLOCK_HEIGHT = 15; |
---|
[42adb19] | 80 | static const int DEPTH_BAR_MARGIN = 6; |
---|
| 81 | static const int DEPTH_BAR_OFFSET_Y = 16 + DEPTH_BAR_MARGIN; |
---|
[b56df45] | 82 | static const int TICK_LENGTH = 4; |
---|
[42adb19] | 83 | static const int SCALE_BAR_OFFSET_X = 15; |
---|
| 84 | static const int SCALE_BAR_OFFSET_Y = 12; |
---|
| 85 | static const int SCALE_BAR_HEIGHT = 12; |
---|
[aa048c3] | 86 | |
---|
| 87 | static const gla_colour TEXT_COLOUR = col_GREEN; |
---|
| 88 | static const gla_colour HERE_COLOUR = col_WHITE; |
---|
| 89 | static const gla_colour NAME_COLOUR = col_GREEN; |
---|
[33b2094] | 90 | |
---|
[39e460c9] | 91 | #define HITTEST_SIZE 20 |
---|
| 92 | |
---|
[dde4fe7] | 93 | // vector for lighting angle |
---|
| 94 | static const Vector3 light(.577, .577, .577); |
---|
| 95 | |
---|
[c6d95d8] | 96 | BEGIN_EVENT_TABLE(GfxCore, wxGLCanvas) |
---|
[5809313] | 97 | EVT_PAINT(GfxCore::OnPaint) |
---|
| 98 | EVT_LEFT_DOWN(GfxCore::OnLButtonDown) |
---|
| 99 | EVT_LEFT_UP(GfxCore::OnLButtonUp) |
---|
| 100 | EVT_MIDDLE_DOWN(GfxCore::OnMButtonDown) |
---|
| 101 | EVT_MIDDLE_UP(GfxCore::OnMButtonUp) |
---|
| 102 | EVT_RIGHT_DOWN(GfxCore::OnRButtonDown) |
---|
| 103 | EVT_RIGHT_UP(GfxCore::OnRButtonUp) |
---|
[34d8d1a] | 104 | EVT_MOUSEWHEEL(GfxCore::OnMouseWheel) |
---|
[5809313] | 105 | EVT_MOTION(GfxCore::OnMouseMove) |
---|
[887c26e] | 106 | EVT_LEAVE_WINDOW(GfxCore::OnLeaveWindow) |
---|
[5809313] | 107 | EVT_SIZE(GfxCore::OnSize) |
---|
[a8e9fde] | 108 | EVT_IDLE(GfxCore::OnIdle) |
---|
[4b1fc48] | 109 | EVT_CHAR(GfxCore::OnKeyPress) |
---|
[5809313] | 110 | END_EVENT_TABLE() |
---|
| 111 | |
---|
[5876fcb] | 112 | GfxCore::GfxCore(MainFrm* parent, wxWindow* parent_win, GUIControl* control) : |
---|
[84f1ed1] | 113 | GLACanvas(parent_win, 100), m_HaveData(false) |
---|
[5809313] | 114 | { |
---|
[5876fcb] | 115 | m_Control = control; |
---|
[e2c1671] | 116 | m_ScaleBarWidth = 0; |
---|
[5809313] | 117 | m_Parent = parent; |
---|
| 118 | m_DoneFirstShow = false; |
---|
| 119 | m_Crosses = false; |
---|
| 120 | m_Legs = true; |
---|
| 121 | m_Names = false; |
---|
| 122 | m_OverlappingNames = false; |
---|
| 123 | m_Compass = true; |
---|
[c300a04] | 124 | m_Clino = true; |
---|
[5809313] | 125 | m_Depthbar = true; |
---|
| 126 | m_Scalebar = true; |
---|
| 127 | m_LabelGrid = NULL; |
---|
| 128 | m_Rotating = false; |
---|
[3d00693] | 129 | m_SwitchingTo = 0; |
---|
[fe444b8] | 130 | m_Entrances = false; |
---|
| 131 | m_FixedPts = false; |
---|
| 132 | m_ExportedPts = false; |
---|
[33b2094] | 133 | m_Tubes = false; |
---|
[c1cf79d] | 134 | m_Grid = false; |
---|
[f4c5932] | 135 | m_BoundingBox = false; |
---|
[da6c802] | 136 | m_ColourBy = COLOUR_BY_DEPTH; |
---|
| 137 | AddQuad = &GfxCore::AddQuadrilateralDepth; |
---|
| 138 | AddPoly = &GfxCore::AddPolylineDepth; |
---|
[5627cbb] | 139 | wxConfigBase::Get()->Read(wxT("metric"), &m_Metric, true); |
---|
| 140 | wxConfigBase::Get()->Read(wxT("degrees"), &m_Degrees, true); |
---|
[d67450e] | 141 | m_here.Invalidate(); |
---|
| 142 | m_there.Invalidate(); |
---|
[1690fa9] | 143 | presentation_mode = 0; |
---|
[01d91fd] | 144 | pres_speed = 0.0; |
---|
| 145 | pres_reverse = false; |
---|
[6a4cdcb6] | 146 | mpeg = NULL; |
---|
[e2c1671] | 147 | current_cursor = GfxCore::CURSOR_DEFAULT; |
---|
[5809313] | 148 | |
---|
[39e460c9] | 149 | // Initialise grid for hit testing. |
---|
[fa42426] | 150 | m_PointGrid = new list<LabelInfo*>[HITTEST_SIZE * HITTEST_SIZE]; |
---|
[0e69efe] | 151 | |
---|
| 152 | m_Pens = new GLAPen[NUM_DEPTH_COLOURS + 1]; |
---|
| 153 | for (int pen = 0; pen < NUM_DEPTH_COLOURS + 1; ++pen) { |
---|
| 154 | m_Pens[pen].SetColour(REDS[pen] / 255.0, |
---|
| 155 | GREENS[pen] / 255.0, |
---|
| 156 | BLUES[pen] / 255.0); |
---|
| 157 | } |
---|
[5809313] | 158 | } |
---|
| 159 | |
---|
| 160 | GfxCore::~GfxCore() |
---|
| 161 | { |
---|
| 162 | TryToFreeArrays(); |
---|
[156dc16] | 163 | |
---|
[0e69efe] | 164 | delete[] m_Pens; |
---|
[39e460c9] | 165 | delete[] m_PointGrid; |
---|
[5809313] | 166 | } |
---|
| 167 | |
---|
| 168 | void GfxCore::TryToFreeArrays() |
---|
| 169 | { |
---|
| 170 | // Free up any memory allocated for arrays. |
---|
| 171 | |
---|
[815eab2] | 172 | if (m_LabelGrid) { |
---|
[9eb58d0] | 173 | delete[] m_LabelGrid; |
---|
[815eab2] | 174 | m_LabelGrid = NULL; |
---|
[5809313] | 175 | } |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | // |
---|
| 179 | // Initialisation methods |
---|
| 180 | // |
---|
| 181 | |
---|
[0c6bf5e8] | 182 | void GfxCore::Initialise(bool same_file) |
---|
[5809313] | 183 | { |
---|
| 184 | // Initialise the view from the parent holding the survey data. |
---|
| 185 | |
---|
| 186 | TryToFreeArrays(); |
---|
| 187 | |
---|
[33b2094] | 188 | m_DoneFirstShow = false; |
---|
| 189 | |
---|
[dfe4454c] | 190 | m_HitTestGridValid = false; |
---|
[d35144d] | 191 | m_here_is_temporary = true; |
---|
[d67450e] | 192 | m_here.Invalidate(); |
---|
| 193 | m_there.Invalidate(); |
---|
[dfe4454c] | 194 | |
---|
[d35144d] | 195 | m_MouseOutsideCompass = m_MouseOutsideElev = false; |
---|
| 196 | |
---|
[0c6bf5e8] | 197 | if (!same_file) { |
---|
| 198 | // Apply default parameters unless reloading the same file. |
---|
| 199 | DefaultParameters(); |
---|
| 200 | |
---|
| 201 | // Set the initial scale. |
---|
| 202 | SetScale(1.0); |
---|
| 203 | } |
---|
[9eb58d0] | 204 | |
---|
[125c9ea] | 205 | switch (m_ColourBy) { |
---|
| 206 | case COLOUR_BY_DEPTH: |
---|
[78c67a6] | 207 | if (m_Parent->GetDepthExtent() == 0.0) { |
---|
[125c9ea] | 208 | SetColourBy(COLOUR_BY_NONE); |
---|
| 209 | } |
---|
| 210 | break; |
---|
| 211 | case COLOUR_BY_DATE: |
---|
| 212 | if (m_Parent->GetDateExtent() == 0) { |
---|
| 213 | SetColourBy(COLOUR_BY_NONE); |
---|
| 214 | } |
---|
| 215 | break; |
---|
[c61aa79] | 216 | case COLOUR_BY_ERROR: |
---|
| 217 | if (!m_Parent->HasErrorInformation()) { |
---|
| 218 | SetColourBy(COLOUR_BY_NONE); |
---|
| 219 | } |
---|
| 220 | break; |
---|
[bd21214] | 221 | } |
---|
| 222 | |
---|
[9eb58d0] | 223 | m_HaveData = true; |
---|
[936a197] | 224 | |
---|
| 225 | ForceRefresh(); |
---|
[9eb58d0] | 226 | } |
---|
| 227 | |
---|
| 228 | void GfxCore::FirstShow() |
---|
| 229 | { |
---|
| 230 | GLACanvas::FirstShow(); |
---|
| 231 | |
---|
[8bd480e] | 232 | const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR); |
---|
[86cdcf2] | 233 | list<LabelInfo*>::iterator pos = m_Parent->GetLabelsNC(); |
---|
| 234 | while (pos != m_Parent->GetLabelsNCEnd()) { |
---|
| 235 | LabelInfo* label = *pos++; |
---|
| 236 | // Calculate and set the label width for use when plotting |
---|
| 237 | // none-overlapping labels. |
---|
| 238 | int ext_x; |
---|
| 239 | GLACanvas::GetTextExtent(label->GetText(), &ext_x, NULL); |
---|
[5a24583] | 240 | label->set_width(unsigned(ext_x) / quantise + 1); |
---|
[86cdcf2] | 241 | } |
---|
| 242 | |
---|
[9eb58d0] | 243 | SetBackgroundColour(0.0, 0.0, 0.0); |
---|
[1690fa9] | 244 | |
---|
[c5fc8eb] | 245 | // Set diameter of the viewing volume. |
---|
| 246 | SetVolumeDiameter(sqrt(sqrd(m_Parent->GetXExtent()) + |
---|
| 247 | sqrd(m_Parent->GetYExtent()) + |
---|
| 248 | sqrd(m_Parent->GetZExtent()))); |
---|
[9eb58d0] | 249 | |
---|
| 250 | // Update our record of the client area size and centre. |
---|
| 251 | GetClientSize(&m_XSize, &m_YSize); |
---|
| 252 | |
---|
[5809313] | 253 | m_DoneFirstShow = true; |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | // |
---|
| 257 | // Recalculating methods |
---|
| 258 | // |
---|
| 259 | |
---|
[cd6ea75] | 260 | void GfxCore::SetScale(Double scale) |
---|
[5047c53] | 261 | { |
---|
| 262 | // Fill the plot data arrays with screen coordinates, scaling the survey |
---|
| 263 | // to a particular absolute scale. |
---|
[421b7d2] | 264 | |
---|
[8b0d57f] | 265 | if (scale < 0.05) { |
---|
| 266 | scale = 0.05; |
---|
[8a03058] | 267 | } else { |
---|
[429465a] | 268 | if (scale > 1000.0) scale = 1000.0; |
---|
[5047c53] | 269 | } |
---|
| 270 | |
---|
[5b7164d] | 271 | m_Scale = scale; |
---|
[00a68e0] | 272 | m_HitTestGridValid = false; |
---|
[c00c6713] | 273 | if (m_here_is_temporary) SetHere(); |
---|
[33b2094] | 274 | |
---|
| 275 | GLACanvas::SetScale(scale); |
---|
[d9b3270] | 276 | } |
---|
| 277 | |
---|
[f433fda] | 278 | bool GfxCore::HasUndergroundLegs() const |
---|
| 279 | { |
---|
| 280 | return m_Parent->HasUndergroundLegs(); |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | bool GfxCore::HasSurfaceLegs() const |
---|
| 284 | { |
---|
| 285 | return m_Parent->HasSurfaceLegs(); |
---|
| 286 | } |
---|
| 287 | |
---|
[50e8979] | 288 | bool GfxCore::HasTubes() const |
---|
| 289 | { |
---|
| 290 | return m_Parent->HasTubes(); |
---|
| 291 | } |
---|
| 292 | |
---|
[d9b3270] | 293 | void GfxCore::UpdateBlobs() |
---|
| 294 | { |
---|
[d2fcc9b] | 295 | InvalidateList(LIST_BLOBS); |
---|
[33b2094] | 296 | } |
---|
| 297 | |
---|
[cd6ea75] | 298 | // |
---|
[5876fcb] | 299 | // Event handlers |
---|
[cd6ea75] | 300 | // |
---|
[5047c53] | 301 | |
---|
[887c26e] | 302 | void GfxCore::OnLeaveWindow(wxMouseEvent& event) { |
---|
| 303 | SetHere(); |
---|
| 304 | ClearCoords(); |
---|
| 305 | } |
---|
| 306 | |
---|
[5876fcb] | 307 | void GfxCore::OnIdle(wxIdleEvent& event) |
---|
| 308 | { |
---|
| 309 | // Handle an idle event. |
---|
[b72f4b5] | 310 | if (Animate()) { |
---|
| 311 | ForceRefresh(); |
---|
| 312 | event.RequestMore(); |
---|
| 313 | } |
---|
[5809313] | 314 | } |
---|
| 315 | |
---|
[b4fe9fb] | 316 | void GfxCore::OnPaint(wxPaintEvent&) |
---|
[5809313] | 317 | { |
---|
| 318 | // Redraw the window. |
---|
[b462168] | 319 | |
---|
| 320 | // Get a graphics context. |
---|
[1b12b82] | 321 | wxPaintDC dc(this); |
---|
[5809313] | 322 | |
---|
[8abf9bb] | 323 | assert(GetContext()); |
---|
| 324 | |
---|
[815eab2] | 325 | if (m_HaveData) { |
---|
[01d91fd] | 326 | // Make sure we're initialised. |
---|
| 327 | bool first_time = !m_DoneFirstShow; |
---|
| 328 | if (first_time) { |
---|
| 329 | FirstShow(); |
---|
| 330 | } |
---|
| 331 | |
---|
[58dfdd21] | 332 | StartDrawing(); |
---|
| 333 | |
---|
| 334 | // Clear the background. |
---|
| 335 | Clear(); |
---|
| 336 | |
---|
[429465a] | 337 | // Set up model transformation matrix. |
---|
| 338 | SetDataTransform(); |
---|
| 339 | |
---|
[9eb58d0] | 340 | timer.Start(); // reset timer |
---|
[203d2a7] | 341 | |
---|
[429465a] | 342 | if (m_Legs || m_Tubes) { |
---|
| 343 | if (m_Tubes) { |
---|
[d67450e] | 344 | EnableSmoothPolygons(true); // FIXME: allow false for wireframe view |
---|
[d2fcc9b] | 345 | DrawList(LIST_TUBES); |
---|
[429465a] | 346 | DisableSmoothPolygons(); |
---|
| 347 | } |
---|
[e4d40792] | 348 | |
---|
[50e8979] | 349 | // Draw the underground legs. Do this last so that anti-aliasing |
---|
[e4d40792] | 350 | // works over polygons. |
---|
| 351 | SetColour(col_GREEN); |
---|
[d2fcc9b] | 352 | DrawList(LIST_UNDERGROUND_LEGS); |
---|
[429465a] | 353 | } |
---|
[33b2094] | 354 | |
---|
[429465a] | 355 | if (m_Surface) { |
---|
| 356 | // Draw the surface legs. |
---|
[d2fcc9b] | 357 | DrawList(LIST_SURFACE_LEGS); |
---|
[429465a] | 358 | } |
---|
[bbc22ca] | 359 | |
---|
[db59b02] | 360 | DrawList(LIST_BLOBS); |
---|
[6adffadf] | 361 | |
---|
[f4c5932] | 362 | if (m_BoundingBox) { |
---|
| 363 | DrawShadowedBoundingBox(); |
---|
| 364 | } |
---|
[429465a] | 365 | if (m_Grid) { |
---|
| 366 | // Draw the grid. |
---|
[37d7084] | 367 | DrawList(LIST_GRID); |
---|
[429465a] | 368 | } |
---|
[b13aee4] | 369 | |
---|
[86fe6e4] | 370 | if (m_Crosses) { |
---|
| 371 | DrawList(LIST_CROSSES); |
---|
| 372 | } |
---|
| 373 | |
---|
[429465a] | 374 | SetIndicatorTransform(); |
---|
| 375 | |
---|
[6adffadf] | 376 | // Draw station names. |
---|
| 377 | if (m_Names /*&& !m_Control->MouseDown() && !Animating()*/) { |
---|
| 378 | SetColour(NAME_COLOUR); |
---|
| 379 | |
---|
| 380 | if (m_OverlappingNames) { |
---|
| 381 | SimpleDrawNames(); |
---|
| 382 | } else { |
---|
| 383 | NattyDrawNames(); |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | |
---|
[d67450e] | 387 | if (!Animating() && (m_here.IsValid() || m_there.IsValid())) { |
---|
[429465a] | 388 | // Draw "here" and "there". |
---|
[aa048c3] | 389 | Double hx, hy; |
---|
| 390 | SetColour(HERE_COLOUR); |
---|
[d67450e] | 391 | if (m_here.IsValid()) { |
---|
[429465a] | 392 | Double dummy; |
---|
[d67450e] | 393 | Transform(m_here, &hx, &hy, &dummy); |
---|
[570d62c3] | 394 | if (!m_here_is_temporary) DrawRing(hx, hy); |
---|
[429465a] | 395 | } |
---|
[d67450e] | 396 | if (m_there.IsValid()) { |
---|
[429465a] | 397 | Double tx, ty; |
---|
| 398 | Double dummy; |
---|
[d67450e] | 399 | Transform(m_there, &tx, &ty, &dummy); |
---|
| 400 | if (m_here.IsValid()) { |
---|
[429465a] | 401 | BeginLines(); |
---|
| 402 | PlaceIndicatorVertex(hx, hy); |
---|
| 403 | PlaceIndicatorVertex(tx, ty); |
---|
[42d23c5] | 404 | EndLines(); |
---|
[429465a] | 405 | } |
---|
[e633bb1] | 406 | BeginBlobs(); |
---|
[81aea4e] | 407 | DrawBlob(tx, ty); |
---|
[e633bb1] | 408 | EndBlobs(); |
---|
[429465a] | 409 | } |
---|
| 410 | } |
---|
[f433fda] | 411 | |
---|
[429465a] | 412 | // Draw indicators. |
---|
[6747314] | 413 | // |
---|
| 414 | // There's no advantage in generating an OpenGL list for the |
---|
| 415 | // indicators since they change with almost every redraw (and |
---|
| 416 | // sometimes several times between redraws). This way we avoid |
---|
| 417 | // the need to track when to update the indicator OpenGL list, |
---|
| 418 | // and also avoid indicator update bugs when we don't quite get this |
---|
| 419 | // right... |
---|
| 420 | DrawIndicators(); |
---|
[33b2094] | 421 | |
---|
[58dfdd21] | 422 | FinishDrawing(); |
---|
| 423 | |
---|
| 424 | drawtime = timer.Time(); |
---|
[5997ffd] | 425 | } else { |
---|
| 426 | dc.SetBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWFRAME)); |
---|
| 427 | dc.Clear(); |
---|
[58dfdd21] | 428 | } |
---|
[5809313] | 429 | } |
---|
| 430 | |
---|
[f4c5932] | 431 | void GfxCore::DrawBoundingBox() |
---|
| 432 | { |
---|
[d67450e] | 433 | const Vector3 v = 0.5 * m_Parent->GetExtent(); |
---|
[f4c5932] | 434 | |
---|
| 435 | SetColour(col_BLUE); |
---|
| 436 | EnableDashedLines(); |
---|
| 437 | BeginPolyline(); |
---|
[d67450e] | 438 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 439 | PlaceVertex(-v.GetX(), v.GetY(), v.GetZ()); |
---|
| 440 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 441 | PlaceVertex(v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 442 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
[f4c5932] | 443 | EndPolyline(); |
---|
| 444 | BeginPolyline(); |
---|
[d67450e] | 445 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 446 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 447 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 448 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 449 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 450 | EndPolyline(); |
---|
| 451 | BeginLines(); |
---|
[d67450e] | 452 | PlaceVertex(-v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 453 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 454 | PlaceVertex(-v.GetX(), v.GetY(), v.GetZ()); |
---|
| 455 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 456 | PlaceVertex(v.GetX(), v.GetY(), v.GetZ()); |
---|
| 457 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 458 | PlaceVertex(v.GetX(), -v.GetY(), v.GetZ()); |
---|
| 459 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 460 | EndLines(); |
---|
| 461 | DisableDashedLines(); |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | void GfxCore::DrawShadowedBoundingBox() |
---|
| 465 | { |
---|
[d67450e] | 466 | const Vector3 v = 0.5 * m_Parent->GetExtent(); |
---|
[f4c5932] | 467 | |
---|
[f7dae86] | 468 | DrawBoundingBox(); |
---|
| 469 | |
---|
[6673525] | 470 | // FIXME: these gl* calls should be in gla-gl.cc |
---|
[f4c5932] | 471 | glPolygonOffset(1.0, 1.0); |
---|
| 472 | glEnable(GL_POLYGON_OFFSET_FILL); |
---|
| 473 | |
---|
| 474 | SetColour(col_DARK_GREY); |
---|
| 475 | BeginQuadrilaterals(); |
---|
[d67450e] | 476 | PlaceVertex(-v.GetX(), -v.GetY(), -v.GetZ()); |
---|
| 477 | PlaceVertex(-v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 478 | PlaceVertex(v.GetX(), v.GetY(), -v.GetZ()); |
---|
| 479 | PlaceVertex(v.GetX(), -v.GetY(), -v.GetZ()); |
---|
[f4c5932] | 480 | EndQuadrilaterals(); |
---|
| 481 | |
---|
| 482 | glDisable(GL_POLYGON_OFFSET_FILL); |
---|
| 483 | |
---|
[d2fcc9b] | 484 | DrawList(LIST_SHADOW); |
---|
[f4c5932] | 485 | } |
---|
| 486 | |
---|
[c1cf79d] | 487 | void GfxCore::DrawGrid() |
---|
| 488 | { |
---|
| 489 | // Draw the grid. |
---|
[156dc16] | 490 | SetColour(col_RED); |
---|
[c1cf79d] | 491 | |
---|
| 492 | // Calculate the extent of the survey, in metres across the screen plane. |
---|
[b81eee2] | 493 | Double m_across_screen = SurveyUnitsAcrossViewport(); |
---|
[c1cf79d] | 494 | // Calculate the length of the scale bar in metres. |
---|
| 495 | //--move this elsewhere |
---|
[c6d95d8] | 496 | Double size_snap = pow(10.0, floor(log10(0.75 * m_across_screen))); |
---|
| 497 | Double t = m_across_screen * 0.75 / size_snap; |
---|
[c1cf79d] | 498 | if (t >= 5.0) { |
---|
[429465a] | 499 | size_snap *= 5.0; |
---|
[c1cf79d] | 500 | } |
---|
| 501 | else if (t >= 2.0) { |
---|
[429465a] | 502 | size_snap *= 2.0; |
---|
[c1cf79d] | 503 | } |
---|
| 504 | |
---|
[d67450e] | 505 | Double grid_size = size_snap * 0.1; |
---|
[c6d95d8] | 506 | Double edge = grid_size * 2.0; |
---|
[d67450e] | 507 | Double grid_z = -m_Parent->GetZExtent() * 0.5 - grid_size; |
---|
| 508 | Double left = -m_Parent->GetXExtent() * 0.5 - edge; |
---|
| 509 | Double right = m_Parent->GetXExtent() * 0.5 + edge; |
---|
| 510 | Double bottom = -m_Parent->GetYExtent() * 0.5 - edge; |
---|
| 511 | Double top = m_Parent->GetYExtent() * 0.5 + edge; |
---|
[c1cf79d] | 512 | int count_x = (int) ceil((right - left) / grid_size); |
---|
| 513 | int count_y = (int) ceil((top - bottom) / grid_size); |
---|
[c6d95d8] | 514 | Double actual_right = left + count_x*grid_size; |
---|
| 515 | Double actual_top = bottom + count_y*grid_size; |
---|
[c1cf79d] | 516 | |
---|
[b81eee2] | 517 | BeginLines(); |
---|
| 518 | |
---|
[c1cf79d] | 519 | for (int xc = 0; xc <= count_x; xc++) { |
---|
[429465a] | 520 | Double x = left + xc*grid_size; |
---|
[f433fda] | 521 | |
---|
[b81eee2] | 522 | PlaceVertex(x, bottom, grid_z); |
---|
| 523 | PlaceVertex(x, actual_top, grid_z); |
---|
[c1cf79d] | 524 | } |
---|
| 525 | |
---|
| 526 | for (int yc = 0; yc <= count_y; yc++) { |
---|
[429465a] | 527 | Double y = bottom + yc*grid_size; |
---|
[b81eee2] | 528 | PlaceVertex(left, y, grid_z); |
---|
| 529 | PlaceVertex(actual_right, y, grid_z); |
---|
[c1cf79d] | 530 | } |
---|
[b81eee2] | 531 | |
---|
| 532 | EndLines(); |
---|
[c1cf79d] | 533 | } |
---|
| 534 | |
---|
[1eeb55a] | 535 | int GfxCore::GetClinoOffset() const |
---|
[c300a04] | 536 | { |
---|
| 537 | return m_Compass ? CLINO_OFFSET_X : INDICATOR_OFFSET_X; |
---|
| 538 | } |
---|
| 539 | |
---|
[fe665c4] | 540 | void GfxCore::DrawTick(int angle_cw) |
---|
[6606406] | 541 | { |
---|
[fe665c4] | 542 | const Double theta = rad(angle_cw); |
---|
| 543 | const wxCoord length1 = INDICATOR_RADIUS; |
---|
| 544 | const wxCoord length0 = length1 + TICK_LENGTH; |
---|
| 545 | wxCoord x0 = wxCoord(length0 * sin(theta)); |
---|
| 546 | wxCoord y0 = wxCoord(length0 * cos(theta)); |
---|
| 547 | wxCoord x1 = wxCoord(length1 * sin(theta)); |
---|
| 548 | wxCoord y1 = wxCoord(length1 * cos(theta)); |
---|
[6606406] | 549 | |
---|
[fe665c4] | 550 | PlaceIndicatorVertex(x0, y0); |
---|
| 551 | PlaceIndicatorVertex(x1, y1); |
---|
[6606406] | 552 | } |
---|
| 553 | |
---|
[d67450e] | 554 | void GfxCore::DrawArrow(gla_colour col1, gla_colour col2) { |
---|
| 555 | Vector3 p1(0, INDICATOR_RADIUS, 0); |
---|
| 556 | Vector3 p2(INDICATOR_RADIUS/2, INDICATOR_RADIUS*-.866025404, 0); // 150deg |
---|
| 557 | Vector3 p3(-INDICATOR_RADIUS/2, INDICATOR_RADIUS*-.866025404, 0); // 210deg |
---|
| 558 | Vector3 pc(0, 0, 0); |
---|
| 559 | |
---|
| 560 | DrawTriangle(col_LIGHT_GREY, col1, p2, p1, pc); |
---|
| 561 | DrawTriangle(col_LIGHT_GREY, col2, p3, p1, pc); |
---|
| 562 | } |
---|
| 563 | |
---|
[fe665c4] | 564 | void GfxCore::DrawCompass() { |
---|
| 565 | // Ticks. |
---|
| 566 | BeginLines(); |
---|
| 567 | for (int angle = 315; angle > 0; angle -= 45) { |
---|
| 568 | DrawTick(angle); |
---|
| 569 | } |
---|
| 570 | SetColour(col_GREEN); |
---|
| 571 | DrawTick(0); |
---|
| 572 | EndLines(); |
---|
| 573 | |
---|
| 574 | // Compass background. |
---|
| 575 | DrawCircle(col_LIGHT_GREY_2, col_GREY, 0, 0, INDICATOR_RADIUS); |
---|
[6606406] | 576 | |
---|
[fe665c4] | 577 | // Compass arrow. |
---|
[d67450e] | 578 | DrawArrow(col_INDICATOR_1, col_INDICATOR_2); |
---|
[6606406] | 579 | } |
---|
| 580 | |
---|
[fe665c4] | 581 | // Draw the non-rotating background to the clino. |
---|
| 582 | void GfxCore::DrawClinoBack() { |
---|
| 583 | BeginLines(); |
---|
| 584 | for (int angle = 0; angle <= 180; angle += 90) { |
---|
| 585 | DrawTick(angle); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | SetColour(col_GREY); |
---|
| 589 | PlaceIndicatorVertex(0, INDICATOR_RADIUS); |
---|
| 590 | PlaceIndicatorVertex(0, -INDICATOR_RADIUS); |
---|
| 591 | PlaceIndicatorVertex(0, 0); |
---|
| 592 | PlaceIndicatorVertex(INDICATOR_RADIUS, 0); |
---|
[b56df45] | 593 | |
---|
[fe665c4] | 594 | EndLines(); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | void GfxCore::DrawClino() { |
---|
| 598 | // Ticks. |
---|
| 599 | SetColour(col_GREEN); |
---|
[33b2094] | 600 | BeginLines(); |
---|
[fe665c4] | 601 | DrawTick(0); |
---|
[33b2094] | 602 | EndLines(); |
---|
[fe665c4] | 603 | |
---|
| 604 | // Clino background. |
---|
| 605 | DrawSemicircle(col_LIGHT_GREY_2, col_GREY, 0, 0, INDICATOR_RADIUS, 0); |
---|
| 606 | |
---|
| 607 | // Elevation arrow. |
---|
[d67450e] | 608 | DrawArrow(col_INDICATOR_2, col_INDICATOR_1); |
---|
[b56df45] | 609 | } |
---|
| 610 | |
---|
[6606406] | 611 | void GfxCore::Draw2dIndicators() |
---|
| 612 | { |
---|
[76dd228] | 613 | // Draw the compass and elevation indicators. |
---|
| 614 | |
---|
| 615 | const int centre_y = INDICATOR_BOX_SIZE / 2 + INDICATOR_OFFSET_Y; |
---|
| 616 | |
---|
[fe665c4] | 617 | const int comp_centre_x = GetCompassXPosition(); |
---|
[6606406] | 618 | |
---|
[eef68f9] | 619 | if (m_Compass && !m_Parent->IsExtendedElevation()) { |
---|
[fe665c4] | 620 | // If the user is dragging the compass with the pointer outside the |
---|
| 621 | // compass, we snap to 45 degree multiples, and the ticks go white. |
---|
[76dd228] | 622 | SetColour(m_MouseOutsideCompass ? col_WHITE : col_LIGHT_GREY_2); |
---|
[fe665c4] | 623 | DrawList2D(LIST_COMPASS, comp_centre_x, centre_y, -m_PanAngle); |
---|
[c300a04] | 624 | } |
---|
[76dd228] | 625 | |
---|
[fe665c4] | 626 | const int elev_centre_x = GetClinoXPosition(); |
---|
[76dd228] | 627 | |
---|
[eef68f9] | 628 | if (m_Clino) { |
---|
[fe665c4] | 629 | // If the user is dragging the clino with the pointer outside the |
---|
| 630 | // clino, we snap to 90 degree multiples, and the ticks go white. |
---|
| 631 | SetColour(m_MouseOutsideElev ? col_WHITE : col_LIGHT_GREY_2); |
---|
| 632 | DrawList2D(LIST_CLINO_BACK, elev_centre_x, centre_y, 0); |
---|
| 633 | DrawList2D(LIST_CLINO, elev_centre_x, centre_y, 90 + m_TiltAngle); |
---|
[c300a04] | 634 | } |
---|
[6606406] | 635 | |
---|
[aa048c3] | 636 | SetColour(TEXT_COLOUR); |
---|
[6606406] | 637 | |
---|
[21958ec] | 638 | static int triple_zero_width = 0; |
---|
| 639 | static int height = 0; |
---|
| 640 | if (!triple_zero_width) { |
---|
[5627cbb] | 641 | GetTextExtent(wxT("000"), &triple_zero_width, &height); |
---|
[21958ec] | 642 | } |
---|
| 643 | const int y_off = INDICATOR_OFFSET_Y + INDICATOR_BOX_SIZE + height / 2; |
---|
[421b7d2] | 644 | |
---|
[eef68f9] | 645 | if (m_Compass && !m_Parent->IsExtendedElevation()) { |
---|
[21958ec] | 646 | wxString str; |
---|
| 647 | int value; |
---|
[429465a] | 648 | if (m_Degrees) { |
---|
[21958ec] | 649 | value = int(m_PanAngle); |
---|
[429465a] | 650 | } else { |
---|
[21958ec] | 651 | value = int(m_PanAngle * 200.0 / 180.0); |
---|
[f433fda] | 652 | } |
---|
[5627cbb] | 653 | str.Printf(wxT("%03d"), value); |
---|
[21958ec] | 654 | DrawIndicatorText(comp_centre_x - triple_zero_width / 2, y_off, str); |
---|
| 655 | |
---|
[5627cbb] | 656 | str = wmsg(/*Facing*/203); |
---|
[21958ec] | 657 | int w; |
---|
[d92d282] | 658 | GetTextExtent(str, &w, NULL); |
---|
[21958ec] | 659 | DrawIndicatorText(comp_centre_x - w / 2, y_off + height, str); |
---|
[c300a04] | 660 | } |
---|
| 661 | |
---|
[eef68f9] | 662 | if (m_Clino) { |
---|
[429465a] | 663 | int angle; |
---|
[21958ec] | 664 | wxString str; |
---|
| 665 | int width; |
---|
[429465a] | 666 | if (m_Degrees) { |
---|
[21958ec] | 667 | static int zero_zero_width = 0; |
---|
| 668 | if (!zero_zero_width) { |
---|
[5627cbb] | 669 | GetTextExtent(wxT("00"), &zero_zero_width, NULL); |
---|
[21958ec] | 670 | } |
---|
| 671 | width = zero_zero_width; |
---|
[e577f89] | 672 | angle = int(-m_TiltAngle); |
---|
[5627cbb] | 673 | str = angle ? wxString::Format(wxT("%+03d"), angle) : wxT("00"); |
---|
[429465a] | 674 | } else { |
---|
[21958ec] | 675 | width = triple_zero_width; |
---|
[e577f89] | 676 | angle = int(-m_TiltAngle * 200.0 / 180.0); |
---|
[5627cbb] | 677 | str = angle ? wxString::Format(wxT("%+04d"), angle) : wxT("000"); |
---|
[f433fda] | 678 | } |
---|
[21958ec] | 679 | |
---|
| 680 | // Adjust horizontal position so the left of the first digit is |
---|
| 681 | // always in the same place. |
---|
| 682 | int sign_offset = 0; |
---|
| 683 | if (angle < 0) { |
---|
| 684 | static int minus_width = 0; |
---|
| 685 | if (!minus_width) { |
---|
[5627cbb] | 686 | GetTextExtent(wxT("-"), &minus_width, NULL); |
---|
[21958ec] | 687 | } |
---|
| 688 | sign_offset = minus_width + 1; |
---|
| 689 | } else if (angle > 0) { |
---|
| 690 | static int plus_width = 0; |
---|
| 691 | if (!plus_width) { |
---|
[5627cbb] | 692 | GetTextExtent(wxT("+"), &plus_width, NULL); |
---|
[21958ec] | 693 | } |
---|
| 694 | sign_offset = plus_width + 1; |
---|
| 695 | } |
---|
| 696 | DrawIndicatorText(elev_centre_x - sign_offset - width / 2, y_off, str); |
---|
| 697 | |
---|
[5627cbb] | 698 | str = wmsg(/*Elevation*/118); |
---|
[21958ec] | 699 | int w; |
---|
[d92d282] | 700 | GetTextExtent(str, &w, NULL); |
---|
[21958ec] | 701 | DrawIndicatorText(elev_centre_x - w / 2, y_off + height, str); |
---|
[c300a04] | 702 | } |
---|
[5809313] | 703 | } |
---|
| 704 | |
---|
| 705 | void GfxCore::NattyDrawNames() |
---|
| 706 | { |
---|
[84cab34] | 707 | // Draw station names, without overlapping. |
---|
[f433fda] | 708 | |
---|
[d92d282] | 709 | const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR); |
---|
| 710 | const unsigned int quantised_x = m_XSize / quantise; |
---|
| 711 | const unsigned int quantised_y = m_YSize / quantise; |
---|
[84cab34] | 712 | const size_t buffer_size = quantised_x * quantised_y; |
---|
[f433fda] | 713 | |
---|
[69463a0] | 714 | if (!m_LabelGrid) m_LabelGrid = new char[buffer_size]; |
---|
[5809313] | 715 | |
---|
[33b2094] | 716 | memset((void*) m_LabelGrid, 0, buffer_size); |
---|
[156dc16] | 717 | |
---|
[33b2094] | 718 | list<LabelInfo*>::const_iterator label = m_Parent->GetLabels(); |
---|
[36c3285] | 719 | for ( ; label != m_Parent->GetLabelsEnd(); ++label) { |
---|
[ece003f] | 720 | if (!((m_Surface && (*label)->IsSurface()) || |
---|
| 721 | (m_Legs && (*label)->IsUnderground()) || |
---|
| 722 | (!(*label)->IsSurface() && !(*label)->IsUnderground()))) { |
---|
| 723 | // if this station isn't to be displayed, skip to the next |
---|
| 724 | // (last case is for stns with no legs attached) |
---|
| 725 | continue; |
---|
| 726 | } |
---|
| 727 | |
---|
[429465a] | 728 | Double x, y, z; |
---|
[f433fda] | 729 | |
---|
[d67450e] | 730 | Transform(**label, &x, &y, &z); |
---|
[36c3285] | 731 | // Check if the label is behind us (in perspective view). |
---|
[d92d282] | 732 | if (z <= 0.0 || z >= 1.0) continue; |
---|
[421b7d2] | 733 | |
---|
[1eeb55a] | 734 | // Apply a small shift so that translating the view doesn't make which |
---|
| 735 | // labels are displayed change as the resulting twinkling effect is |
---|
| 736 | // distracting. |
---|
[429465a] | 737 | Double tx, ty, tz; |
---|
[d67450e] | 738 | Transform(Vector3(), &tx, &ty, &tz); |
---|
[429465a] | 739 | tx -= floor(tx / quantise) * quantise; |
---|
| 740 | ty -= floor(ty / quantise) * quantise; |
---|
[5809313] | 741 | |
---|
[f12e8cc] | 742 | tx = x - tx; |
---|
| 743 | if (tx < 0) continue; |
---|
| 744 | |
---|
| 745 | ty = y - ty; |
---|
| 746 | if (ty < 0) continue; |
---|
[421b7d2] | 747 | |
---|
[f12e8cc] | 748 | unsigned int iy = unsigned(ty) / quantise; |
---|
[d92d282] | 749 | if (iy >= quantised_y) continue; |
---|
[5a24583] | 750 | unsigned int width = (*label)->get_width(); |
---|
[f12e8cc] | 751 | unsigned int ix = unsigned(tx) / quantise; |
---|
| 752 | if (ix + width >= quantised_x) continue; |
---|
[33b2094] | 753 | |
---|
[f12e8cc] | 754 | char * test = m_LabelGrid + ix + iy * quantised_x; |
---|
[d92d282] | 755 | if (memchr(test, 1, width)) continue; |
---|
[33b2094] | 756 | |
---|
[8bd480e] | 757 | x += 3; |
---|
| 758 | y -= GetFontSize() / 2; |
---|
[d92d282] | 759 | DrawIndicatorText((int)x, (int)y, (*label)->GetText()); |
---|
| 760 | |
---|
| 761 | if (iy > QUANTISE_FACTOR) iy = QUANTISE_FACTOR; |
---|
| 762 | test -= quantised_x * iy; |
---|
[f12e8cc] | 763 | iy += 4; |
---|
| 764 | while (--iy && test < m_LabelGrid + buffer_size) { |
---|
[d92d282] | 765 | memset(test, 1, width); |
---|
| 766 | test += quantised_x; |
---|
[429465a] | 767 | } |
---|
[84cab34] | 768 | } |
---|
[5809313] | 769 | } |
---|
| 770 | |
---|
| 771 | void GfxCore::SimpleDrawNames() |
---|
| 772 | { |
---|
[a8aedf4] | 773 | // Draw all station names, without worrying about overlaps |
---|
[d5de678] | 774 | list<LabelInfo*>::const_iterator label = m_Parent->GetLabels(); |
---|
[01d91fd] | 775 | for ( ; label != m_Parent->GetLabelsEnd(); ++label) { |
---|
[ece003f] | 776 | if (!((m_Surface && (*label)->IsSurface()) || |
---|
| 777 | (m_Legs && (*label)->IsUnderground()) || |
---|
| 778 | (!(*label)->IsSurface() && !(*label)->IsUnderground()))) { |
---|
| 779 | // if this station isn't to be displayed, skip to the next |
---|
| 780 | // (last case is for stns with no legs attached) |
---|
| 781 | continue; |
---|
| 782 | } |
---|
| 783 | |
---|
[d92d282] | 784 | Double x, y, z; |
---|
[d67450e] | 785 | Transform(**label, &x, &y, &z); |
---|
[d92d282] | 786 | |
---|
| 787 | // Check if the label is behind us (in perspective view). |
---|
| 788 | if (z <= 0) continue; |
---|
| 789 | |
---|
[8bd480e] | 790 | x += 3; |
---|
| 791 | y -= GetFontSize() / 2; |
---|
[d92d282] | 792 | DrawIndicatorText((int)x, (int)y, (*label)->GetText()); |
---|
[84cab34] | 793 | } |
---|
[5809313] | 794 | } |
---|
| 795 | |
---|
| 796 | void GfxCore::DrawDepthbar() |
---|
| 797 | { |
---|
[76dd228] | 798 | const int total_block_height = |
---|
| 799 | DEPTH_BAR_BLOCK_HEIGHT * (GetNumDepthBands() - 1); |
---|
| 800 | const int top = -(total_block_height + DEPTH_BAR_OFFSET_Y); |
---|
[1eeb55a] | 801 | int size = 0; |
---|
[c300a04] | 802 | |
---|
[0e69efe] | 803 | wxString* strs = new wxString[GetNumDepthBands()]; |
---|
[63dc4eb] | 804 | int band; |
---|
[0e69efe] | 805 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
[78c67a6] | 806 | Double z = m_Parent->GetDepthMin() + m_Parent->GetOffset().GetZ() + |
---|
| 807 | m_Parent->GetDepthExtent() * band / (GetNumDepthBands() - 1); |
---|
[429465a] | 808 | strs[band] = FormatLength(z, false); |
---|
[203d2a7] | 809 | |
---|
[a74b014] | 810 | int x; |
---|
| 811 | GetTextExtent(strs[band], &x, NULL); |
---|
[429465a] | 812 | if (x > size) size = x; |
---|
[c300a04] | 813 | } |
---|
| 814 | |
---|
[76dd228] | 815 | int left = -DEPTH_BAR_OFFSET_X - DEPTH_BAR_BLOCK_WIDTH |
---|
| 816 | - DEPTH_BAR_MARGIN - size; |
---|
[c300a04] | 817 | |
---|
[aa048c3] | 818 | DrawRectangle(col_BLACK, col_DARK_GREY, |
---|
[76dd228] | 819 | left - DEPTH_BAR_MARGIN - DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
| 820 | top - DEPTH_BAR_MARGIN * 2, |
---|
[0e69efe] | 821 | DEPTH_BAR_BLOCK_WIDTH + size + DEPTH_BAR_MARGIN * 3 + |
---|
[429465a] | 822 | DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
[76dd228] | 823 | total_block_height + DEPTH_BAR_MARGIN*4); |
---|
[5809313] | 824 | |
---|
[76dd228] | 825 | int y = top; |
---|
| 826 | for (band = 0; band < GetNumDepthBands() - 1; band++) { |
---|
| 827 | DrawShadedRectangle(GetPen(band), GetPen(band + 1), left, y, |
---|
| 828 | DEPTH_BAR_BLOCK_WIDTH, DEPTH_BAR_BLOCK_HEIGHT); |
---|
| 829 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 830 | } |
---|
[dde4fe7] | 831 | |
---|
[a74b014] | 832 | y = top - GetFontSize() / 2; |
---|
[76dd228] | 833 | left += DEPTH_BAR_BLOCK_WIDTH + 5; |
---|
[5809313] | 834 | |
---|
[76dd228] | 835 | SetColour(TEXT_COLOUR); |
---|
| 836 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
| 837 | DrawIndicatorText(left, y, strs[band]); |
---|
[429465a] | 838 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
[84cab34] | 839 | } |
---|
[c300a04] | 840 | |
---|
| 841 | delete[] strs; |
---|
[5809313] | 842 | } |
---|
| 843 | |
---|
[d4650b3] | 844 | void GfxCore::DrawDatebar() |
---|
| 845 | { |
---|
[a74b014] | 846 | int total_block_height = DEPTH_BAR_BLOCK_HEIGHT * (GetNumDepthBands() - 1); |
---|
| 847 | if (!m_Parent->HasCompleteDateInfo()) |
---|
| 848 | total_block_height += DEPTH_BAR_BLOCK_HEIGHT + DEPTH_BAR_MARGIN; |
---|
[d4650b3] | 849 | const int top = -(total_block_height + DEPTH_BAR_OFFSET_Y); |
---|
[a74b014] | 850 | |
---|
[d4650b3] | 851 | int size = 0; |
---|
[a74b014] | 852 | if (!m_Parent->HasCompleteDateInfo()) { |
---|
[5627cbb] | 853 | GetTextExtent(wxT("No info"), &size, NULL); |
---|
[a74b014] | 854 | } |
---|
[d4650b3] | 855 | |
---|
| 856 | wxString* strs = new wxString[GetNumDepthBands()]; |
---|
| 857 | char buf[128]; |
---|
| 858 | int band; |
---|
| 859 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
| 860 | time_t date = m_Parent->GetDateMin() + |
---|
[60dbe70] | 861 | time_t((double)m_Parent->GetDateExtent() * band / (GetNumDepthBands() - 1)); |
---|
[d4650b3] | 862 | size_t res = strftime(buf, sizeof(buf), "%Y-%m-%d", gmtime(&date)); |
---|
| 863 | // Insert extra "" to avoid trigraphs issues. |
---|
| 864 | if (res == 0 || res == sizeof(buf)) strcpy(buf, "?""?""?""?-?""?-?""?"); |
---|
[5627cbb] | 865 | strs[band] = wxString(buf, wxConvUTF8); |
---|
[d4650b3] | 866 | |
---|
[a74b014] | 867 | int x; |
---|
| 868 | GetTextExtent(strs[band], &x, NULL); |
---|
[d4650b3] | 869 | if (x > size) size = x; |
---|
| 870 | } |
---|
| 871 | |
---|
| 872 | int left = -DEPTH_BAR_OFFSET_X - DEPTH_BAR_BLOCK_WIDTH |
---|
| 873 | - DEPTH_BAR_MARGIN - size; |
---|
| 874 | |
---|
| 875 | DrawRectangle(col_BLACK, col_DARK_GREY, |
---|
| 876 | left - DEPTH_BAR_MARGIN - DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
| 877 | top - DEPTH_BAR_MARGIN * 2, |
---|
| 878 | DEPTH_BAR_BLOCK_WIDTH + size + DEPTH_BAR_MARGIN * 3 + |
---|
| 879 | DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
| 880 | total_block_height + DEPTH_BAR_MARGIN*4); |
---|
| 881 | |
---|
| 882 | int y = top; |
---|
[a74b014] | 883 | |
---|
| 884 | if (!m_Parent->HasCompleteDateInfo()) { |
---|
| 885 | DrawShadedRectangle(GetSurfacePen(), GetSurfacePen(), left, y, |
---|
| 886 | DEPTH_BAR_BLOCK_WIDTH, DEPTH_BAR_BLOCK_HEIGHT); |
---|
| 887 | y += DEPTH_BAR_BLOCK_HEIGHT + DEPTH_BAR_MARGIN; |
---|
| 888 | } |
---|
| 889 | |
---|
[d4650b3] | 890 | for (band = 0; band < GetNumDepthBands() - 1; band++) { |
---|
| 891 | DrawShadedRectangle(GetPen(band), GetPen(band + 1), left, y, |
---|
| 892 | DEPTH_BAR_BLOCK_WIDTH, DEPTH_BAR_BLOCK_HEIGHT); |
---|
| 893 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 894 | } |
---|
| 895 | |
---|
[a74b014] | 896 | y = top - GetFontSize() / 2; |
---|
[d4650b3] | 897 | left += DEPTH_BAR_BLOCK_WIDTH + 5; |
---|
| 898 | |
---|
| 899 | SetColour(TEXT_COLOUR); |
---|
[a74b014] | 900 | |
---|
| 901 | if (!m_Parent->HasCompleteDateInfo()) { |
---|
| 902 | y += DEPTH_BAR_MARGIN; |
---|
[5627cbb] | 903 | DrawIndicatorText(left, y, wxT("No info")); |
---|
[a74b014] | 904 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 905 | } |
---|
| 906 | |
---|
[d4650b3] | 907 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
| 908 | DrawIndicatorText(left, y, strs[band]); |
---|
| 909 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | delete[] strs; |
---|
| 913 | } |
---|
| 914 | |
---|
[c61aa79] | 915 | void GfxCore::DrawErrorbar() |
---|
| 916 | { |
---|
[a74b014] | 917 | int total_block_height = DEPTH_BAR_BLOCK_HEIGHT * (GetNumDepthBands() - 1); |
---|
| 918 | // Always show the "Not a loop" legend for now (FIXME). |
---|
| 919 | total_block_height += DEPTH_BAR_BLOCK_HEIGHT + DEPTH_BAR_MARGIN; |
---|
[c61aa79] | 920 | const int top = -(total_block_height + DEPTH_BAR_OFFSET_Y); |
---|
[a74b014] | 921 | |
---|
[c61aa79] | 922 | int size = 0; |
---|
[5627cbb] | 923 | GetTextExtent(wxT("Not a loop"), &size, NULL); |
---|
[c61aa79] | 924 | |
---|
| 925 | wxString* strs = new wxString[GetNumDepthBands()]; |
---|
| 926 | int band; |
---|
| 927 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
| 928 | double E = MAX_ERROR * band / (GetNumDepthBands() - 1); |
---|
[5627cbb] | 929 | strs[band].Printf(wxT("%.2f"), E); |
---|
[c61aa79] | 930 | |
---|
[a74b014] | 931 | int x; |
---|
| 932 | GetTextExtent(strs[band], &x, NULL); |
---|
[c61aa79] | 933 | if (x > size) size = x; |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | int left = -DEPTH_BAR_OFFSET_X - DEPTH_BAR_BLOCK_WIDTH |
---|
| 937 | - DEPTH_BAR_MARGIN - size; |
---|
| 938 | |
---|
| 939 | DrawRectangle(col_BLACK, col_DARK_GREY, |
---|
| 940 | left - DEPTH_BAR_MARGIN - DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
| 941 | top - DEPTH_BAR_MARGIN * 2, |
---|
| 942 | DEPTH_BAR_BLOCK_WIDTH + size + DEPTH_BAR_MARGIN * 3 + |
---|
| 943 | DEPTH_BAR_EXTRA_LEFT_MARGIN, |
---|
| 944 | total_block_height + DEPTH_BAR_MARGIN*4); |
---|
| 945 | |
---|
| 946 | int y = top; |
---|
[a74b014] | 947 | |
---|
| 948 | DrawShadedRectangle(GetSurfacePen(), GetSurfacePen(), left, y, |
---|
| 949 | DEPTH_BAR_BLOCK_WIDTH, DEPTH_BAR_BLOCK_HEIGHT); |
---|
| 950 | y += DEPTH_BAR_BLOCK_HEIGHT + DEPTH_BAR_MARGIN; |
---|
| 951 | |
---|
[c61aa79] | 952 | for (band = 0; band < GetNumDepthBands() - 1; band++) { |
---|
| 953 | DrawShadedRectangle(GetPen(band), GetPen(band + 1), left, y, |
---|
| 954 | DEPTH_BAR_BLOCK_WIDTH, DEPTH_BAR_BLOCK_HEIGHT); |
---|
| 955 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 956 | } |
---|
| 957 | |
---|
[a74b014] | 958 | y = top - GetFontSize() / 2; |
---|
[c61aa79] | 959 | left += DEPTH_BAR_BLOCK_WIDTH + 5; |
---|
| 960 | |
---|
| 961 | SetColour(TEXT_COLOUR); |
---|
[a74b014] | 962 | |
---|
| 963 | y += DEPTH_BAR_MARGIN; |
---|
[5627cbb] | 964 | DrawIndicatorText(left, y, wxT("Not in loop")); |
---|
[a74b014] | 965 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 966 | |
---|
[c61aa79] | 967 | for (band = 0; band < GetNumDepthBands(); band++) { |
---|
| 968 | DrawIndicatorText(left, y, strs[band]); |
---|
| 969 | y += DEPTH_BAR_BLOCK_HEIGHT; |
---|
| 970 | } |
---|
| 971 | |
---|
| 972 | delete[] strs; |
---|
| 973 | } |
---|
| 974 | |
---|
[c6d95d8] | 975 | wxString GfxCore::FormatLength(Double size_snap, bool scalebar) |
---|
[ac537e9] | 976 | { |
---|
| 977 | wxString str; |
---|
[1eb2590] | 978 | bool negative = (size_snap < 0.0); |
---|
| 979 | |
---|
| 980 | if (negative) { |
---|
[429465a] | 981 | size_snap = -size_snap; |
---|
[1eb2590] | 982 | } |
---|
[ac537e9] | 983 | |
---|
| 984 | if (size_snap == 0.0) { |
---|
[5627cbb] | 985 | str = wxT("0"); |
---|
[7a89dc2] | 986 | } else if (m_Metric) { |
---|
[ac537e9] | 987 | #ifdef SILLY_UNITS |
---|
[429465a] | 988 | if (size_snap < 1e-12) { |
---|
[5627cbb] | 989 | str.Printf(wxT("%.3gpm"), size_snap * 1e12); |
---|
[429465a] | 990 | } else if (size_snap < 1e-9) { |
---|
[5627cbb] | 991 | str.Printf(wxT("%.fpm"), size_snap * 1e12); |
---|
[429465a] | 992 | } else if (size_snap < 1e-6) { |
---|
[5627cbb] | 993 | str.Printf(wxT("%.fnm"), size_snap * 1e9); |
---|
[429465a] | 994 | } else if (size_snap < 1e-3) { |
---|
[5627cbb] | 995 | str.Printf(wxT("%.fum"), size_snap * 1e6); |
---|
[ac537e9] | 996 | #else |
---|
[429465a] | 997 | if (size_snap < 1e-3) { |
---|
[5627cbb] | 998 | str.Printf(wxT("%.3gmm"), size_snap * 1e3); |
---|
[421b7d2] | 999 | #endif |
---|
[429465a] | 1000 | } else if (size_snap < 1e-2) { |
---|
[5627cbb] | 1001 | str.Printf(wxT("%.fmm"), size_snap * 1e3); |
---|
[429465a] | 1002 | } else if (size_snap < 1.0) { |
---|
[5627cbb] | 1003 | str.Printf(wxT("%.fcm"), size_snap * 100.0); |
---|
[429465a] | 1004 | } else if (size_snap < 1e3) { |
---|
[5627cbb] | 1005 | str.Printf(wxT("%.fm"), size_snap); |
---|
[ac537e9] | 1006 | #ifdef SILLY_UNITS |
---|
[429465a] | 1007 | } else if (size_snap < 1e6) { |
---|
[5627cbb] | 1008 | str.Printf(wxT("%.fkm"), size_snap * 1e-3); |
---|
[429465a] | 1009 | } else if (size_snap < 1e9) { |
---|
[5627cbb] | 1010 | str.Printf(wxT("%.fMm"), size_snap * 1e-6); |
---|
[429465a] | 1011 | } else { |
---|
[5627cbb] | 1012 | str.Printf(wxT("%.fGm"), size_snap * 1e-9); |
---|
[ac537e9] | 1013 | #else |
---|
[429465a] | 1014 | } else { |
---|
[5627cbb] | 1015 | str.Printf(scalebar ? wxT("%.fkm") : wxT("%.2fkm"), size_snap * 1e-3); |
---|
[ac537e9] | 1016 | #endif |
---|
[429465a] | 1017 | } |
---|
[7a89dc2] | 1018 | } else { |
---|
[429465a] | 1019 | size_snap /= METRES_PER_FOOT; |
---|
| 1020 | if (scalebar) { |
---|
| 1021 | Double inches = size_snap * 12; |
---|
| 1022 | if (inches < 1.0) { |
---|
[5627cbb] | 1023 | str.Printf(wxT("%.3gin"), inches); |
---|
[429465a] | 1024 | } else if (size_snap < 1.0) { |
---|
[5627cbb] | 1025 | str.Printf(wxT("%.fin"), inches); |
---|
[429465a] | 1026 | } else if (size_snap < 5279.5) { |
---|
[5627cbb] | 1027 | str.Printf(wxT("%.fft"), size_snap); |
---|
[429465a] | 1028 | } else { |
---|
[5627cbb] | 1029 | str.Printf(wxT("%.f miles"), size_snap / 5280.0); |
---|
[429465a] | 1030 | } |
---|
| 1031 | } else { |
---|
[5627cbb] | 1032 | str.Printf(wxT("%.fft"), size_snap); |
---|
[429465a] | 1033 | } |
---|
[ac537e9] | 1034 | } |
---|
| 1035 | |
---|
[5627cbb] | 1036 | return negative ? wxString(wxT("-")) + str : str; |
---|
[ac537e9] | 1037 | } |
---|
| 1038 | |
---|
[5809313] | 1039 | void GfxCore::DrawScalebar() |
---|
| 1040 | { |
---|
[84cab34] | 1041 | // Draw the scalebar. |
---|
[eef68f9] | 1042 | if (GetPerspective()) return; |
---|
[5809313] | 1043 | |
---|
[37bc1f5] | 1044 | // Calculate how many metres of survey are currently displayed across the |
---|
| 1045 | // screen. |
---|
[087bc72] | 1046 | Double across_screen = SurveyUnitsAcrossViewport(); |
---|
[156dc16] | 1047 | |
---|
[087bc72] | 1048 | // Convert to imperial measurements if required. |
---|
[7a89dc2] | 1049 | Double multiplier = 1.0; |
---|
| 1050 | if (!m_Metric) { |
---|
[429465a] | 1051 | across_screen /= METRES_PER_FOOT; |
---|
| 1052 | multiplier = METRES_PER_FOOT; |
---|
| 1053 | if (across_screen >= 5280.0 / 0.75) { |
---|
| 1054 | across_screen /= 5280.0; |
---|
| 1055 | multiplier *= 5280.0; |
---|
| 1056 | } |
---|
[7a89dc2] | 1057 | } |
---|
[5757725] | 1058 | |
---|
[7a89dc2] | 1059 | // Calculate the length of the scale bar. |
---|
[087bc72] | 1060 | Double size_snap = pow(10.0, floor(log10(0.65 * across_screen))); |
---|
| 1061 | Double t = across_screen * 0.65 / size_snap; |
---|
[98860c5] | 1062 | if (t >= 5.0) { |
---|
[429465a] | 1063 | size_snap *= 5.0; |
---|
[7a89dc2] | 1064 | } else if (t >= 2.0) { |
---|
[429465a] | 1065 | size_snap *= 2.0; |
---|
[98860c5] | 1066 | } |
---|
| 1067 | |
---|
[7a89dc2] | 1068 | if (!m_Metric) size_snap *= multiplier; |
---|
| 1069 | |
---|
[84cab34] | 1070 | // Actual size of the thing in pixels: |
---|
[087bc72] | 1071 | int size = int((size_snap / SurveyUnitsAcrossViewport()) * m_XSize); |
---|
[e2c1671] | 1072 | m_ScaleBarWidth = size; |
---|
[421b7d2] | 1073 | |
---|
[5809313] | 1074 | // Draw it... |
---|
[e2c1671] | 1075 | const int end_y = SCALE_BAR_OFFSET_Y + SCALE_BAR_HEIGHT; |
---|
[5809313] | 1076 | int interval = size / 10; |
---|
| 1077 | |
---|
[aa048c3] | 1078 | gla_colour col = col_WHITE; |
---|
[5809313] | 1079 | for (int ix = 0; ix < 10; ix++) { |
---|
[e2c1671] | 1080 | int x = SCALE_BAR_OFFSET_X + int(ix * ((Double) size / 10.0)); |
---|
[421b7d2] | 1081 | |
---|
[e2c1671] | 1082 | DrawRectangle(col, col, x, end_y, interval + 2, SCALE_BAR_HEIGHT); |
---|
[421b7d2] | 1083 | |
---|
[aa048c3] | 1084 | col = (col == col_WHITE) ? col_GREY : col_WHITE; |
---|
[5809313] | 1085 | } |
---|
| 1086 | |
---|
[84cab34] | 1087 | // Add labels. |
---|
[ac537e9] | 1088 | wxString str = FormatLength(size_snap); |
---|
[84cab34] | 1089 | |
---|
[1eeb55a] | 1090 | int text_width, text_height; |
---|
[56da40e] | 1091 | GetTextExtent(str, &text_width, &text_height); |
---|
[8bd480e] | 1092 | const int text_y = end_y - text_height + 1; |
---|
| 1093 | SetColour(TEXT_COLOUR); |
---|
[5627cbb] | 1094 | DrawIndicatorText(SCALE_BAR_OFFSET_X, text_y, wxT("0")); |
---|
[8bd480e] | 1095 | DrawIndicatorText(SCALE_BAR_OFFSET_X + size - text_width, text_y, str); |
---|
[5809313] | 1096 | } |
---|
[56da40e] | 1097 | |
---|
[2072157] | 1098 | bool GfxCore::CheckHitTestGrid(const wxPoint& point, bool centre) |
---|
[2effbf1] | 1099 | { |
---|
[0874c07e] | 1100 | if (Animating()) return false; |
---|
| 1101 | |
---|
[203d2a7] | 1102 | if (point.x < 0 || point.x >= m_XSize || |
---|
[429465a] | 1103 | point.y < 0 || point.y >= m_YSize) { |
---|
| 1104 | return false; |
---|
[137e31b] | 1105 | } |
---|
[421b7d2] | 1106 | |
---|
[156f645] | 1107 | SetDataTransform(); |
---|
[00a68e0] | 1108 | |
---|
[69463a0] | 1109 | if (!m_HitTestGridValid) CreateHitTestGrid(); |
---|
[fa42426] | 1110 | |
---|
[2effbf1] | 1111 | int grid_x = (point.x * (HITTEST_SIZE - 1)) / m_XSize; |
---|
| 1112 | int grid_y = (point.y * (HITTEST_SIZE - 1)) / m_YSize; |
---|
[137e31b] | 1113 | |
---|
[fa42426] | 1114 | LabelInfo *best = NULL; |
---|
| 1115 | int dist_sqrd = 25; |
---|
[2effbf1] | 1116 | int square = grid_x + grid_y * HITTEST_SIZE; |
---|
[fa42426] | 1117 | list<LabelInfo*>::iterator iter = m_PointGrid[square].begin(); |
---|
[00a68e0] | 1118 | |
---|
[fa42426] | 1119 | while (iter != m_PointGrid[square].end()) { |
---|
[429465a] | 1120 | LabelInfo *pt = *iter++; |
---|
[fa42426] | 1121 | |
---|
[429465a] | 1122 | Double cx, cy, cz; |
---|
[00a68e0] | 1123 | |
---|
[d67450e] | 1124 | Transform(*pt, &cx, &cy, &cz); |
---|
[00a68e0] | 1125 | |
---|
[429465a] | 1126 | cy = m_YSize - cy; |
---|
[00a68e0] | 1127 | |
---|
[429465a] | 1128 | int dx = point.x - int(cx); |
---|
| 1129 | int ds = dx * dx; |
---|
| 1130 | if (ds >= dist_sqrd) continue; |
---|
| 1131 | int dy = point.y - int(cy); |
---|
[fa42426] | 1132 | |
---|
[429465a] | 1133 | ds += dy * dy; |
---|
| 1134 | if (ds >= dist_sqrd) continue; |
---|
[f433fda] | 1135 | |
---|
[429465a] | 1136 | dist_sqrd = ds; |
---|
| 1137 | best = pt; |
---|
[f433fda] | 1138 | |
---|
[429465a] | 1139 | if (ds == 0) break; |
---|
[2effbf1] | 1140 | } |
---|
[f433fda] | 1141 | |
---|
[7c29c976] | 1142 | m_Parent->ShowInfo(best); |
---|
[fa42426] | 1143 | if (best) { |
---|
[429465a] | 1144 | if (centre) { |
---|
[e67ed1b] | 1145 | // FIXME: allow Ctrl-Click to not set there or something? |
---|
[82c3731] | 1146 | CentreOn(*best); |
---|
[fc768a8] | 1147 | WarpPointer(m_XSize / 2, m_YSize / 2); |
---|
[82c3731] | 1148 | SetThere(*best); |
---|
[429465a] | 1149 | m_Parent->SelectTreeItem(best); |
---|
| 1150 | } |
---|
[e67ed1b] | 1151 | } else { |
---|
| 1152 | // Left-clicking not on a survey cancels the measuring line. |
---|
[0633bcc] | 1153 | if (centre) { |
---|
| 1154 | ClearTreeSelection(); |
---|
| 1155 | } else { |
---|
| 1156 | Double x, y, z; |
---|
| 1157 | ReverseTransform(point.x, m_YSize - point.y, &x, &y, &z); |
---|
| 1158 | SetHere(Point(Vector3(x, y, z))); |
---|
[c00c6713] | 1159 | m_here_is_temporary = true; |
---|
[0633bcc] | 1160 | } |
---|
[2effbf1] | 1161 | } |
---|
[203d2a7] | 1162 | |
---|
| 1163 | return best; |
---|
[2effbf1] | 1164 | } |
---|
| 1165 | |
---|
[5876fcb] | 1166 | void GfxCore::OnSize(wxSizeEvent& event) |
---|
[5809313] | 1167 | { |
---|
[5876fcb] | 1168 | // Handle a change in window size. |
---|
[bbc22ca] | 1169 | |
---|
[5876fcb] | 1170 | wxSize size = event.GetSize(); |
---|
[5809313] | 1171 | |
---|
[78beaf1] | 1172 | if (size.GetWidth() <= 0 || size.GetHeight() <= 0) { |
---|
[0580c6a] | 1173 | // Before things are fully initialised, we sometimes get a bogus |
---|
| 1174 | // resize message... |
---|
[6ef8bd73] | 1175 | // FIXME have changes in MainFrm cured this? It still happens with |
---|
[0580c6a] | 1176 | // 1.0.32 and wxGtk 2.5.2 (load a file from the command line). |
---|
[78beaf1] | 1177 | // With 1.1.6 and wxGtk 2.4.2 we only get negative sizes if MainFrm |
---|
| 1178 | // is resized such that the GfxCore window isn't visible. |
---|
| 1179 | //printf("OnSize(%d,%d)\n", size.GetWidth(), size.GetHeight()); |
---|
[0580c6a] | 1180 | return; |
---|
| 1181 | } |
---|
[b72f4b5] | 1182 | |
---|
| 1183 | wxGLCanvas::OnSize(event); |
---|
| 1184 | |
---|
[5876fcb] | 1185 | m_XSize = size.GetWidth(); |
---|
| 1186 | m_YSize = size.GetHeight(); |
---|
[39e460c9] | 1187 | |
---|
[5876fcb] | 1188 | if (m_DoneFirstShow) { |
---|
[69463a0] | 1189 | if (m_LabelGrid) { |
---|
| 1190 | delete[] m_LabelGrid; |
---|
| 1191 | m_LabelGrid = NULL; |
---|
| 1192 | } |
---|
[6ebc0ce] | 1193 | |
---|
[69463a0] | 1194 | m_HitTestGridValid = false; |
---|
[33b2094] | 1195 | |
---|
[d67450e] | 1196 | ForceRefresh(); |
---|
[5809313] | 1197 | } |
---|
| 1198 | } |
---|
| 1199 | |
---|
[de7a879] | 1200 | void GfxCore::DefaultParameters() |
---|
[5809313] | 1201 | { |
---|
[33b2094] | 1202 | // Set default viewing parameters. |
---|
[b462168] | 1203 | |
---|
[f433fda] | 1204 | m_Surface = false; |
---|
| 1205 | if (!m_Parent->HasUndergroundLegs()) { |
---|
| 1206 | if (m_Parent->HasSurfaceLegs()) { |
---|
| 1207 | // If there are surface legs, but no underground legs, turn |
---|
| 1208 | // surface surveys on. |
---|
| 1209 | m_Surface = true; |
---|
| 1210 | } else { |
---|
| 1211 | // If there are no legs (e.g. after loading a .pos file), turn |
---|
| 1212 | // crosses on. |
---|
| 1213 | m_Crosses = true; |
---|
| 1214 | } |
---|
[b462168] | 1215 | } |
---|
| 1216 | |
---|
[714daae] | 1217 | m_PanAngle = 0.0; |
---|
[eef68f9] | 1218 | if (m_Parent->IsExtendedElevation()) { |
---|
| 1219 | m_TiltAngle = 0.0; |
---|
| 1220 | } else { |
---|
| 1221 | m_TiltAngle = 90.0; |
---|
[b462168] | 1222 | } |
---|
[714daae] | 1223 | |
---|
[08253d9] | 1224 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[d67450e] | 1225 | SetTranslation(Vector3()); |
---|
[33b2094] | 1226 | |
---|
[e577f89] | 1227 | m_RotationStep = 30.0; |
---|
[5809313] | 1228 | m_Rotating = false; |
---|
[3d00693] | 1229 | m_SwitchingTo = 0; |
---|
[fe444b8] | 1230 | m_Entrances = false; |
---|
| 1231 | m_FixedPts = false; |
---|
| 1232 | m_ExportedPts = false; |
---|
[c1cf79d] | 1233 | m_Grid = false; |
---|
[f4c5932] | 1234 | m_BoundingBox = false; |
---|
[33b2094] | 1235 | m_Tubes = false; |
---|
[1eeb55a] | 1236 | if (GetPerspective()) TogglePerspective(); |
---|
[de7a879] | 1237 | } |
---|
[5809313] | 1238 | |
---|
[de7a879] | 1239 | void GfxCore::Defaults() |
---|
| 1240 | { |
---|
| 1241 | // Restore default scale, rotation and translation parameters. |
---|
| 1242 | DefaultParameters(); |
---|
[8b0d57f] | 1243 | SetScale(1.0); |
---|
[ba358fc] | 1244 | |
---|
| 1245 | // Invalidate all the cached lists. |
---|
| 1246 | GLACanvas::FirstShow(); |
---|
| 1247 | |
---|
[fa42426] | 1248 | ForceRefresh(); |
---|
[5809313] | 1249 | } |
---|
[84cab34] | 1250 | |
---|
[5876fcb] | 1251 | // return: true if animation occured (and ForceRefresh() needs to be called) |
---|
[1690fa9] | 1252 | bool GfxCore::Animate() |
---|
[5809313] | 1253 | { |
---|
[2a3d328] | 1254 | if (!Animating()) return false; |
---|
| 1255 | |
---|
| 1256 | // Don't show pointer coordinates while animating. |
---|
[4b031c0] | 1257 | // FIXME : only do this when we *START* animating! Use a static copy |
---|
| 1258 | // of the value of "Animating()" last time we were here to track this? |
---|
| 1259 | // MainFrm now checks if we're trying to clear already cleared labels |
---|
| 1260 | // and just returns, but it might be simpler to check here! |
---|
[2a3d328] | 1261 | ClearCoords(); |
---|
[7c29c976] | 1262 | m_Parent->ShowInfo(NULL); |
---|
[5809313] | 1263 | |
---|
[5876fcb] | 1264 | static double last_t = 0; |
---|
[6a4cdcb6] | 1265 | double t; |
---|
| 1266 | if (mpeg) { |
---|
[6673525] | 1267 | // FIXME: this glReadPixels call should be in gla-gl.cc |
---|
[6a4cdcb6] | 1268 | glReadPixels(0, 0, mpeg->GetWidth(), mpeg->GetHeight(), GL_RGB, |
---|
| 1269 | GL_UNSIGNED_BYTE, (GLvoid *)mpeg->GetBuffer()); |
---|
| 1270 | mpeg->AddFrame(); |
---|
| 1271 | t = 1.0 / 25.0; // 25 frames per second |
---|
| 1272 | } else { |
---|
| 1273 | t = timer.Time() * 1.0e-3; |
---|
| 1274 | if (t == 0) t = 0.001; |
---|
| 1275 | else if (t > 1.0) t = 1.0; |
---|
| 1276 | if (last_t > 0) t = (t + last_t) / 2; |
---|
| 1277 | last_t = t; |
---|
| 1278 | } |
---|
[5809313] | 1279 | |
---|
[128fac4] | 1280 | if (presentation_mode == PLAYING && pres_speed != 0.0) { |
---|
| 1281 | t *= fabs(pres_speed); |
---|
[1690fa9] | 1282 | while (t >= next_mark_time) { |
---|
| 1283 | t -= next_mark_time; |
---|
[128fac4] | 1284 | this_mark_total = 0; |
---|
[58dfdd21] | 1285 | PresentationMark prev_mark = next_mark; |
---|
[e577f89] | 1286 | if (prev_mark.angle < 0) prev_mark.angle += 360.0; |
---|
| 1287 | else if (prev_mark.angle >= 360.0) prev_mark.angle -= 360.0; |
---|
[128fac4] | 1288 | if (pres_reverse) |
---|
| 1289 | next_mark = m_Parent->GetPresMark(MARK_PREV); |
---|
| 1290 | else |
---|
| 1291 | next_mark = m_Parent->GetPresMark(MARK_NEXT); |
---|
[1690fa9] | 1292 | if (!next_mark.is_valid()) { |
---|
[128fac4] | 1293 | SetView(prev_mark); |
---|
[1690fa9] | 1294 | presentation_mode = 0; |
---|
[6a4cdcb6] | 1295 | if (mpeg) { |
---|
| 1296 | delete mpeg; |
---|
| 1297 | mpeg = 0; |
---|
| 1298 | } |
---|
[1690fa9] | 1299 | break; |
---|
| 1300 | } |
---|
[58dfdd21] | 1301 | |
---|
[128fac4] | 1302 | double tmp = (pres_reverse ? prev_mark.time : next_mark.time); |
---|
| 1303 | if (tmp > 0) { |
---|
| 1304 | next_mark_time = tmp; |
---|
[58dfdd21] | 1305 | } else { |
---|
[d67450e] | 1306 | double d = (next_mark - prev_mark).magnitude(); |
---|
[49ce5b0] | 1307 | // FIXME: should ignore component of d which is unseen in |
---|
| 1308 | // non-perspective mode? |
---|
[8674eea] | 1309 | next_mark_time = sqrd(d / 30.0); |
---|
[49ce5b0] | 1310 | double a = next_mark.angle - prev_mark.angle; |
---|
| 1311 | if (a > 180.0) { |
---|
| 1312 | next_mark.angle -= 360.0; |
---|
| 1313 | a = 360.0 - a; |
---|
| 1314 | } else if (a < -180.0) { |
---|
| 1315 | next_mark.angle += 360.0; |
---|
| 1316 | a += 360.0; |
---|
| 1317 | } else { |
---|
| 1318 | a = fabs(a); |
---|
| 1319 | } |
---|
| 1320 | next_mark_time += sqrd(a / 60.0); |
---|
| 1321 | double ta = fabs(next_mark.tilt_angle - prev_mark.tilt_angle); |
---|
| 1322 | next_mark_time += sqrd(ta / 60.0); |
---|
| 1323 | double s = fabs(log(next_mark.scale) - log(prev_mark.scale)); |
---|
[8674eea] | 1324 | next_mark_time += sqrd(s / 2.0); |
---|
[49ce5b0] | 1325 | next_mark_time = sqrt(next_mark_time); |
---|
[8674eea] | 1326 | // was: next_mark_time = max(max(d / 30, s / 2), max(a, ta) / 60); |
---|
[49ce5b0] | 1327 | //printf("*** %.6f from (\nd: %.6f\ns: %.6f\na: %.6f\nt: %.6f )\n", |
---|
[8674eea] | 1328 | // next_mark_time, d/30.0, s/2.0, a/60.0, ta/60.0); |
---|
| 1329 | if (tmp < 0) next_mark_time /= -tmp; |
---|
[58dfdd21] | 1330 | } |
---|
[1690fa9] | 1331 | } |
---|
| 1332 | |
---|
| 1333 | if (presentation_mode) { |
---|
| 1334 | // Advance position towards next_mark |
---|
| 1335 | double p = t / next_mark_time; |
---|
| 1336 | double q = 1 - p; |
---|
| 1337 | PresentationMark here = GetView(); |
---|
[d877aa2] | 1338 | if (next_mark.angle < 0) { |
---|
[e577f89] | 1339 | if (here.angle >= next_mark.angle + 360.0) |
---|
| 1340 | here.angle -= 360.0; |
---|
| 1341 | } else if (next_mark.angle >= 360.0) { |
---|
| 1342 | if (here.angle <= next_mark.angle - 360.0) |
---|
| 1343 | here.angle += 360.0; |
---|
[d877aa2] | 1344 | } |
---|
[8674eea] | 1345 | here.assign(q * here + p * next_mark); |
---|
[1690fa9] | 1346 | here.angle = q * here.angle + p * next_mark.angle; |
---|
[e577f89] | 1347 | if (here.angle < 0) here.angle += 360.0; |
---|
| 1348 | else if (here.angle >= 360.0) here.angle -= 360.0; |
---|
[1690fa9] | 1349 | here.tilt_angle = q * here.tilt_angle + p * next_mark.tilt_angle; |
---|
[58dfdd21] | 1350 | here.scale = exp(q * log(here.scale) + p * log(next_mark.scale)); |
---|
[1690fa9] | 1351 | SetView(here); |
---|
[128fac4] | 1352 | this_mark_total += t; |
---|
[1690fa9] | 1353 | next_mark_time -= t; |
---|
| 1354 | } |
---|
| 1355 | } |
---|
| 1356 | |
---|
[5876fcb] | 1357 | // When rotating... |
---|
| 1358 | if (m_Rotating) { |
---|
[1690fa9] | 1359 | TurnCave(m_RotationStep * t); |
---|
[5876fcb] | 1360 | } |
---|
[5809313] | 1361 | |
---|
[5876fcb] | 1362 | if (m_SwitchingTo == PLAN) { |
---|
[429465a] | 1363 | // When switching to plan view... |
---|
[e577f89] | 1364 | TiltCave(90.0 * t); |
---|
| 1365 | if (m_TiltAngle == 90.0) { |
---|
[429465a] | 1366 | m_SwitchingTo = 0; |
---|
| 1367 | } |
---|
[1690fa9] | 1368 | } else if (m_SwitchingTo == ELEVATION) { |
---|
[429465a] | 1369 | // When switching to elevation view... |
---|
[e577f89] | 1370 | if (fabs(m_TiltAngle) < 90.0 * t) { |
---|
[429465a] | 1371 | m_SwitchingTo = 0; |
---|
| 1372 | TiltCave(-m_TiltAngle); |
---|
[1690fa9] | 1373 | } else if (m_TiltAngle < 0.0) { |
---|
[e577f89] | 1374 | TiltCave(90.0 * t); |
---|
[1690fa9] | 1375 | } else { |
---|
[e577f89] | 1376 | TiltCave(-90.0 * t); |
---|
[429465a] | 1377 | } |
---|
[3ddd351] | 1378 | } else if (m_SwitchingTo) { |
---|
| 1379 | int angle = (m_SwitchingTo - NORTH) * 90; |
---|
| 1380 | double diff = angle - m_PanAngle; |
---|
| 1381 | if (diff < -180) diff += 360; |
---|
| 1382 | if (diff > 180) diff -= 360; |
---|
| 1383 | double move = 90.0 * t; |
---|
| 1384 | if (move >= fabs(diff)) { |
---|
| 1385 | TurnCave(diff); |
---|
| 1386 | m_SwitchingTo = 0; |
---|
| 1387 | } else if (diff < 0) { |
---|
| 1388 | TurnCave(-move); |
---|
| 1389 | } else { |
---|
| 1390 | TurnCave(move); |
---|
| 1391 | } |
---|
[5876fcb] | 1392 | } |
---|
[5809313] | 1393 | |
---|
[7757a4ed] | 1394 | return true; |
---|
[5809313] | 1395 | } |
---|
[84cab34] | 1396 | |
---|
[0580c6a] | 1397 | // How much to allow around the box - this is because of the ring shape |
---|
| 1398 | // at one end of the line. |
---|
| 1399 | static const int HIGHLIGHTED_PT_SIZE = 2; // FIXME: tie in to blob and ring size |
---|
| 1400 | #define MARGIN (HIGHLIGHTED_PT_SIZE * 2 + 1) |
---|
| 1401 | void GfxCore::RefreshLine(const Point &a, const Point &b, const Point &c) |
---|
[7a89dc2] | 1402 | { |
---|
[06d367d] | 1403 | // Best of all might be to copy the window contents before we draw the |
---|
| 1404 | // line, then replace each time we redraw. |
---|
[796d7bf] | 1405 | |
---|
[5876fcb] | 1406 | // Calculate the minimum rectangle which includes the old and new |
---|
| 1407 | // measuring lines to minimise the redraw time |
---|
| 1408 | int l = INT_MAX, r = INT_MIN, u = INT_MIN, d = INT_MAX; |
---|
[796d7bf] | 1409 | Double X, Y, Z; |
---|
[d67450e] | 1410 | if (a.IsValid()) { |
---|
| 1411 | if (!Transform(a, &X, &Y, &Z)) { |
---|
[796d7bf] | 1412 | printf("oops\n"); |
---|
| 1413 | } else { |
---|
| 1414 | int x = int(X); |
---|
| 1415 | int y = m_YSize - 1 - int(Y); |
---|
| 1416 | l = x - MARGIN; |
---|
| 1417 | r = x + MARGIN; |
---|
| 1418 | u = y + MARGIN; |
---|
| 1419 | d = y - MARGIN; |
---|
| 1420 | } |
---|
[5876fcb] | 1421 | } |
---|
[d67450e] | 1422 | if (b.IsValid()) { |
---|
| 1423 | if (!Transform(b, &X, &Y, &Z)) { |
---|
[796d7bf] | 1424 | printf("oops\n"); |
---|
| 1425 | } else { |
---|
| 1426 | int x = int(X); |
---|
| 1427 | int y = m_YSize - 1 - int(Y); |
---|
| 1428 | l = min(l, x - MARGIN); |
---|
| 1429 | r = max(r, x + MARGIN); |
---|
| 1430 | u = max(u, y + MARGIN); |
---|
| 1431 | d = min(d, y - MARGIN); |
---|
| 1432 | } |
---|
[5876fcb] | 1433 | } |
---|
[d67450e] | 1434 | if (c.IsValid()) { |
---|
| 1435 | if (!Transform(c, &X, &Y, &Z)) { |
---|
[796d7bf] | 1436 | printf("oops\n"); |
---|
| 1437 | } else { |
---|
| 1438 | int x = int(X); |
---|
| 1439 | int y = m_YSize - 1 - int(Y); |
---|
| 1440 | l = min(l, x - MARGIN); |
---|
| 1441 | r = max(r, x + MARGIN); |
---|
| 1442 | u = max(u, y + MARGIN); |
---|
| 1443 | d = min(d, y - MARGIN); |
---|
| 1444 | } |
---|
[5876fcb] | 1445 | } |
---|
| 1446 | const wxRect R(l, d, r - l, u - d); |
---|
| 1447 | Refresh(false, &R); |
---|
[7a89dc2] | 1448 | } |
---|
| 1449 | |
---|
[5876fcb] | 1450 | void GfxCore::SetHere() |
---|
[7a89dc2] | 1451 | { |
---|
[d67450e] | 1452 | if (!m_here.IsValid()) return; |
---|
[5876fcb] | 1453 | Point old = m_here; |
---|
[d67450e] | 1454 | m_here.Invalidate(); |
---|
[0580c6a] | 1455 | RefreshLine(old, m_there, m_here); |
---|
[7a89dc2] | 1456 | } |
---|
| 1457 | |
---|
[82c3731] | 1458 | void GfxCore::SetHere(const Point &p) |
---|
[c6d95d8] | 1459 | { |
---|
[5876fcb] | 1460 | Point old = m_here; |
---|
[82c3731] | 1461 | m_here = p; |
---|
[0580c6a] | 1462 | RefreshLine(old, m_there, m_here); |
---|
[c00c6713] | 1463 | m_here_is_temporary = false; |
---|
[156dc16] | 1464 | } |
---|
| 1465 | |
---|
[5876fcb] | 1466 | void GfxCore::SetThere() |
---|
[156dc16] | 1467 | { |
---|
[d67450e] | 1468 | if (!m_there.IsValid()) return; |
---|
[5876fcb] | 1469 | Point old = m_there; |
---|
[d67450e] | 1470 | m_there.Invalidate(); |
---|
[0580c6a] | 1471 | RefreshLine(m_here, old, m_there); |
---|
[156dc16] | 1472 | } |
---|
| 1473 | |
---|
[82c3731] | 1474 | void GfxCore::SetThere(const Point &p) |
---|
[156dc16] | 1475 | { |
---|
[5876fcb] | 1476 | Point old = m_there; |
---|
[82c3731] | 1477 | m_there = p; |
---|
[0580c6a] | 1478 | RefreshLine(m_here, old, m_there); |
---|
[156dc16] | 1479 | } |
---|
| 1480 | |
---|
[5876fcb] | 1481 | void GfxCore::CreateHitTestGrid() |
---|
[156dc16] | 1482 | { |
---|
[00a68e0] | 1483 | // Clear hit-test grid. |
---|
[5876fcb] | 1484 | for (int i = 0; i < HITTEST_SIZE * HITTEST_SIZE; i++) { |
---|
[429465a] | 1485 | m_PointGrid[i].clear(); |
---|
[5876fcb] | 1486 | } |
---|
[156dc16] | 1487 | |
---|
[5876fcb] | 1488 | // Fill the grid. |
---|
| 1489 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 1490 | list<LabelInfo*>::const_iterator end = m_Parent->GetLabelsEnd(); |
---|
| 1491 | while (pos != end) { |
---|
[429465a] | 1492 | LabelInfo* label = *pos++; |
---|
[33b2094] | 1493 | |
---|
[429465a] | 1494 | if (!((m_Surface && label->IsSurface()) || |
---|
[dc42b8e] | 1495 | (m_Legs && label->IsUnderground()) || |
---|
| 1496 | (!label->IsSurface() && !label->IsUnderground()))) { |
---|
| 1497 | // if this station isn't to be displayed, skip to the next |
---|
| 1498 | // (last case is for stns with no legs attached) |
---|
[429465a] | 1499 | continue; |
---|
| 1500 | } |
---|
[33b2094] | 1501 | |
---|
[429465a] | 1502 | // Calculate screen coordinates. |
---|
| 1503 | Double cx, cy, cz; |
---|
[d67450e] | 1504 | Transform(*label, &cx, &cy, &cz); |
---|
[429465a] | 1505 | if (cx < 0 || cx >= m_XSize) continue; |
---|
| 1506 | if (cy < 0 || cy >= m_YSize) continue; |
---|
[33b2094] | 1507 | |
---|
[429465a] | 1508 | cy = m_YSize - cy; |
---|
[00a68e0] | 1509 | |
---|
[429465a] | 1510 | // On-screen, so add to hit-test grid... |
---|
| 1511 | int grid_x = int((cx * (HITTEST_SIZE - 1)) / m_XSize); |
---|
| 1512 | int grid_y = int((cy * (HITTEST_SIZE - 1)) / m_YSize); |
---|
[33b2094] | 1513 | |
---|
[429465a] | 1514 | m_PointGrid[grid_x + grid_y * HITTEST_SIZE].push_back(label); |
---|
[33b2094] | 1515 | } |
---|
| 1516 | |
---|
[00a68e0] | 1517 | m_HitTestGridValid = true; |
---|
[33b2094] | 1518 | } |
---|
[c6d95d8] | 1519 | |
---|
[2a02de2] | 1520 | // |
---|
[5876fcb] | 1521 | // Methods for controlling the orientation of the survey |
---|
[2a02de2] | 1522 | // |
---|
| 1523 | |
---|
[5876fcb] | 1524 | void GfxCore::TurnCave(Double angle) |
---|
[156dc16] | 1525 | { |
---|
[5876fcb] | 1526 | // Turn the cave around its z-axis by a given angle. |
---|
[156dc16] | 1527 | |
---|
[5876fcb] | 1528 | m_PanAngle += angle; |
---|
[e577f89] | 1529 | if (m_PanAngle >= 360.0) { |
---|
| 1530 | m_PanAngle -= 360.0; |
---|
[5876fcb] | 1531 | } else if (m_PanAngle < 0.0) { |
---|
[e577f89] | 1532 | m_PanAngle += 360.0; |
---|
[156dc16] | 1533 | } |
---|
[33b2094] | 1534 | |
---|
[00a68e0] | 1535 | m_HitTestGridValid = false; |
---|
[c00c6713] | 1536 | if (m_here_is_temporary) SetHere(); |
---|
[00a68e0] | 1537 | |
---|
[08253d9] | 1538 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[156dc16] | 1539 | } |
---|
| 1540 | |
---|
[5876fcb] | 1541 | void GfxCore::TurnCaveTo(Double angle) |
---|
[d80805e] | 1542 | { |
---|
[3ddd351] | 1543 | timer.Start(drawtime); |
---|
| 1544 | int new_switching_to = ((int)angle) / 90 + NORTH; |
---|
| 1545 | if (new_switching_to == m_SwitchingTo) { |
---|
| 1546 | // A second order to switch takes us there right away |
---|
| 1547 | TurnCave(angle - m_PanAngle); |
---|
| 1548 | m_SwitchingTo = 0; |
---|
| 1549 | ForceRefresh(); |
---|
| 1550 | } else { |
---|
| 1551 | m_SwitchingTo = new_switching_to; |
---|
| 1552 | } |
---|
[d80805e] | 1553 | } |
---|
| 1554 | |
---|
[5876fcb] | 1555 | void GfxCore::TiltCave(Double tilt_angle) |
---|
[156dc16] | 1556 | { |
---|
[5876fcb] | 1557 | // Tilt the cave by a given angle. |
---|
[e577f89] | 1558 | if (m_TiltAngle + tilt_angle > 90.0) { |
---|
[08253d9] | 1559 | m_TiltAngle = 90.0; |
---|
[e577f89] | 1560 | } else if (m_TiltAngle + tilt_angle < -90.0) { |
---|
[08253d9] | 1561 | m_TiltAngle = -90.0; |
---|
| 1562 | } else { |
---|
| 1563 | m_TiltAngle += tilt_angle; |
---|
[d80805e] | 1564 | } |
---|
| 1565 | |
---|
[00a68e0] | 1566 | m_HitTestGridValid = false; |
---|
[c00c6713] | 1567 | if (m_here_is_temporary) SetHere(); |
---|
[00a68e0] | 1568 | |
---|
[08253d9] | 1569 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[5ffa439] | 1570 | } |
---|
| 1571 | |
---|
[5876fcb] | 1572 | void GfxCore::TranslateCave(int dx, int dy) |
---|
[5ffa439] | 1573 | { |
---|
[33b2094] | 1574 | AddTranslationScreenCoordinates(dx, dy); |
---|
[00a68e0] | 1575 | m_HitTestGridValid = false; |
---|
| 1576 | |
---|
[c00c6713] | 1577 | if (m_here_is_temporary) SetHere(); |
---|
| 1578 | |
---|
[33b2094] | 1579 | ForceRefresh(); |
---|
| 1580 | } |
---|
[5876fcb] | 1581 | |
---|
[33b2094] | 1582 | void GfxCore::DragFinished() |
---|
| 1583 | { |
---|
[76dd228] | 1584 | m_MouseOutsideCompass = m_MouseOutsideElev = false; |
---|
[5876fcb] | 1585 | ForceRefresh(); |
---|
[2173dbd] | 1586 | } |
---|
| 1587 | |
---|
[d877aa2] | 1588 | void GfxCore::ClearCoords() |
---|
| 1589 | { |
---|
| 1590 | m_Parent->ClearCoords(); |
---|
| 1591 | } |
---|
| 1592 | |
---|
[5876fcb] | 1593 | void GfxCore::SetCoords(wxPoint point) |
---|
[fd6e0d5] | 1594 | { |
---|
[0874c07e] | 1595 | // We can't work out 2D coordinates from a perspective view, and it |
---|
| 1596 | // doesn't really make sense to show coordinates while we're animating. |
---|
| 1597 | if (GetPerspective() || Animating()) return; |
---|
[0a811ab] | 1598 | |
---|
[5876fcb] | 1599 | // Update the coordinate or altitude display, given the (x, y) position in |
---|
| 1600 | // window coordinates. The relevant display is updated depending on |
---|
| 1601 | // whether we're in plan or elevation view. |
---|
| 1602 | |
---|
[a2b3d62] | 1603 | Double cx, cy, cz; |
---|
[5876fcb] | 1604 | |
---|
[a2b3d62] | 1605 | SetDataTransform(); |
---|
[887c26e] | 1606 | ReverseTransform(point.x, m_YSize - 1 - point.y, &cx, &cy, &cz); |
---|
[5876fcb] | 1607 | |
---|
[0633bcc] | 1608 | if (ShowingPlan()) { |
---|
[d67450e] | 1609 | m_Parent->SetCoords(cx + m_Parent->GetOffset().GetX(), |
---|
| 1610 | cy + m_Parent->GetOffset().GetY()); |
---|
[0633bcc] | 1611 | } else if (ShowingElevation()) { |
---|
[d67450e] | 1612 | m_Parent->SetAltitude(cz + m_Parent->GetOffset().GetZ()); |
---|
[d479c15] | 1613 | } else { |
---|
[429465a] | 1614 | m_Parent->ClearCoords(); |
---|
[a2b3d62] | 1615 | } |
---|
[fd6e0d5] | 1616 | } |
---|
| 1617 | |
---|
[1eeb55a] | 1618 | int GfxCore::GetCompassXPosition() const |
---|
[1fd2edb] | 1619 | { |
---|
[f433fda] | 1620 | // Return the x-coordinate of the centre of the compass in window |
---|
| 1621 | // coordinates. |
---|
[1eeb55a] | 1622 | return m_XSize - INDICATOR_OFFSET_X - INDICATOR_BOX_SIZE / 2; |
---|
[1fd2edb] | 1623 | } |
---|
| 1624 | |
---|
[1eeb55a] | 1625 | int GfxCore::GetClinoXPosition() const |
---|
[1fd2edb] | 1626 | { |
---|
[f433fda] | 1627 | // Return the x-coordinate of the centre of the compass in window |
---|
| 1628 | // coordinates. |
---|
[1eeb55a] | 1629 | return m_XSize - GetClinoOffset() - INDICATOR_BOX_SIZE / 2; |
---|
[1fd2edb] | 1630 | } |
---|
| 1631 | |
---|
[1eeb55a] | 1632 | int GfxCore::GetIndicatorYPosition() const |
---|
[dfe4454c] | 1633 | { |
---|
[f433fda] | 1634 | // Return the y-coordinate of the centre of the indicators in window |
---|
| 1635 | // coordinates. |
---|
[1eeb55a] | 1636 | return m_YSize - INDICATOR_OFFSET_Y - INDICATOR_BOX_SIZE / 2; |
---|
[5876fcb] | 1637 | } |
---|
[fa42426] | 1638 | |
---|
[1eeb55a] | 1639 | int GfxCore::GetIndicatorRadius() const |
---|
[5876fcb] | 1640 | { |
---|
| 1641 | // Return the radius of each indicator. |
---|
[1eeb55a] | 1642 | return (INDICATOR_BOX_SIZE - INDICATOR_MARGIN * 2) / 2; |
---|
[5876fcb] | 1643 | } |
---|
[dfe4454c] | 1644 | |
---|
[14acdae] | 1645 | bool GfxCore::PointWithinCompass(wxPoint point) const |
---|
[5876fcb] | 1646 | { |
---|
[f433fda] | 1647 | // Determine whether a point (in window coordinates) lies within the |
---|
| 1648 | // compass. |
---|
[e2c1671] | 1649 | if (!ShowingCompass()) return false; |
---|
| 1650 | |
---|
[33b2094] | 1651 | glaCoord dx = point.x - GetCompassXPosition(); |
---|
| 1652 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1653 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 1654 | |
---|
[5876fcb] | 1655 | return (dx * dx + dy * dy <= radius * radius); |
---|
| 1656 | } |
---|
[fa42426] | 1657 | |
---|
[14acdae] | 1658 | bool GfxCore::PointWithinClino(wxPoint point) const |
---|
[5876fcb] | 1659 | { |
---|
| 1660 | // Determine whether a point (in window coordinates) lies within the clino. |
---|
[e2c1671] | 1661 | if (!ShowingClino()) return false; |
---|
| 1662 | |
---|
[33b2094] | 1663 | glaCoord dx = point.x - GetClinoXPosition(); |
---|
| 1664 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1665 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 1666 | |
---|
[5876fcb] | 1667 | return (dx * dx + dy * dy <= radius * radius); |
---|
[dfe4454c] | 1668 | } |
---|
[8000d8f] | 1669 | |
---|
[14acdae] | 1670 | bool GfxCore::PointWithinScaleBar(wxPoint point) const |
---|
[5876fcb] | 1671 | { |
---|
[e2c1671] | 1672 | // Determine whether a point (in window coordinates) lies within the scale |
---|
| 1673 | // bar. |
---|
| 1674 | if (!ShowingScaleBar()) return false; |
---|
[8000d8f] | 1675 | |
---|
[e2c1671] | 1676 | return (point.x >= SCALE_BAR_OFFSET_X && |
---|
| 1677 | point.x <= SCALE_BAR_OFFSET_X + m_ScaleBarWidth && |
---|
| 1678 | point.y <= m_YSize - SCALE_BAR_OFFSET_Y - SCALE_BAR_HEIGHT && |
---|
| 1679 | point.y >= m_YSize - SCALE_BAR_OFFSET_Y - SCALE_BAR_HEIGHT*2); |
---|
[5876fcb] | 1680 | } |
---|
[8000d8f] | 1681 | |
---|
[5876fcb] | 1682 | void GfxCore::SetCompassFromPoint(wxPoint point) |
---|
[8000d8f] | 1683 | { |
---|
[d877aa2] | 1684 | // Given a point in window coordinates, set the heading of the survey. If |
---|
| 1685 | // the point is outside the compass, it snaps to 45 degree intervals; |
---|
| 1686 | // otherwise it operates as normal. |
---|
[8000d8f] | 1687 | |
---|
[5876fcb] | 1688 | wxCoord dx = point.x - GetCompassXPosition(); |
---|
| 1689 | wxCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1690 | wxCoord radius = GetIndicatorRadius(); |
---|
[7aa15c0] | 1691 | |
---|
[0580c6a] | 1692 | double angle = deg(atan2(double(dx), double(dy))) - 180.0; |
---|
[5876fcb] | 1693 | if (dx * dx + dy * dy <= radius * radius) { |
---|
[3ddd351] | 1694 | TurnCave(angle - m_PanAngle); |
---|
[429465a] | 1695 | m_MouseOutsideCompass = false; |
---|
[e577f89] | 1696 | } else { |
---|
[3ddd351] | 1697 | TurnCave(int(angle / 45.0) * 45.0 - m_PanAngle); |
---|
[429465a] | 1698 | m_MouseOutsideCompass = true; |
---|
[7aa15c0] | 1699 | } |
---|
[8000d8f] | 1700 | |
---|
[5876fcb] | 1701 | ForceRefresh(); |
---|
| 1702 | } |
---|
| 1703 | |
---|
| 1704 | void GfxCore::SetClinoFromPoint(wxPoint point) |
---|
| 1705 | { |
---|
[d877aa2] | 1706 | // Given a point in window coordinates, set the elevation of the survey. |
---|
| 1707 | // If the point is outside the clino, it snaps to 90 degree intervals; |
---|
| 1708 | // otherwise it operates as normal. |
---|
[8000d8f] | 1709 | |
---|
[33b2094] | 1710 | glaCoord dx = point.x - GetClinoXPosition(); |
---|
| 1711 | glaCoord dy = point.y - GetIndicatorYPosition(); |
---|
| 1712 | glaCoord radius = GetIndicatorRadius(); |
---|
[f433fda] | 1713 | |
---|
[5876fcb] | 1714 | if (dx >= 0 && dx * dx + dy * dy <= radius * radius) { |
---|
[0580c6a] | 1715 | TiltCave(deg(atan2(double(dy), double(dx))) - m_TiltAngle); |
---|
[429465a] | 1716 | m_MouseOutsideElev = false; |
---|
[e577f89] | 1717 | } else if (dy >= INDICATOR_MARGIN) { |
---|
| 1718 | TiltCave(90.0 - m_TiltAngle); |
---|
[429465a] | 1719 | m_MouseOutsideElev = true; |
---|
[e577f89] | 1720 | } else if (dy <= -INDICATOR_MARGIN) { |
---|
| 1721 | TiltCave(-90.0 - m_TiltAngle); |
---|
[429465a] | 1722 | m_MouseOutsideElev = true; |
---|
[e577f89] | 1723 | } else { |
---|
[429465a] | 1724 | TiltCave(-m_TiltAngle); |
---|
| 1725 | m_MouseOutsideElev = true; |
---|
[5876fcb] | 1726 | } |
---|
[8000d8f] | 1727 | |
---|
[5876fcb] | 1728 | ForceRefresh(); |
---|
[8000d8f] | 1729 | } |
---|
| 1730 | |
---|
[5876fcb] | 1731 | void GfxCore::SetScaleBarFromOffset(wxCoord dx) |
---|
[8000d8f] | 1732 | { |
---|
[5876fcb] | 1733 | // Set the scale of the survey, given an offset as to how much the mouse has |
---|
| 1734 | // been dragged over the scalebar since the last scale change. |
---|
[8000d8f] | 1735 | |
---|
[5b7164d] | 1736 | SetScale((m_ScaleBarWidth + dx) * m_Scale / m_ScaleBarWidth); |
---|
[5876fcb] | 1737 | ForceRefresh(); |
---|
| 1738 | } |
---|
[8000d8f] | 1739 | |
---|
[5876fcb] | 1740 | void GfxCore::RedrawIndicators() |
---|
| 1741 | { |
---|
| 1742 | // Redraw the compass and clino indicators. |
---|
[8000d8f] | 1743 | |
---|
[203d2a7] | 1744 | const wxRect r(m_XSize - INDICATOR_OFFSET_X - INDICATOR_BOX_SIZE*2 - |
---|
[429465a] | 1745 | INDICATOR_GAP, |
---|
| 1746 | m_YSize - INDICATOR_OFFSET_Y - INDICATOR_BOX_SIZE, |
---|
| 1747 | INDICATOR_BOX_SIZE*2 + INDICATOR_GAP, |
---|
| 1748 | INDICATOR_BOX_SIZE); |
---|
[f433fda] | 1749 | |
---|
[5876fcb] | 1750 | Refresh(false, &r); |
---|
[8000d8f] | 1751 | } |
---|
| 1752 | |
---|
[5876fcb] | 1753 | void GfxCore::StartRotation() |
---|
[8000d8f] | 1754 | { |
---|
[5876fcb] | 1755 | // Start the survey rotating. |
---|
[f433fda] | 1756 | |
---|
[5876fcb] | 1757 | m_Rotating = true; |
---|
| 1758 | timer.Start(drawtime); |
---|
| 1759 | } |
---|
[8000d8f] | 1760 | |
---|
[5876fcb] | 1761 | void GfxCore::ToggleRotation() |
---|
| 1762 | { |
---|
| 1763 | // Toggle the survey rotation on/off. |
---|
[f433fda] | 1764 | |
---|
[5876fcb] | 1765 | if (m_Rotating) { |
---|
[2a3d328] | 1766 | StopRotation(); |
---|
| 1767 | } else { |
---|
| 1768 | StartRotation(); |
---|
[5876fcb] | 1769 | } |
---|
| 1770 | } |
---|
[8000d8f] | 1771 | |
---|
[5876fcb] | 1772 | void GfxCore::StopRotation() |
---|
| 1773 | { |
---|
| 1774 | // Stop the survey rotating. |
---|
[8000d8f] | 1775 | |
---|
[5876fcb] | 1776 | m_Rotating = false; |
---|
[33b2094] | 1777 | ForceRefresh(); |
---|
[5876fcb] | 1778 | } |
---|
[8000d8f] | 1779 | |
---|
[eef68f9] | 1780 | bool GfxCore::IsExtendedElevation() const |
---|
[5876fcb] | 1781 | { |
---|
[eef68f9] | 1782 | return m_Parent->IsExtendedElevation(); |
---|
[5876fcb] | 1783 | } |
---|
[8000d8f] | 1784 | |
---|
[5876fcb] | 1785 | void GfxCore::ReverseRotation() |
---|
| 1786 | { |
---|
| 1787 | // Reverse the direction of rotation. |
---|
[8000d8f] | 1788 | |
---|
[5876fcb] | 1789 | m_RotationStep = -m_RotationStep; |
---|
| 1790 | } |
---|
[8000d8f] | 1791 | |
---|
[5876fcb] | 1792 | void GfxCore::RotateSlower(bool accel) |
---|
| 1793 | { |
---|
| 1794 | // Decrease the speed of rotation, optionally by an increased amount. |
---|
[8000d8f] | 1795 | |
---|
[5876fcb] | 1796 | m_RotationStep /= accel ? 1.44 : 1.2; |
---|
[e577f89] | 1797 | if (m_RotationStep < 1.0) { |
---|
| 1798 | m_RotationStep = 1.0; |
---|
[1690fa9] | 1799 | } |
---|
[8000d8f] | 1800 | } |
---|
| 1801 | |
---|
[5876fcb] | 1802 | void GfxCore::RotateFaster(bool accel) |
---|
| 1803 | { |
---|
| 1804 | // Increase the speed of rotation, optionally by an increased amount. |
---|
| 1805 | |
---|
| 1806 | m_RotationStep *= accel ? 1.44 : 1.2; |
---|
[e577f89] | 1807 | if (m_RotationStep > 450.0) { |
---|
| 1808 | m_RotationStep = 450.0; |
---|
[1690fa9] | 1809 | } |
---|
[5876fcb] | 1810 | } |
---|
[8000d8f] | 1811 | |
---|
[5876fcb] | 1812 | void GfxCore::SwitchToElevation() |
---|
[8000d8f] | 1813 | { |
---|
[5876fcb] | 1814 | // Perform an animated switch to elevation view. |
---|
[8000d8f] | 1815 | |
---|
[5876fcb] | 1816 | switch (m_SwitchingTo) { |
---|
[429465a] | 1817 | case 0: |
---|
| 1818 | timer.Start(drawtime); |
---|
| 1819 | m_SwitchingTo = ELEVATION; |
---|
| 1820 | break; |
---|
[f433fda] | 1821 | |
---|
[429465a] | 1822 | case PLAN: |
---|
| 1823 | m_SwitchingTo = ELEVATION; |
---|
| 1824 | break; |
---|
[f433fda] | 1825 | |
---|
[429465a] | 1826 | case ELEVATION: |
---|
| 1827 | // a second order to switch takes us there right away |
---|
| 1828 | TiltCave(-m_TiltAngle); |
---|
| 1829 | m_SwitchingTo = 0; |
---|
| 1830 | ForceRefresh(); |
---|
[5876fcb] | 1831 | } |
---|
[8000d8f] | 1832 | } |
---|
| 1833 | |
---|
[5876fcb] | 1834 | void GfxCore::SwitchToPlan() |
---|
[8000d8f] | 1835 | { |
---|
[5876fcb] | 1836 | // Perform an animated switch to plan view. |
---|
[8000d8f] | 1837 | |
---|
[5876fcb] | 1838 | switch (m_SwitchingTo) { |
---|
[429465a] | 1839 | case 0: |
---|
| 1840 | timer.Start(drawtime); |
---|
| 1841 | m_SwitchingTo = PLAN; |
---|
| 1842 | break; |
---|
[f433fda] | 1843 | |
---|
[429465a] | 1844 | case ELEVATION: |
---|
| 1845 | m_SwitchingTo = PLAN; |
---|
| 1846 | break; |
---|
[8000d8f] | 1847 | |
---|
[429465a] | 1848 | case PLAN: |
---|
[0580c6a] | 1849 | // A second order to switch takes us there right away |
---|
[e577f89] | 1850 | TiltCave(90.0 - m_TiltAngle); |
---|
[429465a] | 1851 | m_SwitchingTo = 0; |
---|
| 1852 | ForceRefresh(); |
---|
[8000d8f] | 1853 | } |
---|
[5876fcb] | 1854 | } |
---|
[8000d8f] | 1855 | |
---|
[d1628e8e] | 1856 | void GfxCore::SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax) |
---|
| 1857 | { |
---|
| 1858 | |
---|
| 1859 | SetTranslation(-Vector3((xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2)); |
---|
[d0f5918] | 1860 | Double scale = HUGE_VAL; |
---|
[d1628e8e] | 1861 | const Vector3 ext = m_Parent->GetExtent(); |
---|
| 1862 | if (xmax > xmin) { |
---|
| 1863 | Double s = ext.GetX() / (xmax - xmin); |
---|
| 1864 | if (s < scale) scale = s; |
---|
| 1865 | } |
---|
| 1866 | if (ymax > ymin) { |
---|
| 1867 | Double s = ext.GetY() / (ymax - ymin); |
---|
| 1868 | if (s < scale) scale = s; |
---|
| 1869 | } |
---|
| 1870 | if (!ShowingPlan() && zmax > zmin) { |
---|
| 1871 | Double s = ext.GetZ() / (zmax - zmin); |
---|
| 1872 | if (s < scale) scale = s; |
---|
| 1873 | } |
---|
[d0f5918] | 1874 | if (scale != HUGE_VAL) SetScale(scale); |
---|
[d1628e8e] | 1875 | ForceRefresh(); |
---|
| 1876 | } |
---|
| 1877 | |
---|
[14acdae] | 1878 | bool GfxCore::CanRaiseViewpoint() const |
---|
[5876fcb] | 1879 | { |
---|
| 1880 | // Determine if the survey can be viewed from a higher angle of elevation. |
---|
[f433fda] | 1881 | |
---|
[0662b0b] | 1882 | return GetPerspective() ? (m_TiltAngle > -90.0) : (m_TiltAngle < 90.0); |
---|
[8000d8f] | 1883 | } |
---|
| 1884 | |
---|
[14acdae] | 1885 | bool GfxCore::CanLowerViewpoint() const |
---|
[2effbf1] | 1886 | { |
---|
[5876fcb] | 1887 | // Determine if the survey can be viewed from a lower angle of elevation. |
---|
[2effbf1] | 1888 | |
---|
[0662b0b] | 1889 | return GetPerspective() ? (m_TiltAngle < 90.0) : (m_TiltAngle > -90.0); |
---|
[5876fcb] | 1890 | } |
---|
[2effbf1] | 1891 | |
---|
[78c67a6] | 1892 | bool GfxCore::HasDepth() const |
---|
[bd21214] | 1893 | { |
---|
[78c67a6] | 1894 | return m_Parent->GetDepthExtent() == 0.0; |
---|
[bd21214] | 1895 | } |
---|
| 1896 | |
---|
[d4650b3] | 1897 | bool GfxCore::HasRangeOfDates() const |
---|
| 1898 | { |
---|
| 1899 | return m_Parent->GetDateExtent() > 0; |
---|
| 1900 | } |
---|
| 1901 | |
---|
[c61aa79] | 1902 | bool GfxCore::HasErrorInformation() const |
---|
| 1903 | { |
---|
| 1904 | return m_Parent->HasErrorInformation(); |
---|
| 1905 | } |
---|
| 1906 | |
---|
[14acdae] | 1907 | bool GfxCore::ShowingPlan() const |
---|
[5876fcb] | 1908 | { |
---|
| 1909 | // Determine if the survey is in plan view. |
---|
[f433fda] | 1910 | |
---|
[e577f89] | 1911 | return (m_TiltAngle == 90.0); |
---|
[2effbf1] | 1912 | } |
---|
| 1913 | |
---|
[14acdae] | 1914 | bool GfxCore::ShowingElevation() const |
---|
[8000d8f] | 1915 | { |
---|
[5876fcb] | 1916 | // Determine if the survey is in elevation view. |
---|
[f433fda] | 1917 | |
---|
[5876fcb] | 1918 | return (m_TiltAngle == 0.0); |
---|
[8000d8f] | 1919 | } |
---|
| 1920 | |
---|
[14acdae] | 1921 | bool GfxCore::ShowingMeasuringLine() const |
---|
[8000d8f] | 1922 | { |
---|
[5876fcb] | 1923 | // Determine if the measuring line is being shown. |
---|
[f433fda] | 1924 | |
---|
[c00c6713] | 1925 | return (m_there.IsValid() && m_here.IsValid()); |
---|
[8000d8f] | 1926 | } |
---|
| 1927 | |
---|
[eff44b9] | 1928 | void GfxCore::ToggleFlag(bool* flag, int update) |
---|
[5876fcb] | 1929 | { |
---|
| 1930 | *flag = !*flag; |
---|
[6747314] | 1931 | if (update == UPDATE_BLOBS) { |
---|
[eff44b9] | 1932 | UpdateBlobs(); |
---|
[ef1870d] | 1933 | } else if (update == UPDATE_BLOBS_AND_CROSSES) { |
---|
| 1934 | UpdateBlobs(); |
---|
| 1935 | InvalidateList(LIST_CROSSES); |
---|
[6cd6bbe] | 1936 | } |
---|
[eff44b9] | 1937 | ForceRefresh(); |
---|
[5876fcb] | 1938 | } |
---|
[93744a5] | 1939 | |
---|
[14acdae] | 1940 | int GfxCore::GetNumEntrances() const |
---|
[4b1fc48] | 1941 | { |
---|
[5876fcb] | 1942 | return m_Parent->GetNumEntrances(); |
---|
| 1943 | } |
---|
[bd7a61b] | 1944 | |
---|
[14acdae] | 1945 | int GfxCore::GetNumFixedPts() const |
---|
[5876fcb] | 1946 | { |
---|
| 1947 | return m_Parent->GetNumFixedPts(); |
---|
| 1948 | } |
---|
[7757a4ed] | 1949 | |
---|
[14acdae] | 1950 | int GfxCore::GetNumExportedPts() const |
---|
[5876fcb] | 1951 | { |
---|
| 1952 | return m_Parent->GetNumExportedPts(); |
---|
| 1953 | } |
---|
| 1954 | |
---|
| 1955 | void GfxCore::ClearTreeSelection() |
---|
| 1956 | { |
---|
| 1957 | m_Parent->ClearTreeSelection(); |
---|
| 1958 | } |
---|
| 1959 | |
---|
[82c3731] | 1960 | void GfxCore::CentreOn(const Point &p) |
---|
[5876fcb] | 1961 | { |
---|
[d67450e] | 1962 | SetTranslation(-p); |
---|
[00a68e0] | 1963 | m_HitTestGridValid = false; |
---|
[f433fda] | 1964 | |
---|
[5876fcb] | 1965 | ForceRefresh(); |
---|
[4b1fc48] | 1966 | } |
---|
[5876fcb] | 1967 | |
---|
[33b2094] | 1968 | void GfxCore::ForceRefresh() |
---|
| 1969 | { |
---|
| 1970 | Refresh(false); |
---|
| 1971 | } |
---|
| 1972 | |
---|
[d2fcc9b] | 1973 | void GfxCore::GenerateList(unsigned int l) |
---|
[33b2094] | 1974 | { |
---|
[9eb58d0] | 1975 | assert(m_HaveData); |
---|
[3ddcad8] | 1976 | |
---|
[d2fcc9b] | 1977 | switch (l) { |
---|
[fe665c4] | 1978 | case LIST_COMPASS: |
---|
| 1979 | DrawCompass(); |
---|
| 1980 | break; |
---|
| 1981 | case LIST_CLINO: |
---|
| 1982 | DrawClino(); |
---|
| 1983 | break; |
---|
| 1984 | case LIST_CLINO_BACK: |
---|
| 1985 | DrawClinoBack(); |
---|
| 1986 | break; |
---|
[252d759] | 1987 | case LIST_DEPTHBAR: |
---|
| 1988 | DrawDepthbar(); |
---|
| 1989 | break; |
---|
[d4650b3] | 1990 | case LIST_DATEBAR: |
---|
| 1991 | DrawDatebar(); |
---|
| 1992 | break; |
---|
[c61aa79] | 1993 | case LIST_ERRORBAR: |
---|
| 1994 | DrawErrorbar(); |
---|
| 1995 | break; |
---|
[d2fcc9b] | 1996 | case LIST_UNDERGROUND_LEGS: |
---|
| 1997 | GenerateDisplayList(); |
---|
| 1998 | break; |
---|
| 1999 | case LIST_TUBES: |
---|
| 2000 | GenerateDisplayListTubes(); |
---|
| 2001 | break; |
---|
| 2002 | case LIST_SURFACE_LEGS: |
---|
| 2003 | GenerateDisplayListSurface(); |
---|
| 2004 | break; |
---|
[86fe6e4] | 2005 | case LIST_BLOBS: |
---|
| 2006 | GenerateBlobsDisplayList(); |
---|
[37d7084] | 2007 | break; |
---|
[86fe6e4] | 2008 | case LIST_CROSSES: { |
---|
| 2009 | BeginCrosses(); |
---|
| 2010 | SetColour(col_LIGHT_GREY); |
---|
| 2011 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 2012 | while (pos != m_Parent->GetLabelsEnd()) { |
---|
| 2013 | const LabelInfo* label = *pos++; |
---|
| 2014 | |
---|
| 2015 | if ((m_Surface && label->IsSurface()) || |
---|
| 2016 | (m_Legs && label->IsUnderground()) || |
---|
| 2017 | (!label->IsSurface() && !label->IsUnderground())) { |
---|
| 2018 | // Check if this station should be displayed |
---|
| 2019 | // (last case is for stns with no legs attached) |
---|
| 2020 | DrawCross(label->GetX(), label->GetY(), label->GetZ()); |
---|
| 2021 | } |
---|
| 2022 | } |
---|
| 2023 | EndCrosses(); |
---|
| 2024 | break; |
---|
| 2025 | } |
---|
[37d7084] | 2026 | case LIST_GRID: |
---|
| 2027 | DrawGrid(); |
---|
[d2fcc9b] | 2028 | break; |
---|
[86fe6e4] | 2029 | case LIST_SHADOW: |
---|
| 2030 | GenerateDisplayListShadow(); |
---|
[d2fcc9b] | 2031 | break; |
---|
| 2032 | default: |
---|
| 2033 | assert(false); |
---|
| 2034 | break; |
---|
| 2035 | } |
---|
| 2036 | } |
---|
| 2037 | |
---|
[d67450e] | 2038 | void GfxCore::ToggleSmoothShading() |
---|
| 2039 | { |
---|
| 2040 | GLACanvas::ToggleSmoothShading(); |
---|
| 2041 | InvalidateList(LIST_TUBES); |
---|
| 2042 | ForceRefresh(); |
---|
| 2043 | } |
---|
| 2044 | |
---|
[d2fcc9b] | 2045 | void GfxCore::GenerateDisplayList() |
---|
| 2046 | { |
---|
| 2047 | // Generate the display list for the underground legs. |
---|
[c61aa79] | 2048 | list<traverse>::const_iterator trav = m_Parent->traverses_begin(); |
---|
| 2049 | list<traverse>::const_iterator tend = m_Parent->traverses_end(); |
---|
[3ddcad8] | 2050 | while (trav != tend) { |
---|
| 2051 | (this->*AddPoly)(*trav); |
---|
| 2052 | ++trav; |
---|
| 2053 | } |
---|
[33b2094] | 2054 | } |
---|
| 2055 | |
---|
[9eb58d0] | 2056 | void GfxCore::GenerateDisplayListTubes() |
---|
[33b2094] | 2057 | { |
---|
[9eb58d0] | 2058 | // Generate the display list for the tubes. |
---|
[ee05463] | 2059 | list<vector<XSect> >::const_iterator trav = m_Parent->tubes_begin(); |
---|
| 2060 | list<vector<XSect> >::const_iterator tend = m_Parent->tubes_end(); |
---|
[3ddcad8] | 2061 | while (trav != tend) { |
---|
| 2062 | SkinPassage(*trav); |
---|
| 2063 | ++trav; |
---|
| 2064 | } |
---|
[9eb58d0] | 2065 | } |
---|
[33b2094] | 2066 | |
---|
[9eb58d0] | 2067 | void GfxCore::GenerateDisplayListSurface() |
---|
| 2068 | { |
---|
| 2069 | // Generate the display list for the surface legs. |
---|
[3ddcad8] | 2070 | EnableDashedLines(); |
---|
[c61aa79] | 2071 | list<traverse>::const_iterator trav = m_Parent->surface_traverses_begin(); |
---|
| 2072 | list<traverse>::const_iterator tend = m_Parent->surface_traverses_end(); |
---|
[3ddcad8] | 2073 | while (trav != tend) { |
---|
[c61aa79] | 2074 | if (m_ColourBy == COLOUR_BY_ERROR) { |
---|
| 2075 | AddPolylineError(*trav); |
---|
| 2076 | } else { |
---|
| 2077 | AddPolyline(*trav); |
---|
| 2078 | } |
---|
[3ddcad8] | 2079 | ++trav; |
---|
| 2080 | } |
---|
| 2081 | DisableDashedLines(); |
---|
[d9b3270] | 2082 | } |
---|
[33b2094] | 2083 | |
---|
[37d7084] | 2084 | void GfxCore::GenerateDisplayListShadow() |
---|
[f4c5932] | 2085 | { |
---|
| 2086 | SetColour(col_BLACK); |
---|
[c61aa79] | 2087 | list<traverse>::const_iterator trav = m_Parent->traverses_begin(); |
---|
| 2088 | list<traverse>::const_iterator tend = m_Parent->traverses_end(); |
---|
[f4c5932] | 2089 | while (trav != tend) { |
---|
| 2090 | AddPolylineShadow(*trav); |
---|
| 2091 | ++trav; |
---|
| 2092 | } |
---|
| 2093 | } |
---|
| 2094 | |
---|
[d2fcc9b] | 2095 | // Plot blobs. |
---|
[d9b3270] | 2096 | void GfxCore::GenerateBlobsDisplayList() |
---|
| 2097 | { |
---|
[e633bb1] | 2098 | if (!(m_Entrances || m_FixedPts || m_ExportedPts || |
---|
| 2099 | m_Parent->GetNumHighlightedPts())) |
---|
| 2100 | return; |
---|
[429465a] | 2101 | |
---|
[e633bb1] | 2102 | // Plot blobs. |
---|
| 2103 | gla_colour prev_col = col_BLACK; // not a colour used for blobs |
---|
| 2104 | list<LabelInfo*>::const_iterator pos = m_Parent->GetLabels(); |
---|
| 2105 | BeginBlobs(); |
---|
| 2106 | while (pos != m_Parent->GetLabelsEnd()) { |
---|
[429465a] | 2107 | const LabelInfo* label = *pos++; |
---|
| 2108 | |
---|
| 2109 | // When more than one flag is set on a point: |
---|
| 2110 | // search results take priority over entrance highlighting |
---|
| 2111 | // which takes priority over fixed point |
---|
| 2112 | // highlighting, which in turn takes priority over exported |
---|
| 2113 | // point highlighting. |
---|
| 2114 | |
---|
| 2115 | if (!((m_Surface && label->IsSurface()) || |
---|
| 2116 | (m_Legs && label->IsUnderground()) || |
---|
| 2117 | (!label->IsSurface() && !label->IsUnderground()))) { |
---|
| 2118 | // if this station isn't to be displayed, skip to the next |
---|
| 2119 | // (last case is for stns with no legs attached) |
---|
| 2120 | continue; |
---|
| 2121 | } |
---|
| 2122 | |
---|
[e633bb1] | 2123 | gla_colour col; |
---|
| 2124 | |
---|
[429465a] | 2125 | if (label->IsHighLighted()) { |
---|
| 2126 | col = col_YELLOW; |
---|
| 2127 | } else if (m_Entrances && label->IsEntrance()) { |
---|
| 2128 | col = col_GREEN; |
---|
| 2129 | } else if (m_FixedPts && label->IsFixedPt()) { |
---|
| 2130 | col = col_RED; |
---|
| 2131 | } else if (m_ExportedPts && label->IsExportedPt()) { |
---|
| 2132 | col = col_TURQUOISE; |
---|
| 2133 | } else { |
---|
| 2134 | continue; |
---|
| 2135 | } |
---|
| 2136 | |
---|
[e633bb1] | 2137 | // Stations are sorted by blob type, so colour changes are infrequent. |
---|
| 2138 | if (col != prev_col) { |
---|
[aa048c3] | 2139 | SetColour(col); |
---|
[e633bb1] | 2140 | prev_col = col; |
---|
[429465a] | 2141 | } |
---|
[e633bb1] | 2142 | DrawBlob(label->GetX(), label->GetY(), label->GetZ()); |
---|
[d9b3270] | 2143 | } |
---|
[e633bb1] | 2144 | EndBlobs(); |
---|
[33b2094] | 2145 | } |
---|
| 2146 | |
---|
[6747314] | 2147 | void GfxCore::DrawIndicators() |
---|
[33b2094] | 2148 | { |
---|
| 2149 | // Draw depthbar. |
---|
[d4650b3] | 2150 | if (m_Depthbar) { |
---|
[78c67a6] | 2151 | if (m_ColourBy == COLOUR_BY_DEPTH && m_Parent->GetDepthExtent() != 0.0) { |
---|
[d4650b3] | 2152 | DrawList2D(LIST_DEPTHBAR, m_XSize, m_YSize, 0); |
---|
| 2153 | } else if (m_ColourBy == COLOUR_BY_DATE && m_Parent->GetDateExtent()) { |
---|
| 2154 | DrawList2D(LIST_DATEBAR, m_XSize, m_YSize, 0); |
---|
[c61aa79] | 2155 | } else if (m_ColourBy == COLOUR_BY_ERROR && m_Parent->HasErrorInformation()) { |
---|
| 2156 | DrawList2D(LIST_ERRORBAR, m_XSize, m_YSize, 0); |
---|
[d4650b3] | 2157 | } |
---|
[33b2094] | 2158 | } |
---|
[56da40e] | 2159 | |
---|
[203d2a7] | 2160 | // Draw compass or elevation/heading indicators. |
---|
[eef68f9] | 2161 | if (m_Compass || m_Clino) { |
---|
| 2162 | if (!m_Parent->IsExtendedElevation()) Draw2dIndicators(); |
---|
[203d2a7] | 2163 | } |
---|
[f433fda] | 2164 | |
---|
[56da40e] | 2165 | // Draw scalebar. |
---|
| 2166 | if (m_Scalebar) { |
---|
[429465a] | 2167 | DrawScalebar(); |
---|
[56da40e] | 2168 | } |
---|
[33b2094] | 2169 | } |
---|
| 2170 | |
---|
[d67450e] | 2171 | void GfxCore::PlaceVertexWithColour(const Vector3 & v, Double factor) |
---|
[f383708] | 2172 | { |
---|
[da6c802] | 2173 | SetColour(GetSurfacePen(), factor); // FIXME : assumes surface pen is white! |
---|
[d67450e] | 2174 | PlaceVertex(v); |
---|
[da6c802] | 2175 | } |
---|
[f433fda] | 2176 | |
---|
[d67450e] | 2177 | void GfxCore::PlaceVertexWithDepthColour(const Vector3 &v, Double factor) |
---|
[da6c802] | 2178 | { |
---|
| 2179 | // Set the drawing colour based on the altitude. |
---|
[78c67a6] | 2180 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
[125c9ea] | 2181 | assert(z_ext > 0); |
---|
[f383708] | 2182 | |
---|
[78c67a6] | 2183 | Double z = v.GetZ() - m_Parent->GetDepthMin(); |
---|
[f383708] | 2184 | // points arising from tubes may be slightly outside the limits... |
---|
[78c67a6] | 2185 | if (z < 0) z = 0; |
---|
| 2186 | if (z > z_ext) z = z_ext; |
---|
[a6f081c] | 2187 | |
---|
[78c67a6] | 2188 | Double how_far = z / z_ext; |
---|
[f383708] | 2189 | assert(how_far >= 0.0); |
---|
| 2190 | assert(how_far <= 1.0); |
---|
| 2191 | |
---|
[0e69efe] | 2192 | int band = int(floor(how_far * (GetNumDepthBands() - 1))); |
---|
| 2193 | GLAPen pen1 = GetPen(band); |
---|
[d4650b3] | 2194 | if (band < GetNumDepthBands() - 1) { |
---|
| 2195 | const GLAPen& pen2 = GetPen(band + 1); |
---|
[f433fda] | 2196 | |
---|
[d4650b3] | 2197 | Double interval = z_ext / (GetNumDepthBands() - 1); |
---|
[78c67a6] | 2198 | Double into_band = z / interval - band; |
---|
[f433fda] | 2199 | |
---|
[d4650b3] | 2200 | // printf("%g z_offset=%g interval=%g band=%d\n", into_band, |
---|
| 2201 | // z_offset, interval, band); |
---|
| 2202 | // FIXME: why do we need to clamp here? Is it because the walls can |
---|
| 2203 | // extend further up/down than the centre-line? |
---|
| 2204 | if (into_band < 0.0) into_band = 0.0; |
---|
| 2205 | if (into_band > 1.0) into_band = 1.0; |
---|
| 2206 | assert(into_band >= 0.0); |
---|
| 2207 | assert(into_band <= 1.0); |
---|
[f433fda] | 2208 | |
---|
[d4650b3] | 2209 | pen1.Interpolate(pen2, into_band); |
---|
| 2210 | } |
---|
[aa048c3] | 2211 | SetColour(pen1, factor); |
---|
[f383708] | 2212 | |
---|
[d67450e] | 2213 | PlaceVertex(v); |
---|
[f383708] | 2214 | } |
---|
| 2215 | |
---|
[82f584f] | 2216 | void GfxCore::SplitLineAcrossBands(int band, int band2, |
---|
[4a0e6b35] | 2217 | const Vector3 &p, const Vector3 &q, |
---|
[82f584f] | 2218 | Double factor) |
---|
[b5d64e6] | 2219 | { |
---|
[4a0e6b35] | 2220 | const int step = (band < band2) ? 1 : -1; |
---|
[b5d64e6] | 2221 | for (int i = band; i != band2; i += step) { |
---|
[4a0e6b35] | 2222 | const Double z = GetDepthBoundaryBetweenBands(i, i + step); |
---|
| 2223 | |
---|
| 2224 | // Find the intersection point of the line p -> q |
---|
| 2225 | // with the plane parallel to the xy-plane with z-axis intersection z. |
---|
[d67450e] | 2226 | assert(q.GetZ() - p.GetZ() != 0.0); |
---|
[4a0e6b35] | 2227 | |
---|
[d67450e] | 2228 | const Double t = (z - p.GetZ()) / (q.GetZ() - p.GetZ()); |
---|
[4a0e6b35] | 2229 | // assert(0.0 <= t && t <= 1.0); FIXME: rounding problems! |
---|
| 2230 | |
---|
[d67450e] | 2231 | const Double x = p.GetX() + t * (q.GetX() - p.GetX()); |
---|
| 2232 | const Double y = p.GetY() + t * (q.GetY() - p.GetY()); |
---|
[4a0e6b35] | 2233 | |
---|
[d67450e] | 2234 | PlaceVertexWithDepthColour(Vector3(x, y, z), factor); |
---|
[b5d64e6] | 2235 | } |
---|
| 2236 | } |
---|
| 2237 | |
---|
[14acdae] | 2238 | int GfxCore::GetDepthColour(Double z) const |
---|
[b5d64e6] | 2239 | { |
---|
[82f584f] | 2240 | // Return the (0-based) depth colour band index for a z-coordinate. |
---|
[78c67a6] | 2241 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
[125c9ea] | 2242 | assert(z_ext > 0); |
---|
[78c67a6] | 2243 | z -= m_Parent->GetDepthMin(); |
---|
[a6f081c] | 2244 | z += z_ext / 2; |
---|
[125c9ea] | 2245 | return int(z / z_ext * (GetNumDepthBands() - 1)); |
---|
[b5d64e6] | 2246 | } |
---|
| 2247 | |
---|
[14acdae] | 2248 | Double GfxCore::GetDepthBoundaryBetweenBands(int a, int b) const |
---|
[b5d64e6] | 2249 | { |
---|
[82f584f] | 2250 | // Return the z-coordinate of the depth colour boundary between |
---|
| 2251 | // two adjacent depth colour bands (specified by 0-based indices). |
---|
| 2252 | |
---|
| 2253 | assert((a == b - 1) || (a == b + 1)); |
---|
[0e69efe] | 2254 | if (GetNumDepthBands() == 1) return 0; |
---|
[82f584f] | 2255 | |
---|
| 2256 | int band = (a > b) ? a : b; // boundary N lies on the bottom of band N. |
---|
[78c67a6] | 2257 | Double z_ext = m_Parent->GetDepthExtent(); |
---|
| 2258 | return (z_ext * band / (GetNumDepthBands() - 1)) - z_ext / 2 |
---|
| 2259 | + m_Parent->GetDepthMin(); |
---|
[b5d64e6] | 2260 | } |
---|
| 2261 | |
---|
[c61aa79] | 2262 | void GfxCore::AddPolyline(const traverse & centreline) |
---|
[da6c802] | 2263 | { |
---|
| 2264 | BeginPolyline(); |
---|
| 2265 | SetColour(GetSurfacePen()); |
---|
[d4650b3] | 2266 | vector<PointInfo>::const_iterator i = centreline.begin(); |
---|
[d67450e] | 2267 | PlaceVertex(*i); |
---|
[da6c802] | 2268 | ++i; |
---|
| 2269 | while (i != centreline.end()) { |
---|
[d67450e] | 2270 | PlaceVertex(*i); |
---|
[da6c802] | 2271 | ++i; |
---|
| 2272 | } |
---|
| 2273 | EndPolyline(); |
---|
| 2274 | } |
---|
[2a3d328] | 2275 | |
---|
[c61aa79] | 2276 | void GfxCore::AddPolylineShadow(const traverse & centreline) |
---|
[f4c5932] | 2277 | { |
---|
| 2278 | BeginPolyline(); |
---|
[78c67a6] | 2279 | const double z = -0.5 * m_Parent->GetZExtent(); |
---|
[d4650b3] | 2280 | vector<PointInfo>::const_iterator i = centreline.begin(); |
---|
[78c67a6] | 2281 | PlaceVertex(i->GetX(), i->GetY(), z); |
---|
[f4c5932] | 2282 | ++i; |
---|
| 2283 | while (i != centreline.end()) { |
---|
[78c67a6] | 2284 | PlaceVertex(i->GetX(), i->GetY(), z); |
---|
[f4c5932] | 2285 | ++i; |
---|
| 2286 | } |
---|
| 2287 | EndPolyline(); |
---|
| 2288 | } |
---|
| 2289 | |
---|
[c61aa79] | 2290 | void GfxCore::AddPolylineDepth(const traverse & centreline) |
---|
[da6c802] | 2291 | { |
---|
| 2292 | BeginPolyline(); |
---|
[d4650b3] | 2293 | vector<PointInfo>::const_iterator i, prev_i; |
---|
[da6c802] | 2294 | i = centreline.begin(); |
---|
[ee7af72] | 2295 | int band0 = GetDepthColour(i->GetZ()); |
---|
[d67450e] | 2296 | PlaceVertexWithDepthColour(*i); |
---|
[da6c802] | 2297 | prev_i = i; |
---|
| 2298 | ++i; |
---|
| 2299 | while (i != centreline.end()) { |
---|
[ee7af72] | 2300 | int band = GetDepthColour(i->GetZ()); |
---|
[da6c802] | 2301 | if (band != band0) { |
---|
[d67450e] | 2302 | SplitLineAcrossBands(band0, band, *prev_i, *i); |
---|
[da6c802] | 2303 | band0 = band; |
---|
| 2304 | } |
---|
[d67450e] | 2305 | PlaceVertexWithDepthColour(*i); |
---|
[da6c802] | 2306 | prev_i = i; |
---|
| 2307 | ++i; |
---|
| 2308 | } |
---|
| 2309 | EndPolyline(); |
---|
| 2310 | } |
---|
| 2311 | |
---|
[f433fda] | 2312 | void GfxCore::AddQuadrilateral(const Vector3 &a, const Vector3 &b, |
---|
[14acdae] | 2313 | const Vector3 &c, const Vector3 &d) |
---|
[da6c802] | 2314 | { |
---|
| 2315 | Vector3 normal = (a - c) * (d - b); |
---|
| 2316 | normal.normalise(); |
---|
| 2317 | Double factor = dot(normal, light) * .3 + .7; |
---|
[a517825] | 2318 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 2319 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
[9b57c71b] | 2320 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
[da6c802] | 2321 | BeginQuadrilaterals(); |
---|
[6673525] | 2322 | // FIXME: these glTexCoord2i calls should be in gla-gl.cc |
---|
[a517825] | 2323 | glTexCoord2i(0, 0); |
---|
[d67450e] | 2324 | PlaceVertexWithColour(a, factor); |
---|
[a517825] | 2325 | glTexCoord2i(w, 0); |
---|
[d67450e] | 2326 | PlaceVertexWithColour(b, factor); |
---|
[a517825] | 2327 | glTexCoord2i(w, h); |
---|
[d67450e] | 2328 | PlaceVertexWithColour(c, factor); |
---|
[a517825] | 2329 | glTexCoord2i(0, h); |
---|
[d67450e] | 2330 | PlaceVertexWithColour(d, factor); |
---|
[da6c802] | 2331 | EndQuadrilaterals(); |
---|
| 2332 | } |
---|
| 2333 | |
---|
| 2334 | void GfxCore::AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b, |
---|
| 2335 | const Vector3 &c, const Vector3 &d) |
---|
[2b02270] | 2336 | { |
---|
| 2337 | Vector3 normal = (a - c) * (d - b); |
---|
| 2338 | normal.normalise(); |
---|
| 2339 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 2340 | int a_band, b_band, c_band, d_band; |
---|
[d67450e] | 2341 | a_band = GetDepthColour(a.GetZ()); |
---|
[0e69efe] | 2342 | a_band = min(max(a_band, 0), GetNumDepthBands()); |
---|
[d67450e] | 2343 | b_band = GetDepthColour(b.GetZ()); |
---|
[0e69efe] | 2344 | b_band = min(max(b_band, 0), GetNumDepthBands()); |
---|
[d67450e] | 2345 | c_band = GetDepthColour(c.GetZ()); |
---|
[0e69efe] | 2346 | c_band = min(max(c_band, 0), GetNumDepthBands()); |
---|
[d67450e] | 2347 | d_band = GetDepthColour(d.GetZ()); |
---|
[0e69efe] | 2348 | d_band = min(max(d_band, 0), GetNumDepthBands()); |
---|
[97fb83a] | 2349 | // All this splitting is incorrect - we need to make a separate polygon |
---|
| 2350 | // for each depth band... |
---|
[a517825] | 2351 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 2352 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
[9b57c71b] | 2353 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
[b5d64e6] | 2354 | BeginPolygon(); |
---|
[d67450e] | 2355 | //// PlaceNormal(normal); |
---|
[6673525] | 2356 | // FIXME: these glTexCoord2i calls should be in gla-gl.cc |
---|
[a517825] | 2357 | glTexCoord2i(0, 0); |
---|
[d67450e] | 2358 | PlaceVertexWithDepthColour(a, factor); |
---|
[2b02270] | 2359 | if (a_band != b_band) { |
---|
[b5d64e6] | 2360 | SplitLineAcrossBands(a_band, b_band, a, b, factor); |
---|
[2b02270] | 2361 | } |
---|
[a517825] | 2362 | glTexCoord2i(w, 0); |
---|
[d67450e] | 2363 | PlaceVertexWithDepthColour(b, factor); |
---|
[2b02270] | 2364 | if (b_band != c_band) { |
---|
[b5d64e6] | 2365 | SplitLineAcrossBands(b_band, c_band, b, c, factor); |
---|
[2b02270] | 2366 | } |
---|
[a517825] | 2367 | glTexCoord2i(w, h); |
---|
[d67450e] | 2368 | PlaceVertexWithDepthColour(c, factor); |
---|
[2b02270] | 2369 | if (c_band != d_band) { |
---|
[b5d64e6] | 2370 | SplitLineAcrossBands(c_band, d_band, c, d, factor); |
---|
[2b02270] | 2371 | } |
---|
[a517825] | 2372 | glTexCoord2i(0, h); |
---|
[d67450e] | 2373 | PlaceVertexWithDepthColour(d, factor); |
---|
[2b02270] | 2374 | if (d_band != a_band) { |
---|
[b5d64e6] | 2375 | SplitLineAcrossBands(d_band, a_band, d, a, factor); |
---|
[2b02270] | 2376 | } |
---|
[b5d64e6] | 2377 | EndPolygon(); |
---|
[2b02270] | 2378 | } |
---|
| 2379 | |
---|
[d4650b3] | 2380 | void GfxCore::SetColourFromDate(time_t date, Double factor) |
---|
| 2381 | { |
---|
| 2382 | // Set the drawing colour based on a date. |
---|
| 2383 | |
---|
| 2384 | if (date == 0) { |
---|
| 2385 | SetColour(GetSurfacePen(), factor); |
---|
| 2386 | return; |
---|
| 2387 | } |
---|
| 2388 | |
---|
| 2389 | time_t date_ext = m_Parent->GetDateExtent(); |
---|
[125c9ea] | 2390 | assert(date_ext > 0); |
---|
[d4650b3] | 2391 | time_t date_offset = date - m_Parent->GetDateMin(); |
---|
| 2392 | |
---|
| 2393 | Double how_far = (Double)date_offset / date_ext; |
---|
| 2394 | assert(how_far >= 0.0); |
---|
| 2395 | assert(how_far <= 1.0); |
---|
| 2396 | |
---|
| 2397 | int band = int(floor(how_far * (GetNumDepthBands() - 1))); |
---|
| 2398 | GLAPen pen1 = GetPen(band); |
---|
| 2399 | if (band < GetNumDepthBands() - 1) { |
---|
| 2400 | const GLAPen& pen2 = GetPen(band + 1); |
---|
| 2401 | |
---|
| 2402 | Double interval = date_ext / (GetNumDepthBands() - 1); |
---|
| 2403 | Double into_band = date_offset / interval - band; |
---|
| 2404 | |
---|
| 2405 | // printf("%g z_offset=%g interval=%g band=%d\n", into_band, |
---|
| 2406 | // z_offset, interval, band); |
---|
| 2407 | // FIXME: why do we need to clamp here? Is it because the walls can |
---|
| 2408 | // extend further up/down than the centre-line? |
---|
| 2409 | if (into_band < 0.0) into_band = 0.0; |
---|
| 2410 | if (into_band > 1.0) into_band = 1.0; |
---|
| 2411 | assert(into_band >= 0.0); |
---|
| 2412 | assert(into_band <= 1.0); |
---|
| 2413 | |
---|
| 2414 | pen1.Interpolate(pen2, into_band); |
---|
| 2415 | } |
---|
| 2416 | SetColour(pen1, factor); |
---|
| 2417 | } |
---|
| 2418 | |
---|
[c61aa79] | 2419 | void GfxCore::AddPolylineDate(const traverse & centreline) |
---|
[d4650b3] | 2420 | { |
---|
| 2421 | BeginPolyline(); |
---|
| 2422 | vector<PointInfo>::const_iterator i, prev_i; |
---|
| 2423 | i = centreline.begin(); |
---|
| 2424 | time_t date = i->GetDate(); |
---|
| 2425 | SetColourFromDate(date, 1.0); |
---|
[d67450e] | 2426 | PlaceVertex(*i); |
---|
[d4650b3] | 2427 | prev_i = i; |
---|
| 2428 | while (++i != centreline.end()) { |
---|
| 2429 | time_t newdate = i->GetDate(); |
---|
| 2430 | if (newdate != date) { |
---|
| 2431 | EndPolyline(); |
---|
| 2432 | BeginPolyline(); |
---|
| 2433 | date = newdate; |
---|
| 2434 | SetColourFromDate(date, 1.0); |
---|
[d67450e] | 2435 | PlaceVertex(*prev_i); |
---|
[d4650b3] | 2436 | } |
---|
[d67450e] | 2437 | PlaceVertex(*i); |
---|
[d4650b3] | 2438 | prev_i = i; |
---|
| 2439 | } |
---|
| 2440 | EndPolyline(); |
---|
| 2441 | } |
---|
| 2442 | |
---|
| 2443 | static time_t static_date_hack; // FIXME |
---|
| 2444 | |
---|
| 2445 | void GfxCore::AddQuadrilateralDate(const Vector3 &a, const Vector3 &b, |
---|
| 2446 | const Vector3 &c, const Vector3 &d) |
---|
| 2447 | { |
---|
| 2448 | Vector3 normal = (a - c) * (d - b); |
---|
| 2449 | normal.normalise(); |
---|
| 2450 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 2451 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 2452 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 2453 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
| 2454 | BeginPolygon(); |
---|
[d67450e] | 2455 | //// PlaceNormal(normal); |
---|
[d4650b3] | 2456 | SetColourFromDate(static_date_hack, factor); |
---|
| 2457 | // FIXME: these glTexCoord2i calls should be in gla-gl.cc |
---|
| 2458 | glTexCoord2i(0, 0); |
---|
[d67450e] | 2459 | PlaceVertex(a); |
---|
[d4650b3] | 2460 | glTexCoord2i(w, 0); |
---|
[d67450e] | 2461 | PlaceVertex(b); |
---|
[d4650b3] | 2462 | glTexCoord2i(w, h); |
---|
[d67450e] | 2463 | PlaceVertex(c); |
---|
[d4650b3] | 2464 | glTexCoord2i(0, h); |
---|
[d67450e] | 2465 | PlaceVertex(d); |
---|
[d4650b3] | 2466 | EndPolygon(); |
---|
| 2467 | } |
---|
| 2468 | |
---|
[c61aa79] | 2469 | static double static_E_hack; // FIXME |
---|
| 2470 | |
---|
| 2471 | void GfxCore::SetColourFromError(double E, Double factor) |
---|
| 2472 | { |
---|
| 2473 | // Set the drawing colour based on an error value. |
---|
| 2474 | |
---|
| 2475 | if (E < 0) { |
---|
| 2476 | SetColour(GetSurfacePen(), factor); |
---|
| 2477 | return; |
---|
| 2478 | } |
---|
| 2479 | |
---|
| 2480 | Double how_far = E / MAX_ERROR; |
---|
| 2481 | assert(how_far >= 0.0); |
---|
| 2482 | if (how_far > 1.0) how_far = 1.0; |
---|
| 2483 | |
---|
| 2484 | int band = int(floor(how_far * (GetNumDepthBands() - 1))); |
---|
| 2485 | GLAPen pen1 = GetPen(band); |
---|
| 2486 | if (band < GetNumDepthBands() - 1) { |
---|
| 2487 | const GLAPen& pen2 = GetPen(band + 1); |
---|
| 2488 | |
---|
| 2489 | Double interval = MAX_ERROR / (GetNumDepthBands() - 1); |
---|
| 2490 | Double into_band = E / interval - band; |
---|
| 2491 | |
---|
| 2492 | // printf("%g z_offset=%g interval=%g band=%d\n", into_band, |
---|
| 2493 | // z_offset, interval, band); |
---|
| 2494 | // FIXME: why do we need to clamp here? Is it because the walls can |
---|
| 2495 | // extend further up/down than the centre-line? |
---|
| 2496 | if (into_band < 0.0) into_band = 0.0; |
---|
| 2497 | if (into_band > 1.0) into_band = 1.0; |
---|
| 2498 | assert(into_band >= 0.0); |
---|
| 2499 | assert(into_band <= 1.0); |
---|
| 2500 | |
---|
| 2501 | pen1.Interpolate(pen2, into_band); |
---|
| 2502 | } |
---|
| 2503 | SetColour(pen1, factor); |
---|
| 2504 | } |
---|
| 2505 | |
---|
| 2506 | void GfxCore::AddQuadrilateralError(const Vector3 &a, const Vector3 &b, |
---|
| 2507 | const Vector3 &c, const Vector3 &d) |
---|
| 2508 | { |
---|
| 2509 | Vector3 normal = (a - c) * (d - b); |
---|
| 2510 | normal.normalise(); |
---|
| 2511 | Double factor = dot(normal, light) * .3 + .7; |
---|
| 2512 | int w = int(ceil(((b - a).magnitude() + (d - c).magnitude()) / 2)); |
---|
| 2513 | int h = int(ceil(((b - c).magnitude() + (d - a).magnitude()) / 2)); |
---|
| 2514 | // FIXME: should plot triangles instead to avoid rendering glitches. |
---|
| 2515 | BeginPolygon(); |
---|
| 2516 | //// PlaceNormal(normal); |
---|
| 2517 | SetColourFromError(static_E_hack, factor); |
---|
| 2518 | // FIXME: these glTexCoord2i calls should be in gla-gl.cc |
---|
| 2519 | glTexCoord2i(0, 0); |
---|
| 2520 | PlaceVertex(a); |
---|
| 2521 | glTexCoord2i(w, 0); |
---|
| 2522 | PlaceVertex(b); |
---|
| 2523 | glTexCoord2i(w, h); |
---|
| 2524 | PlaceVertex(c); |
---|
| 2525 | glTexCoord2i(0, h); |
---|
| 2526 | PlaceVertex(d); |
---|
| 2527 | EndPolygon(); |
---|
| 2528 | } |
---|
| 2529 | |
---|
| 2530 | void GfxCore::AddPolylineError(const traverse & centreline) |
---|
| 2531 | { |
---|
| 2532 | BeginPolyline(); |
---|
| 2533 | SetColourFromError(centreline.E, 1.0); |
---|
| 2534 | vector<PointInfo>::const_iterator i; |
---|
| 2535 | for(i = centreline.begin(); i != centreline.end(); ++i) { |
---|
| 2536 | PlaceVertex(*i); |
---|
| 2537 | } |
---|
| 2538 | EndPolyline(); |
---|
| 2539 | } |
---|
| 2540 | |
---|
[da6c802] | 2541 | void |
---|
[ee05463] | 2542 | GfxCore::SkinPassage(const vector<XSect> & centreline) |
---|
[3ddcad8] | 2543 | { |
---|
[b3852b5] | 2544 | assert(centreline.size() > 1); |
---|
[3ddcad8] | 2545 | Vector3 U[4]; |
---|
[ee05463] | 2546 | XSect prev_pt_v; |
---|
[3ddcad8] | 2547 | Vector3 last_right(1.0, 0.0, 0.0); |
---|
| 2548 | |
---|
[c61aa79] | 2549 | // FIXME: it's not simple to set the colour of a tube based on error... |
---|
| 2550 | // static_E_hack = something... |
---|
[ee05463] | 2551 | vector<XSect>::const_iterator i = centreline.begin(); |
---|
| 2552 | vector<XSect>::size_type segment = 0; |
---|
[3ddcad8] | 2553 | while (i != centreline.end()) { |
---|
| 2554 | // get the coordinates of this vertex |
---|
[ee05463] | 2555 | const XSect & pt_v = *i++; |
---|
[3ddcad8] | 2556 | |
---|
| 2557 | double z_pitch_adjust = 0.0; |
---|
| 2558 | bool cover_end = false; |
---|
| 2559 | |
---|
| 2560 | Vector3 right, up; |
---|
| 2561 | |
---|
| 2562 | const Vector3 up_v(0.0, 0.0, 1.0); |
---|
| 2563 | |
---|
| 2564 | if (segment == 0) { |
---|
| 2565 | assert(i != centreline.end()); |
---|
| 2566 | // first segment |
---|
| 2567 | |
---|
| 2568 | // get the coordinates of the next vertex |
---|
[ee05463] | 2569 | const XSect & next_pt_v = *i; |
---|
[3ddcad8] | 2570 | |
---|
| 2571 | // calculate vector from this pt to the next one |
---|
[d67450e] | 2572 | Vector3 leg_v = next_pt_v - pt_v; |
---|
[3ddcad8] | 2573 | |
---|
| 2574 | // obtain a vector in the LRUD plane |
---|
| 2575 | right = leg_v * up_v; |
---|
| 2576 | if (right.magnitude() == 0) { |
---|
| 2577 | right = last_right; |
---|
| 2578 | // Obtain a second vector in the LRUD plane, |
---|
| 2579 | // perpendicular to the first. |
---|
[760ad29d] | 2580 | //up = right * leg_v; |
---|
| 2581 | up = up_v; |
---|
[3ddcad8] | 2582 | } else { |
---|
| 2583 | last_right = right; |
---|
| 2584 | up = up_v; |
---|
[da6c802] | 2585 | } |
---|
| 2586 | |
---|
[3ddcad8] | 2587 | cover_end = true; |
---|
[d4650b3] | 2588 | static_date_hack = next_pt_v.GetDate(); |
---|
[3ddcad8] | 2589 | } else if (segment + 1 == centreline.size()) { |
---|
| 2590 | // last segment |
---|
| 2591 | |
---|
| 2592 | // Calculate vector from the previous pt to this one. |
---|
[d67450e] | 2593 | Vector3 leg_v = pt_v - prev_pt_v; |
---|
[3ddcad8] | 2594 | |
---|
| 2595 | // Obtain a horizontal vector in the LRUD plane. |
---|
| 2596 | right = leg_v * up_v; |
---|
| 2597 | if (right.magnitude() == 0) { |
---|
[d67450e] | 2598 | right = Vector3(last_right.GetX(), last_right.GetY(), 0.0); |
---|
[3ddcad8] | 2599 | // Obtain a second vector in the LRUD plane, |
---|
| 2600 | // perpendicular to the first. |
---|
[760ad29d] | 2601 | //up = right * leg_v; |
---|
| 2602 | up = up_v; |
---|
[3ddcad8] | 2603 | } else { |
---|
| 2604 | last_right = right; |
---|
| 2605 | up = up_v; |
---|
| 2606 | } |
---|
[da6c802] | 2607 | |
---|
[3ddcad8] | 2608 | cover_end = true; |
---|
[d4650b3] | 2609 | static_date_hack = pt_v.GetDate(); |
---|
[3ddcad8] | 2610 | } else { |
---|
| 2611 | assert(i != centreline.end()); |
---|
| 2612 | // Intermediate segment. |
---|
| 2613 | |
---|
| 2614 | // Get the coordinates of the next vertex. |
---|
[ee05463] | 2615 | const XSect & next_pt_v = *i; |
---|
[3ddcad8] | 2616 | |
---|
| 2617 | // Calculate vectors from this vertex to the |
---|
| 2618 | // next vertex, and from the previous vertex to |
---|
| 2619 | // this one. |
---|
[d67450e] | 2620 | Vector3 leg1_v = pt_v - prev_pt_v; |
---|
| 2621 | Vector3 leg2_v = next_pt_v - pt_v; |
---|
[3ddcad8] | 2622 | |
---|
| 2623 | // Obtain horizontal vectors perpendicular to |
---|
| 2624 | // both legs, then normalise and average to get |
---|
| 2625 | // a horizontal bisector. |
---|
| 2626 | Vector3 r1 = leg1_v * up_v; |
---|
| 2627 | Vector3 r2 = leg2_v * up_v; |
---|
| 2628 | r1.normalise(); |
---|
| 2629 | r2.normalise(); |
---|
| 2630 | right = r1 + r2; |
---|
| 2631 | if (right.magnitude() == 0) { |
---|
| 2632 | // This is the "mid-pitch" case... |
---|
| 2633 | right = last_right; |
---|
| 2634 | } |
---|
| 2635 | if (r1.magnitude() == 0) { |
---|
| 2636 | Vector3 n = leg1_v; |
---|
| 2637 | n.normalise(); |
---|
[d67450e] | 2638 | z_pitch_adjust = n.GetZ(); |
---|
| 2639 | //up = Vector3(0, 0, leg1_v.GetZ()); |
---|
[760ad29d] | 2640 | //up = right * up; |
---|
| 2641 | up = up_v; |
---|
[3ddcad8] | 2642 | |
---|
| 2643 | // Rotate pitch section to minimise the |
---|
| 2644 | // "tortional stress" - FIXME: use |
---|
| 2645 | // triangles instead of rectangles? |
---|
| 2646 | int shift = 0; |
---|
| 2647 | Double maxdotp = 0; |
---|
| 2648 | |
---|
| 2649 | // Scale to unit vectors in the LRUD plane. |
---|
| 2650 | right.normalise(); |
---|
| 2651 | up.normalise(); |
---|
| 2652 | Vector3 vec = up - right; |
---|
| 2653 | for (int orient = 0; orient <= 3; ++orient) { |
---|
[d67450e] | 2654 | Vector3 tmp = U[orient] - prev_pt_v; |
---|
[3ddcad8] | 2655 | tmp.normalise(); |
---|
| 2656 | Double dotp = dot(vec, tmp); |
---|
| 2657 | if (dotp > maxdotp) { |
---|
| 2658 | maxdotp = dotp; |
---|
| 2659 | shift = orient; |
---|
| 2660 | } |
---|
| 2661 | } |
---|
| 2662 | if (shift) { |
---|
| 2663 | if (shift != 2) { |
---|
| 2664 | Vector3 temp(U[0]); |
---|
[b3852b5] | 2665 | U[0] = U[shift]; |
---|
| 2666 | U[shift] = U[2]; |
---|
| 2667 | U[2] = U[shift ^ 2]; |
---|
| 2668 | U[shift ^ 2] = temp; |
---|
[ee7af72] | 2669 | } else { |
---|
[3ddcad8] | 2670 | swap(U[0], U[2]); |
---|
| 2671 | swap(U[1], U[3]); |
---|
[ee7af72] | 2672 | } |
---|
[3ddcad8] | 2673 | } |
---|
| 2674 | #if 0 |
---|
| 2675 | // Check that the above code actually permuted |
---|
| 2676 | // the vertices correctly. |
---|
| 2677 | shift = 0; |
---|
| 2678 | maxdotp = 0; |
---|
[b3852b5] | 2679 | for (int j = 0; j <= 3; ++j) { |
---|
[d67450e] | 2680 | Vector3 tmp = U[j] - prev_pt_v; |
---|
[3ddcad8] | 2681 | tmp.normalise(); |
---|
| 2682 | Double dotp = dot(vec, tmp); |
---|
| 2683 | if (dotp > maxdotp) { |
---|
| 2684 | maxdotp = dotp + 1e-6; // Add small tolerance to stop 45 degree offset cases being flagged... |
---|
[b3852b5] | 2685 | shift = j; |
---|
[da6c802] | 2686 | } |
---|
[3ddcad8] | 2687 | } |
---|
| 2688 | if (shift) { |
---|
| 2689 | printf("New shift = %d!\n", shift); |
---|
| 2690 | shift = 0; |
---|
| 2691 | maxdotp = 0; |
---|
[b3852b5] | 2692 | for (int j = 0; j <= 3; ++j) { |
---|
[d67450e] | 2693 | Vector3 tmp = U[j] - prev_pt_v; |
---|
[3ddcad8] | 2694 | tmp.normalise(); |
---|
| 2695 | Double dotp = dot(vec, tmp); |
---|
[b3852b5] | 2696 | printf(" %d : %.8f\n", j, dotp); |
---|
[da6c802] | 2697 | } |
---|
| 2698 | } |
---|
[3ddcad8] | 2699 | #endif |
---|
| 2700 | } else if (r2.magnitude() == 0) { |
---|
| 2701 | Vector3 n = leg2_v; |
---|
| 2702 | n.normalise(); |
---|
[d67450e] | 2703 | z_pitch_adjust = n.GetZ(); |
---|
| 2704 | //up = Vector3(0, 0, leg2_v.GetZ()); |
---|
[760ad29d] | 2705 | //up = right * up; |
---|
| 2706 | up = up_v; |
---|
[3ddcad8] | 2707 | } else { |
---|
| 2708 | up = up_v; |
---|
[da6c802] | 2709 | } |
---|
[3ddcad8] | 2710 | last_right = right; |
---|
[d4650b3] | 2711 | static_date_hack = pt_v.GetDate(); |
---|
[da6c802] | 2712 | } |
---|
| 2713 | |
---|
[3ddcad8] | 2714 | // Scale to unit vectors in the LRUD plane. |
---|
| 2715 | right.normalise(); |
---|
| 2716 | up.normalise(); |
---|
[33b2094] | 2717 | |
---|
[3ddcad8] | 2718 | if (z_pitch_adjust != 0) up += Vector3(0, 0, fabs(z_pitch_adjust)); |
---|
[ce2f3ce] | 2719 | |
---|
[57a3cd4] | 2720 | Double l = fabs(pt_v.GetL()); |
---|
| 2721 | Double r = fabs(pt_v.GetR()); |
---|
| 2722 | Double u = fabs(pt_v.GetU()); |
---|
| 2723 | Double d = fabs(pt_v.GetD()); |
---|
[3ddcad8] | 2724 | |
---|
| 2725 | // Produce coordinates of the corners of the LRUD "plane". |
---|
| 2726 | Vector3 v[4]; |
---|
[d67450e] | 2727 | v[0] = pt_v - right * l + up * u; |
---|
| 2728 | v[1] = pt_v + right * r + up * u; |
---|
| 2729 | v[2] = pt_v + right * r - up * d; |
---|
| 2730 | v[3] = pt_v - right * l - up * d; |
---|
[3ddcad8] | 2731 | |
---|
| 2732 | if (segment > 0) { |
---|
| 2733 | (this->*AddQuad)(v[0], v[1], U[1], U[0]); |
---|
| 2734 | (this->*AddQuad)(v[2], v[3], U[3], U[2]); |
---|
| 2735 | (this->*AddQuad)(v[1], v[2], U[2], U[1]); |
---|
| 2736 | (this->*AddQuad)(v[3], v[0], U[0], U[3]); |
---|
[9eb58d0] | 2737 | } |
---|
| 2738 | |
---|
[3ddcad8] | 2739 | if (cover_end) { |
---|
| 2740 | (this->*AddQuad)(v[3], v[2], v[1], v[0]); |
---|
| 2741 | } |
---|
[9eb58d0] | 2742 | |
---|
[3ddcad8] | 2743 | prev_pt_v = pt_v; |
---|
| 2744 | U[0] = v[0]; |
---|
| 2745 | U[1] = v[1]; |
---|
| 2746 | U[2] = v[2]; |
---|
| 2747 | U[3] = v[3]; |
---|
[9eb58d0] | 2748 | |
---|
[3ddcad8] | 2749 | ++segment; |
---|
| 2750 | } |
---|
[33b2094] | 2751 | } |
---|
[b13aee4] | 2752 | |
---|
| 2753 | void GfxCore::FullScreenMode() |
---|
| 2754 | { |
---|
[ea940373] | 2755 | m_Parent->ViewFullScreen(); |
---|
[b13aee4] | 2756 | } |
---|
[fdfa926] | 2757 | |
---|
| 2758 | bool GfxCore::IsFullScreen() const |
---|
| 2759 | { |
---|
| 2760 | return m_Parent->IsFullScreen(); |
---|
| 2761 | } |
---|
[1690fa9] | 2762 | |
---|
[46361bc] | 2763 | void |
---|
| 2764 | GfxCore::MoveViewer(double forward, double up, double right) |
---|
| 2765 | { |
---|
[e577f89] | 2766 | double cT = cos(rad(m_TiltAngle)); |
---|
| 2767 | double sT = sin(rad(m_TiltAngle)); |
---|
| 2768 | double cP = cos(rad(m_PanAngle)); |
---|
| 2769 | double sP = sin(rad(m_PanAngle)); |
---|
[46361bc] | 2770 | Vector3 v_forward(cT * sP, cT * cP, -sT); |
---|
[867a1141] | 2771 | Vector3 v_up(-sT * sP, -sT * cP, -cT); |
---|
| 2772 | Vector3 v_right(-cP, sP, 0); |
---|
[d4a5aaf] | 2773 | assert(fabs(dot(v_forward, v_up)) < 1e-6); |
---|
| 2774 | assert(fabs(dot(v_forward, v_right)) < 1e-6); |
---|
| 2775 | assert(fabs(dot(v_right, v_up)) < 1e-6); |
---|
[46361bc] | 2776 | Vector3 move = v_forward * forward + v_up * up + v_right * right; |
---|
[d67450e] | 2777 | AddTranslation(-move); |
---|
[d877aa2] | 2778 | // Show current position. |
---|
[d67450e] | 2779 | m_Parent->SetCoords(m_Parent->GetOffset() - GetTranslation()); |
---|
[46361bc] | 2780 | ForceRefresh(); |
---|
| 2781 | } |
---|
| 2782 | |
---|
[1690fa9] | 2783 | PresentationMark GfxCore::GetView() const |
---|
| 2784 | { |
---|
[d67450e] | 2785 | return PresentationMark(GetTranslation() + m_Parent->GetOffset(), |
---|
| 2786 | m_PanAngle, m_TiltAngle, m_Scale); |
---|
[1690fa9] | 2787 | } |
---|
| 2788 | |
---|
| 2789 | void GfxCore::SetView(const PresentationMark & p) |
---|
| 2790 | { |
---|
| 2791 | m_SwitchingTo = 0; |
---|
[d67450e] | 2792 | SetTranslation(p - m_Parent->GetOffset()); |
---|
[1690fa9] | 2793 | m_PanAngle = p.angle; |
---|
| 2794 | m_TiltAngle = p.tilt_angle; |
---|
[08253d9] | 2795 | SetRotation(m_PanAngle, m_TiltAngle); |
---|
[1690fa9] | 2796 | SetScale(p.scale); |
---|
| 2797 | ForceRefresh(); |
---|
| 2798 | } |
---|
| 2799 | |
---|
[128fac4] | 2800 | void GfxCore::PlayPres(double speed, bool change_speed) { |
---|
| 2801 | if (!change_speed || presentation_mode == 0) { |
---|
| 2802 | if (speed == 0.0) { |
---|
| 2803 | presentation_mode = 0; |
---|
| 2804 | return; |
---|
| 2805 | } |
---|
| 2806 | presentation_mode = PLAYING; |
---|
| 2807 | next_mark = m_Parent->GetPresMark(MARK_FIRST); |
---|
| 2808 | SetView(next_mark); |
---|
| 2809 | next_mark_time = 0; // There already! |
---|
| 2810 | this_mark_total = 0; |
---|
| 2811 | pres_reverse = (speed < 0); |
---|
| 2812 | } |
---|
| 2813 | |
---|
[d67450e] | 2814 | if (change_speed) pres_speed = speed; |
---|
| 2815 | |
---|
[128fac4] | 2816 | if (speed != 0.0) { |
---|
| 2817 | bool new_pres_reverse = (speed < 0); |
---|
| 2818 | if (new_pres_reverse != pres_reverse) { |
---|
| 2819 | pres_reverse = new_pres_reverse; |
---|
| 2820 | if (pres_reverse) { |
---|
| 2821 | next_mark = m_Parent->GetPresMark(MARK_PREV); |
---|
| 2822 | } else { |
---|
| 2823 | next_mark = m_Parent->GetPresMark(MARK_NEXT); |
---|
| 2824 | } |
---|
| 2825 | swap(this_mark_total, next_mark_time); |
---|
| 2826 | } |
---|
| 2827 | } |
---|
[1690fa9] | 2828 | } |
---|
[6a4cdcb6] | 2829 | |
---|
[da6c802] | 2830 | void GfxCore::SetColourBy(int colour_by) { |
---|
| 2831 | m_ColourBy = colour_by; |
---|
| 2832 | switch (colour_by) { |
---|
| 2833 | case COLOUR_BY_DEPTH: |
---|
| 2834 | AddQuad = &GfxCore::AddQuadrilateralDepth; |
---|
| 2835 | AddPoly = &GfxCore::AddPolylineDepth; |
---|
| 2836 | break; |
---|
[d4650b3] | 2837 | case COLOUR_BY_DATE: |
---|
| 2838 | AddQuad = &GfxCore::AddQuadrilateralDate; |
---|
| 2839 | AddPoly = &GfxCore::AddPolylineDate; |
---|
| 2840 | break; |
---|
[c61aa79] | 2841 | case COLOUR_BY_ERROR: |
---|
| 2842 | AddQuad = &GfxCore::AddQuadrilateralError; |
---|
| 2843 | AddPoly = &GfxCore::AddPolylineError; |
---|
| 2844 | break; |
---|
[da6c802] | 2845 | default: // case COLOUR_BY_NONE: |
---|
| 2846 | AddQuad = &GfxCore::AddQuadrilateral; |
---|
| 2847 | AddPoly = &GfxCore::AddPolyline; |
---|
| 2848 | break; |
---|
| 2849 | } |
---|
| 2850 | |
---|
[d2fcc9b] | 2851 | InvalidateList(LIST_UNDERGROUND_LEGS); |
---|
[c61aa79] | 2852 | InvalidateList(LIST_SURFACE_LEGS); |
---|
[d2fcc9b] | 2853 | InvalidateList(LIST_TUBES); |
---|
[da6c802] | 2854 | |
---|
| 2855 | ForceRefresh(); |
---|
| 2856 | } |
---|
| 2857 | |
---|
[6a4cdcb6] | 2858 | bool GfxCore::ExportMovie(const wxString & fnm) |
---|
| 2859 | { |
---|
| 2860 | int width; |
---|
| 2861 | int height; |
---|
| 2862 | GetSize(&width, &height); |
---|
[028829f] | 2863 | // Round up to next multiple of 2 (required by ffmpeg). |
---|
| 2864 | width += (width & 1); |
---|
[6a4cdcb6] | 2865 | height += (height & 1); |
---|
| 2866 | |
---|
[1805274] | 2867 | mpeg = new MovieMaker(); |
---|
[6a4cdcb6] | 2868 | |
---|
[5627cbb] | 2869 | if (!mpeg->Open(fnm.fn_str(), width, height)) { |
---|
[9b540e6] | 2870 | // FIXME : sort out reporting actual errors from ffmpeg library |
---|
[5627cbb] | 2871 | wxGetApp().ReportError(wxString::Format(wmsg(/*Error writing to file `%s'*/110), fnm.c_str())); |
---|
[6a4cdcb6] | 2872 | delete mpeg; |
---|
| 2873 | mpeg = 0; |
---|
| 2874 | return false; |
---|
| 2875 | } |
---|
[f433fda] | 2876 | |
---|
[128fac4] | 2877 | PlayPres(1, false); |
---|
[6a4cdcb6] | 2878 | return true; |
---|
| 2879 | } |
---|
[223f1ad] | 2880 | |
---|
[ce403f1] | 2881 | void |
---|
| 2882 | GfxCore::OnPrint(const wxString &filename, const wxString &title, |
---|
| 2883 | const wxString &datestamp) |
---|
| 2884 | { |
---|
| 2885 | svxPrintDlg * p; |
---|
| 2886 | p = new svxPrintDlg(m_Parent, filename, title, datestamp, |
---|
| 2887 | m_PanAngle, m_TiltAngle, |
---|
[5940815] | 2888 | m_Names, m_Crosses, m_Legs, m_Surface, |
---|
| 2889 | true); |
---|
[ce403f1] | 2890 | p->Show(TRUE); |
---|
| 2891 | } |
---|
| 2892 | |
---|
[5940815] | 2893 | void |
---|
[223f1ad] | 2894 | GfxCore::OnExport(const wxString &filename, const wxString &title) |
---|
| 2895 | { |
---|
[5940815] | 2896 | svxPrintDlg * p; |
---|
[5627cbb] | 2897 | p = new svxPrintDlg(m_Parent, filename, title, wxString(), |
---|
[5940815] | 2898 | m_PanAngle, m_TiltAngle, |
---|
| 2899 | m_Names, m_Crosses, m_Legs, m_Surface, |
---|
| 2900 | false); |
---|
| 2901 | p->Show(TRUE); |
---|
[223f1ad] | 2902 | } |
---|
[e2c1671] | 2903 | |
---|
| 2904 | static wxCursor |
---|
| 2905 | make_cursor(const unsigned char * bits, const unsigned char * mask, |
---|
| 2906 | int hotx, int hoty) |
---|
| 2907 | { |
---|
[b72f4b5] | 2908 | #if defined __WXMSW__ || defined __WXMAC__ |
---|
[7f3fe6d] | 2909 | wxBitmap cursor_bitmap(reinterpret_cast<const char *>(bits), 32, 32); |
---|
| 2910 | wxBitmap mask_bitmap(reinterpret_cast<const char *>(mask), 32, 32); |
---|
| 2911 | cursor_bitmap.SetMask(new wxMask(mask_bitmap)); |
---|
[e2c1671] | 2912 | wxImage cursor_image = cursor_bitmap.ConvertToImage(); |
---|
| 2913 | cursor_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotx); |
---|
| 2914 | cursor_image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hoty); |
---|
[7f3fe6d] | 2915 | return wxCursor(cursor_image); |
---|
[e2c1671] | 2916 | #else |
---|
| 2917 | return wxCursor((const char *)bits, 32, 32, hotx, hoty, |
---|
| 2918 | (const char *)mask, wxWHITE, wxBLACK); |
---|
| 2919 | #endif |
---|
| 2920 | } |
---|
| 2921 | |
---|
| 2922 | const |
---|
| 2923 | #include "hand.xbm" |
---|
| 2924 | const |
---|
| 2925 | #include "handmask.xbm" |
---|
| 2926 | |
---|
| 2927 | const |
---|
| 2928 | #include "brotate.xbm" |
---|
| 2929 | const |
---|
| 2930 | #include "brotatemask.xbm" |
---|
| 2931 | |
---|
| 2932 | const |
---|
| 2933 | #include "vrotate.xbm" |
---|
| 2934 | const |
---|
| 2935 | #include "vrotatemask.xbm" |
---|
| 2936 | |
---|
| 2937 | const |
---|
| 2938 | #include "rotate.xbm" |
---|
| 2939 | const |
---|
| 2940 | #include "rotatemask.xbm" |
---|
| 2941 | |
---|
[ecf2d23] | 2942 | const |
---|
| 2943 | #include "rotatezoom.xbm" |
---|
| 2944 | const |
---|
| 2945 | #include "rotatezoommask.xbm" |
---|
| 2946 | |
---|
[e2c1671] | 2947 | void |
---|
| 2948 | GfxCore::SetCursor(GfxCore::cursor new_cursor) |
---|
| 2949 | { |
---|
| 2950 | // Check if we're already showing that cursor. |
---|
| 2951 | if (current_cursor == new_cursor) return; |
---|
| 2952 | |
---|
| 2953 | current_cursor = new_cursor; |
---|
| 2954 | switch (current_cursor) { |
---|
| 2955 | case GfxCore::CURSOR_DEFAULT: |
---|
| 2956 | GLACanvas::SetCursor(wxNullCursor); |
---|
| 2957 | break; |
---|
| 2958 | case GfxCore::CURSOR_POINTING_HAND: |
---|
| 2959 | GLACanvas::SetCursor(wxCursor(wxCURSOR_HAND)); |
---|
| 2960 | break; |
---|
| 2961 | case GfxCore::CURSOR_DRAGGING_HAND: |
---|
| 2962 | GLACanvas::SetCursor(make_cursor(hand_bits, handmask_bits, 12, 18)); |
---|
| 2963 | break; |
---|
| 2964 | case GfxCore::CURSOR_HORIZONTAL_RESIZE: |
---|
| 2965 | GLACanvas::SetCursor(wxCursor(wxCURSOR_SIZEWE)); |
---|
| 2966 | break; |
---|
| 2967 | case GfxCore::CURSOR_ROTATE_HORIZONTALLY: |
---|
| 2968 | GLACanvas::SetCursor(make_cursor(rotate_bits, rotatemask_bits, 15, 15)); |
---|
| 2969 | break; |
---|
| 2970 | case GfxCore::CURSOR_ROTATE_VERTICALLY: |
---|
| 2971 | GLACanvas::SetCursor(make_cursor(vrotate_bits, vrotatemask_bits, 15, 15)); |
---|
| 2972 | break; |
---|
| 2973 | case GfxCore::CURSOR_ROTATE_EITHER_WAY: |
---|
| 2974 | GLACanvas::SetCursor(make_cursor(brotate_bits, brotatemask_bits, 15, 15)); |
---|
| 2975 | break; |
---|
| 2976 | case GfxCore::CURSOR_ZOOM: |
---|
| 2977 | GLACanvas::SetCursor(wxCursor(wxCURSOR_MAGNIFIER)); |
---|
| 2978 | break; |
---|
[ecf2d23] | 2979 | case GfxCore::CURSOR_ZOOM_ROTATE: |
---|
| 2980 | GLACanvas::SetCursor(make_cursor(rotatezoom_bits, rotatezoommask_bits, 15, 15)); |
---|
| 2981 | break; |
---|
[e2c1671] | 2982 | } |
---|
| 2983 | } |
---|